public static function retrieveReportsSearchDefs()
 {
     $searchdefs = array();
     $searchFields = array();
     $defs = SugarAutoLoader::loadWithMetafiles('Reports', 'searchdefs');
     if ($defs) {
         require $defs;
     }
     $searchFields = SugarAutoLoader::loadSearchFields('Reports');
     return array('searchdefs' => $searchdefs, 'searchFields' => $searchFields);
 }
Beispiel #2
0
 /**
  * loads SearchFields MetaData, sets member variables
  *
  * @param string $module moduleDir
  * @param bean $seedBean seed bean to use
  * @param string $tpl template to use, defaults to moduleDir/SearchForm.html
  *
  */
 function SearchForm($module, $seedBean, $tpl = null)
 {
     global $app_strings;
     $this->module = $module;
     $searchFields = SugarAutoLoader::loadSearchFields($module);
     $this->searchFields = $searchFields[$module];
     if (empty($tpl)) {
         if (!empty($GLOBALS['layout_edit_mode'])) {
             $this->tpl = sugar_cached('studio/custom/working/modules/' . $module . '/SearchForm.html');
         } else {
             $this->tpl = get_custom_file_if_exists('modules/' . $module . '/SearchForm.html');
         }
     } else {
         $this->tpl = $tpl;
     }
     $this->bean = $seedBean;
     $this->tabs = array(array('title' => $app_strings['LNK_BASIC_SEARCH'], 'link' => $module . '|basic_search', 'key' => $module . '|basic_search'), array('title' => $app_strings['LNK_ADVANCED_SEARCH'], 'link' => $module . '|advanced_search', 'key' => $module . '|advanced_search'));
     if (SugarAutoLoader::fileExists('modules/' . $this->module . '/index.php')) {
         $this->tabs[] = array('title' => $app_strings['LNK_SAVED_VIEWS'], 'link' => $module . '|saved_views', 'key' => $module . '|saved_views');
     }
 }
Beispiel #3
0
 function setup($file)
 {
     if (isset($this->_popupMeta)) {
         if (isset($this->_popupMeta['create']['formBase'])) {
             require_once 'modules/' . $this->seed->module_dir . '/' . $this->_popupMeta['create']['formBase'];
             $this->_create = true;
         }
     }
     if (!empty($this->_popupMeta['create'])) {
         $formBase = new $this->_popupMeta['create']['formBaseClass']();
         if (isset($_REQUEST['doAction']) && $_REQUEST['doAction'] == 'save') {
             //If it's a new record, set useRequired to false
             $useRequired = empty($_REQUEST['id']) ? false : true;
             $formBase->handleSave('', false, $useRequired);
         }
     }
     $params = array();
     if (!empty($this->_popupMeta['orderBy'])) {
         $params['orderBy'] = $this->_popupMeta['orderBy'];
     }
     $searchFields = SugarAutoLoader::loadSearchFields($this->module);
     $this->searchdefs[$this->module]['templateMeta']['maxColumns'] = 2;
     $this->searchdefs[$this->module]['templateMeta']['widths']['label'] = 10;
     $this->searchdefs[$this->module]['templateMeta']['widths']['field'] = 30;
     $this->searchForm->view = 'PopupSearchForm';
     $this->searchForm->setup($this->searchdefs, $searchFields, 'SearchFormGenericAdvanced.tpl', 'advanced_search', $this->listviewdefs);
     $lv = new ListViewSmarty();
     $displayColumns = array();
     if (!empty($_REQUEST['displayColumns'])) {
         foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) {
             if (!empty($listViewDefs[$this->module][$col])) {
                 $displayColumns[$col] = $this->listviewdefs[$this->module][$col];
             }
         }
     } else {
         foreach ($this->listviewdefs[$this->module] as $col => $para) {
             if (!empty($para['default']) && $para['default']) {
                 $displayColumns[$col] = $para;
             }
         }
     }
     $params['massupdate'] = true;
     if (!empty($_REQUEST['orderBy'])) {
         $params['orderBy'] = $_REQUEST['orderBy'];
         $params['overrideOrder'] = true;
         if (!empty($_REQUEST['sortOrder'])) {
             $params['sortOrder'] = $_REQUEST['sortOrder'];
         }
     }
     $lv->displayColumns = $displayColumns;
     $this->searchForm->lv = $lv;
     $this->searchForm->displaySavedSearch = false;
     SugarACL::listFilter($this->module, $this->searchForm->fieldDefs, array("owner_override" => true), array("use_value" => true, "suffix" => '_advanced', "add_acl" => true));
     $this->searchForm->populateFromRequest('advanced_search');
     $searchWhere = $this->_get_where_clause();
     $this->searchColumns = $this->searchForm->searchColumns;
     //parent::setup($this->seed, $file, $searchWhere, $params, 0, -1, $this->filter_fields);
     $this->should_process = true;
     if (isset($params['export'])) {
         $this->export = $params['export'];
     }
     if (!empty($params['multiSelectPopup'])) {
         $this->multi_select_popup = $params['multiSelectPopup'];
     }
     if (!empty($params['massupdate']) && $params['massupdate'] != false) {
         $this->show_mass_update_form = true;
         $this->mass = new MassUpdate();
         $this->mass->setSugarBean($this->seed);
         if (!empty($params['handleMassupdate']) || !isset($params['handleMassupdate'])) {
             $this->mass->handleMassUpdate();
         }
     }
     // create filter fields based off of display columns
     if (empty($this->filter_fields) || $this->mergeDisplayColumns) {
         foreach ($this->displayColumns as $columnName => $def) {
             $this->filter_fields[strtolower($columnName)] = true;
             if (!empty($def['related_fields'])) {
                 foreach ($def['related_fields'] as $field) {
                     //id column is added by query construction function. This addition creates duplicates
                     //and causes issues in oracle. #10165
                     if ($field != 'id') {
                         $this->filter_fields[$field] = true;
                     }
                 }
             }
             if (!empty($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'])) {
                 foreach ($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'] as $index => $field) {
                     if (!isset($this->filter_fields[strtolower($field)]) || !$this->filter_fields[strtolower($field)]) {
                         $this->filter_fields[strtolower($field)] = true;
                     }
                 }
             }
         }
         foreach ($this->searchColumns as $columnName => $def) {
             $this->filter_fields[strtolower($columnName)] = true;
         }
     }
     /**
      * Bug #46842 : The relate field field_to_name_array fails to copy over custom fields
      * By default bean's create_new_list_query function loads fields displayed on the page or used in the search
      * add fields used to populate forms from _viewdefs :: field_to_name_array to retrive from db
      */
     if (isset($_REQUEST['field_to_name']) && $_REQUEST['field_to_name']) {
         $_REQUEST['field_to_name'] = is_array($_REQUEST['field_to_name']) ? $_REQUEST['field_to_name'] : array($_REQUEST['field_to_name']);
         foreach ($_REQUEST['field_to_name'] as $add_field) {
             $add_field = strtolower($add_field);
             if ($add_field != 'id' && !isset($this->filter_fields[$add_field]) && isset($this->seed->field_defs[$add_field])) {
                 $this->filter_fields[$add_field] = true;
             }
         }
     } else {
         if (isset($_REQUEST['request_data'])) {
             $request_data = get_object_vars(json_decode(htmlspecialchars_decode($_REQUEST['request_data'])));
             $request_data['field_to_name'] = get_object_vars($request_data['field_to_name_array']);
             if (isset($request_data['field_to_name']) && is_array($request_data['field_to_name'])) {
                 foreach ($request_data['field_to_name'] as $add_field) {
                     $add_field = strtolower($add_field);
                     if ($add_field != 'id' && !isset($this->filter_fields[$add_field]) && isset($this->seed->field_defs[$add_field])) {
                         $this->filter_fields[$add_field] = true;
                     }
                 }
             }
         }
     }
     //check for team_set_count
     if (!empty($this->filter_fields['team_name']) && empty($this->filter_fields['team_count'])) {
         $this->filter_fields['team_count'] = true;
         $this->displayColumns['TEAM_NAME']['type'] = 'teamset';
         $this->displayColumns['TEAM_NAME']['width'] = '2';
         $this->displayColumns['TEAM_NAME']['label'] = 'LBL_LIST_TEAM';
         unset($this->displayColumns['TEAM_NAME']['link']);
         //Add the team_id entry so that we can retrieve the team_id to display primary team
         $this->filter_fields['team_id'] = true;
     }
     if (!empty($_REQUEST['query']) || !empty($GLOBALS['sugar_config']['save_query']) && $GLOBALS['sugar_config']['save_query'] != 'populate_only') {
         $data = $this->lvd->getListViewData($this->seed, $searchWhere, 0, -1, $this->filter_fields, $params, 'id');
     } else {
         $this->should_process = false;
         $data = array('data' => array(), 'pageData' => array('bean' => array('moduleDir' => $this->seed->module_dir), 'ordering' => '', 'offsets' => array('total' => 0, 'next' => 0, 'current' => 0)));
     }
     $this->fillDisplayColumnsWithVardefs();
     $data = $this->setupHTMLFields($data);
     $this->process($file, $data, $this->seed->object_name);
 }
Beispiel #4
0
function generateSearchWhere($module, $query)
{
    //this function is similar with function prepareSearchForm() in view.list.php
    $seed = BeanFactory::newBean($module);
    if (SugarAutoLoader::fileExists('modules/' . $module . '/SearchForm.html')) {
        if (SugarAutoLoader::fileExists('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.
            // Currently, massupdate will not generate 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';
        $searchdefs_file = SugarAutoLoader::loadWithMetafiles($module, 'searchdefs');
        if ($searchdefs_file) {
            require $searchdefs_file;
        }
        $searchFields = SugarAutoLoader::loadSearchFields($module);
        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 = getSearchForm($seed, $module);
        $searchForm->setup($searchdefs, $searchFields, '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;
}
 /**
  * Generate unifed search fields for a particular module even if the module does not participate in the unified search.
  *
  * @param string $moduleName
  * @return array An array of fields to be searched against.
  */
 function generateUnifiedSearchFields($moduleName)
 {
     global $beanList, $beanFiles, $dictionary;
     if (!isset($beanList[$moduleName])) {
         return array();
     }
     $beanName = $beanList[$moduleName];
     if (!isset($beanFiles[$beanName])) {
         return array();
     }
     $beanName = BeanFactory::getObjectName($moduleName);
     $manager = new VardefManager();
     $manager->loadVardef($moduleName, $beanName);
     // obtain the field definitions used by generateSearchWhere (duplicate code in view.list.php)
     $searchFields = SugarAutoLoader::loadSearchFields($moduleName);
     $fields = array();
     foreach ($dictionary[$beanName]['fields'] as $field => $def) {
         if (strpos($field, 'email') !== false) {
             $field = 'email';
         }
         //bug: 38139 - allow phone to be searched through Global Search
         if (strpos($field, 'phone') !== false) {
             $field = 'phone';
         }
         if (isset($def['unified_search']) && $def['unified_search'] && isset($searchFields[$moduleName][$field])) {
             $fields[$field] = $searchFields[$moduleName][$field];
         }
     }
     //If no fields with the unified flag have been set then lets add a default field.
     if (empty($fields)) {
         if (isset($dictionary[$beanName]['fields']['name']) && isset($searchFields[$moduleName]['name'])) {
             $fields['name'] = $searchFields[$moduleName]['name'];
         } else {
             if (isset($dictionary[$beanName]['fields']['first_name']) && isset($searchFields[$moduleName]['first_name'])) {
                 $fields['first_name'] = $searchFields[$moduleName]['first_name'];
             }
             if (isset($dictionary[$beanName]['fields']['last_name']) && isset($searchFields[$moduleName]['last_name'])) {
                 $fields['last_name'] = $searchFields[$moduleName]['last_name'];
             }
         }
     }
     return $fields;
 }
Beispiel #6
0
 if (!empty($_REQUEST['select_entire_list']) && $_REQUEST['select_entire_list'] != 'undefined' && isset($_REQUEST['current_query_by_page'])) {
     $order_by = '';
     $current_query_by_page = $_REQUEST['current_query_by_page'];
     $current_query_by_page_array = unserialize(base64_decode($current_query_by_page));
     $module = $current_query_by_page_array['module'];
     $seed = BeanFactory::getBean($module);
     if (empty($seed)) {
         sugar_die($GLOBALS['app_strings']['ERROR_NO_BEAN']);
     }
     $where_clauses = '';
     require_once 'include/SearchForm/SearchForm2.php';
     $searchdefs_file = SugarAutoLoader::loadWithMetafiles($module, 'searchdefs');
     if ($searchdefs_file) {
         require $searchdefs_file;
     }
     $searchFields = SugarAutoLoader::loadSearchFields($module);
     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) . ')';
         }
     }
     $query = $seed->create_new_list_query($order_by, $where_clauses);
     $result = $GLOBALS['db']->query($query, true);
     $uids = array();
     while ($val = $GLOBALS['db']->fetchByAssoc($result, false)) {
         array_push($uids, $val['id']);
     }
 function buildCache()
 {
     global $beanList, $beanFiles, $dictionary;
     $supported_modules = array();
     foreach ($beanList as $moduleName => $beanName) {
         if (!isset($beanFiles[$beanName])) {
             continue;
         }
         $beanName = BeanFactory::getObjectName($moduleName);
         $manager = new VardefManager();
         $manager->loadVardef($moduleName, $beanName);
         // obtain the field definitions used by generateSearchWhere (duplicate code in view.list.php)
         $searchFields = SugarAutoLoader::loadSearchFields($moduleName);
         //If there are $searchFields are empty, just continue, there are no search fields defined for the module
         if (empty($searchFields[$moduleName])) {
             continue;
         }
         $isCustomModule = preg_match('/^([a-z0-9]{1,5})_([a-z0-9_]+)$/i', $moduleName);
         //If the bean supports unified search or if it's a custom module bean and unified search is not defined
         if (!empty($dictionary[$beanName]['unified_search']) || $isCustomModule) {
             $fields = array();
             foreach ($dictionary[$beanName]['fields'] as $field => $def) {
                 // We cannot enable or disable unified_search for email in the vardefs as we don't actually have a vardef entry for 'email'
                 // the searchFields entry for 'email' doesn't correspond to any vardef entry. Instead it contains SQL to directly perform the search.
                 // 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
                 if (strpos($field, 'email') !== false) {
                     $field = 'email';
                 }
                 //bug: 38139 - allow phone to be searched through Global Search
                 if (strpos($field, 'phone') !== false) {
                     $field = 'phone';
                 }
                 if (!empty($def['unified_search']) && isset($searchFields[$moduleName][$field])) {
                     $fields[$field] = $searchFields[$moduleName][$field];
                 }
             }
             foreach ($searchFields[$moduleName] as $field => $def) {
                 if (isset($def['force_unifiedsearch']) and $def['force_unifiedsearch']) {
                     $fields[$field] = $def;
                 }
             }
             if (count($fields) > 0) {
                 $supported_modules[$moduleName]['fields'] = $fields;
                 if (isset($dictionary[$beanName]['unified_search_default_enabled']) && $dictionary[$beanName]['unified_search_default_enabled'] === TRUE) {
                     $supported_modules[$moduleName]['default'] = true;
                 } else {
                     $supported_modules[$moduleName]['default'] = false;
                 }
             }
         }
     }
     ksort($supported_modules);
     write_array_to_file('unified_search_modules', $supported_modules, $this->cache_search);
 }
Beispiel #8
0
 /**
  * populateFromPost
  *
  * @see parent::populateFromPost
  * This method checks to see if enable_range_search is set.  If so, ensure that the
  * searchdefs for the module include the additional range fields.
  */
 function populateFromPost()
 {
     parent::populateFromPost();
     //If we are enabling range search, make sure we add the start and end range fields
     if (!empty($this->enable_range_search)) {
         //If range search is enabled, set the options attribute for the dropdown choice selections
         $this->options = $this->type == 'date' || $this->type == 'datetimecombo' || $this->type == 'datetime' ? 'date_range_search_dom' : 'numeric_range_search_dom';
         if (isset($_REQUEST['view_module'])) {
             $module = $_REQUEST['view_module'];
             $searchFields = SugarAutoLoader::loadSearchFields($module);
             $field_name = $this->get_field_name($module, $_REQUEST['name']);
             if (isset($searchFields[$module])) {
                 $field_name_range = 'range_' . $field_name;
                 $field_name_start = 'start_range_' . $field_name;
                 $field_name_end = 'end_range_' . $field_name;
                 $isDateField = $this->type == 'date' || $this->type == 'datetimecombo' || $this->type == 'datetime';
                 $searchFields[$module][$field_name_range] = array('query_type' => 'default', 'enable_range_search' => true);
                 if ($isDateField) {
                     $searchFields[$module][$field_name_range]['is_date_field'] = true;
                 }
                 $searchFields[$module][$field_name_start] = array('query_type' => 'default', 'enable_range_search' => true);
                 if ($isDateField) {
                     $searchFields[$module][$field_name_start]['is_date_field'] = true;
                 }
                 $searchFields[$module][$field_name_end] = array('query_type' => 'default', 'enable_range_search' => true);
                 if ($isDateField) {
                     $searchFields[$module][$field_name_end]['is_date_field'] = true;
                 }
                 if (!file_exists('custom/modules/' . $module . '/metadata/SearchFields.php')) {
                     mkdir_recursive('custom/modules/' . $module . '/metadata');
                 }
                 write_array_to_file("searchFields['{$module}']", $searchFields[$module], 'custom/modules/' . $module . '/metadata/SearchFields.php');
             }
             if (file_exists($cachefile = sugar_cached("modules/{$module}/SearchForm_basic.tpl"))) {
                 unlink($cachefile);
             }
             if (file_exists($cachefile = sugar_cached("modules/{$module}/SearchForm_advanced.tpl"))) {
                 unlink($cachefile);
             }
         }
     } else {
         //Otherwise, try to restore the searchFields to their state prior to being enabled
         if (isset($_REQUEST['view_module'])) {
             $module = $_REQUEST['view_module'];
             if (file_exists('modules/' . $module . '/metadata/SearchFields.php')) {
                 require 'modules/' . $module . '/metadata/SearchFields.php';
             }
             if (file_exists('custom/modules/' . $module . '/metadata/SearchFields.php')) {
                 require 'custom/modules/' . $module . '/metadata/SearchFields.php';
             }
             $field_name = $this->get_field_name($module, $_REQUEST['name']);
             if (isset($searchFields[$module])) {
                 $field_name_range = 'range_' . $field_name;
                 $field_name_start = 'start_range_' . $field_name;
                 $field_name_end = 'end_range_' . $field_name;
                 if (isset($searchFields[$module][$field_name_range])) {
                     unset($searchFields[$module][$field_name_range]);
                 }
                 if (isset($searchFields[$module][$field_name_start])) {
                     unset($searchFields[$module][$field_name_start]);
                 }
                 if (isset($searchFields[$module][$field_name_end])) {
                     unset($searchFields[$module][$field_name_end]);
                 }
                 if (!file_exists('custom/modules/' . $module . '/metadata/SearchFields.php')) {
                     mkdir_recursive('custom/modules/' . $module . '/metadata');
                 }
                 write_array_to_file("searchFields['{$module}']", $searchFields[$module], 'custom/modules/' . $module . '/metadata/SearchFields.php');
             }
             if (file_exists($cachefile = sugar_cached("modules/{$module}/SearchForm_basic.tpl"))) {
                 unlink($cachefile);
             }
             if (file_exists($cachefile = sugar_cached("modules/{$module}/SearchForm_advanced.tpl"))) {
                 unlink($cachefile);
             }
         }
     }
 }
Beispiel #9
0
 protected function getSearchFields($module)
 {
     return SugarAutoLoader::loadSearchFields($module);
 }
Beispiel #10
0
 /**
  * Return the search defs for a particular module.
  *
  * @static
  * @param $module
  */
 public static function retrieveSearchDefs($module)
 {
     $searchFields = SugarAutoLoader::loadSearchFields($module);
     $searchdefs = array();
     $file = SugarAutoLoader::loadWithMetafiles($module, 'searchdefs');
     if ($file) {
         require $file;
     }
     return array('searchdefs' => $searchdefs, 'searchFields' => $searchFields);
 }
Beispiel #11
0
 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();
     }
 }