Example #1
0
 public function action_search()
 {
     //set ajax view
     $this->view = 'ajax';
     //get the module
     $module = !empty($_REQUEST['qModule']) ? $_REQUEST['qModule'] : '';
     //lowercase module name
     $lmodule = strtolower($module);
     //get the search term
     $term = !empty($_REQUEST['term']) ? $GLOBALS['db']->quote($_REQUEST['term']) : '';
     //in the case of Campaigns we need to use the related module
     $relModule = !empty($_REQUEST['rel_module']) ? $_REQUEST['rel_module'] : null;
     $max = !empty($_REQUEST['max']) ? $_REQUEST['max'] : 10;
     $order_by = !empty($_REQUEST['order_by']) ? $_REQUEST['order_by'] : $lmodule . ".name";
     $offset = !empty($_REQUEST['offset']) ? $_REQUEST['offset'] : 0;
     $response = array();
     if (!empty($module)) {
         $where = '';
         $deleted = '0';
         $using_cp = false;
         if (!empty($term)) {
             if ($module == 'Contacts' || $module == 'Leads') {
                 $where = $lmodule . ".first_name like '%" . $term . "%' OR " . $lmodule . ".last_name like '%" . $term . "%'";
                 $order_by = $lmodule . ".last_name";
             } else {
                 $where = $lmodule . ".name like '" . $term . "%'";
             }
         }
         if ($module == 'CampaignProspects') {
             $using_cp = true;
             $module = 'Prospects';
             $lmodule = strtolower($relModule);
             $campign_where = $_SESSION['MAILMERGE_WHERE'];
             $where = $lmodule . ".first_name like '%" . $term . "%' OR " . $lmodule . ".last_name like '%" . $term . "%'";
             if ($campign_where) {
                 $where .= " AND " . $campign_where;
             }
             $where .= " AND related_type = #" . $lmodule . "#";
         }
         $seed = BeanFactory::getBean($module);
         if ($using_cp) {
             $fields = array('id', 'first_name', 'last_name');
             $dataList = $seed->retrieveTargetList($where, $fields, $offset, -1, $max, $deleted);
         } else {
             $dataList = $seed->get_list($order_by, $where, $offset, -1, $max, $deleted);
         }
         $list = $dataList['list'];
         $row_count = $dataList['row_count'];
         $output_list = array();
         foreach ($list as $value) {
             $output_list[] = get_return_value($value, $module);
         }
         $response['result'] = array('result_count' => $row_count, 'entry_list' => $output_list);
     }
     $json = getJSONobj();
     $json_response = $json->encode($response, true);
     print $json_response;
 }
Example #2
0
function get_modified_entries($session, $module_name, $ids, $select_fields)
{
    global $beanList, $beanFiles;
    $error = new SoapError();
    $field_list = array();
    $output_list = array();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('field_list' => $field_list, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('field_list' => $field_list, '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('field_list' => $field_list, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    $class_name = $beanList[$module_name];
    require_once $beanFiles[$class_name];
    $seed = new $class_name();
    //rsmith
    $in = '';
    $field_select = '';
    $table_name = $seed->table_name;
    if (isset($ids)) {
        foreach ($ids as $value) {
            if (empty($in)) {
                $in .= "('" . $GLOBALS['db']->quote($value) . "'";
            } else {
                $in .= ",'" . $GLOBALS['db']->quote($value) . "'";
            }
        }
        //end foreach
    }
    $index = 0;
    foreach ($select_fields as $field) {
        if (!isset($seed->field_defs[$field])) {
            continue;
        }
        $field_select .= $table_name . "." . $field;
        if ($index < count($select_fields) - 1) {
            $field_select .= ",";
            $index++;
        }
    }
    //end foreach
    $ids = array();
    //end rsmith
    if (!empty($in)) {
        $in .= ')';
    }
    $ret_array = $seed->create_new_list_query('', "{$table_name}.id IN {$in}", $select_fields, array(), -2, '', 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'];
    $result = $seed->db->query($main_query);
    $xml = '<?xml version="1.0" encoding="utf-8"?><items>';
    while ($row = $seed->db->fetchByAssoc($result)) {
        if (version_compare(phpversion(), '5.0') < 0) {
            $temp = $seed;
        } else {
            $temp = @clone $seed;
        }
        $temp->setupCustomFields($temp->module_dir);
        $temp->loadFromRow($row);
        $temp->fill_in_additional_detail_fields();
        if (isset($temp->emailAddress)) {
            $temp->emailAddress->handleLegacyRetrieve($temp);
        }
        $val = get_return_value($temp, $table_name);
        $xml .= get_name_value_xml($val, $module_name);
    }
    $xml .= "</items>";
    $xml = base64_encode($xml);
    return array('result' => $xml, 'error' => $error->get_soap_array());
}
Example #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());
}
Example #4
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());
}
Example #5
0
function get_altered($module_name, $from_date, $to_date)
{
    $name = strtolower($module_name);
    global $disable_date_format;
    $disable_date_format = true;
    global $sugar_config;
    //$sugar_config['list_max_entries_per_page'] = 1000;
    $seed = BeanFactory::getBean($module_name);
    $table_name = $seed->table_name;
    $removeAutoIncrementFields = false;
    $fieldsToRemove = array();
    if ($module_name == 'Quotes') {
        $removeAutoIncrementFields = true;
        $fieldsToRemove = array('quote_num');
    }
    //rrs bug: 29890 - if record on Offline Client is assigned to a team the user does not have access to
    //then it will not sync to server, but the relationship will.  We will assume the user would like to ignore team
    //level security; however, I have added it as an variable "DISABLE_ROW_LEVEL_SECURITY" to this file (see above) so that it can be changed
    //by the server and synced down.
    $seed->disable_row_level_security = DISABLE_ROW_LEVEL_SECURITY;
    $db = DBManagerFactory::getInstance();
    $where = "{$table_name}.date_modified > {$db->convert($db->quoted($from_date), 'datetime')}";
    $where .= " AND {$table_name}.date_modified <= {$db->convert($db->quoted($to_date), 'datetime')}";
    $response = $seed->get_list('', $where, 0, -1, -1, 2);
    $list = $response['list'];
    $output_list = array();
    $field_list = array();
    foreach ($list as $value) {
        if ($removeAutoIncrementFields) {
            foreach ($fieldsToRemove as $fieldToRemove) {
                unset($value->{$fieldToRemove});
            }
        }
        if (isset($value->emailAddress)) {
            $value->emailAddress->handleLegacyRetrieve($value);
        }
        $output_list[] = get_return_value($value, $module_name);
        if (isset($_SESSION['force_accept_server'])) {
            $output_list[sizeof($output_list) - 1]['resolve'] = $_SESSION['force_accept_server'];
        } else {
            $output_list[sizeof($output_list) - 1]['resolve'] = 0;
        }
    }
    return array('result_count' => sizeof($output_list), 'entry_list' => $output_list);
}
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());
}
function json_get_objects_from_module($request_id, &$params)
{
    global $beanList, $beanFiles, $json, $current_user;
    $module_name = $params[0]['module'];
    $offset = intval($params[0]['offset']);
    $where = $params[0]['where'];
    $max = $params[0]['max'];
    $order_by = $params[0]['order_by'];
    $class_name = $beanList[$module_name];
    require_once $beanFiles[$class_name];
    $seed = new $class_name();
    if ($where == '') {
        $where = '';
    }
    if ($offset == '' || $offset == -1) {
        $offset = 0;
    }
    if ($max == '') {
        $max = 10;
    }
    $deleted = '0';
    $response = $seed->get_list($order_by, $where, $offset, -1, $max, $deleted);
    $list = $response['list'];
    $row_count = $response['row_count'];
    $output_list = array();
    foreach ($list as $value) {
        $output_list[] = get_return_value($value, $module_name);
    }
    $response = array();
    $response['id'] = $request_id;
    $response['result'] = array('result_count' => $row_count, 'entry_list' => $output_list);
    //echo $response['result'];
    $json_response = $json->encode($response);
    //echo $offset;
    print $json_response;
    exit;
}
Example #9
0
function sync_set_entries($session, $module_name, $from_date, $to_date, $sync_entry_list, $deleted)
{
    $name = strtolower($module_name);
    $entry_list = get_decoded($sync_entry_list);
    $status = 0;
    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;
    require_once 'modules/Sync/SyncController.php';
    if (!in_array($module_name, $read_only_override) && !check_modules_access($current_user, $module_name, 'write')) {
        $error->set_error('no_access');
        return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array());
    }
    global $sugar_config;
    $sugar_config['list_max_entries_per_page'] = '-99';
    $conflicts = array();
    $in = '';
    $ids = array();
    foreach ($entry_list as $value) {
        $ids[$value['id']] = $value['id'];
        if ($value['resolve'] == 0) {
            if (empty($in)) {
                $in .= "('" . $GLOBALS['db']->quote($value['id']) . "'";
            } else {
                $in .= ",'" . $GLOBALS['db']->quote($value['id']) . "'";
            }
        }
    }
    $list = array();
    $output_list = array();
    $field_list = array();
    if (!empty($in)) {
        $in .= ')';
        $seed = BeanFactory::getBean($module_name);
        $table_name = $seed->table_name;
        //query for any of the records that have been modified after the fact
        $response = $seed->get_list('', "{$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') . " AND {$table_name}.id IN {$in} ", 0, -1, -1, (int) $deleted);
        $list = $response['list'];
        foreach ($list as $value) {
            $cur = BeanFactory::getBean($module_name, $value->id);
            unset($ids[$value->id]);
            $output_list[] = get_return_value($cur, $module_name);
            if (empty($field_list)) {
                $field_list = get_field_list($value);
            }
        }
    }
    $myoutput = get_encoded($output_list);
    if (empty($list)) {
        foreach ($entry_list as $value) {
            $cur = $seed->getCleanCopy();
            foreach ($value['name_value_list'] as $name_value) {
                $cur->{$name_value}['name'] = $name_value['value'];
            }
            $temp = BeanFactory::getBean($module_name, $cur->id);
            if (empty($tmp)) {
                $cur->new_with_id = true;
            }
            if ($value['resolve'] < 1 || $cur->new_with_id) {
                $cur->update_date_modified = true;
                $cur->update_modified_by = true;
                $cur->date_modified = $to_date;
                if ($cur->deleted != 0) {
                    $cur->mark_deleted($cur->id);
                } else {
                    $cur->save();
                }
            }
        }
        $status = 'success';
    } else {
        $status = 'conflict';
    }
    return array('conflicts' => $myoutput, 'status' => $status, 'ids' => $ids, 'error' => $error->get_soap_array());
}
Example #10
0
function json_get_objects_from_module($request_id, $params)
{
    global $beanList, $beanFiles, $current_user;
    $json = getJSONobj();
    $module_name = $params[0]['module'];
    $offset = intval($params[0]['offset']);
    $where = $params[0]['where'];
    $max = $params[0]['max'];
    $order_by = $params[0]['order_by'];
    $using_cp = false;
    if ($module_name == 'CampaignProspects') {
        $module_name = 'Prospects';
        $using_cp = true;
    }
    $class_name = $beanList[$module_name];
    require_once $beanFiles[$class_name];
    $seed = new $class_name();
    if ($where == '') {
        $where = '';
    }
    if ($offset == '' || $offset == -1) {
        $offset = 0;
    }
    if ($max == '') {
        $max = 10;
    }
    $deleted = '0';
    if ($using_cp) {
        $fields = array('id', 'first_name', 'last_name');
        $response = $seed->retrieveTargetList($where, $fields, $offset, -1, $max, $deleted);
    } else {
        $response = $seed->get_list($order_by, $where, $offset, -1, $max, $deleted);
    }
    $list = $response['list'];
    $row_count = $response['row_count'];
    $output_list = array();
    foreach ($list as $value) {
        $output_list[] = get_return_value($value, $module_name);
    }
    $response = array();
    $response['id'] = $request_id;
    $response['result'] = array('result_count' => $row_count, 'entry_list' => $output_list);
    $json_response = $json->encode($response, true);
    print $json_response;
}
Example #11
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 (!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());
}
Example #12
0
     }
     $dm = gmdate($GLOBALS['timedate']->get_db_date_time_format(), time() - 36000);
     $id = $synccontact_ids[0];
     echo '<br><br>Modifying Local and Through Soap - Should Have Conflict - test sync_set_entries' . $id;
     $current_user = new User();
     $current_user->retrieve('1');
     $contact = new Contact();
     echo 'saving ' . $id;
     $contact->retrieve($id);
     $contact->first_name = 'modifed local';
     $contact->save();
     $contact->retrieve($id);
     $contact->first_name = 'modifed server';
     $timestart = microtime(true);
     $commit = array();
     $commit[] = get_return_value($contact, 'Contacts');
     $commit[0]['resolve'] = 0;
     echo 'RESOLVING ' . $commit[0]['resolve'];
     $commit = get_encoded($commit);
     $result = $soapclient->call('sync_set_entries', array('session' => $session, 'module_name' => 'Contacts', 'from_date' => $dm, 'sync_entry_list' => $commit));
     $diff = microtime(true) - $timestart;
     echo "<b>Time for retrieving the contacts added list is {$diff} </b> <br><br>";
     print_result($result);
 }
 echo '<BR>TESTING NOTES<BR>';
 echo '<br><br><b>Set A Note - set_entry test:</b><BR>';
 $time = $timedate->nowDb();
 $date = $timedate->asDbDate($timedate->getNow()->get("+" + rand(0, 360000) + "seconds"));
 $hour = $timedate->asDbTime($timedate->getNow()->get("+" + rand(0, 360000) + "seconds"));
 $result = $soapclient->call('set_entry', array('session' => $session, 'module_name' => 'Notes', 'name_value_list' => array(array('name' => 'name', 'value' => "{$time} Note {$i}"))));
 $note_id = $result['id'];
/**
 * 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());
}