|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* The MIT License (MIT) |
|
6
|
|
|
* |
|
7
|
|
|
* Copyright (c) 2016 Daniel Popiniuc |
|
8
|
|
|
* |
|
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
11
|
|
|
* in the Software without restriction, including without limitation the rights |
|
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
14
|
|
|
* furnished to do so, subject to the following conditions: |
|
15
|
|
|
* |
|
16
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
17
|
|
|
* copies or substantial portions of the Software. |
|
18
|
|
|
* |
|
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
25
|
|
|
* SOFTWARE. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
namespace danielgp\salariu; |
|
30
|
|
|
|
|
31
|
|
|
trait BasicSalariu |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
use \danielgp\common_lib\CommonCode; |
|
35
|
|
|
|
|
36
|
|
|
protected $appFlags; |
|
37
|
|
|
protected $tApp = null; |
|
38
|
|
|
|
|
39
|
|
|
private function handleLocalizationSalariu($appSettings) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->handleLocalizationSalariuInputsIntoSession($appSettings); |
|
42
|
|
|
$this->handleLocalizationSalariuSafe($appSettings); |
|
43
|
|
|
$localizationFile = 'Salariu/locale/' . $this->tCmnSession->get('lang') . '/LC_MESSAGES/salariu.mo'; |
|
44
|
|
|
$translations = new \Gettext\Translations; |
|
45
|
|
|
$translations->addFromMoFile($localizationFile); |
|
46
|
|
|
$this->tApp = new \Gettext\Translator(); |
|
47
|
|
|
$this->tApp->loadTranslations($translations); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function handleLocalizationSalariuInputsIntoSession($appSettings) |
|
51
|
|
|
{ |
|
52
|
|
|
if (is_null($this->tCmnSuperGlobals->get('lang')) && is_null($this->tCmnSession->get('lang'))) { |
|
53
|
|
|
$this->tCmnSession->set('lang', $appSettings['Default Language']); |
|
54
|
|
|
} elseif (!is_null($this->tCmnSuperGlobals->get('lang'))) { |
|
55
|
|
|
$this->tCmnSession->set('lang', filter_var($this->tCmnSuperGlobals->get('lang'), FILTER_SANITIZE_STRING)); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* To avoid potential language injections from other applications that do not applies here |
|
61
|
|
|
* |
|
62
|
|
|
* @param type $appSettings |
|
63
|
|
|
*/ |
|
64
|
|
|
private function handleLocalizationSalariuSafe($appSettings) |
|
65
|
|
|
{ |
|
66
|
|
|
if (!array_key_exists($this->tCmnSession->get('lang'), $appSettings['Available Languages'])) { |
|
67
|
|
|
$this->tCmnSession->set('lang', $appSettings['Default Language']); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
private function processFormInputDefaults($inDefaultValues) |
|
72
|
|
|
{ |
|
73
|
|
|
if (is_null($this->tCmnSuperGlobals->get('ym'))) { |
|
74
|
|
|
$this->tCmnSuperGlobals->request->set('ym', mktime(0, 0, 0, date('m'), 1, date('Y'))); |
|
75
|
|
|
} |
|
76
|
|
|
foreach ($inDefaultValues as $key => $value) { |
|
77
|
|
|
if (is_null($this->tCmnSuperGlobals->get($key))) { |
|
78
|
|
|
$this->tCmnSuperGlobals->request->set($key, $value); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
private function setFooterHtml($appSettings) |
|
84
|
|
|
{ |
|
85
|
|
|
$sReturn = $this->setUpperRightBoxLanguages($appSettings['Available Languages']) |
|
86
|
|
|
. '<div class="resetOnly author">© ' . date('Y') . ' ' |
|
87
|
|
|
. $appSettings['Copyright Holder'] . '</div>' |
|
88
|
|
|
. '<hr/>' |
|
89
|
|
|
. '<div class="disclaimer">' |
|
90
|
|
|
. $this->tApp->gettext('i18n_Disclaimer') |
|
91
|
|
|
. '</div>'; |
|
92
|
|
|
return $this->setFooterCommon($sReturn); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
private function setHeaderHtml() |
|
96
|
|
|
{ |
|
97
|
|
|
$headerParameters = [ |
|
98
|
|
|
'lang' => str_replace('_', '-', $this->tCmnSession->get('lang')), |
|
99
|
|
|
'title' => $this->tApp->gettext('i18n_ApplicationName'), |
|
100
|
|
|
'css' => [ |
|
101
|
|
|
'vendor/components/flag-icon-css/css/flag-icon.min.css', |
|
102
|
|
|
'Salariu/css/salariu.css', |
|
103
|
|
|
], |
|
104
|
|
|
]; |
|
105
|
|
|
return $this->setHeaderCommon($headerParameters) |
|
106
|
|
|
. '<h1>' . $this->tApp->gettext('i18n_ApplicationName') . '</h1>'; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
private function setLabel($labelId) |
|
110
|
|
|
{ |
|
111
|
|
|
$labelInfo = $this->appFlags['FI'][$labelId]['Label']; |
|
112
|
|
|
$sReturn = ''; |
|
113
|
|
|
if (is_array($labelInfo)) { |
|
114
|
|
|
if (count($labelInfo) == 3) { |
|
115
|
|
|
$pieces = [ |
|
116
|
|
|
$this->tApp->gettext($labelInfo[0]), |
|
117
|
|
|
$this->tApp->gettext($labelInfo[1]), |
|
118
|
|
|
]; |
|
119
|
|
|
$sReturn = sprintf($pieces[0], $pieces[1], $labelInfo[2]); |
|
120
|
|
|
} |
|
121
|
|
|
} elseif (is_string($labelInfo)) { |
|
122
|
|
|
$sReturn = $this->tApp->gettext($labelInfo); |
|
123
|
|
|
} |
|
124
|
|
|
return $this->setLabelSuffix($sReturn); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
private function setLabelSuffix($text) |
|
128
|
|
|
{ |
|
129
|
|
|
$suffix = ''; |
|
130
|
|
|
if (!in_array($text, ['', ' ']) && (strpos($text, '<input') === false) && (substr($text, -1) !== '!')) { |
|
131
|
|
|
$suffix = ':'; |
|
132
|
|
|
} |
|
133
|
|
|
return $text . $suffix; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: