PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Home/UnifiedSearchAdvanced.php

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