PageRenderTime 10ms CodeModel.GetById 9ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 1ms

/modules/Home/UnifiedSearchAdvanced.php

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