<?php
include("../../../include/startup.php"); 
if(isset($_REQUEST['action']) && $_REQUEST['action']=='get_package_price'){
	$packages_id = $_REQUEST['packages_id'];
	$row = utility::getTableRowByField("fixed_packages","id",$packages_id);
	$returnArray["price"] = $row["price"];
	echo json_encode($returnArray);
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='get_hourly_packages_price'){
	$hourly_packages_id = $_REQUEST['hourly_packages_id'];
	$row = utility::getTableRowByField("hourly_packages","id",$hourly_packages_id);
	$returnArray["price"] = $row["price"];
	
	if($hourly_packages_id == 1){
		$months = 3;
	}else if($hourly_packages_id == 2){
		$months = 6;
	}else if($hourly_packages_id == 3){
		$months = 12;
	}
	//$days_in_a_month = utility::getTableFieldById('keycode','code','name','days_in_a_month');
	//$hours_in_a_day = utility::getTableFieldById('keycode','code','name','hours_in_a_day');
	//$total_hours = $months * $days_in_a_month * $hours_in_a_day;
	$total_hours = $row["total_consultancy_hours"];
	$returnArray["total_hours"] = $total_hours;
	echo json_encode($returnArray);
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='send_mail'){
	include('send_mail_modal.php');
	die;
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='mail_send'){
	$job_id = $_REQUEST['job_id'];
	$admin_id = utility::getTableFieldById("job_admin_mapping","admin_id","job_id",$job_id);
	$mail_format_subject = addslashes($_REQUEST['mail_format_subject']);
	$mail_format_body =  str_replace("Â","",$_REQUEST['mail_format_body']);
	$mail_format_body = addslashes($mail_format_body);
	$email_id = utility::getTableFieldById("job","email","id",$job_id);
	$email_id_test = "parvindar1995@gmail.com";
	
	$email_date = date("Y-m-d");
	$sql = "INSERT INTO email_track(job_id,email_subject,email_body,email_id,email_date) VALUES('$job_id','$mail_format_subject','$mail_format_body','$email_id','$email_date')";
	mysqli_query($conn,$sql);
	$email_track_id = mysqli_insert_id($conn);
	/***************************** File Upload *************************************************/
	$digits = 5;
	
	$file_path 		= array();
	foreach($_FILES['mail_document'] as $file_pro => $file_value){
		foreach($_FILES['mail_document'][$file_pro] as $k => $v){
			if(!(isset($v) && $v !="")){
				continue;
			}
			${$file_pro}[$k] = $v;
		}
    }
	foreach($name as $key => $file_name){
		$my_path = $_SERVER['DOCUMENT_ROOT']."/{$other_fields["project_folder_name"]}admin/document_upload/";
		
		$random_number = rand(pow(10, $digits-1), pow(10, $digits)-1);
		$uploaddir = '../../document_upload/';
		$document_name_array = explode(".",$file_name);
		$document_name = $document_name_array[0]."_".$random_number.".".$document_name_array[1];
		$uploadfile = $uploaddir . $document_name;
		array_push($file_path,$my_path.$document_name);
		move_uploaded_file($tmp_name[$key], $uploadfile);
		$sql= "INSERT into mail_document_upload(job_id,email_track_id,document_name) VALUES('$job_id','$email_track_id','$document_name')";
		mysqli_query($conn,$sql);
	}
	/***************************** End File Upload *************************************************/	
	$mail_format_subject = $_REQUEST['mail_format_subject'];
	$mail_format_body = $_REQUEST['mail_format_body'];
	//echo $functions->HTMLemailWithoutSignatureBlock($mail_format_body,$admin_id);
	//die;
	//////////////////////// send mail ////////////////////
	$site_email = $config->siteEmail;
	if(utility::mailSMTP_new($email_id, $mail_format_subject, $functions->HTMLemailWithoutSignatureBlock($mail_format_body,$admin_id), $file_path,$site_email,$site_email,"","","",$admin_id)){
		utility::mailSMTP_new($email_id_test, $mail_format_subject, $functions->HTMLemailWithoutSignatureBlock($mail_format_body,$admin_id), $file_path,$site_email,$site_email,"","","",$admin_id);
		echo "Mail send successfully";
	}else{
		echo "There is some error.";
	}
	die;
	///////////////// End send mail  //////////////////////
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='timer_time'){
	//date_default_timezone_set('Europe/London');
	$job_id = $_REQUEST['job_id'];
	$button = $_REQUEST['button'];
	if($button == "start"){
		$_SESSION["timer_running"] = 1;
		$sql = "SELECT * FROM timer WHERE job_id = $job_id ";
		$rs = mysqli_query($conn,$sql);
		if(mysqli_num_rows($rs) > 0){
			$row = mysqli_fetch_assoc($rs);
			$is_running = $row["is_running"];
			$changed_on = date('Y-m-d H:i:s');
			if($is_running == 0){
				mysqli_query($conn,"UPDATE timer SET is_running = '1',changed_on = '$changed_on' WHERE job_id = $job_id ");
				$t_time = $row['timer_time'];
				$t_time_array = explode(":",$t_time);
				$t_time_hours = $t_time_array[0];
				$t_time_mins = $t_time_array[1];
				$t_time_secs = $t_time_array[2];
				$returnArray = array();
				$returnArray['t_time_hours'] = ltrim($t_time_hours,'0'); 
				$returnArray['t_time_mins'] = ltrim($t_time_mins,'0');
				$returnArray['t_time_secs'] = ltrim($t_time_secs,'0'); 
				echo json_encode($returnArray);
				die;
			}
		}else{
			$changed_on = date('Y-m-d H:i:s');
			mysqli_query($conn,"INSERT into timer(job_id,is_start,is_running,timer_time,changed_on) VALUES('$job_id','1','1','00:00:00','$changed_on')");
		}
		die;
	}else if($button == "pause"){
		$changed_on = date('Y-m-d H:i:s');
		$timer_value = $_REQUEST['timer_value'];
		mysqli_query($conn,"UPDATE timer SET timer_time = '$timer_value',is_running = '0',changed_on = '$changed_on' WHERE job_id = $job_id ");
	}else if($button == "page_reload"){
		$timer_value = $_REQUEST['timer_value'];
		$sql = "SELECT * FROM timer WHERE job_id = $job_id AND is_start = '1' ";
		$rs = mysqli_query($conn,$sql);
		if(mysqli_num_rows($rs) > 0){
			$row = mysqli_fetch_assoc($rs);
			$is_running = $row["is_running"];
			if($is_running == 1){
				$changed_on = $row["changed_on"];
				$seconds  = strtotime(date('Y-m-d H:i:s')) - strtotime($changed_on);
				$timer_time = $gsi->getTimerTimeInSecondByJobId($job_id);
				$seconds  = $seconds + $timer_time;
	 
				$hours = floor($seconds / 3600);
				$mins = floor(($seconds - ($hours*3600)) / 60);
				$secs = floor($seconds % 60);
				$timer_value_new = $hours.":".$mins.":".$secs;
				$changed_on = date('Y-m-d H:i:s');
				mysqli_query($conn,"UPDATE timer SET timer_time = '$timer_value_new',changed_on = '$changed_on' WHERE job_id = $job_id ");
				$t_time = utility::getTableFieldById("timer","timer_time","job_id",$job_id);
				$t_time_array = explode(":",$t_time);
				$t_time_hours = $t_time_array[0];
				$t_time_mins = $t_time_array[1];
				$t_time_secs = $t_time_array[2];
				$returnArray = array();
				$returnArray['timer_value_new'] = $t_time; 
				$returnArray['t_time_hours'] = $hours; 
				$returnArray['t_time_mins'] = $mins; 
				$returnArray['t_time_secs'] = $secs; 
				echo json_encode($returnArray);
				die;
			}else{
				$returnArray = array();
				$t_time = utility::getTableFieldById("timer","timer_time","job_id",$job_id);
				$t_time_array = explode(":",$t_time);
				$t_time_hours = $t_time_array[0];
				$t_time_mins = $t_time_array[1];
				$t_time_secs = $t_time_array[2];
				$returnArray = array();
				$returnArray['timer_value_new'] = $t_time; 
				$returnArray['t_time_hours'] = ltrim($t_time_hours,'0'); 
				$returnArray['t_time_mins'] = ltrim($t_time_mins,'0');
				$returnArray['t_time_secs'] = ltrim($t_time_secs,'0'); 
				$returnArray['pause'] = 1; 
				echo json_encode($returnArray);
				die;
			}
		}
	}else if($button == "clear"){
		unset($_SESSION["timer_running"]);
		$timer_value = $_REQUEST['timer_value'];
		mysqli_query($conn,"UPDATE timer SET timer_time = '$timer_value',is_start = '0' WHERE job_id = $job_id ");
		$timer_time_in_second = $gsi->getTimerTimeInSecondByJobId($job_id);
		$timer_time_in_minute = $timer_time_in_second / 60;
		if($timer_time_in_minute <= 15){
			$timesheet_time = "00:15:00";
		}else if($timer_time_in_minute > 15 && $timer_time_in_minute <= 30){
			$timesheet_time = "00:30:00";
		}else if($timer_time_in_minute > 30 && $timer_time_in_minute <= 45){
			$timesheet_time = "00:45:00";
		}else if($timer_time_in_minute > 45 && $timer_time_in_minute <= 60){
			$timesheet_time = "00:60:00";
		}else if($timer_time_in_minute > 60 && $timer_time_in_minute <= 75){
			$timesheet_time = "01:15:00";
		}else if($timer_time_in_minute > 75 && $timer_time_in_minute <= 90){
			$timesheet_time = "01:30:00";
		}else{
			$timesheet_time = $timer_value;
		}
		///////////////////////// Timesheet Enrty /////////////////////////////////////
		$source =  $gsi->getEnqQuoteJobStatusById($job_id);	
		$admin_id = $_SESSION['user_id'];
		$timesheet_text = "Timesheet entry";
		//$entry_for_month = $gsi->getEntryForMonthByJobId($job_id);
		$timesheet_date	 = date("Y-m-d");
		//$timesheet_time = $timer_value;
		$created_on = date("Y-m-d");
		$sql= "INSERT INTO timesheet (job_id,source,admin_id,timesheet_text,timesheet_date,timesheet_time,updated_by,created_on) VALUES('$job_id','$source','$admin_id','$timesheet_text','$timesheet_date','$timesheet_time','".$_SESSION['user_id']."','$created_on')";
		mysqli_query($conn,$sql);
		///////////////////////// End Timesheet Enrty /////////////////////////////////////
		mysqli_query($conn,"DELETE FROM timer WHERE job_id = $job_id ");
	}
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='get_address_by_org_id'){
	$dataArray = array();
	$dataArray["status"] = 0;
	$org_id = $_REQUEST['org_id'];
	$sql = "SELECT * FROM organisation_management WHERE id = '$org_id' ";
	$rs = mysqli_query($conn,$sql);
	if(mysqli_num_rows($rs) > 0){
		$row = mysqli_fetch_assoc($rs);
		$row=utility::validate_crypt_data($row);
		
		$dataArray["address1"] 		= $row['address1'];
		$dataArray["address2"] 		= $row['address2'];
		$dataArray["address3"] 		= $row['address3'];
		$dataArray["city"] 			= $row['city'];
		$dataArray["county"] 		= $row['county'];
		$dataArray["postcode"] 		= $row['postcode'];
		$dataArray["phone_no"] 		= $row['phone_no'];
		$dataArray["landline_phone_no"] = $row['landline_phone_no'];
		$dataArray["status"]		= 1;
	}
	echo json_encode($dataArray);

}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='validate_client_email'){
	$email = utility::app_crypt($_REQUEST['email'],'e');
	$id = $_REQUEST['id'];
	$where = "";
	if(isset($id) && $id !=""){
		$where = " AND id != '$id' ";
	}
	$returnArray = array();
	$sql = "SELECT * FROM job WHERE email = '$email' $where";
	$rs = mysqli_query($conn,$sql);
	if(mysqli_num_rows($rs) > 0){
		$row = mysqli_fetch_assoc($rs);
		$returnArray['status'] = "failure";
	}else{
		$returnArray['status'] = "success";
	}
	echo json_encode($returnArray);	
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='validate_enquiry_email'){
	$email = utility::app_crypt($_REQUEST['email'],'e');
	$id = $_REQUEST['id'];
	$where = "";
	if(isset($id) && $id !=""){
		$where = " AND id != '$id' ";
	}
	$returnArray = array();
	$sql = "SELECT * FROM job WHERE email = '$email' $where";
	$rs = mysqli_query($conn,$sql);
	if(mysqli_num_rows($rs) > 0){
		$row = mysqli_fetch_assoc($rs);
		$returnArray['status'] = "failure";
	}else{
		$returnArray['status'] = "success";
	}
	echo json_encode($returnArray);	
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='count_no_of_appointment'){
	$returnArray = array();
	$returnArray["status"] = 0;
	$job_id = $_REQUEST['job_id'];
	$sql = "SELECT count(id) as total_appointment FROM appointment WHERE job_id = '$job_id' ";
	$rs = mysqli_query($conn,$sql);
	if(mysqli_num_rows($rs) > 0){
		$row = mysqli_fetch_assoc($rs);
		$returnArray["total_appointment"] = $row['total_appointment'];
		$returnArray["status"] = "success";
	}
	echo json_encode($returnArray);

}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='count_no_of_notes'){
	$returnArray = array();
	$returnArray["status"] = 0;
	$job_id = $_REQUEST['job_id'];
	$sql = "SELECT count(id) as total_notes FROM notes WHERE note_type = 0 AND job_id = '$job_id' ";
	$rs = mysqli_query($conn,$sql);
	if(mysqli_num_rows($rs) > 0){
		$row = mysqli_fetch_assoc($rs);
		$returnArray["total_notes"] = $row['total_notes'];
		$returnArray["status"] = "success";
	}
	echo json_encode($returnArray);

}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='count_no_of_reminder'){
	$returnArray = array();
	$returnArray["status"] = 0;
	$job_id = $_REQUEST['job_id'];
	$sql = "SELECT count(id) as total_reminder FROM notes WHERE note_type = 1 AND job_id = '$job_id' ";
	$rs = mysqli_query($conn,$sql);
	if(mysqli_num_rows($rs) > 0){
		$row = mysqli_fetch_assoc($rs);
		$returnArray["total_reminder"] = $row['total_reminder'];
		$returnArray["status"] = "success";
	}
	echo json_encode($returnArray);

}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='enquiry_search_postcode'){
	$enquiry_search_postcode = rawurlencode($_REQUEST['enquiry_search_postcode']);
	//$enquiry_search_postcode = urlencode($enquiry_search_postcode);
	$url = "https://api.getAddress.io/find/".$enquiry_search_postcode."?api-key=G634Ejo6I0WwbLwhIls7UA22555&expand=true";
	
	$client = curl_init($url);
	curl_setopt($client,CURLOPT_RETURNTRANSFER,true);
	$response = curl_exec($client);

	$result = json_decode($response,true); 
	 //////////////////////////////////////////////////////////////////////////////////////////////
	 /* 
	 $result = array
	(
		"postcode" => "NN3 6ES",
		"latitude" => "52.266918182373",
		"longitude" => "-0.87506705522537",
		"addresses" => array
			(
				"0" => array
					("formatted_address" => array(
								"0" => "1 Thruxton Drive",
								"1" => "",
								"2" => "",
								"3" => "Northampton",
								"4" => "Northamptonshire",
							),
						"thoroughfare" => "Thruxton Drive",
						"building_name" => "",
						"sub_building_name" => "",
						"sub_building_number" =>"", 
						"building_number" => "1",
						"line_1" => "1 Thruxton Drive",
						"line_2" => "",
						"line_3" => "",
						"line_4" => "",
						"locality" => "",
						"town_or_city" => "Northampton",
						"county" => "Northamptonshire",
						"district" => "Northampton",
						"country" => "England",
					)
		   )

	);
	  */
	 //////////////////////////////////////////////////////////////////////////////////////////////
	$address_array = array(); 
	$drop_down_array_text = "";
	$drop_down_array_value = "";
	foreach($result['addresses'] as $add_key=>$add_val){
			
			if($add_val['line_1']){
				$drop_down_array_text .= $add_val['line_1']." ";
				
			}
			$drop_down_array_value .= $add_val['line_1']."##";
			if($add_val['line_2']){
				$drop_down_array_text .= $add_val['line_2']." ";
				
			}
			$drop_down_array_value .= $add_val['line_2']."##";
			if($add_val['line_3']){
				$drop_down_array_text .= $add_val['line_3']." ";
				
			}
			$drop_down_array_value .= $add_val['line_3']."##";
			if($add_val['line_4']){
				$drop_down_array_text .= $add_val['line_4']." ";
				
			}
			$drop_down_array_value .= $add_val['line_4']."##";
			if($add_val['town_or_city']){
				$drop_down_array_text .= $add_val['town_or_city']." ";
				
			}
			$drop_down_array_value .= $add_val['town_or_city']."##";
			if($add_val['county']){
				$drop_down_array_text .= $add_val['county']." ";
				
			}
			
			
			$drop_down_array_value .= utility::getTableFieldById("county","id","county",$add_val['county'])."##";
			
			$drop_down_array_value .= $_REQUEST['enquiry_search_postcode']."##";
			
			$drop_down_array_text = substr($drop_down_array_text,0,-1);
			//$drop_down_array_value = substr($drop_down_array_value,0,-2);
			
			$address_array[$drop_down_array_value] = $drop_down_array_text;
			$drop_down_array_value = "";
			$drop_down_array_text ="";
			/* echo "line_1".$add_val['line_1']."<br>";	
			echo "town_or_city".$add_val['town_or_city']."<br>";	
			echo "county".$add_val['county']."<br>";	
			echo "===============================================<br>";	 */
	} 
	ob_clean();
	echo utility::createList($address_array,"enquiry_address_list","","100%","Select Address",false,"form-control select2");
	
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='update_status_active_inactive'){
	$returnArray = array();
	$job_id 		= $_REQUEST['job_id'];
	$active 	    = $_REQUEST['active'];
	$updated_by	    = $_SESSION['user_id'];
	
	$sql = "SELECT id FROM job WHERE id = '$job_id' ";
	$rs = mysqli_query($conn,$sql);
	if(mysqli_num_rows($rs) > 0){
		$row = mysqli_fetch_assoc($rs);
		$id = $row['id'];
		
		$update_message = "UPDATE job SET status = '".$active."', updated_by = '".$updated_by."' WHERE id = '$id' ";
		mysqli_query($conn,$update_message);
		
		$returnArray["status"] = "success";
		
	}	
	echo json_encode($returnArray);
	die;
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='update_enquiry_tab_session_info'){
	$_SESSION['tabbs']=$_REQUEST['tabb'];
}
else if(isset($_REQUEST['action']) && $_REQUEST['action']=='add_job_notes'){ 


	////////////// For Insert and Update ///////////////////////////
	utility::addslashesOnAllInput(array("query_string"));
	
	$id					 = $_REQUEST['id'];
	$page_action		 = $_REQUEST['page_action_notes'];
	$job_id		 		 = $_REQUEST['job_id'];
	$job_name		 	 = $_REQUEST['job_name'];
	$date		 	     = utility::setFormatedDate($_REQUEST['date']);
	$job_details_id		 	 = $_REQUEST['details'];
	$hours		 	 	 = $_REQUEST['hours'];
	$miles		 	 	 = $_REQUEST['miles'];
	$created_by			 = $_SESSION["user_id"];
	$updated_by		 	 = $_SESSION["user_id"];
	$created_on		 	 = date("Y-m-d H:i:s");
	
	$new_details 				= $_REQUEST['new_details'];
	if(isset($new_details) && $new_details !=""){
		$max_order = Keycode::getMaxKeycodeOrderByName("job_details") + 1;
		$sql1= "INSERT INTO keycode(name,code,ord) VALUES('job_details','$new_details','$max_order')";
		mysqli_query($conn,$sql1);
		$job_details_id = mysqli_insert_id($conn);
	}
	if($page_action == "add"){
		$sql = "job_id = '".$job_id."',job_name = '".$job_name."',date = '".$date."',
		details = '".$job_details_id."', hours = '".$hours."', miles = '".$miles."',
		created_by = '".$created_by."', created_on = '".$created_on."', updated_by = '".$updated_by."'";
	   $sql= "INSERT INTO job_schedular SET ".$sql;
		mysqli_query($conn,$sql);
		 
	}else{
		$sql = "job_id = '".$job_id."',date = '".$date."', details = '".$details."', hours = '".$hours."', miles = '".$miles."',updated_by = '".$updated_by."'";
		$sql = "UPDATE job_schedular SET ".$sql." WHERE id = '".$id."'";
		mysqli_query($conn,$sql);
	}
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='ajax_job_notes_fetch_1'){ 
	////////////// For Listing data through JSON ///////////////////////////
	echo$date11 = $_REQUEST['date_'];
    $query_for_notes = "SELECT * FROM job_schedular WHERE 1=1 and date='$date11' ORDER BY id DESC ";
	$sql_for_notes = mysqli_query($conn,$query_for_notes);
	$result_for_notes = mysqli_num_rows($sql_for_notes);
	$notes_post_out = "";
	if($result_for_notes > 0){
		
		$notes_post_out .= '{';
		$notes_post_out .= '"data" : [';
		while($row_notes = mysqli_fetch_assoc($sql_for_notes)){
	   	$notes_post_out .= '{"details":"'  . Keycode::getKeycodeById($row_notes['details']). '",';
			$notes_post_out .= '"hours":"'  .$row_notes["hours"]. '",';
			$notes_post_out .= '"miles":"'  .$row_notes["miles"]. '",';
			$notes_post_out .= '"job_name":"'  .$row_notes["job_name"]. '",';
			$notes_post_out .= '"date":"'  .utility::getFormatedDateReturn($row_notes["date"]). '",';
			$notes_post_out .= '"job_id":"'  . $gsi->getEnqJobNumberById($row_notes["job_id"]). '",';
			
			$notes_post_out .= '"created_on":"'  . date("d-m-Y g:i:s A", strtotime($row_notes['created_on'])). '",';
			
			 if(date("l", strtotime($row_notes['created_on'])) == 'Monday'){
				$tr_bg_color = "blue";  // Monday
			} else if(date("l", strtotime($row_notes['created_on'])) == 'Tuesday'){
				$tr_bg_color = "#f3b1a6";    // Tuesday
			} else if(date("l", strtotime($row_notes['created_on'])) == 'Wednesday'){
				$tr_bg_color = "green";    // Wednesday
			} else if(date("l", strtotime($row_notes['created_on'])) == 'Thursday'){
				$tr_bg_color = "#8d8de4";    // Thursday
			}else if(date("l", strtotime($row_notes['created_on'])) == 'Friday'){
				$tr_bg_color = "#8d8de4";    // Friday
			}else if(date("l", strtotime($row_notes['created_on'])) == 'Saturday'){
				$tr_bg_color = "#8d8de4";    // Saturday
			}else if(date("l", strtotime($row_notes['created_on'])) == 'Sunday'){
				$tr_bg_color = "blue";    // Sunday
			}
			
			
			$notes_post_out .= '"tr_bg_color":"'  . $tr_bg_color . '",';
			$notes_post_out .= '"id":"'  . $row_notes['id'] . '"},';
		}
		$notes_post_out = substr($notes_post_out,0,-1);
		$notes_post_out .= "]";
		$notes_post_out .= '}';
	}else{
		$notes_post_out .= '{';
		$notes_post_out .= '"data" : [';
		$notes_post_out .= "]";
		$notes_post_out .= '}';
	}
	echo $notes_post_out;
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='get_edit_job_notes'){
	$id = $_REQUEST['id'];
	$sql= "SELECT * FROM job_schedular WHERE id = '$id'";
    $result_edit = mysqli_query($conn,$sql);
    $row_edit = mysqli_fetch_assoc($result_edit);

    $data_array = array();
	foreach($row_edit as $key => $value){
		if($key == "created_on"){
			$value = utility::getFormatedDateReturn($value);
		}else{
			$data_array[$key] = $value;
		}
	}
	
	$returnArray["data_array"] = $data_array;
	$returnArray["status"] = "success";
	echo json_encode($returnArray, JSON_FORCE_OBJECT);
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='delete_job_notes'){
	$notes_id = $_REQUEST['notes_id'];
	mysqli_query($conn,"DELETE FROM job_schedular WHERE id = '$notes_id'");
	$returnArray["status"] = "success";
	echo json_encode($returnArray);
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='getjob_id_by_job_name'){
	$dataArray = array();
	$dataArray["status"] = "failure";
	$job_id = $_REQUEST['job_id'];
   $sql = "SELECT id,address1,address2,address3,town,county,postcode FROM job  WHERE id = '$job_id' ";
	$rs = mysqli_query($conn,$sql);
	if(mysqli_num_rows($rs) > 0){
		$row = mysqli_fetch_assoc($rs);
		
		$dataArray["status"] = "success";
		$address = "";
		if(isset($row["address1"]) && $row["address1"] !=""){
			$address .= $row["address1"].", ";
		}
		if(isset($row["address2"]) && $row["address2"] !=""){
			$address .= $row["address2"].", ";
		}
		if(isset($row["address3"]) && $row["address3"] !=""){
			$address .= $row["address3"].", ";
		}
		if(isset($row["town"]) && $row["town"] !=""){
			$address .= $row["town"].", ";
		}
		if(isset($row["county"]) && $row["county"] !=""){
			$address .= $gsi->getCountyById($row['county']).", ";
		}
		if(isset($row["postcode"]) && $row["postcode"] !=""){
			$address .= $row['postcode'];
		}
		//echo $address;
		$dataArray["address"] = $address;
	}
	echo json_encode($dataArray);
	die;
}
die;
?>