<?php 
session_start();
require_once '../../Server/connection.php';
$staff_id = $_SESSION['staff_id'];
$query153 = "select * from staff where staff_id='$staff_id'";
$result153 = $conn->query($query153);
$row153 = $result153->fetch_array();
$des_id = $row153['des_id'];
if($_POST){
  $client_id = $_POST['client_id'];
  $fowardedto_id = $_POST['fowardedto_id'];
  $fowardedby_id = $_SESSION['user_id'];
  $remarks = addslashes($_POST['remarks']);
  $action = "fowarded";
  $status = 0;
  $perm_id = 67;
  $upl_status = $_POST['upl_status'];
  $assignedBy_role = 'CSO';
  $assignedTo_role = 'DCO';
  
  $query154 = "select * from staff,users,designation where users.user_id='$fowardedto_id' and users.staff_id=staff.staff_id and staff.des_id=designation.des_id";
  $result154 = $conn->query($query154);
  $row154 = $result154->fetch_array();
  $desId = $row154['des_id'];
  
  $invItemSql = "INSERT INTO assignstatus (client_id,assigned_to,assignedToDes_id,assignedTo_role,assigned_by,assignedByDes_id,assignedBy_role,permission_id,status,action,remarks) 
				VALUES ('$client_id','$fowardedto_id','$desId','$assignedTo_role','$fowardedby_id','$des_id','$assignedBy_role','$perm_id','$status','$action','$remarks')";

  $result11 = $conn->query($invItemSql);
  
  
  if($upl_status=='Yes' && $result11){
  foreach ($_FILES["file"]["name"] as $key => $name){
		$newFilename = time() . "_" . $name;
		move_uploaded_file($_FILES["file"]["tmp_name"][$key],'../../files/'.$newFilename);
		$location = '../../files/' . $newFilename;
		
		$fSql12 = "INSERT INTO client_docs (client_id,role,fileName) 
				VALUES ('$client_id','CSO','$location')";

		$resFSql12 = $conn->query($fSql12);
	          }
			
           if($resFSql12){			
		
					
				$_SESSION['success_message'] = "Customer Has Been fowarded to DCO Successfully";
                       header("Location: ../fowardCustomer.php");
                             exit();
			
                }				
			  
              }else{
				  
	
					$_SESSION['success_message'] = "Customer Has Been fowarded to DCO Successfully";
                       header("Location: ../fowardCustomer.php");
                             exit();
			
				  
				  
			  }
  
  
  
    
	  
  
}