class form_clients_contacts { public $id; public $form_type; public $company_name; public $first_name; public $last_name; public $phone; public $mobile_phone; public $fax; public $email; public $alt_contact; public $alt_phone; public $address; public $post_code; public $state; public $suburb; public $country; public $config; public $validation; public $reasons; public function __construct($context) { $this->client_id = $context['client_id']; $this->id = $context['id']; $this->form_type = $context['form_type']; } public function set() { global $database; $client_id = $this->client_id; $id = $this->id; if(!empty($id)) { $contacts = common_ref_client::get_contact($id); $this->location_id = $contacts['location_id']; $this->job_title = $contacts['job_title']; $this->first_name = $contacts['first_name']; $this->last_name = $contacts['last_name']; $this->email = $contacts['email']; $this->mobile_phone = $contacts['mobile_phone']; $this->business_phone = $contacts['business_phone']; $this->client_id = $contacts['client_id']; $client = common_ref_client::get_client($this->client_id); $current_primary = $client['primary_contact_id']; $this->primary_contact = 0; if($id == $current_primary) $this->primary_contact = 1; } if($_POST['Submit'] == "Save") { $this->location_id = $_POST['location_id']; $this->job_title = $_POST['job_title']; $this->first_name = $_POST['first_name']; $this->last_name = $_POST['last_name']; $this->email = $_POST['email']; $this->mobile_phone = $_POST['mobile_phone']; $this->business_phone = $_POST['business_phone']; } $this->config['location_id'] = array("id"=> $id,"value"=> $this->location_id, "input_name" => "location_id", "name" => "Location","rule" => "required"); $this->config['job_title'] = array("id"=> $id,"value"=> $this->job_title, "input_name" => "job_title", "name" => "Job Title","rule" => ""); $this->config['first_name'] = array("id"=> $id,"value"=> $this->first_name, "input_name" => "first_name", "name" => "First Name","rule" => "required"); $this->config['last_name'] = array("id"=> $id,"value"=> $this->last_name, "input_name" => "last_name", "name" => "Last Name","rule" => "required"); $this->config['email'] = array("id"=> $id,"value"=> $this->email, "input_name" => "email", "name" => "Email","rule" => ""); $this->config['mobile_phone'] = array("id"=> $id,"value"=> $this->mobile_phone, "input_name" => "mobile_phone", "name" => "Mobile Phone","rule" => ""); $this->config['business_phone'] = array("id"=> $id,"value"=> $this->business_phone, "input_name" => "business_phone", "name" => "Business Phone","rule" => ""); self::run_validation(); } public function run_validation() { $static_function = (($_POST['Submit'] == "")) ? "initial" : "validate"; $this->validation['location_id'] = validation::$static_function($this->config['location_id']); $this->validation['job_title'] = validation::$static_function($this->config['job_title']); $this->validation['first_name'] = validation::$static_function($this->config['first_name']); $this->validation['last_name'] = validation::$static_function($this->config['last_name']); $this->validation['email'] = validation::$static_function($this->config['email']); $this->validation['mobile_phone'] = validation::$static_function($this->config['mobile_phone']); $this->validation['business_phone'] = validation::$static_function($this->config['business_phone']); $this->reasons = validation::formalise($this->validation); } public function form() { global $database; $id = $this->id; $form_type = $this->form_type; $config = $this->config; $validation = $this->validation; $options = array("class" => "medium"); $options_select = array("class" => "large form"); $table_class = (empty($form_type)) ? "tab_form" : "tab_form_ajax"; $client_type = $this->client_type; if(empty($form_type)) { ?>