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