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
|
|
|
* usefull functions to get quick results |
33
|
|
|
* |
34
|
|
|
* @author Daniel Popiniuc |
35
|
|
|
*/ |
36
|
|
|
trait MySQLiAdvancedOutput |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
use DomComponentsByDanielGP, |
40
|
|
|
MySQLiByDanielGP; |
41
|
|
|
|
42
|
|
|
protected $advCache = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Establish Database and Table intended to work with |
46
|
|
|
* (in case the DB is ommited get the default one) |
47
|
|
|
* |
48
|
|
|
* @param string $tblSrc |
49
|
|
|
*/ |
50
|
|
|
private function establishDatabaseAndTable($tblSrc) |
51
|
|
|
{ |
52
|
|
|
if (strpos($tblSrc, '.') === false) { |
53
|
|
|
if (!defined('MYSQL_DATABASE')) { |
54
|
|
|
define('MYSQL_DATABASE', 'information_schema'); |
55
|
|
|
} |
56
|
|
|
return [$tblSrc, MYSQL_DATABASE]; |
57
|
|
|
} |
58
|
|
|
return explode('.', str_replace('`', '', $tblSrc)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function establishDefaultEnumSet($fldType) |
62
|
|
|
{ |
63
|
|
|
$dfltArray = [ |
64
|
|
|
'enum' => ['additional' => ['size' => 1], 'suffix' => ''], |
65
|
|
|
'set' => ['additional' => ['size' => 5, 'multiselect'], 'suffix' => '[]'], |
66
|
|
|
]; |
67
|
|
|
return $dfltArray[$fldType]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function getFieldCompletionType($details) |
71
|
|
|
{ |
72
|
|
|
$inputFeatures = ['display' => '***', 'ftrs' => ['title' => 'Mandatory', 'class' => 'inputMandatory']]; |
73
|
|
|
if ($details['IS_NULLABLE'] == 'YES') { |
74
|
|
|
$inputFeatures = ['display' => '~', 'ftrs' => ['title' => 'Optional', 'class' => 'inputOptional']]; |
75
|
|
|
} |
76
|
|
|
return $this->setStringIntoTag($inputFeatures['display'], 'span', $inputFeatures['ftrs']); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the name of a field for displaying |
81
|
|
|
* |
82
|
|
|
* @param array $details |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
private function getFieldNameForDisplay($details) |
86
|
|
|
{ |
87
|
|
|
$tableUniqueId = $details['TABLE_SCHEMA'] . '.' . $details['TABLE_NAME']; |
88
|
|
|
if ($details['COLUMN_COMMENT'] != '') { |
89
|
|
|
return $details['COLUMN_COMMENT']; |
90
|
|
|
} elseif (isset($this->advCache['tableStructureLocales'][$tableUniqueId][$details['COLUMN_NAME']])) { |
91
|
|
|
return $this->advCache['tableStructureLocales'][$tableUniqueId][$details['COLUMN_NAME']]; |
92
|
|
|
} |
93
|
|
|
return $details['COLUMN_NAME']; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns a Enum or Set field to use in form |
98
|
|
|
* |
99
|
|
|
* @param string $tblSrc |
100
|
|
|
* @param string $fldType |
101
|
|
|
* @param array $val |
102
|
|
|
* @param array $iar |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
private function getFieldOutputEnumSet($tblSrc, $fldType, $val, $iar = []) |
106
|
|
|
{ |
107
|
|
|
$adnlThings = $this->establishDefaultEnumSet($fldType); |
108
|
|
|
if (array_key_exists('readonly', $val)) { |
109
|
|
|
return $this->getFieldOutputEnumSetReadOnly($val, $adnlThings); |
110
|
|
|
} |
111
|
|
|
$inAdtnl = $adnlThings['additional']; |
112
|
|
|
if ($iar !== []) { |
113
|
|
|
$inAdtnl = array_merge($inAdtnl, $iar); |
114
|
|
|
} |
115
|
|
|
$vlSlct = explode(',', $this->getFieldValue($val)); |
116
|
|
|
$slctOptns = $this->getSetOrEnum2Array($tblSrc, $val['COLUMN_NAME']); |
117
|
|
|
return $this->setArrayToSelect($slctOptns, $vlSlct, $val['COLUMN_NAME'] . $adnlThings['suffix'], $inAdtnl); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
private function getFieldOutputEnumSetReadOnly($val, $adnlThings) |
121
|
|
|
{ |
122
|
|
|
$inputFeatures = [ |
123
|
|
|
'name' => $val['COLUMN_NAME'] . $adnlThings['suffix'], |
124
|
|
|
'id' => $val['COLUMN_NAME'], |
125
|
|
|
'readonly' => 'readonly', |
126
|
|
|
'class' => 'input_readonly', |
127
|
|
|
'size' => 50, |
128
|
|
|
'value' => $this->getFieldValue($val), |
129
|
|
|
]; |
130
|
|
|
return $this->setStringIntoShortTag('input', $inputFeatures); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Returns a Numeric field 2 use in a form |
135
|
|
|
* |
136
|
|
|
* @param string $tblSrc |
137
|
|
|
* @param array $value |
138
|
|
|
* @param array $features |
|
|
|
|
139
|
|
|
* @param array $iar |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
private function getFieldOutputNumeric($tblSrc, $value, $iar = []) |
143
|
|
|
{ |
144
|
|
|
if ($value['EXTRA'] == 'auto_increment') { |
145
|
|
|
if ($this->getFieldValue($value) == '') { |
146
|
|
|
return $this->setStringIntoTag('auto-numar', 'span', [ |
147
|
|
|
'id' => $value['COLUMN_NAME'], |
148
|
|
|
'style' => 'font-style:italic;', |
149
|
|
|
]); |
150
|
|
|
} |
151
|
|
|
$inAdtnl = [ |
152
|
|
|
'type' => 'hidden', |
153
|
|
|
'name' => $value['COLUMN_NAME'], |
154
|
|
|
'id' => $value['COLUMN_NAME'], |
155
|
|
|
'value' => $this->getFieldValue($value), |
156
|
|
|
]; |
157
|
|
|
if ($iar !== []) { |
158
|
|
|
$inAdtnl = array_merge($inAdtnl, $iar); |
159
|
|
|
} |
160
|
|
|
return $this->setStringIntoTag($this->getFieldValue($value), 'b') |
161
|
|
|
. $this->setStringIntoShortTag('input', $inAdtnl); |
162
|
|
|
} |
163
|
|
|
$database = $this->advCache['workingDatabase']; |
164
|
|
|
$fkArray = $this->getForeignKeysToArray($database, $tblSrc, $value['COLUMN_NAME']); |
165
|
|
|
if (is_null($fkArray)) { |
166
|
|
|
$fldNos = $this->setFieldNumbers($value); |
167
|
|
|
$inAdtnl = [ |
168
|
|
|
'type' => 'text', |
169
|
|
|
'name' => $value['COLUMN_NAME'], |
170
|
|
|
'id' => $value['COLUMN_NAME'], |
171
|
|
|
'value' => $this->getFieldValue($value), |
172
|
|
|
'size' => min(50, $fldNos['l']), |
173
|
|
|
'maxlength' => min(50, $fldNos['l']) |
174
|
|
|
]; |
175
|
|
|
if ($iar !== []) { |
176
|
|
|
$inAdtnl = array_merge($inAdtnl, $iar); |
177
|
|
|
} |
178
|
|
|
return $this->setStringIntoShortTag('input', $inAdtnl); |
179
|
|
|
} |
180
|
|
|
$query = $this->sQueryGenericSelectKeyValue([ |
181
|
|
|
$fkArray[$value['COLUMN_NAME']][1], |
182
|
|
|
$fkArray[$value['COLUMN_NAME']][2], |
183
|
|
|
$fkArray[$value['COLUMN_NAME']][0] |
184
|
|
|
]); |
185
|
|
|
$selectOptions = $this->setMySQLquery2Server($query, 'array_key_value')['result']; |
186
|
|
|
$selectValue = $this->getFieldValue($value); |
187
|
|
|
$inAdtnl = ['size' => 1]; |
188
|
|
|
if ($value['IS_NULLABLE'] == 'YES') { |
189
|
|
|
$inAdtnl = array_merge($inAdtnl, ['include_null']); |
190
|
|
|
} |
191
|
|
|
if ($iar !== []) { |
192
|
|
|
$inAdtnl = array_merge($inAdtnl, $iar); |
193
|
|
|
} |
194
|
|
|
return $this->setArrayToSelect($selectOptions, $selectValue, $value['COLUMN_NAME'], $inAdtnl); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Returns a Char field 2 use in a form |
199
|
|
|
* |
200
|
|
|
* @param string $tbl |
201
|
|
|
* @param string $fieldType |
202
|
|
|
* @param array $value |
203
|
|
|
* @param array $features |
|
|
|
|
204
|
|
|
* @param array $iar |
205
|
|
|
* @return string |
206
|
|
|
*/ |
207
|
|
|
private function getFieldOutputText($tbl, $fieldType, $value, $iar = []) |
208
|
|
|
{ |
209
|
|
|
if (!in_array($fieldType, ['char', 'tinytext', 'varchar'])) { |
210
|
|
|
return ''; |
211
|
|
|
} |
212
|
|
|
$database = $this->advCache['workingDatabase']; |
213
|
|
|
if (strpos($tbl, '`.`')) { |
214
|
|
|
$database = substr($tbl, 0, strpos($tbl, '`.`')); |
215
|
|
|
} |
216
|
|
|
if (($tbl != 'user_rights') && ($value['COLUMN_NAME'] != 'eid')) { |
217
|
|
|
$foreignKeysArray = $this->getForeignKeysToArray($database, $tbl, $value['COLUMN_NAME']); |
218
|
|
|
if (is_null($foreignKeysArray)) { |
219
|
|
|
unset($foreignKeysArray); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
if (isset($foreignKeysArray)) { |
223
|
|
|
return $this->getFieldOutputTextFK($foreignKeysArray, $value, $iar); |
224
|
|
|
} |
225
|
|
|
return $this->getFieldOutputTextNonFK($value, $iar); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
private function getFieldOutputTextFK($foreignKeysArray, $value, $iar) |
229
|
|
|
{ |
230
|
|
|
$query = $this->storedQuery('generic_select_key_value', [ |
|
|
|
|
231
|
|
|
$foreignKeysArray[$value['COLUMN_NAME']][1], |
232
|
|
|
$foreignKeysArray[$value['COLUMN_NAME']][2], |
233
|
|
|
$foreignKeysArray[$value['COLUMN_NAME']][0] |
234
|
|
|
]); |
235
|
|
|
$inAdtnl = ['size' => 1]; |
236
|
|
|
if ($value['IS_NULLABLE'] == 'YES') { |
237
|
|
|
$inAdtnl = array_merge($inAdtnl, ['include_null']); |
238
|
|
|
} |
239
|
|
|
if ($iar !== []) { |
240
|
|
|
$inAdtnl = array_merge($inAdtnl, $iar); |
241
|
|
|
} |
242
|
|
|
$slct = [ |
243
|
|
|
'Options' => $this->setQuery2Server($query, 'array_key_value'), |
|
|
|
|
244
|
|
|
'Value' => $this->getFieldValue($value), |
245
|
|
|
]; |
246
|
|
|
return $this->setArrayToSelect($slct['Options'], $slct['Value'], $value['COLUMN_NAME'], $inAdtnl); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Returns a Text field 2 use in a form |
251
|
|
|
* |
252
|
|
|
* @param string $table_source |
|
|
|
|
253
|
|
|
* @param string $fieldType |
254
|
|
|
* @param array $value |
255
|
|
|
* @param array $features |
|
|
|
|
256
|
|
|
* @param array $iar |
257
|
|
|
* @return string |
258
|
|
|
*/ |
259
|
|
|
private function getFieldOutputTextLarge($fieldType, $value, $iar = []) |
260
|
|
|
{ |
261
|
|
|
if (!in_array($fieldType, ['blob', 'text'])) { |
262
|
|
|
return ''; |
263
|
|
|
} |
264
|
|
|
$inAdtnl = [ |
265
|
|
|
'name' => $value['COLUMN_NAME'], |
266
|
|
|
'id' => $value['COLUMN_NAME'], |
267
|
|
|
'rows' => 4, |
268
|
|
|
'cols' => 55, |
269
|
|
|
]; |
270
|
|
|
if ($iar !== []) { |
271
|
|
|
$inAdtnl = array_merge($inAdtnl, $iar); |
272
|
|
|
} |
273
|
|
|
return $this->setStringIntoTag($this->getFieldValue($value), 'textarea', $inAdtnl); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
private function getFieldOutputTextNonFK($value, $iar) |
277
|
|
|
{ |
278
|
|
|
$fldNos = $this->setFieldNumbers($value); |
279
|
|
|
$inAdtnl = [ |
280
|
|
|
'type' => ($value['COLUMN_NAME'] == 'password' ? 'password' : 'text'), |
281
|
|
|
'name' => $value['COLUMN_NAME'], |
282
|
|
|
'id' => $value['COLUMN_NAME'], |
283
|
|
|
'size' => min(30, $fldNos['l']), |
284
|
|
|
'maxlength' => min(255, $fldNos['l']), |
285
|
|
|
'value' => $this->getFieldValue($value), |
286
|
|
|
]; |
287
|
|
|
if ($iar !== []) { |
288
|
|
|
$inAdtnl = array_merge($inAdtnl, $iar); |
289
|
|
|
} |
290
|
|
|
return $this->setStringIntoShortTag('input', $inAdtnl); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
private function getFieldOutputTT($value, $szN, $iar = []) |
294
|
|
|
{ |
295
|
|
|
$inAdtnl = [ |
296
|
|
|
'id' => $value['COLUMN_NAME'], |
297
|
|
|
'maxlength' => $szN, |
298
|
|
|
'name' => $value['COLUMN_NAME'], |
299
|
|
|
'size' => $szN, |
300
|
|
|
'type' => 'text', |
301
|
|
|
'value' => $this->getFieldValue($value), |
302
|
|
|
]; |
303
|
|
|
if ($iar !== []) { |
304
|
|
|
$inAdtnl = array_merge($inAdtnl, $iar); |
305
|
|
|
} |
306
|
|
|
return $this->setStringIntoShortTag('input', $inAdtnl); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Returns a Time field 2 use in a form |
311
|
|
|
* |
312
|
|
|
* @param array $value |
313
|
|
|
* @param array $iar |
314
|
|
|
* @return string |
315
|
|
|
*/ |
316
|
|
|
private function getFieldOutputTime($value, $iar = []) |
317
|
|
|
{ |
318
|
|
|
return $this->getFieldOutputTT($value, 8, $iar); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Returns a Timestamp field 2 use in a form |
323
|
|
|
* |
324
|
|
|
* @param array $value |
325
|
|
|
* @param array $iar |
326
|
|
|
* @return string |
327
|
|
|
*/ |
328
|
|
|
private function getFieldOutputTimestamp($value, $iar = []) |
329
|
|
|
{ |
330
|
|
|
$input = $this->getFieldOutputTT($value, 19, $iar); |
331
|
|
|
if (!array_key_exists('readonly', $iar)) { |
332
|
|
|
$input .= $this->setCalendarControlWithTime($value['COLUMN_NAME']); |
333
|
|
|
} |
334
|
|
|
return $input; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* Returns a Year field 2 use in a form |
339
|
|
|
* |
340
|
|
|
* @param array $details |
341
|
|
|
* @param array $iar |
342
|
|
|
* @return string |
343
|
|
|
*/ |
344
|
|
|
private function getFieldOutputYear($details, $iar) |
345
|
|
|
{ |
346
|
|
|
for ($c = 1901; $c <= 2155; $c++) { |
347
|
|
|
$listOfValues[$c] = $c; |
|
|
|
|
348
|
|
|
} |
349
|
|
|
if ($iar == []) { |
350
|
|
|
$slDflt = $this->getFieldValue($details); |
351
|
|
|
return $this->setArrayToSelect($listOfValues, $slDflt, $details['COLUMN_NAME'], ['size' => 1]); |
|
|
|
|
352
|
|
|
} |
353
|
|
|
return $this->getFieldOutputText('varchar', $details, $iar); |
|
|
|
|
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Returns given value for a field from $_REQUEST |
358
|
|
|
* |
359
|
|
|
* @param array $details |
360
|
|
|
* @return string |
361
|
|
|
*/ |
362
|
|
|
private function getFieldValue($details) |
363
|
|
|
{ |
364
|
|
|
$this->initializeSprGlbAndSession(); |
365
|
|
|
$rqCN = $this->tCmnRequest->request->get($details['COLUMN_NAME']); |
366
|
|
|
if (!is_null($rqCN)) { |
367
|
|
|
if (($details['IS_NULLABLE'] == 'YES') && ($rqCN == '')) { |
368
|
|
|
return 'NULL'; |
369
|
|
|
} |
370
|
|
|
return $rqCN; |
371
|
|
|
} |
372
|
|
|
return $this->getFieldValueWithoutUserInput($details); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* Handles field value ignoring any input from the user |
377
|
|
|
* |
378
|
|
|
* @param array $details |
379
|
|
|
* @return string |
380
|
|
|
*/ |
381
|
|
|
private function getFieldValueWithoutUserInput($details) |
382
|
|
|
{ |
383
|
|
|
if ($details['COLUMN_DEFAULT'] === null) { |
384
|
|
|
if ($details['IS_NULLABLE'] == 'YES') { |
385
|
|
|
return 'NULL'; |
386
|
|
|
} |
387
|
|
|
return ''; |
388
|
|
|
} |
389
|
|
|
return $details['COLUMN_DEFAULT']; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Returns an array with fields referenced by a Foreign key |
394
|
|
|
* |
395
|
|
|
* @param object $db |
|
|
|
|
396
|
|
|
* @param string $database |
397
|
|
|
* @param string $tblName |
398
|
|
|
* @param string $onlyCols |
|
|
|
|
399
|
|
|
* @return array |
400
|
|
|
*/ |
401
|
|
|
private function getForeignKeysToArray($database, $tblName, $onlyCol = '') |
402
|
|
|
{ |
403
|
|
|
if (strpos($tblName, '.`')) { |
404
|
|
|
$tblName = substr($tblName, strpos($tblName, '.`') + 2, 64); |
405
|
|
|
} |
406
|
|
|
$this->setTableForeginKeyCache($database, $tblName); |
407
|
|
|
$array2return = null; |
408
|
|
|
if (isset($this->advCache['tableFKs'][$database][$tblName])) { |
409
|
|
|
foreach ($this->advCache['tableFKs'][$database][$tblName] as $value) { |
410
|
|
|
if ($value['COLUMN_NAME'] == $onlyCol) { |
411
|
|
|
$query = $this->sQueryMySqlColumns([ |
412
|
|
|
'TABLE_SCHEMA' => $value['REFERENCED_TABLE_SCHEMA'], |
413
|
|
|
'TABLE_NAME' => $value['REFERENCED_TABLE_NAME'], |
414
|
|
|
'DATA_TYPE' => [ |
415
|
|
|
'char', |
416
|
|
|
'varchar', |
417
|
|
|
'text', |
418
|
|
|
], |
419
|
|
|
]); |
420
|
|
|
$targetTblTxtFlds = $this->setMySQLquery2Server($query, 'full_array_key_numbered')['result']; |
421
|
|
|
$significance = $targetTblTxtFlds[0]['COLUMN_NAME']; |
422
|
|
|
unset($targetTblTxtFlds); |
423
|
|
|
$array2return[$onlyCol] = [ |
424
|
|
|
'`' . implode('`.`', [ |
425
|
|
|
$value['REFERENCED_TABLE_SCHEMA'], |
426
|
|
|
$value['REFERENCED_TABLE_NAME'], |
427
|
|
|
]) . '`', |
428
|
|
|
$value['REFERENCED_COLUMN_NAME'], |
429
|
|
|
'`' . $significance . '`', |
430
|
|
|
]; |
431
|
|
|
} |
432
|
|
|
} |
433
|
|
|
} |
434
|
|
|
return $array2return; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
private function getLabel($details) |
438
|
|
|
{ |
439
|
|
|
return $this->setStringIntoTag($this->getFieldNameForDisplay($details), 'span', ['class' => 'fake_label']); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Returns an array with possible values of a SET or ENUM column |
444
|
|
|
* |
445
|
|
|
* @param string $refTbl |
446
|
|
|
* @param string $refCol |
447
|
|
|
* @return array |
448
|
|
|
*/ |
449
|
|
|
protected function getSetOrEnum2Array($refTbl, $refCol) |
450
|
|
|
{ |
451
|
|
|
if ((strpos($refTbl, '`') !== false) && (substr($refTbl, 0, 1) != '`')) { |
452
|
|
|
$refTbl = '`' . $refTbl . '`'; |
453
|
|
|
} |
454
|
|
|
$dat = $this->establishDatabaseAndTable($refTbl); |
455
|
|
|
foreach ($this->advCache['tableStructureCache'][$dat[0]][$dat[1]] as $value) { |
456
|
|
|
if ($value['COLUMN_NAME'] == $refCol) { |
457
|
|
|
$clndVls = explode(',', str_replace([$value['DATA_TYPE'], '(', "'", ')'], '', $value['COLUMN_TYPE'])); |
458
|
|
|
$enmVls = array_combine($clndVls, $clndVls); |
459
|
|
|
if ($value['IS_NULLABLE'] == 'YES') { |
460
|
|
|
$enmVls['NULL'] = ''; |
461
|
|
|
} |
462
|
|
|
} |
463
|
|
|
} |
464
|
|
|
ksort($enmVls); |
465
|
|
|
return $enmVls; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Returns a timestamp field value |
470
|
|
|
* |
471
|
|
|
* @param array $dtl |
472
|
|
|
* @return array |
473
|
|
|
*/ |
474
|
|
|
private function getTimestamping($dtl) |
475
|
|
|
{ |
476
|
|
|
$inM = $this->setStringIntoTag($this->getFieldValue($dtl), 'span'); |
477
|
|
|
if (in_array($this->getFieldValue($dtl), ['', 'CURRENT_TIMESTAMP', 'NULL'])) { |
478
|
|
|
$mCN = [ |
479
|
|
|
'InsertDateTime' => 'data/timpul ad. informatiei', |
480
|
|
|
'ModificationDateTime' => 'data/timpul modificarii inf.', |
481
|
|
|
'modification_datetime' => 'data/timpul modificarii inf.', |
482
|
|
|
]; |
483
|
|
|
if (array_key_exists($dtl['COLUMN_NAME'], $mCN)) { |
484
|
|
|
$inM = $this->setStringIntoTag($mCN[$dtl['COLUMN_NAME']], 'span', ['style' => 'font-style:italic;']); |
485
|
|
|
} |
486
|
|
|
} |
487
|
|
|
return ['label' => $this->getLabel($dtl), 'input' => $inM]; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Manages features flag |
492
|
|
|
* |
493
|
|
|
* @param string $fieldName |
494
|
|
|
* @param array $features |
495
|
|
|
* @return string |
496
|
|
|
*/ |
497
|
|
|
private function handleFeatures($fieldName, $features) |
498
|
|
|
{ |
499
|
|
|
$rOly = $this->handleFeaturesSingle($fieldName, $features, 'readonly'); |
500
|
|
|
$rDbld = $this->handleFeaturesSingle($fieldName, $features, 'disabled'); |
501
|
|
|
$rNl = []; |
502
|
|
|
if (isset($features['include_null']) && in_array($fieldName, $features['include_null'])) { |
503
|
|
|
$rNl = ['include_null']; |
504
|
|
|
} |
505
|
|
|
return array_merge([], $rOly, $rDbld, $rNl); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
private function handleFeaturesSingle($fieldName, $features, $featureKey) |
509
|
|
|
{ |
510
|
|
|
$fMap = [ |
511
|
|
|
'readonly' => ['readonly', 'class', 'input_readonly'], |
512
|
|
|
'disabled' => ['disabled'] |
513
|
|
|
]; |
514
|
|
|
$aReturn = []; |
515
|
|
|
if (array_key_exists($featureKey, $features)) { |
516
|
|
|
if (array_key_exists($fieldName, $features[$featureKey])) { |
517
|
|
|
$aReturn[$featureKey][$fMap[$featureKey][0]] = $fMap[$featureKey][0]; |
518
|
|
|
if (count($fMap[$featureKey]) > 1) { |
519
|
|
|
$aReturn[$featureKey][$fMap[$featureKey][1]] = $fMap[$featureKey][2]; |
520
|
|
|
} |
521
|
|
|
} |
522
|
|
|
} |
523
|
|
|
return $aReturn; |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* Returns a generic form based on a given table |
528
|
|
|
* |
529
|
|
|
* @param string $tblSrc Table Source |
530
|
|
|
* @param array $feat |
531
|
|
|
* @param string/array $hiddenInfo List of hidden fields |
|
|
|
|
532
|
|
|
* |
533
|
|
|
* @return string Form to add/modify detail for a single row within a table |
534
|
|
|
*/ |
535
|
|
|
protected function setFormGenericSingleRecord($tblSrc, $feat, $hiddenInfo = '') |
536
|
|
|
{ |
537
|
|
|
echo $this->setStringIntoTag('', 'div', [ |
538
|
|
|
'id' => 'loading' |
539
|
|
|
]); // Ajax container |
540
|
|
|
if (strpos($tblSrc, '.') !== false) { |
541
|
|
|
$tblSrc = explode('.', str_replace('`', '', $tblSrc))[1]; |
542
|
|
|
} |
543
|
|
|
$this->setTableCache($tblSrc); // will populate $this->advCache['tableStructureCache'][$dt[0]][$dt[1]] |
|
|
|
|
544
|
|
|
if (count($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc]) != 0) { |
545
|
|
|
foreach ($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc] as $value) { |
546
|
|
|
$sReturn[] = $this->setNeededField($tblSrc, $value, $feat); |
|
|
|
|
547
|
|
|
} |
548
|
|
|
} |
549
|
|
|
$btn[] = $this->setStringIntoShortTag('input', [ |
|
|
|
|
550
|
|
|
'type' => 'submit', |
551
|
|
|
'id' => 'submit', |
552
|
|
|
'style' => 'margin-left:220px;', |
553
|
|
|
'value' => $this->lclMsgCmn('i18n_Form_ButtonSave'), |
554
|
|
|
]); |
555
|
|
|
$adtnlScriptAfterForm = $this->setJavascriptContent(implode('', [ |
556
|
|
|
'$(document).ready(function(){', |
557
|
|
|
'$("form#' . $feat['id'] . '").submit(function(){', |
558
|
|
|
'$("input").attr("readonly", true);', |
559
|
|
|
'$("input[type=submit]").attr("disabled", "disabled");', |
560
|
|
|
'$("input[type=submit]").attr("value", "' . $this->lclMsgCmn('i18n_Form_ButtonSaving') . '");', |
561
|
|
|
'});', |
562
|
|
|
'});', |
563
|
|
|
])); |
564
|
|
|
if (isset($feat['insertAndUpdate'])) { |
565
|
|
|
$btn[] = $this->setStringIntoShortTag('input', [ |
566
|
|
|
'type' => 'hidden', |
567
|
|
|
'id' => 'insertAndUpdate', |
568
|
|
|
'name' => 'insertAndUpdate', |
569
|
|
|
'value' => 'insertAndUpdate' |
570
|
|
|
]); |
571
|
|
|
} |
572
|
|
|
$sReturn[] = $this->setStringIntoTag(implode('', $btn), 'div'); |
|
|
|
|
573
|
|
|
if (isset($hiddenInfo)) { |
574
|
|
|
if (is_array($hiddenInfo)) { |
575
|
|
|
foreach ($hiddenInfo as $key => $value) { |
576
|
|
|
$hiddenInput = $this->setStringIntoShortTag('input', [ |
577
|
|
|
'type' => 'hidden', |
578
|
|
|
'name' => $key, |
579
|
|
|
'id' => $key, |
580
|
|
|
'value' => $value, |
581
|
|
|
]); |
582
|
|
|
$sReturn[] = $this->setStringIntoTag($hiddenInput, 'div'); |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
} |
586
|
|
|
return $this->setStringIntoTag(implode('', $sReturn), 'form', [ |
587
|
|
|
'id' => $feat['id'], |
588
|
|
|
'action' => $feat['action'], |
589
|
|
|
'method' => $feat['method'] |
590
|
|
|
]) |
591
|
|
|
. $adtnlScriptAfterForm; |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
protected function setTableLocaleFields($localizationStrings) |
595
|
|
|
{ |
596
|
|
|
$this->advCache['tableStructureLocales'] = $localizationStrings; |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
/** |
600
|
|
|
* Analyse the field and returns the proper line 2 use in forms |
601
|
|
|
* |
602
|
|
|
* @param string $tableSource |
603
|
|
|
* @param array $details |
604
|
|
|
* @param array $features |
605
|
|
|
* @return string|array |
606
|
|
|
*/ |
607
|
|
|
private function setNeededField($tableSource, $details, $features) |
|
|
|
|
608
|
|
|
{ |
609
|
|
|
if (isset($features['hidden'])) { |
610
|
|
|
if (in_array($details['COLUMN_NAME'], $features['hidden'])) { |
611
|
|
|
return null; |
612
|
|
|
} |
613
|
|
|
} |
614
|
|
|
$fieldLabel = $this->getFieldNameForDisplay($details); |
615
|
|
|
if ($fieldLabel == 'hidden') { |
616
|
|
|
return null; |
617
|
|
|
} |
618
|
|
|
switch ($details['COLUMN_NAME']) { |
619
|
|
|
case 'host': |
620
|
|
|
$sReturn['label'] = $this->setStringIntoTag('Numele calculatorului', 'label', [ |
|
|
|
|
621
|
|
|
'for' => $details['COLUMN_NAME'] |
622
|
|
|
]); |
623
|
|
|
$sReturn['input'] = $this->setStringIntoShortTag('input', [ |
624
|
|
|
'type' => 'input', |
625
|
|
|
'size' => 15, |
626
|
|
|
'readonly' => 'readonly', |
627
|
|
|
'value' => gethostbyaddr($_SERVER['REMOTE_ADDR']) |
628
|
|
|
]); |
629
|
|
|
break; |
630
|
|
|
case 'InsertDateTime': |
631
|
|
|
case 'modification_datetime': |
632
|
|
|
case 'ModificationDateTime': |
633
|
|
|
$sReturn = call_user_func_array([$this, 'getTimestamping'], [$details]); |
634
|
|
|
break; |
635
|
|
|
default: |
636
|
|
|
$aLabel = [ |
637
|
|
|
'for' => $details['COLUMN_NAME'], |
638
|
|
|
'id' => $details['COLUMN_NAME'] . '_label' |
639
|
|
|
]; |
640
|
|
|
if (isset($features['disabled'])) { |
641
|
|
|
if (in_array($details['COLUMN_NAME'], $features['disabled'])) { |
642
|
|
|
$aLabel = array_merge($aLabel, ['style' => 'color: grey;']); |
643
|
|
|
} |
644
|
|
|
} |
645
|
|
|
$sReturn['label'] = $this->setStringIntoTag($fieldLabel, 'label', $aLabel); |
|
|
|
|
646
|
|
|
$result = $this->setNeededFieldByType($tableSource, $details, $features); |
647
|
|
|
if ($details['COLUMN_NAME'] == 'ChoiceId') { |
648
|
|
|
$result = $this->setStringIntoShortTag('input', [ |
649
|
|
|
'type' => 'text', |
650
|
|
|
'name' => $details['COLUMN_NAME'], |
651
|
|
|
'value' => $_REQUEST[$details['COLUMN_NAME']] |
652
|
|
|
]); |
653
|
|
|
} |
654
|
|
|
$sReturn['input'] = $result; |
655
|
|
|
break; |
656
|
|
|
} |
657
|
|
|
$finalReturn[] = $sReturn['label']; |
|
|
|
|
658
|
|
|
$finalReturn[] = $this->setStringIntoTag($sReturn['input'], 'span', ['class' => 'labell']); |
659
|
|
|
$wrkDb = $this->advCache['workingDatabase']; |
660
|
|
|
if (isset($this->tableFKsCache[$wrkDb][$tableSource])) { |
|
|
|
|
661
|
|
|
if (in_array($details['COLUMN_NAME'], $this->advCache['FKcol'][$wrkDb][$tableSource])) { |
662
|
|
|
$finalReturn[] = $this->getFieldLength($details); |
|
|
|
|
663
|
|
|
} |
664
|
|
|
} |
665
|
|
|
return $this->setStringIntoTag(implode('', $finalReturn), 'div'); |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* Analyse the field type and returns the proper lines 2 use in forms |
670
|
|
|
* |
671
|
|
|
* @param string $tblName |
672
|
|
|
* @param array $details |
673
|
|
|
* @param array $features |
674
|
|
|
* @return string|array |
675
|
|
|
*/ |
676
|
|
|
private function setNeededFieldByType($tblName, $details, $features) |
677
|
|
|
{ |
678
|
|
|
$sReturn = null; |
679
|
|
|
if (isset($features['special']) && isset($features['special'][$details['COLUMN_NAME']])) { |
680
|
|
|
$slctOpt = $this->setQuery2Server($features['special'][$details['COLUMN_NAME']], 'array_key_value'); |
|
|
|
|
681
|
|
|
$sReturn = $this->setArrayToSelect($slctOpt, $this->getFieldValue($details), $details['COLUMN_NAME'], [ |
682
|
|
|
'size' => 1 |
683
|
|
|
]); |
684
|
|
|
} else { |
685
|
|
|
$iar = $this->handleFeatures($details['COLUMN_NAME'], $features); |
686
|
|
|
switch ($details['DATA_TYPE']) { |
687
|
|
|
case 'bigint': |
688
|
|
|
case 'int': |
689
|
|
|
case 'mediumint': |
690
|
|
|
case 'smallint': |
691
|
|
|
case 'tinyint': |
692
|
|
|
case 'float': |
693
|
|
|
case 'double': |
694
|
|
|
case 'decimal': |
695
|
|
|
case 'numeric': |
696
|
|
|
$sReturn = $this->getFieldOutputNumeric($tblName, $details, $iar); |
697
|
|
|
break; |
698
|
|
|
case 'char': |
699
|
|
|
case 'tinytext': |
700
|
|
|
case 'varchar': |
701
|
|
|
$sReturn = $this->getFieldOutputText($tblName, $details['DATA_TYPE'], $details, $iar); |
702
|
|
|
break; |
703
|
|
|
case 'date': |
704
|
|
|
$sReturn = $this->getFieldOutputDate($details['DATA_TYPE'], $details, $iar); |
|
|
|
|
705
|
|
|
break; |
706
|
|
|
case 'datetime': |
707
|
|
|
case 'timestamp': |
708
|
|
|
$sReturn = $this->getFieldOutputTimestamp($details, $iar); |
709
|
|
|
break; |
710
|
|
|
case 'enum': |
711
|
|
|
case 'set': |
712
|
|
|
$sReturn = $this->getFieldOutputEnumSet($tblName, $details['DATA_TYPE'], $details, $iar); |
713
|
|
|
break; |
714
|
|
|
case 'text': |
715
|
|
|
case 'blob': |
716
|
|
|
$sReturn = $this->getFieldOutputTextLarge($details['DATA_TYPE'], $details, $iar); |
717
|
|
|
break; |
718
|
|
|
case 'time': |
719
|
|
|
$sReturn = $this->getFieldOutputTime($details, $iar); |
720
|
|
|
break; |
721
|
|
|
case 'year': |
722
|
|
|
$sReturn = $this->getFieldOutputYear($details, $iar); |
723
|
|
|
break; |
724
|
|
|
} |
725
|
|
|
} |
726
|
|
|
return $this->getFieldCompletionType($details) . $sReturn; |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
/** |
730
|
|
|
* create a Cache for given table to use it in many places |
731
|
|
|
* |
732
|
|
|
* @param type $tblSrc |
733
|
|
|
*/ |
734
|
|
|
private function setTableCache($tblSrc) |
735
|
|
|
{ |
736
|
|
|
$dat = $this->establishDatabaseAndTable($tblSrc); |
737
|
|
|
if (!isset($this->advCache['tableStructureCache'][$dat[0]][$dat[1]])) { |
738
|
|
|
switch ($dat[1]) { |
739
|
|
|
case 'user_rights': |
740
|
|
|
$this->advCache['workingDatabase'] = 'usefull_security'; |
741
|
|
|
break; |
742
|
|
|
default: |
743
|
|
|
$this->advCache['workingDatabase'] = $dat[0]; |
744
|
|
|
break; |
745
|
|
|
} |
746
|
|
|
$this->advCache['tableStructureCache'][$dat[0]][$dat[1]] = $this->getMySQLlistColumns([ |
747
|
|
|
'TABLE_SCHEMA' => $dat[0], |
748
|
|
|
'TABLE_NAME' => $dat[1], |
749
|
|
|
]); |
750
|
|
|
$this->setTableForeginKeyCache($dat[0], $dat[1]); |
751
|
|
|
} |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
private function setTableForeginKeyCache($dbName, $tblName) |
755
|
|
|
{ |
756
|
|
|
$frgnKs = $this->getMySQLlistIndexes([ |
757
|
|
|
'TABLE_SCHEMA' => $dbName, |
758
|
|
|
'TABLE_NAME' => $tblName, |
759
|
|
|
'REFERENCED_TABLE_NAME' => 'NOT NULL', |
760
|
|
|
]); |
761
|
|
|
if (!is_null($frgnKs)) { |
762
|
|
|
$this->advCache['tableFKs'][$dbName][$tblName] = $frgnKs; |
763
|
|
|
$this->advCache['FKcol'][$dbName][$tblName] = array_column($frgnKs, 'COLUMN_NAME', 'CONSTRAINT_NAME'); |
764
|
|
|
} |
765
|
|
|
} |
766
|
|
|
|
767
|
|
|
private function setViewDeleteFeedbacks() |
768
|
|
|
{ |
769
|
|
|
return [ |
770
|
|
|
'Confirmation' => $this->lclMsgCmn('i18n_Action_Confirmation'), |
771
|
|
|
'Failed' => $this->lclMsgCmn('i18n_ActionDelete_Failed'), |
772
|
|
|
'Impossible' => $this->lclMsgCmn('i18n_ActionDelete_Impossible'), |
773
|
|
|
'Success' => $this->lclMsgCmn('i18n_ActionDelete_Success'), |
774
|
|
|
]; |
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
private function setViewDeletePackedFinal($sReturn) |
778
|
|
|
{ |
779
|
|
|
$finalJavascript = $this->setJavascriptContent(implode('', [ |
780
|
|
|
'$("#DeleteFeedback").fadeOut(4000, function() {', |
781
|
|
|
'$(this).remove();', |
782
|
|
|
'});', |
783
|
|
|
])); |
784
|
|
|
return '<div id="DeleteFeedback">' . $sReturn . '</div>' . $finalJavascript; |
785
|
|
|
} |
786
|
|
|
|
787
|
|
|
/** |
788
|
|
|
* Automatic handler for Record deletion |
789
|
|
|
* |
790
|
|
|
* @param string $tbl |
791
|
|
|
* @param string $idn |
792
|
|
|
* @return string |
793
|
|
|
*/ |
794
|
|
|
protected function setViewModernDelete($tbl, $idn) |
|
|
|
|
795
|
|
|
{ |
796
|
|
|
$tMsg = $this->setViewDeleteFeedbacks(); |
797
|
|
|
if ($tbl == '') { |
798
|
|
|
$sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Impossible']); |
799
|
|
|
} else { |
800
|
|
|
$this->setMySQLquery2Server($this->sQueryToDeleteSingleIdentifier([$tbl, $idn, $_REQUEST[$idn]])); |
801
|
|
|
$sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Failed']) |
802
|
|
|
. '(' . $this->mySQLconnection->error . ')'; |
803
|
|
|
if ($this->mySQLconnection->affected_rows > 0) { |
804
|
|
|
$sReturn = $this->setFeedbackModern('check', $tMsg['Confirmation'], $tMsg['Success']); |
805
|
|
|
} |
806
|
|
|
} |
807
|
|
|
return $this->setViewDeletePackedFinal($sReturn); |
808
|
|
|
} |
809
|
|
|
} |
810
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.