3131 */
3232class 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 };'> </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
0 commit comments