]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/QuickSearchDefaults.php
Release 6.5.0
[Github/sugarcrm.git] / include / QuickSearchDefaults.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  * QuickSearchDefaults class, outputs default values for setting up quicksearch
41  *
42  * @copyright  2004-2007 SugarCRM Inc.
43  * @license    http://www.sugarcrm.com/crm/products/sugar-professional-eula.html  SugarCRM Professional End User License
44  * @since      Class available since Release 4.0
45  */
46
47 class QuickSearchDefaults
48 {
49
50         var $form_name = 'EditView';
51
52     /**
53      * getQuickSearchDefaults
54      *
55      * This is a static function to get an instance of QuickSearchDefaults object
56      *
57      * @param array $lookup Array with custom files and class names for custom QuickSearchDefaults classes, optional
58      * @return QuickSearchDefaults
59      */
60     static public function getQuickSearchDefaults(array $lookup = array())
61     {
62        $lookup['custom/include/QuickSearchDefaults.php'] = 'QuickSearchDefaultsCustom';
63        foreach ($lookup as $file => $class)
64        {
65            if (file_exists($file))
66            {
67                require_once($file);
68                return new $class();
69            }
70        }
71        return new QuickSearchDefaults();
72     }
73
74         function setFormName($name = 'EditView') {
75                 $this->form_name = $name;
76         }
77
78     function getQSParent($parent = 'Accounts') {
79         global $app_strings;
80
81         $qsParent = array(
82                     'form' => $this->form_name,
83                     'method' => 'query',
84                     'modules' => array($parent),
85                     'group' => 'or',
86                     'field_list' => array('name', 'id'),
87                     'populate_list' => array('parent_name', 'parent_id'),
88                     'required_list' => array('parent_id'),
89                     'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')),
90                     'order' => 'name',
91                     'limit' => '30',
92                     'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
93                     );
94
95         return $qsParent;
96     }
97
98     function getQSAccount($nameKey, $idKey, $billingKey = null, $shippingKey = null, $additionalFields = null) {
99
100         global $app_strings;
101
102
103         $field_list = array('name', 'id');
104         $populate_list = array($nameKey, $idKey);
105         if($billingKey != null) {
106             $field_list = array_merge($field_list, array('billing_address_street', 'billing_address_city',
107                                                            'billing_address_state', 'billing_address_postalcode', 'billing_address_country'));
108
109             $populate_list = array_merge($populate_list, array($billingKey . "_address_street", $billingKey . "_address_city",
110                                                                 $billingKey . "_address_state", $billingKey . "_address_postalcode", $billingKey . "_address_country"));
111         } //if
112
113         if($shippingKey != null) {
114             $field_list = array_merge($field_list, array('shipping_address_street', 'shipping_address_city',
115                                                            'shipping_address_state', 'shipping_address_postalcode', 'shipping_address_country'));
116
117             $populate_list = array_merge($populate_list, array($shippingKey . "_address_street", $shippingKey . "_address_city",
118                                                                 $shippingKey . "_address_state", $shippingKey . "_address_postalcode", $shippingKey . "_address_country"));
119         }
120
121         if(!empty($additionalFields) && is_array($additionalFields)) {
122            $field_list = array_merge($field_list, array_keys($additionalFields));
123            $populate_list = array_merge($populate_list, array_values($additionalFields));
124         }
125
126         $qsParent = array(
127                                         'form' => $this->form_name,
128                     'method' => 'query',
129                     'modules' => array('Accounts'),
130                     'group' => 'or',
131                     'field_list' => $field_list,
132                     'populate_list' => $populate_list,
133                     'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')),
134                     'required_list' => array($idKey),
135                     'order' => 'name',
136                     'limit' => '30',
137                     'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
138                     );
139
140         return $qsParent;
141     }
142
143     /**
144      * getQSContact
145      * This is a customized method to handle returning in JSON notation the QuickSearch formats
146      * for searching the Contacts module for a contact name.  The method takes into account
147      * the locale settings (s = salutation, f = first name, l = last name) that are permissible.
148      * It should be noted though that any other characters present in the formatting will render
149      * this widget non-functional.
150      * @return The JSON format of a QuickSearch definition for the Contacts module
151      */
152     function getQSContact($name, $idName) {
153         global $app_strings, $locale;
154
155         $qsContact = array('form' => $this->form_name,
156                                            'method'=>'get_contact_array',
157                            'modules'=>array('Contacts'),
158                            'field_list' => array('salutation', 'first_name', 'last_name', 'id'),
159                            'populate_list' => array($name, $idName, $idName, $idName),
160                            'required_list' => array($idName),
161                            'group' => 'or',
162                            'conditions' => array(
163                                                  array('name'=>'first_name', 'op'=>'like_custom','end'=>'%','value'=>''),
164                                                  array('name'=>'last_name', 'op'=>'like_custom','end'=>'%','value'=>'')
165                                            ),
166                            'order'=>'last_name',
167                            'limit'=>'30',
168                            'no_match_text'=> $app_strings['ERR_SQS_NO_MATCH']);
169         return $qsContact;
170     }
171
172     function getQSUser($p_name = 'assigned_user_name', $p_id ='assigned_user_id') {
173         global $app_strings;
174
175         $qsUser = array('form' => $this->form_name,
176                                         'method' => 'get_user_array', // special method
177                         'field_list' => array('user_name', 'id'),
178                         'populate_list' => array($p_name, $p_id),
179                         'required_list' => array($p_id),
180                         'conditions' => array(array('name'=>'user_name','op'=>'like_custom','end'=>'%','value'=>'')),
181                         'limit' => '30','no_match_text' => $app_strings['ERR_SQS_NO_MATCH']);
182         return $qsUser;
183     }
184     function getQSCampaigns($c_name = 'campaign_name', $c_id = 'campaign_id') {
185         global $app_strings;
186
187         $qsCampaign = array('form' => $this->form_name,
188                                                 'method' => 'query',
189                             'modules'=> array('Campaigns'),
190                             'group' => 'or',
191                             'field_list' => array('name', 'id'),
192                             'populate_list' => array($c_name, $c_id),
193                             'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')),
194                             'required_list' => array('campaign_id'),
195                             'order' => 'name',
196                             'limit' => '30',
197                             'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']);
198         return $qsCampaign;
199     }
200
201
202     /**
203      * Loads Quick Search Object for any object (if suitable method is defined)
204      *
205      * @param string $module the given module we want to load the vardefs for
206      * @param string $object the given object we wish to load the vardefs for
207      * @param string $relationName the name of the relation between entities
208      * @param type $nameField the name of the field to populate
209      * @param type $idField the id of the field to populate
210      */
211     function loadQSObject($module, $object, $relationName, $nameField, $idField)
212     {
213         $result = array();
214         VardefManager::loadVardef($module, $object);
215         if (isset($GLOBALS['dictionary'][$object]['relationships']) && array_key_exists($relationName, $GLOBALS['dictionary'][$object]['relationships']))
216         {
217             if (method_exists($this, 'getQS' . $module))
218             {
219                 $result = $this->{'getQS' . $module};
220             } elseif (method_exists($this, 'getQS' . $object))
221             {
222                 $result = $this->{'getQS' . $object};
223             }
224         } else
225         {
226             if (method_exists($this, 'getQS' . $module))
227             {
228                 $result = $this->{'getQS' . $module}($nameField, $idField);
229             } elseif (method_exists($this, 'getQS' . $object))
230             {
231                 $result = $this->{'getQS' . $object}($nameField, $idField);
232             }
233         }
234         return $result;
235     }
236
237     // BEGIN QuickSearch functions for 4.5.x backwards compatibility support
238     function getQSScripts() {
239                 global $sugar_version, $sugar_config, $theme;
240                 $qsScripts = '<script type="text/javascript">sqsWaitGif = "' . SugarThemeRegistry::current()->getImageURL('sqsWait.gif') . '";</script>
241                 <script type="text/javascript" src="'. getJSPath('include/javascript/quicksearch.js') . '"></script>';
242                 return $qsScripts;
243         }
244
245         function getQSScriptsNoServer() {
246                 return $this->getQSScripts();
247         }
248
249         function getQSScriptsJSONAlreadyDefined() {
250                 global $sugar_version, $sugar_config, $theme;
251                 $qsScriptsJSONAlreadyDefined = '<script type="text/javascript">sqsWaitGif = "' . SugarThemeRegistry::current()->getImageURL('sqsWait.gif') . '";</script><script type="text/javascript" src="' . getJSPath('include/javascript/quicksearch.js') . '"></script>';
252                 return $qsScriptsJSONAlreadyDefined;
253         }
254     // END QuickSearch functions for 4.5.x backwards compatibility support
255 }
256
257 ?>