diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index fa48b5a21..c3864e288 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -151,15 +151,23 @@ class Employees extends Persons //Password has been changed OR first time password set if($this->input->post('password') != '') { + $exploded = explode(":", $this->input->post('language')); $employee_data = array( - 'username' => $this->input->post('username'), - 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT), - 'hash_version' => 2 + 'username' => $this->input->post('username'), + 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT), + 'hash_version' => 2, + 'language_code' => $exploded[0], + 'language' => $exploded[1] ); } else //Password not changed { - $employee_data = array('username' => $this->input->post('username')); + $exploded = explode(":", $this->input->post('language')); + $employee_data = array( + 'username' => $this->input->post('username'), + 'language_code' => $exploded[0], + 'language' => $exploded[1] + ); } if($this->Employee->save_employee($person_data, $employee_data, $grants_array, $employee_id)) diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 62d278ea0..2c2d6d0b7 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -198,7 +198,6 @@ class Receivings extends Secure_Controller $data['cart'] = $this->receiving_lib->get_cart(); $data['total'] = $this->receiving_lib->get_total(); - $data['receipt_title'] = $this->lang->line('receivings_receipt'); $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat')); $data['mode'] = $this->receiving_lib->get_mode(); $data['comment'] = $this->receiving_lib->get_comment(); @@ -285,7 +284,6 @@ class Receivings extends Secure_Controller $data['cart'] = $this->receiving_lib->get_cart(); $data['total'] = $this->receiving_lib->get_total(); $data['mode'] = $this->receiving_lib->get_mode(); - $data['receipt_title'] = $this->lang->line('receivings_receipt'); $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($receiving_info['receiving_time'])); $data['show_stock_locations'] = $this->Stock_location->show_locations('receivings'); $data['payment_type'] = $receiving_info['payment_type']; diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 729b070fb..abbba0d47 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -504,7 +504,6 @@ class Sales extends Secure_Controller $data = array(); $data['dinner_table'] = $this->sale_lib->get_dinner_table(); $data['cart'] = $this->sale_lib->get_cart(); - $data['receipt_title'] = $this->lang->line('sales_receipt'); $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat')); $data['transaction_date'] = date($this->config->item('dateformat')); $data['show_stock_locations'] = $this->Stock_location->show_locations('sales'); @@ -882,7 +881,6 @@ class Sales extends Secure_Controller $data['taxes'] = $this->sale_lib->get_taxes(); $data['discount'] = $this->sale_lib->get_discount(); - $data['receipt_title'] = $this->lang->line('sales_receipt'); $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($sale_info['sale_time'])); $data['transaction_date'] = date($this->config->item('dateformat'), strtotime($sale_info['sale_time'])); $data['show_stock_locations'] = $this->Stock_location->show_locations('sales'); diff --git a/application/helpers/locale_helper.php b/application/helpers/locale_helper.php index 3e1d61693..33e36543a 100644 --- a/application/helpers/locale_helper.php +++ b/application/helpers/locale_helper.php @@ -4,14 +4,73 @@ * Currency locale helper */ -function current_language_code() +function current_language_code($load_system_language = FALSE) { - return get_instance()->config->item('language_code'); + // Returns the language code of the employee if set or system language code if not + if(get_instance()->Employee->is_logged_in() && $load_system_language != TRUE) + { + $employee_language_code = get_instance()->Employee->get_logged_in_employee_info()->language_code; + if($employee_language_code != NULL && $employee_language_code != '') + { + return $employee_language_code; + } + } + return get_instance()->config->item('language_code'); } -function current_language() +function current_language($load_system_language = FALSE) { - return get_instance()->config->item('language'); + // Returns the language of the employee if set or system language if not + if(get_instance()->Employee->is_logged_in() && $load_system_language != TRUE) + { + $employee_language = get_instance()->Employee->get_logged_in_employee_info()->language; + if($employee_language != NULL && $employee_language != '') + { + return $employee_language; + } + } + return get_instance()->config->item('language'); +} + +function get_languages() +{ + return array( + 'en-US:english' => 'English (United States)', + 'en-GB:english' => 'English (Great Britain)', + 'es:spanish' => 'Spanish', + 'nl-BE:dutch' => 'Dutch (Belgium)', + 'de:german' => 'German (Germany)', + 'de-CH:german' => 'German (Swiss)', + 'fr:french' => 'French', + 'zh:simplified-chinese' => 'Chinese', + 'id:indonesian' => 'Indonesian', + 'th:thai' => 'Thai', + 'tr:turkish' => 'Turkish', + 'ru:russian' => 'Russian', + 'hu-HU:hungarian' => 'Hungarian', + 'pt-BR:portuguese-brazilian' => 'Portuguese (Brazil)', + 'hr-HR' => 'Croatian (Croatia)', + 'ar-EG:arabic' => 'Arabic (Egypt)', + 'az-AZ:azerbaijani' => 'Azerbaijani (Azerbaijan)' + ); +} + +function load_language($load_system_language = FALSE, array $lang_array) +{ + if($load_system_language = TRUE) + { + foreach($lang_array as $language_file) + { + get_instance()->lang->load($language_file,current_language_code(TRUE)); + } + } + else + { + foreach($lang_array as $language_file) + { + get_instance()->lang->load($language_file,current_language_code()); + } + } } function currency_side() diff --git a/application/hooks/db_log.php b/application/hooks/db_log.php index 04459d5d7..2c6d21834 100644 --- a/application/hooks/db_log.php +++ b/application/hooks/db_log.php @@ -1,5 +1,8 @@ -db->query_times; - foreach ($CI->db->queries as $key => $query) + foreach($CI->db->queries as $key => $query) { // Generating SQL file alongwith execution time $sql = $query . " \n Execution Time:" . $times[$key]; @@ -26,4 +29,5 @@ function db_log_queries() fclose($handle); } } -?> \ No newline at end of file + +?> diff --git a/application/hooks/load_config.php b/application/hooks/load_config.php index e99bbdff9..d0585dbac 100644 --- a/application/hooks/load_config.php +++ b/application/hooks/load_config.php @@ -1,5 +1,8 @@ -config->set_item('language_code', 'en-US'); } - load_language_files('../vendor/codeigniter/framework/system/language', current_language()); - load_language_files('../application/language', current_language_code()); + _load_language_files($CI, '../vendor/codeigniter/framework/system/language', current_language()); + _load_language_files($CI, '../application/language', current_language_code()); } //Set timezone from config database @@ -37,13 +40,12 @@ function load_config() } /** - * @param $language * @param $CI + * @param $path + * @param $language */ -function load_language_files($path, $language) +function _load_language_files($CI, $path, $language) { - $CI =& get_instance(); - $map = directory_map($path . DIRECTORY_SEPARATOR . $language); foreach($map as $file) diff --git a/application/hooks/load_stats.php b/application/hooks/load_stats.php index e5c592a7d..feece32ba 100644 --- a/application/hooks/load_stats.php +++ b/application/hooks/load_stats.php @@ -1,4 +1,4 @@ - \ No newline at end of file +?> diff --git a/application/language/en-GB/employees_lang.php b/application/language/en-GB/employees_lang.php index 02577fd7b..ffe4719ac 100644 --- a/application/language/en-GB/employees_lang.php +++ b/application/language/en-GB/employees_lang.php @@ -10,6 +10,7 @@ $lang["employees_employee"] = "Employee"; $lang["employees_error_adding_updating"] = "Employee add or update failed"; $lang["employees_error_deleting_demo_admin"] = "You cannot delete the demo admin user"; $lang["employees_error_updating_demo_admin"] = "You cannot change the demo admin user"; +$lang["employees_language"] = "Language"; $lang["employees_login_info"] = "Login"; $lang["employees_new"] = "New Employee"; $lang["employees_none_selected"] = "You have not selected any Employee(s) to delete"; @@ -27,6 +28,7 @@ $lang["employees_successful_adding"] = "Employee add successful"; $lang["employees_successful_change_password"] = "Password change successful"; $lang["employees_successful_deleted"] = "You have successfully deleted Employee"; $lang["employees_successful_updating"] = "You have successfully updated Employee"; +$lang["employees_system_language"] = "System Language"; $lang["employees_unsuccessful_change_password"] = "Password change failed"; $lang["employees_update"] = "Update Employee"; $lang["employees_username"] = "Username"; diff --git a/application/language/en-US/employees_lang.php b/application/language/en-US/employees_lang.php index 67f685b97..5576db5f5 100644 --- a/application/language/en-US/employees_lang.php +++ b/application/language/en-US/employees_lang.php @@ -10,6 +10,7 @@ $lang["employees_employee"] = "Employee"; $lang["employees_error_adding_updating"] = "Employee add or update failed."; $lang["employees_error_deleting_demo_admin"] = "You can not delete the demo admin user."; $lang["employees_error_updating_demo_admin"] = "You can not change the demo admin user."; +$lang["employees_language"] = "Language"; $lang["employees_login_info"] = "Login"; $lang["employees_new"] = "New Employee"; $lang["employees_none_selected"] = "You have not selected any employee(s) to delete."; @@ -27,6 +28,7 @@ $lang["employees_successful_adding"] = "Employee add successful."; $lang["employees_successful_change_password"] = "Password change successful."; $lang["employees_successful_deleted"] = "You have successfully deleted"; $lang["employees_successful_updating"] = "You have successfully updated employee"; +$lang["employees_system_language"] = "System Language"; $lang["employees_unsuccessful_change_password"] = "Password change failed."; $lang["employees_update"] = "Update Employee"; $lang["employees_username"] = "Username"; diff --git a/application/views/configs/locale_config.php b/application/views/configs/locale_config.php index 585d3ec72..29850ae00 100644 --- a/application/views/configs/locale_config.php +++ b/application/views/configs/locale_config.php @@ -141,26 +141,12 @@
lang->line('config_language'), 'language', array('class' => 'control-label col-xs-2')); ?>
- 'American English', - 'en-GB:english' => 'British English', - 'es:spanish' => 'Spanish', - 'nl-BE:dutch' => 'Dutch (Belgium)', - 'de:german' => 'German (Germany)', - 'de-CH:german' => 'German (Swiss)', - 'fr:french' => 'French', - 'zh:simplified-chinese' => 'Chinese', - 'id:indonesian' => 'Indonesian', - 'th:thai' => 'Thai', - 'tr:turkish' => 'Turkish', - 'ru:russian' => 'Russian', - 'hu-HU:hungarian' => 'Hungarian', - 'pt-BR:portuguese-brazilian' => 'Portuguese (Brazil)', - 'hr-HR' => 'Croatian (Croatia)', - 'ar-EG:arabic' => 'Arabic (Egypt)', - 'az-AZ:azerbaijani' => 'Azerbaijani (Azerbaijan)' - ), - current_language_code() . ':' . current_language(), array('class' => 'form-control input-sm')); + 'form-control input-sm') + ); ?>
diff --git a/application/views/employees/form.php b/application/views/employees/form.php index a6a208eb9..7f1950ae5 100644 --- a/application/views/employees/form.php +++ b/application/views/employees/form.php @@ -68,6 +68,34 @@ + +
+ lang->line('employees_language'), 'language', array('class' => 'control-label col-xs-3')); ?> +
+
+ lang->line('employees_system_language'); + $language_code = current_language_code(); + $language = current_language(); + + // If No language is set then it will display "System Language" + if($language_code === current_language_code(TRUE)) + { + $language_code = ''; + $language = ''; + } + + echo form_dropdown( + 'language', + $languages, + $language_code . ':' . $language, + array('class' => 'form-control input-sm') + ); + ?> +
+
+
@@ -154,7 +182,7 @@ $(document).ready(function() $that.prop("disabled", !checked); !checked && $that.prop("checked", false); } - $this.change(function() { + $this.change(function() { updateCheckboxes($this.is(":checked")); }); updateCheckboxes($this.is(":checked")); @@ -231,4 +259,4 @@ $(document).ready(function() } }, form_support.error)); }); - \ No newline at end of file + diff --git a/application/views/receivings/receipt.php b/application/views/receivings/receipt.php index 46a07dc39..378fa7594 100644 --- a/application/views/receivings/receipt.php +++ b/application/views/receivings/receipt.php @@ -1,14 +1,17 @@ load->view("partial/header"); ?> ".$error_message.""; - exit; -} -?> + if (isset($error_message)) + { + echo "
".$error_message."
"; + exit; + } -load->view('partial/print_receipt', array('print_after_sale', $print_after_sale, 'selected_printer'=>'receipt_printer')); ?> + $this->load->view('partial/print_receipt', array('print_after_sale', $print_after_sale, 'selected_printer'=>'receipt_printer')); + + // Temporarily loads the system language for _lang to print invoice in the system language rather than user defined. + load_language(TRUE,array('common','receivings','suppliers','employees','items','sales')); +?> @@ -139,5 +142,4 @@ if (isset($error_message)) - load->view("partial/footer"); ?> diff --git a/application/views/sales/invoice.php b/application/views/sales/invoice.php index c7443d6b8..978d60f42 100755 --- a/application/views/sales/invoice.php +++ b/application/views/sales/invoice.php @@ -43,6 +43,11 @@ $(document).ready(function()  ' . $this->lang->line('sales_takings'), array('class'=>'btn btn-info btn-sm', 'id'=>'show_takings_button')); ?> + +
diff --git a/application/views/sales/invoice_email.php b/application/views/sales/invoice_email.php index 13db2411d..b1328ba4e 100644 --- a/application/views/sales/invoice_email.php +++ b/application/views/sales/invoice_email.php @@ -7,11 +7,14 @@ ".$error_message."
"; - exit; -} + if(isset($error_message)) + { + echo "
".$error_message."
"; + exit; + } + + // Temporarily loads the system language for _lang to print invoice in the system language rather than user defined. + load_language(TRUE,array('sales','common')); ?>
diff --git a/application/views/sales/quote.php b/application/views/sales/quote.php index 427ec4b95..282f81933 100644 --- a/application/views/sales/quote.php +++ b/application/views/sales/quote.php @@ -31,7 +31,12 @@ if (isset($error_message)) -load->view('partial/print_receipt', array('print_after_sale'=>$print_after_sale, 'selected_printer'=>'invoice_printer')); ?> +load->view('partial/print_receipt', array('print_after_sale'=>$print_after_sale, 'selected_printer'=>'invoice_printer')); + + // Temporarily loads the system language for _lang to print invoice in the system language rather than user defined. + load_language(TRUE,array('sales','common')); +?> "; - exit; -} + if (isset($error_message)) + { + echo "
".$error_message."
"; + exit; + } + + // Temporarily loads the system language for _lang to print invoice in the system language rather than user defined. + load_language(TRUE,array('sales','common')); ?>
diff --git a/application/views/sales/receipt_default.php b/application/views/sales/receipt_default.php index d27311bbe..52bb692f5 100644 --- a/application/views/sales/receipt_default.php +++ b/application/views/sales/receipt_default.php @@ -1,3 +1,8 @@ + +
config->item('address')); ?>
config->item('phone'); ?>
-
+
lang->line('sales_receipt'); ?>
diff --git a/application/views/sales/receipt_email.php b/application/views/sales/receipt_email.php index 5bd1b5453..080760809 100644 --- a/application/views/sales/receipt_email.php +++ b/application/views/sales/receipt_email.php @@ -1,3 +1,8 @@ + +
config->item('address')); ?>
config->item('phone'); ?>

-
+
lang->line('sales_receipt'); ?>
diff --git a/application/views/sales/receipt_short.php b/application/views/sales/receipt_short.php index 2dbd827ac..f0168366a 100644 --- a/application/views/sales/receipt_short.php +++ b/application/views/sales/receipt_short.php @@ -1,3 +1,8 @@ + +
config->item('address')); ?>
config->item('phone'); ?>
-
+
lang->line('sales_receipt'); ?>
diff --git a/database/3.1.1_to_3.2.0.sql b/database/3.1.1_to_3.2.0.sql index cb0bce55c..fdbb27ba7 100644 --- a/database/3.1.1_to_3.2.0.sql +++ b/database/3.1.1_to_3.2.0.sql @@ -66,3 +66,10 @@ INSERT INTO `ospos_permissions` (`permission_id`, `module_id`) VALUES INSERT INTO `ospos_grants` (`permission_id`, `person_id`, `menu_group`) VALUES ('sales_delete', 1, '--'); + + +-- Add columns to save per-user language selection + +ALTER TABLE `ospos_employees` + ADD COLUMN `language` VARCHAR(48) DEFAULT NULL, + ADD COLUMN `language_code` VARCHAR(8) DEFAULT NULL; diff --git a/database/database.sql b/database/database.sql index 13dab3e87..e1b042b6f 100644 --- a/database/database.sql +++ b/database/database.sql @@ -156,6 +156,8 @@ CREATE TABLE `ospos_employees` ( `person_id` int(10) NOT NULL, `deleted` int(1) NOT NULL DEFAULT '0', `hash_version` int(1) NOT NULL DEFAULT '2', + `language` VARCHAR(48) DEFAULT NULL, + `language_code` VARCHAR(8) DEFAULT NULL, UNIQUE KEY `username` (`username`), KEY `person_id` (`person_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/database/migrate_phppos_dist.sql b/database/migrate_phppos_dist.sql index f13cffe1a..f12db0ca2 100644 --- a/database/migrate_phppos_dist.sql +++ b/database/migrate_phppos_dist.sql @@ -156,6 +156,8 @@ CREATE TABLE `ospos_employees` ( `person_id` int(10) NOT NULL, `deleted` int(1) NOT NULL DEFAULT '0', `hash_version` int(1) NOT NULL DEFAULT '2', + `language` VARCHAR(48) DEFAULT NULL, + `language_code` VARCHAR(8) DEFAULT NULL, UNIQUE KEY `username` (`username`), KEY `person_id` (`person_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/database/tables.sql b/database/tables.sql index bbf4c6e37..58c70eba5 100644 --- a/database/tables.sql +++ b/database/tables.sql @@ -156,6 +156,8 @@ CREATE TABLE `ospos_employees` ( `person_id` int(10) NOT NULL, `deleted` int(1) NOT NULL DEFAULT '0', `hash_version` int(1) NOT NULL DEFAULT '2', + `language` VARCHAR(48) DEFAULT NULL, + `language_code` VARCHAR(8) DEFAULT NULL, UNIQUE KEY `username` (`username`), KEY `person_id` (`person_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;