1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* The MIT License (MIT) |
6
|
|
|
* |
7
|
|
|
* Copyright (c) 2015 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\common_lib; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* DOM component functions |
33
|
|
|
* |
34
|
|
|
* @author Daniel Popiniuc |
35
|
|
|
*/ |
36
|
|
|
trait DomComponentsByDanielGP |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
use DomCssAndJavascriptByDanielGP, |
40
|
|
|
DomDynamicSelectByDanielGP; |
41
|
|
|
|
42
|
|
|
private function normalizeArrayForUrl($featArray) |
43
|
|
|
{ |
44
|
|
|
foreach ($featArray as $key => $value) { |
45
|
|
|
if (is_numeric($key)) { |
46
|
|
|
$featArray[$value] = 1; |
47
|
|
|
unset($featArray[$key]); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
return $featArray; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Builds a <select> based on a given array |
55
|
|
|
* |
56
|
|
|
* @version 20080618 |
57
|
|
|
* @param array $aElements |
58
|
|
|
* @param string/array $sDefaultValue |
|
|
|
|
59
|
|
|
* @param string $selectName |
60
|
|
|
* @param array $featArray |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
protected function setArrayToSelect($aElements, $sDefaultValue, $selectName, $featArray = null) |
64
|
|
|
{ |
65
|
|
|
if (!is_array($aElements)) { |
66
|
|
|
return ''; |
67
|
|
|
} |
68
|
|
|
if (isset($featArray['readonly'])) { |
69
|
|
|
return $this->setStringIntoShortTag('input', [ |
70
|
|
|
'name' => $selectName, |
71
|
|
|
'id' => $this->buildSelectId($selectName, $featArray), |
72
|
|
|
'readonly' => 'readonly', |
73
|
|
|
'class' => 'input_readonly', |
74
|
|
|
'value' => $sDefaultValue, |
75
|
|
|
]) . $aElements[$sDefaultValue]; |
76
|
|
|
} |
77
|
|
|
return $this->setArrayToSelectNotReadOnly($aElements, $sDefaultValue, $selectName, $featArray); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Converts an array to string |
82
|
|
|
* |
83
|
|
|
* @param string $sSeparator |
84
|
|
|
* @param array $aElements |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
protected function setArrayToStringForUrl($sSeparator, $aElements, $aExceptedElements = ['']) |
88
|
|
|
{ |
89
|
|
|
$outArray = $this->normalizeArrayForUrl($aElements); |
90
|
|
|
$xptArray = $this->normalizeArrayForUrl($aExceptedElements); |
91
|
|
|
$finalArray = array_diff_key($outArray, $xptArray); |
92
|
|
|
return http_build_query($finalArray, '', $sSeparator); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns a table from an query |
97
|
|
|
* |
98
|
|
|
* @param array $gArray |
|
|
|
|
99
|
|
|
* @param array $features |
|
|
|
|
100
|
|
|
* @param boolean $bKeepFullPage |
|
|
|
|
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
protected function setArrayToTable($aElements, $ftrs = null, $bKpFlPge = true) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$rows = count($aElements); |
106
|
|
|
if ($rows == 0) { |
107
|
|
|
$divTab = [ |
108
|
|
|
'start' => '', |
109
|
|
|
'end' => '', |
110
|
|
|
]; |
111
|
|
|
if (array_key_exists('showGroupingCounter', $ftrs)) { |
112
|
|
|
if (array_key_exists('grouping_cell_type', $ftrs) && ($ftrs['grouping_cell_type'] == 'tab')) { |
113
|
|
|
$ditTitle = 'No data found'; |
114
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
115
|
|
|
$ditTitle .= ' (0)'; |
116
|
|
|
} |
117
|
|
|
$divTab = [ |
118
|
|
|
'start' => '<div class="tabbertab tabbertabdefault" id="tab_NoData" title="' . $ditTitle . '">', |
119
|
|
|
'end' => '</div><!-- from tab_NoData -->', |
120
|
|
|
]; |
121
|
|
|
if (!isset($ftrs['noGlobalTab'])) { |
122
|
|
|
$divTab = [ |
123
|
|
|
'start' => '<div class="tabber" id="tab">' . $divTab['start'], |
124
|
|
|
'end' => $divTab['end'] . '</div><!-- from global Tab -->', |
125
|
|
|
]; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
return $divTab['start'] |
130
|
|
|
. $this->setFeedbackModern('error', 'Error', $this->lclMsgCmn('i18n_NoData')) |
131
|
|
|
. $divTab['end']; |
132
|
|
|
} |
133
|
|
|
if (isset($ftrs['limits'])) { |
134
|
|
|
$ftrs['limits'][1] = min($ftrs['limits'][1], $ftrs['limits'][2]); |
135
|
|
|
if ($ftrs['limits'][2] > $ftrs['limits'][1]) { |
136
|
|
|
$iStartingPageRecord = 1; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
$sReturn = ''; |
140
|
|
|
if (isset($ftrs['hidden_columns'])) { |
141
|
|
|
$hdClmns = $this->setArrayValuesAsKey($ftrs['hidden_columns']); |
|
|
|
|
142
|
|
|
} else { |
143
|
|
|
$hdClmns = ['']; |
144
|
|
|
} |
145
|
|
|
if ((isset($ftrs['actions']['checkbox_inlineEdit'])) || (isset($ftrs['actions']['checkbox']))) { |
146
|
|
|
$checkboxFormId = 'frm' . date('YmdHis'); |
147
|
|
|
$sReturn .= '<form id="' . $checkboxFormId . '" ' . 'name="' . $checkboxFormId |
148
|
|
|
. '" method="post" ' . ' action="' . $_SERVER['PHP_SELF'] . '" >'; |
149
|
|
|
} |
150
|
|
|
$tbl['Def'] = '<table' |
|
|
|
|
151
|
|
|
. (isset($ftrs['table_style']) ? ' style="' . $ftrs['table_style'] . '"' : '') |
152
|
|
|
. (isset($ftrs['table_class']) ? ' class="' . $ftrs['table_class'] . '"' : '') |
153
|
|
|
. '>'; |
154
|
|
|
if (!isset($ftrs['grouping_cell_type'])) { |
155
|
|
|
$ftrs['grouping_cell_type'] = 'row'; |
156
|
|
|
} |
157
|
|
|
switch ($ftrs['grouping_cell_type']) { |
158
|
|
|
case 'row': |
159
|
|
|
$sReturn .= $tbl['Def']; |
160
|
|
|
break; |
161
|
|
|
case 'tab': |
162
|
|
|
if (!isset($ftrs['noGlobalTab'])) { |
163
|
|
|
$sReturn .= '<div class="tabber" id="tab">'; |
164
|
|
|
} |
165
|
|
|
break; |
166
|
|
|
} |
167
|
|
|
$iTableColumns = 0; |
168
|
|
|
$remebered_value = -1; |
169
|
|
|
$remindGroupValue = null; |
170
|
|
|
$color_no = null; |
171
|
|
|
if (!isset($ftrs['headers_breaked'])) { |
172
|
|
|
$ftrs['headers_breaked'] = true; |
173
|
|
|
} |
174
|
|
|
for ($rCntr = 0; $rCntr < $rows; $rCntr++) { |
175
|
|
|
if ($rCntr == 0) { |
176
|
|
|
$header = array_diff_key($aElements[$rCntr], $hdClmns); |
177
|
|
|
$iTableColumns = count($header); |
178
|
|
|
if (isset($ftrs['computed_columns'])) { |
179
|
|
|
$iTableColumns += count($ftrs['computed_columns']); |
180
|
|
|
} |
181
|
|
|
if (isset($ftrs['actions'])) { |
182
|
|
|
$iTableColumns += 1; |
183
|
|
|
} |
184
|
|
|
if (isset($ftrs['grouping_cell'])) { |
185
|
|
|
$iTableColumns -= 1; |
186
|
|
|
} |
187
|
|
|
$tbl['Head'] = '<thead>'; |
188
|
|
|
if ($ftrs['grouping_cell_type'] == 'row') { |
189
|
|
|
$sReturn .= $tbl['Head']; |
190
|
|
|
} |
191
|
|
View Code Duplication |
if (isset($iStartingPageRecord)) { |
|
|
|
|
192
|
|
|
$pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2], $bKpFlPge); |
|
|
|
|
193
|
|
|
$sReturn .= $this->setStringIntoTag($this->setStringIntoTag($pgn, 'th', [ |
194
|
|
|
'colspan' => $iTableColumns |
195
|
|
|
]), 'tr'); |
196
|
|
|
} |
197
|
|
|
$tbl['Header'] = '<tr>'; |
198
|
|
|
if (isset($ftrs['grouping_cell'])) { // Grouping columns |
199
|
|
|
$header = array_diff_key($header, [$ftrs['grouping_cell'] => '']); |
200
|
|
|
} |
201
|
|
|
if (isset($ftrs['actions'])) { // Action column |
202
|
|
|
$tbl['Header'] .= '<th> </th>'; |
203
|
|
|
} |
204
|
|
|
if (isset($ftrs['RowStyle'])) { //Exclude style columns from displaying |
205
|
|
|
$tmpClmns = $this->setArrayValuesAsKey([$ftrs['RowStyle']]); |
|
|
|
|
206
|
|
|
$header = array_diff_key($header, $tmpClmns); |
207
|
|
|
$hdClmns = array_merge($hdClmns, $tmpClmns); |
208
|
|
|
unset($tmpClmns); |
209
|
|
|
} |
210
|
|
|
$tbl['Header'] .= $this->setTableHeader($header, $ftrs['headers_breaked']); // Regular columns |
211
|
|
|
if (isset($ftrs['computed_columns'])) { // Computed columns |
212
|
|
|
$tbl['Header'] .= $this->setTableHeader($ftrs['computed_columns'], $ftrs['headers_breaked']); |
213
|
|
|
} |
214
|
|
|
$tbl['Header'] .= '</tr></thead><tbody>'; |
215
|
|
|
if ($ftrs['grouping_cell_type'] == 'row') { |
216
|
|
|
$sReturn .= $tbl['Header']; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
$row_current = array_diff_key($aElements[$rCntr], $hdClmns); |
220
|
|
|
if (isset($ftrs['row_colored_alternated'])) { |
221
|
|
|
if ($ftrs['row_colored_alternated'][0] == '#') { |
222
|
|
|
$color_column_value = $rCntr; |
223
|
|
|
} else { |
224
|
|
|
$color_column_value = $row_current[$ftrs['row_colored_alternated'][0]]; |
225
|
|
|
} |
226
|
|
|
if ($remebered_value != $color_column_value) { |
227
|
|
|
if (isset($color_no)) { |
228
|
|
|
$color_no = 1; |
229
|
|
|
} else { |
230
|
|
|
$color_no = 2; |
231
|
|
|
} |
232
|
|
|
$remebered_value = $color_column_value; |
233
|
|
|
} |
234
|
|
|
$color = ' style="background-color: ' . $ftrs['row_colored_alternated'][$color_no] . ';"'; |
235
|
|
|
} else { |
236
|
|
|
if (isset($ftrs['RowStyle'])) { |
237
|
|
|
$color = ' style="' . $aElements[$rCntr][$ftrs['RowStyle']] . '"'; |
238
|
|
|
} else { |
239
|
|
|
$color = ''; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
$tbl['tr_Color'] = '<tr' . $color . '>'; |
243
|
|
|
// Grouping column |
244
|
|
|
if (isset($ftrs['grouping_cell'])) { |
245
|
|
|
foreach ($aElements[$rCntr] as $key => $value) { |
246
|
|
|
if (($ftrs['grouping_cell'] == $key) && ($remindGroupValue != $value)) { |
247
|
|
|
switch ($ftrs['grouping_cell_type']) { |
248
|
|
|
case 'row': |
249
|
|
|
$sReturn .= $tbl['tr_Color'] . '<td ' . 'colspan="' . $iTableColumns . '">' |
250
|
|
|
. $this->setStringIntoTag($value, 'div', ['class' => 'rowGroup rounded']) |
251
|
|
|
. '</td></tr>'; |
252
|
|
|
break; |
253
|
|
|
case 'tab': |
254
|
|
|
if (is_null($remindGroupValue)) { |
255
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
256
|
|
|
$groupCounter = 0; |
257
|
|
|
} |
258
|
|
|
} else { |
259
|
|
|
$sReturn .= '</tbody></table>'; |
260
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
261
|
|
|
$sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
|
|
|
|
262
|
|
|
$groupCounter = 0; |
263
|
|
|
} |
264
|
|
|
$sReturn .= '</div>'; |
265
|
|
|
} |
266
|
|
|
$sReturn .= '<div class="tabbertab'; |
267
|
|
|
if (isset($ftrs['grouping_default_tab'])) { |
268
|
|
|
$sReturn .= ($ftrs['grouping_default_tab'] == $value ? ' tabbertabdefault' : ''); |
269
|
|
|
} |
270
|
|
|
$sReturn .= '" id="tab_' . $this->cleanStringForId($value) . '" ' |
271
|
|
|
. 'title="' . $value . '">' |
272
|
|
|
. $tbl['Def'] . $tbl['Head'] . $tbl['Header']; |
273
|
|
|
break; |
274
|
|
|
} |
275
|
|
|
$remindGroupValue = $value; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
if (isset($ftrs['grouping_cell'])) { |
280
|
|
|
if ($ftrs['grouping_cell_type'] == 'tab') { |
281
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
282
|
|
|
$groupCounter++; |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
$sReturn .= $tbl['tr_Color']; |
287
|
|
|
// Action column |
288
|
|
|
if (isset($ftrs['actions'])) { |
289
|
|
|
$sReturn .= '<td style="white-space:nowrap;">'; |
290
|
|
|
$action_argument = 0; |
291
|
|
|
if (isset($ftrs['actions']['key'])) { |
292
|
|
|
$action_key = $ftrs['actions']['key']; |
293
|
|
|
} else { |
294
|
|
|
$action_key = 'view'; |
295
|
|
|
} |
296
|
|
|
if (isset($ftrs['action_prefix'])) { |
297
|
|
|
$actPrfx = $ftrs['action_prefix'] . '&'; |
298
|
|
|
$action_key = 'view2'; |
299
|
|
|
} else { |
300
|
|
|
$actPrfx = ''; |
301
|
|
|
} |
302
|
|
|
foreach ($ftrs['actions'] as $key => $value) { |
303
|
|
|
if ($action_argument != 0) { |
304
|
|
|
$sReturn .= ' '; |
305
|
|
|
} |
306
|
|
|
switch ($key) { |
307
|
|
|
case 'checkbox': |
308
|
|
|
$checkboxName = $value . '[]'; |
309
|
|
|
$checkboxNameS = $value; |
310
|
|
|
$sReturn .= ' <input type="checkbox" name="' . $checkboxName |
311
|
|
|
. '" id="n' . $aElements[$rCntr][$value] |
312
|
|
|
. '" value="' . $aElements[$rCntr][$value] . '" '; |
313
|
|
|
if (isset($_REQUEST[$checkboxNameS])) { |
314
|
|
|
if (is_array($_REQUEST[$checkboxNameS])) { |
315
|
|
|
if (in_array($aElements[$rCntr][$value], $_REQUEST[$checkboxNameS])) { |
316
|
|
|
$sReturn .= 'checked="checked" '; |
317
|
|
|
} |
318
|
|
|
} else { |
319
|
|
|
if ($aElements[$rCntr][$value] == $_REQUEST[$checkboxNameS]) { |
320
|
|
|
$sReturn .= 'checked="checked" '; |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
if (strpos($_REQUEST['view'], 'multiEdit') !== false) { |
325
|
|
|
$sReturn .= 'disabled="disabled" '; |
326
|
|
|
} |
327
|
|
|
$sReturn .= '/>'; |
328
|
|
|
break; |
329
|
|
|
case 'checkbox_inlineEdit': |
330
|
|
|
$checkboxName = $value . '[]'; |
331
|
|
|
$checkboxNameS = $value; |
332
|
|
|
$sReturn .= ' <input type="checkbox" name="' . $checkboxName |
333
|
|
|
. '" id="n' . $aElements[$rCntr][$value] . '" value="' |
334
|
|
|
. $aElements[$rCntr][$value] . '"/>'; |
335
|
|
|
break; |
336
|
|
|
case 'edit': |
337
|
|
|
$edt = ''; |
338
|
|
|
if (isset($ftrs['NoAjaxEditing'])) { |
339
|
|
|
$edt .= $_SERVER['PHP_SELF'] . '?' . $actPrfx |
340
|
|
|
. $action_key . '=' . $value[0] . '&'; |
341
|
|
|
$iActArgs = count($value[1]); |
342
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
343
|
|
|
$edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
344
|
|
|
} |
345
|
|
|
$sReturn .= '<a href="' . $edt . '"><i class="fa fa-pencil"> </i></a>'; |
346
|
|
View Code Duplication |
} else { |
|
|
|
|
347
|
|
|
$edt .= 'javascript:loadAE(\'' . $_SERVER['PHP_SELF'] . '?' |
348
|
|
|
. $actPrfx . $action_key . '=' . $value[0] . '&'; |
349
|
|
|
$iActArgs = count($value[1]); |
350
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
351
|
|
|
$edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
352
|
|
|
} |
353
|
|
|
$edt .= '\');'; |
354
|
|
|
$sReturn .= '<a href="#" onclick="' . $edt . '">' |
355
|
|
|
. '<i class="fa fa-pencil"> </i></a>'; |
356
|
|
|
} |
357
|
|
|
break; |
358
|
|
|
case 'list2': |
359
|
|
|
$edt = ''; |
360
|
|
|
if (isset($ftrs['NoAjaxEditing'])) { |
361
|
|
|
$sReturn .= '<a href="?' . $actPrfx . $action_key . '=' . $value[0] . '&'; |
362
|
|
|
$iActArgs = count($value[1]); |
363
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
364
|
|
|
$sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
365
|
|
|
} |
366
|
|
|
$sReturn .= '"><i class="fa fa-list"> </i></a>'; |
367
|
|
View Code Duplication |
} else { |
|
|
|
|
368
|
|
|
$edt .= 'javascript:loadAE(\'' . $_SERVER['PHP_SELF'] . '?' |
369
|
|
|
. $actPrfx . $action_key . '=' . $value[0] . '&'; |
370
|
|
|
$iActArgs = count($value[1]); |
371
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
372
|
|
|
$edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
373
|
|
|
} |
374
|
|
|
$edt .= '\');'; |
375
|
|
|
$sReturn .= '<a href="#" onclick="' . $edt . '">' |
376
|
|
|
. '<i class="fa fa-list"> </i></a>'; |
377
|
|
|
} |
378
|
|
|
break; |
379
|
|
|
case 'delete': |
380
|
|
|
$sReturn .= '<a href="javascript:setQuest(\'' . $value[0] . '\',\''; |
381
|
|
|
$iActArgs = count($value[1]); |
382
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
383
|
|
|
$sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
384
|
|
|
} |
385
|
|
|
$sReturn .= '\');"><i class="fa fa-times"> </i></a>'; |
386
|
|
|
break; |
387
|
|
|
} |
388
|
|
|
$action_argument += 1; |
389
|
|
|
} |
390
|
|
|
$sReturn .= '</td>'; |
391
|
|
|
} |
392
|
|
|
// Regular columns |
393
|
|
|
$sReturn .= $this->setTableCell($row_current, $ftrs); |
394
|
|
|
// Computed columns |
395
|
|
|
if (isset($ftrs['computed_columns'])) { |
396
|
|
|
foreach ($ftrs['computed_columns'] as $key => $value) { |
397
|
|
|
if ($value[0] == '%') { |
398
|
|
|
$dec = $value[2] + 2; |
399
|
|
|
} else { |
400
|
|
|
$dec = $value[2]; |
401
|
|
|
} |
402
|
|
|
switch ($value[1]) { |
403
|
|
|
case '/': |
404
|
|
|
// next variable is only to avoid a long line |
405
|
|
|
$shorter = [ |
406
|
|
|
$aElements[$rCntr][$value[3]], |
407
|
|
|
$aElements[$rCntr][$value[4]], |
408
|
|
|
]; |
409
|
|
|
$aElements[$rCntr][$key] = $this->setDividedResult($shorter[0], $shorter[1], $dec); |
|
|
|
|
410
|
|
|
break; |
411
|
|
|
case '+': |
412
|
|
|
// next variable is only to avoid a long line |
413
|
|
|
$iTemp = $this->setArrayValuesAsKey([ |
|
|
|
|
414
|
|
|
$value[0], |
415
|
|
|
$value[1], |
416
|
|
|
$value[2] |
417
|
|
|
]); |
418
|
|
|
$aTemp = array_diff($value, $iTemp); |
419
|
|
|
$aElements[$rCntr][$key] = 0; |
420
|
|
|
foreach ($aTemp as $sValue) { |
421
|
|
|
$aElements[$rCntr][$key] += $aElements[$rCntr][$sValue]; |
422
|
|
|
} |
423
|
|
|
break; |
424
|
|
|
default: |
425
|
|
|
$row_computed[$key] = ''; |
|
|
|
|
426
|
|
|
break; |
427
|
|
|
} |
428
|
|
|
if ($value[0] == '%') { |
429
|
|
|
$row_computed[$key] = ($aElements[$rCntr][$key] * 100); |
|
|
|
|
430
|
|
|
$dec -= 2; |
431
|
|
|
} else { |
432
|
|
|
$row_computed[$key] = $aElements[$rCntr][$key]; |
433
|
|
|
} |
434
|
|
|
$decimals[$key] = $dec; |
|
|
|
|
435
|
|
|
} |
436
|
|
|
// displaying them |
437
|
|
|
$sReturn .= $this->setTableCell($row_computed, ['decimals' => $decimals]); |
|
|
|
|
438
|
|
|
} |
439
|
|
|
$sReturn .= '</tr>'; |
440
|
|
|
} |
441
|
|
View Code Duplication |
if (isset($iStartingPageRecord)) { |
|
|
|
|
442
|
|
|
$pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2]); |
|
|
|
|
443
|
|
|
$sReturn .= '<tr>' . $this->setStringIntoTag($pgn, 'th', ['colspan' => $iTableColumns]) . '</tr>'; |
444
|
|
|
} |
445
|
|
|
$sReturn .= '</tbody></table>'; |
446
|
|
|
if ($ftrs['grouping_cell_type'] == 'tab') { |
447
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
448
|
|
|
$sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
449
|
|
|
} |
450
|
|
|
$sReturn .= '</div><!-- from ' . $remindGroupValue . ' -->'; |
451
|
|
|
if (!isset($ftrs['noGlobalTab'])) { |
452
|
|
|
$sReturn .= '</div><!-- from global tab -->'; |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
if (isset($ftrs['actions']['checkbox'])) { |
456
|
|
|
if (strpos($_REQUEST['view'], 'multiEdit') === false) { |
457
|
|
|
$sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
|
|
|
|
458
|
|
|
. '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
|
|
|
|
459
|
|
|
. '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
460
|
|
|
. '\',\'' . $checkboxName . '\',false);">Uncheck All</a> ' |
461
|
|
|
. '<input type="hidden" name="action" value="multiEdit_' . $checkboxNameS . '" />'; |
|
|
|
|
462
|
|
View Code Duplication |
if (isset($ftrs['hiddenInput'])) { |
|
|
|
|
463
|
|
|
if (is_array($ftrs['hiddenInput'])) { |
464
|
|
|
foreach ($ftrs['hiddenInput'] as $valueF) { |
465
|
|
|
$sReturn .= '<input type="hidden" name="' . $valueF |
466
|
|
|
. '" value="' . $_REQUEST[$valueF] . '" />'; |
467
|
|
|
} |
468
|
|
|
} else { |
469
|
|
|
$sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
470
|
|
|
. '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
471
|
|
|
} |
472
|
|
|
} |
473
|
|
|
$sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" ' . 'value="Edit selected" />'; |
474
|
|
|
} |
475
|
|
|
$sReturn .= '</form>'; |
476
|
|
|
} |
477
|
|
|
if (isset($ftrs['actions']['checkbox_inlineEdit'])) { |
478
|
|
|
$sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
479
|
|
|
. '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
480
|
|
|
. '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
481
|
|
|
. '\',\'' . $checkboxName . '\',false);">Uncheck All</a> '; |
482
|
|
|
if (isset($ftrs['visibleInput'])) { |
483
|
|
|
$sReturn .= $ftrs['visibleInput']; |
484
|
|
|
} |
485
|
|
|
$sReturn .= '<input type="hidden" name="view" value="save_' . $checkboxNameS . '" />'; |
486
|
|
View Code Duplication |
if (isset($ftrs['hiddenInput'])) { |
|
|
|
|
487
|
|
|
if (is_array($ftrs['hiddenInput'])) { |
488
|
|
|
foreach ($ftrs['hiddenInput'] as $valueF) { |
489
|
|
|
$sReturn .= '<input type="hidden" name="' . $valueF |
490
|
|
|
. '" value="' . $_REQUEST[$valueF] . '" />'; |
491
|
|
|
} |
492
|
|
|
} else { |
493
|
|
|
$sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
494
|
|
|
. '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
495
|
|
|
} |
496
|
|
|
} |
497
|
|
|
$sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" value="Store the modification" />'; |
498
|
|
|
$sReturn .= '</form>'; |
499
|
|
|
} |
500
|
|
|
return $sReturn; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* Set a control to a user-friendly calendar |
505
|
|
|
* |
506
|
|
|
* @param string $controlName |
507
|
|
|
* @param string $additionalStyle |
508
|
|
|
* @return string |
509
|
|
|
*/ |
510
|
|
View Code Duplication |
public function setCalendarControl($controlName, $additionalStyle = '') |
|
|
|
|
511
|
|
|
{ |
512
|
|
|
return $this->setStringIntoTag(' ', 'span', [ |
513
|
|
|
'onclick' => implode('', [ |
514
|
|
|
'javascript:NewCssCal(\'' . $controlName, |
515
|
|
|
'\',\'yyyyMMdd\',\'dropdown\',false,\'24\',false);', |
516
|
|
|
]), |
517
|
|
|
'class' => 'fa fa-calendar', |
518
|
|
|
'id' => $controlName . '_picker', |
519
|
|
|
'style' => 'cursor:pointer;' . $additionalStyle, |
520
|
|
|
]); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* Set a control to a user-friendly calendar with time included |
525
|
|
|
* |
526
|
|
|
* @param string $controlName |
527
|
|
|
* @param string $additionalStyle |
528
|
|
|
* @return string |
529
|
|
|
*/ |
530
|
|
View Code Duplication |
public function setCalendarControlWithTime($controlName, $additionalStyle = '') |
|
|
|
|
531
|
|
|
{ |
532
|
|
|
return $this->setStringIntoTag(' ', 'span', [ |
533
|
|
|
'onclick' => implode('', [ |
534
|
|
|
'javascript:NewCssCal(\'' . $controlName, |
535
|
|
|
'\',\'yyyyMMdd\',\'dropdown\',true,\'24\',true);', |
536
|
|
|
]), |
537
|
|
|
'class' => 'fa fa-calendar', |
538
|
|
|
'id' => $controlName . '_picker', |
539
|
|
|
'style' => 'cursor:pointer;' . $additionalStyle, |
540
|
|
|
]); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* Builds a structured modern message |
545
|
|
|
* |
546
|
|
|
* @param string $sType |
547
|
|
|
* @param string $sTitle |
548
|
|
|
* @param string $sMsg |
549
|
|
|
* @param boolean $skipBr |
550
|
|
|
*/ |
551
|
|
|
protected function setFeedbackModern($sType, $sTitle, $sMsg, $skipBr = false) |
552
|
|
|
{ |
553
|
|
|
if ($sTitle == 'light') { |
554
|
|
|
return $sMsg; |
555
|
|
|
} |
556
|
|
|
$stl = $this->setFeedbackModernStyles($sType); |
557
|
|
|
$legend = $this->setStringIntoTag($sTitle, 'legend', ['style' => $stl['Ttl']]); |
558
|
|
|
return implode('', [ |
559
|
|
|
($skipBr ? '' : '<br/>'), |
560
|
|
|
$this->setStringIntoTag($legend . $sMsg, 'fieldset', ['style' => $stl['Msg']]), |
561
|
|
|
]); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
private function setFeedbackModernStyles($sType) |
565
|
|
|
{ |
566
|
|
|
$formatTitle = 'margin-top:-5px;margin-right:20px;padding:5px;'; |
567
|
|
|
$formatMessage = 'display:inline;padding-right:5px;padding-bottom:5px;'; |
568
|
|
|
$styleByType = [ |
569
|
|
|
'alert' => [ |
570
|
|
|
'border:medium solid orange;background-color:orange;color:navy;', |
571
|
|
|
'background-color:navy;color:orange;border:medium solid orange;', |
572
|
|
|
], |
573
|
|
|
'check' => [ |
574
|
|
|
'border:medium solid green;background-color:green;color:white;', |
575
|
|
|
'background-color:yellow;color:green;border:medium solid green;', |
576
|
|
|
], |
577
|
|
|
'error' => [ |
578
|
|
|
'border:medium solid red;background-color:red;color:white;', |
579
|
|
|
'background-color:yellow;color:red;border:medium solid red;', |
580
|
|
|
], |
581
|
|
|
'info' => [ |
582
|
|
|
'border:medium solid black;background-color:black;color:white;font-weight:bold;', |
583
|
|
|
'background-color: white; color: black;border:medium solid black;', |
584
|
|
|
], |
585
|
|
|
]; |
586
|
|
|
return ['Ttl' => $formatTitle . $styleByType[$sType], 'Msg' => $formatMessage . $styleByType[$sType]]; |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
/** |
590
|
|
|
* Outputs an HTML footer |
591
|
|
|
* |
592
|
|
|
* @param array $footerInjected |
593
|
|
|
* @return string |
594
|
|
|
*/ |
595
|
|
|
protected function setFooterCommon($footerInjected = null) |
|
|
|
|
596
|
|
|
{ |
597
|
|
|
if (isset($_REQUEST['specialHook']) && (in_array('noFooter', $_REQUEST['specialHook']))) { |
598
|
|
|
return ''; |
599
|
|
|
} |
600
|
|
|
return $this->setFooterCommonInjected($footerInjected) . '</body></html>'; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
protected function setFooterCommonInjected($footerInjected = null) |
604
|
|
|
{ |
605
|
|
|
$sReturn = ''; |
606
|
|
|
if (!is_null($footerInjected)) { |
607
|
|
|
$sReturn = $footerInjected; |
608
|
|
|
if (is_array($footerInjected)) { |
609
|
|
|
$sReturn = implode('', $footerInjected); |
610
|
|
|
} |
611
|
|
|
} |
612
|
|
|
return $sReturn; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
/** |
616
|
|
|
* Outputs an HTML header |
617
|
|
|
* |
618
|
|
|
* @param array $headerFeatures |
619
|
|
|
* @return string |
620
|
|
|
*/ |
621
|
|
|
protected function setHeaderCommon($headerFeatures = null) |
|
|
|
|
622
|
|
|
{ |
623
|
|
|
$sReturn = []; |
624
|
|
|
if (isset($_REQUEST['specialHook']) && (in_array('noHeader', $_REQUEST['specialHook']))) { |
625
|
|
|
$sReturn[] = ''; // no Header |
626
|
|
|
} else { |
627
|
|
|
$fixedHeaderElements = [ |
628
|
|
|
'start' => '<!DOCTYPE html>', |
629
|
|
|
'lang' => '<html lang="en-US">', |
630
|
|
|
'head' => '<head>', |
631
|
|
|
'charset' => '<meta charset="utf-8" />', |
632
|
|
|
'viewport' => '<meta name="viewport" content="' . implode(', ', [ |
633
|
|
|
'width=device-width', |
634
|
|
|
'height=device-height', |
635
|
|
|
'initial-scale=1', |
636
|
|
|
]) . '" />', |
637
|
|
|
]; |
638
|
|
|
if (!is_null($headerFeatures)) { |
639
|
|
|
if (is_array($headerFeatures)) { |
640
|
|
|
$aFeatures = []; |
641
|
|
|
foreach ($headerFeatures as $key => $value) { |
642
|
|
|
switch ($key) { |
643
|
|
View Code Duplication |
case 'css': |
|
|
|
|
644
|
|
|
if (is_array($value)) { |
645
|
|
|
foreach ($value as $value2) { |
646
|
|
|
$aFeatures[] = $this->setCssFile(filter_var($value2, FILTER_SANITIZE_URL)); |
647
|
|
|
} |
648
|
|
|
} else { |
649
|
|
|
$aFeatures[] = $this->setCssFile(filter_var($value, FILTER_SANITIZE_URL)); |
650
|
|
|
} |
651
|
|
|
break; |
652
|
|
View Code Duplication |
case 'javascript': |
|
|
|
|
653
|
|
|
if (is_array($value)) { |
654
|
|
|
foreach ($value as $value2) { |
655
|
|
|
$vl = filter_var($value2, FILTER_SANITIZE_URL); |
656
|
|
|
$aFeatures[] = $this->setJavascriptFile($vl); |
657
|
|
|
} |
658
|
|
|
} else { |
659
|
|
|
$aFeatures[] = $this->setJavascriptFile(filter_var($value, FILTER_SANITIZE_URL)); |
660
|
|
|
} |
661
|
|
|
break; |
662
|
|
|
case 'lang': |
663
|
|
|
$fixedHeaderElements['lang'] = '<html lang="' |
664
|
|
|
. filter_var($value, FILTER_SANITIZE_STRING) . '">'; |
665
|
|
|
break; |
666
|
|
|
case 'title': |
667
|
|
|
$aFeatures[] = '<title>' |
668
|
|
|
. filter_var($value, FILTER_SANITIZE_STRING) . '</title>'; |
669
|
|
|
break; |
670
|
|
|
} |
671
|
|
|
} |
672
|
|
|
$sReturn[] = implode('', $fixedHeaderElements) |
673
|
|
|
. implode('', $aFeatures) |
674
|
|
|
. '</head>' |
675
|
|
|
. '<body>'; |
676
|
|
|
} else { |
677
|
|
|
$sReturn[] = implode('', $fixedHeaderElements) |
678
|
|
|
. '</head>' |
679
|
|
|
. '<body>' |
680
|
|
|
. '<p style="background-color:red;color:#FFF;">The parameter sent to ' |
681
|
|
|
. __FUNCTION__ . ' must be an array</p>' |
682
|
|
|
. $this->setFooterCommon(); |
683
|
|
|
throw new \Exception($sReturn); |
684
|
|
|
} |
685
|
|
|
} |
686
|
|
|
} |
687
|
|
|
return implode('', $sReturn); |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
/** |
691
|
|
|
* Generates a table cell |
692
|
|
|
* |
693
|
|
|
* @param array $aElements |
694
|
|
|
* @param array $features |
695
|
|
|
* @return string |
696
|
|
|
*/ |
697
|
|
|
private function setTableCell($aElements, $features = null) |
698
|
|
|
{ |
699
|
|
|
$sReturn = null; |
700
|
|
|
foreach ($aElements as $key => $value) { |
701
|
|
|
$value = str_replace(['& ', '\"', "\'"], ['& ', '"', "'"], $value); |
702
|
|
|
if ((isset($features['grouping_cell'])) && ($features['grouping_cell'] == $key)) { |
|
|
|
|
703
|
|
|
// just skip |
704
|
|
|
} else { |
705
|
|
|
$sReturn .= '<td '; |
706
|
|
|
if (isset($features['column_formatting'][$key])) { |
707
|
|
|
switch ($features['column_formatting'][$key]) { |
708
|
|
|
case '@': |
709
|
|
|
$sReturn .= 'style="text-align:left;">' . $value; |
710
|
|
|
break; |
711
|
|
|
case 'right': |
712
|
|
|
$sReturn .= 'style="text-align:right;">' . $value; |
713
|
|
|
break; |
714
|
|
|
default: |
715
|
|
|
$sReturn .= '???'; |
716
|
|
|
break; |
717
|
|
|
} |
718
|
|
|
} else { |
719
|
|
|
if (is_numeric($value)) { |
720
|
|
|
if (substr($value, 0, 1) === '0') { |
721
|
|
|
$sReturn .= 'style="text-align: right;">' . $value; |
722
|
|
|
} else { |
723
|
|
|
$decimals = 0; |
724
|
|
|
if (isset($features['no_of_decimals'])) { |
725
|
|
|
$decimals = $features['no_of_decimals']; |
726
|
|
|
} |
727
|
|
|
if (isset($features['decimals']) && array_key_exists($key, $features['decimals'])) { |
728
|
|
|
$decimals = $features['decimals'][$key]; |
729
|
|
|
} |
730
|
|
|
$sReturn .= 'style="text-align: right;">'; |
731
|
|
|
$sReturn .= $this->setNumberFormat($value, [ |
732
|
|
|
'MinFractionDigits' => $decimals, |
733
|
|
|
'MaxFractionDigits' => $decimals |
734
|
|
|
]); |
735
|
|
|
} |
736
|
|
|
} else { |
737
|
|
|
$outputet = false; |
738
|
|
|
if ((strpos($value, '-') !== false) && (strlen($value) == 10)) { |
739
|
|
|
if (preg_match("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $value, $regs)) { |
740
|
|
|
$outputet = true; |
741
|
|
|
$sReturn .= 'style="text-align:right;width: 10px;">' |
742
|
|
|
. $regs[3] . '.' . $regs[2] . '.' . $regs[1]; |
743
|
|
|
} |
744
|
|
|
} |
745
|
|
|
if (!$outputet) { |
746
|
|
|
$sReturn .= 'style="text-align:left;">' . $value; |
747
|
|
|
} |
748
|
|
|
} |
749
|
|
|
} |
750
|
|
|
$sReturn .= '</td>'; |
751
|
|
|
} |
752
|
|
|
} |
753
|
|
|
return $sReturn; |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
/** |
757
|
|
|
* Generates a table header |
758
|
|
|
* |
759
|
|
|
* @param array $aElements |
760
|
|
|
* @param boolean $bHeadersBreaked |
761
|
|
|
* @return string |
762
|
|
|
*/ |
763
|
|
|
private function setTableHeader($aElements, $bHeadersBreaked) |
764
|
|
|
{ |
765
|
|
|
if ($bHeadersBreaked) { |
766
|
|
|
$aTableHeader = $this->setArrayToArrayKbr($aElements); |
|
|
|
|
767
|
|
|
} else { |
768
|
|
|
$aTableHeader = $aElements; |
769
|
|
|
} |
770
|
|
|
$sReturn[] = null; |
|
|
|
|
771
|
|
|
foreach (array_keys($aTableHeader) as $value) { |
772
|
|
|
$sReturn[] = $this->setStringIntoTag($value, 'th'); |
773
|
|
|
} |
774
|
|
|
return implode('', $sReturn); |
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
/** |
778
|
|
|
* Create an upper right box with choices for languages |
779
|
|
|
* (requires flag-icon.min.css to be loaded) |
780
|
|
|
* (makes usage of custom class "upperRightBox" and id = "visibleOnHover", provided here as scss file) |
781
|
|
|
* |
782
|
|
|
* @param array $aAvailableLanguages |
783
|
|
|
* @return string |
784
|
|
|
*/ |
785
|
|
|
protected function setUpperRightBoxLanguages($aAvailableLanguages) |
786
|
|
|
{ |
787
|
|
|
$this->handleLanguageIntoSession(); |
788
|
|
|
return '<div class="upperRightBox">' |
789
|
|
|
. '<div style="text-align:right;">' |
790
|
|
|
. '<span class="flag-icon flag-icon-' . strtolower(substr($this->tCmnSuperGlobals->get('lang'), -2)) |
791
|
|
|
. '" style="margin-right:2px;"> </span>' |
792
|
|
|
. $aAvailableLanguages[$this->tCmnSession->get('lang')] |
793
|
|
|
. '</div><!-- default Language -->' |
794
|
|
|
. $this->setUpperRightVisibleOnHoverLanguages($aAvailableLanguages) |
795
|
|
|
. '</div><!-- upperRightBox end -->'; |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
private function setUpperRightVisibleOnHoverLanguages($aAvailableLanguages) |
799
|
|
|
{ |
800
|
|
|
$linkWithoutLanguage = ''; |
801
|
|
|
if (isset($this->tCmnSuperGlobals->request)) { |
802
|
|
|
$linkWithoutLanguage = $this->setArrayToStringForUrl('&', $this->tCmnSuperGlobals->request, ['lang']) |
803
|
|
|
. '&'; |
804
|
|
|
} |
805
|
|
|
$sReturn = []; |
806
|
|
|
foreach ($aAvailableLanguages as $key => $value) { |
807
|
|
|
if ($this->tCmnSession->get('lang') !== $key) { |
808
|
|
|
$sReturn[] = '<a href="?' . $linkWithoutLanguage . 'lang=' . $key . '" style="display:block;">' |
809
|
|
|
. '<span class="flag-icon flag-icon-' . strtolower(substr($key, -2)) |
810
|
|
|
. '" style="margin-right:2px;"> </span>' |
811
|
|
|
. $value . '</a>'; |
812
|
|
|
} |
813
|
|
|
} |
814
|
|
|
return '<div id="visibleOnHover">' . implode('', $sReturn) . '</div><!-- visibleOnHover end -->'; |
815
|
|
|
} |
816
|
|
|
} |
817
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.