<?php 
session_start();
// ============
//include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();



extract($_REQUEST);

$today = date('Y-m-d');
$branch = $_SESSION["LOGIN_BRANCHES"];

 if($section_id){
	$SEND_STATUS=$obj->View_colmn_By_Cond("_atd_daily_status_class","_approve_satus","_section_id='$section_id'  AND  DATE(_entry_date)='$today'");
	
	if( $SEND_STATUS[0]['_approve_satus']==0){
		
		foreach($obj->View_Student_List_atttd_status_classwise("sc._id='$section_id' AND pf_std._status!='D' AND DATE(hmc._entry_date)='$today' AND hmc._atd_status !='P' ORDER BY hmc._atd_status ASC") as $value){
			
			$send_mobile = $value['_contact_mobile'];
			$att_status = $value['_atd_status'];
			$full_name = $value['_full_name'];
			$late_time = $value['_late_time'];
			$class_name = $value['_class_name'];
			$section_roll = $value['_section_roll'];
			
			if($att_status=='P'){
				$message  = "Dear Guardian, Your child ".$full_name.", Class : ".$class_name.", Class Roll : ".$section_roll." was arrived to school in due time. Thank you! ";
			}
			elseif($att_status=='A'){
			//	$message  = "Dear Guardian,  Your child ".$full_name.", Class : ".$class_name.", Class Roll : ".$section_roll." is absent from school. As we need to ensure that all absent children are safe. Thank you!" ;
				$message  = "Dear Guardian, Your child ".$full_name.", Class : ".$class_name.", Roll : ".$section_roll." is absent from school today. We need to ensure that your child is safe." ;
			//$message  = "জনাব/জনাবা,  আপনার সন্তান নাম: ".$full_name.", ক্লাস : ".$class_name.", রোল : ".$section_roll." আজ আমাদের কোচিং এ আসেনি। আপনার সন্তানের সঠিক তথ্য নিন। ধন্যবাদ.ডায়মন্ড একাডেমিক কেয়ার,মোবাইল: 01717548568 " ;
			
			}
			elseif($att_status=='LA'){
				$message  = "Dear Guardian,  Your child ".$full_name.", Class : ".$class_name.", Class Roll : ".$section_roll." was late (".$late_time." minute). Lateness to school impacts a child\'s academic success. Thank you!" ;
			}
			elseif($att_status=='LE'){
				$message  = "Dear Guardian, Your child ".$full_name.", Class : ".$class_name.", Class Roll : ".$section_roll." is at leave . Thank you! ";
			}
			
			$entry_by = $_SESSION['LOGIN_USERID'];
			$institute_id = $_SESSION["LOGIN_INSTITUTE_ID"];
			$date_time = date("Y:m:d h:i:s");
			$sms_type="bangla";
			
			$sms_res = $obj->Sms_Send($institute_id,$module_id,$sms_type,$send_mobile,$message,"M",$entry_by,$date_time);
				
		}
		if($sms_res){
			$table_name="_atd_daily_status_class";
			$column="_approve_satus = 1";
			$where_cond='_atd_status = 1 AND  DATE(_entry_date) = "'.$today.'" AND _section_id = "'.$section_id.'"';	
			$all_section_id = $obj->Update_Data2($table_name,$column,$where_cond);
			
			if($all_section_id){
				echo 'Success';
			}
		}
	}
	else{echo 'Already Approved';}
					
 }
 else{echo 'Section Not Available';}
 

 
?>