<?php 
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();
$branch = $_SESSION["LOGIN_BRANCHES"];
extract($_REQUEST);

$today = date('Y-m-d');




function send_sms($obj,$branch,$module_id,$send_mobile,$message){
		if($send_mobile && $send_mobile !='' ){
			$priority = 'N';
			$entry2=$obj->Sms_Send($_SESSION["LOGIN_INSTITUTE_ID"],$module_id,'Homework',$send_mobile,$message, $priority, $_SESSION['LOGIN_USERID'],  date("Y:m:d h:i:s") );
	
	
		$smsstatus = true; 
			
			// return $_SESSION["LOGIN_INSTITUTE_ID"];
	   }
	/* $form = array('inst'=>$_SESSION["LOGIN_INSTITUTE_ID"],'modu'=>$module_id,'pro'=>'Automatic','mobile'=>$send_mobile,'message'=>$message, 'priroty'=>$priority, 'user'=>$_SESSION['LOGIN_USERID'],'date'=>  date("Y:m:d h:i:s"));
			echo '<pre>';
				print_r($form);		
			echo '</pre>';*/
	   
	   
	}
		
	function send_sms_by_guardian($obj,$branch,$module_id,$full_name, $guardian,$gender,$mobile,$message,$class_name,$section_roll){
		
		if($gender=='Male'){
			$gender = 'son';
		}else if($gender=='Female'){
			$gender = 'daughter';
		}else{
			$gender= 'child' ;
		}
		
		if($guardian=='F'){
			$send_mobile = $mobile['father_phone'];
			$guardian = 'Parents';	
		}
		if($guardian=='M'){
			$send_mobile = $mobile['mother_phone'];	
			$guardian = 'Parents';
		}
		if($guardian=='O'){
			$send_mobile = $mobile['guardian_phone'];	
			$guardian = 'Guardian';
		}
		
		
		
		
		 return send_sms($obj,$branch,$module_id,$send_mobile,$message);
		 
	}

 if($section_id){
	 $table_name =  "_homework_daily_status_class ";
			$COLUMN = '_approve_satus';
			$where_cond = '	_section_id='.$section_id.'  &&  DATE(_entry_date) ="'.$today.'"'  ;
			$SEND_STATUS=$obj->View_colmn_By_Cond($table_name,$COLUMN,$where_cond);
			
			// print_r($SEND_STATUS);
			if( $SEND_STATUS[0]['_approve_satus']==0){
	 
					 foreach($obj->View_Student_List_with_topics('sc._id="'.$section_id.'" && pf_std._status!="D" && hmc._homework_message_status = 1 AND DATE(hmc._entry_date) ="'.$today.'" ORDER BY _section_roll ASC') as $value){
						 
						
							$mobile = array();
							$mobile['guardian_phone'] = $value['guardian_phone'];
							$mobile['mother_phone'] = $value['mother_phone'];
							$mobile['father_phone'] = $value['father_phone'];	
							
							$message = $value['_homework_topics'] ;		
							/*echo '<pre>';
								print_r($value);		
							echo '</pre>'; */
				
							
							send_sms_by_guardian($obj, $branch,$module_id,$value['_full_name'] , $value['_current_guardian'],$value['_gender'], $mobile,$message,$value['_class_name'],$value['_section_roll']);		
						 
						 
					}
		}
	$table_name=" _homework_daily_status_class";
$column="_approve_satus = 1";
$where_cond='_homework_status = 1 AND  DATE(_entry_date) = "'.$today.'" AND _section_id = "'.$section_id.'"';
 $all_section_id=$obj->Update_Data2($table_name,$column,$where_cond);
	
 }
 echo 'success';
?>