<?php
include("../db.php");
$ch=$_REQUEST["type"];
if($ch=="getAttandencCalender"){
	$aryList=$db->getRows("select * from staff where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by name");
	if(is_array($aryList) && count($aryList)>0)
	{
		$mn=date('m',strtotime($_REQUEST["year"]."-".$_REQUEST["month"]."-1"));$y=0;
		$y=$_REQUEST["year"];
		$maxDays=date('t',strtotime($y."-".$mn."-1"));
		?>
         <style>table tr td{border:3px groove #CC9;}</style>
        <table style="margin:20px;display:inline-table">
            <thead>
                <tr>
                    <th>S.No</th>
                    <th colspan="1">Name</th>
                   			 <?php for($i=1; $i<= $maxDays;$i++){ $day=date('D',strtotime($y."-".$mn."-".$i)); ?>
					<th> <?php echo $day; ?> </th>
							<?php } ?>
                    
                </tr>
            </thead>
            
            <tbody>
            <?php $ijk=0;
			 foreach($aryList as $clist){ $i++; $ijk++;
            $aryPgAct["id"]=$clist['idno'];
          
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                    <td><?php echo $ijk; ?></td>
                    <td><?php echo ucfirst($clist["name"]); ?></td>
                   <?php for($i=1; $i<= $maxDays;$i++){ $day=date('D',strtotime($y."-".$mn."-".$i)); ?>
                    <td>
                    <?php $ColorClass="success";
					$chkHoli=$db->getVal("select status from staff_holiday where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$y."-".$mn."-".$i."' and teacher='".$clist['idno']."'");
				//	echo $ss="select status from holiday where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$y."-".$mn."-".$i."' and teacher='".$clist['idno']."'";
					$chkAtt=$db->getVal("select status from attandenc where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$y."-".$mn."-".$i."' and type='1' and idno='".$clist["idno"]."'");
					//echo $db->getLastQuery();
					if(strtolower($day)=="sun") $ColorClass="danger sunday";
					elseif($chkHoli===1) $ColorClass="danger holiday";
					elseif($chkAtt===0) $ColorClass="default absent";
					
					?>
                    <span type="button" onclick="addAttandenc('<?php echo $clist["idno"] ?>','<?php echo $i ?>',this)" class="btn btn-<?php echo $ColorClass; ?>">
					<?php echo $i; ?>
                    </span></td>
                    <?php } ?>
                </tr>
            <?php } ?>
            </tbody>
           
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
}
elseif($ch=="addAttandenc"){
	$date=$_REQUEST["year"]."-".$_REQUEST["month"]."-".$_REQUEST["date"];
	
	$arr=explode("-",$date);
	$m=$arr["1"];
	$month =  date("F", mktime(0, 0, 0, $m));
	$dataAry=array( "date"=>$date,
					"idno"=>$_REQUEST["id"],
					"session"=>$_SESSION["admin"]["session"],
					"month"=>$month,
					"status"=>$_REQUEST["status"],
					"school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"],
					"type"=>"1"
	);
	$db->insertAry("attandenc",$dataAry);
	if($_REQUEST["status"]=="0"){
		sms(mydetail("mobile",$_REQUEST["id"],"staff"),"Dear ".mydetail("name",$_REQUEST["id"],"staff").", You are absent on ".$date,"faculty_attandance");
	}
	echo "Attandence Add successfully".$db->getErMsg();
}
elseif($ch=="removeAttandenc"){
	$date=$_REQUEST["year"]."-".$_REQUEST["month"]."-".$_REQUEST["date"];
	$db->delete("attandenc","where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$date."' and idno='".$_REQUEST["id"]."' and status=0 and type=1");
	//echo $db->getLastQuery();
	echo "Attandence remove successfully";
}

/*
///////////////////////////////////////////Student section//////////////////////////////////////////////
*/
elseif($ch=="getAttandencCalenderStudent"){

	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")$where="and section='".$_REQUEST["section"]."'";

		$sturoll=$db->getval("SELECT max(fincome) from student WHERE fincome IS NOT NULL and school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status=1 $where");
		//echo $ss="SELECT max(fincome) from student WHERE fincome IS NOT NULL and school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status=1 $where";
	$detail=$db->getVal("SELECT max(fincome) from student WHERE fincome IS NOT NULL and school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status=1 $where");	
//	print_r($sturoll);
if($sturoll)
{
    echo '1';
	$aryList=$db->getRows("select * from student where  class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status=1 and  school_id='".$_SESSION["admin"]["school_id"]."'  $where order by LENGTH(fincome), fincome");
//echo '1';
//echo $ss="select * from student where   class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status=1 and school_id='".$_SESSION["admin"]["school_id"]."' $where order by LENGTH(fincome), fincome";
}

else
{
 
echo '2';	
	$aryList=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status=1 $where order by name");
}
	
	
	
	if(is_array($aryList) && count($aryList)>0)
	{$ijk=0;
		$mn=date('m',strtotime($_REQUEST["year"]."-".$_REQUEST["month"]."-1"));$y=0;
		$y=$_REQUEST["year"];
		$maxDays=date('t',strtotime($y."-".$mn."-1"));
		
		?>
        <style>table tr td{border:3px groove #CC9;}</style>
        <table style="margin:20px">
            <thead>
                <tr>
                	<th>S.No</th>
                	<th>Roll.No</th>
                    <th>Name</th>
                    <?php for($i=1; $i<= $maxDays;$i++){ $day=date('D',strtotime($y."-".$mn."-".$i)); ?>
							<th><?php echo $day; ?></th>
					<?php } ?>
                    <th></th>
                </tr>
            </thead>
            
            <tbody>
            <?php foreach($aryList as $clist){ $i++;$ijk++; 
            $aryPgAct["id"]=$clist['idno'];
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                	<td><?php echo $ijk; ?></td>
                		<td><?php echo $clist["fincome"] ?></td>
                    <td colspan="1"><?php echo ucfirst($clist["name"]) ?></td>
                   <?php for($i=1; $i<= $maxDays;$i++){ $day=date('D',strtotime($y."-".$mn."-".$i)); ?>
                    <td>
                    <?php $ColorClass="success";
					$chkHoli=$db->getVal("select status from holiday where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST['class']."' and date='".$y."-".$mn."-".$i."'");
					$chkAtt=$db->getVal("select status from attandenc where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$y."-".$mn."-".$i."' and type='2' and idno='".$clist["idno"]."'");
					$chkLeave=$db->getVal("select status from attandenc where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$y."-".$mn."-".$i."' and type='3' and idno='".$clist["idno"]."'");
					
					//echo $db->getLastQuery();
					if(strtolower($day)=="sun") $ColorClass="danger sunday";
					elseif($chkHoli===1) $ColorClass="danger holiday";
					elseif($chkAtt===0) $ColorClass="default absent";
					elseif($chkLeave===0) $ColorClass="default late";
				// 	echo $chkAtt;
					?>
                     <span type="button" onclick="addAttandenc('<?php echo $clist["idno"] ?>','<?php echo $i ?>',this)" class="btn btn-<?php echo $ColorClass; ?>">
					<?php echo $i; ?>
                    </span></td>
                    <?php } ?>
                </tr>
            <?php } ?>
            </tbody>
           
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
}
elseif($ch=="getAttandencCalenderStudent_late"){
	$aryList=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status=1 order by name");
	if(is_array($aryList) && count($aryList)>0)
	{$ijk=0;
		$mn=date('m',strtotime($_REQUEST["year"]."-".$_REQUEST["month"]."-1"));$y=0;
		$y=$_REQUEST["year"];
		$maxDays=date('t',strtotime($y."-".$mn."-1"));
		
		?>
        <style>table tr td{border:3px groove #CC9;}</style>
        <table style="margin:20px">
            <thead>
                <tr>
                	<th>S.No</th>
                    <th>Name</th>
                    <?php for($i=1; $i<= $maxDays;$i++){ $day=date('D',strtotime($y."-".$mn."-".$i)); ?>
							<th><?php echo $day; ?></th>
					<?php } ?>
                    <th></th>
                </tr>
            </thead>
            
            <tbody>
            <?php foreach($aryList as $clist){ $i++;$ijk++; 
            $aryPgAct["id"]=$clist['idno'];
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                	<td><?php echo $ijk; ?></td>
                    <td colspan="1"><?php echo ucfirst($clist["name"])."<span style='color:red;'>(".$clist["fname"].")"; ?></td>
                   <?php for($i=1; $i<= $maxDays;$i++){ $day=date('D',strtotime($y."-".$mn."-".$i)); ?>
                    <td>
                    <?php $ColorClass="success";
					$chkHoli=$db->getVal("select status from holiday where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$y."-".$mn."-".$i."'");
					$chkAtt=$db->getVal("select status from attandenc where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$y."-".$mn."-".$i."' and type='2' and idno='".$clist["idno"]."'");
					$chkLeave=$db->getVal("select status from attandenc where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$y."-".$mn."-".$i."' and type='3' and idno='".$clist["idno"]."'");
					
					//echo $db->getLastQuery();
					if(strtolower($day)=="sun") $ColorClass="danger sunday";
					elseif($chkHoli=="1") $ColorClass="danger holiday";
					elseif($chkAtt=="0") $ColorClass="default absent";
					elseif($chkLeave=="0") $ColorClass="default leave";
					
					?>
                     <span type="button" onclick="addAttandenc_late('<?php echo $clist["idno"] ?>','<?php echo $i ?>',this)" class="btn btn-<?php echo $ColorClass; ?>">
                     
					<?php echo $i; ?>
                    </span></td>
                    <?php } ?>
                </tr>
            <?php } ?>
            </tbody>
           
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
}
elseif($ch=="addAttandencStudent"){
	$date=$_REQUEST["year"]."-".$_REQUEST["month"]."-".$_REQUEST["date"];
	$arr=explode("-",$date);
	$m=$arr["1"];
	
		$de= $db->getRow("select fincome, class,section from student where idno ='$_REQUEST[id]'");
	$roll= $de['fincome'];
	$cl=  $de['class'];
	$s = $de['section'];
	$month =  date("F", mktime(0, 0, 0, $m));
	$dataAry=array( "date"=>$date,
					"idno"=>$_REQUEST["id"],
					"month"=>$month,
					"status"=>$_REQUEST["status"],
					"school_id"=>$_SESSION["admin"]["school_id"],"session"=>$_SESSION["admin"]["session"],"added_by"=>$_SESSION["admin"]["uid"],
					"type"=>"2"
	);
	$db->insertAry("attandenc",$dataAry);
	
	//	sms(mydetail("mobile",$_REQUEST["id"],"student"),"Dear ".mydetail("fname",$_REQUEST["id"],"student").", Your Child(".mydetail("name",$_REQUEST["id"],"student").") is absent in school on ".date("d-m-Y",strtotime($date))." regards ".$LinksDetails["site_name"],"student_attandance");
	
			sms(mydetail("mobile",$_REQUEST["id"],"student"),"Dear ".mydetail("fname",$_REQUEST["id"],"student").", Your Child(".mydetail("name",$_REQUEST["id"],"student").") rollno-$roll class-$cl-$s is absent in school on ".date("d-m-Y",strtotime($date))." regards ".$LinksDetails["site_name"],"student_attandance");

	echo "Attandenc add successfully";

 
 
 
 
  $session =$_SESSION["admin"]["session"];
$msg ="Dear ".mydetail("fname",$_REQUEST["id"],"student").", Your Child(".mydetail("name",$_REQUEST["id"],"student").") rollno-$roll class-$cl-$s is absent in school on ".date("d-m-Y",strtotime($date))." regards ".$LinksDetails["site_name"];
$stu_id = $_REQUEST["id"];
 $set_title ="Attendance";

// Enabling error reporting
error_reporting(-1);
ini_set('display_errors', 'On');

$upOne = realpath(__DIR__ . '/..');

 $upOne2 = realpath(__DIR__ . '/..'.'api_new/firebase/push.php');



require_once  $upOne.'/api_new/firebase/firebase.php';
require_once  $upOne.'/api_new/firebase/push.php';

$firebase = new Firebase();
$push = new Push();
$tokenlist=$db->getRows("SELECT idno,name,fcm_token from student where idno='$stu_id' and  session='$session' and status='1' ");
//echo $ss="SELECT name,fcm_token from student where class='$class' and session='$session' and status='1' ";


foreach ($tokenlist as $value) {
  

             $stu_id =  $value['idno'];
             $target_user_name =  $value['name'];
            $fb_token =  $value['fcm_token'];
      

       

        if (strlen($fb_token) > 0 ) {
            // optional payload
            $payload = array();
            $payload['name'] = $target_user_name;
            $payload['msg'] = $msg; // whether to include to image or not
             $payload['stu_id'] = $stu_id;
            $include_image = TRUE;
            $push->setTitle($set_title);
            $push->setMessage($msg);
            if ($include_image) {
                $push->setImage('https://api.androidhive.info/images/minion.jpg');
            } else {
                $push->setImage('');
            }
            $push->setIsBackground(FALSE);
            $push->setPayload($payload);
            $json = '';
            $response = '';
            $json = $push->getPush();
       
            $response = $firebase->send($fb_token, $json);
        }


    //}

}
	   
    
    
}
elseif($ch=="removeAttandencStudent"){
    
  				 	$class=$db->getVal("select class from student where idno='".$_REQUEST["id"]."'");
  
    
	$date=$_REQUEST["year"]."-".$_REQUEST["month"]."-".$_REQUEST["date"];
			$db->delete("attandenc","where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$date."' and idno='".$_REQUEST["id"]."' and status=0 and type=2");
	echo "Attandenc Remove successfully";
		sms(mydetail("mobile",$_REQUEST["id"],"student"),"Dear ".mydetail("fname",$_REQUEST["id"],"student").", sorry for the inconvenience, Your Child(".mydetail("name",$_REQUEST["id"],"student").") is Present in school of class '".$class."'  on ".date("d-m-Y",strtotime($date))." regards ".$LinksDetails["site_name"],"student_attandance");

	//echo $db->getLastQuery();
$session =$_SESSION["admin"]["session"];
$msg ="Dear ".mydetail("fname",$_REQUEST["id"],"student").", sorry for the inconvenience, Your Child(".mydetail("name",$_REQUEST["id"],"student").") is Present in school of class '".$class."'  on ".date("d-m-Y",strtotime($date))." regards ".$LinksDetails["site_name"];
$stu_id = $_REQUEST["id"];
 $set_title ="Attendance";

// Enabling error reporting
error_reporting(-1);
ini_set('display_errors', 'On');

$upOne = realpath(__DIR__ . '/..');

 $upOne2 = realpath(__DIR__ . '/..'.'api_new/firebase/push.php');



require_once  $upOne.'/api_new/firebase/firebase.php';
require_once  $upOne.'/api_new/firebase/push.php';

$firebase = new Firebase();
$push = new Push();
$tokenlist=$db->getRows("SELECT idno,name,fcm_token from student where idno='$stu_id' and  session='$session' and status='1' ");
//echo $ss="SELECT name,fcm_token from student where class='$class' and session='$session' and status='1' ";


foreach ($tokenlist as $value) {
  

             $stu_id =  $value['idno'];
             $target_user_name =  $value['name'];
            $fb_token =  $value['fcm_token'];
      

       

        if (strlen($fb_token) > 0 ) {
            // optional payload
            $payload = array();
            $payload['name'] = $target_user_name;
            $payload['msg'] = $msg; // whether to include to image or not
             $payload['stu_id'] = $stu_id;
            $include_image = TRUE;
            $push->setTitle($set_title);
            $push->setMessage($msg);
            if ($include_image) {
                $push->setImage('https://api.androidhive.info/images/minion.jpg');
            } else {
                $push->setImage('');
            }
            $push->setIsBackground(FALSE);
            $push->setPayload($payload);
            $json = '';
            $response = '';
            $json = $push->getPush();
       
            $response = $firebase->send($fb_token, $json);
        }


    //}

}   
    
    
}
elseif($ch=="addAttandencStudent_late"){
	$date=$_REQUEST["year"]."-".$_REQUEST["month"]."-".$_REQUEST["date"];
	$arr=explode("-",$date);
	$m=$arr["1"];
	$month =  date("F", mktime(0, 0, 0, $m));
	$dataAry=array( "date"=>$date,
					"idno"=>$_REQUEST["id"],
					"month"=>$month,
					"status"=>$_REQUEST["status"],
					"school_id"=>$_SESSION["admin"]["school_id"],"session"=>$_SESSION["admin"]["session"],"added_by"=>$_SESSION["admin"]["uid"],
					"type"=>"3"
	);
	$db->insertAry("attandenc",$dataAry);
	
		sms(mydetail("mobile",$_REQUEST["id"],"student"),"Dear ".mydetail("fname",$_REQUEST["id"],"student").", Your Child(".mydetail("name",$_REQUEST["id"],"student").") is reached late in school on ".date("d-m-Y",strtotime($date))." regards ".$LinksDetails["site_name"],"student_attandance");
	
	echo "Attandenc add successfully";
}
elseif($ch=="removeAttandencStudent_late"){
	$date=$_REQUEST["year"]."-".$_REQUEST["month"]."-".$_REQUEST["date"];
			$db->delete("attandenc","where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$date."' and idno='".$_REQUEST["id"]."' and status=0 and type=3");
	echo "Attandenc Remove successfully";
	//echo $db->getLastQuery();
}
elseif($ch=="getHolidayCalender"){
 	   $y=$_REQUEST["year"];
       $class=$_REQUEST["cls"];
   
	?> <style>table tr td{border:3px groove #CC9;}</style>
    <table style="margin:20px"><?php
	for($m = 1;$m <= 12; $m++){ 
		?><tr><?php
		for($j=0; $j<= 31;$j++){
		  $monthNum = $m;
          $month = date("F", mktime(0, 0, 0, $monthNum, 10));
		    //$month = date("F", mktime(0, 0, 0, $m)); 
			//$month =  date("F", mktime(0, 0, 0, $m)); 
			$maxDays=date('t',strtotime($y."-".$m."-1"));
			$day=date('D',strtotime($y."-".$m."-".$j));
			$chkHoli=$db->getVal("select status from holiday where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$y."-".$m."-".$j."' and class='$class' ");
			$ColorClass="default";if(strtolower($day)=="sun") $ColorClass="danger";
			elseif($chkHoli=="1") $ColorClass="info";
			?><td>
            <?php if($j<=$maxDays){ if($j==0){ 
			echo $month;
			}else{?>
            	<button title="<?php echo $day; ?>" type="button" <?php if(strtolower($day)!="sun"){ ?> onclick="addHoliday('<?php echo $y."-".$m."-".$j ?>','<?php echo $class   ?>',this)" <?php } ?> class="btn btn-<?php echo $ColorClass; ?>">
					<?php echo $j; ?>
                  </button>
            <?php }} ?>
			</td><?php
		}
		?><tr><?php
	}
	?></table><?php
}



elseif($ch=="getHolidayCalender_faculty"){
 	   $y=$_REQUEST["year"];
        $class=$_REQUEST["cls"];
    $whereteacher = "";

    if($class != "ALL"){
        $whereteacher = " and teacher='$class' ";
    } 

	?> <style>table tr td{border:3px groove #CC9;}</style>
    <table style="margin:20px"><?php
	for($m = 1;$m <= 12; $m++){ 
		?><tr><?php
		for($j=0; $j<= 31;$j++){
			$month =  date("F", mktime(0, 0, 0, $m, 10)); 
			$maxDays=date('t',strtotime($y."-".$m."-1"));
			$day=date('D',strtotime($y."-".$m."-".$j));
			$chkHoli=$db->getVal("select status from staff_holiday where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and date='".$y."-".$m."-".$j."' $whereteacher ");
			$ColorClass="default";if(strtolower($day)=="sun") $ColorClass="danger";
			elseif($chkHoli=="1") $ColorClass="info";
			?><td>
            <?php if($j<=$maxDays){ if($j==0){ 
			echo $month;
			}else{?>
            	<button title="<?php echo $day; ?>" type="button" <?php if(strtolower($day)!="sun"){ ?> onclick="add_staff_Holiday('<?php echo $y."-".$m."-".$j ?>','<?php echo $class   ?>',this)" <?php } ?> class="btn btn-<?php echo $ColorClass; ?>">
					<?php echo $j; ?>
                  </button>
            <?php }} ?>
			</td><?php
		}
		?><tr><?php
	}
	?></table><?php
}
elseif($ch=="addHoliday"){
	$date=$_REQUEST["date"];
	$arr=explode("-",$date);
	$m=$arr["1"];
	$month =  date("F", mktime(0, 0, 0, $m));
	//echo $month;exit;
	
	$class = $_REQUEST["cls"];
	if($class == "ALL"){
	    $allclass = $db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' ");
	    foreach($allclass as $cls){
	        $chk=$db->getVal("select * from holiday where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$date."' and class='".$cls["class"]."' ");
	        if($chk==""){
        		$dataAry=array( "date"      =>  $date,
        						"reasion"   =>  $_REQUEST["reasion"],
        						"month"     =>  $month,
        						"class"     =>  $cls["class"],
        						"school_id" =>  $_SESSION["admin"]["school_id"],
        						"session"   =>  $_SESSION["admin"]["session"],
        						"added_by"  =>  $_SESSION["admin"]["uid"]
        		);
        		$db->insertAry("holiday",$dataAry);
        	}
	    }
	    echo "Holiday inserted successfully".$db->getErMsg();
	}
	else {
	$chk=$db->getVal("select * from holiday where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$date."' and class='".$_REQUEST["cls"]."' ");
	//echo $ss="select * from holiday where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$date."'";
	if($chk==""){
		$dataAry=array( "date"=>$date,
						"reasion"=>$_REQUEST["reasion"],
						 "month"=>$month,
						  "class"=>$_REQUEST["cls"],
						"school_id"=>$_SESSION["admin"]["school_id"],"session"=>$_SESSION["admin"]["session"],"added_by"=>$_SESSION["admin"]["uid"]
		);
		$db->insertAry("holiday",$dataAry);
	}
	echo "Holiday inserted successfully".$db->getErMsg();
	}
}
elseif($ch=="removeHoliday"){
	$row=$db->delete("holiday","where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$_REQUEST["date"]."'");
	echo "Holiday remove successfully";
}


elseif($ch=="remove_staff_Holiday"){
     $_REQUEST["date"];
	$row=$db->delete("staff_holiday","where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$_REQUEST["date"]."'");
	echo "Holiday remove successfully";
}
elseif($ch=="add_staff_Holiday"){
	$date=$_REQUEST["date"];
	$_REQUEST["cls"];
	$arr=explode("-",$date);
	$m=$arr["1"];
	$month =  date("F", mktime(0, 0, 0, $m));
	//echo $month;exit; 
	
	if($_REQUEST["cls"]=="ALL"){

	    $allstaff = $db->getRows("select * from staff where status=1 and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' ");
	    foreach($allstaff as $staff){
        	$chk=$db->getVal("select * from staff_holiday where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$date."' and teacher='".$staff["idno"]."' ");
        	if($chk==""){
        		$dataAry=array( "date"=>$date,
        						"reasion"=>$_REQUEST["reasion"],
        						"month"=>$month,
        						"teacher"=>$staff["idno"],
        						"school_id"=>$_SESSION["admin"]["school_id"],"session"=>$_SESSION["admin"]["session"],"added_by"=>$_SESSION["admin"]["uid"]
        		);
        		$db->insertAry("staff_holiday",$dataAry);
        	}
	    }
        echo "Holiday inserted successfully".$db->getErMsg();
	} else {
	
	$chk=$db->getVal("select * from staff_holiday where school_id='".$_SESSION["admin"]["school_id"]."' and date='".$date."' and teacher='".$_REQUEST["cls"]."' ");
	if($chk==""){
		$dataAry=array( "date"=>$date,
						"reasion"=>$_REQUEST["reasion"],
						 "month"=>$month,
						  "teacher"=>$_REQUEST["cls"],
						"school_id"=>$_SESSION["admin"]["school_id"],"session"=>$_SESSION["admin"]["session"],"added_by"=>$_SESSION["admin"]["uid"]
		);
		$db->insertAry("staff_holiday",$dataAry);
	}
	echo "Holiday inserted successfully".$db->getErMsg();
	}
}


elseif($ch=="admission_data"){
	$where="";
	if(isset($_REQUEST["class"]))$where.=" AND class='".$_REQUEST["class"]."' ";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="undefined")$where.=" AND section='".$_REQUEST["section"]."' ";
	$sql_limit="select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $where and status=1 $where and issue_TC=0 order by name";
	$aryList=$db->getRows($sql_limit);
	
	$aryPgAct=array("page_id"=>"make_admission","action"=>"add");
	if(is_array($aryList) && count($aryList)>0)
	{
		$aryData='{ "aaData": [
		';
	    $i=0;
		foreach($aryList as $iList)
		{
			$aryPgAct["id"]=$iList['idno'];
			$i++;
			$aryData.='["'.$i.'",';
			$aryData.='"'.POST($iList['name']).'",';
			$aryData.='"'.POST($iList['class'])."(".POST($iList['section']).")".'",';
			$aryData.='"'.POST($iList['medium']).'",';
			$aryData.='"'.POST($iList['admissionno']).'",';
			$aryData.='"'.POST($db->getVal("select root from bus where id=".$iList["bus"])).'",';
			//s$aryData.='"'.POST($iList["cast"]).'",';
			$aryData.='"'.POST($iList['fname']).'",';
			$aryData.='"'.POST($iList['mobile']).'",';
			$aryData.='"';
			$attr=$db->getRow("select * from allattandence where idno='".$iList["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
			$aryData.='<input name=\'student['.$iList['idno'].']\' type=\'text\' value=\''.$attr["term1_att"].'\' class=\'txtAtt student '.$iList['idno'].'\' />';
			$aryData.='",';
			$aryData.='"';
			$aryData.='<input name=\'student1['.$iList['idno'].']\' type=\'text\' value=\''.$attr["term2_att"].'\' class=\'txtAtt student '.$iList['idno'].'\' />';
			$aryData.='"]';
			if($i!=count($aryList))$aryData.=",";
		 }
		 $aryData.="] }";	
		 echo $aryData;	
	}else{
		echo $db->getLastQuery().$db->getErMsg();
	}
	
}


elseif($ch=="remarks_data"){
	$where="";
	if(isset($_REQUEST["class"]))$where.=" AND class='".$_REQUEST["class"]."' ";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="undefined")$where.=" AND section='".$_REQUEST["section"]."' ";
	$sql_limit="select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $where and status=1 $where and issue_TC=0 order by name";
	$aryList=$db->getRows($sql_limit);
	
	$aryPgAct=array("page_id"=>"make_admission","action"=>"add");
	if(is_array($aryList) && count($aryList)>0)
	{
		$aryData='{ "aaData": [
		';
	    $i=0;
		foreach($aryList as $iList)
		{
			$aryPgAct["id"]=$iList['idno'];
			$i++;
			$aryData.='["'.$i.'",';
			$aryData.='"'.POST($iList['name']).'",';
			$aryData.='"'.POST($iList['class'])."(".POST($iList['section']).")".'",';
		//	$aryData.='"'.POST($iList['medium']).'",';
			//$aryData.='"'.POST($iList['admissionno']).'",';
			$aryData.='"'.POST($db->getVal("select root from bus where id=".$iList["bus"])).'",';
			//s$aryData.='"'.POST($iList["cast"]).'",';
			$aryData.='"'.POST($iList['fname']).'",';
			$aryData.='"'.POST($iList['fincome']).'",';
			$aryData.='"';
			$attr=$db->getRow("select * from allattandence where idno='".$iList["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
			$aryData.='<input name=\'student['.$iList['idno'].']\' type=\'text\' value=\''.$attr["teacher_remarks_term1"].'\' class=\'txtAtt student '.$iList['idno'].'\' />';
			$aryData.='",';
			$aryData.='"';
			$aryData.='<input name=\'student1['.$iList['idno'].']\' type=\'text\' value=\''.$attr["teacher_remarks_term2"].'\' class=\'txtAtt student '.$iList['idno'].'\' />';
			$aryData.='"]';
			if($i!=count($aryList))$aryData.=",";
		 }
		 $aryData.="] }";	
		 echo $aryData;	
	}else{
		echo $db->getLastQuery().$db->getErMsg();
	}
	
}




elseif($ch=="specific_data"){
	$where="";
	if(isset($_REQUEST["class"]))$where.=" AND class='".$_REQUEST["class"]."' ";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="undefined")$where.=" AND section='".$_REQUEST["section"]."' ";
	$sql_limit="select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $where and status=1 $where and issue_TC=0 order by name";
	$aryList=$db->getRows($sql_limit);
	
	$aryPgAct=array("page_id"=>"make_admission","action"=>"add");
	if(is_array($aryList) && count($aryList)>0)
	{
		$aryData='{ "aaData": [
		';
	    $i=0;
		foreach($aryList as $iList)
		{
			$aryPgAct["id"]=$iList['idno'];
			$i++;
			$aryData.='["'.$i.'",';
			$aryData.='"'.POST($iList['name']).'",';
			$aryData.='"'.POST($iList['class'])."(".POST($iList['section']).")".'",';
		//	$aryData.='"'.POST($iList['medium']).'",';
			//$aryData.='"'.POST($iList['admissionno']).'",';
			$aryData.='"'.POST($db->getVal("select root from bus where id=".$iList["bus"])).'",';
			//s$aryData.='"'.POST($iList["cast"]).'",';
			$aryData.='"'.POST($iList['fname']).'",';
			$aryData.='"'.POST($iList['fincome']).'",';
			$aryData.='"';
			$attr=$db->getRow("select * from allattandence where idno='".$iList["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
			$aryData.='<input name=\'student['.$iList['idno'].']\' type=\'text\' value=\''.$attr["specific_participation_term1"].'\' class=\'txtAtt student '.$iList['idno'].'\' />';
			$aryData.='",';
			$aryData.='"';
			$aryData.='<input name=\'student1['.$iList['idno'].']\' type=\'text\' value=\''.$attr["specific_participation_term2"].'\' class=\'txtAtt student '.$iList['idno'].'\' />';
			$aryData.='"]';
			if($i!=count($aryList))$aryData.=",";
		 }
		 $aryData.="] }";	
		 echo $aryData;	
	}else{
		echo $db->getLastQuery().$db->getErMsg();
	}
	
}
?>
