|
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: TemplatesAdminPages.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class TemplatesAdminPages. |
|
27
|
|
|
*/ |
|
28
|
|
|
class TemplatesAdminPages extends TDMCreateFile |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $tdmcfile = null; |
|
34
|
|
|
|
|
35
|
|
|
/* |
|
36
|
|
|
* @public function constructor |
|
37
|
|
|
* @param null |
|
38
|
|
|
*/ |
|
39
|
|
|
/** |
|
40
|
|
|
* |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct() |
|
43
|
|
|
{ |
|
44
|
|
|
parent::__construct(); |
|
45
|
|
|
$this->tdmcfile = TDMCreateFile::getInstance(); |
|
|
|
|
|
|
46
|
|
|
$this->htmlcode = TDMCreateHtmlSmartyCodes::getInstance(); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/* |
|
50
|
|
|
* @static function &getInstance |
|
51
|
|
|
* @param null |
|
52
|
|
|
*/ |
|
53
|
|
|
/** |
|
54
|
|
|
* @return TemplatesAdminPages |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function &getInstance() |
|
57
|
|
|
{ |
|
58
|
|
|
static $instance = false; |
|
59
|
|
|
if (!$instance) { |
|
60
|
|
|
$instance = new self(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $instance; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/* |
|
67
|
|
|
* @public function write |
|
68
|
|
|
* @param string $module |
|
69
|
|
|
* @param string $table |
|
70
|
|
|
*/ |
|
71
|
|
|
public function write($module, $table) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->setModule($module); |
|
74
|
|
|
$this->setTable($table); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/* |
|
78
|
|
|
* @private function getTemplatesAdminPagesHeader |
|
79
|
|
|
* @param string $moduleDirname |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
private function getTemplatesAdminPagesHeader($moduleDirname) |
|
83
|
|
|
{ |
|
84
|
|
|
$ret = $this->htmlcode->getHtmlComment('Header').PHP_EOL; |
|
|
|
|
|
|
85
|
|
|
$ret .= $this->htmlcode->getSmartyIncludeFile($moduleDirname, 'header', true).PHP_EOL; |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
return $ret; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/* |
|
91
|
|
|
* @private function getTemplatesAdminPagesTableThead |
|
92
|
|
|
* @param string $moduleDirname |
|
|
|
|
|
|
93
|
|
|
* @param string $tableName |
|
|
|
|
|
|
94
|
|
|
* @param string $fields |
|
95
|
|
|
* @param string $language |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
private function getTemplatesAdminPagesTableThead($tableSoleName, $tableAutoincrement, $fields, $language) |
|
99
|
|
|
{ |
|
100
|
|
|
$th = ''; |
|
101
|
|
|
$langHeadId = strtoupper($tableSoleName).'_ID'; |
|
102
|
|
|
if (1 == $tableAutoincrement) { |
|
103
|
|
|
$lang = $this->htmlcode->getSmartyConst($language, $langHeadId); |
|
|
|
|
|
|
104
|
|
|
$th .= $this->htmlcode->getHtmlTag('th', array('class' => 'center'), $lang).PHP_EOL; |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
foreach (array_keys($fields) as $f) { |
|
107
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
|
|
|
|
|
108
|
|
|
$rpFieldName = $this->tdmcfile->getRightString($fieldName); |
|
|
|
|
|
|
109
|
|
|
$langFieldName = strtoupper($tableSoleName).'_'.strtoupper($rpFieldName); |
|
110
|
|
|
if (1 == $fields[$f]->getVar('field_inlist')) { |
|
|
|
|
|
|
111
|
|
|
$lang = $this->htmlcode->getSmartyConst($language, $langFieldName); |
|
|
|
|
|
|
112
|
|
|
$th .= $this->htmlcode->getHtmlTag('th', array('class' => 'center'), $lang).PHP_EOL; |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$lang = $this->htmlcode->getSmartyConst($language, 'FORM_ACTION'); |
|
|
|
|
|
|
117
|
|
|
$th .= $this->htmlcode->getHtmlTag('th', array('class' => 'center width5'), $lang).PHP_EOL; |
|
|
|
|
|
|
118
|
|
|
$tr = $this->htmlcode->getHtmlTag('tr', array('class' => 'head'), $th).PHP_EOL; |
|
|
|
|
|
|
119
|
|
|
$ret = $this->htmlcode->getHtmlTag('thead', array(), $tr).PHP_EOL; |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
return $ret; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/* |
|
125
|
|
|
* @private function getTemplatesAdminPagesTableTBody |
|
126
|
|
|
* @param string $moduleDirname |
|
127
|
|
|
* @param string $tableName |
|
128
|
|
|
* @param string $fields |
|
129
|
|
|
* @param string $language |
|
|
|
|
|
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
|
|
private function getTemplatesAdminPagesTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields) |
|
133
|
|
|
{ |
|
134
|
|
|
$td = ''; |
|
135
|
|
|
if (1 == $tableAutoincrement) { |
|
136
|
|
|
$double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, 'id'); |
|
|
|
|
|
|
137
|
|
|
$td .= $this->htmlcode->getHtmlTableData($double, 'center').PHP_EOL; |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
foreach (array_keys($fields) as $f) { |
|
140
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
|
|
|
|
|
141
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
|
|
|
|
|
142
|
|
|
$rpFieldName = $this->tdmcfile->getRightString($fieldName); |
|
|
|
|
|
|
143
|
|
|
if (0 == $f) { |
|
144
|
|
|
$fieldId = $fieldName; |
|
145
|
|
|
} |
|
146
|
|
|
if (1 == $fields[$f]->getVar('field_inlist')) { |
|
|
|
|
|
|
147
|
|
|
switch ($fieldElement) { |
|
148
|
|
|
case 9: |
|
149
|
|
|
// This is to be reviewed, as it was initially to style = "backgroung-color: #" |
|
150
|
|
|
// Now with HTML5 is not supported inline style in the parameters of the HTML tag |
|
151
|
|
|
// Old code was <span style="background-color: #<{\$list.{$rpFieldName}}>;">... |
|
152
|
|
|
$double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
|
|
|
|
|
153
|
|
|
$span = $this->htmlcode->getHtmlTag('span', array(), $double); |
|
|
|
|
|
|
154
|
|
|
$td .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), $span).PHP_EOL; |
|
|
|
|
|
|
155
|
|
|
/*$ret .= <<<EOT |
|
156
|
|
|
<td class="center"><span style="background-color: #<{\$list.{$rpFieldName}}>;"> </span></td>\n |
|
157
|
|
|
EOT;*/ |
|
158
|
|
|
break; |
|
159
|
|
|
case 10: |
|
160
|
|
|
$src = $this->htmlcode->getSmartyNoSimbol('xoModuleIcons32'); |
|
|
|
|
|
|
161
|
|
|
$src .= $this->htmlcode->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
|
|
|
|
|
162
|
|
|
$img = $this->htmlcode->getHtmlTag('img', array('src' => $src, 'alt' => $tableName), '', false); |
|
|
|
|
|
|
163
|
|
|
$td .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), $img).PHP_EOL; |
|
|
|
|
|
|
164
|
|
|
break; |
|
165
|
|
|
case 13: |
|
166
|
|
|
$single = $this->htmlcode->getSmartySingleVar($moduleDirname.'_upload_url'); |
|
|
|
|
|
|
167
|
|
|
$double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
|
|
|
|
|
168
|
|
|
$img = $this->htmlcode->getHtmlTag('img', array('src' => $single."/images/{$tableName}/".$double, 'alt' => $tableName, 'style' => 'max-width:100px'), '', false); |
|
|
|
|
|
|
169
|
|
|
$td .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), $img).PHP_EOL; |
|
|
|
|
|
|
170
|
|
|
break; |
|
171
|
|
|
default: |
|
172
|
|
|
if (0 != $f) { |
|
173
|
|
|
$double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
|
|
|
|
|
174
|
|
|
$td .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), $double).PHP_EOL; |
|
|
|
|
|
|
175
|
|
|
} |
|
176
|
|
|
break; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
$lang = $this->htmlcode->getSmartyConst('', '_EDIT'); |
|
|
|
|
|
|
181
|
|
|
$double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, 'id'); |
|
|
|
|
|
|
182
|
|
|
$src = $this->htmlcode->getSmartyNoSimbol('xoModuleIcons16 edit.png'); |
|
|
|
|
|
|
183
|
|
|
$img = $this->htmlcode->getHtmlTag('img', array('src' => $src, 'alt' => $tableName), '', false); |
|
|
|
|
|
|
184
|
|
|
$anchor = $this->htmlcode->getHtmlTag('a', array('href' => $tableName.".php?op=edit&{$fieldId}=".$double, 'title' => $lang), $img).PHP_EOL; |
|
|
|
|
|
|
185
|
|
|
$lang = $this->htmlcode->getSmartyConst('', '_DELETE'); |
|
|
|
|
|
|
186
|
|
|
$double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, 'id'); |
|
|
|
|
|
|
187
|
|
|
$src = $this->htmlcode->getSmartyNoSimbol('xoModuleIcons16 delete.png'); |
|
|
|
|
|
|
188
|
|
|
$img = $this->htmlcode->getHtmlTag('img', array('src' => $src, 'alt' => $tableName), '', false); |
|
|
|
|
|
|
189
|
|
|
$anchor .= $this->htmlcode->getHtmlTag('a', array('href' => $tableName.".php?op=delete&{$fieldId}=".$double, 'title' => $lang), $img).PHP_EOL; |
|
|
|
|
|
|
190
|
|
|
$td .= $this->htmlcode->getHtmlTag('td', array('class' => 'center width5'), "\n".$anchor).PHP_EOL; |
|
|
|
|
|
|
191
|
|
|
$cycle = $this->htmlcode->getSmartyNoSimbol('cycle values="odd, even"'); |
|
|
|
|
|
|
192
|
|
|
$tr = $this->htmlcode->getHtmlTag('tr', array('class' => $cycle), $td).PHP_EOL; |
|
|
|
|
|
|
193
|
|
|
$foreach = $this->htmlcode->getSmartyForeach($tableSoleName, $tableName.'_list', $tr).PHP_EOL; |
|
|
|
|
|
|
194
|
|
|
$tbody = $this->htmlcode->getHtmlTag('tbody', array(), $foreach).PHP_EOL; |
|
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
return $this->htmlcode->getSmartyConditions($tableName.'_count', '', '', $tbody).PHP_EOL; |
|
|
|
|
|
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/* |
|
200
|
|
|
* @private function getTemplatesAdminPagesTable |
|
201
|
|
|
* @param string $moduleDirname |
|
202
|
|
|
* @param string $tableName |
|
203
|
|
|
* @param string $fields |
|
204
|
|
|
* @param string $language |
|
205
|
|
|
* @return string |
|
206
|
|
|
*/ |
|
207
|
|
|
private function getTemplatesAdminPagesTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language) |
|
208
|
|
|
{ |
|
209
|
|
|
$tbody = $this->getTemplatesAdminPagesTableThead($tableSoleName, $tableAutoincrement, $fields, $language); |
|
210
|
|
|
$tbody .= $this->getTemplatesAdminPagesTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields); |
|
211
|
|
|
|
|
212
|
|
|
return $this->htmlcode->getHtmlTable($tbody, 'table table-bordered').PHP_EOL; |
|
|
|
|
|
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/* |
|
216
|
|
|
* @private function getTemplatesAdminPages |
|
217
|
|
|
* @param string $moduleDirname |
|
218
|
|
|
* @param string $tableName |
|
219
|
|
|
* @param string $fields |
|
220
|
|
|
* @param string $language |
|
221
|
|
|
* @return string |
|
222
|
|
|
*/ |
|
223
|
|
|
private function getTemplatesAdminPages($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language) |
|
224
|
|
|
{ |
|
225
|
|
|
$htmlTable = $this->getTemplatesAdminPagesTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language); |
|
226
|
|
|
$htmlTable .= $this->htmlcode->getHtmlTag('div', array('class' => 'clear'), ' ').PHP_EOL; |
|
|
|
|
|
|
227
|
|
|
$single = $this->htmlcode->getSmartySingleVar('pagenav'); |
|
|
|
|
|
|
228
|
|
|
$div = $this->htmlcode->getHtmlTag('div', array('class' => 'xo-pagenav floatright'), $single); |
|
|
|
|
|
|
229
|
|
|
$div .= $this->htmlcode->getHtmlTag('div', array('class' => 'clear spacer'), '').PHP_EOL; |
|
|
|
|
|
|
230
|
|
|
$htmlTable .= $this->htmlcode->getSmartyConditions('pagenav', '', '', $div).PHP_EOL; |
|
|
|
|
|
|
231
|
|
|
$ifList = $this->htmlcode->getSmartyConditions($tableName.'_list', '', '', $htmlTable).PHP_EOL; |
|
|
|
|
|
|
232
|
|
|
$single = $this->htmlcode->getSmartySingleVar('form'); |
|
|
|
|
|
|
233
|
|
|
$divComm = $this->htmlcode->getHtmlComment('Display navigation').PHP_EOL; |
|
|
|
|
|
|
234
|
|
|
//$divComm .= $this->htmlcode->getHtmlTag('div', array('class' => 'errorMsg'), $single).PHP_EOL; |
|
|
|
|
|
|
235
|
|
|
$ifList .= $this->htmlcode->getSmartyConditions('form', '', '', $single).PHP_EOL; |
|
|
|
|
|
|
236
|
|
|
$single = $this->htmlcode->getSmartySingleVar('error'); |
|
|
|
|
|
|
237
|
|
|
$strong = $this->htmlcode->getHtmlTag('strong', array(), $single).PHP_EOL; |
|
|
|
|
|
|
238
|
|
|
$div = $this->htmlcode->getHtmlTag('div', array('class' => 'errorMsg'), $strong).PHP_EOL; |
|
|
|
|
|
|
239
|
|
|
$ifList .= $this->htmlcode->getSmartyConditions('error', '', '', $div).PHP_EOL; |
|
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
return $ifList; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/* |
|
245
|
|
|
* @private function getTemplatesAdminPagesFooter |
|
246
|
|
|
* @param string $moduleDirname |
|
247
|
|
|
* @return string |
|
248
|
|
|
*/ |
|
249
|
|
|
private function getTemplatesAdminPagesFooter($moduleDirname) |
|
250
|
|
|
{ |
|
251
|
|
|
$ret = $this->htmlcode->getHtmlTag('br', array(), '', false).PHP_EOL; |
|
|
|
|
|
|
252
|
|
|
$ret .= $this->htmlcode->getHtmlComment('Footer').PHP_EOL; |
|
|
|
|
|
|
253
|
|
|
$ret .= $this->htmlcode->getSmartyIncludeFile($moduleDirname, 'footer', true); |
|
|
|
|
|
|
254
|
|
|
|
|
255
|
|
|
return $ret; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/* |
|
259
|
|
|
* @public function render |
|
260
|
|
|
* @param $filename |
|
261
|
|
|
* @return bool|string |
|
262
|
|
|
*/ |
|
263
|
|
|
public function renderFile($filename) |
|
264
|
|
|
{ |
|
265
|
|
|
$module = $this->getModule(); |
|
266
|
|
|
$table = $this->getTable(); |
|
267
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
268
|
|
|
$language = $this->getLanguage($moduleDirname, 'AM'); |
|
269
|
|
|
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'), 'field_order'); |
|
270
|
|
|
$content = $this->getTemplatesAdminPagesHeader($moduleDirname); |
|
271
|
|
|
$content .= $this->getTemplatesAdminPages($moduleDirname, $table->getVar('table_name'), $table->getVar('table_solename'), $table->getVar('table_autoincrement'), $fields, $language); |
|
272
|
|
|
$content .= $this->getTemplatesAdminPagesFooter($moduleDirname); |
|
273
|
|
|
// |
|
274
|
|
|
$this->tdmcfile->create($moduleDirname, 'templates/admin', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED); |
|
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
return $this->tdmcfile->renderFile(); |
|
|
|
|
|
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.