Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
f14188 1 <?php
T 2
436ed8 3 /*
R 4 Copyright (c) 2007, 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
f14188 31 class plugin_listview extends plugin_base {
T 32
b1a6a5 33     var $module;
MC 34     var $form;
35     var $tab;
36     var $record_id;
37     var $formdef;
38     var $options;
f14188 39
b1a6a5 40     function onShow() {
f14188 41
b1a6a5 42         global $app;
f14188 43
b1a6a5 44         $app->uses('listform');
MC 45         $app->listform->loadListDef($this->options["listdef"]);
f14188 46
b1a6a5 47         //$app->listform->SQLExtWhere = "type = 'alias'";
f14188 48
b1a6a5 49         $listTpl = new tpl;
MC 50         $listTpl->newTemplate('templates/'.$app->listform->listDef["name"].'_list.htm');
f14188 51
b1a6a5 52         //die(print_r($app->tform_actions));
f14188 53
b1a6a5 54         // Changing some of the list values to reflect that the list is called within a tform page
MC 55         $app->listform->listDef["file"] = $app->tform->formDef["action"];
56         // $app->listform->listDef["page_params"] = "&id=".$app->tform_actions->id."&next_tab=".$_SESSION["s"]["form"]["tab"];
57         $app->listform->listDef["page_params"] = "&id=".$this->form->id."&next_tab=".$_SESSION["s"]["form"]["tab"];
58         $listTpl->setVar('parent_id', $this->form->id);
59         $listTpl->setVar('theme', $_SESSION['s']['theme']);
60
61         // Generate the SQL for searching
62         $sql_where = "";
63         if($app->listform->listDef["auth"] != 'no') {
64             if($_SESSION["s"]["user"]["typ"] != "admin") {
a8b07f 65                 $sql_where = $app->tform->getAuthSQL('r')." and";
b1a6a5 66             }
MC 67         }
f14188 68
b1a6a5 69         if($this->options["sqlextwhere"] != '') {
MC 70             $sql_where .= " ".$this->options["sqlextwhere"]." and";
71         }
f14188 72
b1a6a5 73         $sql_where = $app->listform->getSearchSQL($sql_where);
MC 74         $listTpl->setVar($app->listform->searchValues);
f14188 75
b1a6a5 76         // Generate SQL for paging
MC 77         $limit_sql = $app->listform->getPagingSQL($sql_where);
78         $listTpl->setVar("paging", $app->listform->pagingHTML);
79
80         $sql_order_by = '';
81         if(isset($this->options["sql_order_by"])) {
82             $sql_order_by = $this->options["sql_order_by"];
83         }
8145fb 84
X 85         //* Limit each page
b1a6a5 86         $limits = array('5'=>'5', '15'=>'15', '25'=>'25', '50'=>'50', '100'=>'100', '999999999' => 'all');
8145fb 87
X 88         //* create options and set selected, if default -> 15 is selected
a8b07f 89         $options='';
8145fb 90         foreach($limits as $key => $val){
b1a6a5 91             $options .= '<option value="'.$key.'" '.(isset($_SESSION['search']['limit']) &&  $_SESSION['search']['limit'] == $key ? 'selected="selected"':'' ).(!isset($_SESSION['search']['limit']) && $key == '15' ? 'selected="selected"':'').'>'.$val.'</option>';
8145fb 92         }
b1a6a5 93         $listTpl->setVar('search_limit', '<select name="search_limit" style="width:50px">'.$options.'</select>');
8145fb 94
X 95
96         //Sorting
97         if(!isset($_SESSION['search'][$app->listform->listDef["name"]]['order'])){
b1a6a5 98             $_SESSION['search'][$app->listform->listDef["name"]]['order'] = '';
8145fb 99         }
X 100
101         if(!empty($_GET['orderby'])){
b1a6a5 102             $order = str_replace('tbl_col_', '', $_GET['orderby']);
MC 103             //* Check the css class submited value
104             if (preg_match("/^[a-z\_]{1,}$/", $order)) {
105                 if($_SESSION['search'][$app->listform->listDef["name"]]['order'] == $order){
106                     $_SESSION['search'][$app->listform->listDef["name"]]['order'] = $order.' DESC';
107                 } else {
108                     $_SESSION['search'][$app->listform->listDef["name"]]['order'] = $order;
109                 }
110             }
8145fb 111         }
X 112
113         // If a manuel oder by like customers isset the sorting will be infront
114         if(!empty($_SESSION['search'][$app->listform->listDef["name"]]['order'])){
b1a6a5 115             if(empty($sql_order_by)){
MC 116                 $sql_order_by = "ORDER BY ".$_SESSION['search'][$app->listform->listDef["name"]]['order'];
117             } else {
118                 $sql_order_by = str_replace("ORDER BY ", "ORDER BY ".$_SESSION['search'][$app->listform->listDef["name"]]['order'].', ', $sql_order_by);
119             }
8145fb 120         }
f14188 121
b1a6a5 122         // Loading language field
MC 123         $lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$app->listform->listDef['name']."_list.lng";
124         include $lng_file;
125         $listTpl->setVar($wb);
f14188 126
T 127
b1a6a5 128         // Get the data
cc7a82 129         $records = $app->db->queryAllRecords("SELECT * FROM ?? WHERE $sql_where $sql_order_by $limit_sql", $app->listform->listDef["table"]);
f14188 130
b1a6a5 131         $bgcolor = "#FFFFFF";
MC 132         if(is_array($records)) {
133             $idx_key = $app->listform->listDef["table_idx"];
134             foreach($records as $rec) {
f14188 135
b1a6a5 136                 $rec = $app->listform->decode($rec);
f14188 137
b1a6a5 138                 // Change of color
MC 139                 $bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
140                 $rec["bgcolor"] = $bgcolor;
f14188 141
b1a6a5 142                 // substitute value for select fields
MC 143                 foreach($app->listform->listDef["item"] as $field) {
144                     $key = $field["field"];
145                     if($field['formtype'] == "SELECT") {
146                         if(strtolower($rec[$key]) == 'y' or strtolower($rec[$key]) == 'n') {
147                             // Set a additional image variable for bolean fields
148                             $rec['_'.$key.'_'] = (strtolower($rec[$key]) == 'y')?'x16/tick_circle.png':'x16/cross_circle.png';
149                         }
150                         //* substitute value for select field
151                         @$rec[$key] = $field['value'][$rec[$key]];
152                     }
153                     // Create a lowercase version of every item
154                     $rec[$key.'_lowercase'] = strtolower($rec[$key]);
155                 }
f14188 156
b1a6a5 157                 // The variable "id" contains always the index field
MC 158                 $rec["id"] = $rec[$idx_key];
159                 $rec["delete_confirmation"] = $wb['delete_confirmation'];
f14188 160
b1a6a5 161                 $records_new[] = $rec;
MC 162             }
163         }
f14188 164
b1a6a5 165         $listTpl->setLoop('records', @$records_new);
MC 166
167         // Setting Returnto information in the session
168         $list_name = $app->listform->listDef["name"];
169         // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
170         $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
171         $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
172         $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
173         $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
174         $_SESSION["s"]["form"]["return_to"] = $list_name;
175         //die(print_r($_SESSION["s"]["list"][$list_name]));
176
ccccf1 177         // defaults
MC 178         $listTpl->setVar('app_title', $app->_conf['app_title']);
179         if(isset($_SESSION['s']['user'])) {
180             $listTpl->setVar('app_version', $app->_conf['app_version']);
181             // get pending datalog changes
182             $datalog = $app->db->datalogStatus();
183             $listTpl->setVar('datalog_changes_txt', $app->lng('datalog_changes_txt'));
184             $listTpl->setVar('datalog_changes_end_txt', $app->lng('datalog_changes_end_txt'));
185             $listTpl->setVar('datalog_changes_count', $datalog['count']);
186             $listTpl->setLoop('datalog_changes', $datalog['entries']);
187         } else {
188             $listTpl->setVar('app_version', '');
189         }
190         $listTpl->setVar('app_link', $app->_conf['app_link']);
191
192         $listTpl->setVar('app_logo', $app->_conf['logo']);
193
194         $listTpl->setVar('phpsessid', session_id());
195
196         $listTpl->setVar('theme', $_SESSION['s']['theme']);
197         $listTpl->setVar('html_content_encoding', $app->_conf['html_content_encoding']);
198
199         $listTpl->setVar('delete_confirmation', $app->lng('delete_confirmation'));
200         //print_r($_SESSION);
201         if(isset($_SESSION['s']['module']['name'])) {
202             $listTpl->setVar('app_module', $_SESSION['s']['module']['name']);
203         }
204         if(isset($_SESSION['s']['user']) && $_SESSION['s']['user']['typ'] == 'admin') {
205             $listTpl->setVar('is_admin', 1);
206         }
207         if(isset($_SESSION['s']['user']) && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
208             $listTpl->setVar('is_reseller', 1);
209         }
210         /* Show username */
211         if(isset($_SESSION['s']['user'])) {
212             $listTpl->setVar('cpuser', $_SESSION['s']['user']['username']);
213             $listTpl->setVar('logout_txt', $app->lng('logout_txt'));
214             /* Show search field only for normal users, not mail users */
215             if(stristr($_SESSION['s']['user']['username'], '@')){
216                 $listTpl->setVar('usertype', 'mailuser');
217             } else {
218                 $listTpl->setVar('usertype', 'normaluser');
219             }
220         }
221
222         /* Global Search */
223         $listTpl->setVar('globalsearch_resultslimit_of_txt', $app->lng('globalsearch_resultslimit_of_txt'));
224         $listTpl->setVar('globalsearch_resultslimit_results_txt', $app->lng('globalsearch_resultslimit_results_txt'));
225         $listTpl->setVar('globalsearch_noresults_text_txt', $app->lng('globalsearch_noresults_text_txt'));
226         $listTpl->setVar('globalsearch_noresults_limit_txt', $app->lng('globalsearch_noresults_limit_txt'));
227         $listTpl->setVar('globalsearch_searchfield_watermark_txt', $app->lng('globalsearch_searchfield_watermark_txt'));
228         
b1a6a5 229         return $listTpl->grab();
MC 230
231     }
232
f14188 233 }
T 234
b1a6a5 235 ?>