<?php
	set_time_limit(0);
	function sendSms($ID,$Pwd,$remoteApp,$Mobno,$Text)
	{
                                            
		$request =""; //initialise the request variable
		$param[method]= "sendMessage";
		$param[send_to] = "91".$Mobno;
		
		$param[msg] = mb_convert_encoding($Text,"UTF-8");
		$param[userid] = $ID;
		$param[password] = $Pwd;
		$param[v] = "1.1";
		$param[msg_type] = "TEXT"; //Can be "FLASH"/"UNICODE_TEXT"/"BINARY"
		$param[auth_scheme] = "PLAIN";
		//Have to URL encode the values
		foreach($param as $key=>$val) {
		$request.= $key."=".urlencode($val);
		//we have to urlencode the values
		$request.= "&";
		//append the ampersand (&) sign after each
		
		}
		$request = substr($request, 0, strlen($request)-1);
		//remove final (&) sign from the request
		$url = $remoteApp.$request;
		
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		
		$curl_scraped_page = curl_exec($ch);
		
		curl_close($ch);
		return($curl_scraped_page);
	}
			
	function getBalance($ID,$Pwd,$remoteApp)
	{
		$request =""; //initialise the request variable
			
		$url = "http://enterprise.smsgupshup.com/apps/apis/accInfo?userid=2000163671&password=43vHSHCWv&method=balanceCheck";
		
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		
		$curl_scraped_page = curl_exec($ch);
		
		if(curl_errno($ch)){
    			return 'Curl error: ' . curl_error($ch);
		}else{
			$temp=$curl_scraped_page;		
		
			$temp_arry = explode(":",$temp);
			
			if(count($temp_arry)>0){
				return $temp_arry[1];
			}
			else{
				return 0;
			}
			
		}
		curl_close($ch);		
	}
        
    function getPresentData($str_temp = "",$branch_id = "",$semester_id = "",$div_id="",$student_id = "",$present_day = "",$batch_id="",$year_id=0)
    {
		$SQL_PRESENT = "
			SELECT 
				day_present,
				day_absent 
			FROM 
				cms_presentmaster 
			WHERE
                                day_working = 1 AND 
				branch_id = ".$branch_id." AND 
                                semester_id = ".$semester_id." AND 
                                div_id = '".$div_id."' AND 
				year_id = ".$year_id." AND 
				batch_id IN ('".$batch_id."',0)";
																		
		if($present_day != ""){			
                        $SQL_CONDITION = " AND day_date = '".date("Y-m-d",strtotime($present_day))."' ";
			$SQL_PRESENT.=$SQL_CONDITION;
                        
			$RES_PRESENT = dbQuery($SQL_PRESENT);			
			$cnt_lecture = 0;			
			$cnt_present = 0;
			
			while($REC_PRESENT = dbArray($RES_PRESENT)){
				$cnt_lecture++;				
                                $PRESENT= explode(",", $REC_PRESENT['day_present']);				
				if(in_array($student_id,$PRESENT) == true){
					$cnt_present++;
				}
			}				
			if($cnt_lecture > 0){
				$str_temp = str_replace("<CurrentDate>",date('d-M-Y'),$str_temp);
				$str_temp = str_replace("<PresentLecture>",$cnt_present,$str_temp);
				$str_temp = str_replace("<TotalLecture>",$cnt_lecture,$str_temp);
				return $str_temp;		
			}else{
				return "skip student";	
			}
		}
	}
?>


