<?php include("_config/dbconfig.php");
 

ini_set('max_execution_time', 1200); //300 seconds = 5 minutes


########################################################
# Login information for the SMS Gateway
########################################################
$username   = "eventage_sms"; // your username
$password   = "dell1234"; // your Password
$smsurl     = "http://sms.senseflow.pk:80/api/?"; // change smsdomain.com to your provided



########################################################
# Functions used to send the SMS message
########################################################
    function httpRequest($url){
        $args;
        $pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
        preg_match($pattern,$url,$args);
        $in = "";
        $fp = fsockopen("$args[1]", $args[2], $errno, $errstr, 30);
        if (!$fp)
        {
           return("$errstr ($errno)");
        }
        else
        {
            $out = "GET /$args[3] HTTP/1.1\r\n";
            $out .= "Host: $args[1]:$args[2]\r\n";
            $out .= "User-agent: PHP Web SMS client\r\n";
            $out .= "Accept: */*\r\n";
            $out .= "Connection: Close\r\n\r\n";

            fwrite($fp, $out);
            while (!feof($fp))
            {
               $in.=fgets($fp, 128);
            }
        }
        fclose($fp);
        return($in);
    }
      
    function send_sms($phone, $msg, $sender, $debug=false){
        
        global $username,$password,$smsurl;
        $url  = 'username='.$username;
        $url  .= '&password='.$password;
        $url  .= '&receiver='.urlencode($phone);
		$url  .= '&sender='.urlencode($sender);
        $url  .= '&msgdata='.urlencode($msg);
        $urltouse =  $smsurl.$url;
        if($debug)
        {
            echo "Request: <br>$urltouse<br><br>";
        }
        //Open the URL to send the message
        $response ='';
        $response = httpRequest($urltouse);
        if ($debug)
        {
            echo "Response: <br><pre>".
            str_replace(array("<",">"),array("&lt;","&gt;"),$response).
            "</pre><br>";
        }
        return($response); 
    }
 
    
$clients = $obj_jobs_class->getSMSClient();

$ss= 0;
if(count($clients)>0)
foreach($clients  as $cc){
    
    $phone = $cc['phone'];
    $message = $cc['message'];
    $sender = $cc['sender'];  
    "$phone $message $sender <br>";
    
    send_sms($phone, $message, $sender);
    $obj_jobs_class->updateSMSClient($cc['id']);
    $ss++;
}


echo " Total sms sent : $ss";

/*date_default_timezone_set('Asia/Karachi');
date("d-m-Y H:i:s");


/*$to   = "mohi.shaikh25@gmail.com";
$from = 'info@ccc.com';

$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$mesg  = "Testing Testing Testing Testing";
mail($to, "Corn Job Test", $mesg, $headers);
*/



?>