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