<?php 
    $id=$_REQUEST['id'];

	$_SESSION['info_message'] = "Duplicate copy created sucessfully";
	if($_REQUEST['page']=='view_quotation'){
		mysqli_query($conn,"INSERT INTO job(company_name,first_name1,last_name1,first_name2,last_name2,first_name3,last_name3,phone_no1,phone_no2,phone_no3,email,password,address1,address2,address3,city,county,postcode,common_date,done_work,source,enquiry_status,sector,client_industry,enquiry_type,fixed_packages,fixed_amount,hourly_packages,hourly_amount,total_hours,is_enquiry,enquiry_date,enquiry_by)  (SELECT company_name,first_name1,last_name1,first_name2,last_name2,first_name3,last_name3,phone_no1,phone_no2,phone_no3,email,password,address1,address2,address3,city,county,postcode,common_date,done_work,source,enquiry_status,sector,client_industry,enquiry_type,fixed_packages,fixed_amount,hourly_packages,hourly_amount,total_hours,is_enquiry,enquiry_date,enquiry_by FROM job where id=$id)");	 
		$job_id = mysqli_insert_id($conn);
		
		$is_quotation			= 1;
		$company_name			= utility::getTableFieldById("job","company_name","id",$id);
		$quotation_no			= $gsi->getInitialOfCompanyName($company_name).date("dmy");
		$quotation_date			= date("Y-m-d");
		$quotation_by			= $_SESSION['user_id'];
		$updated_by				= $_SESSION['user_id'];
		$update_job = "UPDATE job SET quotation_no='".$quotation_no."',is_quotation='".$is_quotation."', quotation_date='".$quotation_date."', quotation_by='".$quotation_by."', updated_by='".$updated_by."' WHERE id='".$job_id."' ";
		mysqli_query($conn,$update_job);
		
		header("location: $file_name?page=add_quotation&action=edit&id=$job_id".$next_page_condition.$paging);
		exit();
	}else if($_REQUEST['page']=='view_job'){
		mysqli_query($conn,"INSERT INTO job(quotation_no,company_name,first_name1,last_name1,first_name2,last_name2,first_name3,last_name3,phone_no1,phone_no2,phone_no3,email,password,address1,address2,address3,city,county,postcode,common_date,done_work,source,enquiry_status,sector,client_industry,enquiry_type,fixed_packages,fixed_amount,hourly_packages,hourly_amount,total_hours,job_start_date,job_end_date,is_enquiry,enquiry_date,enquiry_by,is_quotation,quotation_date,quotation_by)  (SELECT quotation_no,company_name,first_name1,last_name1,first_name2,last_name2,first_name3,last_name3,phone_no1,phone_no2,phone_no3,email,password,address1,address2,address3,city,county,postcode,common_date,done_work,source,enquiry_status,sector,client_industry,enquiry_type,fixed_packages,fixed_amount,hourly_packages,hourly_amount,total_hours,job_start_date,job_end_date,is_enquiry,enquiry_date,enquiry_by,is_quotation,quotation_date,quotation_by FROM job where id=$id)");	 
		$job_id = mysqli_insert_id($conn);
		
		$is_job					= 1;
		$job_date				= date("Y-m-d");
		$company_name			= utility::getTableFieldById("job","company_name","id",$id);
		$job_no					= $gsi->getInitialOfCompanyName($company_name).date("dmy");
		$job_by					= $_SESSION['user_id'];
		$updated_by				= $_SESSION['user_id'];
		$update_job = "UPDATE job SET is_job='".$is_job."', job_no='".$job_no."', job_date='".$job_date."', job_by='".$job_by."', updated_by='".$updated_by."' WHERE id='".$job_id."' ";
		mysqli_query($conn,$update_job);
		
		header("location: $file_name?page=add_job&action=edit&id=$job_id".$next_page_condition.$paging);
		exit();
	}else{
		mysqli_query($conn,"INSERT INTO job(company_name,first_name1,last_name1,first_name2,last_name2,first_name3,last_name3,phone_no1,phone_no2,phone_no3,email,password,address1,address2,address3,city,county,postcode,common_date,done_work,source,enquiry_status,sector,client_industry,enquiry_type,fixed_packages,fixed_amount,hourly_packages,hourly_amount,total_hours,is_enquiry)  (SELECT company_name,first_name1,last_name1,first_name2,last_name2,first_name3,last_name3,phone_no1,phone_no2,phone_no3,email,password,address1,address2,address3,city,county,postcode,common_date,done_work,source,enquiry_status,sector,client_industry,enquiry_type,fixed_packages,fixed_amount,hourly_packages,hourly_amount,total_hours,is_enquiry FROM job where id=$id)");	 
		$job_id = mysqli_insert_id($conn);
	
		$enquiry_date			= date("Y-m-d");
		$enquiry_by				= $_SESSION['user_id'];
		$updated_by				= $_SESSION['user_id'];
		$update_job = "UPDATE job SET enquiry_date='".$enquiry_date."', enquiry_by='".$enquiry_by."', updated_by='".$updated_by."' WHERE id='".$job_id."' ";
		mysqli_query($conn,$update_job);
	
		header("location: $file_name?page=add&action=edit&id=$job_id".$next_page_condition.$paging);
		exit();
	}
?>