function filter_field_list(&$field_list, $select_fields, $module_name)
{
    return filter_return_list($field_list, $select_fields, $module_name);
}
Beispiel #2
0
/**
 * Retrieve the collection of notes that are related to a bean.
 *
 * @param String $session -- Session ID returned by a previous call to login.
 * @param String $module_name -- The name of the module to return records from.  This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
 * @param String $module_id -- The ID of the bean that you want to associate the note with
 * @param Array  $select_fields -- A list of the fields to be included in the results. This optional parameter allows for only needed fields to be retrieved.
 * @return Array    'result_count' -- The number of records returned (-1 on error)
 *                  'next_offset' -- The start of the next page (This will always be the previous offset plus the number of rows returned.  It does not indicate if there is additional data unless you calculate that the next_offset happens to be closer than it should be.
 *                  'field_list' -- The vardef information on the selected fields.
 *                  'entry_list' -- The records that were retrieved
 *                  'error' -- The SOAP error, if any
 */
function get_related_notes($session, $module_name, $module_id, $select_fields)
{
    global $beanList, $beanFiles;
    $error = new SoapError();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    global $current_user;
    if (!check_modules_access($current_user, $module_name, 'read')) {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    $class_name = $beanList[$module_name];
    require_once $beanFiles[$class_name];
    $seed = new $class_name();
    $seed->retrieve($module_id);
    if (!$seed->ACLAccess('DetailView')) {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    $list = $seed->get_linked_beans('notes', 'Note', array(), 0, -1, 0);
    $output_list = array();
    $field_list = array();
    foreach ($list as $value) {
        $output_list[] = get_return_value($value, 'Notes');
        if (empty($field_list)) {
            $field_list = get_field_list($value);
        }
    }
    $output_list = filter_return_list($output_list, $select_fields, $module_name);
    $field_list = filter_field_list($field_list, $select_fields, $module_name);
    return array('result_count' => sizeof($output_list), 'next_offset' => 0, 'field_list' => $field_list, 'entry_list' => $output_list, 'error' => $error->get_soap_array());
}
Beispiel #3
0
function portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, $row_offset, $limit)
{
    global $beanList, $beanFiles, $portal_modules;
    $error = new SoapError();
    if (!portal_validate_authenticated($session)) {
        $error->set_error('invalid_session');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($_SESSION['type'] == 'lead') {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($module_name == 'Cases') {
        //if the related cases have not yet been loaded into the session object,
        //then call the methods that will load the cases related to the contact/accounts for this user
        if (!isset($_SESSION['viewable'][$module_name])) {
            //retrieve the contact/account id's for this user
            $c = get_contacts_in();
            $a = get_accounts_in();
            if (!empty($c)) {
                get_cases_in_contacts($c);
            }
            if (!empty($a)) {
                get_cases_in_accounts($a);
            }
        }
        $sugar = new aCase();
        $list = array();
        //if no Cases have been loaded into the session as viewable, then do not issue query, just return empty list
        //issuing a query with no cases loaded in session will return ALL the Cases, which is not a good thing
        if (!empty($_SESSION['viewable'][$module_name])) {
            $list = get_related_list(get_module_in($module_name), new aCase(), $where, $order_by, $row_offset, $limit);
        }
    } else {
        if ($module_name == 'Contacts') {
            $sugar = new Contact();
            $list = get_related_list(get_module_in($module_name), new Contact(), $where, $order_by);
        } else {
            if ($module_name == 'Accounts') {
                $sugar = new Account();
                $list = get_related_list(get_module_in($module_name), new Account(), $where, $order_by);
            } else {
                if ($module_name == 'Bugs') {
                    //if the related bugs have not yet been loaded into the session object,
                    //then call the methods that will load the bugs related to the contact/accounts for this user
                    if (!isset($_SESSION['viewable'][$module_name])) {
                        //retrieve the contact/account id's for this user
                        $c = get_contacts_in();
                        $a = get_accounts_in();
                        if (!empty($c)) {
                            get_bugs_in_contacts($c);
                        }
                        if (!empty($a)) {
                            get_bugs_in_accounts($a);
                        }
                    }
                    $list = array();
                    //if no Bugs have been loaded into the session as viewable, then do not issue query, just return empty list
                    //issuing a query with no bugs loaded in session will return ALL the Bugs, which is not a good thing
                    if (!empty($_SESSION['viewable'][$module_name])) {
                        $list = get_related_list(get_module_in($module_name), new Bug(), $where, $order_by, $row_offset, $limit);
                    }
                } else {
                    if ($module_name == 'KBDocuments') {
                    } else {
                        if ($module_name == 'FAQ') {
                        } else {
                            $error->set_error('no_module_support');
                            return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
                        }
                    }
                }
            }
        }
    }
    $output_list = array();
    $field_list = array();
    foreach ($list as $value) {
        //$loga->fatal("Adding another account to the list");
        $output_list[] = get_return_value($value, $module_name);
        $_SESSION['viewable'][$module_name][$value->id] = $value->id;
        if (empty($field_list)) {
            $field_list = get_field_list($value);
        }
    }
    $output_list = filter_return_list($output_list, $select_fields, $module_name);
    $field_list = filter_field_list($field_list, $select_fields, $module_name);
    return array('result_count' => sizeof($output_list), 'next_offset' => 0, 'field_list' => $field_list, 'entry_list' => $output_list, 'error' => $error->get_soap_array());
}
function portal_get_related_list($session, $module_name, $rel_module, $module_id, $select_fields, $order_by, $offset, $limit)
{
    global $beanList, $beanFiles;
    $error = new SoapError();
    if (!portal_validate_authenticated($session)) {
        $error->set_error('invalid_session');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($_SESSION['type'] == 'lead') {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if (empty($_SESSION['viewable'][$module_name][$module_id])) {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    $list = get_related_in_module("('" . $GLOBALS['db']->quote($module_id) . "')", $module_name, $rel_module, $order_by, $offset, $limit);
    $output_list = array();
    $field_list = array();
    foreach ($list as $value) {
        $output_list[] = get_return_value($value, $rel_module);
        $_SESSION['viewable'][$rel_module][$value->id] = $value->id;
        if (empty($field_list)) {
            $field_list = get_field_list($value, true);
        }
    }
    $output_list = filter_return_list($output_list, $select_fields, $module_name);
    $field_list = filter_field_list($field_list, $select_fields, $module_name);
    return array('result_count' => $list['result_count'], 'next_offset' => 0, 'field_list' => $field_list, 'entry_list' => $output_list, 'error' => $error->get_soap_array());
}
function portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, $row_offset, $limit)
{
    global $beanList, $beanFiles, $portal_modules;
    $error = new SoapError();
    if (!portal_validate_authenticated($session)) {
        $error->set_error('invalid_session');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($_SESSION['type'] == 'lead') {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($module_name == 'Cases') {
        //if the related cases have not yet been loaded into the session object,
        //then call the methods that will load the cases related to the contact/accounts for this user
        if (!isset($_SESSION['viewable'][$module_name])) {
            //retrieve the contact/account id's for this user
            $c = get_contacts_in();
            $a = get_accounts_in();
            if (!empty($c)) {
                get_cases_in_contacts($c);
            }
            if (!empty($a)) {
                get_cases_in_accounts($a);
            }
        }
        $sugar = BeanFactory::getBean('Cases');
        $list = array();
        //if no Cases have been loaded into the session as viewable, then do not issue query, just return empty list
        //issuing a query with no cases loaded in session will return ALL the Cases, which is not a good thing
        if (!empty($_SESSION['viewable'][$module_name])) {
            $list = get_related_list(get_module_in($module_name), BeanFactory::getBean('Cases'), $where, $order_by, $row_offset, $limit);
        }
    } else {
        if ($module_name == 'Contacts') {
            $sugar = BeanFactory::getBean('Contacts');
            $list = get_related_list(get_module_in($module_name), BeanFactory::getBean('Contacts'), $where, $order_by);
        } else {
            if ($module_name == 'Accounts') {
                $sugar = BeanFactory::getBean('Accounts');
                $list = get_related_list(get_module_in($module_name), BeanFactory::getBean('Accounts'), $where, $order_by);
            } else {
                if ($module_name == 'Bugs') {
                    //if the related bugs have not yet been loaded into the session object,
                    //then call the methods that will load the bugs related to the contact/accounts for this user
                    if (!isset($_SESSION['viewable'][$module_name])) {
                        //retrieve the contact/account id's for this user
                        $c = get_contacts_in();
                        $a = get_accounts_in();
                        if (!empty($c)) {
                            get_bugs_in_contacts($c);
                        }
                        if (!empty($a)) {
                            get_bugs_in_accounts($a);
                        }
                    }
                    $list = array();
                    //if no Bugs have been loaded into the session as viewable, then do not issue query, just return empty list
                    //issuing a query with no bugs loaded in session will return ALL the Bugs, which is not a good thing
                    if (!empty($_SESSION['viewable'][$module_name])) {
                        $list = get_related_list(get_module_in($module_name), BeanFactory::getBean('Bugs'), $where, $order_by, $row_offset, $limit);
                    }
                } else {
                    if ($module_name == 'KBDocuments') {
                        $sugar = BeanFactory::getBean('KBDocuments');
                        $sugar->disable_row_level_security = true;
                        $keywords = array();
                        //Check if there was a LIKE or = clause built.  If so, the key/value pairs
                        $where = str_replace("\\'", "<##@comma@##>", $where);
                        if (preg_match_all("/kbdocuments[\\.]([^\\s]*?)[\\s]+(LIKE|=)[\\s]+[\\'](.*?)[%][\\']/si", $where, $matches, PREG_SET_ORDER)) {
                            foreach ($matches as $match) {
                                $value = str_replace("<##@comma@##>", "\\'", $match[3]);
                                $keywords[$match[1]] = $value;
                            }
                        }
                        $where = "";
                        $result = create_portal_list_query($sugar, $order_by, $where, $keywords, $row_offset, $limit);
                        $list = array();
                        while ($row = $sugar->db->fetchByAssoc($result)) {
                            $id = $row['id'];
                            //$list[] = $id;
                            $record = BeanFactory::getBean('KBDocuments', $id, array("disable_row_level_security" => true));
                            $record->fill_in_additional_list_fields();
                            $list[] = $record;
                        }
                    } else {
                        if ($module_name == 'FAQ') {
                            $sugar = BeanFactory::getBean('KBDocuments');
                            preg_match("/kbdocuments.tags[\\s]=[\\s]+[(][\\'](.*?)[\\'][)]/si", $where, $matches);
                            //Use KBDocuments/SearchUtils.php
                            //ToDo: Set Global ID for FAQ somewhere, can't assume it's faq1
                            $list = get_faq_list($matches[1], $sugar);
                        } else {
                            $error->set_error('no_module_support');
                            return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
                        }
                    }
                }
            }
        }
    }
    $output_list = array();
    $field_list = array();
    foreach ($list as $value) {
        $output_list[] = get_return_value($value, $module_name);
        $_SESSION['viewable'][$module_name][$value->id] = $value->id;
        if (empty($field_list)) {
            $field_list = get_field_list($value);
        }
    }
    $output_list = filter_return_list($output_list, $select_fields, $module_name);
    $field_list = filter_field_list($field_list, $select_fields, $module_name);
    return array('result_count' => sizeof($output_list), 'next_offset' => 0, 'field_list' => $field_list, 'entry_list' => $output_list, 'error' => $error->get_soap_array());
}
Beispiel #6
0
function sync_get_entries($session, $module_name, $from_date, $to_date, $offset, $max_results, $select_fields, $query, $deleted)
{
    $name = strtolower($module_name);
    global $current_user;
    $error = new SoapError();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    global $current_user;
    if (!check_modules_access($current_user, $module_name, 'read')) {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($max_results > 0) {
        global $sugar_config;
        $sugar_config['list_max_entries_per_page'] = $max_results;
    }
    $seed = BeanFactory::getBean($module_name);
    if (empty($seed)) {
        $error->set_error('no_module');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($offset == '' || $offset == -1) {
        $offset = 0;
    }
    $table_name = $seed->table_name;
    if (!empty($query)) {
        require_once 'include/SugarSQLValidate.php';
        $valid = new SugarSQLValidate();
        if (!$valid->validateQueryClauses($query)) {
            $GLOBALS['log']->error("Bad query: {$query}");
            $error->set_error('no_access');
            return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
        }
        $query = "( {$query} ) AND ";
    }
    $response = $seed->get_list('', $query . "{$table_name}.date_modified > " . db_convert("'" . $GLOBALS['db']->quote($from_date) . "'", 'datetime') . " AND {$table_name}.date_modified <= " . db_convert("'" . $GLOBALS['db']->quote($to_date) . "'", 'datetime'), $offset, -1, -1, $deleted);
    $output_list = array();
    $field_list = array();
    //now handle updating info on teams who we no longer have access to
    $seed->disable_row_level_security = true;
    if ($seed->is_AuditEnabled() && $offset == 0) {
        //embeded selects would have been better
        $query_team = "SELECT audit_table.parent_id FROM " . $seed->get_audit_table_name() . " audit_table  RIGHT JOIN team_memberships  on team_memberships.deleted = 0 AND team_memberships.team_id = audit_table.before_value_string AND team_memberships.user_id = '{$current_user->id}'  where audit_table.field_name = 'team_id' AND audit_table.date_created > " . db_convert("'" . $GLOBALS['db']->quote($from_date) . "'", 'datetime') . "  AND audit_table.date_created <= " . db_convert("'" . $GLOBALS['db']->quote($to_date) . "'", 'datetime');
        $team_results = $seed->db->query($query_team);
        $team_result_ids = array();
        $team_response = array('list' => array());
        while ($row = $seed->db->fetchByAssoc($team_results)) {
            $team_result_ids[] = $row['parent_id'];
        }
        if (!empty($team_result_ids)) {
            $query = " {$seed->table_name}.id IN ('" . implode("', '", $team_result_ids) . "') ";
            $team_response = $seed->get_list('', $query, 0, -99, -1, $deleted);
        }
        foreach ($team_response['list'] as $value) {
            $output_list[] = get_return_value($value, $module_name, false);
            if (empty($field_list)) {
                $field_list = get_field_list($value);
            }
        }
    }
    $list = $response['list'];
    $total_count = $response['row_count'];
    $next_offset = $response['next_offset'];
    foreach ($list as $value) {
        //bug: 31668 - rrs ensure we are sending back the email address along with the bean when performing a sync.
        if (isset($value->emailAddress)) {
            $value->emailAddress->handleLegacyRetrieve($value);
        }
        $output_list[] = get_return_value($value, $module_name);
        if (empty($field_list)) {
            $field_list = get_field_list($value);
        }
    }
    /* now get the fields that have had there teams changed*/
    $output_list = filter_return_list($output_list, $select_fields, $module_name);
    $field_list = filter_field_list($field_list, $select_fields, $module_name);
    $myfields = get_encoded($field_list);
    $myoutput = get_encoded($output_list);
    return array('result_count' => sizeof($output_list), 'next_offset' => $next_offset, 'total_count' => $total_count, 'field_list' => $field_list, 'entry_list' => $myoutput, 'error' => $error->get_soap_array());
}
function portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, $row_offset, $limit)
{
    global $beanList, $beanFiles, $portal_modules;
    $error = new SoapError();
    if (!portal_validate_authenticated($session)) {
        $error->set_error('invalid_session');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($_SESSION['type'] == 'lead') {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if ($module_name == 'Cases') {
        if (!isset($_SESSION['viewable'][$module_name])) {
            get_cases_in_contacts(get_contacts_in());
            get_cases_in_accounts(get_accounts_in());
        }
        $sugar = new aCase();
        $list = get_related_list(get_module_in($module_name), new aCase(), $where, $order_by, $row_offset, $limit);
    } else {
        if ($module_name == 'Contacts') {
            $sugar = new Contact();
            $list = get_related_list(get_module_in($module_name), new Contact(), $where, $order_by);
        } else {
            if ($module_name == 'Accounts') {
                $sugar = new Account();
                $list = get_related_list(get_module_in($module_name), new Account(), $where, $order_by);
            } else {
                if ($module_name == 'Bugs') {
                    if (!isset($_SESSION['viewable'][$module_name])) {
                        get_bugs_in_contacts(get_contacts_in());
                        get_bugs_in_accounts(get_accounts_in());
                    }
                    $list = get_related_list(get_module_in($module_name), new Bug(), $where, $order_by, $row_offset, $limit);
                } else {
                    if ($module_name == 'KBDocuments') {
                    } else {
                        if ($module_name == 'FAQ') {
                        } else {
                            $error->set_error('no_module_support');
                            return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
                        }
                    }
                }
            }
        }
    }
    $output_list = array();
    $field_list = array();
    foreach ($list as $value) {
        //$loga->fatal("Adding another account to the list");
        $output_list[] = get_return_value($value, $module_name);
        $_SESSION['viewable'][$module_name][$value->id] = $value->id;
        if (empty($field_list)) {
            $field_list = get_field_list($value);
        }
    }
    $output_list = filter_return_list($output_list, $select_fields, $module_name);
    $field_list = filter_field_list($field_list, $select_fields, $module_name);
    return array('result_count' => sizeof($output_list), 'next_offset' => 0, 'field_list' => $field_list, 'entry_list' => $output_list, 'error' => $error->get_soap_array());
}
/**
 * Retrieve a list of object based on provided IDs.
 *
 * @param String $session -- Session ID returned by a previous call to login.
 * @param String $module_name -- The name of the module to return records from.  This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
 * @param Array $ids -- An array of  IDs.
 * @param Array $select_fields -- A list of the fields to be included in the results. This optional parameter allows for only needed fields to be retrieved.
 * @return Array 'field_list' -- Var def information about the returned fields
 *               'entry_list' -- The records that were retrieved
 *               'error' -- The SOAP error, if any
 */
function get_entries($session, $module_name, $ids, $select_fields = null)
{
    global $db;
    $error = new SoapError();
    $field_list = array();
    $output_list = array();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_session');
        return array('field_list' => $field_list, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    $AppUI =& $_SESSION['AppUI'];
    $GLOBALS['AppUI'] = $AppUI;
    $modclass = $AppUI->getModuleClass($module_name);
    if (file_exists($modclass)) {
        include_once $modclass;
    } else {
        $error->set_error('no_module');
        return array('field_list' => $field_list, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    $perms =& $AppUI->acl();
    $canAccess = $perms->checkModule($module_name, 'access');
    $canRead = $perms->checkModule($module_name, 'view');
    $canEdit = $perms->checkModule($module_name, 'edit');
    $canAuthor = $perms->checkModule($module_name, 'add');
    $canDelete = $perms->checkModule($module_name, 'delete');
    $GLOBALS['perms'] = $perms;
    if (!$canRead) {
        $error->set_error('no_access');
        return array('field_list' => $field_list, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    $field_defs = $db->MetaColumns($module_name);
    $_SESSION['field_defs'] = $field_defs;
    $class_name = 'C' . ucfirst(rtrim($module_name, 's'));
    foreach ($ids as $id) {
        $seed = new $class_name();
        $seed->load($id);
        $output_list[] = get_return_value($seed, $module_name);
    }
    if (empty($field_list)) {
        $field_list = get_field_list($field_defs);
    }
    $output_list = filter_return_list($output_list, $select_fields, $module_name);
    $field_list = filter_field_list($field_list, $select_fields, $module_name);
    return array('field_list' => $field_list, 'entry_list' => $output_list, 'error' => $error->get_soap_array());
}