<?php
error_reporting(0);
@session_start();
include("config.php");

$cname=$_POST[cname];
$mobile=$_POST[mobile];
$mobile2=$_POST[mobile2];$vehicletyp=$_POST[vehicletyp]; $routefrom=$_POST[routefrom]; $routeto=$_POST[routeto];

$baddress=$_POST[baddress];
$bdate=$_POST[bdate];
$flag = $_REQUEST[flag];
$mode = $_REQUEST[mode];
$dobmonth = substr($bdate, 5);
$cardtyp=$_POST[cardtyp];
$fueltyp=$_POST[fueltyp];
$branch = $_SESSION[branch];

$companyname=$_POST[companyname];
$owner=$_POST[owner];
$ownermobile=$_POST[ownermobile];
$urea=$_POST[urea];

$regdate=$_POST[regdate];
$rtime=$_POST[rtime];
$empname=$_POST[empname];


//$rdte = date("Y/m/d");

$monthdte = date("m-Y");

$vnumber=$_POST[vnumber];
/***********************************/
$id= $_POST[id];

                    


if($id=="")
{
	
	   $Ad = sprintf("SELECT * from customer WHERE customer_mobile = $mobile"); 
						if(!($adminmail=mysql_query($Ad))){echo mysql_error($Ad); exit;}
						$A3=mysql_fetch_assoc($adminmail);
						$dbmobile = $A3[customer_mobile];
                    if($dbmobile == $mobile ){
						header("Location:add-customer.php?flag=exist"); exit;
		              
					} else {
						
    	 $query_insert=sprintf("Insert INTO customer SET 
		                 regdte = '$regdate' ,regtime='$rtime',rdte='$monthdte',status='Y',
		                   cardtyp ='$cardtyp',
						   vehicle_number='$vnumber',vehicletyp='$vehicletyp',
		                 customer_name='$cname',
		           	     customer_mobile='%s',  mobile2='$mobile2',  
				          
						  routefrom='$routefrom', routeto='$routeto',
							urea='$urea',branch='$branch',companyname='$companyname',owner='$owner',ownermobile='$ownermobile' ,empname='$empname'
							",$mobile,$bdate); 
							 	
				
		if(!($resi=mysql_query($query_insert))){echo $query_insert.mysql_error(); exit;}

		    
       
		$message = urlencode("Welcome to Road Ka Raja Programme. You are Registered Successfully. Thank You -Road Ka Raja");
$mobile = $mobile;

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://bulksmsindia.mobi/sendurlcomma.aspx?user=20064497&pwd=Prasad@0509&senderid=RKRAJA&mobileno='.$mobile.'&msgtext='.$message.'&smstype=0',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Cookie: ASP.NET_SessionId=qojdkmyjuhbrhodcflxie1mj'
  ),
));

$response = curl_exec($curl);

curl_close($curl);

			
		header("Location:addressbook.php?flag=dn&vnumber=$vnumber&fueltyp=$fueltyp");
		exit;
	}
}
$id= $_POST[id];
if($id!="")
{
           $query_up=sprintf("UPDATE customer SET 
		   cardtyp ='$cardtyp',
		    vehicle_number='$vnumber',vehicletyp='$vehicletyp',
                      customer_name='$cname',
		           	     customer_mobile='%s',   
						 mobile2='$mobile2', 
				            routefrom='$routefrom', routeto='$routeto',urea='$urea', branch='$branch',
							companyname='$companyname',owner='$owner',ownermobile='$ownermobile' 
							WHERE id='%d' ",$mobile,$bdate,$id);
		   if(!($resu=mysql_query($query_up))){echo $query_up.mysql_error(); exit;}
   
		
		 $query=sprintf("UPDATE customer_product_point SET 

		          mobile='%s'
				  WHERE cid='%d' ",$mobile,$id);
		   if(!($re=mysql_query($query))){echo $query.mysql_error(); exit;}
		
		
	
		header("Location:customer-list.php?flag=up");
		exit;
		
		}
					
?>
