]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/MySettings/StoreQuery.php
Release 6.1.5
[Github/sugarcrm.git] / modules / MySettings / StoreQuery.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 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
41 class StoreQuery{
42         var $query = array();
43         
44         function addToQuery($name, $val){
45                 $this->query[$name] = $val;     
46         }
47         
48         function SaveQuery($name){
49                 global $current_user;
50                 $current_user->setPreference($name.'Q', $this->query);
51         }
52         
53         function clearQuery($name){
54                 $this->query = array();
55                 $this->saveQuery($name);        
56         }
57         
58         function loadQuery($name){
59                 $saveType = $this->getSaveType($name);
60                 if($saveType == 'all' || $saveType == 'myitems'){
61                         global $current_user;
62                         $this->query = StoreQuery::getStoredQueryForUser($name);
63                         if(empty($this->query)){
64                                 $this->query = array(); 
65                         }
66                         if(!empty($this->populate_only) && !empty($this->query['query'])){
67                                 $this->query['query'] = 'MSI';
68                         }
69                 }
70         }
71         
72         
73         function populateRequest(){
74                 foreach($this->query as $key=>$val){
75             //We don't want to step on the search type, module, or offset if they are in the current request
76             if($key != 'advanced' && $key != 'module' && (substr($key, -7) != "_offset" || !isset($_REQUEST[$key]))) {
77                         $_REQUEST[$key] = $val;
78                 $_GET[$key]     = $val;
79             }
80                 }       
81         }
82         
83         function getSaveType($name)
84         {
85                 global $sugar_config;
86                 $save_query = empty($sugar_config['save_query']) ?
87                         'all' : $sugar_config['save_query'];
88
89                 if(is_array($save_query))
90                 {
91                         if(isset($save_query[$name]))
92                         {
93                                 $saveType = $save_query[$name];
94                         }
95                         elseif(isset($save_query['default']))
96                         {
97                                 $saveType = $save_query['default'];
98                         }
99                         else
100                         {
101                                 $saveType = 'all';
102                         }       
103                 }
104                 else
105                 {
106                         $saveType = $save_query;
107                 }       
108                 if($saveType == 'populate_only'){
109                         $saveType = 'all';
110                         $this->populate_only = true;
111                 }
112                 return $saveType;
113         }
114
115         
116         function saveFromRequest($name){
117                 if(isset($_REQUEST['query'])){
118                         if(!empty($_REQUEST['clear_query']) && $_REQUEST['clear_query'] == 'true'){
119                                 $this->clearQuery($name);
120                                 return; 
121                         }
122                         $saveType = $this->getSaveType($name);
123                         
124                         if($saveType == 'myitems'){
125                                 if(!empty($_REQUEST['current_user_only'])){
126                                         $this->query['current_user_only'] = $_REQUEST['current_user_only'];
127                                         $this->query['query'] = true;
128                                 }
129                                 $this->saveQuery($name);
130                                 
131                         }else if($saveType == 'all'){
132                 // Bug 39580 - Added 'EmailTreeLayout','EmailGridWidths' to the list as these are added merely as side-effects of the fact that we store the entire
133                 // $_REQUEST object which includes all cookies.  These are potentially quite long strings as well.
134                                 $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'current_query_by_page','EmailTreeLayout','EmailGridWidths');
135                                 $this->query = $_REQUEST;
136                 foreach($blockVariables as $block) {
137                     unset($this->query[$block]);
138                 }
139                                 $this->saveQuery($name);        
140                         }
141                 }
142         }
143         
144         function saveFromGet($name){
145                 if(isset($_GET['query'])){
146                         if(!empty($_GET['clear_query']) && $_GET['clear_query'] == 'true'){
147                                 $this->clearQuery($name);
148                                 return; 
149                         }
150                         $saveType = $this->getSaveType($name);
151                         
152                         if($saveType == 'myitems'){
153                                 if(!empty($_GET['current_user_only'])){
154                                         $this->query['current_user_only'] = $_GET['current_user_only'];
155                                         $this->query['query'] = true;
156                                 }
157                                 $this->saveQuery($name);
158                                 
159                         }else if($saveType == 'all'){
160                                 $this->query = $_GET;
161                                 $this->saveQuery($name);        
162                         }
163                 }
164         }
165         
166         /**
167          * Static method to retrieve the user's stored query for a particular module
168          *
169          * @param string $module
170          * @return array
171          */
172         public static function getStoredQueryForUser($module){
173                 global $current_user;
174                 return $current_user->getPreference($module.'Q');
175         }
176 }
177
178 ?>