|
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 DomCssAndJavascriptByDanielGP |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
use \danielgp\browser_agent_info\BrowserAgentInfosByDanielGP, |
|
40
|
|
|
DomPaginationByDanielGP, |
|
41
|
|
|
DomCssAndJavascriptByDanielGPwithCDN; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Creates a mask to differentiate between Mandatory and Optional fields |
|
45
|
|
|
* |
|
46
|
|
|
* @param array $details |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function getFieldCompletionType($details) |
|
50
|
|
|
{ |
|
51
|
|
|
$inputFeatures = ['display' => '***', 'ftrs' => ['title' => 'Mandatory', 'class' => 'inputMandatory']]; |
|
52
|
|
|
if ($details['IS_NULLABLE'] == 'YES') { |
|
53
|
|
|
$inputFeatures = ['display' => '~', 'ftrs' => ['title' => 'Optional', 'class' => 'inputOptional']]; |
|
54
|
|
|
} |
|
55
|
|
|
return $this->setStringIntoTag($inputFeatures['display'], 'span', $inputFeatures['ftrs']); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns css codes |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $cssContent |
|
62
|
|
|
* @param array $optionalFlags |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function setCssContent($cssContent, $optionalFlags = null) |
|
66
|
|
|
{ |
|
67
|
|
|
$attr = []; |
|
68
|
|
|
if (is_null($optionalFlags)) { |
|
69
|
|
|
$attr['media'] = 'all'; |
|
70
|
|
|
} else { |
|
71
|
|
|
$knownAttributes = ['media']; |
|
72
|
|
|
foreach ($knownAttributes as $value) { |
|
73
|
|
|
if (array_key_exists($value, $optionalFlags)) { |
|
74
|
|
|
$attr[$value] = $optionalFlags[$value]; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
return '<style type="text/css" media="' . $attr['media'] . '">' |
|
79
|
|
|
. $cssContent . '</style>'; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Returns css link to a given file |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $cssFileName |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function setCssFile($cssFileName, $hostsWithoutCDNrq = null) |
|
89
|
|
|
{ |
|
90
|
|
|
if (is_null($hostsWithoutCDNrq)) { |
|
91
|
|
|
$hostsWithoutCDNrq = []; |
|
92
|
|
|
} |
|
93
|
|
|
if (in_array($this->getClientRealIpAddress(), $hostsWithoutCDNrq)) { |
|
94
|
|
|
return '<link rel="stylesheet" type="text/css" href="' |
|
95
|
|
|
. filter_var($cssFileName, FILTER_SANITIZE_STRING) . '" />'; |
|
96
|
|
|
} |
|
97
|
|
|
$patternFound = $this->setCssFileCDN($cssFileName); |
|
98
|
|
|
return '<link rel="stylesheet" type="text/css" href="' |
|
99
|
|
|
. filter_var($patternFound[1], FILTER_SANITIZE_STRING) . '" />'; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Builds javascript to avoid multiple form submission |
|
104
|
|
|
* |
|
105
|
|
|
* @param string $frmId |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function setFormJavascriptFinal($frmId) |
|
109
|
|
|
{ |
|
110
|
|
|
$cnt = implode(PHP_EOL, [ |
|
111
|
|
|
'$(document).ready(function(){', |
|
112
|
|
|
'$("form#' . $frmId . '").submit(function(){', |
|
113
|
|
|
'$("form#' . $frmId . ' input[type=checkbox]").attr("readonly", true);', |
|
114
|
|
|
'$("form#' . $frmId . ' input[type=password]").attr("readonly", true);', |
|
115
|
|
|
'$("form#' . $frmId . ' input[type=radio]").attr("readonly", true);', |
|
116
|
|
|
'$("form#' . $frmId . ' input[type=text]").attr("readonly", true);', |
|
117
|
|
|
'$("form#' . $frmId . ' textarea").attr("readonly", true);', |
|
118
|
|
|
'$("form#' . $frmId . ' select").attr("readonly", true);', |
|
119
|
|
|
'$("input[type=submit]").attr("disabled", "disabled");', |
|
120
|
|
|
'$("input[type=submit]").attr("value", "' . $this->lclMsgCmn('i18n_Form_ButtonSaving') . '");', |
|
121
|
|
|
'});', |
|
122
|
|
|
'});', |
|
123
|
|
|
]); |
|
124
|
|
|
return $this->setJavascriptContent(PHP_EOL . $cnt . PHP_EOL); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Returns javascript function to support Add or Edit through Ajax |
|
129
|
|
|
* |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
|
|
protected function setJavascriptAddEditByAjax($tabName = 'tabStandard') |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->setJavascriptContent(implode('', [ |
|
135
|
|
|
'function loadAE(action) {', |
|
136
|
|
|
'document.getElementById("' . $tabName . '").tabber.tabShow(1);', |
|
137
|
|
|
'$("#DynamicAddEditSpacer").load(action', |
|
138
|
|
|
'+"&specialHook[]=noHeader"', |
|
139
|
|
|
'+"&specialHook[]=noMenu"', |
|
140
|
|
|
'+"&specialHook[]=noContainer"', |
|
141
|
|
|
'+"&specialHook[]=noFooter"', |
|
142
|
|
|
');', |
|
143
|
|
|
'}', |
|
144
|
|
|
])); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Returns javascript codes |
|
149
|
|
|
* |
|
150
|
|
|
* @param string $javascriptContent |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
|
|
protected function setJavascriptContent($javascriptContent) |
|
154
|
|
|
{ |
|
155
|
|
|
return '<script type="text/javascript">' . $javascriptContent . '</script>'; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Builds up a confirmation dialog and return delection if Yes |
|
160
|
|
|
* |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
|
|
protected function setJavascriptDeleteWithConfirmation() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->setJavascriptContent('function setQuest(a, b) { ' |
|
166
|
|
|
. 'c = a.indexOf("_"); switch(a.slice(0, c)) { ' |
|
167
|
|
|
. 'case \'delete\': ' |
|
168
|
|
|
. 'if (confirm(\'' . $this->lclMsgCmn('i18n_ActionDelete_ConfirmationQuestion') . '\')) { ' |
|
169
|
|
|
. 'window.location = document.location.protocol + "//" + ' |
|
170
|
|
|
. 'document.location.host + document.location.pathname + ' |
|
171
|
|
|
. '"?view=" + a + "&" + b; } break; } }'); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Returns javascript link to a given file |
|
176
|
|
|
* |
|
177
|
|
|
* @param string $jsFileName |
|
178
|
|
|
* @return string |
|
179
|
|
|
*/ |
|
180
|
|
|
protected function setJavascriptFile($jsFileName, $hostsWithoutCDNrq = null) |
|
181
|
|
|
{ |
|
182
|
|
|
if (is_null($hostsWithoutCDNrq)) { |
|
183
|
|
|
$hostsWithoutCDNrq = []; |
|
184
|
|
|
} |
|
185
|
|
|
if (in_array($this->getClientRealIpAddress(), $hostsWithoutCDNrq)) { |
|
186
|
|
|
return '<script type="text/javascript" src="' . filter_var($jsFileName, FILTER_SANITIZE_STRING) |
|
187
|
|
|
. '"></script>'; |
|
188
|
|
|
} |
|
189
|
|
|
$patternFound = $this->setJavascriptFileCDN($jsFileName); |
|
190
|
|
|
return '<script type="text/javascript" src="' . $patternFound[1] . '"></script>' . $patternFound[2]; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Returns javascript codes from given file |
|
195
|
|
|
* |
|
196
|
|
|
* @param string $jsFileName |
|
197
|
|
|
* @return string |
|
198
|
|
|
*/ |
|
199
|
|
|
protected function setJavascriptFileContent($jsFileName) |
|
200
|
|
|
{ |
|
201
|
|
|
return '<script type="text/javascript">' . file_get_contents($jsFileName, true) . '</script>'; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
protected function updateDivTitleName($rememberGroupVal, $groupCounter) |
|
205
|
|
|
{ |
|
206
|
|
|
$jsContent = '$(document).ready(function() { $("#tab_' |
|
207
|
|
|
. $this->cleanStringForId($rememberGroupVal) . '").attr("title", "' |
|
208
|
|
|
. $rememberGroupVal . ' (' . $groupCounter . ')"); });'; |
|
209
|
|
|
return $this->setJavascriptContent($jsContent); |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|