|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder\Files\Templates\User\Defstyle; |
|
4
|
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
|
6
|
|
|
use XoopsModules\Modulebuilder\Files; |
|
7
|
|
|
|
|
8
|
|
|
/* |
|
9
|
|
|
You may not change or alter any portion of this comment or credits |
|
10
|
|
|
of supporting developers from this source code or any supporting source code |
|
11
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
12
|
|
|
|
|
13
|
|
|
This program is distributed in the hope that it will be useful, |
|
14
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* modulebuilder module. |
|
19
|
|
|
* |
|
20
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
21
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
22
|
|
|
* |
|
23
|
|
|
* @since 2.5.0 |
|
24
|
|
|
* |
|
25
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* class UserPrint. |
|
31
|
|
|
*/ |
|
32
|
|
|
class UserPrint extends Files\CreateFile |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var mixed |
|
36
|
|
|
*/ |
|
37
|
|
|
private $hc = null; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var mixed |
|
41
|
|
|
*/ |
|
42
|
|
|
private $sc = null; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @public function constructor |
|
46
|
|
|
* @param null |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct() |
|
49
|
|
|
{ |
|
50
|
|
|
parent::__construct(); |
|
51
|
|
|
$this->hc = Modulebuilder\Files\CreateHtmlCode::getInstance(); |
|
52
|
|
|
$this->sc = Modulebuilder\Files\CreateSmartyCode::getInstance(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @static function getInstance |
|
57
|
|
|
* @param null |
|
58
|
|
|
* @return UserPrint |
|
59
|
|
|
*/ |
|
60
|
|
|
public static function getInstance() |
|
61
|
|
|
{ |
|
62
|
|
|
static $instance = false; |
|
63
|
|
|
if (!$instance) { |
|
64
|
|
|
$instance = new self(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $instance; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @public function write |
|
72
|
|
|
* @param $module |
|
73
|
|
|
* @param $table |
|
74
|
|
|
* @param string $filename |
|
75
|
|
|
*/ |
|
76
|
|
|
public function write($module, $table, $filename) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->setModule($module); |
|
79
|
|
|
$this->setTable($table); |
|
80
|
|
|
$this->setFileName($filename); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @private function getTemplatesUserPrintHeader |
|
85
|
|
|
* @param string $moduleDirname |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
private function getTemplatesUserPrintHeader($moduleDirname) |
|
89
|
|
|
{ |
|
90
|
|
|
$ret = $this->hc->getHtmlComment('Header', '',"\n"); |
|
91
|
|
|
$ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'header', false, '', '', "\n\n"); |
|
92
|
|
|
|
|
93
|
|
|
return $ret; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @private function getTemplatesUserPrintTableThead |
|
98
|
|
|
* @param $tableSoleName |
|
99
|
|
|
* @param $tableAutoincrement |
|
100
|
|
|
* @param array $fields |
|
101
|
|
|
* @param string $language |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
|
|
private function getTemplatesUserPrintTableThead($tableSoleName, $tableAutoincrement, $fields, $language) |
|
105
|
|
|
{ |
|
106
|
|
|
$th = ''; |
|
107
|
|
|
$langHeadId = \mb_strtoupper($tableSoleName) . '_ID'; |
|
108
|
|
|
if (1 == $tableAutoincrement) { |
|
109
|
|
|
$lang = $this->sc->getSmartyConst($language, $langHeadId); |
|
110
|
|
|
$th .= $this->hc->getHtmlTag('th', ['class' => 'center'], $lang, false, "\t\t\t"); |
|
111
|
|
|
} |
|
112
|
|
|
foreach (\array_keys($fields) as $f) { |
|
113
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
114
|
|
|
$rpFieldName = $this->getRightString($fieldName); |
|
115
|
|
|
$langFieldName = \mb_strtoupper($tableSoleName) . '_' . \mb_strtoupper($rpFieldName); |
|
116
|
|
|
if (1 == $fields[$f]->getVar('field_user')) { |
|
117
|
|
|
$lang = $this->sc->getSmartyConst($language, $langFieldName); |
|
118
|
|
|
$th .= $this->hc->getHtmlTag('th', ['class' => 'center'], $lang, false, "\t\t\t"); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$lang = $this->sc->getSmartyConst($language, 'FORM_ACTION'); |
|
123
|
|
|
$th .= $this->hc->getHtmlTag('th', ['class' => 'center width5'], $lang, false, "\t\t\t"); |
|
124
|
|
|
$tr = $this->hc->getHtmlTableRow($th, 'head', "\t\t"); |
|
125
|
|
|
$ret = $this->hc->getHtmlTableThead($tr, '', "\t"); |
|
126
|
|
|
|
|
127
|
|
|
return $ret; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @private function getTemplatesUserPrintTableTBody |
|
132
|
|
|
* @param string $moduleDirname |
|
133
|
|
|
* @param string $tableName |
|
134
|
|
|
* @param $tableSoleName |
|
135
|
|
|
* @param $tableAutoincrement |
|
136
|
|
|
* @param array $fields |
|
137
|
|
|
* @return string |
|
138
|
|
|
* @internal param string $language |
|
139
|
|
|
*/ |
|
140
|
|
|
private function getTemplatesUserPrintTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields) |
|
141
|
|
|
{ |
|
142
|
|
|
$td = ''; |
|
143
|
|
|
if (1 == $tableAutoincrement) { |
|
144
|
|
|
$double = $this->sc->getSmartyDoubleVar($tableSoleName, 'id'); |
|
145
|
|
|
$td .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t"); |
|
146
|
|
|
} |
|
147
|
|
|
foreach (\array_keys($fields) as $f) { |
|
148
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
149
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
150
|
|
|
$rpFieldName = $this->getRightString($fieldName); |
|
151
|
|
|
if (1 == $fields[$f]->getVar('field_user')) { |
|
152
|
|
|
switch ($fieldElement) { |
|
153
|
|
|
case 3: |
|
154
|
|
|
case 4: |
|
155
|
|
|
$double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName . '_short'); |
|
156
|
|
|
$td .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t"); |
|
157
|
|
|
break; |
|
158
|
|
|
case 5: |
|
159
|
|
|
$double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
160
|
|
|
$src = $this->sc->getSmartyNoSimbol('xoModuleIcons16') . $double . '.png'; |
|
161
|
|
|
$img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $tableName], '', true,'',''); |
|
162
|
|
|
$td .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t"); |
|
163
|
|
|
break; |
|
164
|
|
|
case 9: |
|
165
|
|
|
// This is to be reviewed, as it was initially to style = "backgroung-color: #" |
|
166
|
|
|
// Now with HTML5 is not supported inline style in the parameters of the HTML tag |
|
167
|
|
|
// Old code was <span style="background-color: #<{\$list.{$rpFieldName}}>;">... |
|
168
|
|
|
$double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
169
|
|
|
$color = "<span style='background-color:{$double};'> </span>"; |
|
170
|
|
|
$td .= $this->hc->getHtmlTableData($color, 'center', '',"\t\t\t"); |
|
171
|
|
|
break; |
|
172
|
|
|
case 10: |
|
173
|
|
|
$src = $this->sc->getSmartyNoSimbol('xoModuleIcons32'); |
|
174
|
|
|
$src .= $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
175
|
|
|
$img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $tableName], '', true,'',''); |
|
176
|
|
|
$td .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t"); |
|
177
|
|
|
break; |
|
178
|
|
|
case 13: |
|
179
|
|
|
$single = $this->sc->getSmartySingleVar($moduleDirname . '_upload_url'); |
|
180
|
|
|
$double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
181
|
|
|
$img = $this->hc->getHtmlTag('img', ['src' => $single . "/images/{$tableName}/" . $double, 'alt' => $tableName, 'style' => 'max-width:100px'], '', true, '', ''); |
|
182
|
|
|
$td .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t"); |
|
183
|
|
|
break; |
|
184
|
|
|
case 16: |
|
185
|
|
|
$double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
186
|
|
|
$src = $this->sc->getSmartyNoSimbol('$modPathIcon16') . 'status' . $double . '.png'; |
|
187
|
|
|
$imgAlt = $this->sc->getSmartyDoubleVar($tableSoleName, 'status_text'); |
|
188
|
|
|
$img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $imgAlt, 'title' => $imgAlt], '', true,'',''); |
|
189
|
|
|
$td .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t"); |
|
190
|
|
|
break; |
|
191
|
|
|
default: |
|
192
|
|
|
if (0 != $f) { |
|
193
|
|
|
$double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
|
194
|
|
|
$td .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t"); |
|
195
|
|
|
} |
|
196
|
|
|
break; |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
$cycle = $this->sc->getSmartyNoSimbol('cycle values=\'odd, even\''); |
|
201
|
|
|
$tr = $this->hc->getHtmlTableRow($td, $cycle, "\t\t"); |
|
202
|
|
|
$foreach = $this->sc->getSmartyForeach($tableSoleName, $tableName . '_list', $tr, '','', "\t\t"); |
|
203
|
|
|
$tbody = $this->hc->getHtmlTableTbody($foreach,'' , "\t"); |
|
204
|
|
|
|
|
205
|
|
|
return $tbody; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @private function getTemplatesUserPrintTable |
|
210
|
|
|
* @param string $moduleDirname |
|
211
|
|
|
* @param string $tableName |
|
212
|
|
|
* @param $tableSoleName |
|
213
|
|
|
* @param $tableAutoincrement |
|
214
|
|
|
* @param $fields |
|
215
|
|
|
* @param string $language |
|
216
|
|
|
* @return string |
|
217
|
|
|
*/ |
|
218
|
|
|
private function getTemplatesUserPrintTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language) |
|
219
|
|
|
{ |
|
220
|
|
|
$tbody = $this->getTemplatesUserPrintTableThead($tableSoleName, $tableAutoincrement, $fields, $language); |
|
221
|
|
|
$tbody .= $this->getTemplatesUserPrintTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields); |
|
222
|
|
|
|
|
223
|
|
|
return $this->hc->getHtmlTable($tbody, 'table table-bordered', ''); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @private function getTemplatesUserPrint |
|
228
|
|
|
* @param string $moduleDirname |
|
229
|
|
|
* @param string $tableName |
|
230
|
|
|
* @param $tableSoleName |
|
231
|
|
|
* @param $tableAutoincrement |
|
232
|
|
|
* @param $fields |
|
233
|
|
|
* @param string $language |
|
234
|
|
|
* @return string |
|
235
|
|
|
*/ |
|
236
|
|
|
private function getTemplatesUserPrint($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language) |
|
237
|
|
|
{ |
|
238
|
|
|
$htmlTable = $this->getTemplatesUserPrintTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language); |
|
239
|
|
|
|
|
240
|
|
|
return $htmlTable; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* @private function getTemplatesUserPrintFooter |
|
245
|
|
|
* @param string $moduleDirname |
|
246
|
|
|
* @return string |
|
247
|
|
|
*/ |
|
248
|
|
|
private function getTemplatesUserPrintFooter($moduleDirname) |
|
249
|
|
|
{ |
|
250
|
|
|
$ret = $this->hc->getHtmlComment('Footer', '', "\n"); |
|
251
|
|
|
$ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'footer', false); |
|
252
|
|
|
|
|
253
|
|
|
return $ret; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @public function render |
|
258
|
|
|
* @param null |
|
259
|
|
|
* @return bool|string |
|
260
|
|
|
*/ |
|
261
|
|
|
public function render() |
|
262
|
|
|
{ |
|
263
|
|
|
$module = $this->getModule(); |
|
264
|
|
|
$table = $this->getTable(); |
|
265
|
|
|
$filename = $this->getFileName(); |
|
266
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
267
|
|
|
$language = $this->getLanguage($moduleDirname, 'MA'); |
|
268
|
|
|
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'), 'field_order'); |
|
269
|
|
|
$content = $this->getTemplatesUserPrintHeader($moduleDirname); |
|
270
|
|
|
$content .= $this->getTemplatesUserPrint($moduleDirname, $table->getVar('table_name'), $table->getVar('table_solename'), $table->getVar('table_autoincrement'), $fields, $language); |
|
271
|
|
|
$content .= $this->getTemplatesUserPrintFooter($moduleDirname); |
|
272
|
|
|
|
|
273
|
|
|
$this->create($moduleDirname, 'templates', $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED); |
|
274
|
|
|
|
|
275
|
|
|
return $this->renderFile(); |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|