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

extract($_POST);
$message = rawurldecode($sms_body);
$std_sms_checked_list = rawurldecode($selected_std_list);
$change = "`";
$message = str_replace("'",$change,$message);
$show_part_no = $obj->count_total_consumed_sms_part($message);
$ret_msg = "";
if($max_part_no == $show_part_no){
	$tables = "_pf_std_basic_info a left join _pf_std_personal_info b on (a._pid=b._id)";
	$cols = "b._id AS std_id, b._full_name AS std_name,b._uniq_id AS uniq_id,b._section_roll AS std_roll,b._contact_mobile as std_contact";
	$where_cond = " a._section_id=$sec_id and a._session=$session and b._status='A'";

	if($std_sms_checked_list!=NULL){
		$where_cond .=" and b._id in ($std_sms_checked_list)";
	}
	$where_cond .= " order by b._section_roll asc";
	$std_info = $obj->View_colmn_By_Cond($tables,$cols,$where_cond);
	
	if(count($std_info)>0){
		foreach($std_info as $st){
			//$ret_msg .= "inst_id: ".$_SESSION["LOGIN_INSTITUTE_ID"]."\nmod_id: $mod_id\nsms_type: $sms_type\n_num: ".$st['std_contact']."\nsms: $message\npriority: \"M\"\nuser: ".$_SESSION['LOGIN_USERID']."\ndate: ".date("Y:m:d h:i:s")."\n";
			$entry2=$obj->Sms_Send($_SESSION["LOGIN_INSTITUTE_ID"],$mod_id,$sms_type,$st['std_contact'],$message,"M",$_SESSION['LOGIN_USERID'],date("Y:m:d h:i:s"));
			$ret_msg = 'Your request has been successfully submitted';
		}
		$form_notice=array(
				'_institute_id'=>$_SESSION["LOGIN_INSTITUTE_ID"],
				'_branch_id'=>$_SESSION["LOGIN_BRANCH"],
				'_module_id'=>$mod_id,
				//'_student_type'=>substr($student_type, 1, -1),
				'_sections'=>$sec_id,
				//'_notice_subject'=>$subject,
				'_notice_body'=>$message,
				'_notice_part'=>$show_part_no,
				'_priority'=>"M",
				'_status'=>1,
				'_entry_by'=>$_SESSION['LOGIN_USERID'],
				'_entry_date'=>date("Y:m:d h:i:s"),
				'_update_by'=>$_SESSION['LOGIN_USERID']
		);
		$notice=$obj->Insert_Data("_int_std_notice", $form_notice);
	}
	else{
		$ret_msg = "Student Not Found!";
	}
}
else{
	$ret_msg = "Please check you sms size.";
}

echo $ret_msg;	

?>