<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 100% !important;overflow: inherit !important;} 
.dynamic{display:none}
table td {
padding: 6px !important;
}
legend{line-height: 16px;font-weight:100;}

.outer .MigrateLeftFee{ 
  background-color: #DADADA !important;
  border: 5px solid #181616 !important;
  min-height: 440px;
  min-width:700px;
}
.st {
	width: 55px;
	font-size:10px;
	display: inline-block;
	color: #021EF0;
}
.size{
	font-size:12px;
}
.recepit {
	width: 717px !important;
	height: 344px !important;
}
.total{
	color: darkgreen;
    font-weight: 800;
}
</style>


<?php
$pgMod="pending_followup";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);

if(isset($_SESSION['msg']) && $_SESSION['msg']!=""){
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0){
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}

	?>
 <!--   <form method="get" action="">-->
 <!--   <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />-->
	<!--<div class="row-fluid">-->
 <!--           <div class="span12">-->
 <!--           	<div class="top-bar">-->
 <!--                    <fieldset style="width:100%;"><legend>Today's Follow Up</legend>-->
 <!--                    <input type="date" name="follow_date" value ="<?php echo date('Y-m-d') ?>" />-->
	<!--					<button type="submit" name="search" class="btn-classic margin">Search</button>-->
 <!--                    </fieldset>-->
	<!--			</div>-->
	<!--		</div>-->
 <!--   </div>-->
 <!--   </form>-->
	<?php
	$where=array();
	$qry="";

	if(isset($_GET["search"]) && isset($_GET["follow_date"])!=""){
	    $where[]= " follow_date='".$_GET["follow_date"]."' ";
	} else {
	    $where[]= "follow_date < '".date('Y-m-d')."' ";
	}
// 		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
// 			$fdate=$_GET["fyear"]."/".$_GET["fmonth"]."/".$_GET["fdate"];
// 			$tdate=$_GET["tyear"]."/".$_GET["tmonth"]."/".$_GET["tdate"];
// 			$where[]=" (s.udate between '$fdate' and '$tdate') ";
// 		}

		$result=$db->getRows("SELECT * FROM enquiry where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and ".implode(" AND ",$where)." and follow_status=1 order by name");
		?>
		 <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
                    <button class="btn btn-danger" onclick="ExportToExcel('xlsx')">Export Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
                            	<table class="table" id="tbl_exporttable_to_xls">
                    <thead>
                        <tr>
                            <th width="5%">S.No</th>
                            <th>Name</th>
                            <th>Father</th> 
                            <th>Mobile</th>
                            <th>Follow By</th>
                            <th>Follow Date</th>
                            <th>Enquiry Status</th>
                            <th>Status</th>
                            <th>Time</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $full_total=0;
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                    <td><?php echo $db->getVal("select name from staff where idno='$detail[follow_staff]' "); ?></td>
                                    <td><?php echo $detail["follow_date"]; ?></td>
                                    <td><?php echo $detail["discount_mode"]; ?></td> 
                                    <td>
                                        <img src="Enquiry/warning.gif" title="Not Followed" />
                                    </td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                    <td>
                                        <img src="Enquiry/enquiry details.png" onclick="showdetails(<?php echo $detail['idno']; ?>)" title="View Details" />&ensp;&ensp;
                                        <img src="Enquiry/update-follow-up.png" onclick="showmodal(<?php echo $detail['idno']; ?>)" title="Update Follow Up" />
                                    </td>
                                </tr>
								<?php
							}?>
                           
				<?php }else{
							?><tr>
                            <td colspan="13">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="13"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>

</div>

<!-- The Details Modal -->
<div id="detailsModal" class="modal">

  <div class="modal-content">
    <span class="close">&times;</span>

        <h4 style="text-align:center;background:orange;color:white;text-align:center;">Follow Up Details</h4>
        <div id="details"></div>

  </div>

</div>


<!-- The Modal -->
<div id="myModal" class="modal">

  <div class="modal-content">
    <span class="close">&times;</span>

        <h4 style="text-align:center;background:orange;color:white;text-align:center;">Update Follow Up</h4>

        <div id="update_followup"></div>


  </div>

</div>



<style>
    /* The Modal (background) */
    .modal {
      display: none; /* Hidden by default */
      position: fixed; /* Stay in place */
      z-index: 1; /* Sit on top */
      padding-top: 10px; /* Location of the box */
      left:0;
      margin-left: 0px;
      /*top: 0;*/
      width: 100%; /* Full width */
      height: 100%; /* Full height */
      overflow: auto; /* Enable scroll if needed */
      background-color: rgb(0,0,0); /* Fallback color */
      background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    }
    
    /* Modal Content */
    .modal-content {
      background-color: #fefefe;
      margin: auto;
      padding: 20px;
      border: 1px solid #888;
      width: 50%;
    }

    /* The Close Button */
    .close {
      color: #aaaaaa;
      float: right;
      font-size: 28px;
      font-weight: bold;
    }
    
    .close:hover,
    .close:focus {
      color: #000;
      text-decoration: none;
      cursor: pointer;
    }
</style>


	<script type="text/javascript">
	$(document).ready(function(e) {
		var oTable = $('.table').dataTable( {
			"bPaginate": false,
			"bLengthChange": false,
			"bFilter": true,
			"bSort": true,
			"bInfo": true,
			"bAutoWidth": false
		});
	});

    var idno = '';

	function showdetails(id){
	    idno = id;

        $.post("Enquiry/ajax.php", { type: "followup_details", idno: idno} , function( data ) {
            $("#details").html(data);
    	});

        var modal = document.getElementById("detailsModal");

        var span = document.getElementsByClassName("close")[0];

            modal.style.display = "block";

        span.onclick = function() {
          modal.style.display = "none";
        }

        window.onclick = function(event) {
          if (event.target == modal) {
            modal.style.display = "none";
          }
        }

	}
	
	function showmodal(id){
	    idno = id;

        $.post("Enquiry/ajax.php", { type: "followup_update", idno: idno} , function( data ) {
            $("#update_followup").html(data);
    	});

        // Get the modal
        var modal = document.getElementById("myModal");
        
        // Get the button that opens the modal
        // var btn = document.getElementById("myBtn");
        
        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];
        
        // When the user clicks the button, open the modal 
        // btn.onclick = function() {
          modal.style.display = "block";
        // }
        
        // When the user clicks on <span> (x), close the modal
        span.onclick = function() {
          modal.style.display = "none";
        }
        
        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
          if (event.target == modal) {
            modal.style.display = "none";
          }
        }

	}
	
	$(".showhiderow").hide();

	function showhide(val){
	    if(val=="1"){
	        $(".showhiderow").show();
	    } else {
	        $(".showhiderow").hide();
	    }
	}
	
	
	function updateNow(){
	    var medium = document.getElementById("follow_medium").value;
	    var summary = document.getElementById("summary").value;
	    var date = document.getElementById("follow_date").value;
	    var staff = document.getElementById("follow_staff").value;
	    var status = document.getElementById("follow_status").value;

        $.post("Enquiry/ajax.php", { type: "update_followup", idno: idno, medium:medium, summary:summary, date:date, staff:staff, status:status } , function( data ) {
            location.reload();
    	});
        reload();
	}
	
        function ExportToExcel(type, fn, dl) {
            var elt = document.getElementById('tbl_exporttable_to_xls');
            var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" });
            return dl ?
                XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
                XLSX.writeFile(wb, fn || ('Pending FollowUp Report.' + (type || 'xlsx')));
        }

	</script>
    <style>
    tfoot{display: table-footer-group !important;}
	.MigrateLeftFee{width:650px !important}
    </style>