<?php 
//start session
session_start();
require_once('mail.php');
require_once('database.php');

$action = $_GET['action'];

switch($action) {
	case 'add-cons':
		addCons();
	break;
	
	case 'edit-cons':
		editCons();
	break;
	
	case 'delivered':
		markDelivered();
	break;
	
	case 'add-office':
		addNewOffice();
	break;
	
	case 'add-manager':
		addManager();
	break;
	
	case 'update-status':
		updateStatus();
	break;
	
	case 'change-pass':
		changePass();
	break;
			
	case 'logOut':
		logOut();
	break;		
	
}//switch

function addCons(){

	$Shippername = $_POST['Shippername'];
	$Shipperphone = $_POST['Shipperphone'];
	$Shippermail = $_POST['Shippermail'];
	$Shipperaddress = $_POST['Shipperaddress'];
	
	$Receivername = $_POST['Receivername'];
	$Receiverphone = $_POST['Receiverphone'];
	$Receivermail = $_POST['Receivermail'];
	$Receiveraddress = $_POST['Receiveraddress'];
	
	$ConsignmentNo = $_POST['ConsignmentNo'];
	$Shiptype = $_POST['Shiptype'];
	$Weight = $_POST['Weight'];
	$Invoiceno = $_POST['Invoiceno'];
	
	
	$Shipcontent = $_POST['Shipcontent'];
	$Qnty = $_POST['Qnty'];
	$Totalfreight = $_POST['Totalfreight'];
	$Mode = $_POST['Mode'];
	$pmode = $_POST['pmode'];
	
	
	$Packupdate = $_POST['Packupdate'];
	$Deptdate = $_POST['Deptdate'];
	$Origin = $_POST['Origin'];
	$Destination = $_POST['Destination'];
	$status = $_POST['status'];
	

	$sql = "INSERT INTO tbl_courier (cons_no, s_name, s_phone, s_mail, s_add, r_name, r_phone, r_mail, r_add, invoice_no, type, product, weight, qty, mode, freight, dept_date, pick_date, pmode, origin, destination, status )
			VALUES('$ConsignmentNo', '$Shippername','$Shipperphone', '$Shippermail', '$Shipperaddress', '$Receivername','$Receiverphone', '$Receivermail', '$Receiveraddress', '$Invoiceno', '$Shiptype', '$Shipcontent', $Weight ,  $Qnty, '$Mode', '$Totalfreight', '$Deptdate', '$Packupdate', '$pmode', '$Origin', '$Destination',  '$status')";	
	//echo $sql;
	dbQuery($sql);
	
	
	
	   $owneremail="sophyinfotech@gmail.com";/* your bulk sms account email */
						$ownerpwd="Ugofobi2161k"; /* your bulk sms account password */
						$sendto="$phone"; /* destination number */
						$sender="CARGO"; /* sender id */
            						$message="Dear $s_name, Your Shippment have been created successfully. Tracking NO is $cons_no
            						"; /* message to be sent*/
						
						/* create the required URL*/ 
						
						$url = "https://kullsms.com/customer/api/?"
							  . "&username=" . UrlEncode($owneremail)
							  . "&password=" . UrlEncode($ownerpwd)
							  . "&message=" . UrlEncode($message)
							  ."&sender=".UrlEncode($sender)
							  ."&mobiles=".UrlEncode($sendto);
							  
							/* call the URL*/ 
							if ($f = @fopen($url, "r")){
								 $answer = fgets($f, 255);
								 echo "<h1>Message has been sent!</h1>";
							 }else{
								echo "<h1>Message failed to send!</h1>"; 
							 }
						  		

	
	//now send email
	//email it now.	
	 
	$subject = "CONSIGNMEMT REGISTRATION";
	$to = $email;
	$msg_body = "Dear $s_name,<br/><br/>
	 
	
		<link href='https://fonts.googleapis.com/css?family=Kreon:400,700|Playfair+Display:400,400i,700,700i|Raleway:400,400i,700,700i|Roboto:400,400i,700,700i' rel='stylesheet' />
              	 
    <!-- INTRODUCTION -->
<table width='100%' border='0' cellspacing='0' cellpadding='0' align='center'>
    <tr>
        <td bgcolor='#efe9e5'>
            <table width='620' border='0' cellspacing='0' cellpadding='0' align='center' class='scale'>
                <tr>
                    <td bgcolor='#FFFFFF'>
                        
                        <table width='540' border='0' cellspacing='0' cellpadding='0' align='center' class='agile1 scale'>
                            
                           <tr><td class='wls-5h' style='color:green;'><h1><strong>PSS-XPRESS</strong></h1></td></tr> 
                            
                            <tr>
                                <td class='agile-main' style='font-family:Bell Gothic Std; color: #00a78e; font-size: 22px;' class='scale-center-both'>
								
								<strong>ACCOUNT NOTIFICATION</strong></td>
                            </tr>
                            <tr><td height='12' style='font-size: 1px;'>&nbsp;</td></tr>
                            <tr>
                                <td class='w3l-p2' style=' text-align: justify; font-family: Candara, sans-serif; color: #7f8c8d; font-size: 18px; line-height: 28px;' class='scale-center-both'>
                                Dear s_name, Thank you so much for allowing us to help you Ship your item. We are committed to providing our customers with the highest
	level of service and the most innovative logistics products possible. We are very glad you chose us as your Courier and Logistics Company and hope you 
	will take advantage of our wide variety of services.
                                </td>
                            </tr>
                            
                            
      	<div class='container-fluid'>
          <div class='row'>
    <div class='modal-dialog modal-lg'>
        <div class='modal-content'> 



		
            <div class='modal-header'>
            
              <h4 class='modal-title'>Consignment No. : <strong><?php echo $cons_no; ?></strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			  
			  
			  </h4>
            </div>

            <div class='modal-body'>
                <div class='row'>
                    <div class='col-md-6 col-sm-5 col-xs-6'>
                        <h4 style='font-weight:bold;'>Shipper Details</h4>
                        <div style='border: solid 1px #ddd; border-radius:4px; padding-left:5px; line-height:24px;'>
                            Shipper's Name:&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $s_name; ?><br>
                            Shipper's Location:&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $s_add; ?><br>
                            Shipper's Email:&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $s_mail; ?><br> 
							Shipper's Phone:&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $s_phone; ?><br> 
							</div>
                    </div>
                    <div class='col-md-6 col-sm-5 col-xs-6'>
                        <h4 style='font-weight:bold;'>Receiver Details</h4>
                        <div style='border: solid 1px #ddd; border-radius:4px; padding-left:5px; line-height:24px;'>
                           Receiver's Name:&nbsp;&nbsp; <?php echo $r_name; ?><br>
                           Receiver's Location:&nbsp;&nbsp; <?php echo $r_add; ?><br>
                           Receiver's Email:&nbsp;&nbsp; <?php echo $r_mail; ?><br> 
						Receiver's Phone:&nbsp;&nbsp; <?php echo $r_phone; ?><br>
						</div>
						<p>&nbsp;</p>
                    </div>
                    
                    <div class='col-md-6 col-sm-6 col-xs-6'>
                        <ul class='list-group list-group-bordered col-md-12'>
                            <li class='list-group-item'>
                              <b>Bill Of Lading:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $invoice_no; ?> </a>
                            </li>
                            <li class='list-group-item'>
                              <b>Type of Shipment:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $type; ?></a>
                            </li>
                            <li class='list-group-item'>
                              <b>Content of Product:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $product; ?></a>
                            </li>
                            <li class='list-group-item'>
                              <b>Pickup Date:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $pick_date; ?></a>
                            </li>
                            
                        </ul>
                    </div>
                    
                    <div class='col-md-6 col-sm-6 col-xs-6'>
                        <ul class='list-group list-group-bordered col-md-12'>
                            <li class='list-group-item'>
                              <b>Quantity of Product:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $qty; ?></a>
                            </li>
                            <li class='list-group-item'>
                              <b>Weight of Product:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $weight; ?>&nbsp;kg</a>
                            </li>
                            <li class='list-group-item'>
                              <b>Mode of Transport:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $mode; ?></a>
                            </li>
                            <li class='list-group-item'>
                              <b>Total Due Amount:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $freight; ?></a>
                            </li>
                                                    </ul>
                    </div>
                    
                    <div class='clearfix'></div>
                    
                </div>
            </div> 
                                                 
        </div>
    </div>
      
          
                </div>
              </div>
                            
                             <tr><td class='wls-5h' height='60' style='font-size: 16px; color:red;'> Warm Regards,</td></tr> 
	                        
	                         <tr><td class='wls-5h' height='30' style='font-size: 18px; color:orange;'><strong>PSS-XPRESS</strong></td></tr>
                            
                             
                            
                            <tr><td class='wls-5h' height='50'>
                             
					Declaimer: This message was automatically generated via secured online channel, please do not reply this message. All
					correspondent should be address to Customer Service
											 
                            </td></tr>
                            
                        </table>    
            
                    </td>
                </tr>
            </table>
            
        </td>
    </tr>
</table>
                
	 
 
	
	
	";
	
	$mail_data = array('to' => $to, 'sub' => $subject, 'msg' => 'register', 'body' => $msg_body);
	send_email($mail_data);
	
	
	header('Location: courier-add-success.php'); 
	exit;
	//echo $Ship;
}//addCons

function editCons() {
    $cid = $_POST['cid'];
    $Shippername = $_POST['Shippername'];
	$Shipperphone = $_POST['Shipperphone'];
	$Shippermail = $_POST['Shippermail'];
	$Shipperaddress = $_POST['Shipperaddress'];
	
	$Receivername = $_POST['Receivername'];
	$Receiverphone = $_POST['Receiverphone'];
	$Receivermail = $_POST['Receivermail'];
	$Receiveraddress = $_POST['Receiveraddress'];
	
	$ConsignmentNo = $_POST['ConsignmentNo'];
	$Shiptype = $_POST['Shiptype'];
	$Weight = $_POST['Weight'];
	$Invoiceno = $_POST['Invoiceno'];
	
	
	$Shipcontent = $_POST['Shipcontent'];
	$Qnty = $_POST['Qnty'];
	$Totalfreight = $_POST['Totalfreight'];
	$Mode = $_POST['Mode'];
	$pmode = $_POST['pmode'];
	
	
	$Packupdate = $_POST['Packupdate'];
	$Deptdate = $_POST['Deptdate'];
	$Origin = $_POST['Origin'];
	$Destination = $_POST['Destination'];
	$status = $_POST['status']; 
	
	$sql = "UPDATE tbl_courier SET
	cons_no = '$ConsignmentNo',
	s_name = '$Shippername',
	s_phone = '$Shipperphone',  
	s_mail = '$Shippermail', 
	s_add = '$Shipperaddress', 
	r_name = '$Receivername', 
	r_phone = '$Receiverphone', 
	r_add = '$Receiveraddress', 
	invoice_no = '$Invoiceno', 
	type = '$Shiptype', 
	product = '$Shipcontent', 
	weight = '$Weight', 
	qty = '$Qnty', 
	mode = '$Mode', 
	freight = '$Totalfreight', 
	dept_date = '$Deptdate', 
	pick_date = '$Packupdate', 
	pmode = '$pmode', 
	origin = '$Origin', 
	destination = '$Destination', 
	status = '$status'
	WHERE cid = $cid";
	

	dbQuery($sql);
	
	
	header('Location: courier-edit-success.php'); 
	
}//editCons


function markDelivered() {
	$cid = (int)$_GET['cid'];
	$sql = "UPDATE tbl_courier
			SET status = 'Delivered'
			WHERE cid= $cid";
	dbQuery($sql);
	header('Location: delivered-success.php'); 
			
}//markDelivered();

function addNewOffice() {
	
	$OfficeName = $_POST['OfficeName'];
	$OfficeAddress = $_POST['OfficeAddress'];
	$City = $_POST['City'];
	$PhoneNo = $_POST['PhoneNo'];
	$OfficeTiming = $_POST['OfficeTiming'];
	$ContactPerson = $_POST['ContactPerson'];
	
	$sql = "INSERT INTO tbl_offices (off_name, address, city, ph_no, office_time, contact_person)
			VALUES ('$OfficeName', '$OfficeAddress', '$City', '$PhoneNo', '$OfficeTiming', '$ContactPerson')";
	dbQuery($sql);
	header('Location: office-add-success.php');
}//addNewOffice

function addManager() {
	
	$ManagerName = $_POST['ManagerName'];
	$Password = $_POST['Password'];
	$Address = $_POST['Address'];
	$Email = $_POST['Email'];
	$PhoneNo = $_POST['PhoneNo'];
	
	$sql = "INSERT INTO tbl_courier_officers (officer_name, off_pwd, address, email, ph_no)
			VALUES ('$ManagerName', '$Password', '$Address', '$Email', '$PhoneNo' )";
	dbQuery($sql);
	header('Location: manager-add-success.php');

}//addNewOffice

function updateStatus() {
	
	$current_city = $_POST['current_city'];
	$update_date = $_POST['update_date'];
	$new_status = $_POST['new_status'];
	$comments = $_POST['comments'];
	$bk_time = $_POST['bk_time'];
	$cid = (int)$_POST['cid'];
	$cons_no = $_POST['cons_no'];
	$current_location = $_POST['current_location'];
	//$OfficeName = $_POST['OfficeName'];
	
	$sql = "INSERT INTO tbl_courier_track (cid, cons_no, current_city, new_status, current_location, comments, update_date, bk_time)
			VALUES ($cid, '$cons_no', '$current_city', '$new_status', '$current_location', '$comments', '$update_date','$bk_time')";
	dbQuery($sql);
	
	$sql_1 = "UPDATE tbl_courier 
				SET status = '$status' 
				WHERE cid = $cid
				AND cons_no = '$cons_no'";
	dbQuery($sql_1);


	   $owneremail="sophyinfotech@gmail.com";/* your bulk sms account email */
						$ownerpwd="Ugofobi2161k"; /* your bulk sms account password */
						$sendto="$phone"; /* destination number */
						$sender="CARGO"; /* sender id */
            						$message="Dear $s_name, Your Shippment have been created successfully. Tracking NO is $cons_no
            						"; /* message to be sent*/
						
						/* create the required URL*/ 
						
						$url = "https://kullsms.com/customer/api/?"
							  . "&username=" . UrlEncode($owneremail)
							  . "&password=" . UrlEncode($ownerpwd)
							  . "&message=" . UrlEncode($message)
							  ."&sender=".UrlEncode($sender)
							  ."&mobiles=".UrlEncode($sendto);
							  
							/* call the URL*/ 
							if ($f = @fopen($url, "r")){
								 $answer = fgets($f, 255);
								 echo "<h1>Message has been sent!</h1>";
							 }else{
								echo "<h1>Message failed to send!</h1>"; 
							 }
						  		

	
	//now send email
	//email it now.	
	 
	$subject = "NEW LOCATION";
	$to = $email;
	$msg_body = "Dear $r_name,<br/><br/>
	 
	
		<link href='https://fonts.googleapis.com/css?family=Kreon:400,700|Playfair+Display:400,400i,700,700i|Raleway:400,400i,700,700i|Roboto:400,400i,700,700i' rel='stylesheet' />
              	 
    <!-- INTRODUCTION -->
<table width='100%' border='0' cellspacing='0' cellpadding='0' align='center'>
    <tr>
        <td bgcolor='#efe9e5'>
            <table width='620' border='0' cellspacing='0' cellpadding='0' align='center' class='scale'>
                <tr>
                    <td bgcolor='#FFFFFF'>
                        
                        <table width='540' border='0' cellspacing='0' cellpadding='0' align='center' class='agile1 scale'>
                            
                           <tr><td class='wls-5h' style='color:green;'><h1><strong>PSS-XPRESS</strong></h1></td></tr> 
                            
                            <tr>
                                <td class='agile-main' style='font-family:Bell Gothic Std; color: #00a78e; font-size: 22px;' class='scale-center-both'>
								
								<strong>CONSIGNMENT LOCATION UPDATED</strong></td>
                            </tr>
                            <tr><td height='12' style='font-size: 1px;'>&nbsp;</td></tr>
                            <tr>
                                <td class='w3l-p2' style=' text-align: justify; font-family: Candara, sans-serif; color: #7f8c8d; font-size: 18px; line-height: 28px;' class='scale-center-both'>
                                Dear r_name, We wish to notify you of your consignment current status. <br> Kindly find below the current location of your package.
                                </td>
                            </tr>
                            
                            
      	<div class='container-fluid'>
          <div class='row'>
    <div class='modal-dialog modal-lg'>
        <div class='modal-content'> 



		
            <div class='modal-header'>
            
              <h4 class='modal-title'>Consignment No. : <strong><?php echo $cons_no; ?></strong><br>
			  Comment : <strong><?php echo $comments; ?></strong><br>
			  Current Location : <strong><?php echo $current_location; ?></strong>
			  Current City : <strong><?php echo $current_city; ?></strong>
			  Current Status : <strong><?php echo $new_status; ?></strong>
			   Date and Time : <strong><?php echo $update_date; ?>, <?php echo $bk_time; ?></strong>
			  
			  
			  </h4>
            </div>

            <div class='modal-body'>
                <div class='row'>
                    <div class='col-md-6 col-sm-5 col-xs-6'>
                        <h4 style='font-weight:bold;'>Shipper Details</h4>
                        <div style='border: solid 1px #ddd; border-radius:4px; padding-left:5px; line-height:24px;'>
                            Shipper's Name:&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $s_name; ?><br>
                            Shipper's Location:&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $s_add; ?><br>
                            Shipper's Email:&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $s_mail; ?><br> 
							Shipper's Phone:&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $s_phone; ?><br> 
							</div>
                    </div>
                    <div class='col-md-6 col-sm-5 col-xs-6'>
                        <h4 style='font-weight:bold;'>Receiver Details</h4>
                        <div style='border: solid 1px #ddd; border-radius:4px; padding-left:5px; line-height:24px;'>
                           Receiver's Name:&nbsp;&nbsp; <?php echo $r_name; ?><br>
                           Receiver's Location:&nbsp;&nbsp; <?php echo $r_add; ?><br>
                           Receiver's Email:&nbsp;&nbsp; <?php echo $r_mail; ?><br> 
						Receiver's Phone:&nbsp;&nbsp; <?php echo $r_phone; ?><br>
						</div>
						<p>&nbsp;</p>
                    </div>
                    
                    <div class='col-md-6 col-sm-6 col-xs-6'>
                        <ul class='list-group list-group-bordered col-md-12'>
                            <li class='list-group-item'>
                              <b>Bill Of Lading:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $invoice_no; ?> </a>
                            </li>
                            <li class='list-group-item'>
                              <b>Type of Shipment:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $type; ?></a>
                            </li>
                            <li class='list-group-item'>
                              <b>Content of Product:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $product; ?></a>
                            </li>
                            <li class='list-group-item'>
                              <b>Pickup Date:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $pick_date; ?></a>
                            </li>
                            
                        </ul>
                    </div>
                    
                    <div class='col-md-6 col-sm-6 col-xs-6'>
                        <ul class='list-group list-group-bordered col-md-12'>
                            <li class='list-group-item'>
                              <b>Quantity of Product:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $qty; ?></a>
                            </li>
                            <li class='list-group-item'>
                              <b>Weight of Product:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $weight; ?>&nbsp;kg</a>
                            </li>
                            <li class='list-group-item'>
                              <b>Mode of Transport:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $mode; ?></a>
                            </li>
                            <li class='list-group-item'>
                              <b>Total Due Amount:&nbsp;&nbsp;</b> <a class='pull-right'><?php echo $freight; ?></a>
                            </li>
                                                    </ul>
                    </div>
                    
                    <div class='clearfix'></div>
                    
                </div>
            </div> 
                                                 
        </div>
    </div>
      
          
                </div>
              </div>
                            
                             <tr><td class='wls-5h' height='60' style='font-size: 16px; color:red;'> Warm Regards,</td></tr> 
	                        
	                         <tr><td class='wls-5h' height='30' style='font-size: 18px; color:orange;'><strong>PSS-XPRESS</strong></td></tr>
                            
                             
                            
                            <tr><td class='wls-5h' height='50'>
                             
					Declaimer: This message was automatically generated via secured online channel, please do not reply this message. All
					correspondent should be address to Customer Service
											 
                            </td></tr>
                            
                        </table>    
            
                    </td>
                </tr>
            </table>
            
        </td>
    </tr>
</table>
                
	 
 
	
	
	";
	
	$mail_data = array('to' => $to, 'sub' => $subject, 'msg' => 'register', 'body' => $msg_body);
	send_email($mail_data);
	
	
	header('Location: update-success.php');
	exit;
}//updateaccount



function changePass() {
	$cid = $_POST['cid'];
	$ManagerName = $_POST['ManagerName'];
	$Password = $_POST['Password'];
	
	$sql = "UPDATE tbl_courier_officers SET
	officer_name = '$ManagerName',
	off_pwd = '$Password'
	WHERE cid = $cid";
	
	dbQuery($sql);
	header('Location: manager-changepass-success.php');

}//changePass





function logOut(){
	if(isset($_SESSION['user_name'])){
		unset($_SESSION['user_name']);
	}
	if(isset($_SESSION['user_type'])){
		unset($_SESSION['user_type']);
	}
	session_destroy();
	header('Location: login.php');
}//logOut

?>