Skip to content

Commit f1016dd

Browse files
committed
fixed bugs in print output
1 parent 0f02420 commit f1016dd

4 files changed

Lines changed: 152 additions & 114 deletions

File tree

class/Files/Language/LanguageMain.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ private function getLanguageMain($module, $language)
120120
$tableSubmit = 0;
121121
$tableBroken = 0;
122122
$tableRate = 0;
123+
$tablePrint = 0;
123124
foreach (\array_keys($tables) as $i) {
124125
if (1 == $tables[$i]->getVar('table_user')) {
125126
$tableName = $tables[$i]->getVar('table_name');
@@ -133,6 +134,9 @@ private function getLanguageMain($module, $language)
133134
if (1 === (int)$tables[$i]->getVar('table_rate')) {
134135
$tableRate = 1;
135136
}
137+
if (1 === (int)$tables[$i]->getVar('table_print')) {
138+
$tablePrint = 1;
139+
}
136140
$stuTableName = \mb_strtoupper($tableName);
137141
$stuTableSoleName = \mb_strtoupper($tableSoleName);
138142
$ucfTableName = $utility::UcFirstAndToLower($tableName);
@@ -197,6 +201,10 @@ private function getLanguageMain($module, $language)
197201
$ret .= $this->ld->getDefine($language, 'RATING_DISLIKE', 'Dislike');
198202
$ret .= $this->ld->getDefine($language, 'RATING_ERROR1', 'Error: update base table failed!');
199203
}
204+
if (1 === $tablePrint) {
205+
$ret .= $this->ld->getAboveHeadDefines('Print');
206+
$ret .= $this->ld->getDefine($language, 'PRINT', 'Print');
207+
}
200208
return $ret;
201209
}
202210

class/Files/Templates/User/Defstyle/UserPrint.php

Lines changed: 137 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,25 @@
3131
*/
3232
class UserPrint extends Files\CreateFile
3333
{
34+
/**
35+
* @var mixed
36+
*/
37+
private $hc = null;
38+
39+
/**
40+
* @var mixed
41+
*/
42+
private $sc = null;
43+
3444
/**
3545
* @public function constructor
3646
* @param null
3747
*/
3848
public function __construct()
3949
{
4050
parent::__construct();
51+
$this->hc = Modulebuilder\Files\CreateHtmlCode::getInstance();
52+
$this->sc = Modulebuilder\Files\CreateSmartyCode::getInstance();
4153
}
4254

4355
/**
@@ -71,150 +83,172 @@ public function write($module, $table, $filename)
7183
/**
7284
* @private function getTemplatesUserPrintHeader
7385
* @param string $moduleDirname
74-
* @param string $table
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
75101
* @param string $language
76-
*
77102
* @return string
78103
*/
79-
private function getTemplatesUserPrintHeader($moduleDirname, $table, $language)
104+
private function getTemplatesUserPrintTableThead($tableSoleName, $tableAutoincrement, $fields, $language)
80105
{
81-
$ret = <<<EOT
82-
<{include file="db:{$moduleDirname}_header.tpl"}>
83-
<table class="{$moduleDirname}">
84-
<thead class="outer">
85-
<tr class="head">\n
86-
EOT;
87-
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
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+
}
88112
foreach (\array_keys($fields) as $f) {
89-
$fieldName = $fields[$f]->getVar('field_name');
90-
$langStuFieldName = $language . \mb_strtoupper($fieldName);
91-
if ((1 == $table->getVar('table_autoincrement')) || (1 == $fields[$f]->getVar('field_user'))) {
92-
$ret .= <<<EOT
93-
<th class="center"><{\$smarty.const.{$langStuFieldName}}></th>\n
94-
EOT;
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");
95119
}
96120
}
97-
$ret .= <<<EOT
98-
</tr>
99-
</thead>\n
100-
EOT;
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");
101126

102127
return $ret;
103128
}
104129

105130
/**
106-
* @private function getTemplatesUserPrintBody
131+
* @private function getTemplatesUserPrintTableTBody
107132
* @param string $moduleDirname
108-
* @param string $table
133+
* @param string $tableName
134+
* @param $tableSoleName
135+
* @param $tableAutoincrement
136+
* @param array $fields
109137
* @return string
138+
* @internal param string $language
110139
*/
111-
private function getTemplatesUserPrintBody($moduleDirname, $table)
140+
private function getTemplatesUserPrintTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields)
112141
{
113-
$tableName = $table->getVar('table_name');
114-
$ret = <<<EOT
115-
<tbody>
116-
<{foreach item=list from=\${$tableName}}>
117-
<tr class="<{cycle values='odd, even'}>">\n
118-
EOT;
119-
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
142+
$td = '';
143+
if (1 == $tableAutoincrement) {
144+
$double = $this->sc->getSmartyDoubleVar($tableSoleName, 'id');
145+
$td .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t");
146+
}
120147
foreach (\array_keys($fields) as $f) {
121148
$fieldName = $fields[$f]->getVar('field_name');
122149
$fieldElement = $fields[$f]->getVar('field_element');
123150
$rpFieldName = $this->getRightString($fieldName);
124-
if ((1 == $table->getVar('table_autoincrement')) || (1 == $fields[$f]->getVar('field_user'))) {
151+
if (1 == $fields[$f]->getVar('field_user')) {
125152
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;
126164
case 9:
127-
$ret .= <<<EOT
128-
<td class="center"><span style="background-color: #<{\$list.{$rpFieldName}}>;">\t\t</span></td>\n
129-
EOT;
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};'>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
170+
$td .= $this->hc->getHtmlTableData($color, 'center', '',"\t\t\t");
130171
break;
131172
case 10:
132-
$ret .= <<<EOT
133-
<td class="center"><img src="<{xoModuleIcons32}><{\$list.{$rpFieldName}}>" alt="{$tableName}"></td>\n
134-
EOT;
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");
135177
break;
136178
case 13:
137-
$ret .= <<<EOT
138-
<td class="center"><img src="<{\${$moduleDirname}_upload_url}>/images/{$tableName}/<{\$list.{$rpFieldName}}>" alt="{$tableName}"></td>\n
139-
EOT;
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");
140190
break;
141191
default:
142-
$ret .= <<<EOT
143-
<td class="center"><{\$list.{$rpFieldName}}></td>\n
144-
EOT;
192+
if (0 != $f) {
193+
$double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName);
194+
$td .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t");
195+
}
145196
break;
146197
}
147198
}
148199
}
149-
$ret .= <<<EOT
150-
</tr>
151-
<{/foreach}>
152-
</tbody>
153-
</table>\n
154-
EOT;
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");
155204

156-
return $ret;
205+
return $tbody;
157206
}
158207

159208
/**
160-
* @private function getTemplatesUserPrintBodyFieldnameEmpty
209+
* @private function getTemplatesUserPrintTable
161210
* @param string $moduleDirname
162-
* @param $table
211+
* @param string $tableName
212+
* @param $tableSoleName
213+
* @param $tableAutoincrement
214+
* @param $fields
215+
* @param string $language
163216
* @return string
164217
*/
165-
private function getTemplatesUserPrintBodyFieldnameEmpty($moduleDirname, $table)
218+
private function getTemplatesUserPrintTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language)
166219
{
167-
$tableName = $table->getVar('table_name');
168-
$ret = <<<EOT
169-
<tbody>
170-
<{foreach item=list from=\${$tableName}}>
171-
<tr class="<{cycle values='odd, even'}>">\n
172-
EOT;
173-
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
174-
foreach (\array_keys($fields) as $f) {
175-
$fieldName = $fields[$f]->getVar('field_name');
176-
$fieldElement = $fields[$f]->getVar('field_element');
177-
if ((1 == $table->getVar('table_autoincrement')) || (1 == $fields[$f]->getVar('field_user'))) {
178-
switch ($fieldElement) {
179-
case 9:
180-
$ret .= <<<EOT
181-
<td class="center"><span style="background-color: #<{\$list.{$fieldName}}>;"></span></td>\n
182-
EOT;
183-
break;
184-
case 13:
185-
$ret .= <<<EOT
186-
<td class="center"><img src="<{\${$moduleDirname}_upload_url}>/images/{$tableName}/<{\$list.{$fieldName}}>" alt="{$tableName}"></td>\n
187-
EOT;
188-
break;
189-
default:
190-
$ret .= <<<EOT
191-
<td class="center"><{\$list.{$fieldName}}></td>\n
192-
EOT;
193-
break;
194-
}
195-
}
196-
}
197-
$ret .= <<<EOT
198-
</tr>
199-
<{/foreach}>
200-
</tbody>
201-
</table>\n
202-
EOT;
220+
$tbody = $this->getTemplatesUserPrintTableThead($tableSoleName, $tableAutoincrement, $fields, $language);
221+
$tbody .= $this->getTemplatesUserPrintTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields);
203222

204-
return $ret;
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;
205241
}
206242

207243
/**
208244
* @private function getTemplatesUserPrintFooter
209245
* @param string $moduleDirname
210-
*
211246
* @return string
212247
*/
213248
private function getTemplatesUserPrintFooter($moduleDirname)
214249
{
215-
$ret = <<<EOT
216-
<{include file="db:{$moduleDirname}_footer.tpl"}>
217-
EOT;
250+
$ret = $this->hc->getHtmlComment('Footer', '', "\n");
251+
$ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'footer', false);
218252

219253
return $ret;
220254
}
@@ -226,20 +260,15 @@ private function getTemplatesUserPrintFooter($moduleDirname)
226260
*/
227261
public function render()
228262
{
229-
$module = $this->getModule();
230-
$table = $this->getTable();
231-
$filename = $this->getFileName();
232-
$moduleDirname = $module->getVar('mod_dirname');
233-
$tableFieldname = $table->getVar('table_fieldname');
234-
$language = $this->getLanguage($moduleDirname, 'MA');
235-
$content = $this->getTemplatesUserPrintHeader($moduleDirname, $table, $language);
236-
// Verify if table_fieldname is not empty
237-
if (!empty($tableFieldname)) {
238-
$content .= $this->getTemplatesUserPrintBody($moduleDirname, $table);
239-
} else {
240-
$content .= $this->getTemplatesUserPrintBodyFieldnameEmpty($moduleDirname, $table);
241-
}
242-
$content .= $this->getTemplatesUserPrintFooter($moduleDirname);
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);
243272

244273
$this->create($moduleDirname, 'templates', $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED);
245274

class/Files/User/UserPrint.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ public function getUserPrint($moduleDirname, $language)
117117
$ucfFieldName = \ucfirst($fieldName);
118118
}
119119
$ccFieldId = $this->getCamelCase($fieldId, false, true);
120-
$stuLpFieldName = \mb_strtoupper($ccFieldId);
121120
$ret = $this->pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', '');
122121
$ret .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', '');
123122
$ret .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants']);
124123
$ret .= $this->getInclude();
124+
$ret .= $this->pc->getPhpCodeIncludeDir("XOOPS_ROOT_PATH . '/header.php'", '', true, true, 'require', '');
125125
$ret .= $this->xc->getXcXoopsRequest($ccFieldId, (string)$fieldId, '', 'Int');
126126
$ret .= $this->pc->getPhpCodeCommentLine('Define Stylesheet');
127127
$ret .= $this->xc->getXcXoThemeAddStylesheet();
128-
$redirectHeader = $this->xc->getXcRedirectHeader("{$stuModuleDirname}_URL . '/index.php'", '', '2', "{$language}NO{$stuLpFieldName}", false, "\t");
128+
$redirectHeader = $this->xc->getXcRedirectHeader("{$stuModuleDirname}_URL . '/index.php'", '', '2', "{$language}INVALID_PARAM", false, "\t");
129129
$ret .= $this->pc->getPhpCodeConditions("empty(\${$ccFieldId})", '', '', $redirectHeader);
130130

131131
$ret .= $this->pc->getPhpCodeCommentLine('Get Instance of Handler');
@@ -160,11 +160,11 @@ public function getUserPrint($moduleDirname, $language)
160160
$noPerm .= $this->getSimpleString('exit();', "\t");
161161
$ret .= $this->pc->getPhpCodeConditions($gperm, '', '', $noPerm);
162162
$ret .= $this->xc->getXcGetValues($tableName, $tableSoleName, '', true);
163-
$contentForeach = $this->xc->getXcXoopsTplAppend('"{$k}"', '$v', "\t");
164-
$ret .= $this->pc->getPhpCodeForeach($tableSoleName, false, 'k', 'v', $contentForeach);
163+
$ret .= $this->xc->getXcXoopsTplAppend($tableName . '_list', '$' . $tableSoleName, '');
164+
$ret .= $this->pc->getPhpCodeBlankLine();
165165
$ret .= $this->xc->getXcXoopsTplAssign('xoops_sitename', "\$GLOBALS['xoopsConfig']['sitename']");
166-
$getVar = $this->xc->getXcGetVar('', $tableSoleName, $fieldMain, true);
167-
$stripTags = $this->pc->getPhpCodeStripTags('', $getVar . ' - ' . "{$language}PRINT" . ' - ' . "\$GLOBALS['xoopsModule']->name()", true);
166+
$getVar = $this->xc->getXcGetVar('', $tableName, $fieldMain, true);
167+
$stripTags = $this->pc->getPhpCodeStripTags('', $getVar . " . ' - ' . " . "{$language}PRINT" . " . ' - ' . " . "\$GLOBALS['xoopsModule']->getVar('name')", true);
168168
$ret .= $this->xc->getXcXoopsTplAssign('xoops_pagetitle', $stripTags);
169169
$ret .= $this->xc->getXcXoopsTplDisplay($tableName . '_print.tpl', '', false);
170170

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- fixed bugs in pdf creation (goffy)
2222
- allow pdf creation for multiple tables (goffy)
2323
- changed pdf output template based (goffy)
24+
- fixed bugs in print output (goffy)
2425

2526
<h5>3.04 Alpha 1 [2020-06-12]</h5> Dev: XOOPS 2.5.11, PHP 7.4.5
2627
<hr>

0 commit comments

Comments
 (0)