class form_request_old
{
public $id;
public $config;
public $validation;
public $reasons;
public $sign_counter;
public $department;
public $status_table;
public $status_id;
public function __construct($context)
{
$this->id = $context['id'];
$this->status_table = $context['status_table'];
$this->status_id = $context['status'];
$this->department_id = $context['dept_id'];
$this->sign_counter = 0;
}
public function set()
{
global $database;
$my_client_id = $_SESSION['my_client_id'];
$id = $this->id;
$status_id = $this->status_id;
$this->same_billing = 1;
$this->create_new_client = 0;
$this->quote_type = 1;
$this->sign_types = array();
$_SESSION['line_counter'] = (empty($_SESSION['line_counter'])) ? 1500000 : $_SESSION['line_counter'];
if(!empty($id) && !isset($_POST['Submit']))
{
$request = common_quotes::get_details($id);
$this->company_id = $request['client_id'];
$this->client_id = $request['client_id'];
$this->location_id = $request['location_id'];
$this->site_location_id = $request['site_location_id'];
$this->job_name = $request['job_name'];
$this->description = $request['description'];
$this->phone = $request['phone'];
$this->flag = $request['flag'];
$this->status = $request['dqstatus'];
$this->myob_number = $request['myob_number'];
$this->job_name = $request['job_name'];
$this->other_description = $request['other_note'];
$this->quote_type = $request['job_type'];
$this->start_range = $request['start_range'];
$this->end_range = $request['end_range'];
$this->company_name = $request['company_name'];
$this->address = $request['address'];
$this->suburb = $request['suburb'];
$this->state = $request['state'];
$this->post_code = $request['post_code'];
$this->site_address = $request['site_address'];
$this->site_suburb = $request['site_suburb'];
$this->site_state = $request['site_state'];
$this->site_post_code = $request['site_post_code'];
$this->priority = $request['priority'];
if($this->location_id == $this->site_location_id)
$this->same_billing = $location_details['same_billing'];
$this->sign_types= unserialize($request['jobtype']);
$contacts = $request['contacts'];
foreach($contacts AS $contact)
{
$suffix = $contact['id'];
$first_name = $contact['first_name'];
$last_name = $contact['last_name'];
$phone = $contact['phone'];
$email = $contact['email'];
$this->config['first_name_'.$suffix] = array("id"=> $id,"value"=> $first_name, "input_name" => 'first_name_'.$suffix, "name" => "First Name","rule" => "required");
$this->config['last_name_'.$suffix] = array("id"=> $id,"value"=> $last_name, "input_name" => 'last_name_'.$suffix, "name" => "Last Name","rule" => "required");
$this->config['phone_'.$suffix] = array("id"=> $id,"value"=> $phone, "input_name" => 'phone_'.$suffix, "name" => "Phone","rule" => "");
$this->config['email_'.$suffix] = array("id"=> $id,"value"=> $email, "input_name" => 'email_'.$suffix, "name" => "Email","rule" => "required|valid_email");
}
}
else if(!isset($_POST['Submit']) && empty($id))
{
$init_counter = $_SESSION['line_counter'];
$restraint = $init_counter + 1;
$item_type = 1;
for($suffix = $init_counter; $suffix < $restraint; $suffix++)
{
$this->config['first_name_'.$suffix] = array("id"=> $id,"value"=> $first_name, "input_name" => 'first_name_'.$suffix, "name" => "First Name","rule" => "required");
$this->config['last_name_'.$suffix] = array("id"=> $id,"value"=> $last_name, "input_name" => 'last_name_'.$suffix, "name" => "Last Name","rule" => "required");
$this->config['phone_'.$suffix] = array("id"=> $id,"value"=> $phone, "input_name" => 'phone_'.$suffix, "name" => "Phone","rule" => "");
$this->config['email_'.$suffix] = array("id"=> $id,"value"=> $email, "input_name" => 'email_'.$suffix, "name" => "Email","rule" => "required|valid_email");
$_SESSION['line_counter']++;
}
}
if($_POST['Submit'] == "Save")
{
//bug::bug_array("post",$_POST);
$this->create_new_client = $_POST['create_new_client'];
$this->client_type = $_POST['client_type'];
$this->client_id = $_POST['client_id'];
$this->location_id = $_POST['location_id'];
$this->site_location_id = $_POST['site_location_id'];
$this->new_company_name = $_POST['new_company_name'];
$this->company_name = $_POST['company_name'];
$this->new_state = $_POST['new_state'];
$this->new_site_state = $_POST['new_site_state'];
$this->address = $_POST['address'];
$this->post_code = $_POST['post_code'];
$this->state = $_POST['state'];
$this->suburb = $_POST['suburb'];
$this->same_billing = $_POST['same_billing'];
$this->site_address = $_POST['site_address'];
$this->site_post_code = $_POST['site_post_code'];
$this->site_state = $_POST['site_state'];
$this->site_suburb = $_POST['site_suburb'];
$this->description = $_POST['description'];
$this->job_type = $_POST['jobtype'];
$this->company = $_POST['company'];
$this->quote_type = $_POST['quote_type'];
$this->job_start_from = $_POST['job_start_from'];
$this->number_of_jobs = $_POST['number_of_jobs'];
$this->start_range = $_POST['start_range'];
$this->end_range = $_POST['end_range'];
$this->flag =$_POST['flag'];
$this->status = $request['status'];
$this->myob_number =$_POST['myob_number'];
$this->job_name =$_POST['job_name'];
$this->priority =$_POST['priority'];
$this->other_description = $_POST['other_description'];
$this->sign_types = (count($_POST['sign_types']) == 0) ? array() : $_POST['sign_types'];
foreach($_POST AS $key => $value)
{
$split = explode("_",$key);
$name = $split[0]."_".$split[1]."_";
if($name == "first_name_")
{
$suffix = $split[2];
$first_name = $_POST['first_name_'.$suffix];
$last_name = $_POST['last_name_'.$suffix];
$phone = $_POST['phone_'.$suffix];
$email = $_POST['email_'.$suffix];
$this->config['first_name_'.$suffix] = array("id"=> $id,"value"=> $first_name, "input_name" => 'first_name_'.$suffix, "name" => "First Name","rule" => "required");
$this->config['last_name_'.$suffix] = array("id"=> $id,"value"=> $last_name, "input_name" => 'last_name_'.$suffix, "name" => "Last Name","rule" => "required");
$this->config['phone_'.$suffix] = array("id"=> $id,"value"=> $phone, "input_name" => 'phone_'.$suffix, "name" => "Phone","rule" => "");
$this->config['email_'.$suffix] = array("id"=> $id,"value"=> $email, "input_name" => 'email_'.$suffix, "name" => "Email","rule" => "required|valid_email");
}
}
}
$this->config['new_company_name'] = array("id"=> $id,"value"=> $this->new_company_name, "input_name" => "new_company_name", "name" => "Company Name","rule" => "required|company_name");
$this->config['company_name'] = array("id"=> $id,"value"=> $this->company_name, "input_name" => "company_name", "name" => "Company Name","rule" => "required");
$this->config['client_id'] = array("id"=> $id,"value"=> $this->client_id, "input_name" => "client_id", "name" => "Client","rule" => "required");
$this->config['location_id'] = array("id"=> $id,"value"=> $this->location_id, "input_name" => "location_id", "name" => "Address","rule" => "required|numeric");
$this->config['site_location_id'] = array("id"=> $id,"value"=> $this->site_location_id, "input_name" => "site_location_id", "name" => "Site Address","rule" => "required|numeric");
$this->config['address'] = array("id"=> $id,"value"=> $this->address, "input_name" => "address", "name" => "Address","rule" => "required");
$this->config['post_code'] = array("id"=> $id,"value"=> $this->post_code, "input_name" => "post_code", "name" => "Post Code","rule" => "required|integer|exact_length[4]");
$this->config['state'] = array("id"=> $id,"value"=> $this->state, "input_name" => "state", "name" => "State","rule" => "required");
$this->config['new_state'] = array("id"=> $id,"value"=> $this->new_state, "input_name" => "new_state", "name" => "State","rule" => "required");
$this->config['suburb'] = array("id"=> $id,"value"=> $this->suburb, "input_name" => "suburb", "name" => "Suburb","rule" => "required");
$this->config['site_address'] = array("id"=> $id,"value"=> $this->site_address, "input_name" => "site_address", "name" => "Site Address","rule" => "required");
$this->config['site_post_code'] = array("id"=> $id,"value"=> $this->site_post_code, "input_name" => "site_post_code", "name" => "Site Post Code","rule" => "required|integer|exact_length[4]");
$this->config['new_site_state'] = array("id"=> $id,"value"=> $this->new_site_state, "input_name" => "new_site_state", "name" => "Site State","rule" => "required");
$this->config['site_state'] = array("id"=> $id,"value"=> $this->site_state, "input_name" => "site_state", "name" => "Site State","rule" => "required");
$this->config['site_suburb'] = array("id"=> $id,"value"=> $this->site_suburb, "input_name" => "site_suburb", "name" => "Site Suburb","rule" => "required");
$this->config['description'] = array("id"=> $id,"value"=> $this->description, "input_name" => "description", "name" => "Description","rule" => "required");
$this->config['jobtype_id'] = array("id"=> $id,"value"=> $this->jobtype_id, "input_name" => "jobtype_id", "name" => "Job Type ID","rule" => "");
$this->config['status'] = array("id"=> $id,"value"=> $this->status, "input_name" => "status", "name" => "Status","rule" => "");
$this->config['myob_number'] = array("id"=> $id,"value"=> $this->myob_number, "input_name" => "myob_number", "name" => "MYOB Number","rule" => "");
$this->config['job_name'] = array("id"=> $id,"value"=> $this->job_name, "input_name" => "job_name", "name" => "Job Name","rule" => "required");
$this->config['priority'] = array("id"=> $id,"value"=> $this->priority, "input_name" => "priority", "name" => "Priority","rule" => "required|numeric");
$get_start = "
SELECT project_numbers ,normal_jobs_numbers
FROM ".DB_CLIENT_ACCOUNTS."account_settings
WHERE account_id = '$my_client_id'
";
list($this->minimum ,$this->maximum) = $database->getRow($get_start);
$this->maximum -= 1;
$this->config['job_start_from'] = array("id"=> $id,"value"=> $this->job_start_from, "input_name" => "job_start_from", "name" => "Start From","rule" => "required|numeric|job_exist|minimum[".$this->minimum."]|maximum[".$this->maximum."]");
$this->config['number_of_jobs'] = array("id"=> $id,"value"=> $this->number_of_jobs, "input_name" => "number_of_jobs", "name" => "Number Of Jobs","rule" => "required|numeric");
self::run_validation();
}
public function run_validation()
{
$static_function = (($_POST['Submit'] == "")) ? "initial" : "validate";
if(isset($_POST['Submit']))
{
if($this->create_new_client == 1)
{
$this->validation['company_name'] = validation::initial($this->config['company_name']);
$this->validation['client_id'] = validation::initial($this->config['client_id']);
$this->validation['location_id'] = validation::initial($this->config['location_id']);
$this->validation['site_location_id'] = validation::initial($this->config['site_location_id']);
$this->validation['state'] = validation::initial($this->config['state']);
$this->validation['new_company_name'] = validation::$static_function($this->config['new_company_name']);
$this->validation['address'] = validation::$static_function($this->config['address']);
$this->validation['suburb'] = validation::$static_function($this->config['suburb']);
$this->validation['new_state'] = validation::$static_function($this->config['new_state']);
$this->validation['post_code'] = validation::$static_function($this->config['post_code']);
if(empty($_POST['same_billing']))
{
$this->validation['site_state'] = validation::initial($this->config['site_state']);
$this->validation['site_address'] = validation::$static_function($this->config['site_address']);
$this->validation['site_post_code'] = validation::$static_function($this->config['site_post_code']);
$this->validation['new_site_state'] = validation::$static_function($this->config['new_site_state']);
$this->validation['site_suburb'] = validation::$static_function($this->config['site_suburb']);
}
else
{
$this->validation['new_site_state'] = validation::initial($this->config['new_site_state']);
$this->validation['site_address'] = validation::initial($this->config['site_address']);
$this->validation['site_post_code'] = validation::initial($this->config['site_post_code']);
$this->validation['site_state'] = validation::initial($this->config['site_state']);
$this->validation['site_suburb'] = validation::initial($this->config['site_suburb']);
}
}
else
{
$this->validation['new_company_name'] = validation::initial($this->config['new_company_name']);
$this->validation['new_state'] = validation::initial($this->config['new_state']);
$this->validation['new_site_state'] = validation::initial($this->config['new_site_state']);
$this->validation['company_name'] = validation::$static_function($this->config['company_name']);
$this->validation['client_id'] = validation::$static_function($this->config['client_id']);
$this->validation['location_id'] = validation::$static_function($this->config['location_id']);
$this->validation['address'] = validation::$static_function($this->config['address']);
$this->validation['suburb'] = validation::$static_function($this->config['suburb']);
$this->validation['state'] = validation::$static_function($this->config['state']);
$this->validation['post_code'] = validation::$static_function($this->config['post_code']);
if(empty($_POST['same_billing'])) // if site location is required
{
$this->validation['site_location_id'] = validation::$static_function($this->config['site_location_id']);
$this->validation['site_address'] = validation::$static_function($this->config['site_address']);
$this->validation['site_post_code'] = validation::$static_function($this->config['site_post_code']);
$this->validation['site_state'] = validation::$static_function($this->config['site_state']);
$this->validation['site_suburb'] = validation::$static_function($this->config['site_suburb']);
}
else
{
$this->validation['site_location_id'] = validation::initial($this->config['site_location_id']);
$this->validation['site_address'] = validation::initial($this->config['site_address']);
$this->validation['site_post_code'] = validation::initial($this->config['site_post_code']);
$this->validation['site_state'] = validation::initial($this->config['site_state']);
$this->validation['site_suburb'] = validation::initial($this->config['site_suburb']);
}
}
if(empty($this->id))
{
if($_POST['quote_type'] != 2)
{
$this->validation['job_start_from'] = validation::initial($this->config['job_start_from']);
$this->validation['number_of_jobs'] = validation::initial($this->config['number_of_jobs']);
}
else
{
$this->validation['job_start_from'] = validation::$static_function($this->config['job_start_from']);
$this->validation['number_of_jobs'] = validation::$static_function($this->config['number_of_jobs']);
}
}
}
else
{
$this->validation['new_company_name'] = validation::$static_function($this->config['new_company_name']);
$this->validation['company_name'] = validation::$static_function($this->config['company_name']);
$this->validation['client_id'] = validation::$static_function($this->config['client_id']);
$this->validation['location_id'] = validation::$static_function($this->config['location_id']);
$this->validation['site_location_id'] = validation::$static_function($this->config['site_location_id']);
$this->validation['address'] = validation::$static_function($this->config['address']);
$this->validation['suburb'] = validation::$static_function($this->config['suburb']);
$this->validation['new_state'] = validation::$static_function($this->config['new_state']);
$this->validation['state'] = validation::$static_function($this->config['state']);
$this->validation['post_code'] = validation::$static_function($this->config['post_code']);
$this->validation['site_address'] = validation::$static_function($this->config['site_address']);
$this->validation['site_post_code'] = validation::$static_function($this->config['site_post_code']);
$this->validation['new_site_state'] = validation::$static_function($this->config['new_site_state']);
$this->validation['site_state'] = validation::$static_function($this->config['site_state']);
$this->validation['site_suburb'] = validation::$static_function($this->config['site_suburb']);
$this->validation['job_start_from'] = validation::$static_function($this->config['job_start_from']);
$this->validation['number_of_jobs'] = validation::$static_function($this->config['number_of_jobs']);
}
$this->validation['description'] = validation::$static_function($this->config['description']);
$this->validation['myob_number'] = validation::$static_function($this->config['myob_number']);
$this->validation['job_name'] = validation::$static_function($this->config['job_name']);
$this->validation['jobtype_id'] = validation::$static_function($this->config['jobtype_id']);
$this->validation['status'] = validation::$static_function($this->config['status']);
$this->validation['priority'] = validation::$static_function($this->config['priority']);
foreach($this->config AS $key => $value)
{
$split = explode("_",$key);
$name = $split[0]."_".$split[1]."_";
if($name == "first_name_")
{
$suffix = $split[2];
$this->validation['first_name_'.$suffix] = validation::$static_function($this->config['first_name_'.$suffix]);
$this->validation['last_name_'.$suffix] = validation::$static_function($this->config['last_name_'.$suffix]);
$this->validation['phone_'.$suffix] = validation::$static_function($this->config['phone_'.$suffix]);
$this->validation['email_'.$suffix] = validation::$static_function($this->config['email_'.$suffix]);
}
}
$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_large = array("class" => "large");
$options_checkbox = array("class" => "checkbox");
$options_select = array("class" => "medium form");
$table_class = (empty($form_type)) ? "tab_form" : "";
$client_type = $this->client_type;
$options_address = array("class" => "medium","attr" => array("readonly" => "readonly"));
$options_select = array("class" => "medium form");
$options_select_small = array("class" => "small form");
$options_text_medium = array("class" => "medium");
$options_text_small = array("class" => "small");
$options_description = array("class" => "large","attr" => array("rows" => "5"));
$clients['results'] = common_clients::get_all_clients();
?>