<?php

//set_time_limit(0);
	require "commonincludefiles.php";
	require "data/sendingsms_studentpresant.php";
	error_reporting(1);
	if($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])){
		$mobile_number = $_REQUEST['mobile_number']; 	
		$msg_body = trim($_REQUEST['msg_body']); 
		$msg_prefix = $_REQUEST['msg_prefix']; 
		$msg_suffix = $_REQUEST['msg_suffix']; 
		
		if($msg_prefix != ""){
			$msg_body = $msg_prefix.$msg_body;
		}
		if($msg_suffix != ""){
			$msg_body = $msg_body.$msg_suffix;
		}
		
		$mobile_number = explode(",",$mobile_number);
		$objMaster = new TransactionMgmt();
		$objDetail = new TransactionDetailMgmt();
		//$avialabelbal = getBalance($SmsUserName,$SmsPassword,$SMSGetbalance);
		
		$objMaster->user_message	= $msg_body;	
		$objMaster->user_id			= $_SESSION['aUserId'];
		$objMaster->user_lastbal 	= $avialabelbal;
		$objMaster->user_usedbal	= "";
		$objMaster->user_availbal 	= "";
		$objMaster->add();
		
		for($i=0; $i<count($mobile_number); $i++)
		{
				$response = sendSms($SmsUserName,$SmsPassword,$SmsSendapi,$mobile_number[$i],$msg_body);
				$status=explode(" | ",$response);
					if(trim($status[0]) == "success")
						{
							$objDetail->trans_id 		 = $objMaster->trans_id;
							$objDetail->sms_mobileno	 = $mobile_number[$i];							   
							$objDetail->sms_apimessageid = 0;
							$objDetail->sms_credit	   	 = 1;
							$objDetail->add();
						}
				
				//$avialabelbal--;
			
		}
		echo '{"success":"true","msg":"Message Sends to selected student."}';
	}	
?>