Individual languages

This commit is contained in:
FrancescoUK
2017-09-11 21:02:41 +01:00
parent 3a8b28fcb6
commit 1fd6f5fb70
23 changed files with 204 additions and 71 deletions

View File

@@ -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))

View File

@@ -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'];

View File

@@ -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');

View File

@@ -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()

View File

@@ -1,5 +1,8 @@
<?php
// Name of function same as mentioned in Hooks Config
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Name of function same as mentioned in Hooks Config
*/
function db_log_queries()
{
$CI = & get_instance();
@@ -14,7 +17,7 @@ function db_log_queries()
// Get execution time of all the queries executed by controller
$times = $CI->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);
}
}
?>
?>

View File

@@ -1,5 +1,8 @@
<?php
//Loads configuration from database into global CI config
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Loads configuration from database into global CI config
*/
function load_config()
{
$CI =& get_instance();
@@ -19,8 +22,8 @@ function load_config()
$CI->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)

View File

@@ -1,4 +1,4 @@
<?php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function load_stats()
{
@@ -55,4 +55,4 @@ function load_stats()
}
}
?>
?>

View File

@@ -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";

View File

@@ -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";

View File

@@ -141,26 +141,12 @@
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_language'), 'language', array('class' => 'control-label col-xs-2')); ?>
<div class='col-xs-4'>
<?php echo form_dropdown('language', array(
'en-US:english' => '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'));
<?php echo form_dropdown(
'language',
get_languages(),
current_language_code(TRUE) . ':' . current_language(TRUE),
array('class' => 'form-control input-sm')
);
?>
</div>
</div>

View File

@@ -68,6 +68,34 @@
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('employees_language'), 'language', array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-8'>
<div class="input-group">
<?php
$languages = get_languages();
$languages[':'] = $this->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')
);
?>
</div>
</div>
</div>
</fieldset>
</div>
@@ -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));
});
</script>
</script>

View File

@@ -1,14 +1,17 @@
<?php $this->load->view("partial/header"); ?>
<?php
if (isset($error_message))
{
echo "<div class='alert alert-dismissible alert-danger'>".$error_message."</div>";
exit;
}
?>
if (isset($error_message))
{
echo "<div class='alert alert-dismissible alert-danger'>".$error_message."</div>";
exit;
}
<?php $this->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'));
?>
<div class="print_hide" id="control_buttons" style="text-align:right">
<a href="javascript:printdoc();"><div class="btn btn-info btn-sm", id="show_print_button"><?php echo '<span class="glyphicon glyphicon-print">&nbsp</span>' . $this->lang->line('common_print'); ?></div></a>
@@ -37,7 +40,7 @@ if (isset($error_message))
<div id="company_address"><?php echo nl2br($this->config->item('address')); ?></div>
<div id="company_phone"><?php echo $this->config->item('phone'); ?></div>
<div id="sale_receipt"><?php echo $receipt_title; ?></div>
<div id="sale_receipt"><?php echo $this->lang->line('receivings_receipt'); ?></div>
<div id="sale_time"><?php echo $transaction_time ?></div>
</div>
@@ -139,5 +142,4 @@ if (isset($error_message))
<?php echo $receiving_id; ?>
</div>
</div>
<?php $this->load->view("partial/footer"); ?>

View File

@@ -43,6 +43,11 @@ $(document).ready(function()
<?php echo anchor("sales/manage", '<span class="glyphicon glyphicon-list-alt">&nbsp</span>' . $this->lang->line('sales_takings'), array('class'=>'btn btn-info btn-sm', 'id'=>'show_takings_button')); ?>
</div>
<?php
// Temporarily loads the system language for _lang to print invoice in the system language rather than user defined.
load_language(TRUE,array('sales','common'));
?>
<div id="page-wrap">
<div id="header"><?php echo $this->lang->line('sales_invoice'); ?></div>
<div id="block1">

View File

@@ -7,11 +7,14 @@
<body>
<?php
if(isset($error_message))
{
echo "<div class='alert alert-dismissible alert-danger'>".$error_message."</div>";
exit;
}
if(isset($error_message))
{
echo "<div class='alert alert-dismissible alert-danger'>".$error_message."</div>";
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'));
?>
<div id="page-wrap">

View File

@@ -31,7 +31,12 @@ if (isset($error_message))
</script>
<?php endif; ?>
<?php $this->load->view('partial/print_receipt', array('print_after_sale'=>$print_after_sale, 'selected_printer'=>'invoice_printer')); ?>
<?php
$this->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'));
?>
<div class="print_hide" id="control_buttons" style="text-align:right">
<a href="javascript:printdoc();"><div class="btn btn-info btn-sm", id="show_print_button"><?php echo '<span class="glyphicon glyphicon-print">&nbsp</span>' . $this->lang->line('common_print'); ?></div></a>

View File

@@ -7,11 +7,14 @@
<body>
<?php
if (isset($error_message))
{
echo "<div class='alert alert-dismissible alert-danger'>".$error_message."</div>";
exit;
}
if (isset($error_message))
{
echo "<div class='alert alert-dismissible alert-danger'>".$error_message."</div>";
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'));
?>
<div id="page-wrap">

View File

@@ -1,3 +1,8 @@
<?php
// Temporarily loads the system language for to print receipt in the system language rather than user defined.
load_language(TRUE,array('customers','sales','employees'));
?>
<div id="receipt_wrapper" style="font-size:<?php echo $this->config->item('receipt_font_size');?>px">
<div id="receipt_header">
<?php
@@ -22,7 +27,7 @@
<div id="company_address"><?php echo nl2br($this->config->item('address')); ?></div>
<div id="company_phone"><?php echo $this->config->item('phone'); ?></div>
<div id="sale_receipt"><?php echo $receipt_title; ?></div>
<div id="sale_receipt"><?php echo $this->lang->line('sales_receipt'); ?></div>
<div id="sale_time"><?php echo $transaction_time ?></div>
</div>

View File

@@ -1,3 +1,8 @@
<?php
// Temporarily loads the system language for _lang to print invoice in the system language rather than user defined.
load_language(TRUE,array('customers','sales','employees'));
?>
<div id="receipt_wrapper" style="width:100%;">
<div id="receipt_header" style="text-align:center;">
<?php
@@ -23,7 +28,7 @@
<div id="company_address"><?php echo nl2br($this->config->item('address')); ?></div>
<div id="company_phone"><?php echo $this->config->item('phone'); ?></div>
<br>
<div id="sale_receipt"><?php echo $receipt_title; ?></div>
<div id="sale_receipt"><?php echo $this->lang->line('sales_receipt'); ?></div>
<div id="sale_time"><?php echo $transaction_time ?></div>
</div>

View File

@@ -1,3 +1,8 @@
<?php
// Temporarily loads the system language for _lang to print invoice in the system language rather than user defined.
load_language(TRUE,array('customers','sales','employees'));
?>
<div id="receipt_wrapper" style="font-size:<?php echo $this->config->item('receipt_font_size');?>px">
<div id="receipt_header">
<?php
@@ -22,7 +27,7 @@
<div id="company_address"><?php echo nl2br($this->config->item('address')); ?></div>
<div id="company_phone"><?php echo $this->config->item('phone'); ?></div>
<div id="sale_receipt"><?php echo $receipt_title; ?></div>
<div id="sale_receipt"><?php echo $this->lang->line('sales_receipt'); ?></div>
<div id="sale_time"><?php echo $transaction_time ?></div>
</div>

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;