/** * @see SearchForm::setup() */ function setup() { parent::setup(); $this->xtpl->assign('LOADING_IMAGE', getStudioIcon('loading', 'loading', 16, 16)); $this->xtpl->assign('HELP_IMAGE', SugarThemeRegistry::current()->getImageURL('help-dashlet.gif')); $this->xtpl->assign('CLOSE_IMAGE', SugarThemeRegistry::current()->getImageURL('close.gif')); }
function display() { if (!$this->bean->ACLAccess('list')) { ACLController::displayNoAccess(); return; } $module = $GLOBALS['module']; $metadataFile = null; $foundViewDefs = false; if (file_exists('custom/modules/' . $module . '/metadata/listviewdefs.php')) { $metadataFile = 'custom/modules/' . $module . '/metadata/listviewdefs.php'; $foundViewDefs = true; } else { if (file_exists('custom/modules/' . $module . '/metadata/metafiles.php')) { require_once 'custom/modules/' . $module . '/metadata/metafiles.php'; if (!empty($metafiles[$module]['listviewdefs'])) { $metadataFile = $metafiles[$module]['listviewdefs']; $foundViewDefs = true; } } elseif (file_exists('modules/' . $module . '/metadata/metafiles.php')) { require_once 'modules/' . $module . '/metadata/metafiles.php'; if (!empty($metafiles[$module]['listviewdefs'])) { $metadataFile = $metafiles[$module]['listviewdefs']; $foundViewDefs = true; } } } if (!$foundViewDefs && file_exists('modules/' . $module . '/metadata/listviewdefs.php')) { $metadataFile = 'modules/' . $module . '/metadata/listviewdefs.php'; } require_once $metadataFile; $seed = $this->bean; if (!empty($this->bean->object_name) && isset($_REQUEST[$module . '2_' . strtoupper($this->bean->object_name) . '_offset'])) { //if you click the pagination button, it will poplate the search criteria here if (!empty($_REQUEST['current_query_by_page'])) { //The code support multi browser tabs pagination $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'request_data', 'current_query_by_page', $module . '2_' . strtoupper($this->bean->object_name) . '_ORDER_BY'); if (isset($_REQUEST['lvso'])) { $blockVariables[] = 'lvso'; } $current_query_by_page = unserialize(base64_decode($_REQUEST['current_query_by_page'])); foreach ($current_query_by_page as $search_key => $search_value) { if ($search_key != $module . '2_' . strtoupper($this->bean->object_name) . '_offset' && !in_array($search_key, $blockVariables)) { if (!is_array($search_value)) { $_REQUEST[$search_key] = $GLOBALS['db']->quoteForEmail($search_value); } else { foreach ($search_value as $key => &$val) { $val = $GLOBALS['db']->quoteForEmail($val); } $_REQUEST[$search_key] = $search_value; } } } } } if (!empty($_REQUEST['saved_search_select']) && $_REQUEST['saved_search_select'] != '_none') { if (empty($_REQUEST['button']) && (empty($_REQUEST['clear_query']) || $_REQUEST['clear_query'] != 'true')) { $this->saved_search = loadBean('SavedSearch'); $this->saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']); $this->saved_search->populateRequest(); } elseif (!empty($_REQUEST['button'])) { // click the search button, after retrieving from saved_search $_SESSION['LastSavedView'][$_REQUEST['module']] = ''; unset($_REQUEST['saved_search_select']); unset($_REQUEST['saved_search_select_name']); } } $lv = new ListViewSmarty(); $displayColumns = array(); if (!empty($_REQUEST['displayColumns'])) { foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) { if (!empty($listViewDefs[$module][$col])) { $displayColumns[$col] = $listViewDefs[$module][$col]; } } } else { foreach ($listViewDefs[$module] as $col => $params) { if (!empty($params['default']) && $params['default']) { $displayColumns[$col] = $params; } } } global $current_user; if (!is_admin($current_user)) { $params = array('massupdate' => false); $lv->export = false; } else { $params = array('massupdate' => true, 'export' => true); } if (!empty($_REQUEST['orderBy'])) { $params['orderBy'] = $_REQUEST['orderBy']; $params['overrideOrder'] = true; if (!empty($_REQUEST['sortOrder'])) { $params['sortOrder'] = $_REQUEST['sortOrder']; } } $lv->displayColumns = $displayColumns; $this->seed = $seed; $this->module = $module; $searchForm = null; $storeQuery = new StoreQuery(); if (!isset($_REQUEST['query'])) { $storeQuery->loadQuery($this->module); $storeQuery->populateRequest(); } else { $storeQuery->saveFromRequest($this->module); } //search $view = 'basic_search'; if (!empty($_REQUEST['search_form_view'])) { $view = $_REQUEST['search_form_view']; } $headers = true; if (!empty($_REQUEST['search_form_only']) && $_REQUEST['search_form_only']) { $headers = false; } elseif (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') { if (isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') { $view = 'advanced_search'; } else { $view = 'basic_search'; } } $use_old_search = true; if (file_exists('modules/' . $this->module . '/SearchForm.html')) { require_once 'include/SearchForm/SearchForm.php'; $searchForm = new SearchForm($this->module, $this->seed); } else { $use_old_search = false; require_once 'include/SearchForm/SearchForm2.php'; if (file_exists('custom/modules/' . $this->module . '/metadata/searchdefs.php')) { require_once 'custom/modules/' . $this->module . '/metadata/searchdefs.php'; } elseif (!empty($metafiles[$this->module]['searchdefs'])) { require_once $metafiles[$this->module]['searchdefs']; } elseif (file_exists('modules/' . $this->module . '/metadata/searchdefs.php')) { require_once 'modules/' . $this->module . '/metadata/searchdefs.php'; } if (!empty($metafiles[$this->module]['searchfields'])) { require_once $metafiles[$this->module]['searchfields']; } elseif (file_exists('modules/' . $this->module . '/metadata/SearchFields.php')) { require_once 'modules/' . $this->module . '/metadata/SearchFields.php'; } $searchForm = new SearchForm($this->seed, $this->module, $this->action); $searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl', $view, $listViewDefs); $searchForm->lv = $lv; } if (isset($this->options['show_title']) && $this->options['show_title']) { $moduleName = isset($this->seed->module_dir) ? $this->seed->module_dir : $GLOBALS['mod_strings']['LBL_MODULE_NAME']; echo getClassicModuleTitle($moduleName, array($GLOBALS['mod_strings']['LBL_MODULE_TITLE']), FALSE); } $where = ''; if (isset($_REQUEST['query'])) { // we have a query if (!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) { // from EditView cancel $searchForm->populateFromArray($storeQuery->query); } else { $searchForm->populateFromRequest(); } $where_clauses = $searchForm->generateSearchWhere(true, $this->seed->module_dir); if (count($where_clauses) > 0) { $where = '(' . implode(' ) AND ( ', $where_clauses) . ')'; } $GLOBALS['log']->info("List View Where Clause: {$where}"); } if ($use_old_search) { switch ($view) { case 'basic_search': $searchForm->setup(); $searchForm->displayBasic($headers); break; case 'advanced_search': $searchForm->setup(); $searchForm->displayAdvanced($headers); break; case 'saved_views': echo $searchForm->displaySavedViews($listViewDefs, $lv, $headers); break; } } else { echo $searchForm->display($headers); } if (!$headers) { return; } if (empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false) { if (!is_admin($current_user)) { $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', $where, $params); } else { $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, $params); } $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : ' - ' . $_REQUEST['saved_search_select_name']; echo $lv->display(); } }
function generateSearchWhere($module, $query) { //this function is similar with function prepareSearchForm() in view.list.php $seed = loadBean($module); $this->use_old_search = true; if (file_exists('modules/' . $module . '/SearchForm.html')) { if (file_exists('modules/' . $module . '/metadata/SearchFields.php')) { require_once 'include/SearchForm/SearchForm.php'; $searchForm = new SearchForm($module, $seed); } elseif (!empty($_SESSION['export_where'])) { //bug 26026, sometimes some module doesn't have a metadata/SearchFields.php, the searchfrom is generated in the ListView.php. //So currently massupdate will not gernerate the where sql. It will use the sql stored in the SESSION. But this will cause bug 24722, and it cannot be avoided now. $where = $_SESSION['export_where']; $whereArr = explode(" ", trim($where)); if ($whereArr[0] == trim('where')) { $whereClean = array_shift($whereArr); } $this->where_clauses = implode(" ", $whereArr); return; } else { $this->where_clauses = ''; return; } } else { $this->use_old_search = false; require_once 'include/SearchForm/SearchForm2.php'; if (file_exists('custom/modules/' . $module . '/metadata/metafiles.php')) { require 'custom/modules/' . $module . '/metadata/metafiles.php'; } elseif (file_exists('modules/' . $module . '/metadata/metafiles.php')) { require 'modules/' . $module . '/metadata/metafiles.php'; } if (file_exists('custom/modules/' . $module . '/metadata/searchdefs.php')) { require_once 'custom/modules/' . $module . '/metadata/searchdefs.php'; } elseif (!empty($metafiles[$module]['searchdefs'])) { require_once $metafiles[$module]['searchdefs']; } elseif (file_exists('modules/' . $module . '/metadata/searchdefs.php')) { require_once 'modules/' . $module . '/metadata/searchdefs.php'; } if (!empty($metafiles[$module]['searchfields'])) { require_once $metafiles[$module]['searchfields']; } elseif (file_exists('modules/' . $module . '/metadata/SearchFields.php')) { require_once 'modules/' . $module . '/metadata/SearchFields.php'; } if (empty($searchdefs) || empty($searchFields)) { $this->where_clauses = ''; //for some modules, such as iframe, it has massupdate, but it doesn't have search function, the where sql should be empty. return; } $searchForm = new SearchForm($seed, $module); $searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl'); } /* bug 31271: using false to not add all bean fields since some beans - like SavedReports can have fields named 'module' etc. which may break the query */ $searchForm->populateFromArray(unserialize(base64_decode($query)), null, true); // see bug 31271 $this->searchFields = $searchForm->searchFields; $where_clauses = $searchForm->generateSearchWhere(true, $module); if (count($where_clauses) > 0) { $this->where_clauses = '(' . implode(' ) AND ( ', $where_clauses) . ')'; $GLOBALS['log']->info("MassUpdate Where Clause: {$this->where_clauses}"); } else { $this->where_clauses = ''; } }
function generateSearchWhere($module, $query) { //this function is similar with function prepareSearchForm() in view.list.php $seed = loadBean($module); if (file_exists('modules/' . $module . '/SearchForm.html')) { if (file_exists('modules/' . $module . '/metadata/SearchFields.php')) { require_once 'include/SearchForm/SearchForm.php'; $searchForm = new SearchForm($module, $seed); } elseif (!empty($_SESSION['export_where'])) { //bug 26026, sometimes some module doesn't have a metadata/SearchFields.php, the searchfrom is generated in the ListView.php. //So currently massupdate will not gernerate the where sql. It will use the sql stored in the SESSION. But this will cause bug 24722, and it cannot be avoided now. $where = $_SESSION['export_where']; $whereArr = explode(" ", trim($where)); if ($whereArr[0] == trim('where')) { $whereClean = array_shift($whereArr); } $where = implode(" ", $whereArr); //rrs bug: 31329 - previously this was just returning $where, but the problem is the caller of this function //expects the results in an array, not just a string. So rather than fixing the caller, I felt it would be best for //the function to return the results in a standard format. $ret_array['where'] = $where; $ret_array['searchFields'] = array(); return $ret_array; } else { return; } } else { require_once 'include/SearchForm/SearchForm2.php'; if (file_exists('custom/modules/' . $module . '/metadata/metafiles.php')) { require 'custom/modules/' . $module . '/metadata/metafiles.php'; } elseif (file_exists('modules/' . $module . '/metadata/metafiles.php')) { require 'modules/' . $module . '/metadata/metafiles.php'; } if (file_exists('custom/modules/' . $module . '/metadata/searchdefs.php')) { require_once 'custom/modules/' . $module . '/metadata/searchdefs.php'; } elseif (!empty($metafiles[$module]['searchdefs'])) { require_once $metafiles[$module]['searchdefs']; } elseif (file_exists('modules/' . $module . '/metadata/searchdefs.php')) { require_once 'modules/' . $module . '/metadata/searchdefs.php'; } if (!empty($metafiles[$module]['searchfields'])) { require_once $metafiles[$module]['searchfields']; } elseif (file_exists('modules/' . $module . '/metadata/SearchFields.php')) { require_once 'modules/' . $module . '/metadata/SearchFields.php'; } if (empty($searchdefs) || empty($searchFields)) { //for some modules, such as iframe, it has massupdate, but it doesn't have search function, the where sql should be empty. return; } $searchForm = new SearchForm($seed, $module); $searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl'); } $searchForm->populateFromArray(unserialize(base64_decode($query))); $where_clauses = $searchForm->generateSearchWhere(true, $module); if (count($where_clauses) > 0) { $where = '(' . implode(' ) AND ( ', $where_clauses) . ')'; } $GLOBALS['log']->info("Export Where Clause: {$where}"); $ret_array['where'] = $where; $ret_array['searchFields'] = $searchForm->searchFields; return $ret_array; }
} if (file_exists('custom/modules/' . $module . '/metadata/searchdefs.php')) { require_once 'custom/modules/' . $module . '/metadata/searchdefs.php'; } elseif (!empty($metafiles[$module]['searchdefs'])) { require_once $metafiles[$module]['searchdefs']; } elseif (file_exists('modules/' . $module . '/metadata/searchdefs.php')) { require_once 'modules/' . $module . '/metadata/searchdefs.php'; } if (!empty($metafiles[$module]['searchfields'])) { require_once $metafiles[$module]['searchfields']; } elseif (file_exists('modules/' . $module . '/metadata/SearchFields.php')) { require_once 'modules/' . $module . '/metadata/SearchFields.php'; } if (!empty($searchdefs) && !empty($searchFields)) { $searchForm = new SearchForm($seed, $module); $searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl'); $searchForm->populateFromArray($current_query_by_page_array, 'advanced'); $where_clauses_arr = $searchForm->generateSearchWhere(true, $module); if (count($where_clauses_arr) > 0) { $where_clauses = '(' . implode(' ) AND ( ', $where_clauses_arr) . ')'; } } $ret_array = create_export_query_relate_link_patch($module, $searchFields, $where_clauses); $query = $seed->create_export_query($order_by, $ret_array['where'], $ret_array['join']); $result = $GLOBALS['db']->query($query, true); $uids = array(); while ($val = $GLOBALS['db']->fetchByAssoc($result, -1, false)) { array_push($uids, $val['id']); } $_REQUEST['subpanel_id'] = $uids; }
public function testRetrieveByDaterange() { global $current_user; $_REQUEST = $_POST = array("module" => "Meetings", "action" => "index", "searchFormTab" => "basic_search", "query" => "true", "name_basic" => "", "current_user_only_basic" => "0", "favorites_only_basic" => "0", "open_only_basic" => "0", "date_start_basic_range_choice" => "between", "range_date_start_basic" => "", "start_range_date_start_basic" => "13/07/2011", "end_range_date_start_basic" => "14/07/2011", "button" => "Search"); $srch = new SearchForm(new Meeting(), "Meetings"); $srch->setup($this->searchDefs, $this->searchFields, ""); $srch->populateFromRequest(); $w = $srch->generateSearchWhere(); // Due to daylight savings, I cannot hardcode intervals... $GMTDatesStart = $this->timedate->getDayStartEndGMT("2011-07-13"); $GMTDatesEnd = $this->timedate->getDayStartEndGMT("2011-07-14"); // Current User is on GMT+2. // Asking for meeting between 13 and 14 July 2011, I expect to search (GMT) from 12 July at 22:00 until 14 July at 22:00 (excluded) $expectedWhere = "meetings.date_start >= '" . $GMTDatesStart['start'] . "' AND meetings.date_start <= '" . $GMTDatesEnd['end'] . "'"; $this->assertEquals($w[0], $expectedWhere); }
/** * _performSearch * * Performs the search from the global search field. * * @param $query string what we are searching for * @param $modules array modules we are searching in * @param $offset int search result offset * @param $limit int search limit * @return array */ protected function _performSearch($query, $modules, $offset = -1, $limit = 20) { if (empty($query)) { return array(); } $primary_module = ''; $results = array(); require_once 'include/SearchForm/SearchForm2.php'; $where = ''; $searchEmail = preg_match('/^([^%]|%)*@([^%]|%)*$/', $query); // bug49650 - strip out asterisks from query in case // user thinks asterisk is a wildcard value $query = str_replace('*', '', $query); $limit = !empty($GLOBALS['sugar_config']['max_spotresults_initial']) ? $GLOBALS['sugar_config']['max_spotresults_initial'] : 5; if ($offset !== -1) { $limit = !empty($GLOBALS['sugar_config']['max_spotresults_more']) ? $GLOBALS['sugar_config']['max_spotresults_more'] : 20; } $totalCounted = empty($GLOBALS['sugar_config']['disable_count_query']); foreach ($modules as $moduleName) { if (empty($primary_module)) { $primary_module = $moduleName; } $searchFields = SugarSpot::getSearchFields($moduleName); if (empty($searchFields[$moduleName])) { continue; } $class = $GLOBALS['beanList'][$moduleName]; $return_fields = array(); $seed = new $class(); if (!$seed->ACLAccess('ListView')) { continue; } if ($class == 'aCase') { $class = 'Case'; } foreach ($searchFields[$moduleName] as $k => $v) { $keep = false; $searchFields[$moduleName][$k]['value'] = $query; if (!empty($searchFields[$moduleName][$k]['force_unifiedsearch'])) { continue; } if (!empty($GLOBALS['dictionary'][$class]['unified_search'])) { if (empty($GLOBALS['dictionary'][$class]['fields'][$k]['unified_search'])) { if (isset($searchFields[$moduleName][$k]['db_field'])) { foreach ($searchFields[$moduleName][$k]['db_field'] as $field) { if (!empty($GLOBALS['dictionary'][$class]['fields'][$field]['unified_search'])) { if (isset($GLOBALS['dictionary'][$class]['fields'][$field]['type'])) { if (!$this->filterSearchType($GLOBALS['dictionary'][$class]['fields'][$field]['type'], $query)) { unset($searchFields[$moduleName][$k]); continue; } } $keep = true; } } //foreach } # Bug 42961 Spot search for custom fields if (!$keep && (isset($v['force_unifiedsearch']) == false || $v['force_unifiedsearch'] != true)) { if (strpos($k, 'email') === false || !$searchEmail) { unset($searchFields[$moduleName][$k]); } } } else { if ($GLOBALS['dictionary'][$class]['fields'][$k]['type'] == 'int' && !is_numeric($query)) { unset($searchFields[$moduleName][$k]); } } } else { if (empty($GLOBALS['dictionary'][$class]['fields'][$k])) { //If module did not have unified_search defined, then check the exception for an email search before we unset if (strpos($k, 'email') === false || !$searchEmail) { unset($searchFields[$moduleName][$k]); } } else { if (!$this->filterSearchType($GLOBALS['dictionary'][$class]['fields'][$k]['type'], $query)) { unset($searchFields[$moduleName][$k]); } } } } //foreach //If no search field criteria matched then continue to next module if (empty($searchFields[$moduleName])) { continue; } if (empty($searchFields[$moduleName])) { continue; } if (isset($seed->field_defs['name'])) { $return_fields['name'] = $seed->field_defs['name']; } foreach ($seed->field_defs as $k => $v) { if (isset($seed->field_defs[$k]['type']) && $seed->field_defs[$k]['type'] == 'name' && !isset($return_fields[$k])) { $return_fields[$k] = $seed->field_defs[$k]; } } if (!isset($return_fields['name'])) { // if we couldn't find any name fields, try search fields that have name in it foreach ($searchFields[$moduleName] as $k => $v) { if (strpos($k, 'name') != -1 && isset($seed->field_defs[$k]) && !isset($seed->field_defs[$k]['source'])) { $return_fields[$k] = $seed->field_defs[$k]; break; } } } if (!isset($return_fields['name'])) { // last resort - any fields that have 'name' in their name foreach ($seed->field_defs as $k => $v) { if (strpos($k, 'name') != -1 && isset($seed->field_defs[$k]) && !isset($seed->field_defs[$k]['source'])) { $return_fields[$k] = $seed->field_defs[$k]; break; } } } if (!isset($return_fields['name'])) { // FAIL: couldn't find id & name for the module $GLOBALS['log']->error("Unable to find name for module {$moduleName}"); continue; } if (isset($return_fields['name']['fields'])) { // some names are composite foreach ($return_fields['name']['fields'] as $field) { $return_fields[$field] = $seed->field_defs[$field]; } } $searchForm = new SearchForm($seed, $moduleName); $searchForm->setup(array($moduleName => array()), $searchFields, '', 'saved_views'); $where_clauses = $searchForm->generateSearchWhere(); if (empty($where_clauses)) { continue; } if (count($where_clauses) > 1) { $query_parts = array(); $ret_array_start = $seed->create_new_list_query('', '', $return_fields, array(), 0, '', true, $seed, true); $search_keys = array_keys($searchFields[$moduleName]); foreach ($where_clauses as $n => $clause) { $allfields = $return_fields; $skey = $search_keys[$n]; if (isset($seed->field_defs[$skey])) { // Joins for foreign fields aren't produced unless the field is in result, hence the merge $allfields[$skey] = $seed->field_defs[$skey]; } $ret_array = $seed->create_new_list_query('', $clause, $allfields, array(), 0, '', true, $seed, true); $query_parts[] = $ret_array_start['select'] . $ret_array['from'] . $ret_array['where'] . $ret_array['order_by']; } $main_query = "(" . join(") UNION (", $query_parts) . ")"; } else { foreach ($searchFields[$moduleName] as $k => $v) { if (isset($seed->field_defs[$k])) { $return_fields[$k] = $seed->field_defs[$k]; } } $ret_array = $seed->create_new_list_query('', $where_clauses[0], $return_fields, array(), 0, '', true, $seed, true); $main_query = $ret_array['select'] . $ret_array['from'] . $ret_array['where'] . $ret_array['order_by']; } $totalCount = null; if ($limit < -1) { $result = $seed->db->query($main_query); } else { if ($limit == -1) { $limit = $GLOBALS['sugar_config']['list_max_entries_per_page']; } if ($offset == 'end') { $totalCount = $this->_getCount($seed, $main_query); if ($totalCount) { $offset = floor(($totalCount - 1) / $limit) * $limit; } else { $offset = 0; } } $result = $seed->db->limitQuery($main_query, $offset, $limit + 1); } $data = array(); $count = 0; while ($count < $limit && ($row = $seed->db->fetchByAssoc($result))) { $temp = clone $seed; $temp->setupCustomFields($temp->module_dir); $temp->loadFromRow($row); $data[] = $temp->get_list_view_data($return_fields); $count++; } $nextOffset = -1; $prevOffset = -1; $endOffset = -1; if ($count >= $limit) { $nextOffset = $offset + $limit; } if ($offset > 0) { $prevOffset = $offset - $limit; if ($prevOffset < 0) { $prevOffset = 0; } } if ($count >= $limit && $totalCounted) { if (!isset($totalCount)) { $totalCount = $this->_getCount($seed, $main_query); } } else { $totalCount = $count + $offset; } $pageData['offsets'] = array('current' => $offset, 'next' => $nextOffset, 'prev' => $prevOffset, 'end' => $endOffset, 'total' => $totalCount, 'totalCounted' => $totalCounted); $pageData['bean'] = array('objectName' => $seed->object_name, 'moduleDir' => $seed->module_dir); $results[$moduleName] = array("data" => $data, "pageData" => $pageData); } return $results; }
/** * Performs the search * * @param $query string what we are searching for * @param $modules array modules we are searching in * @param $offset int search result offset * @return array */ protected function _performSearch($query, $modules, $offset = -1) { $primary_module = ''; $results = array(); require_once 'include/SearchForm/SearchForm2.php'; $where = ''; $searchEmail = preg_match("/^([^\\%]|\\%)*@([^\\%]|\\%)*\$/", $query); foreach ($modules as $moduleName) { if (empty($primary_module)) { $primary_module = $moduleName; } $searchFields = SugarSpot::getSearchFields($moduleName); $class = $GLOBALS['beanList'][$moduleName]; $return_fields = array(); $seed = new $class(); if (empty($searchFields[$moduleName])) { continue; } if ($class == 'aCase') { $class = 'Case'; } foreach ($searchFields[$moduleName] as $k => $v) { $keep = false; $searchFields[$moduleName][$k]['value'] = $query; if (!empty($GLOBALS['dictionary'][$class]['unified_search'])) { if (empty($GLOBALS['dictionary'][$class]['fields'][$k]['unified_search'])) { if (isset($searchFields[$moduleName][$k]['db_field'])) { foreach ($searchFields[$moduleName][$k]['db_field'] as $field) { if (!empty($GLOBALS['dictionary'][$class]['fields'][$field]['unified_search'])) { $return_fields[] = $field; $keep = true; } } } if (!$keep) { if (strpos($k, 'email') === false || !$searchEmail) { unset($searchFields[$moduleName][$k]); } } } else { $return_fields[] = $k; } } else { if (empty($GLOBALS['dictionary'][$class]['fields'][$k])) { unset($searchFields[$moduleName][$k]); } else { switch ($GLOBALS['dictionary'][$class]['fields'][$k]['type']) { case 'id': case 'date': case 'datetime': case 'bool': unset($searchFields[$moduleName][$k]); default: $return_fields[] = $k; } } } } $searchForm = new SearchForm($seed, $moduleName); $searchForm->setup(array($moduleName => array()), $searchFields, '', 'saved_views'); $where_clauses = $searchForm->generateSearchWhere(); $where = ""; if (count($where_clauses) > 0) { $where = '((' . implode(' ) OR ( ', $where_clauses) . '))'; } $lvd = new ListViewData(); $lvd->additionalDetails = false; $max = !empty($sugar_config['max_spotresults_initial']) ? $sugar_config['max_spotresults_initial'] : 5; if ($offset !== -1) { $max = !empty($sugar_config['max_spotresults_more']) ? $sugar_config['max_spotresults_more'] : 20; } $params = array(); if ($moduleName == 'Reports') { $params['overrideOrder'] = true; $params['orderBy'] = 'name'; } $results[$moduleName] = $lvd->getListViewData($seed, $where, $offset, $max, $return_fields, $params, 'id'); } return $results; }
function search() { if (!file_exists($GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php')) { $this->buildCache(); } include $GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php'; require_once 'include/ListView/ListViewSmarty.php'; global $modListHeader, $beanList, $beanFiles, $current_language, $app_strings, $current_user, $mod_strings; $home_mod_strings = return_module_language($current_language, 'Home'); $overlib = true; $_REQUEST['query_string'] = $GLOBALS['db']->quote(securexss(from_html(clean_string($_REQUEST['query_string'], 'UNIFIED_SEARCH')))); if (!empty($_REQUEST['advanced']) && $_REQUEST['advanced'] != 'false') { $modules_to_search = array(); foreach ($_REQUEST as $param => $value) { if (preg_match('/^search_mod_(.*)$/', $param, $match)) { $modules_to_search[$match[1]] = $beanList[$match[1]]; } } $current_user->setPreference('globalSearch', $modules_to_search, 0, 'search'); // save selections to user preference } else { $users_modules = $current_user->getPreference('globalSearch', 'search'); if (isset($users_modules)) { // use user's previous selections $modules_to_search = $users_modules; } else { // select all the modules (ie first time user has used global search) foreach ($unified_search_modules as $module => $data) { $modules_to_search[$module] = $beanList[$module]; } $current_user->setPreference('globalSearch', $modules_to_search, 'search'); } } echo $this->getDropDownDiv('modules/Home/UnifiedSearchAdvancedForm.tpl'); $module_results = array(); $module_counts = array(); $has_results = false; if (!empty($_REQUEST['query_string'])) { // MFH BUG 15404: Added support to trim off whitespace at the beginning and end of a search string $_REQUEST['query_string'] = trim($_REQUEST['query_string']); foreach ($modules_to_search as $moduleName => $beanName) { if (array_key_exists($moduleName, $modListHeader)) { $unifiedSearchFields = array(); foreach ($unified_search_modules[$moduleName]['fields'] as $field => $def) { $unifiedSearchFields[$moduleName][$field] = $def; $unifiedSearchFields[$moduleName][$field]['value'] = $_REQUEST['query_string']; } /* * Use searchForm2->generateSearchWhere() to create the search query, as it can generate SQL for the full set of comparisons required * generateSearchWhere() expects to find the search conditions for a field in the 'value' parameter of the searchFields entry for that field */ require_once $beanFiles[$beanName]; $seed = new $beanName(); require_once 'include/SearchForm/SearchForm2.php'; $searchForm = new SearchForm($seed, $moduleName); $searchForm->setup(array($moduleName => array()), $unifiedSearchFields, '', 'saved_views'); $where_clauses = $searchForm->generateSearchWhere(); if (count($where_clauses) > 0) { $where = '(' . implode(' ) OR ( ', $where_clauses) . ')'; } $lv = new ListViewSmarty(); $lv->lvd->additionalDetails = false; $mod_strings = return_module_language($current_language, $seed->module_dir); if (file_exists('custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php')) { require_once 'custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php'; } else { require_once 'modules/' . $seed->module_dir . '/metadata/listviewdefs.php'; } $displayColumns = array(); foreach ($listViewDefs[$seed->module_dir] as $colName => $param) { if (!empty($param['default']) && $param['default'] == true) { $param['url_sort'] = true; //bug 27933 $displayColumns[$colName] = $param; } } if (count($displayColumns) > 0) { $lv->displayColumns = $displayColumns; } else { $lv->displayColumns = $listViewDefs[$seed->module_dir]; } $lv->export = false; $lv->mergeduplicates = false; $lv->multiSelect = false; $lv->delete = false; $lv->select = false; if ($overlib) { $lv->overlib = true; $overlib = false; } else { $lv->overlib = false; } $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, 0, 10); $module_results[$moduleName] = '<br /><br />' . get_form_header($GLOBALS['app_list_strings']['moduleList'][$seed->module_dir] . ' (' . $lv->data['pageData']['offsets']['total'] . ')', '', false); $module_counts[$moduleName] = $lv->data['pageData']['offsets']['total']; if ($lv->data['pageData']['offsets']['total'] == 0) { $module_results[$moduleName] .= '<h2>' . $home_mod_strings['LBL_NO_RESULTS_IN_MODULE'] . '</h2>'; } else { $has_results = true; $module_results[$moduleName] .= $lv->display(false, false); } } } } if ($has_results) { arsort($module_counts); foreach ($module_counts as $name => $value) { echo $module_results[$name]; } } else { echo '<br>'; echo $home_mod_strings['LBL_NO_RESULTS']; echo $home_mod_strings['LBL_NO_RESULTS_TIPS']; } }
function search() { if (!file_exists($GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php')) { $this->buildCache(); } include $GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php'; require_once 'include/ListView/ListViewSmarty.php'; global $modListHeader, $beanList, $beanFiles, $current_language, $app_strings, $current_user, $mod_strings; $home_mod_strings = return_module_language($current_language, 'Home'); $overlib = true; $this->query_string = $GLOBALS['db']->quote(securexss(from_html(clean_string($this->query_string, 'UNIFIED_SEARCH')))); if (!empty($_REQUEST['advanced']) && $_REQUEST['advanced'] != 'false') { $modules_to_search = array(); foreach ($_REQUEST as $param => $value) { if (preg_match('/^search_mod_(.*)$/', $param, $match)) { $modules_to_search[$match[1]] = $beanList[$match[1]]; } } $current_user->setPreference('globalSearch', $modules_to_search, 0, 'search'); // save selections to user preference } else { $users_modules = $current_user->getPreference('globalSearch', 'search'); if (isset($users_modules)) { // use user's previous selections foreach ($users_modules as $key => $value) { if (isset($unified_search_modules[$key])) { $modules_to_search[$key] = $value; } } } else { // select all the modules (ie first time user has used global search) foreach ($unified_search_modules as $module => $data) { if (!empty($data['default'])) { $modules_to_search[$module] = $beanList[$module]; } } } $current_user->setPreference('globalSearch', $modules_to_search, 'search'); } echo $this->getDropDownDiv('modules/Home/UnifiedSearchAdvancedForm.tpl'); $module_results = array(); $module_counts = array(); $has_results = false; if (!empty($this->query_string)) { foreach ($modules_to_search as $moduleName => $beanName) { $unifiedSearchFields = array(); $innerJoins = array(); foreach ($unified_search_modules[$moduleName]['fields'] as $field => $def) { //bug: 34125 we might want to try to use the LEFT JOIN operator instead of the INNER JOIN in the case we are //joining against a field that has not been populated. if (!empty($def['innerjoin'])) { if (empty($def['db_field'])) { continue; } $innerJoins[$field] = $def; $def['innerjoin'] = str_replace('INNER', 'LEFT', $def['innerjoin']); } $unifiedSearchFields[$moduleName][$field] = $def; $unifiedSearchFields[$moduleName][$field]['value'] = $this->query_string; } /* * Use searchForm2->generateSearchWhere() to create the search query, as it can generate SQL for the full set of comparisons required * generateSearchWhere() expects to find the search conditions for a field in the 'value' parameter of the searchFields entry for that field */ require_once $beanFiles[$beanName]; $seed = new $beanName(); require_once 'include/SearchForm/SearchForm2.php'; $searchForm = new SearchForm($seed, $moduleName); $searchForm->setup(array($moduleName => array()), $unifiedSearchFields, '', 'saved_views'); $where_clauses = $searchForm->generateSearchWhere(); //add inner joins back into the where clause $params = array('custom_select' => ""); foreach ($innerJoins as $field => $def) { if (isset($def['db_field'])) { foreach ($def['db_field'] as $dbfield) { $where_clauses[] = $dbfield . " LIKE '" . $this->query_string . "%'"; } $params['custom_select'] .= ", {$dbfield}"; $params['distinct'] = true; //$filterFields[$dbfield] = $dbfield; } } if (count($where_clauses) > 0) { $where = '((' . implode(' ) OR ( ', $where_clauses) . '))'; } $lv = new ListViewSmarty(); $lv->lvd->additionalDetails = false; $mod_strings = return_module_language($current_language, $seed->module_dir); if (file_exists('custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php')) { require_once 'custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php'; } else { require_once 'modules/' . $seed->module_dir . '/metadata/listviewdefs.php'; } if (!isset($listViewDefs) || !isset($listViewDefs[$seed->module_dir])) { continue; } $displayColumns = array(); foreach ($listViewDefs[$seed->module_dir] as $colName => $param) { if (!empty($param['default']) && $param['default'] == true) { $param['url_sort'] = true; //bug 27933 $displayColumns[$colName] = $param; } } if (count($displayColumns) > 0) { $lv->displayColumns = $displayColumns; } else { $lv->displayColumns = $listViewDefs[$seed->module_dir]; } $lv->export = false; $lv->mergeduplicates = false; $lv->multiSelect = false; $lv->delete = false; $lv->select = false; $lv->showMassupdateFields = false; if ($overlib) { $lv->overlib = true; $overlib = false; } else { $lv->overlib = false; } $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, $params, 0, 10); $module_results[$moduleName] = '<br /><br />' . get_form_header($GLOBALS['app_list_strings']['moduleList'][$seed->module_dir] . ' (' . $lv->data['pageData']['offsets']['total'] . ')', '', false); $module_counts[$moduleName] = $lv->data['pageData']['offsets']['total']; if ($lv->data['pageData']['offsets']['total'] == 0) { $module_results[$moduleName] .= '<h2>' . $home_mod_strings['LBL_NO_RESULTS_IN_MODULE'] . '</h2>'; } else { $has_results = true; $module_results[$moduleName] .= $lv->display(false, false); } } } if ($has_results) { arsort($module_counts); foreach ($module_counts as $name => $value) { echo $module_results[$name]; } } else { echo '<br>'; echo $home_mod_strings['LBL_NO_RESULTS']; echo $home_mod_strings['LBL_NO_RESULTS_TIPS']; } }
/** * Given a list of modules to search and a search string, return the id, module_name, along with the fields * We will support Accounts, Bug Tracker, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes * * @param string $session - Session ID returned by a previous call to login. * @param string $search_string - string to search * @param string[] $modules - array of modules to query * @param int $offset - a specified offset in the query * @param int $max_results - max number of records to return * @return Array 'entry_list' -- Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do'))) * @exception 'SoapFault' -- The SOAP error, if any */ function search_by_module($session, $search_string, $modules, $offset, $max_results) { $GLOBALS['log']->info('Begin: SugarWebServiceImpl->search_by_module'); global $beanList, $beanFiles; global $sugar_config, $current_language; $error = new SoapError(); $output_list = array(); if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) { $error->set_error('invalid_login'); $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module'); return; } global $current_user; if ($max_results > 0) { $sugar_config['list_max_entries_per_page'] = $max_results; } require_once 'modules/Home/UnifiedSearchAdvanced.php'; require_once 'include/utils.php'; $usa = new UnifiedSearchAdvanced(); if (!file_exists($cachedfile = sugar_cached('modules/unified_search_modules.php'))) { $usa->buildCache(); } include $cachedfile; $modules_to_search = array(); $unified_search_modules['Users'] = array('fields' => array()); $unified_search_modules['ProjectTask'] = array('fields' => array()); foreach ($unified_search_modules as $module => $data) { if (in_array($module, $modules)) { $modules_to_search[$module] = $beanList[$module]; } // if } // foreach $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string); if (!empty($search_string) && isset($search_string)) { $search_string = trim($GLOBALS['db']->quote(securexss(from_html(clean_string($search_string, 'UNIFIED_SEARCH'))))); foreach ($modules_to_search as $name => $beanName) { $where_clauses_array = array(); $unifiedSearchFields = array(); foreach ($unified_search_modules[$name]['fields'] as $field => $def) { $unifiedSearchFields[$name][$field] = $def; $unifiedSearchFields[$name][$field]['value'] = $search_string; } $seed = BeanFactory::getBean($name); require_once 'include/SearchForm/SearchForm2.php'; if ($beanName == "User" || $beanName == "ProjectTask") { if (!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')) { continue; } // if if (!$seed->ACLAccess('ListView')) { continue; } // if } if ($beanName != "User" && $beanName != "ProjectTask") { $searchForm = new SearchForm($seed, $name); $searchForm->setup(array($name => array()), $unifiedSearchFields, '', 'saved_views'); $where_clauses = $searchForm->generateSearchWhere(); require_once 'include/SearchForm/SearchForm2.php'; $searchForm = new SearchForm($seed, $name); $searchForm->setup(array($name => array()), $unifiedSearchFields, '', 'saved_views'); $where_clauses = $searchForm->generateSearchWhere(); $emailQuery = false; $where = ''; if (count($where_clauses) > 0) { $where = '(' . implode(' ) OR ( ', $where_clauses) . ')'; } $mod_strings = return_module_language($current_language, $seed->module_dir); require_once SugarAutoLoader::loadWithMetafiles($seed->module_dir, 'listviewdefs'); $filterFields = array(); foreach ($listViewDefs[$seed->module_dir] as $colName => $param) { if (!empty($param['default']) && $param['default'] == true) { $filterFields[] = strtolower($colName); } // if } // foreach if (!in_array('id', $filterFields)) { $filterFields[] = 'id'; } // if $ret_array = $seed->create_new_list_query('', $where, $filterFields, array(), 0, '', true, $seed, true); if (empty($params) or !is_array($params)) { $params = array(); } if (!isset($params['custom_select'])) { $params['custom_select'] = ''; } if (!isset($params['custom_from'])) { $params['custom_from'] = ''; } if (!isset($params['custom_where'])) { $params['custom_where'] = ''; } if (!isset($params['custom_order_by'])) { $params['custom_order_by'] = ''; } $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by']; } else { if ($beanName == "User") { // $search_string gets cleaned above, so we can use it here $filterFields = array('id', 'user_name', 'first_name', 'last_name', 'email_address'); $main_query = "select users.id, ea.email_address, users.user_name, first_name, last_name from users "; $main_query = $main_query . " LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_module = '{$seed->module_dir}'\nLEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) "; $main_query = $main_query . "where ((users.first_name like '{$search_string}') or (users.last_name like '{$search_string}') or (users.user_name like '{$search_string}') or (ea.email_address like '{$search_string}')) and users.deleted = 0 and users.is_group = 0 and users.employee_status = 'Active'"; } // if if ($beanName == "ProjectTask") { // $search_string gets cleaned above, so we can use it here $filterFields = array('id', 'name', 'project_id', 'project_name'); $main_query = "select {$seed->table_name}.project_task_id id,{$seed->table_name}.project_id, {$seed->table_name}.name, project.name project_name from {$seed->table_name} "; $seed->add_team_security_where_clause($main_query); $main_query .= "LEFT JOIN teams ON {$seed->table_name}.team_id=teams.id AND (teams.deleted=0) "; $main_query .= "LEFT JOIN project ON {$seed->table_name}.project_id = project.id "; $main_query .= "where {$seed->table_name}.name like '{$search_string}%'"; } // if } // else $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - query = ' . $main_query); if ($max_results < -1) { $result = $seed->db->query($main_query); } else { if ($max_results == -1) { $limit = $sugar_config['list_max_entries_per_page']; } else { $limit = $max_results; } $result = $seed->db->limitQuery($main_query, $offset, $limit + 1); } $rowArray = array(); while ($row = $seed->db->fetchByAssoc($result)) { $nameValueArray = array(); foreach ($filterFields as $field) { $nameValue = array(); if (isset($row[$field])) { $nameValueArray[$field] = self::$helperObject->get_name_value($field, $row[$field]); } // if } // foreach $rowArray[] = $nameValueArray; } // while $output_list[] = array('name' => $name, 'records' => $rowArray); } // foreach $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module'); return array('entry_list' => $output_list); } // if return array('entry_list' => $output_list); }
/** * @see SugarView::display() */ public function display() { global $mod_strings; global $app_list_strings; global $app_strings; global $current_user; global $sugar_config; global $currentModule; $seed = new System(); $searchForm = new SearchForm('Administration', $seed); $admin = Administration::getSettings(); $system_id = 1; if (!empty($admin->settings['system_system_id'])) { $system_id = $admin->settings['system_system_id']; } else { $admin->saveSetting('system', 'system_id', $system_id); } $num_lic_oc = $admin->settings['license_num_lic_oc']; if (!isset($system_id) || empty($system_id)) { $system_id = 1; } $error = ''; $where = 'system_id != ' . $system_id; $row_count = $seed->getEnabledOfflineClients($seed->create_new_list_query("", $where)); if (isset($_REQUEST['view']) && ($_REQUEST['view'] == 'disable' || $_REQUEST['view'] == 'enable')) { if (isset($_REQUEST['system_id'])) { $system = new System(); $system->retrieve($_REQUEST['system_id']); if ($system != null && $system->deleted != 1) { if ($_REQUEST['view'] == 'disable') { $system->status = 'Inactive'; $system->save(); } else { if ($_REQUEST['view'] == 'enable') { if ($row_count == $num_lic_oc) { $error = $mod_strings['ERR_NUM_OFFLINE_CLIENTS_MET']; } else { $system->status = 'Active'; $system->save(); $row_count++; } } } if (!empty($_SESSION['EXCEEDING_OC_LICENSES']) && $_SESSION['EXCEEDING_OC_LICENSES'] == true) { if ($row_count - 1 <= $num_lic_oc) { unset($_SESSION['EXCEEDING_OC_LICENSES']); header('Location: index.php?module=Administration&action=ListViewOfflineClient'); } } } } } $user_name = ''; if (isset($_REQUEST['query'])) { $user_name = isset($_REQUEST['user_name']) ? $_REQUEST['user_name'] : ''; require_once 'modules/Administration/metadata/SearchFields.php'; $searchForm->setup(); $user = BeanFactory::getBean('Users'); $searchForm->populateFromRequest('advanced_search'); $where_clauses = $searchForm->generateSearchWhere(true, "Administration"); $search_where = ""; if (count($where_clauses) > 0) { $search_where = implode(' and ', $where_clauses); } } if (isset($search_where) && !empty($search_where)) { $where .= ' AND ' . $search_where; } echo getClassicModuleTitle("Administration", array("<a href='index.php?module=Administration&action=index'>" . translate('LBL_MODULE_NAME', 'Administration') . "</a>", $mod_strings['LBL_MANAGE_OFFLINE_CLIENT']), false); echo '<div class="listViewBody">'; //now we want to display how many offline clients are currently in use echo "<h4>"; if (!empty($error)) { echo "<span class='error'>{$error}</span><br />"; } if ($row_count == 0) { echo "{$mod_strings['NO_ENABLED_OFFLINE_CLIENTS']}"; } else { echo "{$row_count} of {$num_lic_oc} {$mod_strings['ENABLED_OFFLINE_CLIENTS']}"; } echo "</h4>"; //SEARCH if (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') { $search_form = new Sugar_Smarty(); $search_form->assign("MOD", $mod_strings); $search_form->assign("APP", $app_strings); $search_form->assign("BASIC_SEARCH_PNG", SugarThemeRegistry::current()->getImage('basic_search', 'border="0"', null, null, '.gif', $app_strings['LNK_BASIC_SEARCH'])); if (isset($user_name)) { $search_form->assign("USER_NAME", $user_name); } $search_form->assign("JAVASCRIPT", get_clear_form_js()); $search_form->display('modules/Administration/templates/OfflineClientSearchForm.tpl'); } //SEARCH $ListView = new ListView(); $ListView->initNewXTemplate('modules/Administration/templates/ViewOfflineClients.html', $mod_strings); $ListView->xTemplateAssign("RETURN_URL", "&return_module=" . $currentModule . "&return_action=ListView"); $ListView->xTemplateAssign("DELETE_INLINE_PNG", SugarThemeRegistry::current()->getImage('delete_inline', 'align="absmiddle" border="0"', null, null, '.gif', "{SYSTEM.LBL_DISABLE}")); $ListView->setQuery($where, "", "system_key", "SYSTEM"); $ListView->show_export_button = false; $ListView->show_mass_update_form = true; $ListView->show_delete_button = false; $ListView->show_select_menu = false; $ListView->show_mass_update = false; $ListView->processListView($seed, "main", "SYSTEM"); echo '</div>'; }
function display() { if (!$this->bean->ACLAccess('list')) { ACLController::displayNoAccess(); return; } $module = $GLOBALS['module']; $metadataFile = SugarAutoLoader::loadWithMetafiles($module, 'listviewdefs'); require_once $metadataFile; $this->bean->ACLFilterFieldList($listViewDefs[$module], array("owner_override" => true)); $seed = $this->bean; if (!empty($this->bean->object_name) && isset($_REQUEST[$module . '2_' . strtoupper($this->bean->object_name) . '_offset'])) { //if you click the pagination button, it will populate the search criteria here if (!empty($_REQUEST['current_query_by_page'])) { //The code support multi browser tabs pagination $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'request_data', 'current_query_by_page', $module . '2_' . strtoupper($this->bean->object_name) . '_ORDER_BY'); if (isset($_REQUEST['lvso'])) { $blockVariables[] = 'lvso'; } $current_query_by_page = unserialize(base64_decode($_REQUEST['current_query_by_page'])); foreach ($current_query_by_page as $search_key => $search_value) { if ($search_key != $module . '2_' . strtoupper($this->bean->object_name) . '_offset' && !in_array($search_key, $blockVariables)) { if (!is_array($search_value)) { $_REQUEST[$search_key] = $GLOBALS['db']->quote($search_value); } else { foreach ($search_value as $key => &$val) { $val = $GLOBALS['db']->quote($val); } $_REQUEST[$search_key] = $search_value; } } } } } if (!empty($_REQUEST['saved_search_select']) && $_REQUEST['saved_search_select'] != '_none') { if (empty($_REQUEST['button']) && (empty($_REQUEST['clear_query']) || $_REQUEST['clear_query'] != 'true')) { $this->saved_search = BeanFactory::getBean('SavedSearch'); $this->saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']); $this->saved_search->populateRequest(); } elseif (!empty($_REQUEST['button'])) { // click the search button, after retrieving from saved_search $_SESSION['LastSavedView'][$_REQUEST['module']] = ''; unset($_REQUEST['saved_search_select']); unset($_REQUEST['saved_search_select_name']); } } $lv = new ListViewSmarty(); $displayColumns = array(); if (!empty($_REQUEST['displayColumns'])) { foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) { if (!empty($listViewDefs[$module][$col])) { $displayColumns[$col] = $listViewDefs[$module][$col]; } } } else { foreach ($listViewDefs[$module] as $col => $params) { if (!empty($params['default']) && $params['default']) { $displayColumns[$col] = $params; } } } $params = array('massupdate' => true, 'export' => true); if (!empty($_REQUEST['orderBy'])) { $params['orderBy'] = $_REQUEST['orderBy']; $params['overrideOrder'] = true; if (!empty($_REQUEST['sortOrder'])) { $params['sortOrder'] = $_REQUEST['sortOrder']; } } $lv->displayColumns = $displayColumns; $this->seed = $seed; $this->module = $module; $searchForm = null; $storeQuery = new StoreQuery(); if (!isset($_REQUEST['query'])) { $storeQuery->loadQuery($this->module); $storeQuery->populateRequest(); } else { $storeQuery->saveFromRequest($this->module); } //search $view = 'basic_search'; if (!empty($_REQUEST['search_form_view'])) { $view = $_REQUEST['search_form_view']; } $headers = true; if (!empty($_REQUEST['search_form_only']) && $_REQUEST['search_form_only']) { $headers = false; } elseif (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') { if (isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') { $view = 'advanced_search'; } else { $view = 'basic_search'; } } $use_old_search = true; if (SugarAutoLoader::existing('modules/' . $this->module . '/SearchForm.html')) { require_once 'include/SearchForm/SearchForm.php'; $searchForm = new SearchForm($this->module, $this->seed); } else { $use_old_search = false; require_once 'include/SearchForm/SearchForm2.php'; $defs = SugarAutoLoader::loadWithMetafiles($this->module, 'searchdefs'); if (!empty($defs)) { require $defs; } $searchFields = SugarAutoLoader::loadSearchFields($this->module); $searchForm = new SearchForm($this->seed, $this->module, $this->action); $searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl', $view, $listViewDefs); $searchForm->lv = $lv; } if (isset($this->options['show_title']) && $this->options['show_title']) { $moduleName = isset($this->seed->module_dir) ? $this->seed->module_dir : $GLOBALS['mod_strings']['LBL_MODULE_NAME']; echo getClassicModuleTitle($moduleName, array($GLOBALS['mod_strings']['LBL_MODULE_TITLE']), FALSE); } $where = ''; if (isset($_REQUEST['query'])) { // we have a query if (!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) { // from EditView cancel $searchForm->populateFromArray($storeQuery->query); } else { $searchForm->populateFromRequest(); } $where_clauses = $searchForm->generateSearchWhere(true, $this->seed->module_dir); if (count($where_clauses) > 0) { $where = '(' . implode(' ) AND ( ', $where_clauses) . ')'; } $GLOBALS['log']->info("List View Where Clause: {$where}"); } if ($use_old_search) { switch ($view) { case 'basic_search': $searchForm->setup(); $searchForm->displayBasic($headers); break; case 'advanced_search': $searchForm->setup(); $searchForm->displayAdvanced($headers); break; case 'saved_views': echo $searchForm->displaySavedViews($listViewDefs, $lv, $headers); break; } } else { echo $searchForm->display($headers); } if (!$headers) { return; } /* * Bug 50575 - related search columns not inluded in query in a proper way */ $lv->searchColumns = $searchForm->searchColumns; if (isset($GLOBALS['mod_strings']['LBL_MODULE_NAME_SINGULAR'])) { $seed->module_title = $GLOBALS['mod_strings']['LBL_MODULE_NAME_SINGULAR']; } if (isset($GLOBALS['mod_strings']['LBL_LIST_PARENT_NAME'])) { $seed->parent_title = $GLOBALS['mod_strings']['LBL_LIST_PARENT_NAME']; $seed->parent_module_dir = 'Project'; } $project = BeanFactory::getBean('Project'); $project_query = new SugarQuery(); $project_query->from($project); $project_list = $project->fetchFromQuery($project_query); if (count($project_list)) { $seed->show_link = true; } if (empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false) { //Bug 58841 - mass update form was not displayed for non-admin users that should have access if (ACLController::checkAccess($module, 'massupdate') || ACLController::checkAccess($module, 'export')) { $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, $params); } else { $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', $where, $params); } echo $lv->display(); } }
/** * Given a list of modules to search and a search string, return the id, module_name, along with the fields * We will support Accounts, Bug Tracker, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes * * @param string $session - Session ID returned by a previous call to login. * @param string $search_string - string to search * @param string[] $modules - array of modules to query * @param int $offset - a specified offset in the query * @param int $max_results - max number of records to return * @param string $assigned_user_id - a user id to filter all records by, leave empty to exclude the filter * @param string[] $select_fields - An array of fields to return. If empty the default return fields will be from the active list view defs. * @param bool $unified_search_only - A boolean indicating if we should only search against those modules participating in the unified search. * @param bool $favorites - A boolean indicating if we should only search against records marked as favorites. * @return Array return_search_result - Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do'))) * @exception 'SoapFault' -- The SOAP error, if any */ function search_by_module($session, $search_string, $modules, $offset, $max_results, $assigned_user_id = '', $select_fields = array(), $unified_search_only = TRUE, $favorites = FALSE) { $GLOBALS['log']->info('Begin: SugarWebServiceImpl->search_by_module'); global $beanList, $beanFiles; global $sugar_config, $current_language; $error = new SoapError(); $output_list = array(); if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) { $error->set_error('invalid_login'); $GLOBALS['log']->error('End: SugarWebServiceImpl->search_by_module - FAILED on checkSessionAndModuleAccess'); return; } global $current_user; if ($max_results > 0) { $sugar_config['list_max_entries_per_page'] = $max_results; } require_once 'modules/Home/UnifiedSearchAdvanced.php'; require_once 'include/utils.php'; $usa = new UnifiedSearchAdvanced(); if (!file_exists($cachefile = sugar_cached('modules/unified_search_modules.php'))) { $usa->buildCache(); } include $cachefile; $modules_to_search = array(); $unified_search_modules['Users'] = array('fields' => array()); $unified_search_modules['ProjectTask'] = array('fields' => array()); //If we are ignoring the unified search flag within the vardef we need to re-create the search fields. This allows us to search //against a specific module even though it is not enabled for the unified search within the application. if (!$unified_search_only) { foreach ($modules as $singleModule) { if (!isset($unified_search_modules[$singleModule])) { $newSearchFields = array('fields' => self::$helperObject->generateUnifiedSearchFields($singleModule)); $unified_search_modules[$singleModule] = $newSearchFields; } } } foreach ($unified_search_modules as $module => $data) { if (in_array($module, $modules)) { $modules_to_search[$module] = $beanList[$module]; } // if } // foreach $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string); if (!empty($search_string) && isset($search_string)) { $search_string = trim($GLOBALS['db']->quote(securexss(from_html(clean_string($search_string, 'UNIFIED_SEARCH'))))); foreach ($modules_to_search as $name => $beanName) { $where_clauses_array = array(); $unifiedSearchFields = array(); foreach ($unified_search_modules[$name]['fields'] as $field => $def) { $unifiedSearchFields[$name][$field] = $def; $unifiedSearchFields[$name][$field]['value'] = $search_string; } require_once $beanFiles[$beanName]; $seed = new $beanName(); require_once 'include/SearchForm/SearchForm2.php'; if ($beanName == "User" || $beanName == "ProjectTask") { if (!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')) { continue; } // if if (!$seed->ACLAccess('ListView')) { continue; } // if } if ($beanName != "User" && $beanName != "ProjectTask") { $searchForm = new SearchForm($seed, $name); $searchForm->setup(array($name => array()), $unifiedSearchFields, '', 'saved_views'); $where_clauses = $searchForm->generateSearchWhere(); require_once 'include/SearchForm/SearchForm2.php'; $searchForm = new SearchForm($seed, $name); $searchForm->setup(array($name => array()), $unifiedSearchFields, '', 'saved_views'); $where_clauses = $searchForm->generateSearchWhere(); $emailQuery = false; $where = ''; if (count($where_clauses) > 0) { $where = '(' . implode(' ) OR ( ', $where_clauses) . ')'; } $mod_strings = return_module_language($current_language, $seed->module_dir); if (count($select_fields) > 0) { $filterFields = $select_fields; } else { if (file_exists('custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php')) { require_once 'custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php'; } else { require_once 'modules/' . $seed->module_dir . '/metadata/listviewdefs.php'; } $filterFields = array(); foreach ($listViewDefs[$seed->module_dir] as $colName => $param) { if (!empty($param['default']) && $param['default'] == true) { $filterFields[] = strtolower($colName); } } if (!in_array('id', $filterFields)) { $filterFields[] = 'id'; } } //Pull in any db fields used for the unified search query so the correct joins will be added $selectOnlyQueryFields = array(); foreach ($unifiedSearchFields[$name] as $field => $def) { if (isset($def['db_field']) && !in_array($field, $filterFields)) { $filterFields[] = $field; $selectOnlyQueryFields[] = $field; } } //Add the assigned user filter if applicable if (!empty($assigned_user_id) && isset($seed->field_defs['assigned_user_id'])) { $ownerWhere = $seed->getOwnerWhere($assigned_user_id); $where = "({$where}) AND {$ownerWhere}"; } if ($beanName == "Employee") { $where = "({$where}) AND users.deleted = 0 AND users.is_group = 0 AND users.employee_status = 'Active'"; } $list_params = array(); $ret_array = $seed->create_new_list_query('', $where, $filterFields, $list_params, 0, '', true, $seed, true); if (empty($params) or !is_array($params)) { $params = array(); } if (!isset($params['custom_select'])) { $params['custom_select'] = ''; } if (!isset($params['custom_from'])) { $params['custom_from'] = ''; } if (!isset($params['custom_where'])) { $params['custom_where'] = ''; } if (!isset($params['custom_order_by'])) { $params['custom_order_by'] = ''; } $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by']; } else { if ($beanName == "User") { $filterFields = array('id', 'user_name', 'first_name', 'last_name', 'email_address'); $main_query = "select users.id, ea.email_address, users.user_name, first_name, last_name from users "; $main_query = $main_query . " LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_module = '{$seed->module_dir}'\n LEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) "; $main_query = $main_query . "where ((users.first_name like '{$search_string}') or (users.last_name like '{$search_string}') or (users.user_name like '{$search_string}') or (ea.email_address like '{$search_string}')) and users.deleted = 0 and users.is_group = 0 and users.employee_status = 'Active'"; } // if if ($beanName == "ProjectTask") { $filterFields = array('id', 'name', 'project_id', 'project_name'); $main_query = "select {$seed->table_name}.project_task_id id,{$seed->table_name}.project_id, {$seed->table_name}.name, project.name project_name from {$seed->table_name} "; $seed->add_team_security_where_clause($main_query); $main_query .= "LEFT JOIN teams ON {$seed->table_name}.team_id=teams.id AND (teams.deleted=0) "; $main_query .= "LEFT JOIN project ON {$seed->table_name}.project_id = project.id "; $main_query .= "where {$seed->table_name}.name like '{$search_string}%'"; } // if } // else $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - query = ' . $main_query); if ($max_results < -1) { $result = $seed->db->query($main_query); } else { if ($max_results == -1) { $limit = $sugar_config['list_max_entries_per_page']; } else { $limit = $max_results; } $result = $seed->db->limitQuery($main_query, $offset, $limit + 1); } $rowArray = array(); while ($row = $seed->db->fetchByAssoc($result)) { $nameValueArray = array(); foreach ($filterFields as $field) { if (in_array($field, $selectOnlyQueryFields)) { continue; } $nameValue = array(); if (isset($row[$field])) { $nameValueArray[$field] = self::$helperObject->get_name_value($field, $row[$field]); } // if } // foreach $rowArray[] = $nameValueArray; } // while $output_list[] = array('name' => $name, 'records' => $rowArray); } // foreach $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module'); return array('entry_list' => $output_list); } // if return array('entry_list' => $output_list); }
} if (file_exists('custom/modules/' . $module . '/metadata/searchdefs.php')) { require_once 'custom/modules/' . $module . '/metadata/searchdefs.php'; } elseif (!empty($metafiles[$module]['searchdefs'])) { require_once $metafiles[$module]['searchdefs']; } elseif (file_exists('modules/' . $module . '/metadata/searchdefs.php')) { require_once 'modules/' . $module . '/metadata/searchdefs.php'; } if (!empty($metafiles[$module]['searchfields'])) { require_once $metafiles[$module]['searchfields']; } elseif (file_exists('modules/' . $module . '/metadata/SearchFields.php')) { require_once 'modules/' . $module . '/metadata/SearchFields.php'; } if (!empty($searchdefs) && !empty($searchFields)) { $searchForm = new SearchForm($seed, $module); $searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl'); $searchForm->populateFromArray($current_query_by_page_array, 'advanced'); $where_clauses_arr = $searchForm->generateSearchWhere(true, $module); if (count($where_clauses_arr) > 0) { $where_clauses = '(' . implode(' ) AND ( ', $where_clauses_arr) . ')'; } } $ret_array = create_export_query_relate_link_patch($module, $searchFields, $where_clauses); $query = $seed->create_export_query($order_by, $ret_array['where'], $ret_array['join']); $result = $GLOBALS['db']->query($query, true); $uids = array(); while ($val = $GLOBALS['db']->fetchByAssoc($result, false)) { array_push($uids, $val['id']); } $_REQUEST['subpanel_id'] = $uids; }
$params = array('massupdate' => true); // setup ListViewSmarty params if (!empty($_REQUEST['orderBy'])) { // order by coming from $_REQUEST $params['orderBy'] = $_REQUEST['orderBy']; $params['overrideOrder'] = true; if (!empty($_REQUEST['sortOrder'])) { $params['sortOrder'] = $_REQUEST['sortOrder']; } } $lv->displayColumns = $displayColumns; if (!empty($_REQUEST['search_form_only']) && $_REQUEST['search_form_only']) { // handle ajax requests for search forms only switch ($_REQUEST['search_form_view']) { case 'basic_search': $searchForm->setup(); $searchForm->displayBasic(false); break; case 'advanced_search': $searchForm->setup(); $searchForm->displayAdvanced(false); break; case 'saved_views': echo $searchForm->displaySavedViews($listViewDefs, $lv, false); break; } return; } // use the stored query if there is one if (!isset($where)) { $where = "";
/** * search * * Search function run when user goes to Show All and runs a search again. This outputs the search results * calling upon the various listview display functions for each module searched on. * * Todo: Sync this up with SugarSpot.php search method. * * */ function search() { $unified_search_modules = $this->getUnifiedSearchModules(); $unified_search_modules_display = $this->getUnifiedSearchModulesDisplay(); require_once 'include/ListView/ListViewSmarty.php'; global $modListHeader, $beanList, $beanFiles, $current_language, $app_strings, $current_user, $mod_strings; $home_mod_strings = return_module_language($current_language, 'Home'); $overlib = true; $this->query_string = $GLOBALS['db']->quote(securexss(from_html(clean_string($this->query_string, 'UNIFIED_SEARCH')))); if (!empty($_REQUEST['advanced']) && $_REQUEST['advanced'] != 'false') { $modules_to_search = array(); if (!empty($_REQUEST['search_modules'])) { foreach (explode(',', $_REQUEST['search_modules']) as $e) { $modules_to_search[$e] = $beanList[$e]; } } $current_user->setPreference('showGSDiv', isset($_REQUEST['showGSDiv']) ? $_REQUEST['showGSDiv'] : 'no', 0, 'search'); $current_user->setPreference('globalSearch', $modules_to_search, 0, 'search'); // save selections to user preference } else { $users_modules = $current_user->getPreference('globalSearch', 'search'); $modules_to_search = array(); if (!empty($users_modules)) { // use user's previous selections foreach ($users_modules as $key => $value) { if (isset($unified_search_modules_display[$key]) && !empty($unified_search_modules_display[$key]['visible'])) { $modules_to_search[$key] = $beanList[$key]; } } } else { foreach ($unified_search_modules_display as $module => $data) { if (!empty($data['visible'])) { $modules_to_search[$module] = $beanList[$module]; } } } $current_user->setPreference('globalSearch', $modules_to_search, 'search'); } $templateFile = 'modules/Home/UnifiedSearchAdvancedForm.tpl'; if (file_exists('custom/' . $templateFile)) { $templateFile = 'custom/' . $templateFile; } echo $this->getDropDownDiv($templateFile); $module_results = array(); $module_counts = array(); $has_results = false; if (!empty($this->query_string)) { foreach ($modules_to_search as $moduleName => $beanName) { require_once $beanFiles[$beanName]; $seed = new $beanName(); $lv = new ListViewSmarty(); $lv->lvd->additionalDetails = false; $mod_strings = return_module_language($current_language, $seed->module_dir); //retrieve the original list view defs and store for processing in case of custom layout changes require 'modules/' . $seed->module_dir . '/metadata/listviewdefs.php'; $orig_listViewDefs = $listViewDefs; if (file_exists('custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php')) { require 'custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php'; } if (!isset($listViewDefs) || !isset($listViewDefs[$seed->module_dir])) { continue; } $unifiedSearchFields = array(); $innerJoins = array(); foreach ($unified_search_modules[$moduleName]['fields'] as $field => $def) { $listViewCheckField = strtoupper($field); //check to see if the field is in listview defs if (empty($listViewDefs[$seed->module_dir][$listViewCheckField]['default'])) { //check to see if field is in original list view defs (in case we are using custom layout defs) if (!empty($orig_listViewDefs[$seed->module_dir][$listViewCheckField]['default'])) { //if we are here then the layout has been customized, but the field is still needed for query creation $listViewDefs[$seed->module_dir][$listViewCheckField] = $orig_listViewDefs[$seed->module_dir][$listViewCheckField]; } } //bug: 34125 we might want to try to use the LEFT JOIN operator instead of the INNER JOIN in the case we are //joining against a field that has not been populated. if (!empty($def['innerjoin'])) { if (empty($def['db_field'])) { continue; } $innerJoins[$field] = $def; $def['innerjoin'] = str_replace('INNER', 'LEFT', $def['innerjoin']); } if (isset($seed->field_defs[$field]['type'])) { $type = $seed->field_defs[$field]['type']; if ($type == 'int' && !is_numeric($this->query_string)) { continue; } } $unifiedSearchFields[$moduleName][$field] = $def; $unifiedSearchFields[$moduleName][$field]['value'] = $this->query_string; } /* * Use searchForm2->generateSearchWhere() to create the search query, as it can generate SQL for the full set of comparisons required * generateSearchWhere() expects to find the search conditions for a field in the 'value' parameter of the searchFields entry for that field */ require_once $beanFiles[$beanName]; $seed = new $beanName(); require_once 'include/SearchForm/SearchForm2.php'; $searchForm = new SearchForm($seed, $moduleName); $searchForm->setup(array($moduleName => array()), $unifiedSearchFields, '', 'saved_views'); $where_clauses = $searchForm->generateSearchWhere(); //add inner joins back into the where clause $params = array('custom_select' => ""); foreach ($innerJoins as $field => $def) { if (isset($def['db_field'])) { foreach ($def['db_field'] as $dbfield) { $where_clauses[] = $dbfield . " LIKE '" . $this->query_string . "%'"; } $params['custom_select'] .= ", {$dbfield}"; $params['distinct'] = true; //$filterFields[$dbfield] = $dbfield; } } if (count($where_clauses) > 0) { $where = '((' . implode(' ) OR ( ', $where_clauses) . '))'; } $displayColumns = array(); foreach ($listViewDefs[$seed->module_dir] as $colName => $param) { if (!empty($param['default']) && $param['default'] == true) { $param['url_sort'] = true; //bug 27933 $displayColumns[$colName] = $param; } } if (count($displayColumns) > 0) { $lv->displayColumns = $displayColumns; } else { $lv->displayColumns = $listViewDefs[$seed->module_dir]; } $lv->export = false; $lv->mergeduplicates = false; $lv->multiSelect = false; $lv->delete = false; $lv->select = false; $lv->showMassupdateFields = false; $lv->email = false; if ($overlib) { $lv->overlib = true; $overlib = false; } else { $lv->overlib = false; } $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', $where, $params, 0, 10); $module_results[$moduleName] = '<br /><br />' . get_form_header($GLOBALS['app_list_strings']['moduleList'][$seed->module_dir] . ' (' . $lv->data['pageData']['offsets']['total'] . ')', '', false); $module_counts[$moduleName] = $lv->data['pageData']['offsets']['total']; if ($lv->data['pageData']['offsets']['total'] == 0) { //$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>'; $module_results[$moduleName] .= '<h2>' . $home_mod_strings['LBL_NO_RESULTS_IN_MODULE'] . '</h2>'; } else { $has_results = true; //$module_results[$moduleName] .= "<li class='noBullet' id='whole_subpanel_{$moduleName}'><div id='div_{$moduleName}'>" . $lv->display(false, false) . '</div></li>'; $module_results[$moduleName] .= $lv->display(false, false); } } } if ($has_results) { foreach ($module_counts as $name => $value) { echo $module_results[$name]; } } else { if (empty($_REQUEST['form_only'])) { echo $home_mod_strings['LBL_NO_RESULTS']; echo $home_mod_strings['LBL_NO_RESULTS_TIPS']; } } }