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

if ($_POST) {
    $tblinfo = array("report_due_month" => $_POST['report_due_month'], "report_resultview" => $_POST['report_resultview']);
    $db->updateAry("tbl_info", $tblinfo, " where id='1' ");

    if (is_array($_POST["allstudent"]) && count($_POST["allstudent"]) > 0) {
        $i = 0;
        foreach ($_POST["allstudent"] as $stu) {
            $idno = $_POST["idno$stu"];

            if ($idno) {
                $stuAry = array("report_view_result" => 1);
            } else {
                $stuAry = array("report_view_result" => 0);
            }
            $db->updateAry("student", $stuAry, " where idno='$stu' ");
            $i++;
        }
    }
}


/*
 if(isset($_REQUEST["sms"]) && ($_POST["msgHindi"]!="" || $_POST["msgEnglish"]!="")){
// 	$status="";$send="";$fail="";
// 	$mob=array();$alert_err=array();$mmm="";
// 	if(is_array($_POST["cat"]) && count($_POST["cat"])>0){
// 		for($i=0;$i<(count($_POST["cat"]));$i++){
// 			$phoneNumber=$_POST["cat"][$i];
// 			if($phoneNumber != ""){
			    
// 			    if($_GET["type"] == "class" || $_GET["type"]=="hostel"){
// 			        $type= "class_sms";
// 			    } else { 
// 			        $type =  $_GET["type"]; 
// 			    }
// 			}
// 		}
// 	}

// 	if($status!=""){
// 		$_SESSION["msg"]="message send successfully";
// 		redirect();
// 	}
// 	?><script>
//     $(document).ready(function(e) {
//         $('#loaders').hide()
//     });
//     </script><?php
	
// }

elseif(isset($_REQUEST["templatesms"]) ){
	$status="";$send="";$fail="";
	$mob=array();$alert_err=array();$mmm="";
	if(is_array($_POST["cat"]) && count($_POST["cat"])>0){
		for($i=0;$i<(count($_POST["cat"]));$i++){

			$Number=$_POST["cat"][$i];
$str_arr = explode (",", $Number);

for($k=0;$k<(count($str_arr));$k++)
{
    $pt = explode ("~", $str_arr[$k]);
    $pt[0];
    $pt[1];
    $ch_name=$db->getRow("select name,admissionno,password from student where mobile='".$pt[0]."' and  idno='".$pt[1]."' and  session='".$_SESSION["admin"]["session"]."' ");

	 $ch_name["admissionno"];

      	$SMSdetail="Dear Parents, Download your School App of your child(".$ch_name["name"].") from google play store ".$LinksDetails["website"]." or you can type your school name on play store \n user id-".$ch_name["admissionno"]."  \n password -".$ch_name["password"]." \n Regard  \n ".$LinksDetails["site_name"]."  ";

$_GET["type"]="class";
			$status.=sms($pt[0],$SMSdetail,$_GET["type"]."_sms");
		
 }
		}  
	}

	if($status!=""){
		$_SESSION["msg"]="message send successfully";
		redirect();
	}
	?><?php
	
}

*/

if (isset($_SESSION['msg']) && $_SESSION['msg'] != "") {
    ?>
    <embed src='media/sms_voice.mp3' width='180' height='90' loop='false' autostart='true' hidden='true'
           style="position:absolute; top:-1000px"/>
    <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
}
?>
<div id="loaders"
     style="position:fixed; z-index: 999999999; padding-top: 15%; display:none; top:0; left:0; width:100%; height:100%; opacity:0.7; background-color:#000; vertical-align:central; text-align:center">
    <img src="assets/img/load.gif"/><br/>
    <h1>Loading...</h1>
</div>


<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: 96.7% !important;
        overflow: inherit !important;
    }

    .classList {
        cursor: pointer;
        text-decoration: none;
        display: block;
        border: 1px solid #666;
        margin: 5px 0;
        padding: 5px 11px;
    }

    .selected {
        background-color: #ccc;
        color: #fff;
        font-weight: bolder;
        box-shadow: 5px 5px 16px #000;
    }

    .imgs {
        float: left;
        height: 60px;
        margin-right: 10px;
    }

    .classList span {
        color: #F00;
        font-weight: bolder;
    }

    .driverDetail {
        border: 1px solid #000;
        padding: 5px 10px;
        background-color: #ccc;
        box-shadow: 0 0 10px #2B2929;
        font-weight: bolder;
        font-size: 14px;
        margin: 10px 5px;
    }

    .cat {
        display: inline-block;
        width: 87%;
        border: 1px solid #ccc;
        padding: 5px 10px;
        box-shadow: 4px 3px 6px #ccc;
        cursor: pointer;
        margin-right: 6px;
    }

    .subcat {
        display: inline-block;
        width: 75%;
        border: 1px solid #ccc;
        padding: 5px 10px;
        box-shadow: 4px 3px 6px #ccc;
        cursor: pointer;
        margin-left: 28px;
    }

    .selected {
        box-shadow: inset 0 0 10px #ccc;
    }

    .cat .check, .subcat .check {
        float: left;
        margin: 5px 5px 5px 0;
    }
</style>
<script type="text/javascript" src="https://www.google.com/jsapi?key=AIzaSyC1uIsI9XJycYUDq1B7iMjn3jnPDx-5gkY"></script>

<script type="text/javascript">
    function checkAll(checkboxa) {
        if ($('#' + checkboxa).is(':checked')) {
            $('.' + checkboxa).attr('checked', 'checked');
            $('.' + checkboxa).parent('span').addClass('checked');
        } else {
            $('.' + checkboxa).parent('span').removeClass('checked');
            $('.' + checkboxa).removeAttr('checked');
        }
    }
</script>
<form method="post" action="" enctype="multipart/form-data">
    <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Report Setting</h3>
                <button style="float:right; margin-top:5px" class="btn btn-primary" type="submit">Save</button>
            </div>

            <?php
            $tbldata = $db->getRow("select report_due_month, report_resultview from tbl_info");
            $currentmonth = $tbldata['report_due_month'];
            ?>
            <div class="well">
                <table class="table">
                    <tr>
                        <td>Select Dues Month</td>
                        <td>
                            <select name="report_due_month" id="report_due_month" STYLE="width: 250px;">
                                <option value="">Month</option>
                                <?php
                                    // for ($m = 1; $m <= 12; $m++) {
                                    //     $newDate = date("Y")."-".$m."-1";
                                    //     $month = date("F", strtotime($newDate));
                                    //     $selected = "";
                                    //     if ($currentmonth == $m) $selected = " selected ";
                                    //     echo "<option $selected value='$m'>$month</option>";
                                    // }
                                $allmonths = $db->getRows("select * from months");

                                    foreach($allmonths as $mn){
                                        $checked = "";
                                    	    if($currentmonth == $mn["month"] ){
                						        $checked="selected='selected'";
                                    	    }
                                	    echo "<option value='".$mn['month']."' $checked>$mn[name]</option>";
                        	        }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Show result to:</td>
                        <td>
                            <input type="radio" name="report_resultview"
                                   value="1" <?php if ($tbldata['report_resultview'] == '1') echo "checked"; ?>> Show result to
                            all students </br>
                            <input type="radio" name="report_resultview"
                                   value="2" <?php if ($tbldata['report_resultview'] == '2') echo "checked"; ?>> Clear dues
                            students </br>
                            <input type="radio" name="report_resultview"
                                   value="3" <?php if ($tbldata['report_resultview'] == '3') echo "checked"; ?>> Clear dues
                            students + Selected Students</br>
                            <input type="radio" name="report_resultview"
                                   value="4" <?php if ($tbldata['report_resultview'] == '4') echo "checked"; ?>> Only selected
                            Students</br>
                            <input type="radio" name="report_resultview"
                                   value="5" <?php if ($tbldata['report_resultview'] == '5') echo "checked"; ?>> Don't show to
                            any student </br>
                        </td>
                    </tr>
                </table>
            </div>

            <div class="well">

                <div class="span6" style="display:inline-block;">
                    <div class="top-bar">
                        <h3><i class="icon-cog"></i><input type="text" id="filter" style="float:right; margin-left:30px"
                                                           placeholder="Search Here"/><label
                                    style="float:right; margin-left:10px;"
                                    for="<?php echo $checkbox; ?>">All <?php echo ucfirst($_GET["type"]); ?></label>
                            <?php $allclass = $db->getRows("select * from class where school_id='" . $_SESSION["admin"]["school_id"] . "' and status=1");
                            $allsection = $db->getRows("select * from section");
                            ?>
                            <input onclick="fetchByClass(<?php echo count($allclass); ?>,<?php echo count($allsection); ?>,'allclass')"
                                   class="check" type="checkbox" value="1" id="Class"/>
                        </h3>
                    </div>

                    <div class="well no-padding"
                         style="max-height: 848px;overflow-y: auto !important;overflow-x: hidden !important;">
                        <div class="control-group">
                            <?php
                            $class = $db->getRows("select * from class where school_id='" . $_SESSION["admin"]["school_id"] . "' and status=1");
                            if (is_array($class) && count($class) > 0) {
                                $i = 0;
                                foreach ($class as $cla) {
                                    $number = array();
                                    $i++;
                                    $mobile = $db->getRows("select mobile from student where school_id='" . $_SESSION["admin"]["school_id"] . "' and class='" . $cla["class"] . "' and  session='" . $_SESSION["admin"]["session"] . "' and status = 1");
                                    if (is_array($mobile) && count($mobile) > 0) {
                                        foreach ($mobile as $mob) {
                                            $number[] = $mob["mobile"];
                                        }
                                    }
                                    $sections = $db->getRows("select * from section");
                                    ?>
                                    <div class="subcat">

                                        <input class="check Class" type="checkbox"
                                               value="<?php echo implode(",", $number); ?>" id="cat<?php echo $i; ?>"
                                               onclick="fetchByClass(<?php echo count($class); ?>, <?php echo count($sections); ?>)"
                                               data-class="<?php echo $cla["class"]; ?>"/>
                                        <label for="cat<?php echo $cla["id"]; ?>">
                                    <span style="width:50px;position:absolute;">
                                        <?php echo $cla["class"] ?>
                                    </span>
                                            <span style="position:relative;margin-left:50px;">
                                <?php $s = 1;
                                foreach ($sections as $sec) {
                                    $allstudent = $db->getVal("select count(idno) from student where class='" . $cla["class"] . "' and section='" . $sec['name'] . "' and  session='" . $_SESSION["admin"]["session"] . "' and school_id='" . $_SESSION["admin"]["school_id"] . "' and status = 1");
                                    if ($allstudent > 0) {
                                        echo " <input type='checkbox' value='$sec[name]' id='sec_" . $i . "_" . $s . "' onclick='fetchByClass(" . count($class) . ", " . count($sections) . ")' /> $sec[name] &nbsp";

                                        $s++;
                                    }
                                }
                                ?>
                                </span>
                                        </label>
                                    </div>
                                <?php }
                            }
                            ?>
                        </div>

                    </div>

                </div>

                <!--<div class="span6">-->

                <!--<div class="top-bar">-->
                <!--                <h3>Enter SMS </h3>-->
                <!--            </div>-->

                <!--<div class="well no-padding">-->
                <!--<div class="control-group">-->
                <!--	<label class="control-label" for="inputInline"><i class="icon-edit"></i> SMS Contentd -->
                <!--                     <input type="hidden"  name="changer" id="changer" value="hindi" />-->
                <!--                      </label>-->
                <!--                      <div class="controls" id="english">-->
                <!--	<textarea name="msgEnglish" id="englishtext" maxlength="<?php echo $LinksDetails["perpage"]; ?>" rows="3" class="span12"></textarea>-->
                <!--                      <p id="englishLeft"></p>-->
                <!--	</div>-->
                <!--</div>-->

                <!--<div class="form-actions">-->
                <!--	<button type="submit" name="sms" value="sms" onclick="$('#loaders').show()" class="btn btn-primary"> Send</button>-->
                <!--	<button type="reset" class="btn"> Cancel</button>-->
                <!--</div>-->


                <!--</div>-->
                <!--</div>-->

                <div class="span6">
                    <div class="top-bar">
                        <h3>Student List</h3>
                    </div>
                    <div class="well no-padding">
                        <div id="studentList"></div>
                    </div>
                </div>

            </div>
        </div>

    </div>
</form>

<script>
    function fetchByClass(totalclass, totalsection, type = '') {
        var classes = [];

        if (type == 'allclass') {
            if ($('#Class').is(':checked')) {
                $(".Class").prop("checked", true);
            } else {
                $(".Class").prop("checked", false);
            }
        }

        for (var i = 1; i <= totalclass; i++) {
            if (document.getElementById("cat" + i).checked) {
                var cls = document.getElementById("cat" + i).getAttribute("data-class");
                var sectest = [];
                for (var j = 1; j <= totalsection; j++) {
                    if (document.getElementById("sec_" + i + "_" + j)) {
                        if (document.getElementById("sec_" + i + "_" + j).checked) {
                            var sec = document.getElementById("sec_" + i + "_" + j).value;
                            sectest.push(sec);
                        }
                    }
                }
                classes.push({class: cls, section: sectest});
            }
        }
        // alert(JSON.stringify(classes));
        $.post("Notice/ajax.php", {type: "get_report_list", classAry: classes}, function (data) {
            $('#studentList').html(data);
            // alert(data);
        });

    }


    function checkStudents() {
        if (document.getElementById("checkall").checked) {
            $(".check-students").prop("checked", true);
        } else {
            $(".check-students").prop("checked", false);
        }
    }


</script>