function checkACLAccess($bean, $viewType, $errorObject, $error_key)
{
    if (!$bean->ACLAccess($viewType)) {
        $errorObject->set_error($error_key);
        setFaultObject($errorObject);
        return false;
    }
    // if
    return true;
}
/**
 * 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
}