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 \danielgp\browser_agent_info\BrowserAgentInfosByDanielGP; |
40
|
|
|
|
41
|
|
|
private function buildAttributesForTag($features) |
42
|
|
|
{ |
43
|
|
|
$attributes = ''; |
44
|
|
|
foreach ($features as $key => $value) { |
45
|
|
|
$val = $value; |
46
|
|
|
if (is_array($value)) { |
47
|
|
|
$valA = []; |
48
|
|
|
foreach ($value as $key2 => $value2) { |
49
|
|
|
$valA[] = $key2 . ':' . $value2 . ';'; |
50
|
|
|
} |
51
|
|
|
$val = implode(';', $valA); |
52
|
|
|
} |
53
|
|
|
$attributes .= ' ' . $key . '="' . $val . '"'; |
54
|
|
|
} |
55
|
|
|
return $attributes; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Calculate the optimal for all options within a select tag |
60
|
|
|
* |
61
|
|
|
* @param array $aElements |
62
|
|
|
* @param array $aFeatures |
63
|
|
|
* @return string|int |
64
|
|
|
*/ |
65
|
|
|
private function calculateSelectOptionsSize($aElements, $aFeatures = []) |
66
|
|
|
{ |
67
|
|
|
if (is_null($aFeatures)) { |
68
|
|
|
$aFeatures = []; |
69
|
|
|
} |
70
|
|
|
if (is_array($aElements)) { |
71
|
|
|
if (isset($aFeatures['size'])) { |
72
|
|
|
if ($aFeatures['size'] == 0) { |
73
|
|
|
$selectSize = count($aElements); |
74
|
|
|
} else { |
75
|
|
|
$selectSize = min(count($aElements), $aFeatures['size']); |
76
|
|
|
} |
77
|
|
|
} else { |
78
|
|
|
$selectSize = 1; |
79
|
|
|
} |
80
|
|
|
if ((in_array('include_null', $aFeatures)) && ($selectSize != '1')) { |
81
|
|
|
$selectSize++; |
82
|
|
|
} |
83
|
|
|
return $selectSize; |
84
|
|
|
} else { |
85
|
|
|
return ''; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function cleanStringForId($givenString) |
90
|
|
|
{ |
91
|
|
|
return preg_replace("/[^a-zA-Z0-9]/", '', ucwords($givenString)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Builds a <select> based on a given array |
96
|
|
|
* |
97
|
|
|
* @version 20080618 |
98
|
|
|
* @param array $aElements |
99
|
|
|
* @param string/array $sDefaultValue |
|
|
|
|
100
|
|
|
* @param string $select_name |
101
|
|
|
* @param array $features_array |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
protected function setArrayToSelect($aElements, $sDefaultValue, $select_name, $features_array = null) |
105
|
|
|
{ |
106
|
|
|
if (!is_array($aElements)) { |
107
|
|
|
return ''; |
108
|
|
|
} |
109
|
|
|
$select_id = '" id="' . str_replace(['[', ']'], ['', ''], $select_name) |
110
|
|
|
. (isset($features_array['id_no']) ? $features_array['id_no'] : ''); |
111
|
|
|
if (isset($features_array['readonly'])) { |
112
|
|
|
return $this->setStringIntoShortTag('input', [ |
113
|
|
|
'name' => $select_name, |
114
|
|
|
'id' => $select_id, |
115
|
|
|
'readonly' => 'readonly', |
116
|
|
|
'class' => 'input_readonly', |
117
|
|
|
'value' => $sDefaultValue, |
118
|
|
|
]) . $aElements[$sDefaultValue]; |
119
|
|
|
} |
120
|
|
|
if (isset($features_array['id_no'])) { |
121
|
|
|
unset($features_array['id_no']); |
122
|
|
|
} |
123
|
|
|
$string2return = '<select name="' . $select_name . $select_id |
124
|
|
|
. '" size="' . $this->calculateSelectOptionsSize($aElements, $features_array) . '"'; |
125
|
|
|
if (is_array($features_array)) { |
126
|
|
|
if (isset($features_array['additional_javascript_action'])) { |
127
|
|
|
$temporary_string = $features_array['additional_javascript_action']; |
128
|
|
|
} else { |
129
|
|
|
$temporary_string = ''; |
130
|
|
|
} |
131
|
|
|
if (in_array('autosubmit', $features_array)) { |
132
|
|
|
$string2return .= ' onchange="javascript:' . $temporary_string . 'submit();"'; |
133
|
|
|
} else { |
134
|
|
|
if ($temporary_string != '') { |
135
|
|
|
$string2return .= ' onchange="javascript:' . $temporary_string . '"'; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
if (in_array('disabled', $features_array)) { |
139
|
|
|
$string2return .= ' disabled="disabled"'; |
140
|
|
|
} |
141
|
|
|
if (in_array('hidden', $features_array)) { |
142
|
|
|
$string2return .= ' style="visibility: hidden;"'; |
143
|
|
|
} |
144
|
|
|
if (in_array('multiselect', $features_array)) { |
145
|
|
|
$string2return .= ' multiple="multiple"'; |
146
|
|
|
} |
147
|
|
|
if (array_key_exists('style', $features_array)) { |
148
|
|
|
$string2return .= ' style="' . $features_array['style'] . '"'; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
$string2return .= '>' |
152
|
|
|
. $this->setOptionsForSelect($aElements, $sDefaultValue, $features_array) |
153
|
|
|
. '</select>'; |
154
|
|
|
return $string2return; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Converts an array to string |
159
|
|
|
* |
160
|
|
|
* @param string $sSeparator |
161
|
|
|
* @param array $aElements |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
protected function setArrayToStringForUrl($sSeparator, $aElements, $aExceptedElements = ['']) |
165
|
|
|
{ |
166
|
|
|
if (is_array($aElements)) { |
167
|
|
|
if (count($aElements) == 0) { |
168
|
|
|
$sReturn = ['']; |
169
|
|
|
} else { |
170
|
|
|
$sReturn = []; |
171
|
|
|
foreach ($aElements as $key => $value) { |
172
|
|
|
if (!in_array($key, $aExceptedElements)) { |
173
|
|
|
if (is_array($aElements[$key])) { |
174
|
|
|
$aCounter = count($aElements[$key]); |
175
|
|
|
for ($counter2 = 0; $counter2 < $aCounter; $counter2++) { |
176
|
|
|
if ($value[$counter2] !== '') { |
177
|
|
|
$sReturn[] = $key . '[]=' . $value[$counter2]; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
} else { |
181
|
|
|
if ($value !== '') { |
182
|
|
|
$sReturn[] = $key . '=' . $value; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
} else { |
189
|
|
|
$sReturn = ['']; |
190
|
|
|
} |
191
|
|
|
return implode($sSeparator, $sReturn); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Returns a table from an query |
196
|
|
|
* |
197
|
|
|
* @param array $gArray |
|
|
|
|
198
|
|
|
* @param array $features |
|
|
|
|
199
|
|
|
* @param boolean $bKeepFullPage |
|
|
|
|
200
|
|
|
* @return string |
201
|
|
|
*/ |
202
|
|
|
protected function setArrayToTable($aElements, $ftrs = null, $bKpFlPge = true) |
|
|
|
|
203
|
|
|
{ |
204
|
|
|
$rows = count($aElements); |
205
|
|
|
if ($rows == 0) { |
206
|
|
|
$divTab = [ |
207
|
|
|
'start' => '', |
208
|
|
|
'end' => '', |
209
|
|
|
]; |
210
|
|
|
if (array_key_exists('showGroupingCounter', $ftrs)) { |
211
|
|
|
if (array_key_exists('grouping_cell_type', $ftrs) && ($ftrs['grouping_cell_type'] == 'tab')) { |
212
|
|
|
$ditTitle = 'No data found'; |
213
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
214
|
|
|
$ditTitle .= ' (0)'; |
215
|
|
|
} |
216
|
|
|
$divTab = [ |
217
|
|
|
'start' => '<div class="tabbertab tabbertabdefault" id="tab_NoData" title="' . $ditTitle . '">', |
218
|
|
|
'end' => '</div><!-- from tab_NoData -->', |
219
|
|
|
]; |
220
|
|
|
if (!isset($ftrs['noGlobalTab'])) { |
221
|
|
|
$divTab = [ |
222
|
|
|
'start' => '<div class="tabber" id="tab">' . $divTab['start'], |
223
|
|
|
'end' => $divTab['end'] . '</div><!-- from global Tab -->', |
224
|
|
|
]; |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
return $divTab['start'] |
229
|
|
|
. $this->setFeedbackModern('error', 'Error', $this->lclMsgCmn('i18n_NoData')) |
|
|
|
|
230
|
|
|
. $divTab['end']; |
231
|
|
|
} |
232
|
|
|
if (isset($ftrs['limits'])) { |
233
|
|
|
$ftrs['limits'][1] = min($ftrs['limits'][1], $ftrs['limits'][2]); |
234
|
|
|
if ($ftrs['limits'][2] > $ftrs['limits'][1]) { |
235
|
|
|
$iStartingPageRecord = 1; |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
$sReturn = ''; |
239
|
|
|
if (isset($ftrs['hidden_columns'])) { |
240
|
|
|
$hdClmns = $this->setArrayValuesAsKey($ftrs['hidden_columns']); |
|
|
|
|
241
|
|
|
} else { |
242
|
|
|
$hdClmns = ['']; |
243
|
|
|
} |
244
|
|
|
if ((isset($ftrs['actions']['checkbox_inlineEdit'])) || (isset($ftrs['actions']['checkbox']))) { |
245
|
|
|
$checkboxFormId = 'frm' . date('YmdHis'); |
246
|
|
|
$sReturn .= '<form id="' . $checkboxFormId . '" ' . 'name="' . $checkboxFormId |
247
|
|
|
. '" method="post" ' . ' action="' . $_SERVER['PHP_SELF'] . '" >'; |
248
|
|
|
} |
249
|
|
|
$tbl['Def'] = '<table' |
|
|
|
|
250
|
|
|
. (isset($ftrs['table_style']) ? ' style="' . $ftrs['table_style'] . '"' : '') |
251
|
|
|
. (isset($ftrs['table_class']) ? ' class="' . $ftrs['table_class'] . '"' : '') |
252
|
|
|
. '>'; |
253
|
|
|
if (!isset($ftrs['grouping_cell_type'])) { |
254
|
|
|
$ftrs['grouping_cell_type'] = 'row'; |
255
|
|
|
} |
256
|
|
|
switch ($ftrs['grouping_cell_type']) { |
257
|
|
|
case 'row': |
258
|
|
|
$sReturn .= $tbl['Def']; |
259
|
|
|
break; |
260
|
|
|
case 'tab': |
261
|
|
|
if (!isset($ftrs['noGlobalTab'])) { |
262
|
|
|
$sReturn .= '<div class="tabber" id="tab">'; |
263
|
|
|
} |
264
|
|
|
break; |
265
|
|
|
} |
266
|
|
|
$iTableColumns = 0; |
267
|
|
|
$remebered_value = -1; |
268
|
|
|
$remindGroupValue = null; |
269
|
|
|
$color_no = null; |
270
|
|
|
if (!isset($ftrs['headers_breaked'])) { |
271
|
|
|
$ftrs['headers_breaked'] = true; |
272
|
|
|
} |
273
|
|
|
for ($rCntr = 0; $rCntr < $rows; $rCntr++) { |
274
|
|
|
if ($rCntr == 0) { |
275
|
|
|
$header = array_diff_key($aElements[$rCntr], $hdClmns); |
276
|
|
|
$iTableColumns = count($header); |
277
|
|
|
if (isset($ftrs['computed_columns'])) { |
278
|
|
|
$iTableColumns += count($ftrs['computed_columns']); |
279
|
|
|
} |
280
|
|
|
if (isset($ftrs['actions'])) { |
281
|
|
|
$iTableColumns += 1; |
282
|
|
|
} |
283
|
|
|
if (isset($ftrs['grouping_cell'])) { |
284
|
|
|
$iTableColumns -= 1; |
285
|
|
|
} |
286
|
|
|
$tbl['Head'] = '<thead>'; |
287
|
|
|
if ($ftrs['grouping_cell_type'] == 'row') { |
288
|
|
|
$sReturn .= $tbl['Head']; |
289
|
|
|
} |
290
|
|
View Code Duplication |
if (isset($iStartingPageRecord)) { |
|
|
|
|
291
|
|
|
$pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2], $bKpFlPge); |
|
|
|
|
292
|
|
|
$sReturn .= $this->setStringIntoTag($this->setStringIntoTag($pgn, 'th', [ |
293
|
|
|
'colspan' => $iTableColumns |
294
|
|
|
]), 'tr'); |
295
|
|
|
} |
296
|
|
|
$tbl['Header'] = '<tr>'; |
297
|
|
|
if (isset($ftrs['grouping_cell'])) { // Grouping columns |
298
|
|
|
$header = array_diff_key($header, [$ftrs['grouping_cell'] => '']); |
299
|
|
|
} |
300
|
|
|
if (isset($ftrs['actions'])) { // Action column |
301
|
|
|
$tbl['Header'] .= '<th> </th>'; |
302
|
|
|
} |
303
|
|
|
if (isset($ftrs['RowStyle'])) { //Exclude style columns from displaying |
304
|
|
|
$tmpClmns = $this->setArrayValuesAsKey([$ftrs['RowStyle']]); |
|
|
|
|
305
|
|
|
$header = array_diff_key($header, $tmpClmns); |
306
|
|
|
$hdClmns = array_merge($hdClmns, $tmpClmns); |
307
|
|
|
unset($tmpClmns); |
308
|
|
|
} |
309
|
|
|
$tbl['Header'] .= $this->setTableHeader($header, $ftrs['headers_breaked']); // Regular columns |
310
|
|
|
if (isset($ftrs['computed_columns'])) { // Computed columns |
311
|
|
|
$tbl['Header'] .= $this->setTableHeader($ftrs['computed_columns'], $ftrs['headers_breaked']); |
312
|
|
|
} |
313
|
|
|
$tbl['Header'] .= '</tr></thead><tbody>'; |
314
|
|
|
if ($ftrs['grouping_cell_type'] == 'row') { |
315
|
|
|
$sReturn .= $tbl['Header']; |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
$row_current = array_diff_key($aElements[$rCntr], $hdClmns); |
319
|
|
|
if (isset($ftrs['row_colored_alternated'])) { |
320
|
|
|
if ($ftrs['row_colored_alternated'][0] == '#') { |
321
|
|
|
$color_column_value = $rCntr; |
322
|
|
|
} else { |
323
|
|
|
$color_column_value = $row_current[$ftrs['row_colored_alternated'][0]]; |
324
|
|
|
} |
325
|
|
|
if ($remebered_value != $color_column_value) { |
326
|
|
|
if (isset($color_no)) { |
327
|
|
|
$color_no = 1; |
328
|
|
|
} else { |
329
|
|
|
$color_no = 2; |
330
|
|
|
} |
331
|
|
|
$remebered_value = $color_column_value; |
332
|
|
|
} |
333
|
|
|
$color = ' style="background-color: ' . $ftrs['row_colored_alternated'][$color_no] . ';"'; |
334
|
|
|
} else { |
335
|
|
|
if (isset($ftrs['RowStyle'])) { |
336
|
|
|
$color = ' style="' . $aElements[$rCntr][$ftrs['RowStyle']] . '"'; |
337
|
|
|
} else { |
338
|
|
|
$color = ''; |
339
|
|
|
} |
340
|
|
|
} |
341
|
|
|
$tbl['tr_Color'] = '<tr' . $color . '>'; |
342
|
|
|
// Grouping column |
343
|
|
|
if (isset($ftrs['grouping_cell'])) { |
344
|
|
|
foreach ($aElements[$rCntr] as $key => $value) { |
345
|
|
|
if (($ftrs['grouping_cell'] == $key) && ($remindGroupValue != $value)) { |
346
|
|
|
switch ($ftrs['grouping_cell_type']) { |
347
|
|
|
case 'row': |
348
|
|
|
$sReturn .= $tbl['tr_Color'] . '<td ' . 'colspan="' . $iTableColumns . '">' |
349
|
|
|
. $this->setStringIntoTag($value, 'div', ['class' => 'rowGroup rounded']) |
350
|
|
|
. '</td></tr>'; |
351
|
|
|
break; |
352
|
|
|
case 'tab': |
353
|
|
|
if (is_null($remindGroupValue)) { |
354
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
355
|
|
|
$groupCounter = 0; |
356
|
|
|
} |
357
|
|
|
} else { |
358
|
|
|
$sReturn .= '</tbody></table>'; |
359
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
360
|
|
|
$sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
|
|
|
|
361
|
|
|
$groupCounter = 0; |
362
|
|
|
} |
363
|
|
|
$sReturn .= '</div>'; |
364
|
|
|
} |
365
|
|
|
$sReturn .= '<div class="tabbertab'; |
366
|
|
|
if (isset($ftrs['grouping_default_tab'])) { |
367
|
|
|
$sReturn .= ($ftrs['grouping_default_tab'] == $value ? ' tabbertabdefault' : ''); |
368
|
|
|
} |
369
|
|
|
$sReturn .= '" id="tab_' . $this->cleanStringForId($value) . '" ' |
370
|
|
|
. 'title="' . $value . '">' |
371
|
|
|
. $tbl['Def'] . $tbl['Head'] . $tbl['Header']; |
372
|
|
|
break; |
373
|
|
|
} |
374
|
|
|
$remindGroupValue = $value; |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
} |
378
|
|
|
if (isset($ftrs['grouping_cell'])) { |
379
|
|
|
if ($ftrs['grouping_cell_type'] == 'tab') { |
380
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
381
|
|
|
$groupCounter++; |
382
|
|
|
} |
383
|
|
|
} |
384
|
|
|
} |
385
|
|
|
$sReturn .= $tbl['tr_Color']; |
386
|
|
|
// Action column |
387
|
|
|
if (isset($ftrs['actions'])) { |
388
|
|
|
$sReturn .= '<td style="white-space:nowrap;">'; |
389
|
|
|
$action_argument = 0; |
390
|
|
|
if (isset($ftrs['actions']['key'])) { |
391
|
|
|
$action_key = $ftrs['actions']['key']; |
392
|
|
|
} else { |
393
|
|
|
$action_key = 'view'; |
394
|
|
|
} |
395
|
|
|
if (isset($ftrs['action_prefix'])) { |
396
|
|
|
$actPrfx = $ftrs['action_prefix'] . '&'; |
397
|
|
|
$action_key = 'view2'; |
398
|
|
|
} else { |
399
|
|
|
$actPrfx = ''; |
400
|
|
|
} |
401
|
|
|
foreach ($ftrs['actions'] as $key => $value) { |
402
|
|
|
if ($action_argument != 0) { |
403
|
|
|
$sReturn .= ' '; |
404
|
|
|
} |
405
|
|
|
switch ($key) { |
406
|
|
|
case 'checkbox': |
407
|
|
|
$checkboxName = $value . '[]'; |
408
|
|
|
$checkboxNameS = $value; |
409
|
|
|
$sReturn .= ' <input type="checkbox" name="' . $checkboxName |
410
|
|
|
. '" id="n' . $aElements[$rCntr][$value] |
411
|
|
|
. '" value="' . $aElements[$rCntr][$value] . '" '; |
412
|
|
|
if (isset($_REQUEST[$checkboxNameS])) { |
413
|
|
|
if (is_array($_REQUEST[$checkboxNameS])) { |
414
|
|
|
if (in_array($aElements[$rCntr][$value], $_REQUEST[$checkboxNameS])) { |
415
|
|
|
$sReturn .= 'checked="checked" '; |
416
|
|
|
} |
417
|
|
|
} else { |
418
|
|
|
if ($aElements[$rCntr][$value] == $_REQUEST[$checkboxNameS]) { |
419
|
|
|
$sReturn .= 'checked="checked" '; |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
if (strpos($_REQUEST['view'], 'multiEdit') !== false) { |
424
|
|
|
$sReturn .= 'disabled="disabled" '; |
425
|
|
|
} |
426
|
|
|
$sReturn .= '/>'; |
427
|
|
|
break; |
428
|
|
|
case 'checkbox_inlineEdit': |
429
|
|
|
$checkboxName = $value . '[]'; |
430
|
|
|
$checkboxNameS = $value; |
431
|
|
|
$sReturn .= ' <input type="checkbox" name="' . $checkboxName |
432
|
|
|
. '" id="n' . $aElements[$rCntr][$value] . '" value="' |
433
|
|
|
. $aElements[$rCntr][$value] . '"/>'; |
434
|
|
|
break; |
435
|
|
|
case 'edit': |
436
|
|
|
$edt = ''; |
437
|
|
|
if (isset($ftrs['NoAjaxEditing'])) { |
438
|
|
|
$edt .= $_SERVER['PHP_SELF'] . '?' . $actPrfx |
439
|
|
|
. $action_key . '=' . $value[0] . '&'; |
440
|
|
|
$iActArgs = count($value[1]); |
441
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
442
|
|
|
$edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
443
|
|
|
} |
444
|
|
|
$sReturn .= '<a href="' . $edt . '"><i class="fa fa-pencil"> </i></a>'; |
445
|
|
View Code Duplication |
} else { |
|
|
|
|
446
|
|
|
$edt .= 'javascript:loadAE(\'' . $_SERVER['PHP_SELF'] . '?' |
447
|
|
|
. $actPrfx . $action_key . '=' . $value[0] . '&'; |
448
|
|
|
$iActArgs = count($value[1]); |
449
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
450
|
|
|
$edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
451
|
|
|
} |
452
|
|
|
$edt .= '\');'; |
453
|
|
|
$sReturn .= '<a href="#" onclick="' . $edt . '">' |
454
|
|
|
. '<i class="fa fa-pencil"> </i></a>'; |
455
|
|
|
} |
456
|
|
|
break; |
457
|
|
|
case 'list2': |
458
|
|
|
$edt = ''; |
459
|
|
|
if (isset($ftrs['NoAjaxEditing'])) { |
460
|
|
|
$sReturn .= '<a href="?' . $actPrfx . $action_key . '=' . $value[0] . '&'; |
461
|
|
|
$iActArgs = count($value[1]); |
462
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
463
|
|
|
$sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
464
|
|
|
} |
465
|
|
|
$sReturn .= '"><i class="fa fa-list"> </i></a>'; |
466
|
|
View Code Duplication |
} else { |
|
|
|
|
467
|
|
|
$edt .= 'javascript:loadAE(\'' . $_SERVER['PHP_SELF'] . '?' |
468
|
|
|
. $actPrfx . $action_key . '=' . $value[0] . '&'; |
469
|
|
|
$iActArgs = count($value[1]); |
470
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
471
|
|
|
$edt .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
472
|
|
|
} |
473
|
|
|
$edt .= '\');'; |
474
|
|
|
$sReturn .= '<a href="#" onclick="' . $edt . '">' |
475
|
|
|
. '<i class="fa fa-list"> </i></a>'; |
476
|
|
|
} |
477
|
|
|
break; |
478
|
|
|
case 'delete': |
479
|
|
|
$sReturn .= '<a href="javascript:setQuest(\'' . $value[0] . '\',\''; |
480
|
|
|
$iActArgs = count($value[1]); |
481
|
|
|
for ($cntr2 = 0; $cntr2 < $iActArgs; $cntr2++) { |
482
|
|
|
$sReturn .= $value[1][$cntr2] . '=' . $aElements[$rCntr][$value[1][$cntr2]]; |
483
|
|
|
} |
484
|
|
|
$sReturn .= '\');"><i class="fa fa-times"> </i></a>'; |
485
|
|
|
break; |
486
|
|
|
} |
487
|
|
|
$action_argument += 1; |
488
|
|
|
} |
489
|
|
|
$sReturn .= '</td>'; |
490
|
|
|
} |
491
|
|
|
// Regular columns |
492
|
|
|
$sReturn .= $this->setTableCell($row_current, $ftrs); |
493
|
|
|
// Computed columns |
494
|
|
|
if (isset($ftrs['computed_columns'])) { |
495
|
|
|
foreach ($ftrs['computed_columns'] as $key => $value) { |
496
|
|
|
if ($value[0] == '%') { |
497
|
|
|
$dec = $value[2] + 2; |
498
|
|
|
} else { |
499
|
|
|
$dec = $value[2]; |
500
|
|
|
} |
501
|
|
|
switch ($value[1]) { |
502
|
|
|
case '/': |
503
|
|
|
// next variable is only to avoid a long line |
504
|
|
|
$shorter = [ |
505
|
|
|
$aElements[$rCntr][$value[3]], |
506
|
|
|
$aElements[$rCntr][$value[4]], |
507
|
|
|
]; |
508
|
|
|
$aElements[$rCntr][$key] = $this->setDividedResult($shorter[0], $shorter[1], $dec); |
|
|
|
|
509
|
|
|
break; |
510
|
|
|
case '+': |
511
|
|
|
// next variable is only to avoid a long line |
512
|
|
|
$iTemp = $this->setArrayValuesAsKey([ |
|
|
|
|
513
|
|
|
$value[0], |
514
|
|
|
$value[1], |
515
|
|
|
$value[2] |
516
|
|
|
]); |
517
|
|
|
$aTemp = array_diff($value, $iTemp); |
518
|
|
|
$aElements[$rCntr][$key] = 0; |
519
|
|
|
foreach ($aTemp as $sValue) { |
520
|
|
|
$aElements[$rCntr][$key] += $aElements[$rCntr][$sValue]; |
521
|
|
|
} |
522
|
|
|
break; |
523
|
|
|
default: |
524
|
|
|
$row_computed[$key] = ''; |
|
|
|
|
525
|
|
|
break; |
526
|
|
|
} |
527
|
|
|
if ($value[0] == '%') { |
528
|
|
|
$row_computed[$key] = ($aElements[$rCntr][$key] * 100); |
|
|
|
|
529
|
|
|
$dec -= 2; |
530
|
|
|
} else { |
531
|
|
|
$row_computed[$key] = $aElements[$rCntr][$key]; |
532
|
|
|
} |
533
|
|
|
$decimals[$key] = $dec; |
|
|
|
|
534
|
|
|
} |
535
|
|
|
// displaying them |
536
|
|
|
$sReturn .= $this->setTableCell($row_computed, ['decimals' => $decimals]); |
|
|
|
|
537
|
|
|
} |
538
|
|
|
$sReturn .= '</tr>'; |
539
|
|
|
} |
540
|
|
View Code Duplication |
if (isset($iStartingPageRecord)) { |
|
|
|
|
541
|
|
|
$pgn = $this->setPagination($ftrs['limits'][0], $ftrs['limits'][1], $ftrs['limits'][2]); |
|
|
|
|
542
|
|
|
$sReturn .= '<tr>' . $this->setStringIntoTag($pgn, 'th', ['colspan' => $iTableColumns]) . '</tr>'; |
543
|
|
|
} |
544
|
|
|
$sReturn .= '</tbody></table>'; |
545
|
|
|
if ($ftrs['grouping_cell_type'] == 'tab') { |
546
|
|
|
if (isset($ftrs['showGroupingCounter'])) { |
547
|
|
|
$sReturn .= $this->updateDivTitleName($remindGroupValue, $groupCounter); |
548
|
|
|
} |
549
|
|
|
$sReturn .= '</div><!-- from ' . $remindGroupValue . ' -->'; |
550
|
|
|
if (!isset($ftrs['noGlobalTab'])) { |
551
|
|
|
$sReturn .= '</div><!-- from global tab -->'; |
552
|
|
|
} |
553
|
|
|
} |
554
|
|
|
if (isset($ftrs['actions']['checkbox'])) { |
555
|
|
|
if (strpos($_REQUEST['view'], 'multiEdit') === false) { |
556
|
|
|
$sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
|
|
|
|
557
|
|
|
. '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
|
|
|
|
558
|
|
|
. '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
559
|
|
|
. '\',\'' . $checkboxName . '\',false);">Uncheck All</a> ' |
560
|
|
|
. '<input type="hidden" name="action" value="multiEdit_' . $checkboxNameS . '" />'; |
|
|
|
|
561
|
|
View Code Duplication |
if (isset($ftrs['hiddenInput'])) { |
|
|
|
|
562
|
|
|
if (is_array($ftrs['hiddenInput'])) { |
563
|
|
|
foreach ($ftrs['hiddenInput'] as $valueF) { |
564
|
|
|
$sReturn .= '<input type="hidden" name="' . $valueF |
565
|
|
|
. '" value="' . $_REQUEST[$valueF] . '" />'; |
566
|
|
|
} |
567
|
|
|
} else { |
568
|
|
|
$sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
569
|
|
|
. '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
570
|
|
|
} |
571
|
|
|
} |
572
|
|
|
$sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" ' . 'value="Edit selected" />'; |
573
|
|
|
} |
574
|
|
|
$sReturn .= '</form>'; |
575
|
|
|
} |
576
|
|
|
if (isset($ftrs['actions']['checkbox_inlineEdit'])) { |
577
|
|
|
$sReturn .= '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
578
|
|
|
. '\',\'' . $checkboxName . '\',true);">Check All</a> ' |
579
|
|
|
. '<a href="#" onclick="javascript:checking(\'' . $checkboxFormId |
580
|
|
|
. '\',\'' . $checkboxName . '\',false);">Uncheck All</a> '; |
581
|
|
|
if (isset($ftrs['visibleInput'])) { |
582
|
|
|
$sReturn .= $ftrs['visibleInput']; |
583
|
|
|
} |
584
|
|
|
$sReturn .= '<input type="hidden" name="view" value="save_' . $checkboxNameS . '" />'; |
585
|
|
View Code Duplication |
if (isset($ftrs['hiddenInput'])) { |
|
|
|
|
586
|
|
|
if (is_array($ftrs['hiddenInput'])) { |
587
|
|
|
foreach ($ftrs['hiddenInput'] as $valueF) { |
588
|
|
|
$sReturn .= '<input type="hidden" name="' . $valueF |
589
|
|
|
. '" value="' . $_REQUEST[$valueF] . '" />'; |
590
|
|
|
} |
591
|
|
|
} else { |
592
|
|
|
$sReturn .= '<input type="hidden" name="' . $ftrs['hiddenInput'] |
593
|
|
|
. '" value="' . $_REQUEST[$ftrs['hiddenInput']] . '" />'; |
594
|
|
|
} |
595
|
|
|
} |
596
|
|
|
$sReturn .= '<input style="margin: 0 3em 0 3em;" type="submit" value="Store the modification" />'; |
597
|
|
|
$sReturn .= '</form>'; |
598
|
|
|
} |
599
|
|
|
return $sReturn; |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* Set a control to a user-friendly calendar |
604
|
|
|
* |
605
|
|
|
* @param string $controlName |
606
|
|
|
* @param string $additionalStyle |
607
|
|
|
* @return string |
608
|
|
|
*/ |
609
|
|
View Code Duplication |
public function setCalendarControl($controlName, $additionalStyle = '') |
|
|
|
|
610
|
|
|
{ |
611
|
|
|
return $this->setStringIntoTag(' ', 'span', [ |
612
|
|
|
'onclick' => implode('', [ |
613
|
|
|
'javascript:NewCssCal(\'' . $controlName, |
614
|
|
|
'\',\'yyyyMMdd\',\'dropdown\',false,\'24\',false);', |
615
|
|
|
]), |
616
|
|
|
'class' => 'fa fa-calendar', |
617
|
|
|
'id' => $controlName . '_picker', |
618
|
|
|
'style' => 'cursor:pointer;' . $additionalStyle, |
619
|
|
|
]); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
/** |
623
|
|
|
* Set a control to a user-friendly calendar with time included |
624
|
|
|
* |
625
|
|
|
* @param string $controlName |
626
|
|
|
* @param string $additionalStyle |
627
|
|
|
* @return string |
628
|
|
|
*/ |
629
|
|
View Code Duplication |
public function setCalendarControlWithTime($controlName, $additionalStyle = '') |
|
|
|
|
630
|
|
|
{ |
631
|
|
|
return $this->setStringIntoTag(' ', 'span', [ |
632
|
|
|
'onclick' => implode('', [ |
633
|
|
|
'javascript:NewCssCal(\'' . $controlName, |
634
|
|
|
'\',\'yyyyMMdd\',\'dropdown\',true,\'24\',true);', |
635
|
|
|
]), |
636
|
|
|
'class' => 'fa fa-calendar', |
637
|
|
|
'id' => $controlName . '_picker', |
638
|
|
|
'style' => 'cursor:pointer;' . $additionalStyle, |
639
|
|
|
]); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* Cleans a string for certain internal rules |
644
|
|
|
* |
645
|
|
|
* @param type $urlString |
646
|
|
|
* @return type |
647
|
|
|
*/ |
648
|
|
|
protected function setCleanUrl($urlString) |
649
|
|
|
{ |
650
|
|
|
$arrayToReplace = [ |
651
|
|
|
'&' => '&', |
652
|
|
|
'&' => '&', |
653
|
|
|
'&amp;' => '&', |
654
|
|
|
' ' => '%20', |
655
|
|
|
]; |
656
|
|
|
$kys = array_keys($arrayToReplace); |
657
|
|
|
$vls = array_values($arrayToReplace); |
658
|
|
|
return str_replace($kys, $vls, filter_var($urlString, FILTER_SANITIZE_URL)); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
/** |
662
|
|
|
* Returns a div tag that clear any float |
663
|
|
|
* |
664
|
|
|
* @param integer $height |
665
|
|
|
*/ |
666
|
|
View Code Duplication |
protected function setClearBoth1px($height = 1) |
|
|
|
|
667
|
|
|
{ |
668
|
|
|
return $this->setStringIntoTag(' ', 'div', [ |
669
|
|
|
'style' => implode('', [ |
670
|
|
|
'height:' . $height . 'px;', |
671
|
|
|
'line-height:' . $height . 'px;', |
672
|
|
|
'float:none;', |
673
|
|
|
'clear:both;', |
674
|
|
|
'margin:0px;' |
675
|
|
|
]) |
676
|
|
|
]); |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* Returns css codes |
681
|
|
|
* |
682
|
|
|
* @param string $cssContent |
683
|
|
|
* @param array $optionalFlags |
684
|
|
|
* @return string |
685
|
|
|
*/ |
686
|
|
|
protected function setCssContent($cssContent, $optionalFlags = null) |
687
|
|
|
{ |
688
|
|
|
if (is_null($optionalFlags)) { |
689
|
|
|
$attr['media'] = 'all'; |
|
|
|
|
690
|
|
|
} else { |
691
|
|
|
$knownAttributes = ['media']; |
692
|
|
|
foreach ($knownAttributes as $value) { |
693
|
|
|
if (in_array($value, array_keys($optionalFlags))) { |
694
|
|
|
$attr[$value] = $optionalFlags[$value]; |
|
|
|
|
695
|
|
|
} |
696
|
|
|
} |
697
|
|
|
} |
698
|
|
|
return '<style type="text/css" media="' . $attr['media'] . '">' |
|
|
|
|
699
|
|
|
. $cssContent |
700
|
|
|
. '</style>'; |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
/** |
704
|
|
|
* Returns css link to a given file |
705
|
|
|
* |
706
|
|
|
* @param string $cssFile |
|
|
|
|
707
|
|
|
* @return string |
708
|
|
|
*/ |
709
|
|
|
protected function setCssFile($cssFileName, $hostsWithoutCDNrq = null) |
710
|
|
|
{ |
711
|
|
|
$sReturn = null; |
|
|
|
|
712
|
|
|
if (is_null($hostsWithoutCDNrq)) { |
713
|
|
|
$hostsWithoutCDNrq = []; |
714
|
|
|
} |
715
|
|
|
if (in_array($this->getClientRealIpAddress(), $hostsWithoutCDNrq)) { |
716
|
|
|
$sReturn = '<link rel="stylesheet" type="text/css" href="' |
717
|
|
|
. filter_var($cssFileName, FILTER_SANITIZE_STRING) |
718
|
|
|
. '" />'; |
719
|
|
|
} else { |
720
|
|
|
$patternFound = $this->setCssFileCDN($cssFileName); |
|
|
|
|
721
|
|
|
$sReturn = '<link rel="stylesheet" type="text/css" href="' |
722
|
|
|
. filter_var($patternFound[1], FILTER_SANITIZE_STRING) |
723
|
|
|
. '" />'; |
724
|
|
|
} |
725
|
|
|
return $sReturn; |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
/** |
729
|
|
|
* Builds a structured modern message |
730
|
|
|
* |
731
|
|
|
* @param string $sType |
732
|
|
|
* @param string $sTitle |
733
|
|
|
* @param string $sMsg |
734
|
|
|
* @param boolean $skipBr |
735
|
|
|
*/ |
736
|
|
|
protected function setFeedbackModern($sType, $sTitle, $sMsg, $skipBr = false) |
737
|
|
|
{ |
738
|
|
|
$formatTitle[] = 'margin-top:-5px;margin-right:20px;padding:5px;'; |
|
|
|
|
739
|
|
|
$formatMessage[] = 'display:inline;padding-right:5px;padding-bottom:5px;'; |
|
|
|
|
740
|
|
|
switch ($sType) { |
741
|
|
|
case 'alert': |
742
|
|
|
$formatTitle[] = 'border:medium solid orange;background-color:orange;color:navy;'; |
743
|
|
|
$formatMessage[] = 'background-color:navy;color:orange;border:medium solid orange;'; |
744
|
|
|
break; |
745
|
|
|
case 'check': |
746
|
|
|
$formatTitle[] = 'border:medium solid green;background-color:green;color:white;'; |
747
|
|
|
$formatMessage[] = 'background-color:yellow;color:green;border:medium solid green;'; |
748
|
|
|
break; |
749
|
|
|
case 'error': |
750
|
|
|
$formatTitle[] = 'border:medium solid red;background-color:red;color:white;'; |
751
|
|
|
$formatMessage[] = 'background-color:yellow;color:red;border:medium solid red;'; |
752
|
|
|
break; |
753
|
|
|
case 'info': |
754
|
|
|
$formatTitle[] = 'border:medium solid black;background-color:black;color:white;font-weight:bold;'; |
755
|
|
|
$formatMessage[] = 'background-color: white; color: black;border:medium solid black;'; |
756
|
|
|
break; |
757
|
|
|
} |
758
|
|
|
if ($sTitle == 'light') { |
759
|
|
|
echo $sMsg; |
760
|
|
|
} else { |
761
|
|
|
$legend = $this->setStringIntoTag($sTitle, 'legend', ['style' => implode('', $formatTitle)]); |
762
|
|
|
return implode('', [ |
763
|
|
|
($skipBr ? '' : '<br/>'), |
764
|
|
|
$this->setStringIntoTag($legend . $sMsg, 'fieldset', [ |
765
|
|
|
'style' => implode('', $formatMessage) |
766
|
|
|
]), |
767
|
|
|
]); |
768
|
|
|
} |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* Outputs an HTML footer |
773
|
|
|
* |
774
|
|
|
* @param array $footerInjected |
775
|
|
|
* @return string |
776
|
|
|
*/ |
777
|
|
|
protected function setFooterCommon($footerInjected = null) |
|
|
|
|
778
|
|
|
{ |
779
|
|
|
if (isset($_REQUEST['specialHook']) && (in_array('noFooter', $_REQUEST['specialHook']))) { |
780
|
|
|
return ''; |
781
|
|
|
} |
782
|
|
|
return $this->setFooterCommonInjected($footerInjected) . '</body></html>'; |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
protected function setFooterCommonInjected($footerInjected = null) |
786
|
|
|
{ |
787
|
|
|
$sReturn = ''; |
788
|
|
|
if (!is_null($footerInjected)) { |
789
|
|
|
$sReturn = $footerInjected; |
790
|
|
|
if (is_array($footerInjected)) { |
791
|
|
|
$sReturn = implode('', $footerInjected); |
792
|
|
|
} |
793
|
|
|
} |
794
|
|
|
return $sReturn; |
795
|
|
|
} |
796
|
|
|
|
797
|
|
|
/** |
798
|
|
|
* Sets the gzip footer for HTML |
799
|
|
|
*/ |
800
|
|
|
protected function setFooterGZiped() |
|
|
|
|
801
|
|
|
{ |
802
|
|
|
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { |
803
|
|
|
if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) { |
804
|
|
|
if (extension_loaded('zlib')) { |
805
|
|
|
$gzip_contents = ob_get_contents(); |
806
|
|
|
ob_end_clean(); |
807
|
|
|
$gzip_size = strlen($gzip_contents); |
808
|
|
|
$gzip_crc = crc32($gzip_contents); |
809
|
|
|
$gzip_contents = gzcompress($gzip_contents, 9); |
810
|
|
|
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4); |
811
|
|
|
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00"; |
812
|
|
|
echo $gzip_contents; |
813
|
|
|
echo pack('V', $gzip_crc); |
814
|
|
|
echo pack('V', $gzip_size); |
815
|
|
|
} |
816
|
|
|
} |
817
|
|
|
} |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
/** |
821
|
|
|
* Outputs an HTML header |
822
|
|
|
* |
823
|
|
|
* @param array $headerFeatures |
824
|
|
|
* @return string |
825
|
|
|
*/ |
826
|
|
|
protected function setHeaderCommon($headerFeatures = null) |
|
|
|
|
827
|
|
|
{ |
828
|
|
|
$sReturn = []; |
829
|
|
|
if (isset($_REQUEST['specialHook']) && (in_array('noHeader', $_REQUEST['specialHook']))) { |
830
|
|
|
$sReturn[] = ''; // no Header |
831
|
|
|
} else { |
832
|
|
|
$fixedHeaderElements = [ |
833
|
|
|
'start' => '<!DOCTYPE html>', |
834
|
|
|
'lang' => '<html lang="en-US">', |
835
|
|
|
'head' => '<head>', |
836
|
|
|
'charset' => '<meta charset="utf-8" />', |
837
|
|
|
'viewport' => '<meta name="viewport" content="' . implode(', ', [ |
838
|
|
|
'width=device-width', |
839
|
|
|
'height=device-height', |
840
|
|
|
'initial-scale=1', |
841
|
|
|
]) . '" />', |
842
|
|
|
]; |
843
|
|
|
if (!is_null($headerFeatures)) { |
844
|
|
|
if (is_array($headerFeatures)) { |
845
|
|
|
$aFeatures = []; |
846
|
|
|
foreach ($headerFeatures as $key => $value) { |
847
|
|
|
switch ($key) { |
848
|
|
View Code Duplication |
case 'css': |
|
|
|
|
849
|
|
|
if (is_array($value)) { |
850
|
|
|
foreach ($value as $value2) { |
851
|
|
|
$aFeatures[] = $this->setCssFile(filter_var($value2, FILTER_SANITIZE_URL)); |
852
|
|
|
} |
853
|
|
|
} else { |
854
|
|
|
$aFeatures[] = $this->setCssFile(filter_var($value, FILTER_SANITIZE_URL)); |
855
|
|
|
} |
856
|
|
|
break; |
857
|
|
View Code Duplication |
case 'javascript': |
|
|
|
|
858
|
|
|
if (is_array($value)) { |
859
|
|
|
foreach ($value as $value2) { |
860
|
|
|
$vl = filter_var($value2, FILTER_SANITIZE_URL); |
861
|
|
|
$aFeatures[] = $this->setJavascriptFile($vl); |
862
|
|
|
} |
863
|
|
|
} else { |
864
|
|
|
$aFeatures[] = $this->setJavascriptFile(filter_var($value, FILTER_SANITIZE_URL)); |
865
|
|
|
} |
866
|
|
|
break; |
867
|
|
|
case 'lang': |
868
|
|
|
$fixedHeaderElements['lang'] = '<html lang="' |
869
|
|
|
. filter_var($value, FILTER_SANITIZE_STRING) . '">'; |
870
|
|
|
break; |
871
|
|
|
case 'title': |
872
|
|
|
$aFeatures[] = '<title>' |
873
|
|
|
. filter_var($value, FILTER_SANITIZE_STRING) . '</title>'; |
874
|
|
|
break; |
875
|
|
|
} |
876
|
|
|
} |
877
|
|
|
$sReturn[] = implode('', $fixedHeaderElements) |
878
|
|
|
. implode('', $aFeatures) |
879
|
|
|
. '</head>' |
880
|
|
|
. '<body>'; |
881
|
|
|
} else { |
882
|
|
|
$sReturn[] = implode('', $fixedHeaderElements) |
883
|
|
|
. '</head>' |
884
|
|
|
. '<body>' |
885
|
|
|
. '<p style="background-color:red;color:#FFF;">The parameter sent to ' |
886
|
|
|
. __FUNCTION__ . ' must be an array</p>' |
887
|
|
|
. $this->setFooterCommon(); |
888
|
|
|
throw new \Exception($sReturn); |
889
|
|
|
} |
890
|
|
|
} |
891
|
|
|
} |
892
|
|
|
return implode('', $sReturn); |
893
|
|
|
} |
894
|
|
|
|
895
|
|
|
/** |
896
|
|
|
* Sets the gzip header for HTML |
897
|
|
|
*/ |
898
|
|
|
protected function setHeaderGZiped() |
|
|
|
|
899
|
|
|
{ |
900
|
|
|
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { |
901
|
|
|
if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) { |
902
|
|
|
if (extension_loaded('zlib')) { |
903
|
|
|
ob_start(); |
904
|
|
|
ob_implicit_flush(0); |
905
|
|
|
header('Content-Encoding: gzip'); |
906
|
|
|
} |
907
|
|
|
} |
908
|
|
|
} |
909
|
|
|
} |
910
|
|
|
|
911
|
|
|
/** |
912
|
|
|
* Sets the no-cache header |
913
|
|
|
*/ |
914
|
|
|
protected function setHeaderNoCache($contentType = 'application/json') |
915
|
|
|
{ |
916
|
|
|
header("Content-Type: " . $contentType . "; charset=utf-8"); |
917
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
918
|
|
|
header("Cache-Control: no-store, no-cache, must-revalidate"); |
919
|
|
|
header("Cache-Control: post-check=0, pre-check=0", false); |
920
|
|
|
header("Pragma: no-cache"); |
921
|
|
|
} |
922
|
|
|
|
923
|
|
|
/** |
924
|
|
|
* Returns javascript function to support Add or Edit through Ajax |
925
|
|
|
* |
926
|
|
|
* @return string |
927
|
|
|
*/ |
928
|
|
|
protected function setJavascriptAddEditByAjax($tabName = 'tabStandard') |
929
|
|
|
{ |
930
|
|
|
return $this->setJavascriptContent(implode('', [ |
931
|
|
|
'function loadAE(action) {', |
932
|
|
|
'document.getElementById("' . $tabName . '").tabber.tabShow(1);', |
933
|
|
|
'$("#DynamicAddEditSpacer").load(action', |
934
|
|
|
'+"&specialHook[]=noHeader"', |
935
|
|
|
'+"&specialHook[]=noMenu"', |
936
|
|
|
'+"&specialHook[]=noContainer"', |
937
|
|
|
'+"&specialHook[]=noFooter"', |
938
|
|
|
');', |
939
|
|
|
'}', |
940
|
|
|
])); |
941
|
|
|
} |
942
|
|
|
|
943
|
|
|
/** |
944
|
|
|
* Returns javascript codes |
945
|
|
|
* |
946
|
|
|
* @param string $javascriptContent |
947
|
|
|
* @return string |
948
|
|
|
*/ |
949
|
|
|
protected function setJavascriptContent($javascriptContent) |
950
|
|
|
{ |
951
|
|
|
return '<script type="text/javascript">' . $javascriptContent . '</script>'; |
952
|
|
|
} |
953
|
|
|
|
954
|
|
|
/** |
955
|
|
|
* Builds up a confirmation dialog and return delection if Yes |
956
|
|
|
* |
957
|
|
|
* @return string |
958
|
|
|
*/ |
959
|
|
|
protected function setJavascriptDeleteWithConfirmation() |
960
|
|
|
{ |
961
|
|
|
return $this->setJavascriptContent(' function setQuest(a, b) { ' |
962
|
|
|
. 'c = a.indexOf("_"); switch(a.slice(0, c)) { ' |
963
|
|
|
. 'case \'delete\': ' |
964
|
|
|
. 'if (confirm(\'' . $this->lclMsgCmn('i18n_ActionDelete_ConfirmationQuestion') . '\')) { ' |
|
|
|
|
965
|
|
|
. 'window.location = document.location.protocol + "//" + ' |
966
|
|
|
. 'document.location.host + document.location.pathname + ' |
967
|
|
|
. '"?view=" + a + "&" + b; } break; } }'); |
968
|
|
|
} |
969
|
|
|
|
970
|
|
|
/** |
971
|
|
|
* Returns javascript link to a given file |
972
|
|
|
* |
973
|
|
|
* @param string $jsFileName |
974
|
|
|
* @return string |
975
|
|
|
*/ |
976
|
|
|
protected function setJavascriptFile($jsFileName, $hostsWithoutCDNrq = null) |
977
|
|
|
{ |
978
|
|
|
$sReturn = null; |
|
|
|
|
979
|
|
|
if (is_null($hostsWithoutCDNrq)) { |
980
|
|
|
$hostsWithoutCDNrq = []; |
981
|
|
|
} |
982
|
|
|
if (in_array($this->getClientRealIpAddress(), $hostsWithoutCDNrq)) { |
983
|
|
|
$sReturn = '<script type="text/javascript" src="' . $jsFileName . '"></script>'; |
984
|
|
|
} else { |
985
|
|
|
$patternFound = $this->setJavascriptFileCDN($jsFileName); |
|
|
|
|
986
|
|
|
$sReturn = '<script type="text/javascript" src="' . $patternFound[1] . '"></script>' |
987
|
|
|
. $patternFound[2]; |
988
|
|
|
} |
989
|
|
|
return $sReturn; |
990
|
|
|
} |
991
|
|
|
|
992
|
|
|
/** |
993
|
|
|
* Returns javascript codes from given file |
994
|
|
|
* |
995
|
|
|
* @param string $jsFileName |
996
|
|
|
* @return string |
997
|
|
|
*/ |
998
|
|
|
protected function setJavascriptFileContent($jsFileName) |
999
|
|
|
{ |
1000
|
|
|
$sReturn[] = '<script type="text/javascript"><!-- '; |
|
|
|
|
1001
|
|
|
$sReturn[] = file_get_contents($jsFileName, true); |
1002
|
|
|
$sReturn[] = ' //--></script>'; |
1003
|
|
|
return implode('', $sReturn); |
1004
|
|
|
} |
1005
|
|
|
|
1006
|
|
|
/** |
1007
|
|
|
* Creates all the child tags required to populate a SELECT tag |
1008
|
|
|
* |
1009
|
|
|
* @param array $aElements |
1010
|
|
|
* @param string|array $sDefaultValue |
1011
|
|
|
* @param array $features_array |
1012
|
|
|
* @return string |
1013
|
|
|
*/ |
1014
|
|
|
private function setOptionsForSelect($aElements, $sDefaultValue, $features_array = []) |
1015
|
|
|
{ |
1016
|
|
|
$string2return = ''; |
1017
|
|
|
if (is_array($features_array)) { |
1018
|
|
|
if (in_array('include_null', $features_array)) { |
1019
|
|
|
$string2return .= '<option value="NULL"> </option>'; |
1020
|
|
|
} |
1021
|
|
|
if (isset($features_array['defaultValue_isSubstring'])) { |
1022
|
|
|
$default_value_array = explode($features_array['defaultValue_isSubstring'], $sDefaultValue); |
1023
|
|
|
} |
1024
|
|
|
} |
1025
|
|
|
$current_group = null; |
1026
|
|
|
foreach ($aElements as $key => $value) { |
1027
|
|
|
if (isset($features_array['grouping'])) { |
1028
|
|
|
$temporary_string = substr($value, 0, strpos($value, $features_array['grouping']) + 1); |
1029
|
|
|
if ($current_group != $temporary_string) { |
1030
|
|
|
if ($current_group != '') { |
1031
|
|
|
$string2return .= '</optgroup>'; |
1032
|
|
|
} |
1033
|
|
|
$current_group = $temporary_string; |
1034
|
|
|
$string2return .= '<optgroup label="' |
1035
|
|
|
. str_replace($features_array['grouping'], '', $current_group) . '">'; |
1036
|
|
|
} |
1037
|
|
|
} else { |
1038
|
|
|
$current_group = ''; |
1039
|
|
|
} |
1040
|
|
|
$string2return .= '<option value="' . $key . '"'; |
1041
|
|
|
if (is_array($sDefaultValue)) { |
1042
|
|
|
if (in_array($key, $sDefaultValue)) { |
1043
|
|
|
$string2return .= ' selected="selected"'; |
1044
|
|
|
} |
1045
|
|
|
} else { |
1046
|
|
|
if (strcasecmp($key, $sDefaultValue) === 0) { |
1047
|
|
|
$string2return .= ' selected="selected"'; |
1048
|
|
|
} |
1049
|
|
|
if (isset($default_value_array) && is_array($default_value_array)) { |
1050
|
|
|
if (in_array($key, $default_value_array)) { |
1051
|
|
|
$string2return .= ' selected="selected"'; |
1052
|
|
|
} |
1053
|
|
|
} |
1054
|
|
|
} |
1055
|
|
|
if (array_key_exists('styleForOption', $features_array)) { |
1056
|
|
|
$string2return .= ' style="' . $features_array['style'] . '"'; |
1057
|
|
|
} |
1058
|
|
|
$string2return .= '>' . str_replace(['&', $current_group], ['&', ''], $value) . '</option>'; |
1059
|
|
|
} |
1060
|
|
|
if (isset($features_array['grouping'])) { |
1061
|
|
|
if ($current_group != '') { |
1062
|
|
|
$string2return .= '</optgroup>'; |
1063
|
|
|
} |
1064
|
|
|
} |
1065
|
|
|
return $string2return; |
1066
|
|
|
} |
1067
|
|
|
|
1068
|
|
|
/** |
1069
|
|
|
* Puts a given string into a specific short tag |
1070
|
|
|
* |
1071
|
|
|
* @param string $sTag |
1072
|
|
|
* @param array $features |
1073
|
|
|
* @return string |
1074
|
|
|
*/ |
1075
|
|
|
protected function setStringIntoShortTag($sTag, $features = null) |
1076
|
|
|
{ |
1077
|
|
|
$attributes = $this->buildAttributesForTag($features); |
|
|
|
|
1078
|
|
|
return '<' . $sTag . $this->buildAttributesForTag($features) |
1079
|
|
|
. (isset($features['dont_close']) ? '' : '/') . '>'; |
1080
|
|
|
} |
1081
|
|
|
|
1082
|
|
|
/** |
1083
|
|
|
* Puts a given string into a specific tag |
1084
|
|
|
* |
1085
|
|
|
* @param string $sString |
1086
|
|
|
* @param string $sTag |
1087
|
|
|
* @param array $features |
1088
|
|
|
* @return string |
1089
|
|
|
*/ |
1090
|
|
|
protected function setStringIntoTag($sString, $sTag, $features = null) |
1091
|
|
|
{ |
1092
|
|
|
return '<' . $sTag . $this->buildAttributesForTag($features) . '>' . $sString . '</' . $sTag . '>'; |
1093
|
|
|
} |
1094
|
|
|
|
1095
|
|
|
/** |
1096
|
|
|
* Generates a table cell |
1097
|
|
|
* |
1098
|
|
|
* @param array $aElements |
1099
|
|
|
* @param array $features |
1100
|
|
|
* @return string |
1101
|
|
|
*/ |
1102
|
|
|
private function setTableCell($aElements, $features = null) |
1103
|
|
|
{ |
1104
|
|
|
$sReturn = null; |
1105
|
|
|
foreach ($aElements as $key => $value) { |
1106
|
|
|
$value = str_replace(['& ', '\"', "\'"], ['& ', '"', "'"], $value); |
1107
|
|
|
if ((isset($features['grouping_cell'])) && ($features['grouping_cell'] == $key)) { |
|
|
|
|
1108
|
|
|
// just skip |
1109
|
|
|
} else { |
1110
|
|
|
$sReturn .= '<td '; |
1111
|
|
|
if (isset($features['column_formatting'][$key])) { |
1112
|
|
|
switch ($features['column_formatting'][$key]) { |
1113
|
|
|
case '@': |
1114
|
|
|
$sReturn .= 'style="text-align:left;">' . $value; |
1115
|
|
|
break; |
1116
|
|
|
case 'right': |
1117
|
|
|
$sReturn .= 'style="text-align:right;">' . $value; |
1118
|
|
|
break; |
1119
|
|
|
default: |
1120
|
|
|
$sReturn .= '???'; |
1121
|
|
|
break; |
1122
|
|
|
} |
1123
|
|
|
} else { |
1124
|
|
|
if (is_numeric($value)) { |
1125
|
|
|
if (substr($value, 0, 1) === '0') { |
1126
|
|
|
$sReturn .= 'style="text-align: right;">' . $value; |
1127
|
|
|
} else { |
1128
|
|
|
$decimals = 0; |
1129
|
|
|
if (isset($features['no_of_decimals'])) { |
1130
|
|
|
$decimals = $features['no_of_decimals']; |
1131
|
|
|
} |
1132
|
|
|
if (isset($features['decimals']) && array_key_exists($key, $features['decimals'])) { |
1133
|
|
|
$decimals = $features['decimals'][$key]; |
1134
|
|
|
} |
1135
|
|
|
$sReturn .= 'style="text-align: right;">'; |
1136
|
|
|
$sReturn .= $this->setNumberFormat($value, [ |
|
|
|
|
1137
|
|
|
'MinFractionDigits' => $decimals, |
1138
|
|
|
'MaxFractionDigits' => $decimals |
1139
|
|
|
]); |
1140
|
|
|
} |
1141
|
|
|
} else { |
1142
|
|
|
$outputet = false; |
1143
|
|
|
if ((strpos($value, '-') !== false) && (strlen($value) == 10)) { |
1144
|
|
|
if (preg_match("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $value, $regs)) { |
1145
|
|
|
$outputet = true; |
1146
|
|
|
$sReturn .= 'style="text-align:right;width: 10px;">' |
1147
|
|
|
. $regs[3] . '.' . $regs[2] . '.' . $regs[1]; |
1148
|
|
|
} |
1149
|
|
|
} |
1150
|
|
|
if (!$outputet) { |
1151
|
|
|
$sReturn .= 'style="text-align:left;">' . $value; |
1152
|
|
|
} |
1153
|
|
|
} |
1154
|
|
|
} |
1155
|
|
|
$sReturn .= '</td>'; |
1156
|
|
|
} |
1157
|
|
|
} |
1158
|
|
|
return $sReturn; |
1159
|
|
|
} |
1160
|
|
|
|
1161
|
|
|
/** |
1162
|
|
|
* Generates a table header |
1163
|
|
|
* |
1164
|
|
|
* @param array $aElements |
1165
|
|
|
* @param boolean $bHeadersBreaked |
1166
|
|
|
* @return string |
1167
|
|
|
*/ |
1168
|
|
|
private function setTableHeader($aElements, $bHeadersBreaked) |
1169
|
|
|
{ |
1170
|
|
|
if ($bHeadersBreaked) { |
1171
|
|
|
$aTableHeader = $this->setArrayToArrayKbr($aElements); |
|
|
|
|
1172
|
|
|
} else { |
1173
|
|
|
$aTableHeader = $aElements; |
1174
|
|
|
} |
1175
|
|
|
$sReturn[] = null; |
|
|
|
|
1176
|
|
|
foreach (array_keys($aTableHeader) as $value) { |
1177
|
|
|
$sReturn[] = $this->setStringIntoTag($value, 'th'); |
1178
|
|
|
} |
1179
|
|
|
return implode('', $sReturn); |
1180
|
|
|
} |
1181
|
|
|
|
1182
|
|
|
protected function setViewModernLinkAdd($identifier, $ftrs = null) |
1183
|
|
|
{ |
1184
|
|
|
$btnText = '<i class="fa fa-plus-square"> </i>' . ' ' . $this->lclMsgCmn('i18n_AddNewRecord'); |
|
|
|
|
1185
|
|
|
return $this->setStringIntoTag($btnText, 'a', [ |
1186
|
|
|
'href' => $this->setViewModernLinkAddUrl($identifier, $ftrs), |
1187
|
|
|
'style' => 'margin: 5px 0px 10px 0px; display: inline-block;', |
1188
|
|
|
]); |
1189
|
|
|
} |
1190
|
|
|
|
1191
|
|
|
protected function setViewModernLinkAddInjectedArguments($ftrs = null) |
1192
|
|
|
{ |
1193
|
|
|
$sArgmnts = ''; |
1194
|
|
|
if (isset($ftrs['injectAddArguments'])) { |
1195
|
|
|
foreach ($ftrs['injectAddArguments'] as $key => $value) { |
1196
|
|
|
$sArgmnts .= '&' . $key . '=' . $value; |
1197
|
|
|
} |
1198
|
|
|
} |
1199
|
|
|
return $sArgmnts; |
1200
|
|
|
} |
1201
|
|
|
|
1202
|
|
|
protected function setViewModernLinkAddUrl($identifier, $ftrs = null) |
1203
|
|
|
{ |
1204
|
|
|
$sArgmnts = $this->setViewModernLinkAddInjectedArguments($ftrs); |
1205
|
|
|
$rqst = new \Symfony\Component\HttpFoundation\Request; |
1206
|
|
|
$addingUrl = $rqst->server->get('PHP_SELF') . '?view=add_' . $identifier . $sArgmnts; |
1207
|
|
|
if (!isset($ftrs['NoAjax'])) { |
1208
|
|
|
$addingUrl = 'javascript:loadAE(\'' . $addingUrl . '\');'; |
1209
|
|
|
} |
1210
|
|
|
return $addingUrl; |
1211
|
|
|
} |
1212
|
|
|
|
1213
|
|
|
protected function updateDivTitleName($rememberGroupVal, $groupCounter) |
1214
|
|
|
{ |
1215
|
|
|
$jsContent = '$(document).ready(function() { $("#tab_' |
1216
|
|
|
. $this->cleanStringForId($rememberGroupVal) . '").attr("title", "' |
1217
|
|
|
. $rememberGroupVal . ' (' . $groupCounter . ')"); });'; |
1218
|
|
|
return $this->setJavascriptContent($jsContent); |
1219
|
|
|
} |
1220
|
|
|
} |
1221
|
|
|
|
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.