]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Home/UnifiedSearchAdvanced.php
Release 6.2.4
[Github/sugarcrm.git] / modules / Home / UnifiedSearchAdvanced.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-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  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46
47
48 class UnifiedSearchAdvanced {
49     
50     var $query_string = '';
51     
52     function __construct(){
53         if(!empty($_REQUEST['query_string'])){
54             $query_string = trim($_REQUEST['query_string']);
55             if(!empty($query_string)){
56                 $this->query_string = $query_string;
57             }
58         }
59     }
60     
61         function getDropDownDiv($tpl = 'modules/Home/UnifiedSearchAdvanced.tpl') {
62                 global $app_list_strings, $app_strings;
63
64                 if(!file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php'))
65                 {
66                         $this->buildCache();
67                 }
68                 
69                 include($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php');
70
71                 if(!file_exists('custom/modules/unified_search_modules_display.php'))
72                 {
73                    $this->createUnifiedSearchModulesDisplay();
74                 }
75                 
76                 include('custom/modules/unified_search_modules_display.php');           
77                 
78                 global $mod_strings, $modListHeader, $app_list_strings, $current_user, $app_strings, $beanList;
79                 $users_modules = $current_user->getPreference('globalSearch', 'search');
80
81                 // preferences are empty, select all
82                 if(empty($users_modules)) {                     
83                         $users_modules = array();
84                         foreach($unified_search_modules_display as $module=>$data) {
85                                 if (!empty($data['visible']) ) {
86                     $users_modules[$module] = $beanList[$module];
87                 }
88                         }
89                         $current_user->setPreference('globalSearch', $users_modules, 0, 'search');
90                 }
91                 
92                 $sugar_smarty = new Sugar_Smarty();
93
94                 $modules_to_search = array();
95
96                 foreach($users_modules as $key=>$module) 
97                 {
98             if(ACLController::checkAccess($key, 'list', true)) 
99             {
100                 $modules_to_search[$key]['checked'] = true;
101             }
102                 }
103                 
104                 if(!empty($this->query_string))
105                 {
106                         $sugar_smarty->assign('query_string', securexss($this->query_string));
107                 } else {
108                         $sugar_smarty->assign('query_string', '');
109                 }
110                 
111                 $sugar_smarty->assign('MOD', return_module_language($GLOBALS['current_language'], 'Administration'));
112                 $sugar_smarty->assign('APP', $app_strings);
113                 $sugar_smarty->assign('USE_SEARCH_GIF', 0);
114                 $sugar_smarty->assign('LBL_SEARCH_BUTTON_LABEL', $app_strings['LBL_SEARCH_BUTTON_LABEL']);
115                 
116                 $json_enabled = array();
117                 $json_disabled = array();
118                 
119                 //Now add the rest of the modules that are searchable via Global Search settings
120                 foreach($unified_search_modules_display as $module=>$data)
121                 {
122                         if(!isset($modules_to_search[$module]) && $data['visible'] && ACLController::checkAccess($module, 'list', true))
123                         {
124                            $modules_to_search[$module]['checked'] = false;     
125                         } else if (isset($modules_to_search[$module]) && !$data['visible']) {
126                            unset($modules_to_search[$module]);
127                         }
128                 }               
129
130                 //Create the two lists (doing it this way preserves the user's ordering choice for enabled modules)
131                 foreach($modules_to_search as $module=>$data)
132                 {
133                         $label = isset($app_list_strings['moduleList'][$module]) ? $app_list_strings['moduleList'][$module] : $module;
134                         if(!empty($data['checked']))
135                         {
136                                 $json_enabled[] = array("module" => $module, 'label' => $label);
137                         } else {
138                                 $json_disabled[] = array("module" => $module, 'label' => $label);
139                         }       
140                 }
141                 
142                 $sugar_smarty->assign('enabled_modules', json_encode($json_enabled));
143                 $sugar_smarty->assign('disabled_modules', json_encode($json_disabled));                 
144                 
145                 $showDiv = $current_user->getPreference('showGSDiv', 'search');
146                 if(!isset($showDiv))
147                 {
148                    $showDiv = 'no';
149                 }           
150
151                 $sugar_smarty->assign('SHOWGSDIV', $showDiv);
152                 $sugar_smarty->debugging = true;
153                 return $sugar_smarty->fetch($tpl);
154         }
155
156         
157         function search() {
158                 if(!file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php'))
159                 {
160                         $this->buildCache();
161                 }
162                 include $GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php';
163                 
164                 if(!file_exists('custom/modules/unified_search_modules_display.php'))
165                 {
166                    $this->createUnifiedSearchModulesDisplay();
167                 }
168                 include('custom/modules/unified_search_modules_display.php');           
169                 
170                 
171                 require_once 'include/ListView/ListViewSmarty.php';
172                 
173                 global $modListHeader, $beanList, $beanFiles, $current_language, $app_strings, $current_user, $mod_strings;
174                 $home_mod_strings = return_module_language($current_language, 'Home');
175
176                 $overlib = true;
177                 $this->query_string = $GLOBALS['db']->quote(securexss(from_html(clean_string($this->query_string, 'UNIFIED_SEARCH'))));
178
179                 if(!empty($_REQUEST['advanced']) && $_REQUEST['advanced'] != 'false') {
180                         $modules_to_search = array();
181                         if(!empty($_REQUEST['search_modules']))
182                         {
183                             foreach(explode (',', $_REQUEST['search_modules'] ) as $e)
184                     {
185                         $modules_to_search[$e] = $beanList[$e];
186                     }
187                         }
188
189                         $current_user->setPreference('showGSDiv', isset($_REQUEST['showGSDiv']) ? $_REQUEST['showGSDiv'] : 'no', 0, 'search');
190                         $current_user->setPreference('globalSearch', $modules_to_search, 0, 'search'); // save selections to user preference
191                 } else {
192                         $users_modules = $current_user->getPreference('globalSearch', 'search');
193                         $modules_to_search = array();
194                                                 
195                         if(!empty($users_modules)) { 
196                                 // use user's previous selections
197                             foreach ( $users_modules as $key => $value ) {
198                                 if (isset($unified_search_modules_display[$key]) && !empty($unified_search_modules_display[$key]['visible'])) {
199                                 $modules_to_search[$key] = $beanList[$key];
200                                 }
201                             }
202                         } else {
203                                 foreach($unified_search_modules_display as $module=>$data) {
204                                     if (!empty($data['visible']) ) {
205                                         $modules_to_search[$module] = $beanList[$module];
206                                     }
207                                 }
208                         }
209                         $current_user->setPreference('globalSearch', $modules_to_search, 'search');
210                 }
211
212         
213                 $templateFile = 'modules/Home/UnifiedSearchAdvancedForm.tpl';
214                 if(file_exists('custom/' . $templateFile))
215                 {
216                    $templateFile = 'custom/'.$templateFile;
217                 }
218                 
219                 echo $this->getDropDownDiv($templateFile);
220
221                 $module_results = array();
222                 $module_counts = array();
223                 $has_results = false;
224
225                 if(!empty($this->query_string)) {
226                         foreach($modules_to_search as $moduleName => $beanName) {
227                 require_once $beanFiles[$beanName] ;
228                 $seed = new $beanName();
229                 
230                 $lv = new ListViewSmarty();
231                 $lv->lvd->additionalDetails = false;
232                 $mod_strings = return_module_language($current_language, $seed->module_dir);
233                 
234                 //retrieve the original list view defs and store for processing in case of custom layout changes
235                 require('modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
236                                 $orig_listViewDefs = $listViewDefs;
237                                 
238                 if(file_exists('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php'))
239                 {
240                     require('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
241                 }
242                 
243                 if ( !isset($listViewDefs) || !isset($listViewDefs[$seed->module_dir]) )
244                 {
245                     continue;
246                 }
247                 
248                             $unifiedSearchFields = array () ;
249                 $innerJoins = array();
250                 foreach ( $unified_search_modules[ $moduleName ]['fields'] as $field=>$def )
251                 {
252                         $listViewCheckField = strtoupper($field);
253                         //check to see if the field is in listview defs
254                                         if ( empty($listViewDefs[$seed->module_dir][$listViewCheckField]['default']) ) {
255                                                 //check to see if field is in original list view defs (in case we are using custom layout defs)
256                                                 if (!empty($orig_listViewDefs[$seed->module_dir][$listViewCheckField]['default']) ) {
257                                                         //if we are here then the layout has been customized, but the field is still needed for query creation
258                                                         $listViewDefs[$seed->module_dir][$listViewCheckField] = $orig_listViewDefs[$seed->module_dir][$listViewCheckField];
259                                                 }
260
261                                         }
262                     
263                     //bug: 34125 we might want to try to use the LEFT JOIN operator instead of the INNER JOIN in the case we are
264                     //joining against a field that has not been populated.
265                     if(!empty($def['innerjoin']) )
266                     {
267                         if (empty($def['db_field']) )
268                         {
269                             continue;
270                         }
271                         $innerJoins[$field] = $def;
272                         $def['innerjoin'] = str_replace('INNER', 'LEFT', $def['innerjoin']);
273                     }
274                     $unifiedSearchFields[ $moduleName ] [ $field ] = $def ;
275                     $unifiedSearchFields[ $moduleName ] [ $field ][ 'value' ] = $this->query_string ;
276                 }
277                 
278                 /*
279                  * Use searchForm2->generateSearchWhere() to create the search query, as it can generate SQL for the full set of comparisons required
280                  * generateSearchWhere() expects to find the search conditions for a field in the 'value' parameter of the searchFields entry for that field
281                  */
282                 require_once $beanFiles[$beanName] ;
283                 $seed = new $beanName();
284                                 require_once 'include/SearchForm/SearchForm2.php' ;
285                 $searchForm = new SearchForm ( $seed, $moduleName ) ;
286                 
287                 $searchForm->setup (array ( $moduleName => array() ) , $unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
288                 $where_clauses = $searchForm->generateSearchWhere() ;
289                 //add inner joins back into the where clause
290                 $params = array('custom_select' => "");
291                 foreach($innerJoins as $field=>$def) {
292                     if (isset ($def['db_field'])) {
293                       foreach($def['db_field'] as $dbfield)
294                           $where_clauses[] = $dbfield . " LIKE '" . $this->query_string . "%'";
295                           $params['custom_select'] .= ", $dbfield";
296                           $params['distinct'] = true;
297                           //$filterFields[$dbfield] = $dbfield;
298                     }
299                 }
300
301                 if (count($where_clauses) > 0) 
302                 {
303                     $where = '(('. implode(' ) OR ( ', $where_clauses) . '))';
304                 }
305       
306                 $displayColumns = array();
307                 foreach($listViewDefs[$seed->module_dir] as $colName => $param) 
308                 {
309                     if(!empty($param['default']) && $param['default'] == true) 
310                     {
311                         $param['url_sort'] = true;//bug 27933
312                         $displayColumns[$colName] = $param;
313                     }
314                 }
315
316                 if(count($displayColumns) > 0) 
317                 {
318                         $lv->displayColumns = $displayColumns;
319                 } else {
320                         $lv->displayColumns = $listViewDefs[$seed->module_dir];
321                 }
322
323                 $lv->export = false;
324                 $lv->mergeduplicates = false;
325                 $lv->multiSelect = false;
326                 $lv->delete = false;
327                 $lv->select = false;
328                 $lv->showMassupdateFields = false;
329                 $lv->email = false;
330                 if($overlib) {
331                     $lv->overlib = true;
332                     $overlib = false;
333                 } else {
334                         $lv->overlib = false;
335                 }
336                 
337                 $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', $where, $params, 0, 10);
338                 
339                 $module_results[$moduleName] = '<br /><br />' . get_form_header($GLOBALS['app_list_strings']['moduleList'][$seed->module_dir] . ' (' . $lv->data['pageData']['offsets']['total'] . ')', '', false);
340                 $module_counts[$moduleName] = $lv->data['pageData']['offsets']['total'];
341
342                 if($lv->data['pageData']['offsets']['total'] == 0) {
343                     //$module_results[$moduleName] .= "<li class='noBullet' id='whole_subpanel_{$moduleName}'><div id='div_{$moduleName}'><h2>" . $home_mod_strings['LBL_NO_RESULTS_IN_MODULE'] . '</h2></div></li>';
344                     $module_results[$moduleName] .= '<h2>' . $home_mod_strings['LBL_NO_RESULTS_IN_MODULE'] . '</h2>';
345                 } else {
346                     $has_results = true;
347                     //$module_results[$moduleName] .= "<li class='noBullet' id='whole_subpanel_{$moduleName}'><div id='div_{$moduleName}'>" . $lv->display(false, false) . '</div></li>';
348                     $module_results[$moduleName] .= $lv->display(false, false);
349                 }
350                 
351                         }
352                 }
353                                 
354                 if($has_results) {
355                         foreach($module_counts as $name=>$value) {
356                                 echo $module_results[$name];
357                         }
358                 } else if(empty($_REQUEST['form_only'])) {
359                         echo $home_mod_strings['LBL_NO_RESULTS'];
360                         echo $home_mod_strings['LBL_NO_RESULTS_TIPS'];
361                 }
362
363         }
364
365         function buildCache()
366         {
367
368                 global $beanList, $beanFiles, $dictionary;
369                 
370                 $supported_modules = array();
371
372                 foreach($beanList as $moduleName=>$beanName)
373                 {
374                         if (!isset($beanFiles[$beanName]))
375                                 continue;
376
377                         if($beanName == 'aCase') $beanName = 'Case';
378                         
379                         $manager = new VardefManager ( );
380                         $manager->loadVardef( $moduleName , $beanName ) ;
381
382                         // obtain the field definitions used by generateSearchWhere (duplicate code in view.list.php)
383                         if(file_exists('custom/modules/'.$moduleName.'/metadata/metafiles.php')){
384                 require('custom/modules/'.$moduleName.'/metadata/metafiles.php');       
385             }elseif(file_exists('modules/'.$moduleName.'/metadata/metafiles.php')){
386                 require('modules/'.$moduleName.'/metadata/metafiles.php');
387             }
388                 
389                         
390                         if(!empty($metafiles[$moduleName]['searchfields']))
391                         {
392                                 require $metafiles[$moduleName]['searchfields'] ;
393                         } else if(file_exists("modules/{$moduleName}/metadata/SearchFields.php")) {
394                                 require "modules/{$moduleName}/metadata/SearchFields.php" ;
395                         }               
396                         
397                         //Load custom SearchFields.php if it exists
398                         if(file_exists("custom/modules/{$moduleName}/metadata/SearchFields.php")) 
399                         {
400                                 require "custom/modules/{$moduleName}/metadata/SearchFields.php" ;
401                         }                               
402
403             //If there are $searchFields are empty, just continue, there are no search fields defined for the module
404             if(empty($searchFields))
405             {
406                 continue;
407             }
408
409                         $isCustomModule = preg_match('/^([a-z0-9]{1,5})_([a-z0-9_]+)$/i' , $moduleName);
410                         
411                         //If the bean supports unified search or if it's a custom module bean and unified search is not defined
412                         if(!empty($dictionary[$beanName]['unified_search']) || $isCustomModule)
413                         {
414                                 $fields = array();
415                                 foreach ( $dictionary [ $beanName ][ 'fields' ] as $field => $def )
416                                 {
417                                         // We cannot enable or disable unified_search for email in the vardefs as we don't actually have a vardef entry for 'email'
418                                         // the searchFields entry for 'email' doesn't correspond to any vardef entry. Instead it contains SQL to directly perform the search.
419                                         // So as a proxy we allow any field in the vardefs that has a name starting with 'email...' to be tagged with the 'unified_search' parameter
420
421                                         if (strpos($field,'email') !== false)
422                                         {
423                                                 $field = 'email' ;
424                                         }
425                                                 
426                                         //bug: 38139 - allow phone to be searched through Global Search
427                                         if (strpos($field,'phone') !== false)
428                                         {
429                                                 $field = 'phone' ;
430                                         }
431                                         
432                                         if ( !empty($def['unified_search']) && isset ( $searchFields [ $moduleName ] [ $field ]  ))
433                                         {
434                                                 $fields [ $field ] = $searchFields [ $moduleName ] [ $field ] ;
435                                         }
436                                 }
437
438                 foreach ($searchFields[$moduleName] as $field => $def)
439                 {
440                     if (
441                         isset($def['force_unifiedsearch'])
442                         and $def['force_unifiedsearch']
443                     )
444                     {
445                         $fields[$field] = $def;
446                     }
447                 }
448
449                                 if(count($fields) > 0) {
450                                         $supported_modules [$moduleName] ['fields'] = $fields;
451                                         if (isset($dictionary[$beanName]['unified_search_default_enabled']) && $dictionary[$beanName]['unified_search_default_enabled'] === TRUE) 
452                                         {
453                         $supported_modules [$moduleName]['default'] = true;
454                     } else {
455                         $supported_modules [$moduleName]['default'] = false;
456                     }
457                                 }
458
459                         }
460
461                 }
462                 
463                 ksort($supported_modules);
464                 write_array_to_file('unified_search_modules', $supported_modules, $GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php');
465         }
466
467         
468         /**
469          * 
470          */
471         function modifyGlobalSearchSettings()
472         {
473                 global $mod_strings, $app_strings, $app_list_strings;
474
475                 if(!file_exists('custom/modules/unified_search_modules_display.php'))
476                 {
477                         $this->createUnifiedSearchModulesDisplay();
478                 }
479                 
480                 include('custom/modules/unified_search_modules_display.php');
481                                 
482                 $sugar_smarty = new Sugar_Smarty();             
483                 $sugar_smarty->assign('APP', $app_strings);
484                 $sugar_smarty->assign('MOD', $mod_strings);
485                 
486                 //Add the translated attribute for display label
487                 $json_enabled = array();
488                 $json_disabled = array();
489                 foreach($unified_search_modules_display as $module=>$data)
490                 {
491                         $label = isset($app_list_strings['moduleList'][$module]) ? $app_list_strings['moduleList'][$module] : $module;
492                         if($data['visible'] === true)
493                         {
494                            $json_enabled[] = array("module" => $module, 'label' => $label);
495                         } else {
496                            $json_disabled[] = array("module" => $module, 'label' => $label);
497                         }
498                 }
499                 
500                 //If the file doesn't exist
501                 if(!file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php'))
502                 {
503                         $this->buildCache();
504                 }
505                 
506                 include($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php');            
507                 
508                 //Now add any new modules that may have since been added to unified_search_modules.php
509                 foreach($unified_search_modules as $module=>$data)
510                 {
511                         if(!isset($unified_search_modules_display[$module]))
512                         {
513                             $label = isset($app_list_strings['moduleList'][$module]) ? $app_list_strings['moduleList'][$module] : $module;
514                                 if($data['default'])
515                                 {
516                                   $json_enabled[] = array("module" => $module, 'label' => $label);
517                                 } else {
518                                   $json_disabled[] = array("module" => $module, 'label' => $label);
519                                 }
520                         }
521                 }
522                 
523                 $sugar_smarty->assign('enabled_modules', json_encode($json_enabled));
524                 $sugar_smarty->assign('disabled_modules', json_encode($json_disabled));         
525                 
526                 //uasort($unified_search_modules_display, 'unified_search_modules_cmp');
527                 $tpl = 'modules/Administration/templates/GlobalSearchSettings.tpl';
528                 if(file_exists('custom/' . $tpl))
529                 {
530                    $tpl = 'custom/' . $tpl;
531                 }
532                 return $sugar_smarty->fetch($tpl);                              
533         }
534         
535         
536         /**
537          * saveGlobalSearchSettings
538          * This method handles the administrator's request to save the searchable modules selected and stores
539          * the results in the unified_search_modules_display.php file
540          * 
541          */
542         function saveGlobalSearchSettings()
543         {
544                 if(!file_exists('custom/modules/unified_search_modules_display.php'))
545                 {
546                         $this->createUnifiedSearchModulesDisplay();
547                 }
548
549                 include('custom/modules/unified_search_modules_display.php');
550                 
551                 if(isset($_REQUEST['enabled_modules'])) 
552                 {
553                         $new_unified_search_modules_display = array();
554                         
555             foreach(explode (',', $_REQUEST['enabled_modules'] ) as $module)
556             {
557                 $new_unified_search_modules_display[$module]['visible'] = true;
558             }
559      
560                         foreach($unified_search_modules_display as $module=>$data)
561                         {
562                                 if(!isset($new_unified_search_modules_display[$module]))
563                                 {
564                                    $new_unified_search_modules_display[$module]['visible'] = false;
565                                 }
566                         }
567
568                         $this->writeUnifiedSearchModulesDisplayFile($new_unified_search_modules_display);
569                 }
570         }
571         
572         
573         public static function unlinkUnifiedSearchModulesFile() {
574                 //clear the unified_search_module.php file
575         if(file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php'))
576         {
577                 $GLOBALS['log']->info("unlink {$GLOBALS['sugar_config']['cache_dir']}modules/unified_search_modules.php file");
578                 unlink($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php');
579         }       
580         }
581         
582         /**
583          * createUnifiedSearchModulesDisplay
584          * method to create the unified_search_modules_display.php file
585          * 
586          */
587         function createUnifiedSearchModulesDisplay()
588         {
589                 //Make directory if it doesn't exist
590                 if(!file_exists('cache/modules'))
591                 {
592                    mkdir_recursive('cache/modules');    
593                 }
594                 
595                 //Load unified_search_modules.php file
596                 if(!file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php'))
597                 {
598                         $this->buildCache();
599                 }
600                 
601                 include($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php');
602                 
603                 $unified_search_modules_display = array();
604                 
605                 if(!empty($unified_search_modules))
606                 {
607                         foreach($unified_search_modules as $module=>$data)
608                         {
609                                 $unified_search_modules_display[$module]['visible'] = (isset($data['default']) && $data['default']) ? true : false;
610                         }
611                 }
612                 
613                 $this->writeUnifiedSearchModulesDisplayFile($unified_search_modules_display);
614         }
615         
616         
617         /*
618          * writeUnifiedSearchModulesDisplayFile
619          * Private method to handle writing the unified_search_modules_display value to file
620          * 
621          * @param mixed The array of the unified search modules and their display attributes
622          * @return boolean value indication whether or not file was successfully written
623          * @throws Exception Thrown if the file write operation fails
624          */
625         private function writeUnifiedSearchModulesDisplayFile($unified_search_modules_display)
626         {
627                 if(is_null($unified_search_modules_display) || empty($unified_search_modules_display))
628                 {
629                    return false;
630                 }
631                 
632             if(!write_array_to_file("unified_search_modules_display", $unified_search_modules_display, 'custom/modules/unified_search_modules_display.php')) 
633             {
634                 //Log error message and throw Exception
635                 global $app_strings;
636                 $msg = string_format($app_strings['ERR_FILE_WRITE'], array('custom/modules/unified_search_modules_display.php'));
637                 $GLOBALS['log']->error($msg);
638                 throw new Exception($msg);
639             }           
640             
641             return true;
642         }
643 }
644
645
646 function unified_search_modules_cmp($a, $b) {
647         if(!isset($a['translated']) || !isset($b['translated']))
648         {
649            return 0;
650         }
651         
652         $name1 = strtolower($a['translated']);
653         $name2 = strtolower($b['translated']);
654         
655         return $name1 < $name2 ? -1 : 1;
656 }       
657
658 ?>