diff --git a/application/controllers/Config.php b/application/controllers/Config.php index b8e6cb8cb..ca2bbbabc 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -14,7 +14,6 @@ class Config extends Secure_area $data['stock_locations'] = $this->Stock_location->get_all()->result_array(); $data['support_barcode'] = $this->barcode_lib->get_list_barcodes(); $this->load->view("configs/manage", $data); - $this->_remove_duplicate_cookies(); } function save() @@ -62,7 +61,6 @@ class Config extends Secure_area $message = $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully'); $message = $upload_success ? $message : $this->upload->display_errors(); echo json_encode(array('success'=>$success,'message'=>$message)); - $this->_remove_duplicate_cookies(); } function save_locale() @@ -81,8 +79,7 @@ class Config extends Secure_area $result = $this->Appconfig->batch_save( $batch_save_data ); $success = $result ? true : false; echo json_encode(array('success'=>$success, 'message'=>$this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully'))); - $this->_remove_duplicate_cookies(); - } + } function stock_locations() { @@ -127,7 +124,6 @@ class Config extends Secure_area } $success = $this->db->trans_complete(); echo json_encode(array('success'=>$success,'message'=>$this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully'))); - $this->_remove_duplicate_cookies(); } function save_barcode() diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index f582288c0..3caa72aa5 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -42,7 +42,6 @@ class Item_kits extends Secure_area implements iData_controller $data['manage_table'] = get_item_kits_manage_table($item_kits, $this); $this->load->view('item_kits/manage', $data); - $this->_remove_duplicate_cookies(); } /* @@ -65,7 +64,6 @@ class Item_kits extends Secure_area implements iData_controller } $data_rows = get_item_kits_manage_table_data_rows($item_kits, $this); - $this->_remove_duplicate_cookies(); echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links)); } @@ -88,7 +86,6 @@ class Item_kits extends Secure_area implements iData_controller $item_kit = $this->add_totals_to_item_kit($this->Item_kit->get_info($item_kit_id)); echo (get_item_kit_data_row($item_kit, $this)); - $this->_remove_duplicate_cookies(); } function view($item_kit_id=-1) diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 9b4689cdb..b4a00bbc3 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -38,7 +38,6 @@ class Items extends Secure_area implements iData_controller $this->load->view('items/manage', $data); - $this->_remove_duplicate_cookies(); } function find_item_info() @@ -83,8 +82,7 @@ class Items extends Secure_area implements iData_controller $data_rows = get_items_manage_table_data_rows($items, $this); // do not move this line to be after the json_encode otherwise the searhc function won't work!! - $this->_remove_duplicate_cookies(); - + echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links)); } @@ -265,7 +263,6 @@ class Items extends Secure_area implements iData_controller echo $data_row; - $this->_remove_duplicate_cookies(); } function view($item_id=-1) diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 251664472..b7971d08b 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -225,7 +225,6 @@ class Receivings extends Secure_area $this->load->view("receivings/receipt",$data); $this->receiving_lib->clear_all(); } - $this->_remove_duplicate_cookies(); } private function _substitute_variable($text, $variable, $object, $function) @@ -320,7 +319,6 @@ class Receivings extends Secure_area $data['print_after_sale'] = FALSE; $this->load->view("receivings/receipt",$data); $this->receiving_lib->clear_all(); - $this->_remove_duplicate_cookies(); } private function _reload($data=array()) @@ -361,7 +359,6 @@ class Receivings extends Secure_area $data['invoice_number_enabled']=$this->receiving_lib->is_invoice_number_enabled(); $data['print_after_sale']=$this->receiving_lib->is_print_after_sale(); $this->load->view("receivings/receiving",$data); - $this->_remove_duplicate_cookies(); } function save($receiving_id) diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 31512b947..e59ac4e3a 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -65,7 +65,6 @@ class Sales extends Secure_area $this->load->view($data['controller_name'] . '/manage', $data); } - $this->_remove_duplicate_cookies(); } function get_row() @@ -120,8 +119,7 @@ class Sales extends Secure_area $payment_summary = get_sales_manage_payments_summary($payments, $sales, $this); // do not move this line to be after the json_encode otherwise the search function won't work!! - $this->_remove_duplicate_cookies(); - + echo json_encode(array('total_rows' => $total_rows, 'rows' => $sale_rows, 'pagination' => $links, 'payment_summary' => $payment_summary)); } @@ -211,11 +209,11 @@ class Sales extends Secure_area function add_payment() { $data = array(); - $this->form_validation->set_rules( 'amount_tendered', 'lang:sales_amount_tendered', 'trim|required|numeric' ); + $this->form_validation->set_rules('amount_tendered', 'lang:sales_amount_tendered', 'trim|required|numeric'); if ( $this->form_validation->run() == FALSE ) { - if ( $this->input->post( 'payment_type' ) == $this->lang->line( 'sales_gift_card' ) ) + if ( $this->input->post('payment_type') == $this->lang->line('sales_gift_card') ) { $data['error']=$this->lang->line('sales_must_enter_numeric_giftcard'); } @@ -229,34 +227,34 @@ class Sales extends Secure_area return; } - $payment_type = $this->input->post( 'payment_type' ); - if ( $payment_type == $this->lang->line( 'sales_giftcard' ) ) + $payment_type = $this->input->post('payment_type'); + if ( $payment_type == $this->lang->line('sales_giftcard') ) { $payments = $this->sale_lib->get_payments(); - $payment_type = $this->input->post( 'payment_type' ) . ':' . $payment_amount = $this->input->post( 'amount_tendered' ); - $current_payments_with_giftcard = isset( $payments[$payment_type] ) ? $payments[$payment_type]['payment_amount'] : 0; - $cur_giftcard_value = $this->Giftcard->get_giftcard_value( $this->input->post( 'amount_tendered' ) ) - $current_payments_with_giftcard; + $payment_type = $this->input->post('payment_type') . ':' . $payment_amount = $this->input->post('amount_tendered'); + $current_payments_with_giftcard = isset($payments[$payment_type]) ? $payments[$payment_type]['payment_amount'] : 0; + $cur_giftcard_value = $this->Giftcard->get_giftcard_value($this->input->post('amount_tendered')) - $current_payments_with_giftcard; if ( $cur_giftcard_value <= 0 ) { - $data['error'] = $this->lang->line('giftcards_remaining_balance', $this->input->post( 'amount_tendered' ), to_currency( $this->Giftcard->get_giftcard_value( $this->input->post( 'amount_tendered' )))); + $data['error'] = $this->lang->line('giftcards_remaining_balance', $this->input->post('amount_tendered'), to_currency( $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered')))); $this->_reload( $data ); return; } - $new_giftcard_value = $this->Giftcard->get_giftcard_value( $this->input->post( 'amount_tendered' ) ) - $this->sale_lib->get_amount_due( ); + $new_giftcard_value = $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) - $this->sale_lib->get_amount_due(); $new_giftcard_value = ( $new_giftcard_value >= 0 ) ? $new_giftcard_value : 0; $this->sale_lib->set_giftcard_remainder($new_giftcard_value); - $data['warning'] = $this->lang->line('giftcards_remaining_balance', $this->input->post( 'amount_tendered' ), to_currency( $new_giftcard_value, TRUE )); - $payment_amount = min( $this->sale_lib->get_amount_due( ), $this->Giftcard->get_giftcard_value( $this->input->post( 'amount_tendered' ) ) ); + $data['warning'] = $this->lang->line('giftcards_remaining_balance', $this->input->post('amount_tendered'), to_currency( $new_giftcard_value, TRUE )); + $payment_amount = min( $this->sale_lib->get_amount_due( ), $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) ); } else { - $payment_amount = $this->input->post( 'amount_tendered' ); + $payment_amount = $this->input->post('amount_tendered'); } if( !$this->sale_lib->add_payment( $payment_type, $payment_amount ) ) { - $data['error']='Unable to Add Payment! Please try again!'; + $data['error'] = 'Unable to Add Payment! Please try again!'; } $this->_reload($data); @@ -275,7 +273,7 @@ class Sales extends Secure_area $mode = $this->sale_lib->get_mode(); $item_id_or_number_or_item_kit_or_receipt = $this->input->post('item'); - $quantity = ($mode=="return") ? -1 : 1; + $quantity = ($mode == "return") ? -1 : 1; $item_location = $this->sale_lib->get_sale_location(); if($mode == 'return' && $this->sale_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt)) @@ -423,7 +421,7 @@ class Sales extends Secure_area $this->email->subject($this->lang->line('sales_receipt')); if ($this->config->item('use_invoice_template') && $this->sale_lib->is_invoice_number_enabled()) { - $data['image_prefix']=""; + $data['image_prefix'] = ""; $filename = $this->_invoice_email_pdf($data); $this->email->attach($filename); $text = $this->config->item('invoice_email_message'); @@ -434,7 +432,7 @@ class Sales extends Secure_area } else { - $this->email->message($this->load->view("sales/receipt_email",$data, true)); + $this->email->message($this->load->view("sales/receipt_email", $data, true)); } $this->email->send(); } @@ -452,7 +450,6 @@ class Sales extends Secure_area $this->sale_lib->clear_all(); } - $this->_remove_duplicate_cookies(); } private function _invoice_email_pdf($data) @@ -474,7 +471,6 @@ class Sales extends Secure_area $sale_data['image_prefix'] = base_url(); $this->load->view('sales/invoice_email', $sale_data); $this->sale_lib->clear_all(); - $this->_remove_duplicate_cookies(); } function send_invoice($sale_id) @@ -497,13 +493,8 @@ class Sales extends Secure_area $result = $this->email->send(); $message = $this->lang->line($result ? 'sales_invoice_sent' : 'sales_invoice_unsent') . ' ' . $sale_data["customer_email"]; } - echo json_encode(array( - 'success'=>$result, - 'message'=>$message, - 'id'=>$sale_id) - ); + echo json_encode(array('success'=>$result, 'message'=>$message, 'id'=>$sale_id)); $this->sale_lib->clear_all(); - $this->_remove_duplicate_cookies(); } private function _substitute_variable($text, $variable, $object, $function) @@ -521,16 +512,17 @@ class Sales extends Secure_area private function _substitute_customer($text, $cust_info) { // substitute customer info - $customer_id=$this->sale_lib->get_customer(); - if($customer_id!=-1 && $cust_info!='') + $customer_id = $this->sale_lib->get_customer(); + if($customer_id != -1 && $cust_info != '') { - $text=str_replace('$CU',$cust_info->first_name . ' ' . $cust_info->last_name,$text); + $text = str_replace('$CU',$cust_info->first_name . ' ' . $cust_info->last_name,$text); $words = preg_split("/\s+/", trim($cust_info->first_name . ' ' . $cust_info->last_name)); $acronym = ""; - foreach ($words as $w) { + foreach ($words as $w) + { $acronym .= $w[0]; } - $text=str_replace('$CI',$acronym,$text); + $text = str_replace('$CI',$acronym,$text); } return $text; @@ -538,11 +530,11 @@ class Sales extends Secure_area private function _substitute_variables($text, $cust_info) { - $text=$this->_substitute_variable($text, '$YCO', $this->Sale, 'get_invoice_number_for_year'); - $text=$this->_substitute_variable($text, '$CO', $this->Sale , 'get_invoice_count'); - $text=$this->_substitute_variable($text, '$SCO', $this->Sale_suspended, 'get_invoice_count'); - $text=strftime($text); - $text=$this->_substitute_customer($text, $cust_info); + $text = $this->_substitute_variable($text, '$YCO', $this->Sale, 'get_invoice_number_for_year'); + $text = $this->_substitute_variable($text, '$CO', $this->Sale , 'get_invoice_count'); + $text = $this->_substitute_variable($text, '$SCO', $this->Sale_suspended, 'get_invoice_count'); + $text = strftime($text); + $text = $this->_substitute_customer($text, $cust_info); return $text; } @@ -580,7 +572,7 @@ class Sales extends Secure_area $emp_info = $this->Employee->get_info($employee_id); $data['amount_change'] = $this->sale_lib->get_amount_due() * -1; $data['amount_due'] = $this->sale_lib->get_amount_due(); - $data['employee'] = $emp_info->first_name.' '.$emp_info->last_name; + $data['employee'] = $emp_info->first_name . ' ' . $emp_info->last_name; if($customer_id != -1) { @@ -625,7 +617,6 @@ class Sales extends Secure_area $data = $this->_load_sale_data($sale_id); $this->load->view("sales/receipt",$data); $this->sale_lib->clear_all(); - $this->_remove_duplicate_cookies(); } function invoice($sale_id, $sale_info='') @@ -637,7 +628,6 @@ class Sales extends Secure_area $this->load->view("sales/invoice", $sale_info); $this->sale_lib->clear_all(); - $this->_remove_duplicate_cookies(); } function edit($sale_id) @@ -661,13 +651,13 @@ class Sales extends Secure_area function delete($sale_id = -1, $update_inventory=TRUE) { - $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; - $sale_ids= $sale_id == -1 ? $this->input->post('ids') : array($sale_id); + $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; + $sale_ids = $sale_id == -1 ? $this->input->post('ids') : array($sale_id); if($this->Sale->delete_list($sale_ids, $employee_id, $update_inventory)) { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('sales_successfully_deleted').' '. - count($sale_ids).' '.$this->lang->line('sales_one_or_multiple'),'ids'=>$sale_ids)); + echo json_encode(array('success'=>true, 'message'=>$this->lang->line('sales_successfully_deleted').' '. + count($sale_ids).' '.$this->lang->line('sales_one_or_multiple'), 'ids'=>$sale_ids)); } else { @@ -689,7 +679,7 @@ class Sales extends Secure_area if ($this->Sale->update($sale_data, $sale_id)) { - echo json_encode(array('success'=>true, 'message'=>$this->lang->line('sales_successfully_updated'), 'id'=>$sale_id)); + echo json_encode(array('success'=>true, 'message'=>$this->lang->line('sales_successfully_updated'), 'id'=>$sale_id)); } else { @@ -750,7 +740,7 @@ class Sales extends Secure_area if($customer_id != -1) { $cust_info = $this->Customer->get_info($customer_id); - $data['customer'] = $cust_info->first_name.' '.$cust_info->last_name; + $data['customer'] = $cust_info->first_name . ' ' . $cust_info->last_name; $data['customer_email'] = $cust_info->email; } $data['invoice_number'] = $this->_substitute_invoice_number($cust_info); @@ -758,9 +748,8 @@ class Sales extends Secure_area $data['print_after_sale'] = $this->sale_lib->is_print_after_sale(); $data['payments_cover_total'] = $this->_payments_cover_total(); - $this->load->view("sales/register",$data); + $this->load->view("sales/register", $data); - $this->_remove_duplicate_cookies(); } function cancel_sale() @@ -776,7 +765,7 @@ class Sales extends Secure_area $data['taxes'] = $this->sale_lib->get_taxes(); $data['total'] = $this->sale_lib->get_total(); $data['receipt_title'] = $this->lang->line('sales_receipt'); - $data['transaction_time'] = date($this->config->item('dateformat').' '.$this->config->item('timeformat')); + $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat')); $customer_id = $this->sale_lib->get_customer(); $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; $comment = $this->sale_lib->get_comment(); @@ -810,7 +799,7 @@ class Sales extends Secure_area } //SAVE sale to database - $data['sale_id'] = 'POS '.$this->Sale_suspended->save($data['cart'], $customer_id, $employee_id, $comment, $invoice_number, $data['payments']); + $data['sale_id'] = 'POS ' . $this->Sale_suspended->save($data['cart'], $customer_id, $employee_id, $comment, $invoice_number, $data['payments']); if ($data['sale_id'] == 'POS -1') { $data['error_message'] = $this->lang->line('sales_transaction_failed'); diff --git a/application/controllers/Secure_area.php b/application/controllers/Secure_area.php index c02a172a8..6484655f3 100644 --- a/application/controllers/Secure_area.php +++ b/application/controllers/Secure_area.php @@ -61,57 +61,5 @@ class Secure_area extends CI_Controller return $this->pagination->create_links(); } - function _remove_duplicate_cookies () - { - //php < 5.3 doesn't have header remove so this function will fatal error otherwise - if (function_exists('header_remove')) - { - $CI = &get_instance(); - - // clean up all the cookies that are set... - $headers = headers_list(); - $cookies_to_output = array (); - $header_session_cookie = ''; - $session_cookie_name = $CI->config->item('sess_cookie_name'); - - foreach ($headers as $header) - { - list ($header_type, $data) = explode (':', $header, 2); - $header_type = trim ($header_type); - $data = trim ($data); - - if (strtolower ($header_type) == 'set-cookie') - { - header_remove ('Set-Cookie'); - - $cookie_value = current(explode (';', $data)); - list ($key, $val) = explode ('=', $cookie_value); - $key = trim ($key); - - if ($key == $session_cookie_name) - { - // OVERWRITE IT (yes! do it!) - $header_session_cookie = $data; - continue; - } - else - { - // Not a session related cookie, add it as normal. Might be a CSRF or some other cookie we are setting - $cookies_to_output[] = array ('header_type' => $header_type, 'data' => $data); - } - } - } - - if ( ! empty ($header_session_cookie)) - { - $cookies_to_output[] = array ('header_type' => 'Set-Cookie', 'data' => $header_session_cookie); - } - - foreach ($cookies_to_output as $cookie) - { - header ("{$cookie['header_type']}: {$cookie['data']}", false); - } - } - } } ?> \ No newline at end of file