PageRenderTime 61ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/Home/UnifiedSearchAdvanced.php

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