Ejemplo n.º 1
0
 /**
  * @brief generation of new cache file and search for force_unifiedsearch fields in it
  * @group 42961
  */
 public function testBuildCache()
 {
     $beanList = array();
     $beanFiles = array();
     require 'include/modules.php';
     $GLOBALS['beanList'] = $beanList;
     $GLOBALS['beanFiles'] = $beanFiles;
     $unifiedSearchAdvanced = new UnifiedSearchAdvanced();
     $unifiedSearchAdvanced->buildCache();
     $this->assertFileExists($GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php', 'Here should be cache file with data');
     include $GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php';
     $force_unifiedsearch = 0;
     foreach ($unified_search_modules as $moduleName => $moduleInformation) {
         foreach ($moduleInformation['fields'] as $fieldName => $fieldInformation) {
             if (key_exists('force_unifiedsearch', $fieldInformation)) {
                 $force_unifiedsearch++;
             }
         }
     }
     $this->assertGreaterThan(0, $force_unifiedsearch, 'Here should be fields with force_unifiedsearch key');
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 public function testUnifiedSearchAdvancedBuildCache()
 {
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $usa = new UnifiedSearchAdvanced();
     $usa->buildCache();
     //Assert we could build the file without problems
     $this->assertTrue(file_exists($this->unified_search_modules_file), "Assert {$this->unified_search_modules_file} file was created");
     include $this->unified_search_modules_file;
     $this->assertTrue(isset($unified_search_modules['Bug44030_TestPerson']), "Assert that we have the custom module set in unified_search_modules.php file");
     $this->assertTrue(isset($unified_search_modules['Bug44030_TestPerson']['fields']['email']), "Assert that the email field was set for the custom module");
 }
Ejemplo n.º 4
0
 public function test_update_custom_vardefs_without_searchfields()
 {
     if (!file_exists("custom/{$this->module_dir}/metadata")) {
         mkdir_recursive("custom/{$this->module_dir}/metadata");
     }
     copy("{$this->module_dir}/metadata/SearchFields.php", "custom/{$this->module_dir}/metadata/SearchFields.php");
     unlink("{$this->module_dir}/metadata/SearchFields.php");
     $this->assertTrue(!file_exists("{$this->module_dir}/metadata/SearchFields.php"), 'Assert that we do not have a SearchFields.php file in modules directory');
     $this->assertTrue(file_exists("{$this->module_dir}/vardefs.php"), 'Assert that we have a vardefs.php file');
     require_once 'modules/UpgradeWizard/uw_utils.php';
     add_unified_search_to_custom_modules_vardefs();
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $usa = new UnifiedSearchAdvanced();
     $usa->buildCache();
     $this->assertTrue(file_exists("cache/modules/unified_search_modules.php"), 'Assert that we have a unified_search_modules.php file');
     include 'cache/modules/unified_search_modules.php';
     //echo var_export($unified_search_modules['clabc_Bug36845Test'], true);
     $this->assertTrue(isset($unified_search_modules['clabc_Bug36845Test']), 'Assert that the custom module was added to unified_search_modules.php');
 }
Ejemplo n.º 5
0
 public function test_update_custom_vardefs_without_searchfields()
 {
     unlink("{$this->module_dir}/metadata/SearchFields.php");
     $this->assertTrue(!file_exists("{$this->module_dir}/metadata/SearchFields.php"), 'Assert that we have a SearchFields.php file');
     $this->assertTrue(file_exists("{$this->module_dir}/vardefs.php"), 'Assert that we have a vardefs.php file');
     require_once 'modules/UpgradeWizard/uw_utils.php';
     add_unified_search_to_custom_modules_vardefs();
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $usa = new UnifiedSearchAdvanced();
     $usa->buildCache();
     $this->assertTrue(file_exists(sugar_cached('modules/unified_search_modules.php')), 'Assert that we have a unified_search_modules.php file');
     include sugar_cached('modules/unified_search_modules.php');
     $this->assertTrue(empty($unified_search_modules['clabc_Bug36845Test']), 'Assert that the custom module was not added to unified_search_modules.php');
 }
Ejemplo n.º 6
0
 /**
  * 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);
 }
/**
 * Given a list of modules to search and a search string, return the id, module_name, along with the fields
 * We will support Accounts, Bugs, Calls, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes
 * 
 * @param string $user_name 		- username of the Sugar User
 * @param string $password			- password of the Sugar User
 * @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 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 new_search_by_module($user_name, $password, $search_string, $modules, $offset, $max_results)
{
    global $beanList, $beanFiles;
    global $sugar_config;
    $error = new SoapError();
    $output_list = array();
    if (!validate_user($user_name, $password)) {
        $error->set_error('invalid_login');
        setFaultObject($error);
        return;
    }
    global $current_user;
    if ($max_results > 0) {
        $sugar_config['list_max_entries_per_page'] = $max_results;
    }
    require_once 'modules/Home/UnifiedSearchAdvanced.php';
    $usa = new UnifiedSearchAdvanced();
    if (!file_exists($GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php')) {
        $usa->buildCache();
    }
    include $GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php';
    $modules_to_search = array();
    foreach ($unified_search_modules as $module => $data) {
        if (in_array($module, $modules)) {
            $modules_to_search[$module] = $beanList[$module];
        }
        // if
    }
    // foreach
    if (!empty($search_string) && isset($search_string)) {
        foreach ($modules_to_search as $name => $beanName) {
            $where_clauses_array = array();
            foreach ($unified_search_modules[$name]['fields'] as $field => $def) {
                $clause = '';
                if (isset($def['table'])) {
                    // if field is from joining table
                    $clause = "{$def['table']}.{$def['rname']} ";
                } else {
                    $clause = "{$unified_search_modules[$name]['table']}.{$field} ";
                }
                // else
                switch ($def['type']) {
                    case 'int':
                        if (is_numeric($_REQUEST['query_string'])) {
                            $clause .= "in ('{$_REQUEST['query_string']}')";
                        } else {
                            $clause .= "in ('-1')";
                        }
                        break;
                    default:
                        //MFH BUG 15405 - added support for seaching full names in global search
                        if ($field == 'last_name') {
                            if (strpos($_REQUEST['query_string'], ' ')) {
                                $string = explode(' ', $_REQUEST['query_string']);
                                $clause .= "LIKE '{$string[1]}%'";
                            } else {
                                $clause .= "LIKE '{$_REQUEST['query_string']}%'";
                            }
                        } else {
                            $clause .= "LIKE '{$_REQUEST['query_string']}%'";
                        }
                        break;
                }
                // switch
                array_push($where_clauses_array, $clause);
            }
            // foreach
            $where = '(' . implode(' or ', $where_clauses_array) . ')';
            require_once $beanFiles[$beanName];
            $seed = new $beanName();
            $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';
            }
            $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 (!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'];
            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])) {
                        $nameValue['name'] = $field;
                        $nameValue['value'] = $row[$field];
                        $nameValueArray[] = $nameValue;
                    }
                    // if
                }
                // foreach
                $rowArray[] = $nameValueArray;
            }
            // while
            $output_list[] = array('name' => $name, 'records' => $rowArray);
        }
        // foreach
        return array('entry_list' => $output_list);
    }
    // if
}