]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/ListView/ListViewFacade.php
Release 6.5.0
[Github/sugarcrm.git] / include / ListView / ListViewFacade.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 /*
40  * Created on Sep 10, 2007
41  *
42  * To change the template for this generated file go to
43  * Window - Preferences - PHPeclipse - PHP - Code Templates
44  */
45  require_once('include/ListView/ListViewSmarty.php');
46  
47
48  /**
49   * A Facade to ListView and ListViewSmarty
50   */
51  class ListViewFacade{
52
53         var $focus = null;
54         var $module = '';
55         var $type = 0;
56
57         var $lv;
58
59         //ListView fields
60         var $template;
61         var $title;
62         var $where = '';
63         var $params = array();
64         var $offset = 0;
65         var $limit = -1;
66         var $filter_fields = array();
67         var $id_field = 'id';
68         var $prefix = '';
69         var $mod_strings = array();
70
71         /**
72          * Constructor
73          * @param $focus - the bean
74          * @param $module - the module name
75          * @param - 0 = decide for me, 1 = ListView.html, 2 = ListViewSmarty
76          */
77         function ListViewFacade($focus, $module, $type = 0){
78                 $this->focus = $focus;
79                 $this->module = $module;
80                 $this->type = $type;
81                 $this->build();
82         }
83
84         function build(){
85                 //we will assume that if the ListView.html file exists we will want to use that one
86                 if(file_exists('modules/'.$this->module.'/ListView.html')){
87                         $this->type = 1;
88                         $this->lv = new ListView();
89                         $this->template = 'modules/'.$this->module.'/ListView.html';
90                 }else{
91                         $metadataFile = null;
92                 $foundViewDefs = false;
93                 if(file_exists('custom/modules/' . $this->module. '/metadata/listviewdefs.php')){
94                 $metadataFile = 'custom/modules/' .  $this->module . '/metadata/listviewdefs.php';
95                 $foundViewDefs = true;
96                 }else{
97                 if(file_exists('custom/modules/'. $this->module.'/metadata/metafiles.php')){
98                         require_once('custom/modules/'. $this->module.'/metadata/metafiles.php');
99                         if(!empty($metafiles[ $this->module]['listviewdefs'])){
100                         $metadataFile = $metafiles[ $this->module]['listviewdefs'];
101                         $foundViewDefs = true;
102                         }
103                 }elseif(file_exists('modules/'. $this->module.'/metadata/metafiles.php')){
104                         require_once('modules/'. $this->module.'/metadata/metafiles.php');
105                         if(!empty($metafiles[ $this->module]['listviewdefs'])){
106                         $metadataFile = $metafiles[ $this->module]['listviewdefs'];
107                         $foundViewDefs = true;
108                         }
109                 }
110                 }
111                 if(!$foundViewDefs && file_exists('modules/'. $this->module.'/metadata/listviewdefs.php')){
112                         $metadataFile = 'modules/'. $this->module.'/metadata/listviewdefs.php';
113                 }
114                 require_once($metadataFile);
115
116
117                         $this->lv = new ListViewSmarty();
118                         $displayColumns = array();
119                         if(!empty($_REQUEST['displayColumns'])) {
120                             foreach(explode('|', $_REQUEST['displayColumns']) as $num => $col) {
121                                 if(!empty($listViewDefs[$this->module][$col]))
122                                     $displayColumns[$col] = $listViewDefs[$this->module][$col];
123                             }
124                         }
125                         else {
126                             foreach($listViewDefs[$this->module] as $col => $params) {
127                                 if(!empty($params['default']) && $params['default'])
128                                     $displayColumns[$col] = $params;
129                             }
130                         }
131                         $this->lv->displayColumns = $displayColumns;
132                         $this->type = 2;
133                         $this->template = 'include/ListView/ListViewGeneric.tpl';
134                 }
135         }
136
137         function setup($template = '', $where = '', $params = array(), $mod_strings = array(), $offset = 0, $limit = -1, $orderBy = '', $prefix = '', $filter_fields = array(), $id_field = 'id'){
138                 if(!empty($template))
139                         $this->template = $template;
140
141                 $this->mod_strings = $mod_strings;
142
143                 if($this->type == 1){
144                         $this->lv->initNewXTemplate($this->template,$this->mod_strings);
145                         $this->prefix = $prefix;
146                         $this->lv->setQuery($where, $limit, $orderBy, $prefix);
147                         $this->lv->show_select_menu = false;
148                         $this->lv->show_export_button = false;
149                         $this->lv->show_delete_button = false;
150                         $this->lv->show_mass_update = false;
151                         $this->lv->show_mass_update_form = false;
152                 }else{
153                         $this->lv->export = false;
154                         $this->lv->delete = false;
155                         $this->lv->select = false;
156                         $this->lv->mailMerge = false;
157                         $this->lv->multiSelect = false;
158                         $this->lv->setup($this->focus, $this->template, $where, $params, $offset, $limit,  $filter_fields, $id_field);
159                         
160                 }
161         }
162
163         function display($title = '', $section = 'main', $return = FALSE){
164                 if($this->type == 1){
165             ob_start();
166                         $this->lv->setHeaderTitle($title);
167                         $this->lv->processListView($this->focus, $section, $this->prefix);
168             $output = ob_get_contents();
169             ob_end_clean();
170                 }else{
171              $output = get_form_header($title, '', false) . $this->lv->display();
172                 }
173         if($return)
174             return $output;
175         else
176             echo $output;
177         }
178
179         function setTitle($title = ''){
180                 $this->title = $title;
181         }
182  }
183 ?>