|
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 CommonViews |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
use MySQLiAdvancedOutput; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns a generic form based on a given table |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $tblSrc |
|
45
|
|
|
* @param array $feat |
|
46
|
|
|
* @param array $hdnInf |
|
47
|
|
|
* |
|
48
|
|
|
* @return string Form to add/modify detail for a single row within a table |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function setFormGenericSingleRecord($tblSrc, $feat, $hdnInf = []) |
|
51
|
|
|
{ |
|
52
|
|
|
echo $this->setStringIntoTag('', 'div', ['id' => 'loading']); |
|
53
|
|
|
$this->setTableCache($tblSrc); |
|
54
|
|
|
if (strpos($tblSrc, '.') !== false) { |
|
55
|
|
|
$tblSrc = explode('.', str_replace('`', '', $tblSrc))[1]; |
|
56
|
|
|
} |
|
57
|
|
|
$sReturn = []; |
|
58
|
|
|
if (count($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc]) != 0) { |
|
59
|
|
|
foreach ($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc] as $value) { |
|
60
|
|
|
$sReturn[] = $this->setNeededField($tblSrc, $value, $feat); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
$frmFtrs = ['id' => $feat['id'], 'action' => $feat['action'], 'method' => $feat['method']]; |
|
64
|
|
|
return $this->setStringIntoTag(implode('', $sReturn) . $this->setFormButtons($feat, $hdnInf), 'form', $frmFtrs) |
|
65
|
|
|
. $this->setFormJavascriptFinal($feat['id']); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function setTableLocaleFields($localizationStrings) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->advCache['tableStructureLocales'] = $localizationStrings; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function setViewDeleteFeedbacks() |
|
74
|
|
|
{ |
|
75
|
|
|
return [ |
|
76
|
|
|
'Confirmation' => $this->lclMsgCmn('i18n_Action_Confirmation'), |
|
77
|
|
|
'Failed' => $this->lclMsgCmn('i18n_ActionDelete_Failed'), |
|
78
|
|
|
'Impossible' => $this->lclMsgCmn('i18n_ActionDelete_Impossible'), |
|
79
|
|
|
'Success' => $this->lclMsgCmn('i18n_ActionDelete_Success'), |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
private function setViewDeletePackedFinal($sReturn) |
|
84
|
|
|
{ |
|
85
|
|
|
$finalJavascript = $this->setJavascriptContent(implode('', [ |
|
86
|
|
|
'$("#DeleteFeedback").fadeOut(4000, function() {', |
|
87
|
|
|
'$(this).remove();', |
|
88
|
|
|
'});', |
|
89
|
|
|
])); |
|
90
|
|
|
return '<div id="DeleteFeedback">' . $sReturn . '</div>' . $finalJavascript; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Automatic handler for Record deletion |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $tbl |
|
97
|
|
|
* @param string $idn |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function setViewModernDelete($tbl, $idn) |
|
101
|
|
|
{ |
|
102
|
|
|
$tMsg = $this->setViewDeleteFeedbacks(); |
|
103
|
|
|
if ($tbl == '') { |
|
104
|
|
|
$sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Impossible']); |
|
105
|
|
|
} else { |
|
106
|
|
|
$idFldVal = $this->tCmnRequest->request->get($idn); |
|
107
|
|
|
$this->setMySQLquery2Server($this->sQueryToDeleteSingleIdentifier([$tbl, $idn, $idFldVal])); |
|
108
|
|
|
$sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Failed']) |
|
109
|
|
|
. '(' . $this->mySQLconnection->error . ')'; |
|
110
|
|
|
if ($this->mySQLconnection->affected_rows > 0) { |
|
111
|
|
|
$sReturn = $this->setFeedbackModern('check', $tMsg['Confirmation'], $tMsg['Success']); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
return $this->setViewDeletePackedFinal($sReturn); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|