2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
37 require_once('include/MVC/View/SugarView.php');
39 require_once('include/ListView/ListViewSmarty.php');
41 require_once('modules/MySettings/StoreQuery.php');
42 class ViewList extends SugarView{
65 function listViewPrepare(){
66 $module = $GLOBALS['module'];
68 $metadataFile = $this->getMetaDataFile();
70 if( !file_exists($metadataFile) )
71 sugar_die($GLOBALS['app_strings']['LBL_NO_ACTION'] );
73 require_once($metadataFile);
74 $this->listViewDefs = $listViewDefs;
76 if(!empty($this->bean->object_name) && isset($_REQUEST[$module.'2_'.strtoupper($this->bean->object_name).'_offset'])) {//if you click the pagination button, it will poplate the search criteria here
77 if(!empty($_REQUEST['current_query_by_page'])) {//The code support multi browser tabs pagination
78 $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'request_data', 'current_query_by_page',$module.'2_'.strtoupper($this->bean->object_name).'_ORDER_BY' );
79 if(isset($_REQUEST['lvso'])){
80 $blockVariables[] = 'lvso';
82 $current_query_by_page = unserialize(base64_decode($_REQUEST['current_query_by_page']));
83 foreach($current_query_by_page as $search_key=>$search_value) {
84 if($search_key != $module.'2_'.strtoupper($this->bean->object_name).'_offset' && !in_array($search_key, $blockVariables)) {
85 if (!is_array($search_value)) {
86 $_REQUEST[$search_key] = $GLOBALS['db']->quoteForEmail($search_value);
89 foreach ($search_value as $key=>&$val) {
90 $val = $GLOBALS['db']->quoteForEmail($val);
92 $_REQUEST[$search_key] = $search_value;
98 if(!empty($_REQUEST['saved_search_select'])) {
99 if ($_REQUEST['saved_search_select']=='_none' || !empty($_REQUEST['button'])) {
100 $_SESSION['LastSavedView'][$_REQUEST['module']] = '';
101 unset($_REQUEST['saved_search_select']);
102 unset($_REQUEST['saved_search_select_name']);
104 //use the current search module, or the current module to clear out layout changes
105 if(!empty($_REQUEST['search_module']) || !empty($_REQUEST['module'])){
106 $mod = !empty($_REQUEST['search_module']) ? $_REQUEST['search_module'] : $_REQUEST['module'];
107 global $current_user;
108 //Reset the current display columns to default.
109 $current_user->setPreference('ListViewDisplayColumns', array(), 0, $mod);
112 else if(empty($_REQUEST['button']) && (empty($_REQUEST['clear_query']) || $_REQUEST['clear_query']!='true')) {
113 $this->saved_search = loadBean('SavedSearch');
114 $this->saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']);
115 $this->saved_search->populateRequest();
117 elseif(!empty($_REQUEST['button'])) { // click the search button, after retrieving from saved_search
118 $_SESSION['LastSavedView'][$_REQUEST['module']] = '';
119 unset($_REQUEST['saved_search_select']);
120 unset($_REQUEST['saved_search_select_name']);
123 $this->storeQuery = new StoreQuery();
124 if(!isset($_REQUEST['query'])){
125 $this->storeQuery->loadQuery($this->module);
126 $this->storeQuery->populateRequest();
128 $this->storeQuery->saveFromRequest($this->module);
131 $this->seed = $this->bean;
133 $displayColumns = array();
134 if(!empty($_REQUEST['displayColumns'])) {
135 foreach(explode('|', $_REQUEST['displayColumns']) as $num => $col) {
136 if(!empty($this->listViewDefs[$module][$col]))
137 $displayColumns[$col] = $this->listViewDefs[$module][$col];
141 foreach($this->listViewDefs[$module] as $col => $this->params) {
142 if(!empty($this->params['default']) && $this->params['default'])
143 $displayColumns[$col] = $this->params;
146 $this->params = array('massupdate' => true);
147 if(!empty($_REQUEST['orderBy'])) {
148 $this->params['orderBy'] = $_REQUEST['orderBy'];
149 $this->params['overrideOrder'] = true;
150 if(!empty($_REQUEST['sortOrder'])) $this->params['sortOrder'] = $_REQUEST['sortOrder'];
152 $this->lv->displayColumns = $displayColumns;
154 $this->module = $module;
156 $this->prepareSearchForm();
158 if(isset($this->options['show_title']) && $this->options['show_title']) {
159 $moduleName = isset($this->seed->module_dir) ? $this->seed->module_dir : $GLOBALS['mod_strings']['LBL_MODULE_NAME'];
160 echo $this->getModuleTitle(true);
164 function listViewProcess(){
165 $this->processSearchForm();
166 $this->lv->searchColumns = $this->searchForm->searchColumns;
170 if(empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false){
171 $this->lv->ss->assign("SEARCH",true);
172 $this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
173 $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
174 echo $this->lv->display();
177 function prepareSearchForm(){
178 $this->searchForm = null;
181 $view = 'basic_search';
182 if(!empty($_REQUEST['search_form_view']) && $_REQUEST['search_form_view'] == 'advanced_search')
183 $view = $_REQUEST['search_form_view'];
184 $this->headers = true;
185 if(!empty($_REQUEST['search_form_only']) && $_REQUEST['search_form_only'])
186 $this->headers = false;
187 elseif(!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
188 if(isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') {
189 $view = 'advanced_search';
191 $view = 'basic_search';
195 $this->use_old_search = true;
196 if ((file_exists('modules/' . $this->module . '/SearchForm.html')
197 && !file_exists('modules/' . $this->module . '/metadata/searchdefs.php'))
198 || (file_exists('custom/modules/' . $this->module . '/SearchForm.html')
199 && !file_exists('custom/modules/' . $this->module . '/metadata/searchdefs.php'))){
200 require_once('include/SearchForm/SearchForm.php');
201 $this->searchForm = new SearchForm($this->module, $this->seed);
203 $this->use_old_search = false;
204 require_once('include/SearchForm/SearchForm2.php');
206 if(file_exists('custom/modules/'.$this->module.'/metadata/metafiles.php')){
207 require('custom/modules/'.$this->module.'/metadata/metafiles.php');
208 }elseif(file_exists('modules/'.$this->module.'/metadata/metafiles.php')){
209 require('modules/'.$this->module.'/metadata/metafiles.php');
212 /* if(!empty($metafiles[$this->module]['searchdefs']))
213 require_once($metafiles[$this->module]['searchdefs']);
214 elseif(file_exists('modules/'.$this->module.'/metadata/searchdefs.php'))
215 require_once('modules/'.$this->module.'/metadata/searchdefs.php');
218 if (file_exists('custom/modules/'.$this->module.'/metadata/searchdefs.php'))
220 require_once('custom/modules/'.$this->module.'/metadata/searchdefs.php');
222 elseif (!empty($metafiles[$this->module]['searchdefs']))
224 require_once($metafiles[$this->module]['searchdefs']);
226 elseif (file_exists('modules/'.$this->module.'/metadata/searchdefs.php'))
228 require_once('modules/'.$this->module.'/metadata/searchdefs.php');
232 if(!empty($metafiles[$this->module]['searchfields']))
233 require_once($metafiles[$this->module]['searchfields']);
234 elseif(file_exists('modules/'.$this->module.'/metadata/SearchFields.php'))
235 require_once('modules/'.$this->module.'/metadata/SearchFields.php');
237 if(file_exists('custom/modules/'.$this->module.'/metadata/SearchFields.php')){
238 require_once('custom/modules/'.$this->module.'/metadata/SearchFields.php');
242 $this->searchForm = new SearchForm($this->seed, $this->module, $this->action);
243 $this->searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl', $view, $this->listViewDefs);
244 $this->searchForm->lv = $this->lv;
247 function processSearchForm(){
248 if(isset($_REQUEST['query']))
251 if(!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) { // from EditView cancel
252 $this->searchForm->populateFromArray($this->storeQuery->query);
255 $this->searchForm->populateFromRequest();
258 $where_clauses = $this->searchForm->generateSearchWhere(true, $this->seed->module_dir);
260 if (count($where_clauses) > 0 )$this->where = '('. implode(' ) AND ( ', $where_clauses) . ')';
261 $GLOBALS['log']->info("List View Where Clause: $this->where");
263 if($this->use_old_search){
266 $this->searchForm->setup();
267 $this->searchForm->displayBasic($this->headers);
269 case 'advanced_search':
270 $this->searchForm->setup();
271 $this->searchForm->displayAdvanced($this->headers);
274 echo $this->searchForm->displaySavedViews($this->listViewDefs, $this->lv, $this->headers);
278 echo $this->searchForm->display($this->headers);
281 function preDisplay(){
282 $this->lv = new ListViewSmarty();
285 if(!$this->bean || !$this->bean->ACLAccess('list')){
286 ACLController::displayNoAccess();
288 $this->listViewPrepare();
289 $this->listViewProcess();