<?php
if(isset($_SESSION["first"]) && $LinksDetails["sound"]!=""){
	?><embed src='<?php echo $LinksDetails["sound"] ?>' width='180' height='90' loop='false' autostart='true' hidden='true' style="position:absolute; top:-1000px" /><?php
	unset($_SESSION["first"]);
}//echo $LinksDetails["sound"];
?>
<center>
<script>
$(document).ready(function(e) {
<?php 
// $files1 = array("Student","Faculty","Library","Account","Attendance","TimeTable","Hostel","Transport","Promote","sms","TC","Exam","ExamCBSE","OnlineExam","cms","Enquiry","Notice","Budget","Payroll","HR","Reception");
$files1 = array("Faculty","Attendance","Promote","sms","Exam","Notice","Payroll","HR","Reception");
foreach($files1 as $images)
{
	$per=checkPermission($images,$_SESSION["admin"]["roll"]);
	if($per=="none"){
		?>$(".<?php echo $images; ?>").remove();<?php
	}
}
 ?>
 });
</script>
<style>
    .leftdiv{
        width:60%;
        float:left;
        /*position:absolute;*/
        /*border:solid;*/
    }
    .leftdiv .span3{
        width:150px;
        display:inline-block;
    }
    .rightdiv{
        width:38%;
        float:right;
        /*border:solid;*/
    }
</style>

<div class="row-fluid">

<div class="leftdiv">

<!-- Information Boxes: Users Registered --> 
<!--<div class="span3 well infobox Student" style="cursor:pointer" onClick="window.location='./?loginas=Student'">-->
<!--<div class="span3 well infobox Student" style="cursor:pointer;background:orange;margin-left:20px;" onClick="window.location='./?src=Student&page_id=make_admission'">-->
<!--    <i class="icon-6x icon-user"></i>-->
<!--    <div class="text-center">-->
<!--        <b class="huge">Student</b><br>-->
<!--        <span class="caps muted">Enter</span>-->
<!--    </div>-->
<!--</div>-->
<!-- / Information Boxes: Users Registered -->

<!-- Information Boxes: Applications -->
<div class="span3 well infobox Faculty" style="cursor:pointer;background:skyblue;margin-left:20px;" onClick="window.location='./?src=Faculty&page_id=staff'">
    <i class="icon-6x icon-user-md"></i>
    <div class="text-center">
        <b class="huge">Faculty</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>
<!-- / Information Boxes: Applications -->

<!-- Information Boxes: Images -->
<div class="span3 well infobox Attendance" style="cursor:pointer;background:navy;" onClick="window.location='./?src=Attendance&page_id=manual_face_attendance'">
    <i class="icon-6x icon-calendar"></i>
    <div class="text-center">
        <b class="huge">Attendance</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>
<!-- / Information Boxes: Images -->

<!-- Information Boxes: Images -->
<div class="span3 well infobox Payroll" style="cursor:pointer;background:crimson;" onClick="window.location='./?src=Payroll&page_id=salary_components'">
    <i class="icon-6x  icon-edit"></i>
    <div class="text-center">
        <b class="huge">Payroll</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>
<!-- / Information Boxes: Images -->

<!-- Information Boxes: Images -->
<div class="span3 well infobox sms" style="cursor:pointer;background:orange;" onClick="window.location='./?src=sms&page_id=dashboard'">
    <i class="icon-6x icon-mobile-phone"></i>
    <div class="text-center">
        <b class="huge">sms/voice</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>
<!-- / Information Boxes: Images -->


<!--</div>-->
<!--<div class="row-fluid">-->
<!-- Information Boxes: Images -->
<div class="span3 well infobox Exam" style="cursor:pointer;background:brown;" onClick="window.location='./?src=Exam&page_id=student_portal'">
    <i class="icon-6x  icon-edit"></i>
    <div class="text-center">
        <b class="huge">Portal</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>
<!-- / Information Boxes: Images -->
<!-- Information Boxes: Images -->
<div class="span3 well infobox ExamCBSE hide" style="cursor:pointer;background:green;" onClick="window.location='./?src=ExamCBSE&page_id=marks'">
    <i class="icon-6x  icon-edit"></i>
    <div class="text-center">
        <b class="huge">Exam</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>

<div class="span3 well infobox Notice" style="cursor:pointer;background:red;" onClick="window.location='./?src=Notice&page_id=calendar'">
    <i class="icon-6x  icon-copy"></i>
    <div class="text-center">
        <b class="huge">App Data</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>

<!-- Information Boxes: Images -->
<div class="span3 well infobox HR" style="cursor:pointer;background:#B833FF;" onClick="window.location='./?src=HR&page_id=job'">
    <i class="icon-6x icon-mobile-phone"></i>
    <div class="text-center">
        <b class="huge">HR</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>
<!-- / Information Boxes: Images -->

<!-- Information Boxes: Images -->
<div class="span3 well infobox Reception" style="cursor:pointer;background:#FF3364;" onClick="window.location='./?src=Reception&page_id=appointment'">
    <i class="icon-6x icon-mobile-phone"></i>
    <div class="text-center">
        <b class="huge">Front Office</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>
<!-- / Information Boxes: Images -->

<!-- Information Boxes: Images -->
<div class="span3 well infobox website hide" style="cursor:pointer;background:#FF6833;" onClick="window.location='./?src=website&page_id=slider'">
    <i class="icon-6x icon-mobile-phone"></i>
    <div class="text-center">
        <b class="huge">Website</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>
<!-- / Information Boxes: Images -->

<!--</div>-->

<!--<div class="row-fluid">--> 


<!-- Information Boxes: Images --> 
<!--<div class="span3 well infobox Account" style="cursor:pointer" onClick="window.location='./?src=Budget&page_id=budget'">-->
<!--    <i class="icon-6x icon-mobile-phone"></i>-->
<!--    <div class="text-center">-->
<!--        <b class="huge">Budget</b><br>-->
<!--        <span class="caps muted">Enter</span>-->
<!--    </div>-->
<!--</div>-->


<?php if($_SERVER["HTTP_HOST"] == "bps.savarnacloud.com"){ ?>

<div class="span3 well infobox Account" style="cursor:pointer" onClick="window.location='./?src=ERP&page_id=sales_person'">
    <i class="icon-6x icon-bar-chart"></i>
    <div class="text-center"> 
        <b class="huge">ERP</b><br>
        <span class="caps muted">Enter</span>
    </div>
</div>

<?php } ?>
<!-- / Information Boxes: Images -->

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>



<?php $permission = $db->getRow("select * from tbl_privilages where page_name='StudentStrengthGraph' and roll_id='".$_SESSION["admin"]["roll"]."' ");
        if($permission['a']==1){  ?>
<div class="span12" style="background:white;width:650px;margin-top:20px;">
    <?php
    $students = array();
    $allclass = $db->getRows("select class from class");
    $totalstrength = 0;
    $totalmale = 0;
        foreach($allclass as $cls){
            $totalstudent   = $db->getVal("select count(idno) from student where class='$cls[class]' and status='1' and session='".$_SESSION['admin']['session']."' ");
            $male           = $db->getVal("select count(idno) from student where class='$cls[class]' and status='1' and gender='male' and session='".$_SESSION['admin']['session']."' ");
            $female         = $db->getVal("select count(idno) from student where class='$cls[class]' and status='1' and gender='female' and session='".$_SESSION['admin']['session']."' ");
            if($totalstudent>0){
                array_push($students,["class"=>$cls['class'], "0"=>$cls['class'], "total"=>$totalstudent, "1"=> $totalstudent, "male"=>$male, "2"=>$male, "female"=>$female, "3"=>$female ]);
            }
            $totalstrength+=$totalstudent;
            $totalmale+=$male; $totalfemale+=$female;
        }
    $oldstudent   = $db->getVal("select count(idno) from student where stype='old' and status='1' and session='".$_SESSION['admin']['session']."' ");
    $newstudent   = $db->getVal("select count(idno) from student where stype='new' and status='1' and session='".$_SESSION['admin']['session']."' ");
    ?>
<script>
        var my_2d = <?php echo json_encode($students); ?>
</script>
<h4 style="background:crimson;color:white;margin:0px;">STAFF STRENGTH</h4>
<label style="float:left;width:33%;">Total Students - <?php echo $totalstrength; ?> &emsp;|&emsp; </label>
<label style="float:left;width:33%;">New Students - <?php echo $newstudent; ?> &emsp;|&emsp; </label>
<label style="float:left;width:33%;">Old Students - <?php echo $oldstudent; ?> &emsp;|&emsp; </label>
<label style="float:left;width:33%;">Male - <?php echo $totalmale; ?> &emsp;|&emsp; </label>
<label style="float:left;width:33%;">Female - <?php echo $totalfemale; ?></label>

<div id="chart_div" style="margin-left:0px;margin-top:35px;"></div>

<script type="text/javascript">

      // Load the Visualization API and the corechart package.
      google.charts.load('current', {packages: ['corechart', 'bar']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Class');
        data.addColumn('number', 'Total'); 
		data.addColumn('number', 'Male');
		data.addColumn('number', 'Female');
        for(i = 0; i < my_2d.length; i++)
    data.addRow([my_2d[i][0], parseInt(my_2d[i][1]),parseInt(my_2d[i][2]),parseInt(my_2d[i][3])]);
       var options = {
          title: 'Student Strength',
        //   hAxis: { titleTextStyle: {color: '#333'}},
          vAxis: {minValue: 0}, 
		  height:700,
		  width:650,
        };

var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
        chart.draw(data, options);		
       }
</script>

</div>
<?php } ?>


</div>
<style>
    .canvasjs-chart-credit {display:none;}
</style>
    
<div class="rightdiv">

    <?php $permission = $db->getRow("select * from tbl_privilages where page_name='TeacherAttendanceGraph' and roll_id='".$_SESSION["admin"]["roll"]."' ");
        if($permission['a']==1){  ?>
    <div style="box-shadow:0px 0px 8px #333;">
        <h4 style="background:crimson;color:white;padding:5px;margin:0px;">Today's Teacher Attendance</h4>

        <?php
			    $fdate = date('Y')."-".date('m')."-".date('d');
                $todate = date('Y-m-d', strtotime("+1 day"));

                $records = $db->getRows("SELECT * FROM staff WHERE session='".$_SESSION["admin"]["session"]."' and status='1' ");
                $total_teachers = count($records);
                $teacher_present = 0;
                $i=0; 
                foreach($records as $rec){ $i++;
                    $result = $db->getRow("Select * from attendance_new where teacher_id='$rec[idno]' and (timestamp>='$fdate' and timestamp<='$todate') and session='".$_SESSION["admin"]["session"]."' and att_type='IN' ");
                        if($result['att_type']=="IN"){
                            $teacher_present++;
                        }
                }
            $teacher_absent = $total_teachers-$teacher_present;
                $dataPoints2 = [
                                ["label" => "Present", "y"=>$teacher_present],
                                ["label" => "Absent", "y"=>$teacher_absent],
                    ];
            ?>

            <div>
            <script>
                function teacherattend() {
                var staff = new CanvasJS.Chart("chartContainer3", {
                	animationEnabled: true,
                	data: [{
                		type: "pie",
                		yValueFormatString: "#,##0.00",
                		indexLabel: "{label} ({y})",
                		dataPoints: <?php echo json_encode($dataPoints2, JSON_NUMERIC_CHECK); ?>
                	}]
                });
                staff.render();
                 
                }
            </script>
            
            <div id="chartContainer3" style="height: 370px; width: 100%;"></div>

                <table class="table" border="1">
                    <tr>
                        <td>
                            <label style="color:red;"> Teachers: <?php echo $total_teachers; ?></label>
                        </td>
                        <td>
                            <label style="color:green;"> Present: <?php echo $teacher_present; ?></label>
                        </td>
                        <td>
                            <label style="color:brown;"> Absent: <?php echo $teacher_absent; ?></label>
                        </td>
                    </tr>
                </table>

            </div>

    </div>
    <?php } ?>


    <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>

</div>

</div>



</center>

<script>
    complete();

    function monthly(){
        var month = $("#month").val();
        var pay = rec = dis = rem = "";
        $.post("ajax.php", {type: "getmonthly", month: month} , function( data ){
			var ary = JSON.parse(data);
			pay = ary['Payable'];
			rec = ary['Received'];
			dis = ary['Discount'];
			rem = ary['Remaining'];
            $("#payable").html(pay);
            $("#received").html(rec);
            $("#discount").html(dis);
            $("#remaining").html(rem);
            
            var type = 'Monthly Outstanding Report';
            
    		drawChart(pay, rec, dis, rem, type);

		});

    }
    
    function complete(){
        var month = $("#month").val();
        var pay = rec = dis = rem = rawdata = "";
        $.post("ajax.php", {type: "getcomplete", month: month} , function( data ){
			var ary = JSON.parse(data);

			pay = ary['Payable'];
			rec = ary['Received'];
			dis = ary['Discount'];
			rem = ary['Remaining'];
            $("#payable").html(pay);
            $("#received").html(rec);
            $("#discount").html(dis); 
            $("#remaining").html(rem);
            
            var type = 'Complete Outstanding Report';

            rawdata = [{"label":"Received", "y":rec},{"label":"Discount", "y":dis},{"label":"Remaining", "y":rem}];
    		totaloutstanding(rawdata);

		});

    }

    $(document).ready(function() {
        // studentattend();
        teacherattend();
    });

    function classOutstanding1(){
        var month = $("#month1").val();
        $.ajax({
               method: 'POST',
               url: 'ajax.php?type=class_outstanding1',
               data : {month:month},
               beforeSend: function()
            {
                $("#error").fadeOut(0);
                $("#due-div").html('<img src="uploads/ajax-loader.gif" style="margin:20px;width:50px;height:50px;" />   Loading ...');
            },
            success: function( response ){
                $("#due-div").hide(); 
                $("#class_dues1").html(response);
            },
            error: function(xhr, desc, err){
               console.log(err);
            }
        });
    }

        
</script>



