<?
session_start();
$brcode = $_SESSION['brcode'];
$user = $_SESSION['user'];
date_default_timezone_set("Asia/Kolkata"); 
if(strlen($brcode)<=0)
{
 	print "<script> alert('Invalid Login'); parent.document.location='ind.php' </script>";
 	return;
}
include("../opendb.php");
include("../test.php");
$d = $_REQUEST['d'];
$m = $_REQUEST['m'];
$y = $_REQUEST['y'];
$d1 = $_REQUEST['d1'];
$m1 = $_REQUEST['m1'];
$y1 = $_REQUEST['y1'];
$df=$y.'-'.$m.'-'.$d;
$dt=date('Y-m-d');
$chkled = $_REQUEST['chkled'];
$i=0;
foreach($chkled as $a)
{
    $chkled[$i]=$a; 
    $i++;
}
//print_r($chkled);













for($j=0;$j<$i;$j++)
{
    $smsqry=mysqli_query($db,"select phone1,acname from customer where id='$chkled[$j]' and brcode='$brcode'");
    
    $smsrow=mysqli_fetch_array($smsqry);
    $custphone=$smsrow[0];
    $phone ="";
    for ($ctr1=0;$ctr1<=strlen($custphone);$ctr1++)
    {
        $mnum = substr($custphone,$ctr1,1);
        if($mnum>='0' && $mnum<='9')
            $phone .= $mnum;
    }
    $custphone=$phone;
    $msms_code ="";
    for ($ctr=0;$ctr<=3;$ctr++)
    {
	    $msms_code .=chr(rand(48,57)).chr(rand(65,90)).chr(rand(97,122));
    }
    $smsstring=$msms_code.$chkled[$j];
    $curdate=date("Y-m-d H:i:s");
    mysqli_query($db,"insert into accledgersms (acname,datetime,code,custid,brcode,mobile) values('$smsrow[1]','$curdate','$smsstring','$chkled[$j]','$brcode','$custphone')");
    print "insert into accledgersms (acname,datetime,code,custid,brcode,mobile) values('$smsrow[1]','$curdate','$smsstring','$chkled[$j]','$brcode','$custphone')";
    $url="http://psnauto.in/psneicher/paypdf/custledger.php?custid=$smsstring";
     echo $url;
    echo "<br>";
     //$message="GATEENTRY - Vehicle No $regno entered on $curdate for $purps to meet $contactperson. http://psnauto.in/gateentry_3793/admin/index.php";
    $message="Dear Customer, view your ledger here $url.-PSNAUT";
        $message=urlencode($message);
        $url="www.bulksmsalert.in/SendSms.aspx?username=psnauto&password=THCM$456&from=PSNAUT&to=".$custphone."&message=".$message."";
        $ch = curl_init($url); 
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: 0'));
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);  
        if ($output === FALSE) 
        {
            die(curl_error($ch));
        }
        curl_close($ch);
          if ($output === FALSE) 
        {
            die(curl_error($ch));
        }
        else
        {
           // mysqli_query($db,"update vehentry set smsflg='1' where id='$smsrwid' and brcode='$brcode'");
        //echo "message sent successfully";
        }
    /*
    $query2="select corp,acname,id from customer where id='$chkled[$j]' and brcode='$brcode'";
    echo $query2;
    echo "<br>";
	$rs=mysqli_query($db,$query2);
	$jv_parts_row=mysqli_fetch_array($rs);
	*/
     //$msgtxt="'$itmtyp[$j]'";
     
}
?>