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