1- <?php
2-
3- /*
4- Copyright (c) 2005, Till Brehm, projektfarm Gmbh
5- All rights reserved.
6-
7- Redistribution and use in source and binary forms, with or without modification,
8- are permitted provided that the following conditions are met:
9-
10- * Redistributions of source code must retain the above copyright notice,
11- this list of conditions and the following disclaimer.
12- * Redistributions in binary form must reproduce the above copyright notice,
13- this list of conditions and the following disclaimer in the documentation
14- and/or other materials provided with the distribution.
15- * Neither the name of ISPConfig nor the names of its contributors
16- may be used to endorse or promote products derived from this software without
17- specific prior written permission.
18-
19- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22- IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29- */
30-
31- /**
32- * Action framework for the listform library.
33- *
34- * @author Till Brehm <t.brehm@scrigo.org>
35- * @copyright Copyright © 2005, Till Brehm
36- */
37-
38- class listform_actions {
39-
40- var $ id ;
41- var $ idx_key ;
42- var $ DataRowColor ;
43- var $ SQLExtWhere = '' ;
44- var $ SQLOrderBy = '' ;
45-
46- function onLoad () {
47- global $ app , $ conf , $ list_def_file ;
48-
49- if (!is_object ($ app ->tpl )) $ app ->uses ('tpl ' );
50- if (!is_object ($ app ->listform )) $ app ->uses ('listform ' );
51- if (!is_object ($ app ->tform )) $ app ->uses ('tform ' );
52-
53- // Clear session variable that is used when lists are embedded with the listview plugin
54- $ _SESSION ["s " ]["form " ]["return_to " ] = '' ;
55-
56- // Load list definition
57- $ app ->listform ->loadListDef ($ list_def_file );
58-
59- if (!is_file ('templates/ ' .$ app ->listform ->listDef ["name " ].'_list.htm ' )) {
60- $ app ->uses ('listform_tpl_generator ' );
61- $ app ->listform_tpl_generator ->buildHTML ($ app ->listform ->listDef );
62- }
63-
64- $ app ->tpl ->newTemplate ("listpage.tpl.htm " );
65- $ app ->tpl ->setInclude ('content_tpl ' ,'templates/ ' .$ app ->listform ->listDef ["name " ].'_list.htm ' );
66-
67- // Getting Datasets from DB
68- $ records = $ app ->db ->queryAllRecords ($ this ->getQueryString ());
69-
70-
71- $ this ->DataRowColor = "#FFFFFF " ;
72- if (is_array ($ records )) {
73- $ this ->idx_key = $ app ->listform ->listDef ["table_idx " ];
74- foreach ($ records as $ rec ) {
75- $ records_new [] = $ this ->prepareDataRow ($ rec );
76- }
77- }
78-
79- $ app ->tpl ->setLoop ('records ' ,$ records_new );
80-
81- $ this ->onShow ();
82-
83-
84- }
85-
86- function prepareDataRow ($ rec ) {
87- global $ app ;
88-
89- $ rec = $ app ->listform ->decode ($ rec );
90-
91- // Alternating datarow colors
92- $ this ->DataRowColor = ($ this ->DataRowColor == "#FFFFFF " )?"#EEEEEE " :"#FFFFFF " ;
93- $ rec ["bgcolor " ] = $ this ->DataRowColor ;
94-
95- // substitute value for select fields
96- foreach ($ app ->listform ->listDef ["item " ] as $ field ) {
97- $ key = $ field ["field " ];
98- if ($ field ['formtype ' ] == "SELECT " ) {
99- $ rec [$ key ] = $ field ['value ' ][$ rec [$ key ]];
100- }
101- }
102-
103- // The variable "id" contains always the index variable
104- $ rec ["id " ] = $ rec [$ this ->idx_key ];
105-
106- return $ rec ;
107- }
108-
109- function getQueryString () {
110- global $ app ;
111-
112- // Generate the search sql
113- if ($ app ->listform ->listDef ["auth " ] != 'no ' ) {
114- if ($ _SESSION ["s " ]["user " ]["typ " ] == "admin " ) {
115- $ sql_where = "" ;
116- } else {
117- $ sql_where = $ app ->tform ->getAuthSQL ('r ' )." and " ;
118- }
119- }
120-
121- if ($ this ->SQLExtWhere != '' ) {
122- $ sql_where .= " " .$ this ->SQLExtWhere ." and " ;
123- }
124-
125- $ sql_where = $ app ->listform ->getSearchSQL ($ sql_where );
126- $ app ->tpl ->setVar ($ app ->listform ->searchValues );
127-
128- $ order_by_sql = $ this ->SQLOrderBy ;
129-
130- // Generate SQL for paging
131- $ limit_sql = $ app ->listform ->getPagingSQL ($ sql_where );
132- $ app ->tpl ->setVar ("paging " ,$ app ->listform ->pagingHTML );
133-
134- return "SELECT * FROM " .$ app ->listform ->listDef ["table " ]." WHERE $ sql_where $ order_by_sql $ limit_sql " ;
135-
136- }
137-
138-
139- function onShow () {
140- global $ app ;
141-
142- // Language File setzen
143- $ lng_file = "lib/lang/ " .$ _SESSION ["s " ]["language " ]."_ " .$ app ->listform ->listDef ['name ' ]."_list.lng " ;
144- include ($ lng_file );
145- $ app ->tpl ->setVar ($ wb );
146- $ app ->tpl ->setVar ("form_action " ,$ app ->listform ->listDef ["file " ]);
147-
148- // Parse the templates and send output to the browser
149- $ this ->onShowEnd ();
150- }
151-
152- function onShowEnd () {
153- global $ app ;
154-
155- $ app ->tpl_defaults ();
156- $ app ->tpl ->pparse ();
157- }
158- }
159-
1+ <?php
2+
3+ /*
4+ Copyright (c) 2005, Till Brehm, projektfarm Gmbh
5+ All rights reserved.
6+
7+ Redistribution and use in source and binary forms, with or without modification,
8+ are permitted provided that the following conditions are met:
9+
10+ * Redistributions of source code must retain the above copyright notice,
11+ this list of conditions and the following disclaimer.
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ this list of conditions and the following disclaimer in the documentation
14+ and/or other materials provided with the distribution.
15+ * Neither the name of ISPConfig nor the names of its contributors
16+ may be used to endorse or promote products derived from this software without
17+ specific prior written permission.
18+
19+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+ IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+ */
30+
31+ /**
32+ * Action framework for the listform library.
33+ *
34+ * @author Till Brehm <t.brehm@scrigo.org>
35+ * @copyright Copyright © 2005, Till Brehm
36+ */
37+
38+ class listform_actions {
39+
40+ var $ id ;
41+ var $ idx_key ;
42+ var $ DataRowColor ;
43+ var $ SQLExtWhere = '' ;
44+ var $ SQLOrderBy = '' ;
45+
46+ function onLoad () {
47+ global $ app , $ conf , $ list_def_file ;
48+
49+ if (!@is_object ($ app ->tpl )) $ app ->uses ('tpl ' );
50+ if (!@is_object ($ app ->listform )) $ app ->uses ('listform ' );
51+ if (!@is_object ($ app ->tform )) $ app ->uses ('tform ' );
52+
53+ // Clear session variable that is used when lists are embedded with the listview plugin
54+ $ _SESSION ["s " ]["form " ]["return_to " ] = '' ;
55+
56+ // Load list definition
57+ $ app ->listform ->loadListDef ($ list_def_file );
58+
59+ if (!is_file ('templates/ ' .$ app ->listform ->listDef ["name " ].'_list.htm ' )) {
60+ $ app ->uses ('listform_tpl_generator ' );
61+ $ app ->listform_tpl_generator ->buildHTML ($ app ->listform ->listDef );
62+ }
63+
64+ $ app ->tpl ->newTemplate ("listpage.tpl.htm " );
65+ $ app ->tpl ->setInclude ('content_tpl ' ,'templates/ ' .$ app ->listform ->listDef ["name " ].'_list.htm ' );
66+
67+ // Getting Datasets from DB
68+ $ records = $ app ->db ->queryAllRecords ($ this ->getQueryString ());
69+
70+
71+ $ this ->DataRowColor = "#FFFFFF " ;
72+ $ records_new = '' ;
73+ if (is_array ($ records )) {
74+ $ this ->idx_key = $ app ->listform ->listDef ["table_idx " ];
75+ foreach ($ records as $ rec ) {
76+ $ records_new [] = $ this ->prepareDataRow ($ rec );
77+ }
78+ }
79+
80+ $ app ->tpl ->setLoop ('records ' ,$ records_new );
81+
82+ $ this ->onShow ();
83+
84+
85+ }
86+
87+ function prepareDataRow ($ rec ) {
88+ global $ app ;
89+
90+ $ rec = $ app ->listform ->decode ($ rec );
91+
92+ // Alternating datarow colors
93+ $ this ->DataRowColor = ($ this ->DataRowColor == "#FFFFFF " )?"#EEEEEE " :"#FFFFFF " ;
94+ $ rec ["bgcolor " ] = $ this ->DataRowColor ;
95+
96+ // substitute value for select fields
97+ foreach ($ app ->listform ->listDef ["item " ] as $ field ) {
98+ $ key = $ field ["field " ];
99+ if ($ field ['formtype ' ] == "SELECT " ) {
100+ $ rec [$ key ] = $ field ['value ' ][$ rec [$ key ]];
101+ }
102+ }
103+
104+ // The variable "id" contains always the index variable
105+ $ rec ["id " ] = $ rec [$ this ->idx_key ];
106+
107+ return $ rec ;
108+ }
109+
110+ function getQueryString () {
111+ global $ app ;
112+
113+ // Generate the search sql
114+ if ($ app ->listform ->listDef ["auth " ] != 'no ' ) {
115+ if ($ _SESSION ["s " ]["user " ]["typ " ] == "admin " ) {
116+ $ sql_where = "" ;
117+ } else {
118+ $ sql_where = $ app ->tform ->getAuthSQL ('r ' )." and " ;
119+ }
120+ }
121+
122+ if ($ this ->SQLExtWhere != '' ) {
123+ $ sql_where .= " " .$ this ->SQLExtWhere ." and " ;
124+ }
125+
126+ $ sql_where = $ app ->listform ->getSearchSQL ($ sql_where );
127+ $ app ->tpl ->setVar ($ app ->listform ->searchValues );
128+
129+ $ order_by_sql = $ this ->SQLOrderBy ;
130+
131+ // Generate SQL for paging
132+ $ limit_sql = $ app ->listform ->getPagingSQL ($ sql_where );
133+ $ app ->tpl ->setVar ("paging " ,$ app ->listform ->pagingHTML );
134+
135+ return "SELECT * FROM " .$ app ->listform ->listDef ["table " ]." WHERE $ sql_where $ order_by_sql $ limit_sql " ;
136+
137+ }
138+
139+
140+ function onShow () {
141+ global $ app ;
142+
143+ // Language File setzen
144+ $ lng_file = "lib/lang/ " .$ _SESSION ["s " ]["language " ]."_ " .$ app ->listform ->listDef ['name ' ]."_list.lng " ;
145+ include ($ lng_file );
146+ $ app ->tpl ->setVar ($ wb );
147+ $ app ->tpl ->setVar ("form_action " ,$ app ->listform ->listDef ["file " ]);
148+
149+ // Parse the templates and send output to the browser
150+ $ this ->onShowEnd ();
151+ }
152+
153+ function onShowEnd () {
154+ global $ app ;
155+
156+ $ app ->tpl_defaults ();
157+ $ app ->tpl ->pparse ();
158+ }
159+ }
160+
160161?>
0 commit comments