<?php 
include("includes/FCKeditor/fckeditor.php");
$file_name		= "index?page=view_celebrant";
$form_action	= "insert";
$button_value 	= "Add";
$table_name 	= "job";
$id	 = "";
$vat = "";
$query_string = "";
$page_name      = "Add Quotation";
$renewal_dates = date("d-m-Y");
$enquiry_date = date("d-m-Y");
$from = $_REQUEST['from'];
$prospect_status = utility::getTableFieldByTwoCondition("keycode","id","name","prospect_status","code","New");
################################################## START INSERT ##################################################
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'insert'){	
	utility::addslashesOnAllInput(array("query_string","admin_id","celebrant_mentor","sector","accreditation_observer","type_of_celebrant"));
    $org_id		 			= $_REQUEST['org_id']; 
    $company_name 			= $_REQUEST['company_name']; 
    $title 			= $_REQUEST['title']; 
    $first_name 			= $_REQUEST['first_name']; 
    $last_name 				= $_REQUEST['last_name']; 
    $profession 				= $_REQUEST['profession']; 
    $target_market 				= $_REQUEST['target_market']; 
    $phone_no 				= $_REQUEST['phone_no'];
    $landline_phone_no 		= $_REQUEST['landline_phone_no'];
    $email					= $_REQUEST['email'];
	$password				= $_REQUEST['password'];
    $address1 				= $_REQUEST['address1'];
    $address2 				= $_REQUEST['address2'];
    $address3 				= $_REQUEST['address3'];
	$contact1name 			= $_REQUEST['contact1name'];
    $contact1position 		= $_REQUEST['contact1position'];
    $contact2name 			= $_REQUEST['contact2name'];
    $contact2position 		= $_REQUEST['contact2position'];
    $city 					= $_REQUEST['city'];
    $county 				= $_REQUEST['county'];
    $postcode 				= $_REQUEST['postcode'];
	$turnover 						= $_REQUEST['turnover'];
	$number_of_employees	= (isset($_REQUEST['number_of_employees']) && $_REQUEST['number_of_employees'] != '') ? $_REQUEST['number_of_employees'] : '0';
	$insurance_type	= (isset($_REQUEST['insurance_type']) && $_REQUEST['insurance_type'] != '') ? $_REQUEST['insurance_type'] : '0';
	//$insurance_type = Keycode::otherDataInsertIfNotExist('insurance_type',$insurance_type);
	//$business_type	 				= $_REQUEST['business_type'];
	$business_type	= (isset($_REQUEST['business_type']) && $_REQUEST['business_type'] != '') ? $_REQUEST['business_type'] : '0';
	//$policy_type	 				= $_REQUEST['policy_type'];
	$policy_type	= (isset($_REQUEST['policy_type']) && $_REQUEST['policy_type'] != '') ? $_REQUEST['policy_type'] : '0';
	//$contact_method					= $_REQUEST['contact_method'];
	$contact_method	= (isset($_REQUEST['contact_method']) && $_REQUEST['contact_method'] != '') ? $_REQUEST['contact_method'] : '0';
    //$prospect_traffic_lights		= $_REQUEST['prospect_traffic_lights'];
	$prospect_traffic_lights	= (isset($_REQUEST['prospect_traffic_lights']) && $_REQUEST['prospect_traffic_lights'] != '') ? $_REQUEST['prospect_traffic_lights'] : '0';
	$renewal_dates 			= utility::setFormatedDate($_REQUEST['renewal_dates']);
    $enquiry_date 			= utility::setFormatedDate($_REQUEST['enquiry_date']);
	
    $type_of_celebrant				= implode(",",$_REQUEST['type_of_celebrant']);
    //$celebrant_status				= $_REQUEST['celebrant_status'];
	$celebrant_status				= (isset($_REQUEST['celebrant_status']) && $_REQUEST['celebrant_status'] != '') ? $_REQUEST['celebrant_status'] : '0';
    $celebrant_mentor				= implode(",",$_REQUEST['celebrant_mentor']);
    $accreditation_observer			= implode(",",$_REQUEST['accreditation_observer']);
    $sector 						= implode(",",$_REQUEST['sector']);   
    $peer_observation_date			= utility::setFormatedDate(isset($_REQUEST['peer_observation_date']) && $_REQUEST['peer_observation_date'] != '') ? $_REQUEST['peer_observation_date'] : '0000-00-00 00:00:00';   
    $cpd_complete_date				= utility::setFormatedDate(isset($_REQUEST['cpd_complete_date']) && $_REQUEST['cpd_complete_date'] != '') ? $_REQUEST['cpd_complete_date'] : '0000-00-00 00:00:00';
    $last_spoke_date				= utility::setFormatedDate(isset($_REQUEST['last_spoke_date']) && $_REQUEST['last_spoke_date'] != '') ? $_REQUEST['last_spoke_date'] : '0000-00-00 00:00:00';
	$is_celebrant					= 1;
	$is_archive 					= (isset($_REQUEST['is_archive']) && $_REQUEST['is_archive'] !="") ? 1 : 0;
	$celebrant_date					= date("Y-m-d H:i:s");	
	$celebrant_by					= $_SESSION['user_id'];
	$updated_by						= $_SESSION['user_id'];
	$lead_consultant		= $_REQUEST['lead_consultant'];
	$created_on					= date("Y-m-d H:i:s");	
	$created_by					= $_SESSION['user_id'];
	
	$sector_name_new 				= $_REQUEST['sector_name_new'];
	if(isset($sector_name_new) && $sector_name_new !=""){
		$max_order = Keycode::getMaxKeycodeOrderByName("sector") + 1;
		$sql1= "INSERT INTO keycode(name,code,ord) VALUES('sector','$sector_name_new','$max_order')";
		mysqli_query($conn,$sql1);
		$sector = mysqli_insert_id($conn);
	}
	
	
    //$sql= "INSERT INTO $table_name (company_name,title,first_name,last_name,profession,target_market,phone_no,landline_phone_no,email,password,address1,address2,address3,contact1name,contact1position,contact2name,contact2position,city,county,postcode,turnover,number_of_employees,insurance_type,business_type,policy_type,contact_method,prospect_traffic_lights,renewal_dates,enquiry_date,type_of_celebrant,celebrant_status,celebrant_mentor,accreditation_observer,sector,is_celebrant,is_archive,peer_observation_date,cpd_complete_date,last_spoke_date,celebrant_by,updated_by,lead_consultant) VALUES('$company_name','$title','$first_name','$last_name','$profession','$target_market','$phone_no','$landline_phone_no','$email','$password','$address1','$address2','$address3','$contact1name','$contact1position','$contact2name','$contact2position','$city','$county','$postcode','$turnover','$number_of_employees','$insurance_type','$business_type','$policy_type','$contact_method','$prospect_traffic_lights','$renewal_dates','$enquiry_date','$type_of_celebrant','$celebrant_status','$celebrant_mentor','$accreditation_observer','$sector','$is_celebrant','$is_archive','$peer_observation_date','$cpd_complete_date','$last_spoke_date','$celebrant_by','$updated_by','$lead_consultant')";
	
	$sql = "org_id = '".$org_id."', company_name = '".$company_name."', title = '".$title."', first_name = '".$first_name."', last_name = '".$last_name."', profession = '".$profession."', target_market = '".$target_market."', phone_no = '".$phone_no."',landline_phone_no = '".$landline_phone_no."', email = '".$email."', password = '".$password."', address1 = '".$address1."', address2 = '".$address2."', address3 = '".$address3."', contact1name = '".$contact1name."', contact1position = '".$contact1position."', contact2name = '".$contact2name."', contact2position = '".$contact2position."', city = '".$city."', county = '".$county."', postcode = '".$postcode."', number_of_employees = '".$number_of_employees."', insurance_type = '".$insurance_type."', business_type = '".$business_type."', policy_type = '".$policy_type."', contact_method = '".$contact_method."', prospect_traffic_lights = '".$prospect_traffic_lights."', renewal_dates = '".$renewal_dates."', enquiry_date = '".$enquiry_date."', type_of_celebrant = '".$type_of_celebrant."', celebrant_status = '".$celebrant_status."', celebrant_mentor = '".$celebrant_mentor."', accreditation_observer = '".$accreditation_observer."', sector = '".$sector."', is_celebrant = '".$is_celebrant."', is_archive = '".$is_archive."', peer_observation_date = '".$peer_observation_date."', cpd_complete_date = '".$cpd_complete_date."', last_spoke_date = '".$last_spoke_date."', celebrant_date = '".$celebrant_date."', celebrant_by = '".$celebrant_by."', updated_by = '".$updated_by."', lead_consultant = '".$lead_consultant."', created_on = '".$created_on."', created_by = '".$created_by."'";
	$sql=utility::convert_to_crypt_data($sql,$table_name);
	$sql= "INSERT INTO $table_name SET ".$sql;
    mysqli_query($conn,$sql);
	$job_id = mysqli_insert_id($conn);
	
	if(isset($_REQUEST['phone_no']) && $_REQUEST['phone_no'] != ""){
		$phone_log = utility::app_crypt($job_id,"e");
		$sql = "INSERT INTO job_phone_log(phone_log,phone) VALUES('$phone_log','".$_REQUEST['phone_no']."') ";
		mysqli_query($conn,$sql);
	}
	if(isset($_REQUEST['email']) && $_REQUEST['email'] != ""){
		$email_log = utility::app_crypt($job_id,"e");
		$sql = "INSERT INTO job_email_log(email_log,email) VALUES('$email_log','".$_REQUEST['email']."') ";
		mysqli_query($conn,$sql);
	}
	
	if(count($_REQUEST['admin_id']) > 0){
		foreach($_REQUEST['admin_id'] as $admin_id){
			$sql= "INSERT INTO job_admin_mapping (job_id,admin_id) VALUES('$job_id','$admin_id')";
			mysqli_query($conn,$sql);
		}
	}
	
	$_SESSION['info_message'] = "Quotation added sucessfully";
	header("Location: $file_name");
    exit();
}
################################################# END INSERT #################################################

################################################## START EDIT ##################################################
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit'){	
	$id = $_REQUEST['id'];
	
	$j_id = utility::app_crypt($_REQUEST['j_id'],'d');
	if($id != $j_id){
		die("Invaild URL");
	}
	
	$form_action 	= "update";
	$button_value 	= "Update";
	$page_name      = "Edit Quotation";
	$query_string 	=  (isset($_POST['query_string'])) ? $_POST['query_string'] : $_SERVER['QUERY_STRING'];
	
    $sql= "SELECT * FROM $table_name WHERE id = $id";
    $result_edit = mysqli_query($conn,$sql);
    $row_edit = mysqli_fetch_array($result_edit);
	$row_edit = utility::validate_crypt_data($row_edit);

    $org_id= $row_edit['org_id'];
	$company_name= $row_edit['company_name'];
    $title= $row_edit['title'];
    $first_name= $row_edit['first_name'];
    $last_name= $row_edit['last_name'];
    $profession= $row_edit['profession'];
    $target_market= $row_edit['target_market'];
    $phone_no= $row_edit['phone_no'];
    $landline_phone_no= $row_edit['landline_phone_no'];
    $email= $row_edit['email'];
    $password= "";//$row_edit['password'];
    $address1= $row_edit['address1'];
    $address2= $row_edit['address2'];
    $address3= $row_edit['address3'];
	$contact1name= $row_edit['contact1name'];
    $contact1position= $row_edit['contact1position'];
    $contact2name= $row_edit['contact2name'];
    $contact2position= $row_edit['contact2position'];
    $city= $row_edit['city'];
    $county= $row_edit['county'];
    $postcode= $row_edit['postcode'];
    $turnover= $row_edit['turnover'];
    $number_of_employees= $row_edit['number_of_employees'];
    $insurance_type= $row_edit['insurance_type'];
    $business_type= $row_edit['business_type'];
    $policy_type= $row_edit['policy_type'];
    $contact_method= $row_edit['contact_method'];
    $prospect_traffic_lights= $row_edit['prospect_traffic_lights'];
    $renewal_dates= $row_edit['renewal_dates'];
    $enquiry_date= $row_edit['enquiry_date'];
    $lead_consultant= $row_edit['lead_consultant'];
    
    $type_of_celebrant		= explode(",",$row_edit['type_of_celebrant']);
    $celebrant_status		= $row_edit['celebrant_status'];
    $celebrant_mentor		= explode(",",$row_edit['celebrant_mentor']);
    $accreditation_observer	= explode(",",$row_edit['accreditation_observer']);
	$peer_observation_date	= $row_edit['peer_observation_date'];   
    $cpd_complete_date		= $row_edit['cpd_complete_date'];   
    $last_spoke_date		= $row_edit['last_spoke_date'];
    $sector					= explode(",",$row_edit['sector']);
    $is_archive= $row_edit['is_archive'];
	
	
	$admin_id = array();
	$sql_for_job_admin = "SELECT * FROM job_admin_mapping WHERE job_id = $id";
	$result_for_job_admin = mysqli_query($conn,$sql_for_job_admin);
    while($row_for_job_admin = mysqli_fetch_array($result_for_job_admin)){
		array_push($admin_id,$row_for_job_admin["admin_id"]);
	}	
}
################################################# END EDIT ################################################# 


################################################## START UPDATE ################################################## 
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'update'){    
	utility::addslashesOnAllInput(array("query_string","admin_id","celebrant_mentor","sector","accreditation_observer","type_of_celebrant"));
	$id= $_REQUEST['id'];
	$org_id= $_REQUEST['org_id'];
	$company_name= $_REQUEST['company_name'];
	$title= $_REQUEST['title'];
	$first_name= $_REQUEST['first_name'];
	$last_name= $_REQUEST['last_name'];
	$profession= $_REQUEST['profession'];
	$target_market= $_REQUEST['target_market'];
    $phone_no= $_REQUEST['phone_no'];
    $landline_phone_no= $_REQUEST['landline_phone_no'];
    $email= $_REQUEST['email'];
	$update_password = (!empty($_REQUEST['password'])) ? " password= '".$_REQUEST['password']."' , " : "";
    $address1= $_REQUEST['address1'];
    $address2= $_REQUEST['address2'];
    $address3= $_REQUEST['address3'];
	$contact1name 			= $_REQUEST['contact1name'];
    $contact1position 		= $_REQUEST['contact1position'];
    $contact2name 			= $_REQUEST['contact2name'];
    $contact2position 		= $_REQUEST['contact2position'];
    $city= $_REQUEST['city'];
    $county= $_REQUEST['county'];
    $postcode= $_REQUEST['postcode'];
    $turnover= $_REQUEST['turnover'];
    //$number_of_employees= $_REQUEST['number_of_employees'];
    //$insurance_type= $_REQUEST['insurance_type'];
    $number_of_employees	= (isset($_REQUEST['number_of_employees']) && $_REQUEST['number_of_employees'] != '') ? $_REQUEST['number_of_employees'] : '0';
	$insurance_type	= (isset($_REQUEST['insurance_type']) && $_REQUEST['insurance_type'] != '') ? $_REQUEST['insurance_type'] : '0';
	//$insurance_type = Keycode::otherDataInsertIfNotExist('insurance_type',$insurance_type);
	//$business_type	 				= $_REQUEST['business_type'];
	$business_type	= (isset($_REQUEST['business_type']) && $_REQUEST['business_type'] != '') ? $_REQUEST['business_type'] : '0';
	//$policy_type	 				= $_REQUEST['policy_type'];
	$policy_type	= (isset($_REQUEST['policy_type']) && $_REQUEST['policy_type'] != '') ? $_REQUEST['policy_type'] : '0';
	//$contact_method					= $_REQUEST['contact_method'];
	$contact_method	= (isset($_REQUEST['contact_method']) && $_REQUEST['contact_method'] != '') ? $_REQUEST['contact_method'] : '0';
    //$prospect_traffic_lights		= $_REQUEST['prospect_traffic_lights'];
	$prospect_traffic_lights	= (isset($_REQUEST['prospect_traffic_lights']) && $_REQUEST['prospect_traffic_lights'] != '') ? $_REQUEST['prospect_traffic_lights'] : '0';
    $renewal_dates= utility::setFormatedDate($_REQUEST['renewal_dates']);
    $enquiry_date= utility::setFormatedDate($_REQUEST['enquiry_date']);
	
    $type_of_celebrant				= implode(",",$_REQUEST['type_of_celebrant']);
    //$celebrant_status				= $_REQUEST['celebrant_status'];
	$celebrant_status				= (isset($_REQUEST['celebrant_status']) && $_REQUEST['celebrant_status'] != '') ? $_REQUEST['celebrant_status'] : '0';
    $celebrant_mentor				= implode(",",$_REQUEST['celebrant_mentor']);
    $accreditation_observer			= implode(",",$_REQUEST['accreditation_observer']);
	$peer_observation_date			= utility::setFormatedDate(isset($_REQUEST['peer_observation_date']) && $_REQUEST['peer_observation_date'] != '') ? $_REQUEST['peer_observation_date'] : '0000-00-00 00:00:00';   
    $cpd_complete_date				= utility::setFormatedDate(isset($_REQUEST['cpd_complete_date']) && $_REQUEST['cpd_complete_date'] != '') ? $_REQUEST['cpd_complete_date'] : '0000-00-00 00:00:00';
    $last_spoke_date				= utility::setFormatedDate(isset($_REQUEST['last_spoke_date']) && $_REQUEST['last_spoke_date'] != '') ? $_REQUEST['last_spoke_date'] : '0000-00-00 00:00:00';
    $sector= implode(",",$_REQUEST['sector']);
	$is_archive= (isset($_REQUEST['is_archive']) && $_REQUEST['is_archive'] !="") ? 1 : 0;
	
	$updated_by	= $_SESSION['user_id'];
	$lead_consultant	= $_REQUEST['lead_consultant'];
	
	$sector_name_new 				= $_REQUEST['sector_name_new'];
	if(isset($sector_name_new) && $sector_name_new !=""){
		$max_order = Keycode::getMaxKeycodeOrderByName("sector") + 1;
		$sql1= "INSERT INTO keycode(name,code,ord) VALUES('sector','$sector_name_new','$max_order')";
		mysqli_query($conn,$sql1);
		$sector = mysqli_insert_id($conn);
	}
	

   //$sql= "UPDATE $table_name SET company_name = '$company_name',title = '$title',first_name = '$first_name',last_name = '$last_name',profession = '$profession',target_market = '$target_market', phone_no = '$phone_no', landline_phone_no='$landline_phone_no', email = '$email', $update_password address1 = '$address1', address2 = '$address2', address3 = '$address3', contact1name = '$contact1name', contact1position = '$contact1position', contact2name = '$contact2name', contact2position = '$contact2position', city = '$city', county = '$county', postcode = '$postcode', turnover = '$turnover', number_of_employees = '$number_of_employees', insurance_type = '$insurance_type', business_type = '$business_type', policy_type = '$policy_type', contact_method = '$contact_method', prospect_traffic_lights = '$prospect_traffic_lights', renewal_dates = '$renewal_dates', enquiry_date = '$enquiry_date', type_of_celebrant='$type_of_celebrant', celebrant_status='$celebrant_status', celebrant_mentor='$celebrant_mentor',accreditation_observer='$accreditation_observer',peer_observation_date='$peer_observation_date',cpd_complete_date='$cpd_complete_date',last_spoke_date='$last_spoke_date', sector = '$sector',is_archive = '$is_archive', updated_by = '$updated_by', lead_consultant = '$lead_consultant' WHERE id = $id";
   
    $sql = "org_id = '".$org_id."', company_name = '".$company_name."', title = '".$title."', first_name = '".$first_name."', last_name = '".$last_name."', profession = '".$profession."', target_market = '".$target_market."', phone_no = '".$phone_no."',landline_phone_no = '".$landline_phone_no."', email = '".$email."', $update_password address1 = '".$address1."', address2 = '".$address2."', address3 = '".$address3."', contact1name = '".$contact1name."', contact1position = '".$contact1position."', contact2name = '".$contact2name."', contact2position = '".$contact2position."', city = '".$city."', county = '".$county."', postcode = '".$postcode."', number_of_employees = '".$number_of_employees."', insurance_type = '".$insurance_type."', business_type = '".$business_type."', policy_type = '".$policy_type."', contact_method = '".$contact_method."', prospect_traffic_lights = '".$prospect_traffic_lights."', renewal_dates = '".$renewal_dates."', enquiry_date = '".$enquiry_date."', type_of_celebrant = '".$type_of_celebrant."', celebrant_status = '".$celebrant_status."', celebrant_mentor = '".$celebrant_mentor."', accreditation_observer = '".$accreditation_observer."', sector = '".$sector."', is_archive = '".$is_archive."', peer_observation_date = '".$peer_observation_date."', cpd_complete_date = '".$cpd_complete_date."', last_spoke_date = '".$last_spoke_date."', updated_by = '".$updated_by."', lead_consultant = '".$lead_consultant."'";
	$sql=utility::convert_to_crypt_data($sql,$table_name);
	$sql= "UPDATE $table_name SET ".$sql." WHERE id = '".$id."'";
	mysqli_query($conn,$sql);
	
	$phone_log = utility::app_crypt($id,"e");
	$old_phone_no = utility::getTableFieldById('job_phone_log','phone','phone_log',$phone_log);
	if($_REQUEST['phone_no'] != $old_phone_no){
		$sql = "UPDATE job_phone_log SET phone = '".$_REQUEST['phone_no']."' WHERE phone_log = '$phone_log' ";
		mysqli_query($conn,$sql);
	}
	
	$email_log = utility::app_crypt($id,"e");
	$old_email = utility::getTableFieldById('job_email_log','email','email_log',$email_log);
	if($_REQUEST['email'] != $old_email){
		$sql = "UPDATE job_email_log SET email = '".$_REQUEST['email']."' WHERE email_log = '$email_log' ";
		mysqli_query($conn,$sql);
	}
	
	if(count($_REQUEST['admin_id']) > 0){
		mysqli_query($conn,"DELETE FROM job_admin_mapping WHERE job_id = $id ");
		foreach($_REQUEST['admin_id'] as $admin_id){
			$sql= "INSERT INTO job_admin_mapping (job_id,admin_id) VALUES('$id','$admin_id')";
			mysqli_query($conn,$sql);
		}
	}
	
	$query_string = (isset($_REQUEST['query_string']) && !empty($_REQUEST['query_string'])) ? $_REQUEST['query_string'] : "";
	if(strpos($query_string,"from=view_enquiry_for_user") > 0){
		$query_string = str_ireplace("page=add", "page=view_enquiry_for_user", $query_string);
		$query_string = "&".$query_string;
		
		$_SESSION['info_message'] = "Quotation updated sucessfully";
		header("Location: $file_name$query_string");
		exit();
	}
  	$query_string = str_ireplace("page=add_celebrant", "page=view_celebrant", $query_string);
	$query_string = "&".$query_string;
	
	$j_id = urlencode(utility::app_crypt($id,'e'));
	
	$_SESSION['info_message'] = "Quotation updated sucessfully";
	if(isset($from) && $from == "view_enquiry_progress"){
		header("Location: index?page=view_enquiry_progress&from=view_celebrant&j_id=$j_id&id=$id");
		exit();
	}
	
    header("Location: $file_name$query_string");
    exit();
}
################################################# END UPDATE ################################################# 
?>
<style>
em{color:red;font-size: 20px;position: absolute;}
</style>
<section class="content-header">
	<div class="container-fluid">
		<div class="row mb-2">
			<div class="col-sm-6">
				<h1>
					<?=$page_name;?>
				</h1>
			</div>
			<div class="col-sm-6">
				<?
				$query_string 	=  (isset($_POST['query_string'])) ? $_POST['query_string'] : $_SERVER['QUERY_STRING'];
				if(isset($from) && $from == "view_enquiry_progress"){
					$query_string = str_ireplace("page=add_celebrant", "page=view_enquiry_progress", $query_string);
				}else {
					$query_string = str_ireplace("page=add_celebrant", "page=view_celebrant", $query_string);
				}
				?>
				<button type="button" id="back" name="back" value="back"  style="float:right;margin-right:5px;margin-bottom:8px;" class="btn btn-success" onclick="window.location.href = 'index?<?=$query_string;?>'">Back</button>
			</div>
		</div>
	</div>
</section>
<section class="content">
	<div class="row">
		<div class="col-12">
			<!----------------------- Message ------------------------------->
			<? if(isset($_SESSION['info_message'])){ ?>
			  <div class="alert alert-info alert-dismissable">
				<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
				<? echo $_SESSION['info_message']; unset($_SESSION['info_message']);?>
			  </div>
			  <? } ?>
			<!----------------------- End Message ------------------------------->
			<!-- general form elements -->
              <div class="card box-primary">
                <form class="form-horizontal" method="post" name="form1" id="form1" action="index?page=add_celebrant&action=<? echo $form_action; ?>" onsubmit="return validateForm(this)" enctype="multipart/form-data">
                  <div class="card-body">
				  <div class="row">
				  <div class="col-lg-6 col-sm-12">
					<div class="form-group"> 
						<label class="control-label" for="Organisation">Organisation<em>*</em></label> 
						<div class=""> 
							<? $gsi->getOrganisationList("org_id",$org_id,"100%",false,"form-control select2","required"); ?>
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Company Name">Company Name<em>*</em></label> 
						<div class=""> 
							<input type="text" id="company_name" name="company_name" class="form-control" value="<?php echo $company_name;?>" placeholder="Company Name" required>
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Sector">Sector<em>*</em></label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("sector", $sector, $width = "100%", "Sector", "id", "code", "sector","","form-control select2",true,"required"); ?>
							<div id="new_sector_link" style="color:#367FA9;cursor:pointer;">New Sector</div>
						</div> 
					</div>
					<div id="new_sector_div" style="display:none;">
						<div class="form-group"> 
							<label class="control-label" for="New Sector">New Sector</label> 
							<div class=""> 
								<input type="text" id="sector_name_new" name="sector_name_new" class="form-control" value="" placeholder="New Sector"> 
							</div> 
						</div>
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Title">Title<em>*</em></label> 
						<div class="">
							<!--<input type="text" id="title" name="title" class="form-control" value="<?php echo $title;?>" placeholder="Title">-->
							<? //$gsi->getTitleList("title",$title,"100%",false,"form-control","required"); ?>
							<? echo Keycode::getKeycodeListValue("title", $title, $width = "100%", "Please Select", "id", "code", "title","","form-control",false,"required"); ?>
						</div>
					</div>
					<div class="form-group"> 
						<label class="control-label" for="First Name">First Name<em>*</em></label> 
						<div class="">
							<input type="text" id="first_name" name="first_name" class="form-control" value="<?php echo $first_name;?>" placeholder="First Name" required>
						</div>
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Last Name">Last Name<em>*</em></label> 
						<div class="">
							<input type="text" id="last_name" name="last_name" class="form-control" value="<?php echo $last_name;?>" placeholder="Last Name" required> 
						</div>
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Profession">Profession</label> 
						<div class="">
							<input type="text" id="profession" name="profession" class="form-control" value="<?php echo $profession;?>" placeholder="Profession"> 
						</div>
					</div>
					<!--<div class="form-group"> 
						<label class="control-label" for="Target Market">Target Market</label> 
						<div class="">
							<input type="text" id="target_market" name="target_market" class="form-control" value="<?php echo $target_market;?>" placeholder="Target Market"> 
						</div>
					</div>-->
					<div class="form-group"> 
						<label class="control-label" for="Phone No.1">Phone No.1<em>*</em></label> 
						<div class="">
							<input type="text" id="phone_no" name="phone_no" class="form-control" value="<?php echo $phone_no;?>" placeholder="Phone No.1" required> 
						</div>
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Phone No.2">Phone No.2</label> 
						<div class="">
							<input type="text" id="landline_phone_no" name="landline_phone_no" class="form-control" value="<?php echo $landline_phone_no;?>" placeholder="Phone No.2"> 
						</div>
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Email">Email / Username<em>*</em></label> 
						<div class=""> 
							<input type="text" id="email" name="email" class="form-control" value="<?php echo $email;?>" placeholder="Email" required> 
						</div> 
					</div>
					<!--<div class="form-group"> 
						<label class="control-label" for="Password">Password</label> 
						<div class=""> 
							<input type="text" id="password" name="password" class="form-control" value="<?php echo $password;?>" placeholder="Password"> 
						</div> 
					</div>-->					
					
					<div class="form-group"> 
						<label class="control-label" for="Contact 1">Contact 1</label> 
						<div class="row" style="padding: 0;"> 
							<div class="col-sm-6">
								<input type="text" id="contact1name" name="contact1name" class="form-control" value="<?php echo $contact1name;?>" placeholder="Name"> 
							</div>
							<div class="col-sm-6">
								<input type="text" id="contact1position" name="contact1position" class="form-control" value="<?php echo $contact1position;?>" placeholder="Position">
							</div>							
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Contact 2">Contact 2</label> 
						<div class="row" style="padding: 0;"> 
							<div class="col-sm-6">
								<input type="text" id="contact2name" name="contact2name" class="form-control" value="<?php echo $contact2name;?>" placeholder="Name"> 
							</div>
							<div class="col-sm-6">
								<input type="text" id="contact2position" name="contact2position" class="form-control" value="<?php echo $contact2position;?>" placeholder="Position">
							</div>							
						</div> 
					</div>
					</div>
					<div class="col-lg-6 col-sm-12">
					<div class="form-group"> 
						<label class="control-label" for="Address">Address<em></em></label> 
						<div class="row" style="padding: 0;"> 
							<div class="col-sm-4">
								<input type="text" id="address1" name="address1" class="form-control" value="<?php echo $address1;?>" placeholder="Address1"> 
							</div>
							<div class="col-sm-4">
								<input type="text" id="address2" name="address2" class="form-control" value="<?php echo $address2;?>" placeholder="Address2">
							</div>
							<div class="col-sm-4">
								<input type="text" id="address3" name="address3" class="form-control" value="<?php echo $address3;?>" placeholder="Address3"> 
							</div>
						</div> 
					</div>
					
					<div class="form-group"> 
						<label class="control-label" for="City">Town</label> 
						<div class=""> 
							<input type="text" id="city" name="city" class="form-control" value="<?php echo $city;?>" placeholder="Town"> 
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="County">County</label> 
						<div class=""> 
							<? $gsi->getCountyList("county",$county,"100%",false,"form-control"); ?>
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Postcode">Postcode<em></em></label> 
						<div class=""> 
							<input type="text" id="postcode" name="postcode" class="form-control" value="<?php echo $postcode;?>" placeholder="Postcode"> 
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Enquiry Date">Enquiry Date</label> 
						<div class=""> 
							<input type="text" class="form-control datepicker" id="enquiry_date" name="enquiry_date" value="<?php (isset($enquiry_date) && $enquiry_date !="") ? utility::getFormatedDate($enquiry_date) : "";?>">
						</div> 
					</div>
					
					<div class="form-group"> 
						<label class="control-label" for="Renewal Dates">Renewal Dates</label> 
						<div class=""> 
							<input type="text" class="form-control datepicker" id="renewal_dates" name="renewal_dates" value="<?php (isset($renewal_dates) && $renewal_dates !="") ? utility::getFormatedDate($renewal_dates) : "";?>">
						</div> 
					</div>
					
					<!--<div class="form-group"> 
						<label class="control-label" for="Interventions">Interventions</label> 
						<div class=""> 
							<input type="text" id="interventions" name="interventions" class="form-control" value="<?php echo $interventions;?>" placeholder="Interventions"> 
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Sales Process">Sales Process</label> 
						<div class=""> 
							<input type="text" id="sales_process" name="sales_process" class="form-control" value="<?php echo $sales_process;?>" placeholder="Sales Process"> 
						</div> 
					</div>-->
					<div class="form-group hide"> 
						<label class="control-label" for="Consultant">Consultant</label> 
						<div class=""> 
							<? //Admin::getAdminList("admin_id",$admin_id,"100%",true,"form-control select2"); ?>
						</div> 
					</div>
					
					<div class="form-group">  
						<div class="row"> 
							<div class="col-6"> 
								<label class="control-label" for="Consultant">Consultant</label>
								<? Admin::getAdminList("admin_id",$admin_id,"100%",true,"form-control select_admin_id"); ?>
							</div> 
							
							<div class="col-6"> 
								<label class="control-label" for="Lead Consultant">Lead Consultant</label>
								<? 
									if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit'){ 
										foreach($admin_id as $a_id){
											$lead_consultant_array[$a_id] = utility::getTableFieldById('admin','name','id',$a_id);
										}
										print utility::createList($lead_consultant_array,"lead_consultant",$lead_consultant,"100%","Select Consultant",false,"form-control");
									}else{ 
								?>
									<select class="form-control" name="lead_consultant" id="lead_consultant">
										<option>Select Consultant</option>
									</select>
								<? } ?>
							</div> 
						</div>
					</div>
					
					<!--<div class="form-group"> 
						<label class="control-label" for="Behavioural Style">Behavioural Style</label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("behavioural_style", $behavioural_style, $width = "100%", "Behavioural Style", "id", "code", "behavioural_style",""); ?>
						</div> 
					</div>-->
					<!--<div class="form-group"> 
						<label class="control-label" for="Type of Celebrant">Type of Celebrant</label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("type_of_celebrant", $type_of_celebrant, $width = "100%", "Type of Celebrant", "id", "code", "type_of_celebrant","","form-control select2",true); ?>							
						</div> 
					</div>
					
					<div class="form-group"> 
						<label class="control-label" for="Status">Status</label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("celebrant_status", $celebrant_status, $width = "100%", "Celebrant Status", "id", "code", "celebrant_status","","form-control",false); ?>
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Mentor">Mentor</label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("celebrant_mentor", $celebrant_mentor, $width = "100%", "Celebrant Mentor", "id", "code", "celebrant_mentor","","form-control select2",true); ?>
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Accreditation Observer">Accreditation Observer</label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("accreditation_observer", $accreditation_observer, $width = "100%", "Accreditation Observer", "id", "code", "accreditation_observer","","form-control select2",true); ?>
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Date">Peer Observation Date</label> 
						<div class=""> 
							<input type="text" class="form-control datepicker" id="peer_observation_date" name="peer_observation_date" value="<?php (isset($peer_observation_date) && $peer_observation_date !="") ? utility::getFormatedDate($peer_observation_date) : "";?>">
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Date">CPD Complete Date</label> 
						<div class=""> 
							<input type="text" class="form-control datepicker" id="cpd_complete_date" name="cpd_complete_date" value="<?php (isset($cpd_complete_date) && $cpd_complete_date !="") ? utility::getFormatedDate($cpd_complete_date) : "";?>">
						</div> 
					</div>
					<div class="form-group"> 
						<label class="control-label" for="Date">Last Spoke Date</label> 
						<div class=""> 
							<input type="text" class="form-control datepicker" id="last_spoke_date" name="last_spoke_date" value="<?php (isset($last_spoke_date) && $last_spoke_date !="") ? utility::getFormatedDate($last_spoke_date) : "";?>">
						</div> 
					</div>-->
					
					<div class="form-group"> 
						<label class="control-label" for="Turnover">Turnover</label> 
						<div class="">
							<input type="text" id="turnover" name="turnover" class="form-control" value="<?php echo ($turnover != 0) ? $turnover : "";?>" placeholder="Turnover"> 
						</div>
					</div>
					
					<div class="form-group"> 
						<label class="control-label" for="Number of employees">Number of employees</label> 
						<div class="">
							<input type="text" id="number_of_employees" name="number_of_employees" class="form-control" value="<?php echo ($number_of_employees != 0) ? $number_of_employees : "";?>" placeholder="Number of employees"> 
						</div>
					</div>
					
					<div class="form-group"> 
						<label class="control-label" for="Business Type">Package/Insurance Type</label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("insurance_type", $insurance_type, $width = "100%", "Package/Insurance Type", "id", "code", "insurance_type","","form-control select2"); ?>
						</div> 
					</div>
					
					<div class="form-group"> 
						<label class="control-label" for="Business Type">Business Type</label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("business_type", $business_type, $width = "100%", "Business Type", "id", "code", "business_type","","form-control"); ?>
						</div> 
					</div>
					<!--<div class="form-group"> 
						<label class="control-label" for="Policy Type">Policy Type</label> 
						<div class=""> 
							<? //echo Keycode::getKeycodeListValue("policy_type", $policy_type, $width = "100%", "Policy Type", "id", "code", "policy_type","","form-control"); ?>
						</div> 
					</div>-->
					
					<div class="form-group"> 
						<label class="control-label" for="Prospect traffic lights">Prospect traffic lights</label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("prospect_traffic_lights", $prospect_traffic_lights, $width = "100%", "Prospect traffic lights", "id", "code", "prospect_traffic_lights","","form-control"); ?>
						</div> 
					</div>
					
					<div class="form-group"> 
						<label class="control-label" for="Contact Method">Contact Method</label> 
						<div class=""> 
							<? echo Keycode::getKeycodeListValue("contact_method", $contact_method, $width = "100%", "Contact Method", "id", "code", "contact_method","","form-control"); ?>
						</div> 
					</div>
					<? if(isset($_REQUEST['action']) && $_REQUEST['action']=='edit'){?>	
					<div class="form-group"> 
						<label class="control-label" for="Archive">Archive</label> 
						<div class=""> 
							<input type="checkbox" class="flat-red" id="is_archive" name="is_archive" value="1"  <? echo ($is_archive ==1) ? 'checked':''; ?>>
						</div> 
					</div>
					<? }?>
                  </div>
                  </div><!-- /.row -->
                  </div><!-- /.box-body -->
                  <div class="card-footer">
					<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
					<input type="hidden" id="from" name="from" value="<?php echo $from;?>">
					<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
                    <button type="submit" id="submit" name="submit" value="<?php echo $button_value;?>" class="btn btn-primary">Submit
						<i class="fas fa-sync-alt fa-spin" style="display:none;" id="page_load_div"></i>
					</button>
                  </div>
                </form>
              </div><!-- /.box -->
		</div>
	</div>
</section>
<script type="text/javascript">
$(function(){
	$('#form1').submit(function(){
		//$(this).addClass('disabled');
		$("#submit").attr("disabled", true);
		$('#page_load_div').show();
	});
	$("#form1").on("click",".select_admin_id",function(){
		$('#lead_consultant').empty(); 
		$(".select_admin_id option:selected").each(function(){
			//alert($(this).val()+" - "+$(this).text());
			$('#lead_consultant').append($('<option>', {
				value: $(this).val(),
				//selected: 'selected',
				text: $(this).text()
			}));
		});
	});
	$("#new_sector_link").click(function(){
		$("#new_sector_div").toggle();
	});
	$("#new_source_link").click(function(){
		$("#new_source_div").toggle();
	});
	<? if($_REQUEST['action']!='edit'){ ?>
	$("#form1").on("change","#org_id",function(){
		var org_id = $(this).val();
		if(org_id != ""){
		var form_data   = {'org_id':org_id};       
			////////////////////// For fetching address /////////////////////////
			$.ajax({
				async: false,
				type: "POST",
				url: site_url+"/modules/enquiry_management/index.php?page=ajax_actions&action=get_address_by_org_id",
				data: form_data,
				success: function(result){  
					var resultObj = jQuery.parseJSON(result); 
					if(resultObj.status == 1){
						$("#address1").val(resultObj.address1);						
						$("#address2").val(resultObj.address2);						
						$("#address3").val(resultObj.address3);						
						$("#city").val(resultObj.city);						
						$("#county").val(resultObj.county);						
						$("#postcode").val(resultObj.postcode);						
						$("#phone_no").val(resultObj.phone_no);						
						$("#landline_phone_no").val(resultObj.landline_phone_no);						
					}
				}
			});
			////////////////////// End For fetching address /////////////////////////
		}
	});
	<? } ?>
});
</script>