PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/Home/UnifiedSearchAdvanced.php

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