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('Get all request values'); |
109
|
|
|
$ret .= $this->xc->getXcXoopsRequest('op', 'op', 'list', 'Cmd'); |
110
|
|
|
$ret .= $this->xc->getXcXoopsRequest($ccFieldId, $fieldId, '', 'Int'); |
111
|
|
|
$ret .= $this->xc->getXcXoopsRequest('start', 'start', '0', 'Int', false); |
112
|
|
|
$config = $this->xc->getXcGetConfig('adminpager'); |
113
|
|
|
$ret .= $this->xc->getXcXoopsRequest('limit', 'limit', $config, 'Int', false); |
114
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('start', '$start'); |
115
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('limit', '$limit'); |
116
|
|
|
$ret .= $this->pc->getPhpCodeBlankLine(); |
117
|
|
|
|
118
|
|
|
return $ret; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @private function getAdminPagesSwitch |
123
|
|
|
* @param $cases |
124
|
|
|
* |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
private function getAdminPagesSwitch($cases = []) |
128
|
|
|
{ |
129
|
|
|
$contentSwitch = $this->pc->getPhpCodeCaseSwitch($cases, true, false, "\t"); |
130
|
|
|
|
131
|
|
|
return $this->pc->getPhpCodeSwitch('op', $contentSwitch); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @private function getAdminPagesList |
136
|
|
|
* @param $moduleDirname |
137
|
|
|
* @param $table |
138
|
|
|
* @param $language |
139
|
|
|
* @param $fieldInForm |
140
|
|
|
* @param string $t |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
private function getAdminPagesList($moduleDirname, $table, $language, $fieldInForm, $t = '') |
144
|
|
|
{ |
145
|
|
|
$stuModuleDirname = \mb_strtoupper($moduleDirname); |
146
|
|
|
$tableName = $table->getVar('table_name'); |
147
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
148
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
149
|
|
|
$stuTableSoleName = \mb_strtoupper($tableSoleName); |
150
|
|
|
|
151
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Define Stylesheet', '', $t); |
152
|
|
|
$ret .= $this->xc->getXcXoThemeAddStylesheet('style', $t); |
153
|
|
|
$ret .= $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
154
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
155
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
156
|
|
|
|
157
|
|
|
if (\in_array(1, $fieldInForm)) { |
158
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add', $t); |
159
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('buttons', '$adminObject->displayButton(\'left\')', true, $t); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$ret .= $this->xc->getXcHandlerCountObj($tableName, $t); |
163
|
|
|
$ret .= $this->xc->getXcHandlerAllObj($tableName, '', '$start', '$limit', $t); |
164
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign("{$tableName}_count", "\${$tableName}Count", true, $t); |
165
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign("{$moduleDirname}_url", "\\{$stuModuleDirname}_URL", true, $t); |
166
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign("{$moduleDirname}_upload_url", "\\{$stuModuleDirname}_UPLOAD_URL", true, $t); |
167
|
|
|
|
168
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Table view', $tableName, $t); |
169
|
|
|
$contentForeach = $this->xc->getXcGetValues($tableName, $tableSoleName, 'i', false, $t . "\t\t"); |
170
|
|
|
$contentForeach .= $this->xc->getXcXoopsTplAppend("{$tableName}_list", "\${$tableSoleName}", $t . "\t\t"); |
171
|
|
|
$contentForeach .= $this->pc->getPhpCodeUnset($tableSoleName, $t . "\t\t"); |
172
|
|
|
$condIf = $this->pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $contentForeach, $t . "\t"); |
173
|
|
|
$condIf .= $this->xc->getXcPageNav($tableName, $t . "\t"); |
174
|
|
|
$condElse = $this->xc->getXcXoopsTplAssign('error', "{$language}THEREARENT_{$stuTableName}", true, $t . "\t"); |
175
|
|
|
$ret .= $this->pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $condIf, $condElse, $t); |
176
|
|
|
|
177
|
|
|
return $ret; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @private function getAdminPagesNew |
182
|
|
|
* @param $moduleDirname |
183
|
|
|
* @param $tableName |
184
|
|
|
* @param $fieldInForm |
185
|
|
|
* @param $language |
186
|
|
|
* @param string $t |
187
|
|
|
* @return string |
188
|
|
|
*/ |
189
|
|
|
private function getAdminPagesNew($moduleDirname, $tableName, $fieldInForm, $language, $t = '') |
190
|
|
|
{ |
191
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
192
|
|
|
$ret = $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
193
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
194
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
195
|
|
|
|
196
|
|
|
if (\in_array(1, $fieldInForm)) { |
197
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableName, '', 'list', $t); |
198
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('buttons', '$adminObject->displayButton(\'left\')', true, $t); |
199
|
|
|
} |
200
|
|
|
$ret .= $this->xc->getXcCommonPagesNew($tableName, $t); |
201
|
|
|
|
202
|
|
|
return $ret; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @private function getAdminPagesClone |
207
|
|
|
* @param $moduleDirname |
208
|
|
|
* @param $tableName |
209
|
|
|
* @param $fieldInForm |
210
|
|
|
* @param $language |
211
|
|
|
* @param string $t |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
|
|
private function getAdminPagesClone($moduleDirname, $tableName, $tableSoleName, $fieldInForm, $fieldId, $language, $t = '') |
215
|
|
|
{ |
216
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
217
|
|
|
$stuTableSoleName = \mb_strtoupper($tableSoleName); |
218
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
219
|
|
|
$ret = $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
220
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
221
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
222
|
|
|
|
223
|
|
|
if (\in_array(1, $fieldInForm)) { |
224
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableName, '', 'list', $t); |
225
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add', $t); |
226
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('buttons', '$adminObject->displayButton(\'left\')', true, $t); |
227
|
|
|
} |
228
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine("Request source", '', $t); |
229
|
|
|
$ret .= $this->xc->getXcXoopsRequest($ccFieldId . 'Source', $fieldId . '_source', '', 'Int', false, $t); |
230
|
|
|
$ret .= $this->xc->getXcCommonPagesClone($tableName, $ccFieldId, $t); |
231
|
|
|
|
232
|
|
|
return $ret; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @private function getPermissionsSave |
237
|
|
|
* @param $moduleDirname |
238
|
|
|
* @param $perm |
239
|
|
|
* |
240
|
|
|
* @return string |
241
|
|
|
*/ |
242
|
|
|
private function getPermissionsSave($moduleDirname, $perm = 'view') |
243
|
|
|
{ |
244
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Permission to', $perm, "\t\t\t"); |
245
|
|
|
$ret .= $this->xc->getXcDeleteRight('grouppermHandler', "{$moduleDirname}_{$perm}", '$mid', '$permId', false, "\t\t\t"); |
246
|
|
|
$content = $this->xc->getXcAddRight('grouppermHandler', "{$moduleDirname}_{$perm}", '$permId', '$onegroupId', '$mid', false, "\t\t\t\t\t"); |
247
|
|
|
$foreach = $this->pc->getPhpCodeForeach("_POST['groups_{$perm}']", false, false, 'onegroupId', $content, "\t\t\t\t"); |
248
|
|
|
$ret .= $this->pc->getPhpCodeConditions("isset(\$_POST['groups_{$perm}'])", null, null, $foreach, false, "\t\t\t"); |
249
|
|
|
|
250
|
|
|
return $ret; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @private function getAdminPagesSave |
255
|
|
|
* @param $moduleDirname |
256
|
|
|
* @param $tableName |
257
|
|
|
* @param $tableSoleName |
258
|
|
|
* @param $language |
259
|
|
|
* @param $fields |
260
|
|
|
* @param $fieldId |
261
|
|
|
* @param $fieldMain |
262
|
|
|
* @param $tablePerms |
263
|
|
|
* @param string $t |
264
|
|
|
* @return string |
265
|
|
|
*/ |
266
|
|
|
private function getAdminPagesSave($moduleDirname, $tableName, $tableSoleName, $language, $fields, $fieldId, $fieldMain, $tablePerms, $t = '') |
267
|
|
|
{ |
268
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
269
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Security Check','', $t); |
270
|
|
|
$xoopsSecurityCheck = $this->xc->getXcXoopsSecurityCheck('!'); |
271
|
|
|
$securityError = $this->xc->getXcXoopsSecurityErrors(); |
272
|
|
|
$implode = $this->pc->getPhpCodeImplode(',', $securityError); |
273
|
|
|
$redirectError = $this->xc->getXcRedirectHeader($tableName, '', '3', $implode, true, $t . "\t"); |
274
|
|
|
$ret .= $this->pc->getPhpCodeConditions($xoopsSecurityCheck, '', '', $redirectError, false, $t); |
275
|
|
|
|
276
|
|
|
$contentIf = $this->xc->getXcHandlerGetObj($tableName, $ccFieldId, $t . "\t"); |
277
|
|
|
$contentElse = $this->xc->getXcHandlerCreateObj($tableName, $t . "\t"); |
278
|
|
|
$ret .= $this->pc->getPhpCodeConditions("\${$ccFieldId}", ' > ', '0', $contentIf, $contentElse, $t); |
279
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Set Vars', null, $t); |
280
|
|
|
$countUploader = 0; |
281
|
|
|
$fieldLines = ''; |
282
|
|
|
foreach (\array_keys($fields) as $f) { |
283
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
284
|
|
|
$fieldType = $fields[$f]->getVar('field_type'); |
285
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
286
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
287
|
|
|
$fieldMain = $fieldName; |
288
|
|
|
} |
289
|
|
|
if ($f > 0) { // If we want to hide field id |
290
|
|
|
switch ($fieldElement) { |
291
|
|
|
case Constants::FIELD_ELE_CHECKBOX: |
292
|
|
|
case Constants::FIELD_ELE_RADIOYN: |
293
|
|
|
$fieldLines .= $this->xc->getXcSetVarCheckBoxOrRadioYN($tableName, $fieldName, $t); |
294
|
|
|
break; |
295
|
|
|
case Constants::FIELD_ELE_IMAGELIST: |
296
|
|
|
$fieldLines .= $this->axc->getAxcSetVarImageList($tableName, $fieldName, $t, $countUploader); |
297
|
|
|
$countUploader++; |
298
|
|
|
break; |
299
|
|
|
case Constants::FIELD_ELE_SELECTFILE: |
300
|
|
|
$fieldLines .= $this->axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $t, $countUploader, $fieldMain); |
301
|
|
|
$countUploader++; |
302
|
|
|
break; |
303
|
|
|
case Constants::FIELD_ELE_URLFILE: |
304
|
|
|
$fieldLines .= $this->axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, true, $t, $countUploader, $fieldMain); |
305
|
|
|
$countUploader++; |
306
|
|
|
break; |
307
|
|
|
case Constants::FIELD_ELE_UPLOADIMAGE: |
308
|
|
|
$fieldLines .= $this->axc->getAxcSetVarUploadImage($moduleDirname, $tableName, $fieldName, $fieldMain, $t, $countUploader); |
309
|
|
|
$countUploader++; |
310
|
|
|
break; |
311
|
|
|
case Constants::FIELD_ELE_UPLOADFILE: |
312
|
|
|
$fieldLines .= $this->axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $t, $countUploader, $fieldMain); |
313
|
|
|
$countUploader++; |
314
|
|
|
break; |
315
|
|
|
case Constants::FIELD_ELE_TEXTDATESELECT: |
316
|
|
|
$fieldLines .= $this->xc->getXcSetVarTextDateSelect($tableName, $tableSoleName, $fieldName, $t); |
317
|
|
|
break; |
318
|
|
|
case Constants::FIELD_ELE_PASSWORD: |
319
|
|
|
$fieldLines .= $this->axc->getAxcSetVarPassword($tableName, $fieldName, $t); |
320
|
|
|
break; |
321
|
|
|
case Constants::FIELD_ELE_DATETIME: |
322
|
|
|
$fieldLines .= $this->xc->getXcSetVarDateTime($tableName, $tableSoleName, $fieldName, $t); |
323
|
|
|
break; |
324
|
|
|
default: |
325
|
|
|
$fieldLines .= $this->axc->getAxcSetVarMisc($tableName, $fieldName, $fieldType, $fieldElement, $t); |
326
|
|
|
break; |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
if ($countUploader > 0) { |
331
|
|
|
$ret .= $this->xc->getXcEqualsOperator('$uploaderErrors', "''", null, $t); |
332
|
|
|
} |
333
|
|
|
$ret .= $fieldLines; |
334
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Insert Data', null, $t); |
335
|
|
|
$insert = $this->xc->getXcHandlerInsert($tableName, $tableName, 'Obj'); |
336
|
|
|
$contentInsert = ''; |
337
|
|
|
if (1 == $tablePerms) { |
338
|
|
|
$ucfTableName = \ucfirst($tableName); |
339
|
|
|
$ucfFieldId = $this->getCamelCase($fieldId, true); |
340
|
|
|
$contentInsert = $this->xc->getXcEqualsOperator("\$new{$ucfFieldId}", "\${$tableName}Obj->getNewInsertedId{$ucfTableName}()", null, $t . "\t"); |
341
|
|
|
$contentInsert .= $this->pc->getPhpCodeTernaryOperator('permId', "isset(\$_REQUEST['{$fieldId}'])", "\${$ccFieldId}", "\$new{$ucfFieldId}", $t . "\t"); |
342
|
|
|
$contentInsert .= $this->xc->getXcXoopsHandler('groupperm', $t . "\t"); |
343
|
|
|
$contentInsert .= $this->xc->getXcEqualsOperator('$mid', "\$GLOBALS['xoopsModule']->getVar('mid')", null, $t . "\t"); |
344
|
|
|
$contentInsert .= $this->getPermissionsSave($moduleDirname, 'view_' . $tableName); |
345
|
|
|
$contentInsert .= $this->getPermissionsSave($moduleDirname, 'submit_' . $tableName); |
346
|
|
|
$contentInsert .= $this->getPermissionsSave($moduleDirname, 'approve_' . $tableName); |
347
|
|
|
} |
348
|
|
|
if ($countUploader > 0) { |
349
|
|
|
$errIf = $this->xc->getXcRedirectHeader("'{$tableName}.php?op=edit&{$fieldId}=' . \${$ccFieldId}", '', '5', '$uploaderErrors', false, $t . "\t\t"); |
350
|
|
|
$errElse = $this->xc->getXcRedirectHeader("'{$tableName}.php?op=list&start=' . \$start . '&limit=' . \$limit", '', '2', "{$language}FORM_OK", false, $t . "\t\t"); |
351
|
|
|
$contentInsert .= $this->pc->getPhpCodeConditions('$uploaderErrors', ' !== ',"''" , $errIf, $errElse, $t . "\t"); |
352
|
|
|
} else { |
353
|
|
|
$contentInsert .= $this->xc->getXcRedirectHeader("'{$tableName}.php?op=list&start=' . \$start . '&limit=' . \$limit", '', '2', "{$language}FORM_OK", false, $t . "\t\t"); |
354
|
|
|
} |
355
|
|
|
$ret .= $this->pc->getPhpCodeConditions($insert, '', '', $contentInsert, false, $t); |
356
|
|
|
$ret .= $this->pc->getPhpCodeCommentLine('Get Form', null, $t); |
357
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('error', "\${$tableName}Obj->getHtmlErrors()", true, $t); |
358
|
|
|
$ret .= $this->xc->getXcGetForm('form', $tableName, 'Obj', $t); |
359
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('form', '$form->render()', true, $t); |
360
|
|
|
|
361
|
|
|
return $ret; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @private function getAdminPagesEdit |
366
|
|
|
* @param $moduleDirname |
367
|
|
|
* @param $table |
368
|
|
|
* @param $language |
369
|
|
|
* @param $fieldId |
370
|
|
|
* @param $fieldInForm |
371
|
|
|
* @param string $t |
372
|
|
|
* @return string |
373
|
|
|
*/ |
374
|
|
|
private function getAdminPagesEdit($moduleDirname, $table, $language, $fieldId, $fieldInForm, $t = '') |
375
|
|
|
{ |
376
|
|
|
$tableName = $table->getVar('table_name'); |
377
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
378
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
379
|
|
|
$stuTableSoleName = \mb_strtoupper($tableSoleName); |
380
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
381
|
|
|
|
382
|
|
|
$ret = $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
383
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
384
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
385
|
|
|
|
386
|
|
|
if (\in_array(1, $fieldInForm)) { |
387
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add', $t); |
388
|
|
|
$ret .= $this->axc->getAdminItemButton($language, $tableName, $stuTableName, '', 'list', $t); |
389
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('buttons', '$adminObject->displayButton(\'left\')', true, $t); |
390
|
|
|
} |
391
|
|
|
$ret .= $this->xc->getXcCommonPagesEdit($tableName, $ccFieldId, $t); |
392
|
|
|
|
393
|
|
|
return $ret; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* @private function getAdminPagesDelete |
398
|
|
|
* @param $moduleDirname |
399
|
|
|
* @param $tableName |
400
|
|
|
* @param $tableSoleName |
401
|
|
|
* @param $language |
402
|
|
|
* @param $fieldId |
403
|
|
|
* @param $fieldMain |
404
|
|
|
* @param $tableNotifications |
405
|
|
|
* @param string $t |
406
|
|
|
* @return string |
407
|
|
|
*/ |
408
|
|
|
private function getAdminPagesDelete($moduleDirname, $tableName, $tableSoleName, $language, $fieldId, $fieldMain, $tableNotifications, $t = '') |
409
|
|
|
{ |
410
|
|
|
$ret = $this->axc->getAdminTemplateMain($moduleDirname, $tableName, $t); |
411
|
|
|
$navigation = $this->axc->getAdminDisplayNavigation($tableName); |
412
|
|
|
$ret .= $this->xc->getXcXoopsTplAssign('navigation', $navigation, true, $t); |
413
|
|
|
$ret .= $this->xc->getXcCommonPagesDelete($language, $tableName, $tableSoleName, $fieldId, $fieldMain, $tableNotifications, $t, true); |
414
|
|
|
return $ret; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* @public function render |
419
|
|
|
* @param null |
420
|
|
|
* |
421
|
|
|
* @return bool|string |
422
|
|
|
*/ |
423
|
|
|
public function render() |
424
|
|
|
{ |
425
|
|
|
$tf = Modulebuilder\Files\CreateFile::getInstance(); |
426
|
|
|
$new = $clone = $save = $edit = ''; |
427
|
|
|
|
428
|
|
|
$module = $this->getModule(); |
429
|
|
|
$table = $this->getTable(); |
430
|
|
|
$filename = $this->getFileName(); |
431
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
432
|
|
|
$tableName = $table->getVar('table_name'); |
433
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
434
|
|
|
$tablePerms = $table->getVar('table_permissions'); |
435
|
|
|
$tableNotifications = $table->getVar('table_notifications'); |
436
|
|
|
$language = $this->getLanguage($moduleDirname, 'AM'); |
437
|
|
|
$fields = $tf->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
438
|
|
|
$fieldInForm = null; |
439
|
|
|
$fieldId = null; |
440
|
|
|
$fieldMain = null; |
441
|
|
|
foreach (\array_keys($fields) as $f) { |
442
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
443
|
|
|
$fieldInForm[] = $fields[$f]->getVar('field_inform'); |
444
|
|
|
if (0 == $f) { |
445
|
|
|
$fieldId = $fieldName; |
446
|
|
|
} |
447
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
448
|
|
|
$fieldMain = $fieldName; |
449
|
|
|
} |
450
|
|
|
} |
451
|
|
|
$content = $this->getHeaderFilesComments($module); |
452
|
|
|
$content .= $this->getAdminPagesHeader($moduleDirname, $fieldId); |
453
|
|
|
$list = $this->getAdminPagesList($moduleDirname, $table, $language, $fieldInForm, "\t\t"); |
454
|
|
|
if (\in_array(1, $fieldInForm)) { |
455
|
|
|
$new = $this->getAdminPagesNew($moduleDirname, $tableName, $fieldInForm, $language, "\t\t"); |
456
|
|
|
$clone = $this->getAdminPagesClone($moduleDirname, $tableName, $tableSoleName, $fieldInForm, $fieldId, $language, "\t\t"); |
457
|
|
|
$save = $this->getAdminPagesSave($moduleDirname, $tableName, $tableSoleName, $language, $fields, $fieldId, $fieldMain, $tablePerms, "\t\t"); |
458
|
|
|
$edit = $this->getAdminPagesEdit($moduleDirname, $table, $language, $fieldId, $fieldInForm, "\t\t"); |
459
|
|
|
} |
460
|
|
|
$delete = $this->getAdminPagesDelete($moduleDirname, $tableName, $tableSoleName, $language, $fieldId, $fieldMain, $tableNotifications, "\t\t"); |
461
|
|
|
|
462
|
|
|
$cases = [ |
463
|
|
|
'list' => [$list], |
464
|
|
|
'new' => [$new], |
465
|
|
|
'clone' => [$clone], |
466
|
|
|
'save' => [$save], |
467
|
|
|
'edit' => [$edit], |
468
|
|
|
'delete' => [$delete], |
469
|
|
|
]; |
470
|
|
|
$content .= $this->getAdminPagesSwitch($cases); |
471
|
|
|
$content .= $this->getRequire('footer'); |
472
|
|
|
|
473
|
|
|
$tf->create($moduleDirname, 'admin', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED); |
474
|
|
|
|
475
|
|
|
return $tf->renderFile(); |
476
|
|
|
} |
477
|
|
|
} |
478
|
|
|
|