1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder\Files\Admin; |
4
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
6
|
|
|
use XoopsModules\Modulebuilder\{ |
7
|
|
|
Files, |
8
|
|
|
Constants |
9
|
|
|
}; |
10
|
|
|
|
11
|
|
|
/* |
12
|
|
|
You may not change or alter any portion of this comment or credits |
13
|
|
|
of supporting developers from this source code or any supporting source code |
14
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
15
|
|
|
|
16
|
|
|
This program is distributed in the hope that it will be useful, |
17
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19
|
|
|
*/ |
20
|
|
|
/** |
21
|
|
|
* modulebuilder module. |
22
|
|
|
* |
23
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
24
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
25
|
|
|
* |
26
|
|
|
* @since 2.5.0 |
27
|
|
|
* |
28
|
|
|
* @author Txmod Xoops https://xoops.org |
29
|
|
|
* Goffy https://myxoops.org |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class AdminPages. |
35
|
|
|
*/ |
36
|
|
|
class AdminPages extends Files\CreateFile |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var mixed |
40
|
|
|
*/ |
41
|
|
|
private $axc = null; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var mixed |
45
|
|
|
*/ |
46
|
|
|
private $xc = null; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var mixed |
50
|
|
|
*/ |
51
|
|
|
private $pc = null; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @public function constructor |
55
|
|
|
* @param null |
56
|
|
|
*/ |
57
|
|
|
public function __construct() |
58
|
|
|
{ |
59
|
|
|
parent::__construct(); |
60
|
|
|
$this->xc = Modulebuilder\Files\CreateXoopsCode::getInstance(); |
61
|
|
|
$this->pc = Modulebuilder\Files\CreatePhpCode::getInstance(); |
62
|
|
|
$this->axc = Modulebuilder\Files\Admin\AdminXoopsCode::getInstance(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @static function getInstance |
67
|
|
|
* @param null |
68
|
|
|
* |
69
|
|
|
* @return AdminPages |
70
|
|
|
*/ |
71
|
|
|
public static function getInstance() |
72
|
|
|
{ |
73
|
|
|
static $instance = false; |
74
|
|
|
if (!$instance) { |
75
|
|
|
$instance = new self(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $instance; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @public function write |
83
|
|
|
* @param $module |
84
|
|
|
* @param $table |
85
|
|
|
* @param $filename |
86
|
|
|
*/ |
87
|
|
|
public function write($module, $table, $filename) |
88
|
|
|
{ |
89
|
|
|
$this->setModule($module); |
90
|
|
|
$this->setTable($table); |
91
|
|
|
$this->setFileName($filename); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @private function getAdminPagesHeader |
96
|
|
|
* @param $moduleDirname |
97
|
|
|
* @param $fieldId |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
private function getAdminPagesHeader($moduleDirname, $fieldId) |
101
|
|
|
{ |
102
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
103
|
|
|
$ret = $this->pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', ''); |
104
|
|
|
$ret .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', ''); |
105
|
|
|
$ret .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants'], '', ''); |
106
|
|
|
$ret .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Common']); |
107
|
|
|
$ret .= $this->getRequire(); |
108
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('It recovered the value of argument op in URL$'); |
109
|
|
|
$ret .= $this->xc->getXcXoopsRequest('op', 'op', 'list', 'Cmd'); |
110
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine("Request {$fieldId}"); |
111
|
|
|
$ret .= $this->xc->getXcXoopsRequest($ccFieldId, $fieldId, '', 'Int'); |
112
|
|
|
|
113
|
|
|
return $ret; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @private function getAdminPagesSwitch |
118
|
|
|
* @param $cases |
119
|
|
|
* |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
private function getAdminPagesSwitch($cases = []) |
123
|
|
|
{ |
124
|
|
|
$contentSwitch = $this->pc->getPhpCodeCaseSwitch($cases, true, false, "\t"); |
125
|
|
|
|
126
|
|
|
return $this->pc->getPhpCodeSwitch('op', $contentSwitch); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @private function getAdminPagesList |
131
|
|
|
* @param $moduleDirname |
132
|
|
|
* @param $table |
133
|
|
|
* @param $language |
134
|
|
|
* @param $fieldInForm |
135
|
|
|
* @param string $t |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
private function getAdminPagesList($moduleDirname, $table, $language, $fieldInForm, $t = '') |
139
|
|
|
{ |
140
|
|
|
$stuModuleDirname = \mb_strtoupper($moduleDirname); |
141
|
|
|
$tableName = $table->getVar('table_name'); |
142
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
143
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
144
|
|
|
$stuTableSoleName = \mb_strtoupper($tableSoleName); |
145
|
|
|
|
146
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Define Stylesheet', '', $t); |
147
|
|
|
$ret .= $this->xc->getXcXoThemeAddStylesheet('style', $t); |
148
|
|
|
$ret .= $this->xc->getXcXoopsRequest('start', 'start', '0', 'Int', false, $t); |
149
|
|
|
$adminpager = $this->xc->getXcGetConfig('adminpager'); |
150
|
|
|
$ret .= $this->xc->getXcXoopsRequest('limit', 'limit', $adminpager, 'Int', false, $t); |
151
|
|
|
$ret .= $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
152
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
153
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
154
|
|
|
|
155
|
|
|
if (\in_array(1, $fieldInForm)) { |
156
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add', $t); |
157
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('buttons', '$adminObject->displayButton(\'left\')', true, $t); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$ret .= $this->xc->getXcHandlerCountObj($tableName, $t); |
161
|
|
|
$ret .= $this->xc->getXcHandlerAllObj($tableName, '', '$start', '$limit', $t); |
162
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign("{$tableName}_count", "\${$tableName}Count", true, $t); |
163
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign("{$moduleDirname}_url", "\\{$stuModuleDirname}_URL", true, $t); |
164
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign("{$moduleDirname}_upload_url", "\\{$stuModuleDirname}_UPLOAD_URL", true, $t); |
165
|
|
|
|
166
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Table view', $tableName, $t); |
167
|
|
|
$contentForeach = $this->xc->getXcGetValues($tableName, $tableSoleName, 'i', false, $t . "\t\t"); |
168
|
|
|
$contentForeach .= $this->xc->getXcXoopsTplAppend("{$tableName}_list", "\${$tableSoleName}", $t . "\t\t"); |
169
|
|
|
$contentForeach .= $this->pc->getPhpCodeUnset($tableSoleName, $t . "\t\t"); |
170
|
|
|
$condIf = $this->pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $contentForeach, $t . "\t"); |
171
|
|
|
$condIf .= $this->xc->getXcPageNav($tableName, $t . "\t"); |
172
|
|
|
$condElse = $this->xc->getXcXoopsTplAssign('error', "{$language}THEREARENT_{$stuTableName}", true, $t . "\t"); |
173
|
|
|
$ret .= $this->pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $condIf, $condElse, $t); |
174
|
|
|
|
175
|
|
|
return $ret; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @private function getAdminPagesNew |
180
|
|
|
* @param $moduleDirname |
181
|
|
|
* @param $tableName |
182
|
|
|
* @param $fieldInForm |
183
|
|
|
* @param $language |
184
|
|
|
* @param string $t |
185
|
|
|
* @return string |
186
|
|
|
*/ |
187
|
|
|
private function getAdminPagesNew($moduleDirname, $tableName, $fieldInForm, $language, $t = '') |
188
|
|
|
{ |
189
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
190
|
|
|
$ret = $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
191
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
192
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
193
|
|
|
|
194
|
|
|
if (\in_array(1, $fieldInForm)) { |
195
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableName, '', 'list', $t); |
196
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('buttons', '$adminObject->displayButton(\'left\')', true, $t); |
197
|
|
|
} |
198
|
|
|
$ret .= $this->xc->getXcCommonPagesNew($tableName, $t); |
199
|
|
|
|
200
|
|
|
return $ret; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @private function getAdminPagesClone |
205
|
|
|
* @param $moduleDirname |
206
|
|
|
* @param $tableName |
207
|
|
|
* @param $fieldInForm |
208
|
|
|
* @param $language |
209
|
|
|
* @param string $t |
210
|
|
|
* @return string |
211
|
|
|
*/ |
212
|
|
|
private function getAdminPagesClone($moduleDirname, $tableName, $tableSoleName, $fieldInForm, $fieldId, $language, $t = '') |
213
|
|
|
{ |
214
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
215
|
|
|
$stuTableSoleName = \mb_strtoupper($tableSoleName); |
216
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
217
|
|
|
$ret = $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
218
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
219
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
220
|
|
|
|
221
|
|
|
if (\in_array(1, $fieldInForm)) { |
222
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableName, '', 'list', $t); |
223
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add', $t); |
224
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('buttons', '$adminObject->displayButton(\'left\')', true, $t); |
225
|
|
|
} |
226
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine("Request source", '', $t); |
227
|
|
|
$ret .= $this->xc->getXcXoopsRequest($ccFieldId . 'Source', $fieldId . '_source', '', 'Int', false, $t); |
228
|
|
|
$ret .= $this->xc->getXcCommonPagesClone($tableName, $ccFieldId, $t); |
229
|
|
|
|
230
|
|
|
return $ret; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @private function getPermissionsSave |
235
|
|
|
* @param $moduleDirname |
236
|
|
|
* @param $perm |
237
|
|
|
* |
238
|
|
|
* @return string |
239
|
|
|
*/ |
240
|
|
|
private function getPermissionsSave($moduleDirname, $perm = 'view') |
241
|
|
|
{ |
242
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Permission to', $perm, "\t\t\t"); |
243
|
|
|
$ret .= $this->xc->getXcDeleteRight('grouppermHandler', "{$moduleDirname}_{$perm}", '$mid', '$permId', false, "\t\t\t"); |
244
|
|
|
$content = $this->xc->getXcAddRight('grouppermHandler', "{$moduleDirname}_{$perm}", '$permId', '$onegroupId', '$mid', false, "\t\t\t\t\t"); |
245
|
|
|
$foreach = $this->pc->getPhpCodeForeach("_POST['groups_{$perm}']", false, false, 'onegroupId', $content, "\t\t\t\t"); |
246
|
|
|
$ret .= $this->pc->getPhpCodeConditions("isset(\$_POST['groups_{$perm}'])", null, null, $foreach, false, "\t\t\t"); |
247
|
|
|
|
248
|
|
|
return $ret; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @private function getAdminPagesSave |
253
|
|
|
* @param $moduleDirname |
254
|
|
|
* @param $tableName |
255
|
|
|
* @param $tableSoleName |
256
|
|
|
* @param $language |
257
|
|
|
* @param $fields |
258
|
|
|
* @param $fieldId |
259
|
|
|
* @param $fieldMain |
260
|
|
|
* @param $tablePerms |
261
|
|
|
* @param string $t |
262
|
|
|
* @return string |
263
|
|
|
*/ |
264
|
|
|
private function getAdminPagesSave($moduleDirname, $tableName, $tableSoleName, $language, $fields, $fieldId, $fieldMain, $tablePerms, $t = '') |
265
|
|
|
{ |
266
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
267
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Security Check','', $t); |
268
|
|
|
$xoopsSecurityCheck = $this->xc->getXcXoopsSecurityCheck('!'); |
269
|
|
|
$securityError = $this->xc->getXcXoopsSecurityErrors(); |
270
|
|
|
$implode = $this->pc->getPhpCodeImplode(',', $securityError); |
271
|
|
|
$redirectError = $this->xc->getXcRedirectHeader($tableName, '', '3', $implode, true, $t . "\t"); |
272
|
|
|
$ret .= $this->pc->getPhpCodeConditions($xoopsSecurityCheck, '', '', $redirectError, false, $t); |
273
|
|
|
|
274
|
|
|
$contentIf = $this->xc->getXcHandlerGetObj($tableName, $ccFieldId, $t . "\t"); |
275
|
|
|
$contentElse = $this->xc->getXcHandlerCreateObj($tableName, $t . "\t"); |
276
|
|
|
$ret .= $this->pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $contentIf, $contentElse, $t); |
277
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Set Vars', null, $t); |
278
|
|
|
$countUploader = 0; |
279
|
|
|
$fieldLines = ''; |
280
|
|
|
foreach (\array_keys($fields) as $f) { |
281
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
282
|
|
|
$fieldType = $fields[$f]->getVar('field_type'); |
283
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
284
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
285
|
|
|
$fieldMain = $fieldName; |
286
|
|
|
} |
287
|
|
|
if ($f > 0) { // If we want to hide field id |
288
|
|
|
switch ($fieldElement) { |
289
|
|
|
case Constants::FIELD_ELE_CHECKBOX: |
290
|
|
|
case Constants::FIELD_ELE_RADIOYN: |
291
|
|
|
$fieldLines .= $this->xc->getXcSetVarCheckBoxOrRadioYN($tableName, $fieldName, $t); |
292
|
|
|
break; |
293
|
|
|
case Constants::FIELD_ELE_IMAGELIST: |
294
|
|
|
$fieldLines .= $this->axc->getAxcSetVarImageList($tableName, $fieldName, $t, $countUploader); |
295
|
|
|
$countUploader++; |
296
|
|
|
break; |
297
|
|
|
case Constants::FIELD_ELE_SELECTFILE: |
298
|
|
|
$fieldLines .= $this->axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $t, $countUploader, $fieldMain); |
299
|
|
|
$countUploader++; |
300
|
|
|
break; |
301
|
|
|
case Constants::FIELD_ELE_URLFILE: |
302
|
|
|
$fieldLines .= $this->axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, true, $t, $countUploader, $fieldMain); |
303
|
|
|
$countUploader++; |
304
|
|
|
break; |
305
|
|
|
case Constants::FIELD_ELE_UPLOADIMAGE: |
306
|
|
|
$fieldLines .= $this->axc->getAxcSetVarUploadImage($moduleDirname, $tableName, $fieldName, $fieldMain, $t, $countUploader); |
307
|
|
|
$countUploader++; |
308
|
|
|
break; |
309
|
|
|
case Constants::FIELD_ELE_UPLOADFILE: |
310
|
|
|
$fieldLines .= $this->axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $t, $countUploader, $fieldMain); |
311
|
|
|
$countUploader++; |
312
|
|
|
break; |
313
|
|
|
case Constants::FIELD_ELE_TEXTDATESELECT: |
314
|
|
|
$fieldLines .= $this->xc->getXcSetVarTextDateSelect($tableName, $tableSoleName, $fieldName, $t); |
315
|
|
|
break; |
316
|
|
|
case Constants::FIELD_ELE_PASSWORD: |
317
|
|
|
$fieldLines .= $this->axc->getAxcSetVarPassword($tableName, $fieldName, $t); |
318
|
|
|
break; |
319
|
|
|
case Constants::FIELD_ELE_DATETIME: |
320
|
|
|
$fieldLines .= $this->xc->getXcSetVarDateTime($tableName, $tableSoleName, $fieldName, $t); |
321
|
|
|
break; |
322
|
|
|
default: |
323
|
|
|
$fieldLines .= $this->axc->getAxcSetVarMisc($tableName, $fieldName, $fieldType, $fieldElement, $t); |
324
|
|
|
break; |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
if ($countUploader > 0) { |
329
|
|
|
$ret .= $this->xc->getXcEqualsOperator('$uploaderErrors', "''", null, $t); |
330
|
|
|
} |
331
|
|
|
$ret .= $fieldLines; |
332
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Insert Data', null, $t); |
333
|
|
|
$insert = $this->xc->getXcHandlerInsert($tableName, $tableName, 'Obj'); |
334
|
|
|
$contentInsert = ''; |
335
|
|
|
if (1 == $tablePerms) { |
336
|
|
|
$ucfTableName = \ucfirst($tableName); |
337
|
|
|
$ucfFieldId = $this->getCamelCase($fieldId, true); |
338
|
|
|
$contentInsert = $this->xc->getXcEqualsOperator("\$new{$ucfFieldId}", "\${$tableName}Obj->getNewInsertedId{$ucfTableName}()", null, $t . "\t"); |
339
|
|
|
$contentInsert .= $this->pc->getPhpCodeTernaryOperator('permId', "isset(\$_REQUEST['{$fieldId}'])", "\${$ccFieldId}", "\$new{$ucfFieldId}", $t . "\t"); |
340
|
|
|
$contentInsert .= $this->xc->getXcXoopsHandler('groupperm', $t . "\t"); |
341
|
|
|
$contentInsert .= $this->xc->getXcEqualsOperator('$mid', "\$GLOBALS['xoopsModule']->getVar('mid')", null, $t . "\t"); |
342
|
|
|
$contentInsert .= $this->getPermissionsSave($moduleDirname, 'view_' . $tableName); |
343
|
|
|
$contentInsert .= $this->getPermissionsSave($moduleDirname, 'submit_' . $tableName); |
344
|
|
|
$contentInsert .= $this->getPermissionsSave($moduleDirname, 'approve_' . $tableName); |
345
|
|
|
} |
346
|
|
|
if ($countUploader > 0) { |
347
|
|
|
$errIf = $this->xc->getXcRedirectHeader("'{$tableName}.php?op=edit&{$fieldId}=' . \${$ccFieldId}", '', '5', '$uploaderErrors', false, $t . "\t\t"); |
348
|
|
|
$errElse = $this->xc->getXcRedirectHeader($tableName, '?op=list', '2', "{$language}FORM_OK", true, $t . "\t\t"); |
349
|
|
|
$contentInsert .= $this->pc->getPhpCodeConditions('$uploaderErrors', ' !== ',"''" , $errIf, $errElse, $t . "\t"); |
350
|
|
|
} else { |
351
|
|
|
$contentInsert .= $this->xc->getXcRedirectHeader($tableName . '', '?op=list', '2', "{$language}FORM_OK", true, $t . "\t"); |
352
|
|
|
} |
353
|
|
|
$ret .= $this->pc->getPhpCodeConditions($insert, '', '', $contentInsert, false, $t); |
354
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Get Form', null, $t); |
355
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('error', "\${$tableName}Obj->getHtmlErrors()", true, $t); |
356
|
|
|
$ret .= $this->xc->getXcGetForm('form', $tableName, 'Obj', $t); |
357
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('form', '$form->render()', true, $t); |
358
|
|
|
|
359
|
|
|
return $ret; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @private function getAdminPagesEdit |
364
|
|
|
* @param $moduleDirname |
365
|
|
|
* @param $table |
366
|
|
|
* @param $language |
367
|
|
|
* @param $fieldId |
368
|
|
|
* @param $fieldInForm |
369
|
|
|
* @param string $t |
370
|
|
|
* @return string |
371
|
|
|
*/ |
372
|
|
|
private function getAdminPagesEdit($moduleDirname, $table, $language, $fieldId, $fieldInForm, $t = '') |
373
|
|
|
{ |
374
|
|
|
$tableName = $table->getVar('table_name'); |
375
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
376
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
377
|
|
|
$stuTableSoleName = \mb_strtoupper($tableSoleName); |
378
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
379
|
|
|
|
380
|
|
|
$ret = $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
381
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
382
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
383
|
|
|
|
384
|
|
|
if (\in_array(1, $fieldInForm)) { |
385
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add', $t); |
386
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableName, '', 'list', $t); |
387
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('buttons', '$adminObject->displayButton(\'left\')', true, $t); |
388
|
|
|
} |
389
|
|
|
$ret .= $this->xc->getXcCommonPagesEdit($tableName, $ccFieldId, $t); |
390
|
|
|
|
391
|
|
|
return $ret; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @private function getAdminPagesDelete |
396
|
|
|
* @param $moduleDirname |
397
|
|
|
* @param $tableName |
398
|
|
|
* @param $tableSoleName |
399
|
|
|
* @param $language |
400
|
|
|
* @param $fieldId |
401
|
|
|
* @param $fieldMain |
402
|
|
|
* @param $tableNotifications |
403
|
|
|
* @param string $t |
404
|
|
|
* @return string |
405
|
|
|
*/ |
406
|
|
|
private function getAdminPagesDelete($moduleDirname, $tableName, $tableSoleName, $language, $fieldId, $fieldMain, $tableNotifications, $t = '') |
407
|
|
|
{ |
408
|
|
|
$ret = $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
409
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
410
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
411
|
|
|
$ret .= $this->xc->getXcCommonPagesDelete($language, $tableName, $tableSoleName, $fieldId, $fieldMain, $tableNotifications, $t, true); |
412
|
|
|
return $ret; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* @public function render |
417
|
|
|
* @param null |
418
|
|
|
* |
419
|
|
|
* @return bool|string |
420
|
|
|
*/ |
421
|
|
|
public function render() |
422
|
|
|
{ |
423
|
|
|
$tf = Modulebuilder\Files\CreateFile::getInstance(); |
424
|
|
|
$new = $clone = $save = $edit = ''; |
425
|
|
|
|
426
|
|
|
$module = $this->getModule(); |
427
|
|
|
$table = $this->getTable(); |
428
|
|
|
$filename = $this->getFileName(); |
429
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
430
|
|
|
$tableName = $table->getVar('table_name'); |
431
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
432
|
|
|
$tablePerms = $table->getVar('table_permissions'); |
433
|
|
|
$tableNotifications = $table->getVar('table_notifications'); |
434
|
|
|
$language = $this->getLanguage($moduleDirname, 'AM'); |
435
|
|
|
$fields = $tf->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
436
|
|
|
$fieldInForm = null; |
437
|
|
|
$fieldId = null; |
438
|
|
|
$fieldMain = null; |
439
|
|
|
foreach (\array_keys($fields) as $f) { |
440
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
441
|
|
|
$fieldInForm[] = $fields[$f]->getVar('field_inform'); |
442
|
|
|
if (0 == $f) { |
443
|
|
|
$fieldId = $fieldName; |
444
|
|
|
} |
445
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
446
|
|
|
$fieldMain = $fieldName; |
447
|
|
|
} |
448
|
|
|
} |
449
|
|
|
$content = $this->getHeaderFilesComments($module); |
450
|
|
|
$content .= $this->getAdminPagesHeader($moduleDirname, $fieldId); |
451
|
|
|
$list = $this->getAdminPagesList($moduleDirname, $table, $language, $fieldInForm, "\t\t"); |
452
|
|
|
if (\in_array(1, $fieldInForm)) { |
453
|
|
|
$new = $this->getAdminPagesNew($moduleDirname, $tableName, $fieldInForm, $language, "\t\t"); |
454
|
|
|
$clone = $this->getAdminPagesClone($moduleDirname, $tableName, $tableSoleName, $fieldInForm, $fieldId, $language, "\t\t"); |
455
|
|
|
$save = $this->getAdminPagesSave($moduleDirname, $tableName, $tableSoleName, $language, $fields, $fieldId, $fieldMain, $tablePerms, "\t\t"); |
456
|
|
|
$edit = $this->getAdminPagesEdit($moduleDirname, $table, $language, $fieldId, $fieldInForm, "\t\t"); |
457
|
|
|
} |
458
|
|
|
$delete = $this->getAdminPagesDelete($moduleDirname, $tableName, $tableSoleName, $language, $fieldId, $fieldMain, $tableNotifications, "\t\t"); |
459
|
|
|
|
460
|
|
|
$cases = [ |
461
|
|
|
'list' => [$list], |
462
|
|
|
'new' => [$new], |
463
|
|
|
'clone' => [$clone], |
464
|
|
|
'save' => [$save], |
465
|
|
|
'edit' => [$edit], |
466
|
|
|
'delete' => [$delete], |
467
|
|
|
]; |
468
|
|
|
$content .= $this->getAdminPagesSwitch($cases); |
469
|
|
|
$content .= $this->getRequire('footer'); |
470
|
|
|
|
471
|
|
|
$tf->create($moduleDirname, 'admin', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED); |
472
|
|
|
|
473
|
|
|
return $tf->renderFile(); |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
|