2 /*********************************************************************************
3 * SugarCRM 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;
99 if(!empty($_REQUEST['saved_search_select'])) {
100 if ($_REQUEST['saved_search_select']=='_none' || !empty($_REQUEST['button'])) {
101 $_SESSION['LastSavedView'][$_REQUEST['module']] = '';
102 unset($_REQUEST['saved_search_select']);
103 unset($_REQUEST['saved_search_select_name']);
104 global $current_user;
105 //Reset the current display columns to default.
106 $current_user->setPreference('ListViewDisplayColumns', array(), 0, $_REQUEST['search_module']);
108 else if(empty($_REQUEST['button']) && (empty($_REQUEST['clear_query']) || $_REQUEST['clear_query']!='true')) {
109 $this->saved_search = loadBean('SavedSearch');
110 $this->saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']);
111 $this->saved_search->populateRequest();
114 $this->storeQuery = new StoreQuery();
115 if(!isset($_REQUEST['query'])){
116 $this->storeQuery->loadQuery($this->module);
117 $this->storeQuery->populateRequest();
119 $this->storeQuery->saveFromRequest($this->module);
122 $this->seed = $this->bean;
124 $displayColumns = array();
125 if(!empty($_REQUEST['displayColumns'])) {
126 foreach(explode('|', $_REQUEST['displayColumns']) as $num => $col) {
127 if(!empty($this->listViewDefs[$module][$col]))
128 $displayColumns[$col] = $this->listViewDefs[$module][$col];
132 foreach($this->listViewDefs[$module] as $col => $this->params) {
133 if(!empty($this->params['default']) && $this->params['default'])
134 $displayColumns[$col] = $this->params;
137 $this->params = array('massupdate' => true);
138 if(!empty($_REQUEST['orderBy'])) {
139 $this->params['orderBy'] = $_REQUEST['orderBy'];
140 $this->params['overrideOrder'] = true;
141 if(!empty($_REQUEST['sortOrder'])) $this->params['sortOrder'] = $_REQUEST['sortOrder'];
143 $this->lv->displayColumns = $displayColumns;
145 $this->seed = $this->seed;
146 $this->module = $module;
148 $this->prepareSearchForm();
150 if(isset($this->options['show_title']) && $this->options['show_title']) {
151 $moduleName = isset($this->seed->module_dir) ? $this->seed->module_dir : $GLOBALS['mod_strings']['LBL_MODULE_NAME'];
152 echo $this->getModuleTitle(true);
156 function listViewProcess(){
157 $this->processSearchForm();
158 $this->lv->searchColumns = $this->searchForm->searchColumns;
162 if(empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false){
163 $this->lv->ss->assign("SEARCH",true);
164 $this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
165 $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
166 echo $this->lv->display();
169 function prepareSearchForm(){
170 $this->searchForm = null;
173 $view = 'basic_search';
174 if(!empty($_REQUEST['search_form_view']) && $_REQUEST['search_form_view'] == 'advanced_search')
175 $view = $_REQUEST['search_form_view'];
176 $this->headers = true;
177 if(!empty($_REQUEST['search_form_only']) && $_REQUEST['search_form_only'])
178 $this->headers = false;
179 elseif(!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
180 if(isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') {
181 $view = 'advanced_search';
183 $view = 'basic_search';
187 $this->use_old_search = true;
188 if ((file_exists('modules/' . $this->module . '/SearchForm.html')
189 && !file_exists('modules/' . $this->module . '/metadata/searchdefs.php'))
190 || (file_exists('custom/modules/' . $this->module . '/SearchForm.html')
191 && !file_exists('custom/modules/' . $this->module . '/metadata/searchdefs.php'))){
192 require_once('include/SearchForm/SearchForm.php');
193 $this->searchForm = new SearchForm($this->module, $this->seed);
195 $this->use_old_search = false;
196 require_once('include/SearchForm/SearchForm2.php');
198 if(file_exists('custom/modules/'.$this->module.'/metadata/metafiles.php')){
199 require('custom/modules/'.$this->module.'/metadata/metafiles.php');
200 }elseif(file_exists('modules/'.$this->module.'/metadata/metafiles.php')){
201 require('modules/'.$this->module.'/metadata/metafiles.php');
204 /* if(!empty($metafiles[$this->module]['searchdefs']))
205 require_once($metafiles[$this->module]['searchdefs']);
206 elseif(file_exists('modules/'.$this->module.'/metadata/searchdefs.php'))
207 require_once('modules/'.$this->module.'/metadata/searchdefs.php');
210 if (file_exists('custom/modules/'.$this->module.'/metadata/searchdefs.php'))
212 require_once('custom/modules/'.$this->module.'/metadata/searchdefs.php');
214 elseif (!empty($metafiles[$this->module]['searchdefs']))
216 require_once($metafiles[$this->module]['searchdefs']);
218 elseif (file_exists('modules/'.$this->module.'/metadata/searchdefs.php'))
220 require_once('modules/'.$this->module.'/metadata/searchdefs.php');
224 if(!empty($metafiles[$this->module]['searchfields']))
225 require_once($metafiles[$this->module]['searchfields']);
226 elseif(file_exists('modules/'.$this->module.'/metadata/SearchFields.php'))
227 require_once('modules/'.$this->module.'/metadata/SearchFields.php');
229 if(file_exists('custom/modules/'.$this->module.'/metadata/SearchFields.php')){
230 require_once('custom/modules/'.$this->module.'/metadata/SearchFields.php');
234 $this->searchForm = new SearchForm($this->seed, $this->module, $this->action);
235 $this->searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl', $view, $this->listViewDefs);
236 $this->searchForm->lv = $this->lv;
239 function processSearchForm(){
240 if(isset($_REQUEST['query']))
243 if(!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) { // from EditView cancel
244 $this->searchForm->populateFromArray($this->storeQuery->query);
247 $this->searchForm->populateFromRequest();
250 $where_clauses = $this->searchForm->generateSearchWhere(true, $this->seed->module_dir);
252 if (count($where_clauses) > 0 )$this->where = '('. implode(' ) AND ( ', $where_clauses) . ')';
253 $GLOBALS['log']->info("List View Where Clause: $this->where");
255 if($this->use_old_search){
258 $this->searchForm->setup();
259 $this->searchForm->displayBasic($this->headers);
261 case 'advanced_search':
262 $this->searchForm->setup();
263 $this->searchForm->displayAdvanced($this->headers);
266 echo $this->searchForm->displaySavedViews($this->listViewDefs, $this->lv, $this->headers);
270 echo $this->searchForm->display($this->headers);
273 function preDisplay(){
274 $this->lv = new ListViewSmarty();
277 if(!$this->bean || !$this->bean->ACLAccess('list')){
278 ACLController::displayNoAccess();
280 $this->listViewPrepare();
281 $this->listViewProcess();