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.
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.
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
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
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.
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.
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 ********************************************************************************/
44 function addToQuery($name, $val){
45 $this->query[$name] = $val;
48 function SaveQuery($name){
50 $current_user->setPreference($name.'Q', $this->query);
53 function clearQuery($name){
54 $this->query = array();
55 $this->saveQuery($name);
58 function loadQuery($name){
59 $saveType = $this->getSaveType($name);
60 if($saveType == 'all' || $saveType == 'myitems'){
62 $this->query = StoreQuery::getStoredQueryForUser($name);
63 if(empty($this->query)){
64 $this->query = array();
66 if(!empty($this->populate_only) && !empty($this->query['query'])){
67 $this->query['query'] = 'MSI';
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;
83 function getSaveType($name)
86 $save_query = empty($sugar_config['save_query']) ?
87 'all' : $sugar_config['save_query'];
89 if(is_array($save_query))
91 if(isset($save_query[$name]))
93 $saveType = $save_query[$name];
95 elseif(isset($save_query['default']))
97 $saveType = $save_query['default'];
106 $saveType = $save_query;
108 if($saveType == 'populate_only'){
110 $this->populate_only = true;
116 function saveFromRequest($name){
117 if(isset($_REQUEST['query'])){
118 if(!empty($_REQUEST['clear_query']) && $_REQUEST['clear_query'] == 'true'){
119 $this->clearQuery($name);
122 $saveType = $this->getSaveType($name);
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;
129 $this->saveQuery($name);
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]);
139 $this->saveQuery($name);
144 function saveFromGet($name){
145 if(isset($_GET['query'])){
146 if(!empty($_GET['clear_query']) && $_GET['clear_query'] == 'true'){
147 $this->clearQuery($name);
150 $saveType = $this->getSaveType($name);
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;
157 $this->saveQuery($name);
159 }else if($saveType == 'all'){
160 $this->query = $_GET;
161 $this->saveQuery($name);
167 * Static method to retrieve the user's stored query for a particular module
169 * @param string $module
172 public static function getStoredQueryForUser($module){
173 global $current_user;
174 return $current_user->getPreference($module.'Q');