'.$this->lang->line('upload_no_file_selected').'
'); - } + } + + private function _check_encryption() + { + $encryption_key = $this->config->item('encryption_key'); + + // check if the encryption_key config item is the default one + if($encryption_key == '' || $encryption_key == 'YOUR KEY') + { + // Config path + $config_path = APPPATH . 'config/config.php'; + + // Open the file + $config = file_get_contents($config_path); + + // $key will be assigned a 32-byte (256-bit) hex-encoded random key + $key = bin2hex($this->encryption->create_key(32)); + + // replace the empty placeholder with a real randomly generated encryption key + if($encryption_key == '') + { + $config = str_replace("['encryption_key'] = '';", "['encryption_key'] = '" . $key . "';", $config); + } + else + { + $config = str_replace("['encryption_key'] = 'YOUR KEY';", "['encryption_key'] = '" . $key . "';", $config); + } + + // set the encryption key in the config item + $this->config->set_item('encryption_key', $key); + + // Write the new config.php file + $handle = fopen($config_path, 'w+'); + + // Chmod the file + @chmod($config_path, 0777); + + $result = FALSE; + + // Verify file permissions + if(is_writable($config_path)) + { + // Write the file + $result = (fwrite($handle, $config) === FALSE) ? FALSE : TRUE; + } + + // Chmod the file + @chmod($config_path, 0444); + + fclose($handle); + + return $result; + } + + return TRUE; + } - function backup_db() + public function backup_db() { $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; - if($this->Employee->has_module_grant('config',$employee_id)) + if($this->Employee->has_module_grant('config', $employee_id)) { $this->load->dbutil(); + $prefs = array( 'format' => 'zip', 'filename' => 'ospos.sql' ); - $backup =& $this->dbutil->backup($prefs); + $backup = $this->dbutil->backup($prefs); $file_name = 'ospos-' . date("Y-m-d-H-i-s") .'.zip'; - $save = 'uploads/'.$file_name; + $save = 'uploads/' . $file_name; $this->load->helper('download'); - while (ob_get_level()) + while(ob_get_level()) { ob_end_clean(); } + force_download($file_name, $backup); } else diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index 9d0c6cfbc..19296dd0a 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -1,16 +1,17 @@ -get_controller_name(); - $data['table_headers'] = get_people_manage_table_headers(); + $data['table_headers'] = $this->xss_clean(get_people_manage_table_headers()); $this->load->view('people/manage', $data); } @@ -18,13 +19,13 @@ class Customers extends Person_controller /* Returns customer table data rows. This will be called with AJAX. */ - function search() + public function search() { $search = $this->input->get('search'); - $limit = $this->input->get('limit'); + $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); - $sort = $this->input->get('sort'); - $order = $this->input->get('order'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); $customers = $this->Customer->search($search, $limit, $offset, $sort, $order); $total_rows = $this->Customer->get_found_rows($search); @@ -34,22 +35,25 @@ class Customers extends Person_controller { $data_rows[] = get_person_data_row($person, $this); } + + $data_rows = $this->xss_clean($data_rows); + echo json_encode(array('total' => $total_rows, 'rows' => $data_rows)); } /* Gives search suggestions based on what is being searched for */ - function suggest() + public function suggest() { - $suggestions = $this->Customer->get_search_suggestions($this->input->get('term'), TRUE); + $suggestions = $this->xss_clean($this->Customer->get_search_suggestions($this->input->get('term'), TRUE)); echo json_encode($suggestions); } - function suggest_search() + public function suggest_search() { - $suggestions = $this->Customer->get_search_suggestions($this->input->post('term'), FALSE); + $suggestions = $this->xss_clean($this->Customer->get_search_suggestions($this->input->post('term'), FALSE)); echo json_encode($suggestions); } @@ -57,10 +61,16 @@ class Customers extends Person_controller /* Loads the customer edit form */ - function view($customer_id=-1) + public function view($customer_id = -1) { - $data['person_info'] = $this->Customer->get_info($customer_id); - $data['total'] = $this->Customer->get_totals($customer_id)->total; + $info = $this->Customer->get_info($customer_id); + foreach(get_object_vars($info) as $property => $value) + { + $info->$property = $this->xss_clean($value); + } + $data['person_info'] = $info; + + $data['total'] = $this->xss_clean($this->Customer->get_totals($customer_id)->total); $this->load->view("customers/form", $data); } @@ -68,52 +78,58 @@ class Customers extends Person_controller /* Inserts/updates a customer */ - function save($customer_id=-1) + public function save($customer_id = -1) { $person_data = array( - 'first_name'=>$this->input->post('first_name'), - 'last_name'=>$this->input->post('last_name'), - 'gender'=>$this->input->post('gender'), - 'email'=>$this->input->post('email'), - 'phone_number'=>$this->input->post('phone_number'), - 'address_1'=>$this->input->post('address_1'), - 'address_2'=>$this->input->post('address_2'), - 'city'=>$this->input->post('city'), - 'state'=>$this->input->post('state'), - 'zip'=>$this->input->post('zip'), - 'country'=>$this->input->post('country'), - 'comments'=>$this->input->post('comments') + 'first_name' => $this->input->post('first_name'), + 'last_name' => $this->input->post('last_name'), + 'gender' => $this->input->post('gender'), + 'email' => $this->input->post('email'), + 'phone_number' => $this->input->post('phone_number'), + 'address_1' => $this->input->post('address_1'), + 'address_2' => $this->input->post('address_2'), + 'city' => $this->input->post('city'), + 'state' => $this->input->post('state'), + 'zip' => $this->input->post('zip'), + 'country' => $this->input->post('country'), + 'comments' => $this->input->post('comments') ); - $customer_data=array( - 'account_number'=>$this->input->post('account_number') == '' ? null : $this->input->post('account_number'), - 'company_name'=>$this->input->post('company_name') == '' ? null : $this->input->post('company_name'), - 'discount_percent'=>$this->input->post('discount_percent') == '' ? 0.00 : $this->input->post('discount_percent'), - 'taxable'=>$this->input->post('taxable') != null + $customer_data = array( + 'account_number' => $this->input->post('account_number') == '' ? NULL : $this->input->post('account_number'), + 'company_name' => $this->input->post('company_name') == '' ? NULL : $this->input->post('company_name'), + 'discount_percent' => $this->input->post('discount_percent') == '' ? 0.00 : $this->input->post('discount_percent'), + 'taxable' => $this->input->post('taxable') != NULL ); - if($this->Customer->save_customer($person_data,$customer_data,$customer_id)) + + if($this->Customer->save_customer($person_data, $customer_data, $customer_id)) { + $person_data = $this->xss_clean($person_data); + $customer_data = $this->xss_clean($customer_data); + //New customer - if($customer_id==-1) + if($customer_id == -1) { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('customers_successful_adding').' '. - $person_data['first_name'].' '.$person_data['last_name'], 'id' => $customer_data['person_id'])); + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('customers_successful_adding').' '. + $person_data['first_name'].' '.$person_data['last_name'], 'id' => $customer_data['person_id'])); } - else //previous customer + else //Existing customer { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('customers_successful_updating').' '. - $person_data['first_name'].' '.$person_data['last_name'], 'id' => $customer_id)); + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('customers_successful_updating').' '. + $person_data['first_name'].' '.$person_data['last_name'], 'id' => $customer_id)); } } else//failure - { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('customers_error_adding_updating').' '. - $person_data['first_name'].' '.$person_data['last_name'], 'id' => -1)); + { + $person_data = $this->xss_clean($person_data); + + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('customers_error_adding_updating').' '. + $person_data['first_name'].' '.$person_data['last_name'], 'id' => -1)); } } - function check_account_number() + public function check_account_number() { - $exists = $this->Customer->account_number_exists($this->input->post('account_number'),$this->input->post('person_id')); + $exists = $this->Customer->account_number_exists($this->input->post('account_number'), $this->input->post('person_id')); echo !$exists ? 'true' : 'false'; } @@ -121,115 +137,117 @@ class Customers extends Person_controller /* This deletes customers from the customers table */ - function delete() + public function delete() { - $customers_to_delete=$this->input->post('ids'); - + $customers_to_delete = $this->xss_clean($this->input->post('ids')); + if($this->Customer->delete_list($customers_to_delete)) { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('customers_successful_deleted').' '. - count($customers_to_delete).' '.$this->lang->line('customers_one_or_multiple'))); + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('customers_successful_deleted').' '. + count($customers_to_delete).' '.$this->lang->line('customers_one_or_multiple'))); } else { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('customers_cannot_be_deleted'))); + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('customers_cannot_be_deleted'))); } } - - function excel() + + /* + Customers import from excel spreadsheet + */ + public function excel() { - $data = file_get_contents("import_customers.csv"); $name = 'import_customers.csv'; + $data = file_get_contents('../' . $name); force_download($name, $data); } - function excel_import() + public function excel_import() { - $this->load->view("customers/form_excel_import", null); + $this->load->view('customers/form_excel_import', NULL); } - function do_excel_import() + public function do_excel_import() { - $msg = 'do_excel_import'; - $failCodes = array(); - - if ($_FILES['file_path']['error'] != UPLOAD_ERR_OK) + if($_FILES['file_path']['error'] != UPLOAD_ERR_OK) { - $msg = $this->lang->line('items_excel_import_failed'); - echo json_encode( array('success'=>false,'message'=>$msg) ); - - return; + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('customers_excel_import_failed'))); } else { - if (($handle = fopen($_FILES['file_path']['tmp_name'], "r")) !== FALSE) + if(($handle = fopen($_FILES['file_path']['tmp_name'], 'r')) !== FALSE) { // Skip the first row as it's the table description fgetcsv($handle); - - $i=1; - while (($data = fgetcsv($handle)) !== FALSE) + $i = 1; + + $failCodes = array(); + + while(($data = fgetcsv($handle)) !== FALSE) { // XSS file data sanity check - $data = $this->security->xss_clean($data); - - $person_data = array( - 'first_name'=>$data[0], - 'last_name'=>$data[1], - 'gender'=>$data[2], - 'email'=>$data[3], - 'phone_number'=>$data[4], - 'address_1'=>$data[5], - 'address_2'=>$data[6], - 'city'=>$data[7], - 'state'=>$data[8], - 'zip'=>$data[9], - 'country'=>$data[10], - 'comments'=>$data[11] - ); - - $customer_data = array( - 'company_name'=>$data[12], - 'discount_percent'=>$data[14], - 'taxable'=>$data[15]=='' ? 0 : 1 - ); - - $account_number = $data[13]; - $invalidated = false; - if ($account_number != "") + $data = $this->xss_clean($data); + + if(sizeof($data) >= 15) { - $customer_data['account_number'] = $account_number; - $invalidated = $this->Customer->account_number_exists($account_number); + $person_data = array( + 'first_name' => $data[0], + 'last_name' => $data[1], + 'gender' => $data[2], + 'email' => $data[3], + 'phone_number' => $data[4], + 'address_1' => $data[5], + 'address_2' => $data[6], + 'city' => $data[7], + 'state' => $data[8], + 'zip' => $data[9], + 'country' => $data[10], + 'comments' => $data[11] + ); + + $customer_data = array( + 'company_name' => $data[12], + 'discount_percent' => $data[14], + 'taxable' => $data[15] == '' ? 0 : 1 + ); + + $account_number = $data[13]; + $invalidated = FALSE; + if($account_number != '') + { + $customer_data['account_number'] = $account_number; + $invalidated = $this->Customer->account_number_exists($account_number); + } } - + else + { + $invalidated = TRUE; + } + if($invalidated || !$this->Customer->save_customer($person_data, $customer_data)) { $failCodes[] = $i; } - $i++; + ++$i; + } + + if(count($failCodes) > 0) + { + $message = $this->lang->line('customers_excel_import_partially_failed') . ' (' . count($failCodes) . '): ' . implode(', ', $failCodes); + + echo json_encode(array('success' => FALSE, 'message' => $message)); + } + else + { + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('customers_excel_import_success'))); } } else { - echo json_encode( array('success'=>false, 'message'=>'Your uploaded file has no data or wrong format') ); - - return; + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('customers_excel_import_nodata_wrongformat'))); } } - - $success = true; - if(count($failCodes) > 0) - { - $msg = "Most customers imported. But some were not, here is list of their CODE (" .count($failCodes) ."): ".implode(", ", $failCodes); - $success = false; - } - else - { - $msg = "Import of Customers successful"; - } - - echo json_encode( array('success'=>$success, 'message'=>$msg) ); } } ?> \ No newline at end of file diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index a8f484d6d..7bbd8f3a4 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -1,131 +1,168 @@ -get_controller_name(); - $data['table_headers'] = get_people_manage_table_headers(); - $this->load->view('people/manage',$data); + $data['table_headers'] = $this->xss_clean(get_people_manage_table_headers()); + + $this->load->view('people/manage', $data); } /* Returns employee table data rows. This will be called with AJAX. */ - function search() + public function search() { $search = $this->input->get('search'); - $limit = $this->input->get('limit'); + $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); - $sort = $this->input->get('sort'); - $order = $this->input->get('order'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); $employees = $this->Employee->search($search, $limit, $offset, $sort, $order); $total_rows = $this->Employee->get_found_rows($search); + $data_rows = array(); foreach($employees->result() as $person) { $data_rows[] = get_person_data_row($person, $this); } + + $data_rows = $this->xss_clean($data_rows); + echo json_encode(array('total' => $total_rows, 'rows' => $data_rows)); } /* Gives search suggestions based on what is being searched for */ - function suggest_search() + public function suggest_search() { - $suggestions = $this->Employee->get_search_suggestions($this->input->post('term')); + $suggestions = $this->xss_clean($this->Employee->get_search_suggestions($this->input->post('term'))); + echo json_encode($suggestions); } /* Loads the employee edit form */ - function view($employee_id=-1) + public function view($employee_id = -1) { - $data['person_info']=$this->Employee->get_info($employee_id); - $data['all_modules']=$this->Module->get_all_modules(); - $data['all_subpermissions']=$this->Module->get_all_subpermissions(); - $this->load->view("employees/form",$data); + $person_info = $this->Employee->get_info($employee_id); + foreach(get_object_vars($person_info) as $property => $value) + { + $person_info->$property = $this->xss_clean($value); + } + $data['person_info'] = $person_info; + + $modules = array(); + foreach($this->Module->get_all_modules()->result() as $module) + { + $module->module_id = $this->xss_clean($module->module_id); + $module->grant = $this->xss_clean($this->Employee->has_grant($module->module_id, $person_info->person_id)); + + $modules[] = $module; + } + $data['all_modules'] = $modules; + + $permissions = array(); + foreach($this->Module->get_all_subpermissions()->result() as $permission) + { + $permission->module_id = $this->xss_clean($permission->module_id); + $permission->permission_id = $this->xss_clean($permission->permission_id); + $permission->grant = $this->xss_clean($this->Employee->has_grant($permission->permission_id, $person_info->person_id)); + + $permissions[] = $permission; + } + $data['all_subpermissions'] = $permissions; + + $this->load->view("employees/form", $data); } /* Inserts/updates an employee */ - function save($employee_id=-1) + public function save($employee_id = -1) { $person_data = array( - 'first_name'=>$this->input->post('first_name'), - 'last_name'=>$this->input->post('last_name'), - 'gender'=>$this->input->post('gender'), - 'email'=>$this->input->post('email'), - 'phone_number'=>$this->input->post('phone_number'), - 'address_1'=>$this->input->post('address_1'), - 'address_2'=>$this->input->post('address_2'), - 'city'=>$this->input->post('city'), - 'state'=>$this->input->post('state'), - 'zip'=>$this->input->post('zip'), - 'country'=>$this->input->post('country'), - 'comments'=>$this->input->post('comments') + 'first_name' => $this->input->post('first_name'), + 'last_name' => $this->input->post('last_name'), + 'gender' => $this->input->post('gender'), + 'email' => $this->input->post('email'), + 'phone_number' => $this->input->post('phone_number'), + 'address_1' => $this->input->post('address_1'), + 'address_2' => $this->input->post('address_2'), + 'city' => $this->input->post('city'), + 'state' => $this->input->post('state'), + 'zip' => $this->input->post('zip'), + 'country' => $this->input->post('country'), + 'comments' => $this->input->post('comments'), ); - $grants_data = $this->input->post('grants') != null ? $this->input->post('grants') : array(); + $grants_data = $this->input->post('grants') != NULL ? $this->input->post('grants') : array(); //Password has been changed OR first time password set - if ( $this->input->post('password') != '' ) + if($this->input->post('password') != '') { - $employee_data=array( - 'username'=>$this->input->post('username'), - 'password'=>md5($this->input->post('password')) + $employee_data = array( + 'username' => $this->input->post('username'), + 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT), + 'hash_version' => 2 ); } else //Password not changed { - $employee_data=array('username'=>$this->input->post('username')); + $employee_data = array('username' => $this->input->post('username')); } - if($this->Employee->save_employee($person_data,$employee_data,$grants_data,$employee_id)) + if($this->Employee->save_employee($person_data, $employee_data, $grants_data, $employee_id)) { + $person_data = $this->xss_clean($person_data); + $employee_data = $this->xss_clean($employee_data); + //New employee - if($employee_id==-1) + if($employee_id == -1) { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('employees_successful_adding').' '. - $person_data['first_name'].' '.$person_data['last_name'],'id'=>$employee_data['person_id'])); + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('employees_successful_adding').' '. + $person_data['first_name'].' '.$person_data['last_name'], 'id' => $employee_data['person_id'])); } - else //previous employee + else //Existing employee { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('employees_successful_updating').' '. - $person_data['first_name'].' '.$person_data['last_name'],'id'=>$employee_id)); + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('employees_successful_updating').' '. + $person_data['first_name'].' '.$person_data['last_name'], 'id' => $employee_id)); } } else//failure - { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('employees_error_adding_updating').' '. - $person_data['first_name'].' '.$person_data['last_name'],'id'=>-1)); + { + $person_data = $this->xss_clean($person_data); + + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('employees_error_adding_updating').' '. + $person_data['first_name'].' '.$person_data['last_name'], 'id' => -1)); } } /* This deletes employees from the employees table */ - function delete() + public function delete() { - $employees_to_delete=$this->input->post('ids'); - + $employees_to_delete = $this->xss_clean($this->input->post('ids')); + if($this->Employee->delete_list($employees_to_delete)) { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('employees_successful_deleted').' '. - count($employees_to_delete).' '.$this->lang->line('employees_one_or_multiple'))); + echo json_encode(array('success' => TRUE,'message' => $this->lang->line('employees_successful_deleted').' '. + count($employees_to_delete).' '.$this->lang->line('employees_one_or_multiple'))); } else { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('employees_cannot_be_deleted'))); + echo json_encode(array('success' => FALSE,'message' => $this->lang->line('employees_cannot_be_deleted'))); } } } diff --git a/application/controllers/Giftcards.php b/application/controllers/Giftcards.php index f5d7bfbb3..50241b65c 100644 --- a/application/controllers/Giftcards.php +++ b/application/controllers/Giftcards.php @@ -1,19 +1,17 @@ -get_controller_name(); - $data['table_headers'] = get_giftcards_manage_table_headers(); + $data['table_headers'] = $this->xss_clean(get_giftcards_manage_table_headers()); $this->load->view('giftcards/manage', $data); } @@ -21,13 +19,13 @@ class Giftcards extends Secure_area implements iData_controller /* Returns Giftcards table data rows. This will be called with AJAX. */ - function search() + public function search() { $search = $this->input->get('search'); - $limit = $this->input->get('limit'); + $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); - $sort = $this->input->get('sort'); - $order = $this->input->get('order'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); $giftcards = $this->Giftcard->search($search, $limit, $offset, $sort, $order); $total_rows = $this->Giftcard->get_found_rows($search); @@ -37,78 +35,90 @@ class Giftcards extends Secure_area implements iData_controller { $data_rows[] = get_giftcard_data_row($giftcard, $this); } + + $data_rows = $this->xss_clean($data_rows); + echo json_encode(array('total' => $total_rows, 'rows' => $data_rows)); } /* Gives search suggestions based on what is being searched for */ - function suggest_search() + public function suggest_search() { - $suggestions = $this->Giftcard->get_search_suggestions($this->input->post('term')); + $suggestions = $this->xss_clean($this->Giftcard->get_search_suggestions($this->input->post('term'))); + echo json_encode($suggestions); } - function get_row($row_id) + public function get_row($row_id) { - $data_row = get_giftcard_data_row($this->Giftcard->get_info($row_id), $this); + $data_row = $this->xss_clean(get_giftcard_data_row($this->Giftcard->get_info($row_id), $this)); + echo json_encode($data_row); } - function view($giftcard_id=-1) + public function view($giftcard_id = -1) { $giftcard_info = $this->Giftcard->get_info($giftcard_id); - $person_name=$giftcard_id > 0? $giftcard_info->first_name . ' ' . $giftcard_info->last_name : ''; - $data['selected_person_name'] = $giftcard_id > 0 && isset($giftcard_info->person_id) ? $person_name : ''; - $data['selected_person_id'] = $giftcard_info->person_id; - $data['giftcard_number'] = $giftcard_id > 0 ? $giftcard_info->giftcard_number : $this->Giftcard->get_max_number()->giftcard_number + 1; - $data['giftcard_info'] = $giftcard_info; - $this->load->view("giftcards/form",$data); + + $data['selected_person_name'] = ($giftcard_id > 0 && isset($giftcard_info->person_id)) ? $giftcard_info->first_name . ' ' . $giftcard_info->last_name : ''; + $data['selected_person_id'] = $giftcard_info->person_id; + $data['giftcard_number'] = $giftcard_id > 0 ? $giftcard_info->giftcard_number : $this->Giftcard->get_max_number()->giftcard_number + 1; + $data['giftcard_id'] = $giftcard_id; + $data['giftcard_value'] = $giftcard_info->value; + + $data = $this->xss_clean($data); + + $this->load->view("giftcards/form", $data); } - function save($giftcard_id=-1) + public function save($giftcard_id = -1) { $giftcard_data = array( 'record_time' => date('Y-m-d H:i:s'), - 'giftcard_number'=>$this->input->post('giftcard_number', TRUE), - 'value'=>$this->input->post('value', TRUE), - 'person_id'=>$this->input->post('person_id', TRUE) ? $this->input->post('person_id') : null + 'giftcard_number' => $this->input->post('giftcard_number'), + 'value' => parse_decimals($this->input->post('value')), + 'person_id' => $this->input->post('person_id') == '' ? NULL : $this->input->post('person_id') ); - if( $this->Giftcard->save( $giftcard_data, $giftcard_id ) ) + if($this->Giftcard->save($giftcard_data, $giftcard_id)) { + $giftcard_data = $this->xss_clean($giftcard_data); + //New giftcard - if($giftcard_id==-1) + if($giftcard_id == -1) { - echo json_encode(array('success'=>true, 'message'=>$this->lang->line('giftcards_successful_adding').' '. - $giftcard_data['giftcard_number'], 'id'=>$giftcard_data['giftcard_id'])); - $giftcard_id = $giftcard_data['giftcard_id']; + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('giftcards_successful_adding').' '. + $giftcard_data['giftcard_number'], 'id' => $giftcard_data['giftcard_id'])); } - else //previous giftcard + else //Existing giftcard { - echo json_encode(array('success'=>true, 'message'=>$this->lang->line('giftcards_successful_updating').' '. - $giftcard_data['giftcard_number'], 'id'=>$giftcard_id)); + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('giftcards_successful_updating').' '. + $giftcard_data['giftcard_number'], 'id' => $giftcard_id)); } } - else//failure + else //failure { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('giftcards_error_adding_updating').' '. - $giftcard_data['giftcard_number'], 'id'=>-1)); + $giftcard_data = $this->xss_clean($giftcard_data); + + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('giftcards_error_adding_updating').' '. + $giftcard_data['giftcard_number'], 'id' => -1)); } } - function delete() + public function delete() { - $giftcards_to_delete=$this->input->post('ids'); + $giftcards_to_delete = $this->xss_clean($this->input->post('ids')); if($this->Giftcard->delete_list($giftcards_to_delete)) { - echo json_encode(array('success'=>true, 'message'=>$this->lang->line('giftcards_successful_deleted').' '. + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('giftcards_successful_deleted').' '. count($giftcards_to_delete).' '.$this->lang->line('giftcards_one_or_multiple'))); } else { - echo json_encode(array('success'=>false, 'message'=>$this->lang->line('giftcards_cannot_be_deleted'))); + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('giftcards_cannot_be_deleted'))); } } } diff --git a/application/controllers/Home.php b/application/controllers/Home.php index ed78c8161..a2b812dfa 100644 --- a/application/controllers/Home.php +++ b/application/controllers/Home.php @@ -1,20 +1,23 @@ -load->view("home"); + $this->load->view('home'); } - - function logout() + + public function logout() { + $this->track_page('logout', 'logout'); + $this->Employee->logout(); } } diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index 5071cb9e4..07498a20f 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -1,23 +1,29 @@ -total_cost_price = 0; $item_kit->total_unit_price = 0; - foreach ($this->Item_kit_items->get_info($item_kit->item_kit_id) as $item_kit_item) + foreach($this->Item_kit_items->get_info($item_kit->item_kit_id) as $item_kit_item) { $item_info = $this->Item->get_info($item_kit_item['item_id']); + foreach(get_object_vars($item_info) as $property => $value) + { + $item_info->$property = $this->xss_clean($value); + } $item_kit->total_cost_price += $item_info->cost_price * $item_kit_item['quantity']; $item_kit->total_unit_price += $item_info->unit_price * $item_kit_item['quantity']; @@ -26,10 +32,9 @@ class Item_kits extends Secure_area implements iData_controller return $item_kit; } - function index() + public function index() { - $data['controller_name'] = $this->get_controller_name(); - $data['table_headers'] = get_item_kits_manage_table_headers(); + $data['table_headers'] = $this->xss_clean(get_item_kits_manage_table_headers()); $this->load->view('item_kits/manage', $data); } @@ -37,13 +42,13 @@ class Item_kits extends Secure_area implements iData_controller /* Returns Item kits table data rows. This will be called with AJAX. */ - function search() + public function search() { $search = $this->input->get('search'); - $limit = $this->input->get('limit'); + $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); - $sort = $this->input->get('sort'); - $order = $this->input->get('order'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); $item_kits = $this->Item_kit->search($search, $limit, $offset, $sort, $order); $total_rows = $this->Item_kit->get_found_rows($search); @@ -52,49 +57,70 @@ class Item_kits extends Secure_area implements iData_controller foreach($item_kits->result() as $item_kit) { // calculate the total cost and retail price of the Kit so it can be printed out in the manage table - $item_kit = $this->add_totals_to_item_kit($item_kit); + $item_kit = $this->_add_totals_to_item_kit($item_kit); $data_rows[] = get_item_kit_data_row($item_kit, $this); } + $data_rows = $this->xss_clean($data_rows); + echo json_encode(array('total' => $total_rows, 'rows' => $data_rows)); } - function suggest_search() + public function suggest_search() { - $suggestions = $this->Item_kit->get_search_suggestions($this->input->post('term')); + $suggestions = $this->xss_clean($this->Item_kit->get_search_suggestions($this->input->post('term'))); + echo json_encode($suggestions); } - function get_row($row_id) + public function get_row($row_id) { // calculate the total cost and retail price of the Kit so it can be added to the table refresh - $item_kit = $this->add_totals_to_item_kit($this->Item_kit->get_info($row_id)); + $item_kit = $this->_add_totals_to_item_kit($this->Item_kit->get_info($row_id)); echo json_encode(get_item_kit_data_row($item_kit, $this)); } - - function view($item_kit_id=-1) + + public function view($item_kit_id = -1) { - $data['item_kit_info'] = $this->Item_kit->get_info($item_kit_id); + $info = $this->Item_kit->get_info($item_kit_id); + foreach(get_object_vars($info) as $property => $value) + { + $info->$property = $this->xss_clean($value); + } + $data['item_kit_info'] = $info; + + $items = array(); + foreach($this->Item_kit_items->get_info($item_kit_id) as $item_kit_item) + { + $item['name'] = $this->xss_clean($this->Item->get_info($item_kit_item['item_id'])->name); + $item['item_id'] = $this->xss_clean($item_kit_item['item_id']); + $item['quantity'] = $this->xss_clean($item_kit_item['quantity']); + + $items[] = $item; + } + $data['item_kit_items'] = $items; + $this->load->view("item_kits/form", $data); } - function save($item_kit_id=-1) + public function save($item_kit_id = -1) { $item_kit_data = array( 'name' => $this->input->post('name'), 'description' => $this->input->post('description') ); - if ($this->Item_kit->save($item_kit_data, $item_kit_id)) + if($this->Item_kit->save($item_kit_data, $item_kit_id)) { $success = TRUE; //New item kit - if ($item_kit_id==-1) { + if ($item_kit_id == -1) + { $item_kit_id = $item_kit_data['item_kit_id']; } - if ( $this->input->post('item_kit_item') != null ) + if($this->input->post('item_kit_item') != NULL) { $item_kit_items = array(); foreach($this->input->post('item_kit_item') as $item_id => $quantity) @@ -107,46 +133,52 @@ class Item_kits extends Secure_area implements iData_controller $success = $this->Item_kit_items->save($item_kit_items, $item_kit_id); } - echo json_encode(array('success'=>$success, - 'message'=>$this->lang->line('item_kits_successful_adding').' '.$item_kit_data['name'], - 'id'=>$item_kit_id)); + + $item_kit_data = $this->xss_clean($item_kit_data); + + echo json_encode(array('success' => $success, + 'message' => $this->lang->line('item_kits_successful_adding').' '.$item_kit_data['name'], 'id' => $item_kit_id)); } else//failure { - echo json_encode(array('success'=>false, - 'message'=>$this->lang->line('item_kits_error_adding_updating').' '.$item_kit_data['name'], - 'id'=>-1)); + $item_kit_data = $this->xss_clean($item_kit_data); + + echo json_encode(array('success' => FALSE, + 'message' => $this->lang->line('item_kits_error_adding_updating').' '.$item_kit_data['name'], 'id' => -1)); } } - function delete() + public function delete() { - $item_kits_to_delete = $this->input->post('ids'); + $item_kits_to_delete = $this->xss_clean($this->input->post('ids')); - if ($this->Item_kit->delete_list($item_kits_to_delete)) + if($this->Item_kit->delete_list($item_kits_to_delete)) { - echo json_encode(array('success'=>true, - 'message'=>$this->lang->line('item_kits_successful_deleted').' '.count($item_kits_to_delete).' '.$this->lang->line('item_kits_one_or_multiple'))); + echo json_encode(array('success' => TRUE, + 'message' => $this->lang->line('item_kits_successful_deleted').' '.count($item_kits_to_delete).' '.$this->lang->line('item_kits_one_or_multiple'))); } else { - echo json_encode(array('success'=>false, - 'message'=>$this->lang->line('item_kits_cannot_be_deleted'))); + echo json_encode(array('success' => FALSE, + 'message' => $this->lang->line('item_kits_cannot_be_deleted'))); } } - function generate_barcodes($item_kit_ids) + public function generate_barcodes($item_kit_ids) { $this->load->library('barcode_lib'); $result = array(); $item_kit_ids = explode(':', $item_kit_ids); - foreach ($item_kit_ids as $item_kid_id) + foreach($item_kit_ids as $item_kid_id) { // calculate the total cost and retail price of the Kit so it can be added to the barcode text at the bottom - $item_kit = $this->add_totals_to_item_kit($this->Item_kit->get_info($item_kid_id)); + $item_kit = $this->_add_totals_to_item_kit($this->Item_kit->get_info($item_kid_id)); + + $item_kid_id = 'KIT '. urldecode($item_kid_id); - $result[] = array('name'=>$item_kit->name, 'item_id'=>urldecode($item_kid_id), 'item_number'=>urldecode($item_kid_id), 'cost_price'=>$item_kit->total_cost_price, 'unit_price'=>$item_kit->total_unit_price); + $result[] = array('name' => $item_kit->name, 'item_id' => $item_kid_id, 'item_number' => $item_kid_id, + 'cost_price' => $item_kit->total_cost_price, 'unit_price' => $item_kit->total_unit_price); } $data['items'] = $result; @@ -158,7 +190,7 @@ class Item_kits extends Secure_area implements iData_controller $barcode_config['barcode_type'] = 'Code128'; } $data['barcode_config'] = $barcode_config; - + // display barcodes $this->load->view("barcodes/barcode_sheet", $data); } diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 31fc7ee7b..39c93e5f6 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -1,20 +1,22 @@ -load->library('item_lib'); } - function index() + public function index() { - $stock_location = $this->item_lib->get_item_location(); - $stock_locations = $this->Stock_location->get_allowed_locations(); - $data['controller_name'] = $this->get_controller_name(); + $data['table_headers'] = $this->xss_clean(get_items_manage_table_headers()); + + $data['stock_location'] = $this->xss_clean($this->item_lib->get_item_location()); + $data['stock_locations'] = $this->xss_clean($this->Stock_location->get_allowed_locations()); // filters that will be loaded in the multiselect dropdown $data['filters'] = array('empty_upc' => $this->lang->line('items_empty_upc_items'), @@ -24,18 +26,13 @@ class Items extends Secure_area implements iData_controller 'search_custom' => $this->lang->line('items_search_custom_items'), 'is_deleted' => $this->lang->line('items_is_deleted')); - $data['stock_location'] = $stock_location; - $data['stock_locations'] = $stock_locations; - - $data['table_headers'] = get_items_manage_table_headers(); - $this->load->view('items/manage', $data); } /* Returns Items table data rows. This will be called with AJAX. */ - function search() + public function search() { $search = $this->input->get('search'); $limit = $this->input->get('limit'); @@ -56,7 +53,7 @@ class Items extends Secure_area implements iData_controller 'is_deleted' => FALSE); // check if any filter is set in the multiselect dropdown - $filledup = array_fill_keys($this->input->get('filters'), true); + $filledup = array_fill_keys($this->input->get('filters'), TRUE); $filters = array_merge($filters, $filledup); $items = $this->Item->search($search, $filters, $limit, $offset, $sort, $order); @@ -65,23 +62,24 @@ class Items extends Secure_area implements iData_controller $data_rows = array(); foreach($items->result() as $item) { - $data_rows[] = get_item_data_row($item, $this); + $data_rows[] = $this->xss_clean(get_item_data_row($item, $this)); } + echo json_encode(array('total' => $total_rows, 'rows' => $data_rows)); } - function pic_thumb($pic_id) + public function pic_thumb($pic_id) { $this->load->helper('file'); $this->load->library('image_lib'); - $base_path = "uploads/item_pics/" . $pic_id ; - $images = glob ($base_path. "*"); - if (sizeof($images) > 0) + $base_path = './uploads/item_pics/' . $pic_id; + $images = glob($base_path . '.*'); + if(sizeof($images) > 0) { $image_path = $images[0]; $ext = pathinfo($image_path, PATHINFO_EXTENSION); - $thumb_path = $base_path . $this->image_lib->thumb_marker.'.'.$ext; - if (sizeof($images) < 2) + $thumb_path = $base_path . $this->image_lib->thumb_marker . '.' . $ext; + if(sizeof($images) < 2) { $config['image_library'] = 'gd2'; $config['source_image'] = $image_path; @@ -101,26 +99,18 @@ class Items extends Secure_area implements iData_controller /* Gives search suggestions based on what is being searched for */ - function suggest_search() + public function suggest_search() { - $suggestions = $this->Item->get_search_suggestions($this->input->post_get('term'), - array( - 'search_custom' => $this->input->post('search_custom'), - 'is_deleted' => $this->input->post('is_deleted') != null - ), - FALSE); + $suggestions = $this->xss_clean($this->Item->get_search_suggestions($this->input->post_get('term'), + array('search_custom' => $this->input->post('search_custom'), 'is_deleted' => $this->input->post('is_deleted') != NULL), FALSE)); echo json_encode($suggestions); } - function suggest() + public function suggest() { - $suggestions = $this->Item->get_search_suggestions($this->input->post_get('term'), - array( - 'search_custom' => FALSE, - 'is_deleted' => FALSE - ), - TRUE); + $suggestions = $this->xss_clean($this->Item->get_search_suggestions($this->input->post_get('term'), + array('search_custom' => FALSE, 'is_deleted' => FALSE), TRUE)); echo json_encode($suggestions); } @@ -128,9 +118,9 @@ class Items extends Secure_area implements iData_controller /* Gives search suggestions based on what is being searched for */ - function suggest_category() + public function suggest_category() { - $suggestions = $this->Item->get_category_suggestions($this->input->get('term')); + $suggestions = $this->xss_clean($this->Item->get_category_suggestions($this->input->get('term'))); echo json_encode($suggestions); } @@ -138,9 +128,9 @@ class Items extends Secure_area implements iData_controller /* Gives search suggestions based on what is being searched for */ - function suggest_location() + public function suggest_location() { - $suggestions = $this->Item->get_location_suggestions($this->input->get('term')); + $suggestions = $this->xss_clean($this->Item->get_location_suggestions($this->input->get('term'))); echo json_encode($suggestions); } @@ -148,191 +138,216 @@ class Items extends Secure_area implements iData_controller /* Gives search suggestions based on what is being searched for */ - function suggest_custom() + public function suggest_custom() { - $suggestions = $this->Item->get_custom_suggestions($this->input->post('term'), $this->input->post('field_no')); + $suggestions = $this->xss_clean($this->Item->get_custom_suggestions($this->input->post('term'), $this->input->post('field_no'))); echo json_encode($suggestions); } - function get_row($item_ids) + public function get_row($item_ids) { $item_infos = $this->Item->get_multiple_info(explode(":", $item_ids), $this->item_lib->get_item_location()); + $result = array(); foreach($item_infos->result() as $item_info) { - $result[$item_info->item_id] = get_item_data_row($item_info,$this); + $result[$item_info->item_id] = $this->xss_clean(get_item_data_row($item_info, $this)); } + echo json_encode($result); } - function view($item_id=-1) + public function view($item_id = -1) { - $item_info = $this->Item->get_info($item_id); - - $data['item_tax_info'] = $this->Item_taxes->get_info($item_id); + $data['item_tax_info'] = $this->xss_clean($this->Item_taxes->get_info($item_id)); $data['default_tax_1_rate'] = ''; $data['default_tax_2_rate'] = ''; - if($item_id==-1) + $item_info = $this->Item->get_info($item_id); + foreach(get_object_vars($item_info) as $property => $value) { - $data['default_tax_1_rate'] = $this->Appconfig->get('default_tax_1_rate'); - $data['default_tax_2_rate'] = $this->Appconfig->get('default_tax_2_rate'); + $item_info->$property = $this->xss_clean($value); + } + + if($item_id == -1) + { + $data['default_tax_1_rate'] = $this->config->item('default_tax_1_rate'); + $data['default_tax_2_rate'] = $this->config->item('default_tax_2_rate'); $item_info->receiving_quantity = 0; $item_info->reorder_level = 0; } $data['item_info'] = $item_info; - - $suppliers = array(''=>$this->lang->line('items_none')); + + $suppliers = array('' => $this->lang->line('items_none')); foreach($this->Supplier->get_all()->result_array() as $row) { - $suppliers[$row['person_id']] = $row['company_name']; + $suppliers[$this->xss_clean($row['person_id'])] = $this->xss_clean($row['company_name']); } $data['suppliers'] = $suppliers; $data['selected_supplier'] = $item_info->supplier_id; $data['logo_exists'] = $item_info->pic_id != ''; - $images = glob("uploads/item_pics/" . $item_info->pic_id . ".*"); - $data['image_path'] = sizeof($images) > 0 ? base_url($images[0]) : ''; + if (!empty($item_info->pic_id)) + { + $images = glob('./uploads/item_pics/' . $item_info->pic_id . '.*'); + $data['image_path'] = sizeof($images) > 0 ? base_url($images[0]) : ''; + } - $locations_data = $this->Stock_location->get_undeleted_all()->result_array(); - foreach($locations_data as $location) + $stock_locations = $this->Stock_location->get_undeleted_all()->result_array(); + foreach($stock_locations as $location) { - $quantity = $this->Item_quantity->get_item_quantity($item_id,$location['location_id'])->quantity; + $location = $this->xss_clean($location); + + $quantity = $this->xss_clean($this->Item_quantity->get_item_quantity($item_id, $location['location_id'])->quantity); $quantity = ($item_id == -1) ? 0 : $quantity; - $location_array[$location['location_id']] = array('location_name'=>$location['location_name'], 'quantity'=>$quantity); + $location_array[$location['location_id']] = array('location_name' => $location['location_name'], 'quantity' => $quantity); $data['stock_locations'] = $location_array; } - $this->load->view("items/form", $data); + $this->load->view('items/form', $data); } - function inventory($item_id=-1) + public function inventory($item_id = -1) { - $data['item_info'] = $this->Item->get_info($item_id); - + $item_info = $this->Item->get_info($item_id); + foreach(get_object_vars($item_info) as $property => $value) + { + $item_info->$property = $this->xss_clean($value); + } + $data['item_info'] = $item_info; + $data['stock_locations'] = array(); $stock_locations = $this->Stock_location->get_undeleted_all()->result_array(); - foreach($stock_locations as $location_data) - { - $data['stock_locations'][$location_data['location_id']] = $location_data['location_name']; - $data['item_quantities'][$location_data['location_id']] = $this->Item_quantity->get_item_quantity($item_id,$location_data['location_id'])->quantity; - } - - $this->load->view("items/form_inventory", $data); + foreach($stock_locations as $location) + { + $location = $this->xss_clean($location); + $quantity = $this->xss_clean($this->Item_quantity->get_item_quantity($item_id, $location['location_id'])->quantity); + + $data['stock_locations'][$location['location_id']] = $location['location_name']; + $data['item_quantities'][$location['location_id']] = $quantity; + } + + $this->load->view('items/form_inventory', $data); } - function count_details($item_id=-1) + public function count_details($item_id = -1) { - $data['item_info'] = $this->Item->get_info($item_id); - + $item_info = $this->Item->get_info($item_id); + foreach(get_object_vars($item_info) as $property => $value) + { + $item_info->$property = $this->xss_clean($value); + } + $data['item_info'] = $item_info; + $data['stock_locations'] = array(); $stock_locations = $this->Stock_location->get_undeleted_all()->result_array(); - foreach($stock_locations as $location_data) - { - $data['stock_locations'][$location_data['location_id']] = $location_data['location_name']; - $data['item_quantities'][$location_data['location_id']] = $this->Item_quantity->get_item_quantity($item_id,$location_data['location_id'])->quantity; - } - - $this->load->view("items/form_count_details", $data); + foreach($stock_locations as $location) + { + $location = $this->xss_clean($location); + $quantity = $this->xss_clean($this->Item_quantity->get_item_quantity($item_id, $location['location_id'])->quantity); + + $data['stock_locations'][$location['location_id']] = $location['location_name']; + $data['item_quantities'][$location['location_id']] = $quantity; + } + + $this->load->view('items/form_count_details', $data); } - function generate_barcodes($item_ids) + public function generate_barcodes($item_ids) { $this->load->library('barcode_lib'); - $result = array(); $item_ids = explode(':', $item_ids); $result = $this->Item->get_multiple_info($item_ids, $this->item_lib->get_item_location())->result_array(); $config = $this->barcode_lib->get_barcode_config(); $data['barcode_config'] = $config; - + // check the list of items to see if any item_number field is empty foreach($result as &$item) { - // update the UPC/EAN/ISBN field if empty / null with the newly generated barcode - if (empty($item['item_number']) && $this->Appconfig->get('barcode_generate_if_empty')) + $item = $this->xss_clean($item); + + // update the UPC/EAN/ISBN field if empty / NULL with the newly generated barcode + if(empty($item['item_number']) && $this->config->item('barcode_generate_if_empty')) { // get the newly generated barcode $barcode_instance = Barcode_lib::barcode_instance($item, $config); $item['item_number'] = $barcode_instance->getData(); - // remove from item any suppliers table info to avoid save failure because of unknown fields - // WARNING: if suppliers table is changed this list needs to be upgraded, which makes the matter a bit tricky to maintain - unset($item['person_id']); - unset($item['company_name']); - unset($item['account_number']); - unset($item['agency_name']); + $save_item = array('item_number' => $item['item_number']); + // update the item in the database in order to save the UPC/EAN/ISBN field - $this->Item->save($item, $item['item_id']); + $this->Item->save($save_item, $item['item_id']); } } $data['items'] = $result; // display barcodes - $this->load->view("barcodes/barcode_sheet", $data); + $this->load->view('barcodes/barcode_sheet', $data); } - function bulk_edit() + public function bulk_edit() { - $data = array(); $suppliers = array('' => $this->lang->line('items_none')); foreach($this->Supplier->get_all()->result_array() as $row) { + $row = $this->xss_clean($row); + $suppliers[$row['person_id']] = $row['company_name']; } $data['suppliers'] = $suppliers; $data['allow_alt_description_choices'] = array( - ''=>$this->lang->line('items_do_nothing'), - 1 =>$this->lang->line('items_change_all_to_allow_alt_desc'), - 0 =>$this->lang->line('items_change_all_to_not_allow_allow_desc')); + '' => $this->lang->line('items_do_nothing'), + 1 => $this->lang->line('items_change_all_to_allow_alt_desc'), + 0 => $this->lang->line('items_change_all_to_not_allow_allow_desc')); $data['serialization_choices'] = array( - ''=>$this->lang->line('items_do_nothing'), - 1 =>$this->lang->line('items_change_all_to_serialized'), - 0 =>$this->lang->line('items_change_all_to_unserialized')); + '' => $this->lang->line('items_do_nothing'), + 1 => $this->lang->line('items_change_all_to_serialized'), + 0 => $this->lang->line('items_change_all_to_unserialized')); - $this->load->view("items/form_bulk", $data); + $this->load->view('items/form_bulk', $data); } - function save($item_id=-1) + public function save($item_id = -1) { $upload_success = $this->_handle_image_upload(); $upload_data = $this->upload->data(); //Save item data $item_data = array( - 'name'=>$this->input->post('name'), - 'description'=>$this->input->post('description'), - 'category'=>$this->input->post('category'), - 'supplier_id'=>$this->input->post('supplier_id') == '' ? null : $this->input->post('supplier_id'), - 'item_number'=>$this->input->post('item_number') == '' ? null : $this->input->post('item_number'), - 'cost_price'=>$this->input->post('cost_price'), - 'unit_price'=>$this->input->post('unit_price'), - 'reorder_level'=>$this->input->post('reorder_level'), - 'receiving_quantity'=>$this->input->post('receiving_quantity'), - 'allow_alt_description'=>$this->input->post('allow_alt_description') != null, - 'is_serialized'=>$this->input->post('is_serialized') != null, - 'deleted'=>$this->input->post('is_deleted') != null, - 'custom1'=>$this->input->post('custom1') == null ? '' : $this->input->post('custom1'), - 'custom2'=>$this->input->post('custom2') == null ? '' : $this->input->post('custom2'), - 'custom3'=>$this->input->post('custom3') == null ? '' : $this->input->post('custom3'), - 'custom4'=>$this->input->post('custom4') == null ? '' : $this->input->post('custom4'), - 'custom5'=>$this->input->post('custom5') == null ? '' : $this->input->post('custom5'), - 'custom6'=>$this->input->post('custom6') == null ? '' : $this->input->post('custom6'), - 'custom7'=>$this->input->post('custom7') == null ? '' : $this->input->post('custom7'), - 'custom8'=>$this->input->post('custom8') == null ? '' : $this->input->post('custom8'), - 'custom9'=>$this->input->post('custom9') == null ? '' : $this->input->post('custom9'), - 'custom10'=>$this->input->post('custom10') == null ? '' : $this->input->post('custom10') + 'name' => $this->input->post('name'), + 'description' => $this->input->post('description'), + 'category' => $this->input->post('category'), + 'supplier_id' => $this->input->post('supplier_id') == '' ? NULL : $this->input->post('supplier_id'), + 'item_number' => $this->input->post('item_number') == '' ? NULL : $this->input->post('item_number'), + 'cost_price' => parse_decimals($this->input->post('cost_price')), + 'unit_price' => parse_decimals($this->input->post('unit_price')), + 'reorder_level' => parse_decimals($this->input->post('reorder_level')), + 'receiving_quantity' => parse_decimals($this->input->post('receiving_quantity')), + 'allow_alt_description' => $this->input->post('allow_alt_description') != NULL, + 'is_serialized' => $this->input->post('is_serialized') != NULL, + 'deleted' => $this->input->post('is_deleted') != NULL, + 'custom1' => $this->input->post('custom1') == NULL ? '' : $this->input->post('custom1'), + 'custom2' => $this->input->post('custom2') == NULL ? '' : $this->input->post('custom2'), + 'custom3' => $this->input->post('custom3') == NULL ? '' : $this->input->post('custom3'), + 'custom4' => $this->input->post('custom4') == NULL ? '' : $this->input->post('custom4'), + 'custom5' => $this->input->post('custom5') == NULL ? '' : $this->input->post('custom5'), + 'custom6' => $this->input->post('custom6') == NULL ? '' : $this->input->post('custom6'), + 'custom7' => $this->input->post('custom7') == NULL ? '' : $this->input->post('custom7'), + 'custom8' => $this->input->post('custom8') == NULL ? '' : $this->input->post('custom8'), + 'custom9' => $this->input->post('custom9') == NULL ? '' : $this->input->post('custom9'), + 'custom10' => $this->input->post('custom10') == NULL ? '' : $this->input->post('custom10') ); - if (!empty($upload_data['orig_name'])) + if(!empty($upload_data['orig_name'])) { // XSS file image sanity check - if ($this->security->xss_clean($upload_data['raw_name'], TRUE) === TRUE) + if($this->xss_clean($upload_data['raw_name'], TRUE) === TRUE) { $item_data['pic_id'] = $upload_data['raw_name']; } @@ -341,12 +356,12 @@ class Items extends Secure_area implements iData_controller $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; $cur_item_info = $this->Item->get_info($item_id); - if($this->Item->save($item_data,$item_id)) + if($this->Item->save($item_data, $item_id)) { $success = TRUE; $new_item = FALSE; //New item - if ($item_id==-1) + if($item_id == -1) { $item_id = $item_data['item_id']; $new_item = TRUE; @@ -355,64 +370,67 @@ class Items extends Secure_area implements iData_controller $items_taxes_data = array(); $tax_names = $this->input->post('tax_names'); $tax_percents = $this->input->post('tax_percents'); - for($k = 0; $k < count($tax_percents); $k++) + $count = count($tax_percents); + for ($k = 0; $k < $count; ++$k) { - if (is_numeric($tax_percents[$k])) + $tax_percentage = parse_decimals($tax_percents[$k]); + if(is_numeric($tax_percentage)) { - $items_taxes_data[] = array('name'=>$tax_names[$k], 'percent'=>$tax_percents[$k] ); + $items_taxes_data[] = array('name' => $tax_names[$k], 'percent' => $tax_percentage); } } $success &= $this->Item_taxes->save($items_taxes_data, $item_id); //Save item quantity $stock_locations = $this->Stock_location->get_undeleted_all()->result_array(); - foreach($stock_locations as $location_data) + foreach($stock_locations as $location) { - $updated_quantity = $this->input->post('quantity_' . $location_data['location_id']); - $location_detail = array('item_id'=>$item_id, - 'location_id'=>$location_data['location_id'], - 'quantity'=>$updated_quantity); - $item_quantity = $this->Item_quantity->get_item_quantity($item_id, $location_data['location_id']); - if ($item_quantity->quantity != $updated_quantity || $new_item) + $updated_quantity = parse_decimals($this->input->post('quantity_' . $location['location_id'])); + $location_detail = array('item_id' => $item_id, + 'location_id' => $location['location_id'], + 'quantity' => $updated_quantity); + $item_quantity = $this->Item_quantity->get_item_quantity($item_id, $location['location_id']); + if($item_quantity->quantity != $updated_quantity || $new_item) { - $success &= $this->Item_quantity->save($location_detail, $item_id, $location_data['location_id']); + $success &= $this->Item_quantity->save($location_detail, $item_id, $location['location_id']); $inv_data = array( - 'trans_date'=>date('Y-m-d H:i:s'), - 'trans_items'=>$item_id, - 'trans_user'=>$employee_id, - 'trans_location'=>$location_data['location_id'], - 'trans_comment'=>$this->lang->line('items_manually_editing_of_quantity'), - 'trans_inventory'=>$updated_quantity - $item_quantity->quantity + 'trans_date' => date('Y-m-d H:i:s'), + 'trans_items' => $item_id, + 'trans_user' => $employee_id, + 'trans_location' => $location['location_id'], + 'trans_comment' => $this->lang->line('items_manually_editing_of_quantity'), + 'trans_inventory' => $updated_quantity - $item_quantity->quantity ); $success &= $this->Inventory->insert($inv_data); } } + if($success && $upload_success) { - $success_message = $this->lang->line('items_successful_' . ($new_item ? 'adding' : 'updating')) .' '. $item_data['name']; + $message = $this->xss_clean($this->lang->line('items_successful_' . ($new_item ? 'adding' : 'updating')) . ' ' . $item_data['name']); - echo json_encode(array('success'=>true, 'message'=>$success_message, 'id'=>$item_id)); + echo json_encode(array('success' => TRUE, 'message' => $message, 'id' => $item_id)); } else { - $error_message = $upload_success ? - $this->lang->line('items_error_adding_updating') .' '. $item_data['name'] : - $this->upload->display_errors(); + $message = $this->xss_clean($upload_success ? $this->lang->line('items_error_adding_updating') . ' ' . $item_data['name'] : strip_tags($this->upload->display_errors())); - echo json_encode(array('success'=>false, 'message'=>$error_message, 'id'=>$item_id)); + echo json_encode(array('success' => FALSE, 'message' => $message, 'id' => $item_id)); } } else//failure { - echo json_encode(array('success'=>false, 'message'=>$this->lang->line('items_error_adding_updating').' '.$item_data['name'], 'id'=>-1)); + $message = $this->xss_clean($this->lang->line('items_error_adding_updating') . ' ' . $item_data['name']); + + echo json_encode(array('success' => FALSE, 'message' => $message, 'id' => -1)); } } - function check_item_number() + public function check_item_number() { - $exists = $this->Item->item_number_exists($this->input->post('item_number'),$this->input->post('item_id')); + $exists = $this->Item->item_number_exists($this->input->post('item_number'), $this->input->post('item_id')); echo !$exists ? 'true' : 'false'; } @@ -424,11 +442,12 @@ class Items extends Secure_area implements iData_controller // load upload library $config = array('upload_path' => './uploads/item_pics/', - 'allowed_types' => 'gif|jpg|png', - 'max_size' => '100', - 'max_width' => '640', - 'max_height' => '480', - 'file_name' => sizeof($map) + 1); + 'allowed_types' => 'gif|jpg|png', + 'max_size' => '100', + 'max_width' => '640', + 'max_height' => '480', + 'file_name' => sizeof($map) + 1 + ); $this->load->library('upload', $config); $this->upload->do_upload('item_image'); @@ -437,54 +456,56 @@ class Items extends Secure_area implements iData_controller public function remove_logo($item_id) { - $item_data = array('pic_id' => null); + $item_data = array('pic_id' => NULL); $result = $this->Item->save($item_data, $item_id); echo json_encode(array('success' => $result)); } - function save_inventory($item_id=-1) + public function save_inventory($item_id = -1) { - $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; + $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; $cur_item_info = $this->Item->get_info($item_id); $location_id = $this->input->post('stock_location'); $inv_data = array( - 'trans_date'=>date('Y-m-d H:i:s'), - 'trans_items'=>$item_id, - 'trans_user'=>$employee_id, - 'trans_location'=>$location_id, - 'trans_comment'=>$this->input->post('trans_comment'), - 'trans_inventory'=>$this->input->post('newquantity') + 'trans_date' => date('Y-m-d H:i:s'), + 'trans_items' => $item_id, + 'trans_user' => $employee_id, + 'trans_location' => $location_id, + 'trans_comment' => $this->input->post('trans_comment'), + 'trans_inventory' => parse_decimals($this->input->post('newquantity')) ); $this->Inventory->insert($inv_data); //Update stock quantity - $item_quantity= $this->Item_quantity->get_item_quantity($item_id,$location_id); + $item_quantity = $this->Item_quantity->get_item_quantity($item_id, $location_id); $item_quantity_data = array( - 'item_id'=>$item_id, - 'location_id'=>$location_id, - 'quantity'=>$item_quantity->quantity + $this->input->post('newquantity') + 'item_id' => $item_id, + 'location_id' => $location_id, + 'quantity' => $item_quantity->quantity + parse_decimals($this->input->post('newquantity')) ); - if($this->Item_quantity->save($item_quantity_data,$item_id,$location_id)) - { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_updating').' '. - $cur_item_info->name,'id'=>$item_id)); + if($this->Item_quantity->save($item_quantity_data, $item_id, $location_id)) + { + $message = $this->xss_clean($this->lang->line('items_successful_updating') . ' ' . $cur_item_info->name); + + echo json_encode(array('success' => TRUE, 'message' => $message, 'id' => $item_id)); } else//failure - { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('items_error_adding_updating').' '. - $cur_item_info->name,'id'=>-1)); + { + $message = $this->xss_clean($this->lang->line('items_error_adding_updating') . ' ' . $cur_item_info->name); + + echo json_encode(array('success' => FALSE, 'message' => $message, 'id' => -1)); } } - function bulk_update() + public function bulk_update() { - $items_to_update=$this->input->post('item_ids'); + $items_to_update = $this->input->post('item_ids'); $item_data = array(); - foreach($_POST as $key=>$value) + foreach($_POST as $key => $value) { //This field is nullable, so treat it differently if($key == 'supplier_id' && $value != '') @@ -503,15 +524,15 @@ class Items extends Secure_area implements iData_controller $items_taxes_data = array(); $tax_names = $this->input->post('tax_names'); $tax_percents = $this->input->post('tax_percents'); - $tax_updated = false; - - for($k = 0; $k < count($tax_percents); $k++) + $tax_updated = FALSE; + $count = count($tax_percents); + for ($k = 0; $k < $count; ++$k) { - if( !empty($tax_names[$k]) && is_numeric($tax_percents[$k])) + if(!empty($tax_names[$k]) && is_numeric($tax_percents[$k])) { - $tax_updated = true; + $tax_updated = TRUE; - $items_taxes_data[] = array('name'=>$tax_names[$k], 'percent'=>$tax_percents[$k]); + $items_taxes_data[] = array('name' => $tax_names[$k], 'percent' => $tax_percents[$k]); } } @@ -520,92 +541,91 @@ class Items extends Secure_area implements iData_controller $this->Item_taxes->save_multiple($items_taxes_data, $items_to_update); } - echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_bulk_edit'), 'id'=>$items_to_update)); + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('items_successful_bulk_edit'), 'id' => $this->xss_clean($items_to_update))); } else { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('items_error_updating_multiple'))); + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('items_error_updating_multiple'))); } } - function delete() + public function delete() { $items_to_delete = $this->input->post('ids'); if($this->Item->delete_list($items_to_delete)) { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_deleted').' '. - count($items_to_delete).' '.$this->lang->line('items_one_or_multiple'))); + $message = $this->lang->line('items_successful_deleted') . ' ' . count($items_to_delete) . ' ' . $this->lang->line('items_one_or_multiple'); + echo json_encode(array('success' => TRUE, 'message' => $message)); } else { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('items_cannot_be_deleted'))); + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('items_cannot_be_deleted'))); } } - - function excel() + + /* + Items import from excel spreadsheet + */ + public function excel() { - $data = file_get_contents("import_items.csv"); $name = 'import_items.csv'; + $data = file_get_contents('../' . $name); force_download($name, $data); } - function excel_import() + public function excel_import() { - $this->load->view("items/form_excel_import", null); + $this->load->view('items/form_excel_import', NULL); } - function do_excel_import() + public function do_excel_import() { - $msg = 'do_excel_import'; - $failCodes = array(); - - if ($_FILES['file_path']['error'] != UPLOAD_ERR_OK) + if($_FILES['file_path']['error'] != UPLOAD_ERR_OK) { - $msg = $this->lang->line('items_excel_import_failed'); - echo json_encode( array('success'=>false, 'message'=>$msg) ); - - return; + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('items_excel_import_failed'))); } else { - if (($handle = fopen($_FILES['file_path']['tmp_name'], "r")) !== FALSE) + if(($handle = fopen($_FILES['file_path']['tmp_name'], 'r')) !== FALSE) { // Skip the first row as it's the table description fgetcsv($handle); - - $i=1; - while (($data = fgetcsv($handle)) !== FALSE) + $i = 1; + + $failCodes = array(); + + while(($data = fgetcsv($handle)) !== FALSE) { // XSS file data sanity check - $data = $this->security->xss_clean($data); + $data = $this->xss_clean($data); - if (sizeof($data) >= 23) + if(sizeof($data) >= 23) { $item_data = array( - 'name' => $data[1], - 'description' => $data[11], - 'category' => $data[2], - 'cost_price' => $data[4], - 'unit_price' => $data[5], - 'reorder_level' => $data[10], - 'supplier_id' => $this->Supplier->exists($data[3]) ? $data[3] : null, - 'allow_alt_description' => $data[12] != '' ? '1' : '0', - 'is_serialized' => $data[13] != '' ? '1' : '0', - 'custom1' => $data[14], - 'custom2' => $data[15], - 'custom3' => $data[16], - 'custom4' => $data[17], - 'custom5' => $data[18], - 'custom6' => $data[19], - 'custom7' => $data[20], - 'custom8' => $data[21], - 'custom9' => $data[22], - 'custom10' => $data[23] + 'name' => $data[1], + 'description' => $data[11], + 'category' => $data[2], + 'cost_price' => $data[4], + 'unit_price' => $data[5], + 'reorder_level' => $data[10], + 'supplier_id' => $this->Supplier->exists($data[3]) ? $data[3] : NULL, + 'allow_alt_description' => $data[12] != '' ? '1' : '0', + 'is_serialized' => $data[13] != '' ? '1' : '0', + 'custom1' => $data[14], + 'custom2' => $data[15], + 'custom3' => $data[16], + 'custom4' => $data[17], + 'custom5' => $data[18], + 'custom6' => $data[19], + 'custom7' => $data[20], + 'custom8' => $data[21], + 'custom9' => $data[22], + 'custom10' => $data[23] ); $item_number = $data[0]; - $invalidated = false; - if ($item_number != "") + $invalidated = FALSE; + if($item_number != '') { $item_data['item_number'] = $item_number; $invalidated = $this->Item->item_number_exists($item_number); @@ -613,22 +633,22 @@ class Items extends Secure_area implements iData_controller } else { - $invalidated = true; + $invalidated = TRUE; } if(!$invalidated && $this->Item->save($item_data)) { - $items_taxes_data = null; + $items_taxes_data = NULL; //tax 1 - if( is_numeric($data[7]) && $data[6]!='' ) + if(is_numeric($data[7]) && $data[6] != '') { - $items_taxes_data[] = array('name'=>$data[6], 'percent'=>$data[7] ); + $items_taxes_data[] = array('name' => $data[6], 'percent' => $data[7] ); } //tax 2 - if( is_numeric($data[9]) && $data[8]!='' ) + if(is_numeric($data[9]) && $data[8] != '') { - $items_taxes_data[] = array('name'=>$data[8], 'percent'=>$data[9] ); + $items_taxes_data[] = array('name' => $data[8], 'percent' => $data[9] ); } // save tax values @@ -637,9 +657,9 @@ class Items extends Secure_area implements iData_controller $this->Item_taxes->save($items_taxes_data, $item_data['item_id']); } - // quantities & inventory Info - $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; - $emp_info=$this->Employee->get_info($employee_id); + // quantities & inventory Info + $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; + $emp_info = $this->Employee->get_info($employee_id); $comment ='Qty CSV Imported'; $cols = count($data); @@ -649,9 +669,9 @@ class Items extends Secure_area implements iData_controller for ($col = 24; $col < $cols; $col = $col + 2) { $location_id = $data[$col]; - if (array_key_exists($location_id, $allowed_locations)) + if(array_key_exists($location_id, $allowed_locations)) { - $item_quantity_data = array ( + $item_quantity_data = array( 'item_id' => $item_data['item_id'], 'location_id' => $location_id, 'quantity' => $data[$col + 1], @@ -659,11 +679,11 @@ class Items extends Secure_area implements iData_controller $this->Item_quantity->save($item_quantity_data, $item_data['item_id'], $location_id); $excel_data = array( - 'trans_items'=>$item_data['item_id'], - 'trans_user'=>$employee_id, - 'trans_comment'=>$comment, - 'trans_location'=>$data[$col], - 'trans_inventory'=>$data[$col + 1] + 'trans_items' => $item_data['item_id'], + 'trans_user' => $employee_id, + 'trans_comment' => $comment, + 'trans_location' => $data[$col], + 'trans_inventory' => $data[$col + 1] ); $this->Inventory->insert($excel_data); @@ -686,11 +706,11 @@ class Items extends Secure_area implements iData_controller $this->Item_quantity->save($item_quantity_data, $item_data['item_id'], $data[$col]); $excel_data = array( - 'trans_items'=>$item_data['item_id'], - 'trans_user'=>$employee_id, - 'trans_comment'=>$comment, - 'trans_location'=>$location_id, - 'trans_inventory'=>0 + 'trans_items' => $item_data['item_id'], + 'trans_user' => $employee_id, + 'trans_comment' => $comment, + 'trans_location' => $location_id, + 'trans_inventory' => 0 ); $this->Inventory->insert($excel_data); @@ -701,29 +721,25 @@ class Items extends Secure_area implements iData_controller $failCodes[] = $i; } - $i++; + ++$i; } - } - else - { - echo json_encode( array('success'=>false, 'message'=>'Your uploaded file has no data or wrong format') ); - return; - } + if(count($failCodes) > 0) + { + $message = $this->lang->line('items_excel_import_partially_failed') . ' (' . count($failCodes) . '): ' . implode(', ', $failCodes); + + echo json_encode(array('success' => FALSE, 'message' => $message)); + } + else + { + echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('items_excel_import_success'))); + } + } + else + { + echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('items_excel_import_nodata_wrongformat'))); + } } - - $success = true; - if(count($failCodes) > 0) - { - $msg = "Most items imported. But some were not, here is list of their CODE (" . count($failCodes) ."): ". implode(", ", $failCodes); - $success = false; - } - else - { - $msg = "Import of Items successful"; - } - - echo json_encode( array('success'=>$success, 'message'=>$msg) ); } } ?> diff --git a/application/controllers/Languagecheck.php b/application/controllers/Languagecheck.php deleted file mode 100644 index c0d4eff59..000000000 --- a/application/controllers/Languagecheck.php +++ /dev/null @@ -1,192 +0,0 @@ -load->helper('directory'); - - // for simplicity, we don't use views - $this->output('h1', 'Open Source Point of Sale - Language file checking and validation'); - - // determine the language file path - if ( ! is_dir($this->lang_path) ) - { - $this->lang_path = APPPATH . $this->lang_path; - - if ( ! is_dir($this->lang_path) ) - { - $this->output('h2', 'Defined language path "'.$this->lang_path.'" not found!', TRUE); - exit; - } - } - - // fetch the languages directory map - $languages = directory_map( $this->lang_path, TRUE ); - - // is our reference language present? - if ( ! in_array($this->reference, $languages ) ) - { - $this->output('h2', 'Reference language "'.$this->reference.'" not found!', TRUE); - exit; - } - - // load the list of language files for the reference language - $references = directory_map( $this->lang_path . '/' . $this->reference, TRUE ); - - // now process the list - foreach( $references as $reference ) - { - // skip non-language files in the language directory - if ( strpos($reference, '_lang.php') === FALSE ) - { - continue; - } - - // process it - $this->output('h2', 'Processing '.$this->reference . ' » ' .$reference); - - // load the language file - include $this->lang_path . '/' . $this->reference . '/' . $reference; - - // did the file contain any language strings? - if ( empty($lang) ) - { - // language file was empty or not properly defined - $this->output('h3', 'Language file doesn\'t contain any language strings. Skipping file!', TRUE); - continue; - } - - // store the loaded language strings - $lang_ref = $lang; - unset($lang); - - // now loop through the available languages - foreach ( $languages as $language ) - { - // skip the reference language - if ( $language == $this->reference ) - { - continue; - } - - // language file to check - $file = $this->lang_path . '/' . $language . '/' . $reference; - - // check if the language file exists for this language - if ( ! file_exists( $file ) ) - { - // file not found - $this->output('h3', 'Language file doesn\'t exist for the language '.$language.'!', TRUE); - } - else - { - // load the file to compare - include $file; - - // did the file contain any language strings? - if ( empty($lang) ) - { - // language file was empty or not properly defined - $this->output('h3', 'Language file for the language '.$language.' doesn\'t contain any language strings!', TRUE); - } - else - { - // start comparing - $this->output('h3', 'Comparing with the '.$language.' version:'); - - // assume all goes well - $failures = 0; - - // start comparing language keys - foreach( $lang_ref as $key => $value ) - { - if ( ! isset($lang[$key]) ) - { - // report the missing key - $this->output('', 'Missing language string "'.$key.'"', TRUE); - - // increment the failure counter - $failures++; - } - } - - if ( ! $failures ) - { - $this->output('', 'The two language files have matching strings.'); - } - } - - // make sure the lang array is deleted before the next check - if ( isset($lang) ) - { - unset($lang); - } - } - } - - } - - $this->output('h2', 'Language file checking and validation completed'); - } - - // ----------------------------------------------------------------- - - private function output($type = '', $line = '', $highlight = FALSE) - { - switch ($type) - { - case 'h1': - $html = "
- * array(0 => x1,
- * 1 => y1,
- * 2 => x2,
- * 3 => y2,
- * ...
- * );
- *
- *
- * See {@link Style::munge_color()} for the format of the color array.
- * See {@link Cpdf::setLineStyle()} for a description of the $style
- * parameter (aka dash)
- *
- * @param array $points
- * @param array $color
- * @param float $width
- * @param array $style
- * @param bool $fill Fills the polygon if true
- */
- function polygon($points, $color, $width = null, $style = null, $fill = false);
-
- /**
- * Draws a circle at $x,$y with radius $r
- *
- * See {@link Style::munge_color()} for the format of the color array.
- * See {@link Cpdf::setLineStyle()} for a description of the $style
- * parameter (aka dash)
- *
- * @param float $x
- * @param float $y
- * @param float $r
- * @param array $color
- * @param float $width
- * @param array $style
- * @param bool $fill Fills the circle if true
- */
- function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false);
-
- /**
- * Add an image to the pdf.
- *
- * The image is placed at the specified x and y coordinates with the
- * given width and height.
- *
- * @param string $img_url the path to the image
- * @param float $x x position
- * @param float $y y position
- * @param int $w width (in pixels)
- * @param int $h height (in pixels)
- * @param string $resolution The resolution of the image
- */
- function image($img_url, $x, $y, $w, $h, $resolution = "normal");
-
- /**
- * Add an arc to the PDF
- * See {@link Style::munge_color()} for the format of the color array.
- *
- * @param float $x X coordinate of the arc
- * @param float $y Y coordinate of the arc
- * @param float $r1 Radius 1
- * @param float $r2 Radius 2
- * @param float $astart Start angle in degrees
- * @param float $aend End angle in degrees
- * @param array $color Color
- * @param float $width
- * @param array $style
- *
- * @return void
- */
- function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = array());
-
- /**
- * Writes text at the specified x and y coordinates
- * See {@link Style::munge_color()} for the format of the color array.
- *
- * @param float $x
- * @param float $y
- * @param string $text the text to write
- * @param string $font the font file to use
- * @param float $size the font size, in points
- * @param array $color
- * @param float $word_space word spacing adjustment
- * @param float $char_space char spacing adjustment
- * @param float $angle angle
- *
- * @return void
- */
- function text($x, $y, $text, $font, $size, $color = array(0,0,0), $word_space = 0.0, $char_space = 0.0, $angle = 0.0);
-
- /**
- * Add a named destination (similar to ... in html)
- *
- * @param string $anchorname The name of the named destination
- */
- function add_named_dest($anchorname);
-
- /**
- * Add a link to the pdf
- *
- * @param string $url The url to link to
- * @param float $x The x position of the link
- * @param float $y The y position of the link
- * @param float $width The width of the link
- * @param float $height The height of the link
- *
- * @return void
- */
- function add_link($url, $x, $y, $width, $height);
-
- /**
- * Add meta information to the pdf
- *
- * @param string $name Label of the value (Creator, Producer, etc.)
- * @param string $value The text to set
- */
- function add_info($name, $value);
-
- /**
- * Calculates text size, in points
- *
- * @param string $text the text to be sized
- * @param string $font the desired font
- * @param float $size the desired font size
- * @param float $word_spacing word spacing, if any
- * @param float $char_spacing
- *
- * @return float
- */
- function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0);
-
- /**
- * Calculates font height, in points
- *
- * @param string $font
- * @param float $size
- *
- * @return float
- */
- function get_font_height($font, $size);
-
- /**
- * Calculates font baseline, in points
- *
- * @param string $font
- * @param float $size
- *
- * @return float
- */
- function get_font_baseline($font, $size);
-
- /**
- * Returns the font x-height, in points
- *
- * @param string $font
- * @param float $size
- *
- * @return float
- */
- //function get_font_x_height($font, $size);
-
- /**
- * Sets the opacity
- *
- * @param float $opacity
- * @param string $mode
- */
- function set_opacity($opacity, $mode = "Normal");
-
- /**
- * Sets the default view
- *
- * @param string $view
- * 'XYZ' left, top, zoom
- * 'Fit'
- * 'FitH' top
- * 'FitV' left
- * 'FitR' left,bottom,right
- * 'FitB'
- * 'FitBH' top
- * 'FitBV' left
- * @param array $options
- *
- * @return void
- */
- function set_default_view($view, $options = array());
-
- /**
- * @param string $script
- *
- * @return void
- */
- function javascript($script);
-
- /**
- * Starts a new page
- *
- * Subsequent drawing operations will appear on the new page.
- */
- function new_page();
-
- /**
- * Streams the PDF directly to the browser
- *
- * @param string $filename the name of the PDF file
- * @param array $options associative array, 'Attachment' => 0 or 1, 'compress' => 1 or 0
- */
- function stream($filename, $options = null);
-
- /**
- * Returns the PDF as a string
- *
- * @param array $options associative array: 'compress' => 1 or 0
- * @return string
- */
- function output($options = null);
-}
diff --git a/application/helpers/dompdf/include/canvas_factory.cls.php b/application/helpers/dompdf/include/canvas_factory.cls.php
deleted file mode 100755
index ef634e6b0..000000000
--- a/application/helpers/dompdf/include/canvas_factory.cls.php
+++ /dev/null
@@ -1,63 +0,0 @@
-
- * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
- */
-
-/**
- * Create canvas instances
- *
- * The canvas factory creates canvas instances based on the
- * availability of rendering backends and config options.
- *
- * @package dompdf
- */
-class Canvas_Factory {
-
- /**
- * Constructor is private: this is a static class
- */
- private function __construct() { }
-
- /**
- * @param DOMPDF $dompdf
- * @param string|array $paper
- * @param string $orientation
- * @param string $class
- *
- * @return Canvas
- */
- static function get_instance(DOMPDF $dompdf, $paper = null, $orientation = null, $class = null) {
-
- $backend = strtolower(DOMPDF_PDF_BACKEND);
-
- if ( isset($class) && class_exists($class, false) ) {
- $class .= "_Adapter";
- }
-
- else if ( (DOMPDF_PDF_BACKEND === "auto" || $backend === "pdflib" ) &&
- class_exists("PDFLib", false) ) {
- $class = "PDFLib_Adapter";
- }
-
- // FIXME The TCPDF adapter is not ready yet
- //else if ( (DOMPDF_PDF_BACKEND === "auto" || $backend === "cpdf") )
- // $class = "CPDF_Adapter";
-
- else if ( $backend === "tcpdf" ) {
- $class = "TCPDF_Adapter";
- }
-
- else if ( $backend === "gd" ) {
- $class = "GD_Adapter";
- }
-
- else {
- $class = "CPDF_Adapter";
- }
-
- return new $class($paper, $orientation, $dompdf);
- }
-}
diff --git a/application/helpers/dompdf/include/cellmap.cls.php b/application/helpers/dompdf/include/cellmap.cls.php
deleted file mode 100755
index 0982849b3..000000000
--- a/application/helpers/dompdf/include/cellmap.cls.php
+++ /dev/null
@@ -1,790 +0,0 @@
-
- * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
- */
-
-/**
- * Maps table cells to the table grid.
- *
- * This class resolves borders in tables with collapsed borders and helps
- * place row & column spanned table cells.
- *
- * @access private
- * @package dompdf
- */
-class Cellmap {
-
- /**
- * Border style weight lookup for collapsed border resolution.
- *
- * @var array
- */
- static protected $_BORDER_STYLE_SCORE = array(
- "inset" => 1,
- "groove" => 2,
- "outset" => 3,
- "ridge" => 4,
- "dotted" => 5,
- "dashed" => 6,
- "solid" => 7,
- "double" => 8,
- "hidden" => 9,
- "none" => 0,
- );
-
- /**
- * The table object this cellmap is attached to.
- *
- * @var Table_Frame_Decorator
- */
- protected $_table;
-
- /**
- * The total number of rows in the table
- *
- * @var int
- */
- protected $_num_rows;
-
- /**
- * The total number of columns in the table
- *
- * @var int
- */
- protected $_num_cols;
-
- /**
- * 2D array mapping ['.$font.','.$size.','.$pdf->getFontHeight($size).','.$pdf->getFontDescender($size).','.$pdf->fonts[$pdf->currentFont]['FontBBox'][3].','.$pdf->fonts[$pdf->currentFont]['FontBBox'][1].','.$pdf->fonts[$pdf->currentFont]['FontHeightOffset'].','.$pdf->fonts[$pdf->currentFont]['Ascender'].','.$pdf->fonts[$pdf->currentFont]['Descender'].']'; - // - //$pdf->addText($x, $this->y($y) - ($pdf->fonts[$pdf->currentFont]['FontBBox'][3]*$size)/1000, $size, $text, $angle, $word_space, $char_space); - $pdf->addText($x, $this->y($y) - $pdf->getFontHeight($size), $size, $text, $angle, $word_space, $char_space); - } - - //........................................................................ - - function javascript($code) { - $this->_pdf->addJavascript($code); - } - - //........................................................................ - - /** - * Add a named destination (similar to ... in html) - * - * @param string $anchorname The name of the named destination - */ - function add_named_dest($anchorname) { - $this->_pdf->addDestination($anchorname, "Fit"); - } - - //........................................................................ - - /** - * Add a link to the pdf - * - * @param string $url The url to link to - * @param float $x The x position of the link - * @param float $y The y position of the link - * @param float $width The width of the link - * @param float $height The height of the link - */ - function add_link($url, $x, $y, $width, $height) { - - $y = $this->y($y) - $height; - - if ( strpos($url, '#') === 0 ) { - // Local link - $name = substr($url,1); - if ( $name ) { - $this->_pdf->addInternalLink($name, $x, $y, $x + $width, $y + $height); - } - - } - else { - $this->_pdf->addLink(rawurldecode($url), $x, $y, $x + $width, $y + $height); - } - } - - function get_text_width($text, $font, $size, $word_spacing = 0, $char_spacing = 0) { - $this->_pdf->selectFont($font); - - $unicode = $this->_dompdf->get_option("enable_unicode"); - if (!$unicode) { - $text = mb_convert_encoding($text, 'Windows-1252', 'UTF-8'); - } - - return $this->_pdf->getTextWidth($size, $text, $word_spacing, $char_spacing); - } - - function register_string_subset($font, $string) { - $this->_pdf->registerText($font, $string); - } - - function get_font_height($font, $size) { - $this->_pdf->selectFont($font); - - $ratio = $this->_dompdf->get_option("font_height_ratio"); - return $this->_pdf->getFontHeight($size) * $ratio; - } - - /*function get_font_x_height($font, $size) { - $this->_pdf->selectFont($font); - $ratio = $this->_dompdf->get_option("font_height_ratio"); - return $this->_pdf->getFontXHeight($size) * $ratio; - }*/ - - function get_font_baseline($font, $size) { - $ratio = $this->_dompdf->get_option("font_height_ratio"); - return $this->get_font_height($font, $size) / $ratio; - } - - /** - * Writes text at the specified x and y coordinates on every page - * - * The strings '{PAGE_NUM}' and '{PAGE_COUNT}' are automatically replaced - * with their current values. - * - * See {@link Style::munge_color()} for the format of the colour array. - * - * @param float $x - * @param float $y - * @param string $text the text to write - * @param string $font the font file to use - * @param float $size the font size, in points - * @param array $color - * @param float $word_space word spacing adjustment - * @param float $char_space char spacing adjustment - * @param float $angle angle to write the text at, measured CW starting from the x-axis - */ - function page_text($x, $y, $text, $font, $size, $color = array(0,0,0), $word_space = 0.0, $char_space = 0.0, $angle = 0.0) { - $_t = "text"; - $this->_page_text[] = compact("_t", "x", "y", "text", "font", "size", "color", "word_space", "char_space", "angle"); - } - - /** - * Processes a script on every page - * - * The variables $pdf, $PAGE_NUM, and $PAGE_COUNT are available. - * - * This function can be used to add page numbers to all pages - * after the first one, for example. - * - * @param string $code the script code - * @param string $type the language type for script - */ - function page_script($code, $type = "text/php") { - $_t = "script"; - $this->_page_text[] = compact("_t", "code", "type"); - } - - function new_page() { - $this->_page_number++; - $this->_page_count++; - - $ret = $this->_pdf->newPage(); - $this->_pages[] = $ret; - return $ret; - } - - /** - * Add text to each page after rendering is complete - */ - protected function _add_page_text() { - - if ( !count($this->_page_text) ) { - return; - } - - $page_number = 1; - $eval = null; - - foreach ($this->_pages as $pid) { - $this->reopen_object($pid); - - foreach ($this->_page_text as $pt) { - extract($pt); - - switch ($_t) { - case "text": - $text = str_replace(array("{PAGE_NUM}","{PAGE_COUNT}"), - array($page_number, $this->_page_count), $text); - $this->text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle); - break; - - case "script": - if ( !$eval ) { - $eval = new PHP_Evaluator($this); - } - $eval->evaluate($code, array('PAGE_NUM' => $page_number, 'PAGE_COUNT' => $this->_page_count)); - break; - } - } - - $this->close_object(); - $page_number++; - } - } - - /** - * Streams the PDF directly to the browser - * - * @param string $filename the name of the PDF file - * @param array $options associative array, 'Attachment' => 0 or 1, 'compress' => 1 or 0 - */ - function stream($filename, $options = null) { - // Add page text - $this->_add_page_text(); - - $options["Content-Disposition"] = $filename; - $this->_pdf->stream($options); - } - - /** - * Returns the PDF as a string - * - * @param array $options Output options - * @return string - */ - function output($options = null) { - $this->_add_page_text(); - - $debug = isset($options["compress"]) && $options["compress"] != 1; - - return $this->_pdf->output($debug); - } - - /** - * Returns logging messages generated by the Cpdf class - * - * @return string - */ - function get_messages() { - return $this->_pdf->messages; - } -} diff --git a/application/helpers/dompdf/include/css_color.cls.php b/application/helpers/dompdf/include/css_color.cls.php deleted file mode 100755 index 481751db5..000000000 --- a/application/helpers/dompdf/include/css_color.cls.php +++ /dev/null @@ -1,287 +0,0 @@ - - * @author Fabien Ménager
';
- foreach ($_dompdf_warnings as $msg) {
- echo $msg . "\n";
- }
- echo $this->get_canvas()->get_cpdf()->messages;
- echo '';
- flush();
- }
-
- $this->restore_locale();
- }
-
- /**
- * Add meta information to the PDF after rendering
- */
- function add_info($label, $value) {
- if ( !is_null($this->_pdf) ) {
- $this->_pdf->add_info($label, $value);
- }
- }
-
- /**
- * Writes the output buffer in the log file
- *
- * @return void
- */
- private function write_log() {
- $log_output_file = $this->get_option("log_output_file");
- if ( !$log_output_file || !is_writable($log_output_file) ) {
- return;
- }
-
- $frames = Frame::$ID_COUNTER;
- $memory = DOMPDF_memory_usage() / 1024;
- $time = (microtime(true) - $this->_start_time) * 1000;
-
- $out = sprintf(
- "%6d".
- "%10.2f KB".
- "%10.2f ms".
- " ".
- ($this->_quirksmode ? " ON" : "OFF").
- "'" . mb_substr($tmp,0,70) . - (mb_strlen($tmp) > 70 ? "..." : "") . "'"; - } - elseif ( $css_class = $this->_node->getAttribute("class") ) { - $str .= "CSS class: '$css_class'
". $this->_style->__toString() . ""; - - if ( $this->_decorator instanceof Block_Frame_Decorator ) { - $str .= "Lines:
";
- foreach ($this->_decorator->get_line_boxes() as $line) {
- foreach ($line->get_frames() as $frame) {
- if ($frame instanceof Text_Frame_Decorator) {
- $str .= "\ntext: ";
- $str .= "'". htmlspecialchars($frame->get_text()) ."'";
- }
- else {
- $str .= "\nBlock: " . $frame->get_node()->nodeName . " (" . spl_object_hash($frame->get_node()) . ")";
- }
- }
-
- $str .=
- "\ny => " . $line->y . "\n" .
- "w => " . $line->w . "\n" .
- "h => " . $line->h . "\n" .
- "left => " . $line->left . "\n" .
- "right => " . $line->right . "\n";
- }
- $str .= "";
- }
-
- $str .= "\n";
- if ( php_sapi_name() === "cli" ) {
- $str = strip_tags(str_replace(array("" . print_r($mixed, true) . ""; - } - - if ( php_sapi_name() !== "cli" ) { - echo "
";
- }
-
- print_r($mixed);
-
- if ( php_sapi_name() !== "cli" ) {
- echo "";
- }
- else {
- echo "\n";
- }
-
- flush();
-
-}
-}
-
-if ( !function_exists("pre_var_dump") ) {
-/**
- * var_dump wrapper for html/cli output
- *
- * Wraps var_dump() output in < pre > tags if the current sapi is not 'cli'.
- *
- * @param mixed $mixed variable or expression to display.
- */
-function pre_var_dump($mixed) {
- if ( php_sapi_name() !== "cli" ) {
- echo "";
- }
-
- var_dump($mixed);
-
- if ( php_sapi_name() !== "cli" ) {
- echo "";
- }
-}
-}
-
-if ( !function_exists("d") ) {
-/**
- * generic debug function
- *
- * Takes everything and does its best to give a good debug output
- *
- * @param mixed $mixed variable or expression to display.
- */
-function d($mixed) {
- if ( php_sapi_name() !== "cli" ) {
- echo "";
- }
-
- // line
- if ( $mixed instanceof Line_Box ) {
- echo $mixed;
- }
-
- // other
- else {
- var_export($mixed);
- }
-
- if ( php_sapi_name() !== "cli" ) {
- echo "";
- }
-}
-}
-
-/**
- * builds a full url given a protocol, hostname, base path and url
- *
- * @param string $protocol
- * @param string $host
- * @param string $base_path
- * @param string $url
- * @return string
- *
- * Initially the trailing slash of $base_path was optional, and conditionally appended.
- * However on dynamically created sites, where the page is given as url parameter,
- * the base path might not end with an url.
- * Therefore do not append a slash, and **require** the $base_url to ending in a slash
- * when needed.
- * Vice versa, on using the local file system path of a file, make sure that the slash
- * is appended (o.k. also for Windows)
- */
-function build_url($protocol, $host, $base_path, $url) {
- if ( strlen($url) == 0 ) {
- //return $protocol . $host . rtrim($base_path, "/\\") . "/";
- return $protocol . $host . $base_path;
- }
-
- // Is the url already fully qualified or a Data URI?
- if ( mb_strpos($url, "://") !== false || mb_strpos($url, "data:") === 0 ) {
- return $url;
- }
-
- $ret = $protocol;
-
- if ( !in_array(mb_strtolower($protocol), array("http://", "https://", "ftp://", "ftps://")) ) {
- //On Windows local file, an abs path can begin also with a '\' or a drive letter and colon
- //drive: followed by a relative path would be a drive specific default folder.
- //not known in php app code, treat as abs path
- //($url[1] !== ':' || ($url[2]!=='\\' && $url[2]!=='/'))
- if ( $url[0] !== '/' && (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' || ($url[0] !== '\\' && $url[1] !== ':')) ) {
- // For rel path and local acess we ignore the host, and run the path through realpath()
- $ret .= realpath($base_path).'/';
- }
- $ret .= $url;
- $ret = preg_replace('/\?(.*)$/', "", $ret);
- return $ret;
- }
-
- //remote urls with backslash in html/css are not really correct, but lets be genereous
- if ( $url[0] === '/' || $url[0] === '\\' ) {
- // Absolute path
- $ret .= $host . $url;
- }
- else {
- // Relative path
- //$base_path = $base_path !== "" ? rtrim($base_path, "/\\") . "/" : "";
- $ret .= $host . $base_path . $url;
- }
-
- return $ret;
-
-}
-
-/**
- * parse a full url or pathname and return an array(protocol, host, path,
- * file + query + fragment)
- *
- * @param string $url
- * @return array
- */
-function explode_url($url) {
- $protocol = "";
- $host = "";
- $path = "";
- $file = "";
-
- $arr = parse_url($url);
-
- // Exclude windows drive letters...
- if ( isset($arr["scheme"]) && $arr["scheme"] !== "file" && strlen($arr["scheme"]) > 1 ) {
- $protocol = $arr["scheme"] . "://";
-
- if ( isset($arr["user"]) ) {
- $host .= $arr["user"];
-
- if ( isset($arr["pass"]) ) {
- $host .= ":" . $arr["pass"];
- }
-
- $host .= "@";
- }
-
- if ( isset($arr["host"]) ) {
- $host .= $arr["host"];
- }
-
- if ( isset($arr["port"]) ) {
- $host .= ":" . $arr["port"];
- }
-
- if ( isset($arr["path"]) && $arr["path"] !== "" ) {
- // Do we have a trailing slash?
- if ( $arr["path"][ mb_strlen($arr["path"]) - 1 ] === "/" ) {
- $path = $arr["path"];
- $file = "";
- }
- else {
- $path = rtrim(dirname($arr["path"]), '/\\') . "/";
- $file = basename($arr["path"]);
- }
- }
-
- if ( isset($arr["query"]) ) {
- $file .= "?" . $arr["query"];
- }
-
- if ( isset($arr["fragment"]) ) {
- $file .= "#" . $arr["fragment"];
- }
-
- }
- else {
-
- $i = mb_strpos($url, "file://");
- if ( $i !== false ) {
- $url = mb_substr($url, $i + 7);
- }
-
- $protocol = ""; // "file://"; ? why doesn't this work... It's because of
- // network filenames like //COMPU/SHARENAME
-
- $host = ""; // localhost, really
- $file = basename($url);
-
- $path = dirname($url);
-
- // Check that the path exists
- if ( $path !== false ) {
- $path .= '/';
-
- }
- else {
- // generate a url to access the file if no real path found.
- $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://';
-
- $host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : php_uname("n");
-
- if ( substr($arr["path"], 0, 1) === '/' ) {
- $path = dirname($arr["path"]);
- }
- else {
- $path = '/' . rtrim(dirname($_SERVER["SCRIPT_NAME"]), '/') . '/' . $arr["path"];
- }
- }
- }
-
- $ret = array($protocol, $host, $path, $file,
- "protocol" => $protocol,
- "host" => $host,
- "path" => $path,
- "file" => $file);
- return $ret;
-}
-
-/**
- * Converts decimal numbers to roman numerals
- *
- * @param int $num
- *
- * @throws DOMPDF_Exception
- * @return string
- */
-function dec2roman($num) {
-
- static $ones = array("", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix");
- static $tens = array("", "x", "xx", "xxx", "xl", "l", "lx", "lxx", "lxxx", "xc");
- static $hund = array("", "c", "cc", "ccc", "cd", "d", "dc", "dcc", "dccc", "cm");
- static $thou = array("", "m", "mm", "mmm");
-
- if ( !is_numeric($num) ) {
- throw new DOMPDF_Exception("dec2roman() requires a numeric argument.");
- }
-
- if ( $num > 4000 || $num < 0 ) {
- return "(out of range)";
- }
-
- $num = strrev((string)$num);
-
- $ret = "";
- switch (mb_strlen($num)) {
- case 4: $ret .= $thou[$num[3]];
- case 3: $ret .= $hund[$num[2]];
- case 2: $ret .= $tens[$num[1]];
- case 1: $ret .= $ones[$num[0]];
- default: break;
- }
-
- return $ret;
-}
-
-/**
- * Determines whether $value is a percentage or not
- *
- * @param float $value
- *
- * @return bool
- */
-function is_percent($value) {
- return false !== mb_strpos($value, "%");
-}
-
-/**
- * Parses a data URI scheme
- * http://en.wikipedia.org/wiki/Data_URI_scheme
- *
- * @param string $data_uri The data URI to parse
- *
- * @return array The result with charset, mime type and decoded data
- */
-function parse_data_uri($data_uri) {
- if (!preg_match('/^data:(?P";
- }
-
- $bt = debug_backtrace();
-
- array_shift($bt); // remove actual bt() call
- echo "\n";
-
- $i = 0;
- foreach ($bt as $call) {
- $file = basename($call["file"]) . " (" . $call["line"] . ")";
- if ( isset($call["class"]) ) {
- $func = $call["class"] . "->" . $call["function"] . "()";
- }
- else {
- $func = $call["function"] . "()";
- }
-
- echo "#" . str_pad($i, 2, " ", STR_PAD_RIGHT) . ": " . str_pad($file.":", 42) . " $func\n";
- $i++;
- }
- echo "\n";
-
- if ( php_sapi_name() !== "cli") {
- echo "";
- }
-}
-
-/**
- * Print debug messages
- *
- * @param string $type The type of debug messages to print
- * @param string $msg The message to show
- */
-function dompdf_debug($type, $msg) {
- global $_DOMPDF_DEBUG_TYPES, $_dompdf_show_warnings, $_dompdf_debug;
- if ( isset($_DOMPDF_DEBUG_TYPES[$type]) && ($_dompdf_show_warnings || $_dompdf_debug) ) {
- $arr = debug_backtrace();
-
- echo basename($arr[0]["file"]) . " (" . $arr[0]["line"] ."): " . $arr[1]["function"] . ": ";
- pre_r($msg);
- }
-}
-
-if ( !function_exists("print_memusage") ) {
-/**
- * Dump memory usage
- */
-function print_memusage() {
- global $memusage;
- echo "Memory Usage\n";
- $prev = 0;
- $initial = reset($memusage);
- echo str_pad("Initial:", 40) . $initial . "\n\n";
-
- foreach ($memusage as $key=>$mem) {
- $mem -= $initial;
- echo str_pad("$key:" , 40);
- echo str_pad("$mem", 12) . "(diff: " . ($mem - $prev) . ")\n";
- $prev = $mem;
- }
-
- echo "\n" . str_pad("Total:", 40) . memory_get_usage() . "\n";
-}
-}
-
-if ( !function_exists("enable_mem_profile") ) {
-/**
- * Initialize memory profiling code
- */
-function enable_mem_profile() {
- global $memusage;
- $memusage = array("Startup" => memory_get_usage());
- register_shutdown_function("print_memusage");
-}
-}
-
-if ( !function_exists("mark_memusage") ) {
-/**
- * Record the current memory usage
- *
- * @param string $location a meaningful location
- */
-function mark_memusage($location) {
- global $memusage;
- if ( isset($memusage) ) {
- $memusage[$location] = memory_get_usage();
- }
-}
-}
-
-if ( !function_exists('sys_get_temp_dir')) {
-/**
- * Find the current system temporary directory
- *
- * @link http://us.php.net/manual/en/function.sys-get-temp-dir.php#85261
- */
-function sys_get_temp_dir() {
- if (!empty($_ENV['TMP'])) {
- return realpath($_ENV['TMP']);
- }
-
- if (!empty($_ENV['TMPDIR'])) {
- return realpath( $_ENV['TMPDIR']);
- }
-
- if (!empty($_ENV['TEMP'])) {
- return realpath( $_ENV['TEMP']);
- }
-
- $tempfile=tempnam(uniqid(rand(), true), '');
- if (file_exists($tempfile)) {
- unlink($tempfile);
- return realpath(dirname($tempfile));
- }
-}
-}
-
-if ( function_exists("memory_get_peak_usage") ) {
- function DOMPDF_memory_usage(){
- return memory_get_peak_usage(true);
- }
-}
-else if ( function_exists("memory_get_usage") ) {
- function DOMPDF_memory_usage(){
- return memory_get_usage(true);
- }
-}
-else {
- function DOMPDF_memory_usage(){
- return "N/A";
- }
-}
-
-if ( function_exists("curl_init") ) {
- function DOMPDF_fetch_url($url, &$headers = null) {
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HEADER, true);
-
- $data = curl_exec($ch);
- $raw_headers = substr($data, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
- $headers = preg_split("/[\n\r]+/", trim($raw_headers));
- $data = substr($data, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
- curl_close($ch);
-
- return $data;
- }
-}
-else {
- function DOMPDF_fetch_url($url, &$headers = null) {
- $data = file_get_contents($url);
- $headers = $http_response_header;
-
- return $data;
- }
-}
-
-/**
- * Affect null to the unused objects
- * @param mixed $object
- */
-if ( PHP_VERSION_ID < 50300 ) {
- function clear_object(&$object) {
- if ( is_object($object) ) {
- foreach ($object as &$value) {
- clear_object($value);
- }
- }
-
- $object = null;
- unset($object);
- }
-}
-else {
- function clear_object(&$object) {
- // void
- }
-}
diff --git a/application/helpers/dompdf/include/gd_adapter.cls.php b/application/helpers/dompdf/include/gd_adapter.cls.php
deleted file mode 100755
index de5c1e452..000000000
--- a/application/helpers/dompdf/include/gd_adapter.cls.php
+++ /dev/null
@@ -1,840 +0,0 @@
-
- * @author Fabien Ménager
- * array(0 => x1,
- * 1 => y1,
- * 2 => x2,
- * 3 => y2,
- * ...
- * );
- *
- *
- * See {@link Style::munge_color()} for the format of the color array.
- * See {@link Cpdf::setLineStyle()} for a description of the $style
- * parameter (aka dash)
- *
- * @param array $points
- * @param array $color
- * @param float $width
- * @param array $style
- * @param bool $fill Fills the polygon if true
- */
- function polygon($points, $color, $width = null, $style = null, $fill = false) {
-
- // Scale each point by the AA factor
- foreach (array_keys($points) as $i)
- $points[$i] *= $this->_aa_factor;
-
- $c = $this->_allocate_color($color);
-
- // Convert the style array if required
- if ( !is_null($style) && !$fill ) {
- $gd_style = array();
-
- foreach ($style as $length) {
- for ($i = 0; $i < $length; $i++) {
- $gd_style[] = $c;
- }
- }
-
- imagesetstyle($this->_img, $gd_style);
- $c = IMG_COLOR_STYLED;
- }
-
- imagesetthickness($this->_img, $width);
-
- if ( $fill )
- imagefilledpolygon($this->_img, $points, count($points) / 2, $c);
- else
- imagepolygon($this->_img, $points, count($points) / 2, $c);
-
- }
-
- /**
- * Draws a circle at $x,$y with radius $r
- *
- * See {@link Style::munge_color()} for the format of the color array.
- * See {@link Cpdf::setLineStyle()} for a description of the $style
- * parameter (aka dash)
- *
- * @param float $x
- * @param float $y
- * @param float $r
- * @param array $color
- * @param float $width
- * @param array $style
- * @param bool $fill Fills the circle if true
- */
- function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false) {
-
- // Scale by the AA factor
- $x *= $this->_aa_factor;
- $y *= $this->_aa_factor;
- $r *= $this->_aa_factor;
-
- $c = $this->_allocate_color($color);
-
- // Convert the style array if required
- if ( !is_null($style) && !$fill ) {
- $gd_style = array();
-
- foreach ($style as $length) {
- for ($i = 0; $i < $length; $i++) {
- $gd_style[] = $c;
- }
- }
-
- imagesetstyle($this->_img, $gd_style);
- $c = IMG_COLOR_STYLED;
- }
-
- imagesetthickness($this->_img, $width);
-
- if ( $fill )
- imagefilledellipse($this->_img, $x, $y, $r, $r, $c);
- else
- imageellipse($this->_img, $x, $y, $r, $r, $c);
-
- }
-
- /**
- * Add an image to the pdf.
- * The image is placed at the specified x and y coordinates with the
- * given width and height.
- *
- * @param string $img_url the path to the image
- * @param float $x x position
- * @param float $y y position
- * @param int $w width (in pixels)
- * @param int $h height (in pixels)
- * @param string $resolution
- *
- * @return void
- * @internal param string $img_type the type (e.g. extension) of the image
- */
- function image($img_url, $x, $y, $w, $h, $resolution = "normal") {
- $img_type = Image_Cache::detect_type($img_url);
- $img_ext = Image_Cache::type_to_ext($img_type);
-
- if ( !$img_ext ) {
- return;
- }
-
- $func = "imagecreatefrom$img_ext";
- $src = @$func($img_url);
-
- if ( !$src ) {
- return; // Probably should add to $_dompdf_errors or whatever here
- }
-
- // Scale by the AA factor
- $x *= $this->_aa_factor;
- $y *= $this->_aa_factor;
-
- $w *= $this->_aa_factor;
- $h *= $this->_aa_factor;
-
- $img_w = imagesx($src);
- $img_h = imagesy($src);
-
- imagecopyresampled($this->_img, $src, $x, $y, 0, 0, $w, $h, $img_w, $img_h);
-
- }
-
- /**
- * Writes text at the specified x and y coordinates
- * See {@link Style::munge_color()} for the format of the color array.
- *
- * @param float $x
- * @param float $y
- * @param string $text the text to write
- * @param string $font the font file to use
- * @param float $size the font size, in points
- * @param array $color
- * @param float $word_spacing word spacing adjustment
- * @param float $char_spacing
- * @param float $angle Text angle
- *
- * @return void
- */
- function text($x, $y, $text, $font, $size, $color = array(0,0,0), $word_spacing = 0.0, $char_spacing = 0.0, $angle = 0.0) {
-
- // Scale by the AA factor
- $x *= $this->_aa_factor;
- $y *= $this->_aa_factor;
- $size *= $this->_aa_factor;
-
- $h = $this->get_font_height($font, $size);
- $c = $this->_allocate_color($color);
-
- $text = mb_encode_numericentity($text, array(0x0080, 0xff, 0, 0xff), 'UTF-8');
-
- $font = $this->get_ttf_file($font);
-
- // FIXME: word spacing
- @imagettftext($this->_img, $size, $angle, $x, $y + $h, $c, $font, $text);
-
- }
-
- function javascript($code) {
- // Not implemented
- }
-
- /**
- * Add a named destination (similar to ... in html)
- *
- * @param string $anchorname The name of the named destination
- */
- function add_named_dest($anchorname) {
- // Not implemented
- }
-
- /**
- * Add a link to the pdf
- *
- * @param string $url The url to link to
- * @param float $x The x position of the link
- * @param float $y The y position of the link
- * @param float $width The width of the link
- * @param float $height The height of the link
- */
- function add_link($url, $x, $y, $width, $height) {
- // Not implemented
- }
-
- /**
- * Add meta information to the PDF
- *
- * @param string $label label of the value (Creator, Producer, etc.)
- * @param string $value the text to set
- */
- function add_info($label, $value) {
- // N/A
- }
-
- function set_default_view($view, $options = array()) {
- // N/A
- }
-
- /**
- * Calculates text size, in points
- *
- * @param string $text the text to be sized
- * @param string $font the desired font
- * @param float $size the desired font size
- * @param float $word_spacing word spacing, if any
- * @param float $char_spacing char spacing, if any
- *
- * @return float
- */
- function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0) {
- $font = $this->get_ttf_file($font);
-
- $text = mb_encode_numericentity($text, array(0x0080, 0xffff, 0, 0xffff), 'UTF-8');
-
- // FIXME: word spacing
- list($x1,,$x2) = @imagettfbbox($size, 0, $font, $text);
- return $x2 - $x1;
- }
-
- function get_ttf_file($font) {
- if ( strpos($font, '.ttf') === false )
- $font .= ".ttf";
-
- /*$filename = substr(strtolower(basename($font)), 0, -4);
-
- if ( in_array($filename, DOMPDF::$native_fonts) ) {
- return "arial.ttf";
- }*/
-
- return $font;
- }
-
- /**
- * Calculates font height, in points
- *
- * @param string $font
- * @param float $size
- * @return float
- */
- function get_font_height($font, $size) {
- $font = $this->get_ttf_file($font);
- $ratio = $this->_dompdf->get_option("font_height_ratio");
-
- // FIXME: word spacing
- list(,$y2,,,,$y1) = imagettfbbox($size, 0, $font, "MXjpqytfhl"); // Test string with ascenders, descenders and caps
- return ($y2 - $y1) * $ratio;
- }
-
- function get_font_baseline($font, $size) {
- $ratio = $this->_dompdf->get_option("font_height_ratio");
- return $this->get_font_height($font, $size) / $ratio;
- }
-
- /**
- * Starts a new page
- *
- * Subsequent drawing operations will appear on the new page.
- */
- function new_page() {
- $this->_page_number++;
- $this->_page_count++;
- }
-
- function open_object(){
- // N/A
- }
-
- function close_object(){
- // N/A
- }
-
- function add_object(){
- // N/A
- }
-
- function page_text(){
- // N/A
- }
-
- /**
- * Streams the image directly to the browser
- *
- * @param string $filename the name of the image file (ignored)
- * @param array $options associative array, 'type' => jpeg|jpg|png, 'quality' => 0 - 100 (jpeg only)
- */
- function stream($filename, $options = null) {
-
- // Perform any antialiasing
- if ( $this->_aa_factor != 1 ) {
- $dst_w = $this->_width / $this->_aa_factor;
- $dst_h = $this->_height / $this->_aa_factor;
- $dst = imagecreatetruecolor($dst_w, $dst_h);
- imagecopyresampled($dst, $this->_img, 0, 0, 0, 0,
- $dst_w, $dst_h,
- $this->_width, $this->_height);
- } else {
- $dst = $this->_img;
- }
-
- if ( !isset($options["type"]) )
- $options["type"] = "png";
-
- $type = strtolower($options["type"]);
-
- header("Cache-Control: private");
-
- switch ($type) {
-
- case "jpg":
- case "jpeg":
- if ( !isset($options["quality"]) )
- $options["quality"] = 75;
-
- header("Content-type: image/jpeg");
- imagejpeg($dst, '', $options["quality"]);
- break;
-
- case "png":
- default:
- header("Content-type: image/png");
- imagepng($dst);
- break;
- }
-
- if ( $this->_aa_factor != 1 )
- imagedestroy($dst);
- }
-
- /**
- * Returns the PNG as a string
- *
- * @param array $options associative array, 'type' => jpeg|jpg|png, 'quality' => 0 - 100 (jpeg only)
- * @return string
- */
- function output($options = null) {
-
- if ( $this->_aa_factor != 1 ) {
- $dst_w = $this->_width / $this->_aa_factor;
- $dst_h = $this->_height / $this->_aa_factor;
- $dst = imagecreatetruecolor($dst_w, $dst_h);
- imagecopyresampled($dst, $this->_img, 0, 0, 0, 0,
- $dst_w, $dst_h,
- $this->_width, $this->_height);
- } else {
- $dst = $this->_img;
- }
-
- if ( !isset($options["type"]) )
- $options["type"] = "png";
-
- $type = $options["type"];
-
- ob_start();
-
- switch ($type) {
-
- case "jpg":
- case "jpeg":
- if ( !isset($options["quality"]) )
- $options["quality"] = 75;
-
- imagejpeg($dst, '', $options["quality"]);
- break;
-
- case "png":
- default:
- imagepng($dst);
- break;
- }
-
- $image = ob_get_clean();
-
- if ( $this->_aa_factor != 1 )
- imagedestroy($dst);
-
- return $image;
- }
-
-
-}
diff --git a/application/helpers/dompdf/include/image_cache.cls.php b/application/helpers/dompdf/include/image_cache.cls.php
deleted file mode 100755
index 7d7e5603b..000000000
--- a/application/helpers/dompdf/include/image_cache.cls.php
+++ /dev/null
@@ -1,183 +0,0 @@
-
- * @author Helmut Tischer
- * Style->margin_top = "1em";
- * echo (Style->margin_top);
- *
- *
- * __set() automatically calls the provided set function, if one exists,
- * otherwise it sets the property directly. Typically, __set() is not
- * called directly from outside of this class.
- *
- * On each modification clear cache to return accurate setting.
- * Also affects direct settings not using __set
- * For easier finding all assignments, attempted to allowing only explicite assignment:
- * Very many uses, e.g. frame_reflower.cls.php -> for now leave as it is
- * function __set($prop, $val) {
- * throw new DOMPDF_Exception("Implicite replacement of assignment by __set. Not good.");
- * }
- * function props_set($prop, $val) { ... }
- *
- * @param string $prop the property to set
- * @param mixed $val the value of the property
- *
- */
- function __set($prop, $val) {
- $prop = str_replace("-", "_", $prop);
- $this->_prop_cache[$prop] = null;
-
- if ( !isset(self::$_defaults[$prop]) ) {
- global $_dompdf_warnings;
- $_dompdf_warnings[] = "'$prop' is not a valid CSS2 property.";
- return;
- }
-
- if ( $prop !== "content" && is_string($val) && strlen($val) > 5 && mb_strpos($val, "url") === false ) {
- $val = mb_strtolower(trim(str_replace(array("\n", "\t"), array(" "), $val)));
- $val = preg_replace("/([0-9]+) (pt|px|pc|em|ex|in|cm|mm|%)/S", "\\1\\2", $val);
- }
-
- $method = "set_$prop";
-
- if ( !isset(self::$_methods_cache[$method]) ) {
- self::$_methods_cache[$method] = method_exists($this, $method);
- }
-
- if ( self::$_methods_cache[$method] ) {
- $this->$method($val);
- }
- else {
- $this->_props[$prop] = $val;
- }
- }
-
- /**
- * PHP5 overloaded getter
- * Along with {@link Style::__set()} __get() provides access to all CSS
- * properties directly. Typically __get() is not called directly outside
- * of this class.
- * On each modification clear cache to return accurate setting.
- * Also affects direct settings not using __set
- *
- * @param string $prop
- *
- * @throws DOMPDF_Exception
- * @return mixed
- */
- function __get($prop) {
- if ( !isset(self::$_defaults[$prop]) ) {
- throw new DOMPDF_Exception("'$prop' is not a valid CSS2 property.");
- }
-
- if ( isset($this->_prop_cache[$prop]) && $this->_prop_cache[$prop] != null ) {
- return $this->_prop_cache[$prop];
- }
-
- $method = "get_$prop";
-
- // Fall back on defaults if property is not set
- if ( !isset($this->_props[$prop]) ) {
- $this->_props[$prop] = self::$_defaults[$prop];
- }
-
- if ( !isset(self::$_methods_cache[$method]) ) {
- self::$_methods_cache[$method] = method_exists($this, $method);
- }
-
- if ( self::$_methods_cache[$method] ) {
- return $this->_prop_cache[$prop] = $this->$method();
- }
-
- return $this->_prop_cache[$prop] = $this->_props[$prop];
- }
-
- function get_font_family_raw(){
- return trim($this->_props["font_family"], " \t\n\r\x0B\"'");
- }
-
- /**
- * Getter for the 'font-family' CSS property.
- * Uses the {@link Font_Metrics} class to resolve the font family into an
- * actual font file.
- *
- * @link http://www.w3.org/TR/CSS21/fonts.html#propdef-font-family
- * @throws DOMPDF_Exception
- *
- * @return string
- */
- function get_font_family() {
- if ( isset($this->_font_family) ) {
- return $this->_font_family;
- }
-
- $DEBUGCSS=DEBUGCSS; //=DEBUGCSS; Allow override of global setting for ad hoc debug
-
- // Select the appropriate font. First determine the subtype, then check
- // the specified font-families for a candidate.
-
- // Resolve font-weight
- $weight = $this->__get("font_weight");
-
- if ( is_numeric($weight) ) {
- if ( $weight < 600 ) {
- $weight = "normal";
- }
- else {
- $weight = "bold";
- }
- }
- else if ( $weight === "bold" || $weight === "bolder" ) {
- $weight = "bold";
- }
- else {
- $weight = "normal";
- }
-
- // Resolve font-style
- $font_style = $this->__get("font_style");
-
- if ( $weight === "bold" && ($font_style === "italic" || $font_style === "oblique") ) {
- $subtype = "bold_italic";
- }
- else if ( $weight === "bold" && $font_style !== "italic" && $font_style !== "oblique" ) {
- $subtype = "bold";
- }
- else if ( $weight !== "bold" && ($font_style === "italic" || $font_style === "oblique") ) {
- $subtype = "italic";
- }
- else {
- $subtype = "normal";
- }
-
- // Resolve the font family
- if ( $DEBUGCSS ) {
- print "[get_font_family:";
- print '('.$this->_props["font_family"].'.'.$font_style.'.'.$this->__get("font_weight").'.'.$weight.'.'.$subtype.')';
- }
-
- $families = preg_split("/\s*,\s*/", $this->_props["font_family"]);
-
- $font = null;
- foreach($families as $family) {
- //remove leading and trailing string delimiters, e.g. on font names with spaces;
- //remove leading and trailing whitespace
- $family = trim($family, " \t\n\r\x0B\"'");
- if ( $DEBUGCSS ) {
- print '('.$family.')';
- }
- $font = Font_Metrics::get_font($family, $subtype);
-
- if ( $font ) {
- if ($DEBUGCSS) print '('.$font.")get_font_family]\n";
- return $this->_font_family = $font;
- }
- }
-
- $family = null;
- if ( $DEBUGCSS ) {
- print '(default)';
- }
- $font = Font_Metrics::get_font($family, $subtype);
-
- if ( $font ) {
- if ( $DEBUGCSS ) print '('.$font.")get_font_family]\n";
- return$this->_font_family = $font;
- }
-
- throw new DOMPDF_Exception("Unable to find a suitable font replacement for: '" . $this->_props["font_family"] ."'");
-
- }
-
- /**
- * Returns the resolved font size, in points
- *
- * @link http://www.w3.org/TR/CSS21/fonts.html#propdef-font-size
- * @return float
- */
- function get_font_size() {
-
- if ( $this->__font_size_calculated ) {
- return $this->_props["font_size"];
- }
-
- if ( !isset($this->_props["font_size"]) ) {
- $fs = self::$_defaults["font_size"];
- }
- else {
- $fs = $this->_props["font_size"];
- }
-
- if ( !isset($this->_parent_font_size) ) {
- $this->_parent_font_size = self::$default_font_size;
- }
-
- switch ((string)$fs) {
- case "xx-small":
- case "x-small":
- case "small":
- case "medium":
- case "large":
- case "x-large":
- case "xx-large":
- $fs = self::$default_font_size * self::$font_size_keywords[$fs];
- break;
-
- case "smaller":
- $fs = 8/9 * $this->_parent_font_size;
- break;
-
- case "larger":
- $fs = 6/5 * $this->_parent_font_size;
- break;
-
- default:
- break;
- }
-
- // Ensure relative sizes resolve to something
- if ( ($i = mb_strpos($fs, "em")) !== false ) {
- $fs = mb_substr($fs, 0, $i) * $this->_parent_font_size;
- }
- else if ( ($i = mb_strpos($fs, "ex")) !== false ) {
- $fs = mb_substr($fs, 0, $i) * $this->_parent_font_size;
- }
- else {
- $fs = $this->length_in_pt($fs);
- }
-
- //see __set and __get, on all assignments clear cache!
- $this->_prop_cache["font_size"] = null;
- $this->_props["font_size"] = $fs;
- $this->__font_size_calculated = true;
- return $this->_props["font_size"];
-
- }
-
- /**
- * @link http://www.w3.org/TR/CSS21/text.html#propdef-word-spacing
- * @return float
- */
- function get_word_spacing() {
- if ( $this->_props["word_spacing"] === "normal" ) {
- return 0;
- }
-
- return $this->_props["word_spacing"];
- }
-
- /**
- * @link http://www.w3.org/TR/CSS21/text.html#propdef-letter-spacing
- * @return float
- */
- function get_letter_spacing() {
- if ( $this->_props["letter_spacing"] === "normal" ) {
- return 0;
- }
-
- return $this->_props["letter_spacing"];
- }
-
- /**
- * @link http://www.w3.org/TR/CSS21/visudet.html#propdef-line-height
- * @return float
- */
- function get_line_height() {
- $line_height = $this->_props["line_height"];
-
- if ( $line_height === "normal" ) {
- return self::$default_line_height * $this->get_font_size();
- }
-
- if ( is_numeric($line_height) ) {
- return $this->length_in_pt( $line_height . "em", $this->get_font_size());
- }
-
- return $this->length_in_pt( $line_height, $this->_parent_font_size );
- }
-
- /**
- * Returns the color as an array
- *
- * The array has the following format:
- * array(r,g,b, "r" => r, "g" => g, "b" => b, "hex" => "#rrggbb")
- *
- * @link http://www.w3.org/TR/CSS21/colors.html#propdef-color
- * @return array
- */
- function get_color() {
- return $this->munge_color( $this->_props["color"] );
- }
-
- /**
- * Returns the background color as an array
- *
- * The returned array has the same format as {@link Style::get_color()}
- *
- * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-color
- * @return array
- */
- function get_background_color() {
- return $this->munge_color( $this->_props["background_color"] );
- }
-
- /**
- * Returns the background position as an array
- *
- * The returned array has the following format:
- * array(x,y, "x" => x, "y" => y)
- *
- * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-position
- * @return array
- */
- function get_background_position() {
- $tmp = explode(" ", $this->_props["background_position"]);
-
- switch ($tmp[0]) {
- case "left":
- $x = "0%";
- break;
-
- case "right":
- $x = "100%";
- break;
-
- case "top":
- $y = "0%";
- break;
-
- case "bottom":
- $y = "100%";
- break;
-
- case "center":
- $x = "50%";
- $y = "50%";
- break;
-
- default:
- $x = $tmp[0];
- break;
- }
-
- if ( isset($tmp[1]) ) {
-
- switch ($tmp[1]) {
- case "left":
- $x = "0%";
- break;
-
- case "right":
- $x = "100%";
- break;
-
- case "top":
- $y = "0%";
- break;
-
- case "bottom":
- $y = "100%";
- break;
-
- case "center":
- if ( $tmp[0] === "left" || $tmp[0] === "right" || $tmp[0] === "center" ) {
- $y = "50%";
- }
- else {
- $x = "50%";
- }
- break;
-
- default:
- $y = $tmp[1];
- break;
- }
-
- }
- else {
- $y = "50%";
- }
-
- if ( !isset($x) ) {
- $x = "0%";
- }
-
- if ( !isset($y) ) {
- $y = "0%";
- }
-
- return array(
- 0 => $x, "x" => $x,
- 1 => $y, "y" => $y,
- );
- }
-
-
- /**
- * Returns the background as it is currently stored
- *
- * (currently anyway only for completeness.
- * not used for further processing)
- *
- * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-attachment
- * @return string
- */
- function get_background_attachment() {
- return $this->_props["background_attachment"];
- }
-
-
- /**
- * Returns the background_repeat as it is currently stored
- *
- * (currently anyway only for completeness.
- * not used for further processing)
- *
- * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-repeat
- * @return string
- */
- function get_background_repeat() {
- return $this->_props["background_repeat"];
- }
-
-
- /**
- * Returns the background as it is currently stored
- *
- * (currently anyway only for completeness.
- * not used for further processing, but the individual get_background_xxx)
- *
- * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background
- * @return string
- */
- function get_background() {
- return $this->_props["background"];
- }
-
-
- /**#@+
- * Returns the border color as an array
- *
- * See {@link Style::get_color()}
- *
- * @link http://www.w3.org/TR/CSS21/box.html#border-color-properties
- * @return array
- */
- function get_border_top_color() {
- if ( $this->_props["border_top_color"] === "" ) {
- //see __set and __get, on all assignments clear cache!
- $this->_prop_cache["border_top_color"] = null;
- $this->_props["border_top_color"] = $this->__get("color");
- }
-
- return $this->munge_color($this->_props["border_top_color"]);
- }
-
- function get_border_right_color() {
- if ( $this->_props["border_right_color"] === "" ) {
- //see __set and __get, on all assignments clear cache!
- $this->_prop_cache["border_right_color"] = null;
- $this->_props["border_right_color"] = $this->__get("color");
- }
-
- return $this->munge_color($this->_props["border_right_color"]);
- }
-
- function get_border_bottom_color() {
- if ( $this->_props["border_bottom_color"] === "" ) {
- //see __set and __get, on all assignments clear cache!
- $this->_prop_cache["border_bottom_color"] = null;
- $this->_props["border_bottom_color"] = $this->__get("color");
- }
-
- return $this->munge_color($this->_props["border_bottom_color"]);
- }
-
- function get_border_left_color() {
- if ( $this->_props["border_left_color"] === "" ) {
- //see __set and __get, on all assignments clear cache!
- $this->_prop_cache["border_left_color"] = null;
- $this->_props["border_left_color"] = $this->__get("color");
- }
-
- return $this->munge_color($this->_props["border_left_color"]);
- }
-
- /**#@-*/
-
- /**#@+
- * Returns the border width, as it is currently stored
- *
- * @link http://www.w3.org/TR/CSS21/box.html#border-width-properties
- * @return float|string
- */
- function get_border_top_width() {
- $style = $this->__get("border_top_style");
- return $style !== "none" && $style !== "hidden" ? $this->length_in_pt($this->_props["border_top_width"]) : 0;
- }
-
- function get_border_right_width() {
- $style = $this->__get("border_right_style");
- return $style !== "none" && $style !== "hidden" ? $this->length_in_pt($this->_props["border_right_width"]) : 0;
- }
-
- function get_border_bottom_width() {
- $style = $this->__get("border_bottom_style");
- return $style !== "none" && $style !== "hidden" ? $this->length_in_pt($this->_props["border_bottom_width"]) : 0;
- }
-
- function get_border_left_width() {
- $style = $this->__get("border_left_style");
- return $style !== "none" && $style !== "hidden" ? $this->length_in_pt($this->_props["border_left_width"]) : 0;
- }
- /**#@-*/
-
- /**
- * Return an array of all border properties.
- *
- * The returned array has the following structure:
- *
- * array("top" => array("width" => [border-width],
- * "style" => [border-style],
- * "color" => [border-color (array)]),
- * "bottom" ... )
- *
- *
- * @return array
- */
- function get_border_properties() {
- return array(
- "top" => array(
- "width" => $this->__get("border_top_width"),
- "style" => $this->__get("border_top_style"),
- "color" => $this->__get("border_top_color"),
- ),
- "bottom" => array(
- "width" => $this->__get("border_bottom_width"),
- "style" => $this->__get("border_bottom_style"),
- "color" => $this->__get("border_bottom_color"),
- ),
- "right" => array(
- "width" => $this->__get("border_right_width"),
- "style" => $this->__get("border_right_style"),
- "color" => $this->__get("border_right_color"),
- ),
- "left" => array(
- "width" => $this->__get("border_left_width"),
- "style" => $this->__get("border_left_style"),
- "color" => $this->__get("border_left_color"),
- ),
- );
- }
-
- /**
- * Return a single border property
- *
- * @param string $side
- *
- * @return mixed
- */
- protected function _get_border($side) {
- $color = $this->__get("border_" . $side . "_color");
-
- return $this->__get("border_" . $side . "_width") . " " .
- $this->__get("border_" . $side . "_style") . " " . $color["hex"];
- }
-
- /**#@+
- * Return full border properties as a string
- *
- * Border properties are returned just as specified in CSS:
- * [width] [style] [color]- * e.g. "1px solid blue" - * - * @link http://www.w3.org/TR/CSS21/box.html#border-shorthand-properties - * @return string - */ - function get_border_top() { - return $this->_get_border("top"); - } - - function get_border_right() { - return $this->_get_border("right"); - } - - function get_border_bottom() { - return $this->_get_border("bottom"); - } - - function get_border_left() { - return $this->_get_border("left"); - } - /**#@-*/ - - function get_computed_border_radius($w, $h) { - if ( !empty($this->_computed_border_radius) ) { - return $this->_computed_border_radius; - } - - $rTL = $this->__get("border_top_left_radius"); - $rTR = $this->__get("border_top_right_radius"); - $rBL = $this->__get("border_bottom_left_radius"); - $rBR = $this->__get("border_bottom_right_radius"); - - if ( $rTL + $rTR + $rBL + $rBR == 0 ) { - return $this->_computed_border_radius = array( - 0, 0, 0, 0, - "top-left" => 0, - "top-right" => 0, - "bottom-right" => 0, - "bottom-left" => 0, - ); - } - - $t = $this->__get("border_top_width"); - $r = $this->__get("border_right_width"); - $b = $this->__get("border_bottom_width"); - $l = $this->__get("border_left_width"); - - $rTL = min($rTL, $h - $rBL - $t/2 - $b/2, $w - $rTR - $l/2 - $r/2); - $rTR = min($rTR, $h - $rBR - $t/2 - $b/2, $w - $rTL - $l/2 - $r/2); - $rBL = min($rBL, $h - $rTL - $t/2 - $b/2, $w - $rBR - $l/2 - $r/2); - $rBR = min($rBR, $h - $rTR - $t/2 - $b/2, $w - $rBL - $l/2 - $r/2); - - return $this->_computed_border_radius = array( - $rTL, $rTR, $rBR, $rBL, - "top-left" => $rTL, - "top-right" => $rTR, - "bottom-right" => $rBR, - "bottom-left" => $rBL, - ); - } - /**#@-*/ - - - /** - * Returns the outline color as an array - * - * See {@link Style::get_color()} - * - * @link http://www.w3.org/TR/CSS21/box.html#border-color-properties - * @return array - */ - function get_outline_color() { - if ( $this->_props["outline_color"] === "" ) { - //see __set and __get, on all assignments clear cache! - $this->_prop_cache["outline_color"] = null; - $this->_props["outline_color"] = $this->__get("color"); - } - - return $this->munge_color($this->_props["outline_color"]); - } - - /**#@+ - * Returns the outline width, as it is currently stored - * @return float|string - */ - function get_outline_width() { - $style = $this->__get("outline_style"); - return $style !== "none" && $style !== "hidden" ? $this->length_in_pt($this->_props["outline_width"]) : 0; - } - - /**#@+ - * Return full outline properties as a string - * - * Outline properties are returned just as specified in CSS: - *
[width] [style] [color]- * e.g. "1px solid blue" - * - * @link http://www.w3.org/TR/CSS21/box.html#border-shorthand-properties - * @return string - */ - function get_outline() { - $color = $this->__get("outline_color"); - return - $this->__get("outline_width") . " " . - $this->__get("outline_style") . " " . - $color["hex"]; - } - /**#@-*/ - - /** - * Returns border spacing as an array - * - * The array has the format (h_space,v_space) - * - * @link http://www.w3.org/TR/CSS21/tables.html#propdef-border-spacing - * @return array - */ - function get_border_spacing() { - $arr = explode(" ", $this->_props["border_spacing"]); - if ( count($arr) == 1 ) { - $arr[1] = $arr[0]; - } - return $arr; - } - -/*==============================*/ - - /* - !important attribute - For basic functionality of the !important attribute with overloading - of several styles of an element, changes in inherit(), merge() and _parse_properties() - are sufficient [helpers var $_important_props, __construct(), important_set(), important_get()] - - Only for combined attributes extra treatment needed. See below. - - div { border: 1px red; } - div { border: solid; } // Not combined! Only one occurence of same style per context - // - div { border: 1px red; } - div a { border: solid; } // Adding to border style ok by inheritance - // - div { border-style: solid; } // Adding to border style ok because of different styles - div { border: 1px red; } - // - div { border-style: solid; !important} // border: overrides, even though not !important - div { border: 1px dashed red; } - // - div { border: 1px red; !important } - div a { border-style: solid; } // Need to override because not set - - Special treatment: - At individual property like border-top-width need to check whether overriding value is also !important. - Also store the !important condition for later overrides. - Since not known who is initiating the override, need to get passed !important as parameter. - !important Paramter taken as in the original style in the css file. - When property border !important given, do not mark subsets like border_style as important. Only - individual properties. - - Note: - Setting individual property directly from css with e.g. set_border_top_style() is not needed, because - missing set funcions handled by a generic handler __set(), including the !important. - Setting individual property of as sub-property is handled below. - - Implementation see at _set_style_side_type() - Callers _set_style_sides_type(), _set_style_type, _set_style_type_important() - - Related functionality for background, padding, margin, font, list_style - */ - - /* Generalized set function for individual attribute of combined style. - * With check for !important - * Applicable for background, border, padding, margin, font, list_style - * Note: $type has a leading underscore (or is empty), the others not. - */ - protected function _set_style_side_type($style, $side, $type, $val, $important) { - $prop = $style.'_'.$side.$type; - - if ( !isset($this->_important_props[$prop]) || $important) { - //see __set and __get, on all assignments clear cache! - $this->_prop_cache[$prop] = null; - if ( $important ) { - $this->_important_props[$prop] = true; - } - $this->_props[$prop] = $val; - } - } - - protected function _set_style_sides_type($style,$top,$right,$bottom,$left,$type,$important) { - $this->_set_style_side_type($style,'top',$type,$top,$important); - $this->_set_style_side_type($style,'right',$type,$right,$important); - $this->_set_style_side_type($style,'bottom',$type,$bottom,$important); - $this->_set_style_side_type($style,'left',$type,$left,$important); - } - - protected function _set_style_type($style,$type,$val,$important) { - $val = preg_replace("/\s*\,\s*/", ",", $val); // when rgb() has spaces - $arr = explode(" ", $val); - - switch (count($arr)) { - case 1: $this->_set_style_sides_type($style,$arr[0],$arr[0],$arr[0],$arr[0],$type,$important); break; - case 2: $this->_set_style_sides_type($style,$arr[0],$arr[1],$arr[0],$arr[1],$type,$important); break; - case 3: $this->_set_style_sides_type($style,$arr[0],$arr[1],$arr[2],$arr[1],$type,$important); break; - case 4: $this->_set_style_sides_type($style,$arr[0],$arr[1],$arr[2],$arr[3],$type,$important); break; - } - - //see __set and __get, on all assignments clear cache! - $this->_prop_cache[$style.$type] = null; - $this->_props[$style.$type] = $val; - } - - protected function _set_style_type_important($style,$type,$val) { - $this->_set_style_type($style,$type,$val,isset($this->_important_props[$style.$type])); - } - - /* Anyway only called if _important matches and is assigned - * E.g. _set_style_side_type($style,$side,'',str_replace("none", "0px", $val),isset($this->_important_props[$style.'_'.$side])); - */ - protected function _set_style_side_width_important($style,$side,$val) { - //see __set and __get, on all assignments clear cache! - $this->_prop_cache[$style.'_'.$side] = null; - $this->_props[$style.'_'.$side] = str_replace("none", "0px", $val); - } - - protected function _set_style($style,$val,$important) { - if ( !isset($this->_important_props[$style]) || $important) { - if ( $important ) { - $this->_important_props[$style] = true; - } - //see __set and __get, on all assignments clear cache! - $this->_prop_cache[$style] = null; - $this->_props[$style] = $val; - } - } - - protected function _image($val) { - $DEBUGCSS=DEBUGCSS; - $parsed_url = "none"; - - if ( mb_strpos($val, "url") === false ) { - $path = "none"; //Don't resolve no image -> otherwise would prefix path and no longer recognize as none - } - else { - $val = preg_replace("/url\(['\"]?([^'\")]+)['\"]?\)/","\\1", trim($val)); - - // Resolve the url now in the context of the current stylesheet - $parsed_url = explode_url($val); - if ( $parsed_url["protocol"] == "" && $this->_stylesheet->get_protocol() == "" ) { - if ($parsed_url["path"][0] === '/' || $parsed_url["path"][0] === '\\' ) { - $path = $_SERVER["DOCUMENT_ROOT"].'/'; - } - else { - $path = $this->_stylesheet->get_base_path(); - } - - $path .= $parsed_url["path"] . $parsed_url["file"]; - $path = realpath($path); - // If realpath returns FALSE then specifically state that there is no background image - if ( !$path ) { - $path = 'none'; - } - } - else { - $path = build_url($this->_stylesheet->get_protocol(), - $this->_stylesheet->get_host(), - $this->_stylesheet->get_base_path(), - $val); - } - } - if ($DEBUGCSS) { - print "
[_image\n"; - print_r($parsed_url); - print $this->_stylesheet->get_protocol()."\n".$this->_stylesheet->get_base_path()."\n".$path."\n"; - print "_image]";; - } - return $path; - } - -/*======================*/ - - /** - * Sets color - * - * The color parameter can be any valid CSS color value - * - * @link http://www.w3.org/TR/CSS21/colors.html#propdef-color - * @param string $color - */ - function set_color($color) { - $col = $this->munge_color($color); - - if ( is_null($col) || !isset($col["hex"]) ) { - $color = "inherit"; - } - else { - $color = $col["hex"]; - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["color"] = null; - $this->_props["color"] = $color; - } - - /** - * Sets the background color - * - * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-color - * @param string $color - */ - function set_background_color($color) { - $col = $this->munge_color($color); - - if ( is_null($col) ) { - return; - //$col = self::$_defaults["background_color"]; - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["background_color"] = null; - $this->_props["background_color"] = is_array($col) ? $col["hex"] : $col; - } - - /** - * Set the background image url - * @link http://www.w3.org/TR/CSS21/colors.html#background-properties - * - * @param string $val - */ - function set_background_image($val) { - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["background_image"] = null; - $this->_props["background_image"] = $this->_image($val); - } - - /** - * Sets the background repeat - * - * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-repeat - * @param string $val - */ - function set_background_repeat($val) { - if ( is_null($val) ) { - $val = self::$_defaults["background_repeat"]; - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["background_repeat"] = null; - $this->_props["background_repeat"] = $val; - } - - /** - * Sets the background attachment - * - * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-attachment - * @param string $val - */ - function set_background_attachment($val) { - if ( is_null($val) ) { - $val = self::$_defaults["background_attachment"]; - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["background_attachment"] = null; - $this->_props["background_attachment"] = $val; - } - - /** - * Sets the background position - * - * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-position - * @param string $val - */ - function set_background_position($val) { - if ( is_null($val) ) { - $val = self::$_defaults["background_position"]; - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["background_position"] = null; - $this->_props["background_position"] = $val; - } - - /** - * Sets the background - combined options - * - * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background - * @param string $val - */ - function set_background($val) { - $val = trim($val); - $important = isset($this->_important_props["background"]); - - if ( $val === "none" ) { - $this->_set_style("background_image", "none", $important); - $this->_set_style("background_color", "transparent", $important); - } - else { - $pos = array(); - $tmp = preg_replace("/\s*\,\s*/", ",", $val); // when rgb() has spaces - $tmp = preg_split("/\s+/", $tmp); - - foreach($tmp as $attr) { - if ( mb_substr($attr, 0, 3) === "url" || $attr === "none" ) { - $this->_set_style("background_image", $this->_image($attr), $important); - } - elseif ( $attr === "fixed" || $attr === "scroll" ) { - $this->_set_style("background_attachment", $attr, $important); - } - elseif ( $attr === "repeat" || $attr === "repeat-x" || $attr === "repeat-y" || $attr === "no-repeat" ) { - $this->_set_style("background_repeat", $attr, $important); - } - elseif ( ($col = $this->munge_color($attr)) != null ) { - $this->_set_style("background_color", is_array($col) ? $col["hex"] : $col, $important); - } - else { - $pos[] = $attr; - } - } - - if (count($pos)) { - $this->_set_style("background_position", implode(" ", $pos), $important); - } - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["background"] = null; - $this->_props["background"] = $val; - } - - /** - * Sets the font size - * - * $size can be any acceptable CSS size - * - * @link http://www.w3.org/TR/CSS21/fonts.html#propdef-font-size - * @param string|float $size - */ - function set_font_size($size) { - $this->__font_size_calculated = false; - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["font_size"] = null; - $this->_props["font_size"] = $size; - } - - /** - * Sets the font style - * - * combined attributes - * set individual attributes also, respecting !important mark - * exactly this order, separate by space. Multiple fonts separated by comma: - * font-style, font-variant, font-weight, font-size, line-height, font-family - * - * Other than with border and list, existing partial attributes should - * reset when starting here, even when not mentioned. - * If individual attribute is !important and explicite or implicite replacement is not, - * keep individual attribute - * - * require whitespace as delimiters for single value attributes - * On delimiter "/" treat first as font height, second as line height - * treat all remaining at the end of line as font - * font-style, font-variant, font-weight, font-size, line-height, font-family - * - * missing font-size and font-family might be not allowed, but accept it here and - * use default (medium size, enpty font name) - * - * @link http://www.w3.org/TR/CSS21/generate.html#propdef-list-style - * @param $val - */ - function set_font($val) { - $this->__font_size_calculated = false; - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["font"] = null; - $this->_props["font"] = $val; - - $important = isset($this->_important_props["font"]); - - if ( preg_match("/^(italic|oblique|normal)\s*(.*)$/i",$val,$match) ) { - $this->_set_style("font_style", $match[1], $important); - $val = $match[2]; - } - else { - $this->_set_style("font_style", self::$_defaults["font_style"], $important); - } - - if ( preg_match("/^(small-caps|normal)\s*(.*)$/i",$val,$match) ) { - $this->_set_style("font_variant", $match[1], $important); - $val = $match[2]; - } - else { - $this->_set_style("font_variant", self::$_defaults["font_variant"], $important); - } - - //matching numeric value followed by unit -> this is indeed a subsequent font size. Skip! - if ( preg_match("/^(bold|bolder|lighter|100|200|300|400|500|600|700|800|900|normal)\s*(.*)$/i", $val, $match) && - !preg_match("/^(?:pt|px|pc|em|ex|in|cm|mm|%)/",$match[2]) - ) { - $this->_set_style("font_weight", $match[1], $important); - $val = $match[2]; - } - else { - $this->_set_style("font_weight", self::$_defaults["font_weight"], $important); - } - - if ( preg_match("/^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger|\d+\s*(?:pt|px|pc|em|ex|in|cm|mm|%))\s*(.*)$/i",$val,$match) ) { - $this->_set_style("font_size", $match[1], $important); - $val = $match[2]; - if ( preg_match("/^\/\s*(\d+\s*(?:pt|px|pc|em|ex|in|cm|mm|%))\s*(.*)$/i", $val, $match ) ) { - $this->_set_style("line_height", $match[1], $important); - $val = $match[2]; - } - else { - $this->_set_style("line_height", self::$_defaults["line_height"], $important); - } - } - else { - $this->_set_style("font_size", self::$_defaults["font_size"], $important); - $this->_set_style("line_height", self::$_defaults["line_height"], $important); - } - - if( strlen($val) != 0 ) { - $this->_set_style("font_family", $val, $important); - } - else { - $this->_set_style("font_family", self::$_defaults["font_family"], $important); - } - } - - /**#@+ - * Sets page break properties - * - * @link http://www.w3.org/TR/CSS21/page.html#page-breaks - * @param string $break - */ - function set_page_break_before($break) { - if ( $break === "left" || $break === "right" ) { - $break = "always"; - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["page_break_before"] = null; - $this->_props["page_break_before"] = $break; - } - - function set_page_break_after($break) { - if ( $break === "left" || $break === "right" ) { - $break = "always"; - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["page_break_after"] = null; - $this->_props["page_break_after"] = $break; - } - /**#@-*/ - - //........................................................................ - - /**#@+ - * Sets the margin size - * - * @link http://www.w3.org/TR/CSS21/box.html#margin-properties - * @param $val - */ - function set_margin_top($val) { - $this->_set_style_side_width_important('margin','top',$val); - } - - function set_margin_right($val) { - $this->_set_style_side_width_important('margin','right',$val); - } - - function set_margin_bottom($val) { - $this->_set_style_side_width_important('margin','bottom',$val); - } - - function set_margin_left($val) { - $this->_set_style_side_width_important('margin','left',$val); - } - - function set_margin($val) { - $val = str_replace("none", "0px", $val); - $this->_set_style_type_important('margin','',$val); - } - /**#@-*/ - - /**#@+ - * Sets the padding size - * - * @link http://www.w3.org/TR/CSS21/box.html#padding-properties - * @param $val - */ - function set_padding_top($val) { - $this->_set_style_side_width_important('padding','top',$val); - } - - function set_padding_right($val) { - $this->_set_style_side_width_important('padding','right',$val); - } - - function set_padding_bottom($val) { - $this->_set_style_side_width_important('padding','bottom',$val); - } - - function set_padding_left($val) { - $this->_set_style_side_width_important('padding','left',$val); - } - - function set_padding($val) { - $val = str_replace("none", "0px", $val); - $this->_set_style_type_important('padding','',$val); - } - /**#@-*/ - - /** - * Sets a single border - * - * @param string $side - * @param string $border_spec ([width] [style] [color]) - * @param boolean $important - */ - protected function _set_border($side, $border_spec, $important) { - $border_spec = preg_replace("/\s*\,\s*/", ",", $border_spec); - //$border_spec = str_replace(",", " ", $border_spec); // Why did we have this ?? rbg(10, 102, 10) > rgb(10 102 10) - $arr = explode(" ", $border_spec); - - // FIXME: handle partial values - - //For consistency of individal and combined properties, and with ie8 and firefox3 - //reset all attributes, even if only partially given - $this->_set_style_side_type('border',$side,'_style',self::$_defaults['border_'.$side.'_style'],$important); - $this->_set_style_side_type('border',$side,'_width',self::$_defaults['border_'.$side.'_width'],$important); - $this->_set_style_side_type('border',$side,'_color',self::$_defaults['border_'.$side.'_color'],$important); - - foreach ($arr as $value) { - $value = trim($value); - if ( in_array($value, self::$BORDER_STYLES) ) { - $this->_set_style_side_type('border',$side,'_style',$value,$important); - } - else if ( preg_match("/[.0-9]+(?:px|pt|pc|em|ex|%|in|mm|cm)|(?:thin|medium|thick)/", $value ) ) { - $this->_set_style_side_type('border',$side,'_width',$value,$important); - } - else { - // must be color - $this->_set_style_side_type('border',$side,'_color',$value,$important); - } - } - - //see __set and __get, on all assignments clear cache! - $this->_prop_cache['border_'.$side] = null; - $this->_props['border_'.$side] = $border_spec; - } - - /** - * Sets the border styles - * - * @link http://www.w3.org/TR/CSS21/box.html#border-properties - * @param string $val - */ - function set_border_top($val) { - $this->_set_border("top", $val, isset($this->_important_props['border_top'])); - } - - function set_border_right($val) { - $this->_set_border("right", $val, isset($this->_important_props['border_right'])); - } - - function set_border_bottom($val) { - $this->_set_border("bottom", $val, isset($this->_important_props['border_bottom'])); - } - - function set_border_left($val) { - $this->_set_border("left", $val, isset($this->_important_props['border_left'])); - } - - function set_border($val) { - $important = isset($this->_important_props["border"]); - $this->_set_border("top", $val, $important); - $this->_set_border("right", $val, $important); - $this->_set_border("bottom", $val, $important); - $this->_set_border("left", $val, $important); - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["border"] = null; - $this->_props["border"] = $val; - } - - function set_border_width($val) { - $this->_set_style_type_important('border','_width',$val); - } - - function set_border_color($val) { - $this->_set_style_type_important('border','_color',$val); - } - - function set_border_style($val) { - $this->_set_style_type_important('border','_style',$val); - } - - /** - * Sets the border radius size - * - * http://www.w3.org/TR/css3-background/#corners - */ - function set_border_top_left_radius($val) { - $this->_set_border_radius_corner($val, "top_left"); - } - - function set_border_top_right_radius($val) { - $this->_set_border_radius_corner($val, "top_right"); - } - - function set_border_bottom_left_radius($val) { - $this->_set_border_radius_corner($val, "bottom_left"); - } - - function set_border_bottom_right_radius($val) { - $this->_set_border_radius_corner($val, "bottom_right"); - } - - function set_border_radius($val) { - $val = preg_replace("/\s*\,\s*/", ",", $val); // when border-radius has spaces - $arr = explode(" ", $val); - - switch (count($arr)) { - case 1: $this->_set_border_radii($arr[0],$arr[0],$arr[0],$arr[0]); break; - case 2: $this->_set_border_radii($arr[0],$arr[1],$arr[0],$arr[1]); break; - case 3: $this->_set_border_radii($arr[0],$arr[1],$arr[2],$arr[1]); break; - case 4: $this->_set_border_radii($arr[0],$arr[1],$arr[2],$arr[3]); break; - } - } - - protected function _set_border_radii($val1, $val2, $val3, $val4) { - $this->_set_border_radius_corner($val1, "top_left"); - $this->_set_border_radius_corner($val2, "top_right"); - $this->_set_border_radius_corner($val3, "bottom_right"); - $this->_set_border_radius_corner($val4, "bottom_left"); - } - - protected function _set_border_radius_corner($val, $corner) { - $this->_has_border_radius = true; - - //see __set and __get, on all assignments clear cache! - $this->_prop_cache["border_" . $corner . "_radius"] = null; - - $this->_props["border_" . $corner . "_radius"] = $this->length_in_pt($val); - } - - /** - * Sets the outline styles - * - * @link http://www.w3.org/TR/CSS21/ui.html#dynamic-outlines - * @param string $val - */ - function set_outline($val) { - $important = isset($this->_important_props["outline"]); - - $props = array( - "outline_style", - "outline_width", - "outline_color", - ); - - foreach($props as $prop) { - $_val = self::$_defaults[$prop]; - - if ( !isset($this->_important_props[$prop]) || $important) { - //see __set and __get, on all assignments clear cache! - $this->_prop_cache[$prop] = null; - if ( $important ) { - $this->_important_props[$prop] = true; - } - $this->_props[$prop] = $_val; - } - } - - $val = preg_replace("/\s*\,\s*/", ",", $val); // when rgb() has spaces - $arr = explode(" ", $val); - foreach ($arr as $value) { - $value = trim($value); - - if ( in_array($value, self::$BORDER_STYLES) ) { - $this->set_outline_style($value); - } - else if ( preg_match("/[.0-9]+(?:px|pt|pc|em|ex|%|in|mm|cm)|(?:thin|medium|thick)/", $value ) ) { - $this->set_outline_width($value); - } - else { - // must be color - $this->set_outline_color($value); - } - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["outline"] = null; - $this->_props["outline"] = $val; - } - - function set_outline_width($val) { - $this->_set_style_type_important('outline','_width',$val); - } - - function set_outline_color($val) { - $this->_set_style_type_important('outline','_color',$val); - } - - function set_outline_style($val) { - $this->_set_style_type_important('outline','_style',$val); - } - - /** - * Sets the border spacing - * - * @link http://www.w3.org/TR/CSS21/box.html#border-properties - * @param float $val - */ - function set_border_spacing($val) { - $arr = explode(" ", $val); - - if ( count($arr) == 1 ) { - $arr[1] = $arr[0]; - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["border_spacing"] = null; - $this->_props["border_spacing"] = "$arr[0] $arr[1]"; - } - - /** - * Sets the list style image - * - * @link http://www.w3.org/TR/CSS21/generate.html#propdef-list-style-image - * @param $val - */ - function set_list_style_image($val) { - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["list_style_image"] = null; - $this->_props["list_style_image"] = $this->_image($val); - } - - /** - * Sets the list style - * - * @link http://www.w3.org/TR/CSS21/generate.html#propdef-list-style - * @param $val - */ - function set_list_style($val) { - $important = isset($this->_important_props["list_style"]); - $arr = explode(" ", str_replace(",", " ", $val)); - - static $types = array( - "disc", "circle", "square", - "decimal-leading-zero", "decimal", "1", - "lower-roman", "upper-roman", "a", "A", - "lower-greek", - "lower-latin", "upper-latin", - "lower-alpha", "upper-alpha", - "armenian", "georgian", "hebrew", - "cjk-ideographic", "hiragana", "katakana", - "hiragana-iroha", "katakana-iroha", "none" - ); - - static $positions = array("inside", "outside"); - - foreach ($arr as $value) { - /* http://www.w3.org/TR/CSS21/generate.html#list-style - * A value of 'none' for the 'list-style' property sets both 'list-style-type' and 'list-style-image' to 'none' - */ - if ( $value === "none" ) { - $this->_set_style("list_style_type", $value, $important); - $this->_set_style("list_style_image", $value, $important); - continue; - } - - //On setting or merging or inheriting list_style_image as well as list_style_type, - //and url exists, then url has precedence, otherwise fall back to list_style_type - //Firefox is wrong here (list_style_image gets overwritten on explicite list_style_type) - //Internet Explorer 7/8 and dompdf is right. - - if ( mb_substr($value, 0, 3) === "url" ) { - $this->_set_style("list_style_image", $this->_image($value), $important); - continue; - } - - if ( in_array($value, $types) ) { - $this->_set_style("list_style_type", $value, $important); - } - else if ( in_array($value, $positions) ) { - $this->_set_style("list_style_position", $value, $important); - } - } - - //see __set and __get, on all assignments clear cache, not needed on direct set through __set - $this->_prop_cache["list_style"] = null; - $this->_props["list_style"] = $val; - } - - function set_size($val) { - $length_re = "/(\d+\s*(?:pt|px|pc|em|ex|in|cm|mm|%))/"; - - $val = mb_strtolower($val); - - if ( $val === "auto" ) { - return; - } - - $parts = preg_split("/\s+/", $val); - - $computed = array(); - if ( preg_match($length_re, $parts[0]) ) { - $computed[] = $this->length_in_pt($parts[0]); - - if ( isset($parts[1]) && preg_match($length_re, $parts[1]) ) { - $computed[] = $this->length_in_pt($parts[1]); - } - else { - $computed[] = $computed[0]; - } - } - elseif ( isset(CPDF_Adapter::$PAPER_SIZES[$parts[0]]) ) { - $computed = array_slice(CPDF_Adapter::$PAPER_SIZES[$parts[0]], 2, 2); - - if ( isset($parts[1]) && $parts[1] === "landscape" ) { - $computed = array_reverse($computed); - } - } - else { - return; - } - - $this->_props["size"] = $computed; - } - - /** - * Sets the CSS3 transform property - * - * @link http://www.w3.org/TR/css3-2d-transforms/#transform-property - * @param string $val - */ - function set_transform($val) { - $number = "\s*([^,\s]+)\s*"; - $tr_value = "\s*([^,\s]+)\s*"; - $angle = "\s*([^,\s]+(?:deg|rad)?)\s*"; - - if ( !preg_match_all("/[a-z]+\([^\)]+\)/i", $val, $parts, PREG_SET_ORDER) ) { - return; - } - - $functions = array( - //"matrix" => "\($number,$number,$number,$number,$number,$number\)", - - "translate" => "\($tr_value(?:,$tr_value)?\)", - "translateX" => "\($tr_value\)", - "translateY" => "\($tr_value\)", - - "scale" => "\($number(?:,$number)?\)", - "scaleX" => "\($number\)", - "scaleY" => "\($number\)", - - "rotate" => "\($angle\)", - - "skew" => "\($angle(?:,$angle)?\)", - "skewX" => "\($angle\)", - "skewY" => "\($angle\)", - ); - - $transforms = array(); - - foreach($parts as $part) { - $t = $part[0]; - - foreach($functions as $name => $pattern) { - if ( preg_match("/$name\s*$pattern/i", $t, $matches) ) { - $values = array_slice($matches, 1); - - switch($name) { - //
| " + parseString($(this))+ " | "; - } - } - }); - excel += '
| "+parseString($(this))+" | "; - } - } - colCount++; - }); - rowCount++; - excel += '
;?>/images/logo.png)