From 77da39e33eb70b8b01502c09e8057dd199554de6 Mon Sep 17 00:00:00 2001 From: anuko Date: Sat, 13 Jan 2018 20:27:38 +0000 Subject: [PATCH] More refactoring. --- WEB-INF/lib/form/ActionForm.class.php | 2 +- WEB-INF/lib/form/Calendar.class.php | 3 ++- WEB-INF/lib/form/CheckboxGroup.class.php | 7 ++++--- WEB-INF/lib/form/DateField.class.php | 13 +++++-------- WEB-INF/lib/form/FloatField.class.php | 5 ++++- WEB-INF/lib/form/Form.class.php | 4 ++-- WEB-INF/lib/form/FormElement.class.php | 4 ++-- WEB-INF/lib/ttImportHelper.class.php | 8 +++++--- WEB-INF/lib/ttInvoiceHelper.class.php | 1 - WEB-INF/templates/footer.tpl | 2 +- initialize.php | 1 - mobile/user_add.php | 1 - mobile/user_edit.php | 1 - user_add.php | 1 - user_edit.php | 2 +- 15 files changed, 27 insertions(+), 28 deletions(-) diff --git a/WEB-INF/lib/form/ActionForm.class.php b/WEB-INF/lib/form/ActionForm.class.php index ece7ceb9..97c9219c 100644 --- a/WEB-INF/lib/form/ActionForm.class.php +++ b/WEB-INF/lib/form/ActionForm.class.php @@ -176,7 +176,7 @@ class ActionForm { import('form.'.$ref_el["class"]); $class_name = $ref_el["class"]; $el = new $class_name($ref_el["name"]); - if (isset($GLOBALS["I18N"])) $el->localize($GLOBALS["I18N"]); + $el->localize(); $el->setValueSafe(@$_SESSION[$this->mSessionCell . "_" .$el->getName()]); if ($this->mForm && !isset($this->mForm->elements[$ref_el["name"]])) { diff --git a/WEB-INF/lib/form/Calendar.class.php b/WEB-INF/lib/form/Calendar.class.php index ab2dcf57..1340c987 100644 --- a/WEB-INF/lib/form/Calendar.class.php +++ b/WEB-INF/lib/form/Calendar.class.php @@ -57,8 +57,9 @@ class Calendar extends FormElement { $this->highlight = $highlight; } - function localize($i18n) { + function localize() { global $user; + global $i18n; $this->mMonthNames = $i18n->monthNames; $this->mWeekDayShortNames = $i18n->weekdayShortNames; diff --git a/WEB-INF/lib/form/CheckboxGroup.class.php b/WEB-INF/lib/form/CheckboxGroup.class.php index 0bb3ac42..810c9631 100644 --- a/WEB-INF/lib/form/CheckboxGroup.class.php +++ b/WEB-INF/lib/form/CheckboxGroup.class.php @@ -58,9 +58,10 @@ class CheckboxGroup extends FormElement { function setGroupIn($value) { $this->mGroupIn = $value; if ($this->mGroupIn<1) $this->mGroupIn = 1;} function getGroupIn() { return $this->mGroupIn; } - function localize($i18n) { - $this->lSelAll = $i18n->getKey('label.select_all'); - $this->lSelNone = $i18n->getKey('label.select_none'); + function localize() { + global $i18n; + $this->lSelAll = $i18n->getKey('label.select_all'); + $this->lSelNone = $i18n->getKey('label.select_none'); } function getHtml() { diff --git a/WEB-INF/lib/form/DateField.class.php b/WEB-INF/lib/form/DateField.class.php index ecfdaf92..f8eef8cb 100644 --- a/WEB-INF/lib/form/DateField.class.php +++ b/WEB-INF/lib/form/DateField.class.php @@ -41,14 +41,12 @@ class DateField extends TextField { $this->class = 'DateField'; $this->name = $name; $this->mDateObj = new DateAndTime(); - - if (isset($GLOBALS["I18N"])) { - $this->localize($GLOBALS["I18N"]); - } + $this->localize(); } - function localize($i18n) { + function localize() { global $user; + global $i18n; $this->mDateObj->setFormat($user->date_format); @@ -80,6 +78,7 @@ class DateField extends TextField { } function getHtml() { + global $user; if (!$this->isEnabled()) { $html = htmlspecialchars($this->getValue()). @@ -296,9 +295,7 @@ class DateField extends TextField { function getDateString(dateVal) {\n"; - if (isset($GLOBALS['i18n'])) { - $html .= "dateVal.locale = \"".$GLOBALS['i18n']->lang."\";\n"; - } + $html .= "dateVal.locale = \"".$user->lang."\";\n"; $html .= "return dateVal.strftime(dateFormat); } diff --git a/WEB-INF/lib/form/FloatField.class.php b/WEB-INF/lib/form/FloatField.class.php index b11f4a11..cb035c7c 100644 --- a/WEB-INF/lib/form/FloatField.class.php +++ b/WEB-INF/lib/form/FloatField.class.php @@ -33,11 +33,14 @@ class FloatField extends TextField { var $mFFormat; function __construct($name) { + global $user; + $this->class = 'FloatField'; $this->name = $name; + $this->mDelimiter = $user->decimal_mark; } - function localize($i18n) { + function localize() { global $user; $this->mDelimiter = $user->decimal_mark; } diff --git a/WEB-INF/lib/form/Form.class.php b/WEB-INF/lib/form/Form.class.php index cf7890c6..5a4baa9b 100644 --- a/WEB-INF/lib/form/Form.class.php +++ b/WEB-INF/lib/form/Form.class.php @@ -135,7 +135,7 @@ class Form { if ($el!=null) { $el->setFormName($this->name); if (isset($params["id"])) $el->setId($params["id"]); - if (isset($GLOBALS["I18N"])) $el->localize($GLOBALS["I18N"]); + $el->localize(); if (isset($params["enable"])) $el->setEnabled($params["enable"]); if (isset($params["style"])) $el->setStyle($params["style"]); @@ -153,7 +153,7 @@ class Form { function addInputElement(&$el) { if ($el && is_object($el)) { - if (isset($GLOBALS["I18N"])) $el->localize($GLOBALS["I18N"]); + $el->localize(); $el->setFormName($this->name); $this->elements[$el->name] = &$el; diff --git a/WEB-INF/lib/form/FormElement.class.php b/WEB-INF/lib/form/FormElement.class.php index ff7b3b28..0443e6c9 100644 --- a/WEB-INF/lib/form/FormElement.class.php +++ b/WEB-INF/lib/form/FormElement.class.php @@ -84,8 +84,8 @@ class FormElement { function setOnChange($str) { $this->on_change = $str; } function setOnClick($str) { $this->on_click = $str; } - function localize($i18n) {} // Localization occurs in derived classes and is dependent on control type. - // For example, in calendar control we need to localize day and month names. + function localize() {} // Localization occurs in derived classes and is dependent on control type. + // For example, in calendar control we need to localize day and month names. // getHtml returns HTML for the element. function getHtml() { return ''; } diff --git a/WEB-INF/lib/ttImportHelper.class.php b/WEB-INF/lib/ttImportHelper.class.php index f7be431f..5e2d40a5 100644 --- a/WEB-INF/lib/ttImportHelper.class.php +++ b/WEB-INF/lib/ttImportHelper.class.php @@ -329,6 +329,8 @@ class ttImportHelper { // startElement, endElement, and dataElement functions are called as many times as necessary. // Actual import occurs in the endElement handler. function importXml() { + global $i18n; + // Do we have a compressed file? $compressed = false; $file_ext = substr($_FILES['xmlfile']['name'], strrpos($_FILES['xmlfile']['name'], '.') + 1); @@ -343,13 +345,13 @@ class ttImportHelper { // If the file is compressed - uncompress it. if ($compressed) { if (!$this->uncompress($_FILES['xmlfile']['tmp_name'], $filename)) { - $this->errors->add($GLOBALS['I18N']->getKey('error.sys')); + $this->errors->add($i18n->getKey('error.sys')); return; } unlink($_FILES['xmlfile']['tmp_name']); } else { if (!move_uploaded_file($_FILES['xmlfile']['tmp_name'], $filename)) { - $this->errors->add($GLOBALS['I18N']->getKey('error.upload')); + $this->errors->add($i18n->getKey('error.upload')); return; } } @@ -369,7 +371,7 @@ class ttImportHelper { xml_get_current_line_number($parser))); } if (!$this->canImport) { - $this->errors->add($GLOBALS['I18N']->getKey('error.user_exists')); + $this->errors->add($i18n->getKey('error.user_exists')); break; } } diff --git a/WEB-INF/lib/ttInvoiceHelper.class.php b/WEB-INF/lib/ttInvoiceHelper.class.php index b7d2cc28..2784a7b9 100644 --- a/WEB-INF/lib/ttInvoiceHelper.class.php +++ b/WEB-INF/lib/ttInvoiceHelper.class.php @@ -99,7 +99,6 @@ class ttInvoiceHelper { // The getInvoiceItems retrieves tt_log items associated with the invoice. static function getInvoiceItems($invoice_id) { global $user; - global $i18n; $mdb2 = getConnection(); // At this time only detailed invoice is supported. diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index d0675018..1279cfa3 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.13.15.3745 | Copyright © Anuko | +  Anuko Time Tracker 1.13.15.3746 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/initialize.php b/initialize.php index 29425c07..689925d3 100644 --- a/initialize.php +++ b/initialize.php @@ -197,7 +197,6 @@ if (!$lang) { // Load i18n file. $i18n->load($lang); -$GLOBALS['I18N'] = &$i18n; // Assign things for smarty to use in template files. $smarty->assign('i18n', $i18n->keys); diff --git a/mobile/user_add.php b/mobile/user_add.php index c1f7e291..24adc112 100644 --- a/mobile/user_add.php +++ b/mobile/user_add.php @@ -107,7 +107,6 @@ class RateCellRenderer extends DefaultCellRenderer { global $assigned_projects; $field = new FloatField('rate_'.$table->getValueAtName($row, 'id')); $field->setFormName($table->getFormName()); - $field->localize($GLOBALS['I18N']); $field->setSize(5); $field->setFormat('.2'); foreach ($assigned_projects as $p) { diff --git a/mobile/user_edit.php b/mobile/user_edit.php index 204e7137..e8a116ff 100644 --- a/mobile/user_edit.php +++ b/mobile/user_edit.php @@ -137,7 +137,6 @@ class RateCellRenderer extends DefaultCellRenderer { global $assigned_projects; $field = new FloatField('rate_'.$table->getValueAtName($row,'id')); $field->setFormName($table->getFormName()); - $field->localize($GLOBALS['I18N']); $field->setSize(5); $field->setFormat('.2'); foreach ($assigned_projects as $p) { diff --git a/user_add.php b/user_add.php index 3c919056..b8b5d302 100644 --- a/user_add.php +++ b/user_add.php @@ -107,7 +107,6 @@ class RateCellRenderer extends DefaultCellRenderer { global $assigned_projects; $field = new FloatField('rate_'.$table->getValueAtName($row, 'id')); $field->setFormName($table->getFormName()); - $field->localize($GLOBALS['I18N']); $field->setSize(5); $field->setFormat('.2'); foreach ($assigned_projects as $p) { diff --git a/user_edit.php b/user_edit.php index c8608773..d7a3feb5 100644 --- a/user_edit.php +++ b/user_edit.php @@ -135,9 +135,9 @@ class NameCellRenderer extends DefaultCellRenderer { class RateCellRenderer extends DefaultCellRenderer { function render(&$table, $value, $row, $column, $selected = false) { global $assigned_projects; + $field = new FloatField('rate_'.$table->getValueAtName($row,'id')); $field->setFormName($table->getFormName()); - $field->localize($GLOBALS['I18N']); $field->setSize(5); $field->setFormat('.2'); foreach ($assigned_projects as $p) { -- 2.20.1