|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
/** |
|
13
|
|
|
* tdmcreate module. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* |
|
18
|
|
|
* @since 2.5.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
21
|
|
|
* |
|
22
|
|
|
* @version $Id: AdminPages.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
25
|
|
|
/** |
|
26
|
|
|
* Class AdminPages. |
|
27
|
|
|
*/ |
|
28
|
|
|
class AdminPages extends TDMCreateFile |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $adminxoopscode; |
|
34
|
|
|
|
|
35
|
|
|
/* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
private $t2 = "\t\t"; |
|
39
|
|
|
|
|
40
|
|
|
/* |
|
41
|
|
|
* @public function constructor |
|
42
|
|
|
* @param null |
|
43
|
|
|
*/ |
|
44
|
|
|
/** |
|
45
|
|
|
* |
|
46
|
|
|
*/ |
|
47
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
parent::__construct(); |
|
50
|
|
|
$this->tdmcfile = TDMCreateFile::getInstance(); |
|
|
|
|
|
|
51
|
|
|
$this->phpcode = TDMCreatePhpCode::getInstance(); |
|
|
|
|
|
|
52
|
|
|
$this->xoopscode = TDMCreateXoopsCode::getInstance(); |
|
|
|
|
|
|
53
|
|
|
$this->adminxoopscode = AdminXoopsCode::getInstance(); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/* |
|
57
|
|
|
* @static function &getInstance |
|
58
|
|
|
* @param null |
|
59
|
|
|
*/ |
|
60
|
|
|
/** |
|
61
|
|
|
* @return AdminPages |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function &getInstance() |
|
64
|
|
|
{ |
|
65
|
|
|
static $instance = false; |
|
66
|
|
|
if (!$instance) { |
|
67
|
|
|
$instance = new self(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $instance; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/* |
|
74
|
|
|
* @public function write |
|
75
|
|
|
* @param string $module |
|
76
|
|
|
* @param string $table |
|
77
|
|
|
*/ |
|
78
|
|
|
public function write($module, $table) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->setModule($module); |
|
81
|
|
|
$this->setTable($table); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/* |
|
85
|
|
|
* @private function getAdminPagesHeader |
|
86
|
|
|
* @param string $moduleDirname |
|
87
|
|
|
* @param string $tableName |
|
88
|
|
|
* @param $fieldId |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
private function getAdminPagesHeader($moduleDirname, $tableName, $fieldId) |
|
92
|
|
|
{ |
|
93
|
|
|
$ucfModuleDirname = ucfirst($moduleDirname); |
|
|
|
|
|
|
94
|
|
|
$ucfTableName = ucfirst($tableName); |
|
|
|
|
|
|
95
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
|
96
|
|
|
$ret = $this->getInclude(); |
|
97
|
|
|
$ret .= $this->getCommentLine('It recovered the value of argument op in URL$'); |
|
98
|
|
|
$ret .= $this->xoopscode->getXoopsCodeXoopsRequest('op', 'op', 'list'); |
|
|
|
|
|
|
99
|
|
|
$ret .= $this->getCommentLine("Request {$fieldId}"); |
|
100
|
|
|
$ret .= $this->xoopscode->getXoopsCodeXoopsRequest($ccFieldId, $fieldId, '', 'Int'); |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
return $ret; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/* |
|
106
|
|
|
* @private function getAdminPagesSwitch |
|
107
|
|
|
* @param $cases |
|
108
|
|
|
* |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
|
|
private function getAdminPagesSwitch($cases = array()) |
|
112
|
|
|
{ |
|
113
|
|
|
$contentSwitch = $this->phpcode->getPhpCodeCaseSwitch($cases, true); |
|
114
|
|
|
|
|
115
|
|
|
return $this->phpcode->getPhpCodeSwitch('op', $contentSwitch); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/* |
|
119
|
|
|
* @private function getAdminPagesList |
|
120
|
|
|
* @param $moduleDirname |
|
121
|
|
|
* @param $table |
|
122
|
|
|
* @param $tableFieldname |
|
123
|
|
|
* @param $language |
|
124
|
|
|
* @param $fields |
|
125
|
|
|
* @param $fieldId |
|
126
|
|
|
* @param $fieldInForm |
|
127
|
|
|
* @param $fieldMain |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
|
|
private function getAdminPagesList($moduleDirname, $table, $language, $fields, $fieldId, $fieldInForm, $fieldMain) |
|
|
|
|
|
|
131
|
|
|
{ |
|
132
|
|
|
$stuModuleDirname = strtoupper($moduleDirname); |
|
133
|
|
|
$tableName = $table->getVar('table_name'); |
|
134
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
135
|
|
|
$tableFieldname = $table->getVar('table_fieldname'); |
|
136
|
|
|
$ucfTableName = ucfirst($tableName); |
|
137
|
|
|
$stuTableName = strtoupper($tableName); |
|
138
|
|
|
$stuTableSoleName = strtoupper($tableSoleName); |
|
139
|
|
|
$stuTableFieldname = strtoupper($tableFieldname); |
|
|
|
|
|
|
140
|
|
|
$tableAutoincrement = $table->getVar('table_autoincrement'); |
|
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
$ret = $this->xoopscode->getXoopsCodeXoopsRequest('start', 'start', '0', 'Int'); |
|
|
|
|
|
|
143
|
|
|
$adminpager = $this->xoopscode->getXoopsCodeGetConfig($moduleDirname, 'adminpager'); |
|
|
|
|
|
|
144
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeXoopsRequest('limit', 'limit', $adminpager, 'Int'); |
|
|
|
|
|
|
145
|
|
|
$ret .= $this->t2.$this->adminxoopscode->getAdminTemplateMain($moduleDirname, $tableName); |
|
|
|
|
|
|
146
|
|
|
$navigation = $this->adminxoopscode->getAdminAddNavigation($tableName); |
|
|
|
|
|
|
147
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('navigation', $navigation); |
|
|
|
|
|
|
148
|
|
|
|
|
149
|
|
View Code Duplication |
if (1 == $fieldInForm) { |
|
|
|
|
|
|
150
|
|
|
$ret .= $this->t2.$this->adminxoopscode->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add'); |
|
|
|
|
|
|
151
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('buttons', "\$adminMenu->renderButton()"); |
|
|
|
|
|
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeObjHandlerCount($tableName); |
|
|
|
|
|
|
155
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeObjHandlerAll($tableName, '', "\$start", "\$limit"); |
|
|
|
|
|
|
156
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign("{$tableName}_count", "\${$tableName}Count"); |
|
|
|
|
|
|
157
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign("{$moduleDirname}_url", "{$stuModuleDirname}_URL"); |
|
|
|
|
|
|
158
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL"); |
|
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
$ret .= <<<EOT |
|
161
|
|
|
// Table view |
|
162
|
|
|
if (\${$tableName}Count > 0) |
|
163
|
|
|
{ |
|
164
|
|
|
foreach (array_keys(\${$tableName}All) as \$i) |
|
165
|
|
|
{ |
|
166
|
|
|
\${$tableSoleName} = \${$tableName}All[\$i]->getValues{$ucfTableName}(); |
|
167
|
|
|
\$GLOBALS['xoopsTpl']->append('{$tableName}_list', \${$tableSoleName}); |
|
168
|
|
|
unset(\${$tableSoleName}); |
|
169
|
|
|
} |
|
170
|
|
|
if ( \${$tableName}Count > \$limit ) { |
|
171
|
|
|
include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
172
|
|
|
\$pagenav = new XoopsPageNav(\${$tableName}Count, \$limit, \$start, 'start', 'op=list&limit=' . \$limit); |
|
173
|
|
|
\$GLOBALS['xoopsTpl']->assign('pagenav', \$pagenav->renderNav(4)); |
|
174
|
|
|
} |
|
175
|
|
|
} else { |
|
176
|
|
|
\$GLOBALS['xoopsTpl']->assign('error', {$language}THEREARENT_{$stuTableName}); |
|
177
|
|
|
} |
|
178
|
|
|
EOT; |
|
179
|
|
|
|
|
180
|
|
|
return $ret; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/* |
|
184
|
|
|
* @private function getAdminPagesNew |
|
185
|
|
|
* @param string $moduleDirname |
|
186
|
|
|
* @param string $tableName |
|
187
|
|
|
* @param string $fieldInForm |
|
188
|
|
|
* @param string $language |
|
189
|
|
|
* @return string |
|
190
|
|
|
*/ |
|
191
|
|
|
private function getAdminPagesNew($moduleDirname, $tableName, $tableSoleName, $fieldInForm, $language) |
|
192
|
|
|
{ |
|
193
|
|
|
$stuTableName = strtoupper($tableName); |
|
|
|
|
|
|
194
|
|
|
$stuTableSoleName = strtoupper($tableSoleName); |
|
195
|
|
|
$ucfTableName = ucfirst($tableName); |
|
196
|
|
|
|
|
197
|
|
|
$ret = $this->t2.$this->adminxoopscode->getAdminTemplateMain($moduleDirname, $tableName); |
|
|
|
|
|
|
198
|
|
|
$navigation = $this->adminxoopscode->getAdminAddNavigation($tableName); |
|
|
|
|
|
|
199
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('navigation', $navigation); |
|
|
|
|
|
|
200
|
|
|
|
|
201
|
|
View Code Duplication |
if (1 == $fieldInForm) { |
|
|
|
|
|
|
202
|
|
|
$ret .= $this->t2.$this->adminxoopscode->getAdminItemButton($language, $tableName, $stuTableSoleName, '', 'list'); |
|
|
|
|
|
|
203
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('buttons', "\$adminMenu->renderButton()"); |
|
|
|
|
|
|
204
|
|
|
} |
|
205
|
|
|
$ret .= <<<EOT |
|
206
|
|
|
// Get Form |
|
207
|
|
|
\${$tableName}Obj =& \${$tableName}Handler->create(); |
|
208
|
|
|
\$form = \${$tableName}Obj->getForm{$ucfTableName}(); |
|
209
|
|
|
\$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n |
|
210
|
|
|
EOT; |
|
211
|
|
|
|
|
212
|
|
|
return $ret; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/* |
|
216
|
|
|
* @private function getAdminPagesSave |
|
217
|
|
|
* @param string $moduleDirname |
|
218
|
|
|
* @param string $tableName |
|
219
|
|
|
* @param string $language |
|
220
|
|
|
* @param string $fields |
|
221
|
|
|
* @param string $fieldId |
|
222
|
|
|
* @param string $fieldMain |
|
223
|
|
|
* @return string |
|
224
|
|
|
*/ |
|
225
|
|
|
private function getAdminPagesSave($moduleDirname, $tableName, $language, $fields, $fieldId, $fieldMain) |
|
226
|
|
|
{ |
|
227
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
|
228
|
|
|
$ucfTableName = ucfirst($tableName); |
|
229
|
|
|
|
|
230
|
|
|
$ret = $this->phpcode->getPhpCodeCommentLine('Set Vars'); |
|
231
|
|
|
$xoopsSecurityCheck = $this->xoopscode->getXoopsCodeSecurityCheck(); |
|
|
|
|
|
|
232
|
|
|
$securityError = $this->xoopscode->getXoopsCodeSecurityGetError(); |
|
|
|
|
|
|
233
|
|
|
$implode = $this->phpcode->getPhpCodeImplode(',', $securityError); |
|
234
|
|
|
$redirectError = $this->xoopscode->getXoopsCodeRedirectHeader($tableName, '', '3', $implode); |
|
|
|
|
|
|
235
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions($xoopsSecurityCheck, '', '', $redirectError, false, "\t"); |
|
236
|
|
|
|
|
237
|
|
|
$isset = $this->phpcode->getPhpCodeIsset($ccFieldId); |
|
238
|
|
|
$contentIf = $this->xoopscode->getXoopsCodeGet($tableName, $ccFieldId, 'Obj', true); |
|
|
|
|
|
|
239
|
|
|
$contentElse = $this->xoopscode->getXoopsCodeObjHandlerCreate($tableName); |
|
|
|
|
|
|
240
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions($isset, '', '', $contentIf, $contentElse, "\t"); |
|
241
|
|
|
|
|
242
|
|
|
foreach (array_keys($fields) as $f) { |
|
243
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
|
|
|
|
|
244
|
|
|
$fieldType = $fields[$f]->getVar('field_type'); |
|
|
|
|
|
|
245
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
|
|
|
|
|
246
|
|
|
if ($f > 0) { // If we want to hide field id |
|
247
|
|
|
switch ($fieldElement) { |
|
248
|
|
|
case 5: |
|
249
|
|
|
case 6: |
|
250
|
|
|
$ret .= $this->xoopscode->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName); |
|
|
|
|
|
|
251
|
|
|
break; |
|
252
|
|
|
case 10: |
|
253
|
|
|
$ret .= $this->xoopscode->getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName); |
|
|
|
|
|
|
254
|
|
|
break; |
|
255
|
|
|
case 12: |
|
256
|
|
|
$ret .= $this->xoopscode->getXoopsCodeUrlFileSetVar($moduleDirname, $tableName, $fieldName); |
|
|
|
|
|
|
257
|
|
|
break; |
|
258
|
|
|
case 13: |
|
259
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
|
|
|
|
|
|
260
|
|
|
$fieldMain = $fieldName; |
|
261
|
|
|
} |
|
262
|
|
|
$ret .= $this->xoopscode->getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain); |
|
|
|
|
|
|
263
|
|
|
break; |
|
264
|
|
|
case 14: |
|
265
|
|
|
$ret .= $this->xoopscode->getXoopsCodeUploadFileSetVar($moduleDirname, $tableName, $fieldName); |
|
|
|
|
|
|
266
|
|
|
break; |
|
267
|
|
|
case 15: |
|
268
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName); |
|
|
|
|
|
|
269
|
|
|
break; |
|
270
|
|
|
default: |
|
271
|
|
|
if ($fieldType == 2 || $fieldType == 7 || $fieldType == 8) { |
|
272
|
|
|
$ret .= $this->xoopscode->getXoopsCodeSetVarNumb($tableName, $fieldName); |
|
|
|
|
|
|
273
|
|
|
} else { |
|
274
|
|
|
$ret .= $this->xoopscode->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']"); |
|
|
|
|
|
|
275
|
|
|
} |
|
276
|
|
|
break; |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
} |
|
280
|
|
|
$ret .= <<<EOT |
|
281
|
|
|
// Insert Data |
|
282
|
|
|
if (\${$tableName}Handler->insert(\${$tableName}Obj)) { |
|
283
|
|
|
redirect_header('{$tableName}.php?op=list', 2, {$language}FORM_OK); |
|
284
|
|
|
} |
|
285
|
|
|
// Get Form |
|
286
|
|
|
\$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors()); |
|
287
|
|
|
\$form =& \${$tableName}Obj->getForm{$ucfTableName}(); |
|
288
|
|
|
\$GLOBALS['xoopsTpl']->assign('form', \$form->render()); |
|
289
|
|
|
EOT; |
|
290
|
|
|
|
|
291
|
|
|
return $ret; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/* |
|
295
|
|
|
* @private function getAdminPagesEdit |
|
296
|
|
|
* @param string $moduleDirname |
|
297
|
|
|
* @param string $tableName |
|
|
|
|
|
|
298
|
|
|
* @param string $tableFieldname |
|
|
|
|
|
|
299
|
|
|
* @param string $language |
|
300
|
|
|
* @param string $fieldId |
|
301
|
|
|
* @param string $fieldInForm |
|
302
|
|
|
* @return string |
|
303
|
|
|
*/ |
|
304
|
|
|
private function getAdminPagesEdit($moduleDirname, $table, $language, $fieldId, $fieldInForm) |
|
305
|
|
|
{ |
|
306
|
|
|
$tableName = $table->getVar('table_name'); |
|
307
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
308
|
|
|
$tableFieldname = $table->getVar('table_fieldname'); |
|
309
|
|
|
$stuTableName = strtoupper($tableName); |
|
|
|
|
|
|
310
|
|
|
$ucfTableName = ucfirst($tableName); |
|
311
|
|
|
$stuTableSoleName = strtoupper($tableSoleName); |
|
312
|
|
|
$stuTableFieldname = strtoupper($tableFieldname); |
|
|
|
|
|
|
313
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
|
314
|
|
|
|
|
315
|
|
|
$ret = $this->t2.$this->adminxoopscode->getAdminTemplateMain($moduleDirname, $tableName); |
|
|
|
|
|
|
316
|
|
|
$navigation = $this->adminxoopscode->getAdminAddNavigation($tableName); |
|
|
|
|
|
|
317
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('navigation', $navigation); |
|
|
|
|
|
|
318
|
|
|
|
|
319
|
|
|
if (1 == $fieldInForm) { |
|
320
|
|
|
$ret .= $this->t2.$this->adminxoopscode->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add'); |
|
|
|
|
|
|
321
|
|
|
$ret .= $this->t2.$this->adminxoopscode->getAdminItemButton($language, $tableName, $stuTableSoleName, '', 'list'); |
|
|
|
|
|
|
322
|
|
|
$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('buttons', "\$adminMenu->renderButton()"); |
|
|
|
|
|
|
323
|
|
|
} |
|
324
|
|
|
$ret .= <<<EOT |
|
325
|
|
|
// Get Form |
|
326
|
|
|
\${$tableName}Obj = \${$tableName}Handler->get(\${$ccFieldId}); |
|
327
|
|
|
\$form = \${$tableName}Obj->getForm{$ucfTableName}(); |
|
328
|
|
|
\$GLOBALS['xoopsTpl']->assign('form', \$form->render()); |
|
329
|
|
|
EOT; |
|
330
|
|
|
|
|
331
|
|
|
return $ret; |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
/* |
|
335
|
|
|
* @private function getAdminPagesDelete |
|
336
|
|
|
* @param string $tableName |
|
337
|
|
|
* @param string $language |
|
338
|
|
|
* @param string $fieldId |
|
339
|
|
|
* @param string $fieldMain |
|
340
|
|
|
* @return string |
|
341
|
|
|
*/ |
|
342
|
|
|
private function getAdminPagesDelete($tableName, $language, $fieldId, $fieldMain) |
|
343
|
|
|
{ |
|
344
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
|
345
|
|
|
$ret = <<<EOT |
|
346
|
|
|
\${$tableName}Obj =& \${$tableName}Handler->get(\${$ccFieldId}); |
|
347
|
|
|
if (isset(\$_REQUEST['ok']) && 1 == \$_REQUEST['ok']) { |
|
348
|
|
|
if ( !\$GLOBALS['xoopsSecurity']->check() ) { |
|
349
|
|
|
redirect_header('{$tableName}.php', 3, implode(', ', \$GLOBALS['xoopsSecurity']->getErrors())); |
|
350
|
|
|
} |
|
351
|
|
|
if (\${$tableName}Handler->delete(\${$tableName}Obj)) { |
|
352
|
|
|
redirect_header('{$tableName}.php', 3, {$language}FORM_DELETE_OK); |
|
353
|
|
|
} else { |
|
354
|
|
|
\$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors()); |
|
355
|
|
|
} |
|
356
|
|
|
} else { |
|
357
|
|
|
xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => 'delete'), \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_DELETE, \${$tableName}Obj->getVar('{$fieldMain}'))); |
|
358
|
|
|
} |
|
359
|
|
|
EOT; |
|
360
|
|
|
|
|
361
|
|
|
return $ret; |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
/* |
|
365
|
|
|
* @private function getAdminPagesUpdate |
|
366
|
|
|
* @param string $moduleDirname |
|
367
|
|
|
* @param string $tableName |
|
368
|
|
|
* @param string $fieldId |
|
369
|
|
|
* @param string $fieldName |
|
370
|
|
|
* @return string |
|
371
|
|
|
*/ |
|
372
|
|
|
private function getAdminPagesUpdate($moduleDirname, $tableName, $fieldId, $fieldName) |
|
|
|
|
|
|
373
|
|
|
{ |
|
374
|
|
|
$stuModuleName = strtoupper($moduleDirname); |
|
375
|
|
|
$ccFieldId = $this->getCamelCase($fieldId, false, true); |
|
376
|
|
|
$ret = <<<EOT |
|
377
|
|
|
if (isset(\${$ccFieldId})) { |
|
378
|
|
|
\${$tableName}Obj =& \${$tableName}Handler->get(\${$ccFieldId}); |
|
379
|
|
|
} |
|
380
|
|
|
\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']); |
|
381
|
|
|
if (\${$tableName}Handler->insert(\${$tableName}Obj)) { |
|
382
|
|
|
redirect_header('{$tableName}.php', 3, _AM_{$stuModuleName}_FORM_OK); |
|
383
|
|
|
} |
|
384
|
|
|
\$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors()); |
|
385
|
|
|
EOT; |
|
386
|
|
|
|
|
387
|
|
|
return $ret; |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
/* |
|
391
|
|
|
* @public function render |
|
392
|
|
|
* @param null |
|
393
|
|
|
*/ |
|
394
|
|
|
/** |
|
395
|
|
|
* @param $filename |
|
396
|
|
|
* |
|
397
|
|
|
* @return bool|string |
|
398
|
|
|
*/ |
|
399
|
|
|
public function renderFile($filename) |
|
400
|
|
|
{ |
|
401
|
|
|
$module = $this->getModule(); |
|
402
|
|
|
$table = $this->getTable(); |
|
403
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
404
|
|
|
$tableName = $table->getVar('table_name'); |
|
405
|
|
|
$tableSoleName = $table->getVar('table_solename'); |
|
406
|
|
|
$language = $this->getLanguage($moduleDirname, 'AM'); |
|
407
|
|
|
$fields = $this->tdmcfile->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
|
|
|
|
|
|
408
|
|
View Code Duplication |
foreach (array_keys($fields) as $f) { |
|
|
|
|
|
|
409
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
410
|
|
|
$fieldInForm = $fields[$f]->getVar('field_inform'); |
|
411
|
|
|
if (0 == $f) { |
|
412
|
|
|
$fieldId = $fieldName; |
|
413
|
|
|
} |
|
414
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
|
415
|
|
|
$fieldMain = $fieldName; |
|
416
|
|
|
} |
|
417
|
|
|
} |
|
418
|
|
|
$content = $this->getHeaderFilesComments($module, $filename); |
|
419
|
|
|
$content .= $this->getAdminPagesHeader($moduleDirname, $tableName, $fieldId); |
|
|
|
|
|
|
420
|
|
|
$list = $this->getAdminPagesList($moduleDirname, $table, $language, $fields, $fieldId, $fieldInForm, $fieldMain); |
|
|
|
|
|
|
421
|
|
|
if (1 == $fieldInForm) { |
|
422
|
|
|
$new = $this->getAdminPagesNew($moduleDirname, $tableName, $tableSoleName, $fieldInForm, $language); |
|
423
|
|
|
$save = $this->getAdminPagesSave($moduleDirname, $tableName, $language, $fields, $fieldId, $fieldMain); |
|
424
|
|
|
$edit = $this->getAdminPagesEdit($moduleDirname, $table, $language, $fieldId, $fieldInForm); |
|
425
|
|
|
} |
|
426
|
|
|
$delete = $this->getAdminPagesDelete($tableName, $language, $fieldId, $fieldMain); |
|
427
|
|
|
|
|
428
|
|
|
$cases = array('list' => array($list), |
|
429
|
|
|
'new' => array($new), |
|
|
|
|
|
|
430
|
|
|
'save' => array($save), |
|
|
|
|
|
|
431
|
|
|
'edit' => array($edit), |
|
|
|
|
|
|
432
|
|
|
'delete' => array($delete)); |
|
433
|
|
|
$content .= $this->getAdminPagesSwitch($cases); |
|
434
|
|
|
$content .= $this->getInclude('footer'); |
|
435
|
|
|
// |
|
436
|
|
|
$this->tdmcfile->create($moduleDirname, 'admin', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED); |
|
|
|
|
|
|
437
|
|
|
|
|
438
|
|
|
return $this->tdmcfile->renderFile(); |
|
|
|
|
|
|
439
|
|
|
} |
|
440
|
|
|
} |
|
441
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.