/**
  * notify
  * Soap implementation to notify the soap clients of a resource management error
  * @param msg String message to possibly display
  */
 public function notify($msg = '')
 {
     header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
     header('Content-Type: text/xml; charset="ISO-8859-1"');
     $error = new SoapError();
     $error->set_error('resource_management_error');
     //Override the description
     $error->description = $msg;
     $this->soapServer->methodreturn = array('result' => $msg, 'error' => $error->get_soap_array());
     $this->soapServer->serialize_return();
     $this->soapServer->send_response();
     sugar_cleanup(true);
 }
 /**
  * This method calls functions on the implementation class and returns the output or Fault object in case of error to client
  *
  * @return unknown
  */
 function serve()
 {
     if (empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])) {
         if (empty($_REQUEST['method'])) {
             echo '<pre>';
             Reflection::export(new ReflectionClass(get_class($this->implementation)));
         } else {
             $er = new SoapError();
             $er->set_error('invalid_call');
             $this->fault($er);
         }
     } else {
         $method = $_REQUEST['method'];
         return $this->implementation->{$method}();
     }
     // else
 }
示例#3
0
 /**
  * This method calls functions on the implementation class and returns the output or Fault object in case of error to client
  *
  * @return unknown
  */
 function serve()
 {
     $GLOBALS['log']->info('Begin: SugarRestSerialize->serve');
     $data = !empty($_REQUEST['rest_data']) ? $_REQUEST['rest_data'] : '';
     if (empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])) {
         $er = new SoapError();
         $er->set_error('invalid_call');
         $this->fault($er);
     } else {
         $method = $_REQUEST['method'];
         $data = unserialize(from_html($data));
         if (!is_array($data)) {
             $data = array($data);
         }
         $GLOBALS['log']->info('End: SugarRestSerialize->serve');
         return call_user_func_array(array($this->implementation, $method), $data);
     }
     // else
 }
示例#4
0
 /**
  * This method calls functions on the implementation class and returns the output or Fault object in case of error to client
  *
  * @return unknown
  */
 function serve()
 {
     if (empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])) {
         if (empty($_REQUEST['method'])) {
             echo '<pre>';
             $reflect = new ReflectionClass(get_class($this->implementation));
             $restWSDL = $reflect->__toString();
             $restWSDL = preg_replace('/@@.*/', "", $restWSDL);
             echo $restWSDL;
         } else {
             $er = new SoapError();
             $er->set_error('invalid_call');
             $this->fault($er);
         }
     } else {
         $method = $_REQUEST['method'];
         return $this->implementation->{$method}();
     }
     // else
 }
示例#5
0
 /**
  * This method calls functions on the implementation class and returns the output or Fault object in case of error to client
  *
  * @return unknown
  */
 function serve()
 {
     $GLOBALS['log']->info('Begin: SugarRestJSON->serve');
     $json_data = !empty($_REQUEST['rest_data']) ? $GLOBALS['RAW_REQUEST']['rest_data'] : '';
     if (empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])) {
         $er = new SoapError();
         $er->set_error('invalid_call');
         $this->fault($er);
     } else {
         $method = $_REQUEST['method'];
         $json = getJSONObj();
         $data = $json->decode($json_data);
         if (!is_array($data)) {
             $data = array($data);
         }
         $res = call_user_func_array(array($this->implementation, $method), $data);
         $GLOBALS['log']->info('End: SugarRestJSON->serve');
         return $res;
     }
     // else
 }
示例#6
0
function handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE)
{
    global $beanList, $beanFiles, $app_list_strings, $current_user;
    $error = new SoapError();
    $ret_values = array();
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('ids' => array(), 'error' => $error->get_soap_array());
    }
    if (!check_modules_access($current_user, $module_name, 'write')) {
        $error->set_error('no_access');
        return array('ids' => -1, 'error' => $error->get_soap_array());
    }
    $class_name = $beanList[$module_name];
    require_once $beanFiles[$class_name];
    $ids = array();
    $count = 1;
    $total = sizeof($name_value_lists);
    foreach ($name_value_lists as $name_value_list) {
        $seed = new $class_name();
        $seed->update_vcal = false;
        //See if we can retrieve the seed by a given id value
        foreach ($name_value_list as $value) {
            if ($value['name'] == 'id') {
                $seed->retrieve($value['value']);
                break;
            }
        }
        $dataValues = array();
        foreach ($name_value_list as $value) {
            $val = $value['value'];
            if ($seed->field_name_map[$value['name']]['type'] == 'enum' || $seed->field_name_map[$value['name']]['type'] == 'radioenum') {
                $vardef = $seed->field_name_map[$value['name']];
                if (isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$val])) {
                    if (in_array($val, $app_list_strings[$vardef['options']])) {
                        $val = array_search($val, $app_list_strings[$vardef['options']]);
                    }
                }
            } else {
                if ($seed->field_name_map[$value['name']]['type'] == 'multienum') {
                    $vardef = $seed->field_name_map[$value['name']];
                    if (isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$value])) {
                        $items = explode(",", $val);
                        $parsedItems = array();
                        foreach ($items as $item) {
                            if (in_array($item, $app_list_strings[$vardef['options']])) {
                                $keyVal = array_search($item, $app_list_strings[$vardef['options']]);
                                array_push($parsedItems, $keyVal);
                            }
                        }
                        if (!empty($parsedItems)) {
                            $val = encodeMultienumValue($parsedItems);
                        }
                    }
                }
            }
            //Apply the non-empty values now since this will be used for duplicate checks
            //allow string or int of 0 to be updated if set.
            if (!empty($val) || ($val === '0' || $val === 0)) {
                $seed->{$value}['name'] = $val;
            }
            //Store all the values in dataValues Array to apply later
            $dataValues[$value['name']] = $val;
        }
        if ($count == $total) {
            $seed->update_vcal = false;
        }
        $count++;
        //Add the account to a contact
        if ($module_name == 'Contacts') {
            $GLOBALS['log']->debug('Creating Contact Account');
            add_create_account($seed);
            $duplicate_id = check_for_duplicate_contacts($seed);
            if ($duplicate_id == null) {
                if ($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))) {
                    //Now apply the values, since this is not a duplicate we can just pass false for the $firstSync argument
                    apply_values($seed, $dataValues, false);
                    $seed->save();
                    if ($seed->deleted == 1) {
                        $seed->mark_deleted($seed->id);
                    }
                    $ids[] = $seed->id;
                }
            } else {
                //since we found a duplicate we should set the sync flag
                if ($seed->ACLAccess('Save')) {
                    //Determine if this is a first time sync.  We find out based on whether or not a contacts_users relationship exists
                    $seed->id = $duplicate_id;
                    $seed->load_relationship("user_sync");
                    $beans = $seed->user_sync->getBeans();
                    $first_sync = empty($beans);
                    //Now apply the values and indicate whether or not this is a first time sync
                    apply_values($seed, $dataValues, $first_sync);
                    $seed->contacts_users_id = $current_user->id;
                    $seed->save();
                    $ids[] = $duplicate_id;
                    //we have a conflict
                }
            }
        } else {
            if ($module_name == 'Meetings' || $module_name == 'Calls') {
                //we are going to check if we have a meeting in the system
                //with the same outlook_id. If we do find one then we will grab that
                //id and save it
                if ($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))) {
                    if (empty($seed->id) && !isset($seed->id)) {
                        if (!empty($seed->outlook_id) && isset($seed->outlook_id)) {
                            //at this point we have an object that does not have
                            //the id set, but does have the outlook_id set
                            //so we need to query the db to find if we already
                            //have an object with this outlook_id, if we do
                            //then we can set the id, otherwise this is a new object
                            $order_by = "";
                            $query = $seed->table_name . ".outlook_id = '" . $seed->outlook_id . "'";
                            $response = $seed->get_list($order_by, $query, 0, -1, -1, 0);
                            $list = $response['list'];
                            if (count($list) > 0) {
                                foreach ($list as $value) {
                                    $seed->id = $value->id;
                                    break;
                                }
                            }
                            //fi
                        }
                        //fi
                    }
                    //fi
                    if (empty($seed->reminder_time)) {
                        $seed->reminder_time = -1;
                    }
                    if ($seed->reminder_time == -1) {
                        $defaultRemindrTime = $current_user->getPreference('reminder_time');
                        if ($defaultRemindrTime != -1) {
                            $seed->reminder_checked = '1';
                            $seed->reminder_time = $defaultRemindrTime;
                        }
                    }
                    $seed->save();
                    if ($seed->deleted == 1) {
                        $seed->mark_deleted($seed->id);
                    }
                    $ids[] = $seed->id;
                }
                //fi
            } else {
                if ($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))) {
                    $seed->save();
                    $ids[] = $seed->id;
                }
            }
        }
        // if somebody is calling set_entries_detail() and wants fields returned...
        if ($select_fields !== FALSE) {
            $ret_values[$count] = array();
            foreach ($select_fields as $select_field) {
                if (isset($seed->{$select_field})) {
                    $ret_values[$count][] = get_name_value($select_field, $seed->{$select_field});
                }
            }
        }
    }
    // handle returns for set_entries_detail() and set_entries()
    if ($select_fields !== FALSE) {
        return array('name_value_lists' => $ret_values, 'error' => $error->get_soap_array());
    } else {
        return array('ids' => $ids, 'error' => $error->get_soap_array());
    }
}
示例#7
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());
}
示例#8
0
function portal_get_kbdocument_attachment($session, $id)
{
    $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());
    }
    require_once 'modules/KBDocuments/KBDocumentSoap.php';
    $ns = new KBDocumentSoap($id);
    $file = $ns->retrieveFile($id);
    if ($file == -1) {
        $error->set_error('no_file');
        $file = '';
    }
    return array('note_attachment' => array('id' => $id, 'filename' => $ns->retrieveFileName($id), 'file' => $file), 'error' => $error->get_soap_array());
}
示例#9
0
function get_disc_client_file_list($session)
{
    global $sugar_config;
    $tempdir = create_cache_directory("disc_client");
    $temp_file = tempnam($tempdir, "sug");
    $file_list = array();
    $error = new SoapError();
    // write data to temp file
    $all_src_files = findAllFiles(".", array());
    foreach ($all_src_files as $src_file) {
        $md5 = md5_file($src_file);
        $file_list[] = array('filename' => "{$src_file}", 'md5' => "{$md5}");
    }
    if (!write_array_to_file("server_file_list", $file_list, $temp_file)) {
        $error->set_error("get_disc_client_file_list");
        $error->description = "temp_dir: " . $tempdir . " temp_file: " . $temp_file . "SOAP server: Could not write to file: {$temp_file}";
        return array('filename' => $temp_file, 'md5' => "", 'data' => "", 'error' => $error->get_soap_array());
    }
    // return via get_encoded_file
    return get_encoded_file($session, $temp_file);
}
示例#10
0
function get_quick_sync_data($session, $module_name, $related_module_name, $start, $count, $db_type, $deleted)
{
    $error = new SoapError();
    $field_list = array();
    $output_list = array();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('result' => "", 'result_count' => 0, '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' => "", 'result_count' => 0, 'error' => $error->get_soap_array());
    }
    $seed = BeanFactory::getBean($module_name);
    if (empty($seed)) {
        $error->set_error('no_module');
        return array('result' => "", 'result_count' => 0, 'error' => $error->get_soap_array());
    }
    $table_name = "";
    $is_related_query = false;
    if (empty($related_module_name) || !isset($related_module_name)) {
        $params['include_custom_fields'] = true;
        $query_list = $seed->create_new_list_query('', '', array(), $params, (int) $deleted, '', true, $seed);
        $query = "SELECT " . $seed->table_name . ".*";
        if (empty($query_list['from_min'])) {
            $query .= ' ' . $query_list['from'];
        } else {
            $query .= ' ' . $query_list['from_min'];
        }
        $query .= ' ' . $query_list['where'];
        $table_name = $seed->table_name;
    } else {
        $result = retrieve_relationship_query($module_name, $related_module_name, "", $deleted, $start, $count);
        $query = $result['query'];
        $table_name = $result['join_table'];
        $is_related_query = true;
    }
    //set the dbType on the client machine
    $GLOBALS['log']->fatal("Quick Sync Data Query: " . $query);
    $result = $seed->db->generateInsertSQL($seed, $query, $start, $count, $table_name, $db_type, $is_related_query);
    $data['data'] = $result['data'];
    $data['cstm'] = $result['cstm_sql'];
    $ret_data = base64_encode(serialize($data));
    return array('result' => $ret_data, 'result_count' => $result['result_count'], 'next_offset' => $result['next_offset'], 'total_count' => $result['total_count'], 'error' => $error->get_soap_array());
}
function portal_set_newsletters($session, $subscribe_ids, $unsubscribe_ids)
{
    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());
    }
    require_once 'modules/Campaigns/utils.php';
    $contact = new Contact();
    $contact->retrieve($_SESSION['user_id']);
    if (!empty($contact->id)) {
        foreach ($subscribe_ids as $campaign_id) {
            subscribe($campaign_id, null, $contact, true);
        }
        foreach ($unsubscribe_ids as $campaign_id) {
            unsubscribe($campaign_id, $contact);
        }
    }
    return $error->get_soap_array();
}
示例#12
0
function set_custom_field($session, $module_name, $type, $properties, $add_to_layout)
{
    global $current_user;
    global $beanList, $beanFiles;
    global $custom_field_meta;
    $error = new SoapError();
    $request_arr = array('action' => 'SaveField', 'is_update' => 'true', 'module' => 'ModuleBuilder', 'view_module' => $module_name, 'view_package' => 'studio');
    // ERROR CHECKING
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return $error->get_soap_array();
    }
    if (!is_admin($current_user)) {
        $error->set_error('no_admin');
        return $error->get_soap_array();
    }
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return $error->get_soap_array();
    }
    if (empty($custom_field_meta[$type])) {
        $error->set_error('custom_field_type_not_supported');
        return $error->get_soap_array();
    }
    $new_properties = array();
    foreach ($properties as $value) {
        $new_properties[$value['name']] = $value['value'];
    }
    foreach ($custom_field_meta[$type] as $property) {
        if (!isset($new_properties[$property])) {
            $error->set_error('custom_field_property_not_supplied');
            return $error->get_soap_array();
        }
        $request_arr[$property] = $new_properties[$property];
    }
    // $request_arr should now contain all the necessary information to create a custom field
    // merge $request_arr with $_POST/$_REQUEST, where the action_saveField() method expects them
    $_REQUEST = array_merge($_REQUEST, $request_arr);
    $_POST = array_merge($_POST, $request_arr);
    require_once 'modules/ModuleBuilder/controller.php';
    require_once 'modules/ModuleBuilder/parsers/ParserFactory.php';
    $mbc = new ModuleBuilderController();
    $mbc->setup();
    $mbc->action_SaveField();
    // add the field to the given module's EditView and DetailView layouts
    if ($add_to_layout == 1) {
        $layout_properties = array('name' => $new_properties['name'], 'label' => $new_properties['label']);
        if (isset($new_properties['customCode'])) {
            $layout_properties['customCode'] = $new_properties['customCode'];
        }
        if (isset($new_properties['customLabel'])) {
            $layout_properties['customLabel'] = $new_properties['customLabel'];
        }
        // add the field to the DetailView
        $parser = ParserFactory::getParser('layoutview', FALSE);
        $parser->init($module_name, 'DetailView', FALSE);
        $parser->_addField($layout_properties);
        $parser->writeWorkingFile();
        $parser->handleSave();
        unset($parser);
        // add the field to the EditView
        $parser = ParserFactory::getParser('layoutview', FALSE);
        $parser->init($module_name, 'EditView', FALSE);
        $parser->_addField($layout_properties);
        $parser->writeWorkingFile();
        $parser->handleSave();
    }
    return $error->get_soap_array();
}
 /**
  * Log the user into the application
  *
  * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
  *      in the right encoding for the type of authentication the user is setup for.  For Base
  *      sugar validation, password is the MD5 sum of the plain text password.
  * @param String $application -- The name of the application you are logging in from.  (Currently unused).
  * @param array $name_value_list -- Array of name value pair of extra parameters. As of today only 'language' and 'notifyonsave' is supported
  * @return Array - id - String id is the session_id of the session that was created.
  * 				 - module_name - String - module name of user
  * 				 - name_value_list - Array - The name value pair of user_id, user_name, user_language, user_currency_id, user_currency_name,
  *                                         - user_default_team_id, user_is_admin, user_default_dateformat, user_default_timeformat
  * @exception 'SoapFault' -- The SOAP error, if any
  */
 public function login($user_auth, $application, $name_value_list = array())
 {
     $GLOBALS['log']->info('Begin: SugarWebServiceImpl->login');
     global $sugar_config;
     $error = new SoapError();
     $user = BeanFactory::getBean('Users');
     $success = false;
     $authController = AuthenticationController::getInstance();
     if (!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN' && $authController->authController->userAuthenticateClass != "LDAPAuthenticateUser") {
         $user_auth['password'] = md5($user_auth['password']);
     }
     $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
     $usr_id = $user->retrieve_user_id($user_auth['user_name']);
     if ($usr_id) {
         $user->retrieve($usr_id);
     }
     if ($isLoginSuccess) {
         if ($_SESSION['hasExpiredPassword'] == '1') {
             $error->set_error('password_expired');
             $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
             LogicHook::initialize();
             $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
             self::$helperObject->setFaultObject($error);
             return;
         }
         if (!empty($user) && !empty($user->id) && !$user->is_group) {
             $success = true;
             global $current_user;
             $current_user = $user;
         }
     } else {
         if ($usr_id && isset($user->user_name) && $user->getPreference('lockout') == '1') {
             $error->set_error('lockout_reached');
             $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
             LogicHook::initialize();
             $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
             self::$helperObject->setFaultObject($error);
             return;
         } else {
             if ($authController->authController->userAuthenticateClass == "LDAPAuthenticateUser" && (empty($user_auth['encryption']) || $user_auth['encryption'] !== 'PLAIN')) {
                 $error->set_error('ldap_error');
                 LogicHook::initialize();
                 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
                 self::$helperObject->setFaultObject($error);
                 return;
             } else {
                 if (function_exists('mcrypt_cbc')) {
                     $password = self::$helperObject->decrypt_string($user_auth['password']);
                     if ($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id'])) {
                         $success = true;
                     }
                 }
             }
         }
     }
     if ($success) {
         session_start();
         global $current_user;
         //$current_user = $user;
         self::$helperObject->login_success($name_value_list);
         $current_user->loadPreferences();
         $_SESSION['is_valid_session'] = true;
         $_SESSION['ip_address'] = query_client_ip();
         $_SESSION['user_id'] = $current_user->id;
         $_SESSION['type'] = 'user';
         $_SESSION['avail_modules'] = self::$helperObject->get_user_module_list($current_user);
         $_SESSION['authenticated_user_id'] = $current_user->id;
         $_SESSION['unique_key'] = $sugar_config['unique_key'];
         $current_user->call_custom_logic('after_login');
         $GLOBALS['log']->info('End: SugarWebServiceImpl->login - succesful login');
         $nameValueArray = array();
         global $current_language;
         $nameValueArray['user_id'] = self::$helperObject->get_name_value('user_id', $current_user->id);
         $nameValueArray['user_name'] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
         $nameValueArray['user_language'] = self::$helperObject->get_name_value('user_language', $current_language);
         $cur_id = $current_user->getPreference('currency');
         $nameValueArray['user_currency_id'] = self::$helperObject->get_name_value('user_currency_id', $cur_id);
         $nameValueArray['user_is_admin'] = self::$helperObject->get_name_value('user_is_admin', is_admin($current_user));
         $nameValueArray['user_default_team_id'] = self::$helperObject->get_name_value('user_default_team_id', $current_user->default_team);
         $nameValueArray['user_default_dateformat'] = self::$helperObject->get_name_value('user_default_dateformat', $current_user->getPreference('datef'));
         $nameValueArray['user_default_timeformat'] = self::$helperObject->get_name_value('user_default_timeformat', $current_user->getPreference('timef'));
         $num_grp_sep = $current_user->getPreference('num_grp_sep');
         $dec_sep = $current_user->getPreference('dec_sep');
         $nameValueArray['user_number_seperator'] = self::$helperObject->get_name_value('user_number_seperator', empty($num_grp_sep) ? $sugar_config['default_number_grouping_seperator'] : $num_grp_sep);
         $nameValueArray['user_decimal_seperator'] = self::$helperObject->get_name_value('user_decimal_seperator', empty($dec_sep) ? $sugar_config['default_decimal_seperator'] : $dec_sep);
         $nameValueArray['mobile_max_list_entries'] = self::$helperObject->get_name_value('mobile_max_list_entries', $sugar_config['wl_list_max_entries_per_page']);
         $nameValueArray['mobile_max_subpanel_entries'] = self::$helperObject->get_name_value('mobile_max_subpanel_entries', $sugar_config['wl_list_max_entries_per_subpanel']);
         if ($application == 'mobile') {
             $modules = $availModuleNames = array();
             $availModules = array_keys($_SESSION['avail_modules']);
             //ACL check already performed.
             $modules = self::$helperObject->get_visible_mobile_modules($availModules);
             $nameValueArray['available_modules'] = $modules;
             //Get the vardefs md5
             foreach ($modules as $mod_def) {
                 $availModuleNames[] = $mod_def['module_key'];
             }
             $nameValueArray['vardefs_md5'] = self::get_module_fields_md5(session_id(), $availModuleNames);
         }
         $currencyObject = BeanFactory::getBean('Currencies', $cur_id);
         $nameValueArray['user_currency_name'] = self::$helperObject->get_name_value('user_currency_name', $currencyObject->name);
         $_SESSION['user_language'] = $current_language;
         return array('id' => session_id(), 'module_name' => 'Users', 'name_value_list' => $nameValueArray);
     }
     LogicHook::initialize();
     $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
     $error->set_error('invalid_login');
     self::$helperObject->setFaultObject($error);
     $GLOBALS['log']->info('End: SugarWebServiceImpl->login - failed login');
 }
function retrieve_relationship_query($module_name, $related_module, $relationship_query, $show_deleted, $offset, $max_results)
{
    global $beanList, $beanFiles, $dictionary, $current_user;
    $error = new SoapError();
    $result_list = array();
    if (empty($beanList[$module_name]) || empty($beanList[$related_module])) {
        $error->set_error('no_module');
        return array('query' => "", 'module_1' => "", 'join_table' => "", 'error' => $error->get_soap_array());
    }
    $row = retrieve_relationships_properties($module_name, $related_module);
    if (empty($row)) {
        $error->set_error('no_relationship_support');
        return array('query' => "", 'module_1' => "", 'join_table' => "", 'error' => $error->get_soap_array());
    }
    $module_1 = $row['lhs_module'];
    $mod_key = $row['join_key_lhs'];
    $module_2 = $row['rhs_module'];
    $mod2_key = $row['join_key_rhs'];
    $table = $row['join_table'];
    if (empty($table)) {
        return array('query' => "", 'module_1' => "", 'join_table' => "", 'error' => $error->get_soap_array());
    }
    $mod = BeanFactory::getBean($module_1);
    $mod2 = BeanFactory::getBean($module_2);
    $query = "SELECT rt.* FROM  {$table} rt ";
    $query .= " inner join {$mod->table_name} m1 on rt.{$mod_key} = m1.id ";
    $query .= " inner join {$mod2->table_name} m2 on rt.{$mod2_key} = m2.id  ";
    //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.
    if (defined('DISABLE_ROW_LEVEL_SECURITY')) {
        $mod->disable_row_level_security = DISABLE_ROW_LEVEL_SECURITY;
        $mod2->disable_row_level_security = DISABLE_ROW_LEVEL_SECURITY;
    }
    if (!$mod->disable_row_level_security) {
        if (!empty($mod->field_defs['team_id'])) {
            $query .= " INNER JOIN (select tst.team_set_id from team_sets_teams tst ";
            $query .= " INNER JOIN team_memberships tm1 ON tst.team_id = tm1.team_id\n\t\t\t\t\t                       AND tm1.user_id = '{$current_user->id}'\n\t\t\t\t\t\t                   AND tm1.deleted=0 group by tst.team_set_id) m1_tf on m1_tf.team_set_id  = m1.team_set_id ";
        }
    }
    if (!$mod2->disable_row_level_security) {
        if (!empty($mod2->field_defs['team_id'])) {
            $query .= " INNER JOIN (select tst.team_set_id from team_sets_teams tst ";
            $query .= " INNER JOIN team_memberships tm2 ON tst.team_id = tm2.team_id\n\t\t\t\t\t                       AND tm2.user_id = '{$current_user->id}'\n\t\t\t\t\t\t                   AND tm2.deleted=0 group by tst.team_set_id) m2_tf on m2_tf.team_set_id  = m2.team_set_id ";
        }
    }
    if (!empty($relationship_query)) {
        $query .= ' WHERE ' . $relationship_query;
    }
    return array('query' => $query, 'module_1' => $module_1, 'join_table' => $table, 'error' => $error->get_soap_array());
}
function handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE)
{
    global $beanList, $beanFiles;
    $error = new SoapError();
    $ret_values = array();
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('ids' => array(), 'error' => $error->get_soap_array());
    }
    global $current_user;
    if (!check_modules_access($current_user, $module_name, 'write')) {
        $error->set_error('no_access');
        return array('ids' => -1, 'error' => $error->get_soap_array());
    }
    $class_name = $beanList[$module_name];
    require_once $beanFiles[$class_name];
    $ids = array();
    $count = 1;
    $total = sizeof($name_value_lists);
    foreach ($name_value_lists as $name_value_list) {
        $seed = new $class_name();
        $seed->update_vcal = false;
        foreach ($name_value_list as $value) {
            if ($value['name'] == 'id') {
                $seed->retrieve($value['value']);
                break;
            }
        }
        foreach ($name_value_list as $value) {
            $val = $value['value'];
            if ($seed->field_name_map[$value['name']]['type'] == 'enum') {
                $vardef = $seed->field_name_map[$value['name']];
                if (isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$value])) {
                    if (in_array($val, $app_list_strings[$vardef['options']])) {
                        $val = array_search($val, $app_list_strings[$vardef['options']]);
                    }
                }
            }
            $seed->{$value}['name'] = $val;
        }
        if ($count == $total) {
            $seed->update_vcal = false;
        }
        $count++;
        //Add the account to a contact
        if ($module_name == 'Contacts') {
            $GLOBALS['log']->debug('Creating Contact Account');
            add_create_account($seed);
            $duplicate_id = check_for_duplicate_contacts($seed);
            if ($duplicate_id == null) {
                if ($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))) {
                    $seed->save();
                    if ($seed->deleted == 1) {
                        $seed->mark_deleted($seed->id);
                    }
                    $ids[] = $seed->id;
                }
            } else {
                //since we found a duplicate we should set the sync flag
                if ($seed->ACLAccess('Save')) {
                    $seed->id = $duplicate_id;
                    $seed->contacts_users_id = $current_user->id;
                    $seed->save();
                    $ids[] = $duplicate_id;
                    //we have a conflict
                }
            }
        } else {
            if ($module_name == 'Meetings' || $module_name == 'Calls') {
                //we are going to check if we have a meeting in the system
                //with the same outlook_id. If we do find one then we will grab that
                //id and save it
                if ($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))) {
                    if (empty($seed->id) && !isset($seed->id)) {
                        if (!empty($seed->outlook_id) && isset($seed->outlook_id)) {
                            //at this point we have an object that does not have
                            //the id set, but does have the outlook_id set
                            //so we need to query the db to find if we already
                            //have an object with this outlook_id, if we do
                            //then we can set the id, otherwise this is a new object
                            $order_by = "";
                            $query = $seed->table_name . ".outlook_id = '" . $seed->outlook_id . "'";
                            $response = $seed->get_list($order_by, $query, 0, -1, -1, 0);
                            $list = $response['list'];
                            if (count($list) > 0) {
                                foreach ($list as $value) {
                                    $seed->id = $value->id;
                                    break;
                                }
                            }
                            //fi
                        }
                        //fi
                    }
                    //fi
                    $seed->save();
                    $ids[] = $seed->id;
                }
                //fi
            } else {
                if ($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))) {
                    $seed->save();
                    $ids[] = $seed->id;
                }
            }
        }
        // if somebody is calling set_entries_detail() and wants fields returned...
        if ($select_fields !== FALSE) {
            $ret_values[$count] = array();
            foreach ($select_fields as $select_field) {
                if (isset($seed->{$select_field})) {
                    $ret_values[$count][] = get_name_value($select_field, $seed->{$select_field});
                }
            }
        }
    }
    // handle returns for set_entries_detail() and set_entries()
    if ($select_fields !== FALSE) {
        return array('name_value_lists' => $ret_values, 'error' => $error->get_soap_array());
    } else {
        return array('ids' => $ids, 'error' => $error->get_soap_array());
    }
}
/**
 * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a 
 * properly authenticated user to download a document that they have proper rights to download.
 *
 * @param String $session -- Session ID returned by a previous call to login. 
 * @param String $id      -- ID of the document revision to obtain
 * @return return_document_revision - this is a complex type as defined in SoapTypes.php
 */
function get_document_revision($session, $id)
{
    global $sugar_config;
    $error = new SoapError();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
    require_once 'modules/DocumentRevisions/DocumentRevision.php';
    $dr = new DocumentRevision();
    $dr->retrieve($id);
    if (!empty($dr->filename)) {
        $filename = $sugar_config['upload_dir'] . "/" . $dr->id;
        $handle = fopen($filename, "r");
        $contents = fread($handle, filesize($filename));
        fclose($handle);
        $contents = base64_encode($contents);
        return array('document_revision' => array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents), 'error' => $error->get_soap_array());
    } else {
        $error->set_error('no_records');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
}
示例#17
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 = 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());
}
 /**
  * Log the user into the application
  *
  * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
  *      in the right encoding for the type of authentication the user is setup for.  For Base
  *      sugar validation, password is the MD5 sum of the plain text password.
  * @param String $application -- The name of the application you are logging in from.  (Currently unused).
  * @param array $name_value_list -- Array of name value pair of extra parameters. As of today only 'language' and 'notifyonsave' is supported
  * @return Array - id - String id is the session_id of the session that was created.
  * 				 - module_name - String - module name of user
  * 				 - name_value_list - Array - The name value pair of user_id, user_name, user_language
  * @exception 'SoapFault' -- The SOAP error, if any
  */
 public function login($user_auth, $application, $name_value_list)
 {
     $GLOBALS['log']->info('Begin: SugarWebServiceImpl->login');
     global $sugar_config, $system_config;
     $error = new SoapError();
     $user = new User();
     $success = false;
     if (!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN') {
         $user_auth['password'] = md5($user_auth['password']);
     }
     //rrs
     $system_config = new Administration();
     $system_config->retrieveSettings('system');
     $authController = new AuthenticationController(!empty($sugar_config['authenticationClass']) ? $sugar_config['authenticationClass'] : 'SugarAuthenticate');
     //rrs
     $user = $user->retrieve_by_string_fields(array('user_name' => $user_auth['user_name'], 'user_hash' => $user_auth['password'], 'deleted' => 0, 'status' => 'Active', 'portal_only' => 0));
     if (!empty($user) && !empty($user->id) && !$user->is_group) {
         $success = true;
         global $current_user;
         $current_user = $user;
     } else {
         if (function_exists('mcrypt_cbc')) {
             $password = self::$helperObject->decrypt_string($user_auth['password']);
             if ($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id'])) {
                 $success = true;
             }
             // if
         }
     }
     // else if
     if ($success) {
         session_start();
         global $current_user;
         //$current_user = $user;
         self::$helperObject->login_success($name_value_list);
         $current_user->loadPreferences();
         $_SESSION['is_valid_session'] = true;
         $_SESSION['ip_address'] = query_client_ip();
         $_SESSION['user_id'] = $current_user->id;
         $_SESSION['type'] = 'user';
         $_SESSION['avail_modules'] = self::$helperObject->get_user_module_list($current_user);
         $_SESSION['authenticated_user_id'] = $current_user->id;
         $_SESSION['unique_key'] = $sugar_config['unique_key'];
         $current_user->call_custom_logic('after_login');
         $GLOBALS['log']->info('End: SugarWebServiceImpl->login - succesful login');
         $nameValueArray = array();
         global $current_language;
         $nameValueArray[] = self::$helperObject->get_name_value('user_id', $current_user->id);
         $nameValueArray[] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
         $nameValueArray[] = self::$helperObject->get_name_value('user_language', $current_language);
         $_SESSION['user_language'] = $current_language;
         return array('id' => session_id(), 'module_name' => 'Users', 'name_value_list' => $nameValueArray);
     }
     // if
     LogicHook::initialize();
     $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
     $error->set_error('invalid_login');
     self::$helperObject->setFaultObject($error);
     $GLOBALS['log']->info('End: SugarWebServiceImpl->login - failed login');
 }
function retrieve_relationship_query($module_name, $related_module, $relationship_query, $show_deleted, $offset, $max_results)
{
    global $beanList, $beanFiles, $dictionary, $current_user;
    $error = new SoapError();
    $result_list = array();
    if (empty($beanList[$module_name]) || empty($beanList[$related_module])) {
        $error->set_error('no_module');
        return array('query' => "", 'module_1' => "", 'join_table' => "", 'error' => $error->get_soap_array());
    }
    $row = retrieve_relationships_properties($module_name, $related_module);
    if (empty($row)) {
        $error->set_error('no_relationship_support');
        return array('query' => "", 'module_1' => "", 'join_table' => "", 'error' => $error->get_soap_array());
    }
    $module_1 = $row['lhs_module'];
    $mod_key = $row['join_key_lhs'];
    $module_2 = $row['rhs_module'];
    $mod2_key = $row['join_key_rhs'];
    $table = $row['join_table'];
    if (empty($table)) {
        return array('query' => "", 'module_1' => "", 'join_table' => "", 'error' => $error->get_soap_array());
    }
    $class_name = $beanList[$module_1];
    require_once $beanFiles[$class_name];
    $mod = new $class_name();
    $mod2_name = $beanList[$module_2];
    require_once $beanFiles[$mod2_name];
    $mod2 = new $mod2_name();
    $query = "SELECT rt.* FROM  {$table} rt ";
    $query .= " inner join {$mod->table_name} m1 on rt.{$mod_key} = m1.id ";
    $query .= " inner join {$mod2->table_name} m2 on rt.{$mod2_key} = m2.id  ";
    if (!empty($relationship_query)) {
        $query .= ' WHERE ' . $relationship_query;
    }
    return array('query' => $query, 'module_1' => $module_1, 'join_table' => $table, 'error' => $error->get_soap_array());
}
示例#20
0
 /**
  * Log the user into the application
  *
  * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
  *      in the right encoding for the type of authentication the user is setup for.  For Base
  *      sugar validation, password is the MD5 sum of the plain text password.
  * @param String $application -- The name of the application you are logging in from.  (Currently unused).
  * @param array $name_value_list -- Array of name value pair of extra parameters. As of today only 'language' and 'notifyonsave' is supported
  * @return Array - id - String id is the session_id of the session that was created.
  * 				 - module_name - String - module name of user
  * 				 - name_value_list - Array - The name value pair of user_id, user_name, user_language, user_currency_id, user_currency_name,
  *                                         - user_default_team_id, user_is_admin, user_default_dateformat, user_default_timeformat
  * @exception 'SoapFault' -- The SOAP error, if any
  */
 public function login($user_auth, $application, $name_value_list)
 {
     $GLOBALS['log']->info('Begin: SugarWebServiceImpl->login');
     global $sugar_config, $system_config;
     $error = new SoapError();
     $user = new User();
     $success = false;
     if (!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN') {
         $user_auth['password'] = md5($user_auth['password']);
     }
     //rrs
     $system_config = new Administration();
     $system_config->retrieveSettings('system');
     $authController = new AuthenticationController();
     //rrs
     $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
     $usr_id = $user->retrieve_user_id($user_auth['user_name']);
     if ($usr_id) {
         $user->retrieve($usr_id);
     }
     if ($isLoginSuccess) {
         if ($_SESSION['hasExpiredPassword'] == '1') {
             $error->set_error('password_expired');
             $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
             LogicHook::initialize();
             $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
             self::$helperObject->setFaultObject($error);
             return;
         }
         if (!empty($user) && !empty($user->id) && !$user->is_group) {
             $success = true;
             global $current_user;
             $current_user = $user;
         }
     } else {
         if ($usr_id && isset($user->user_name) && $user->getPreference('lockout') == '1') {
             $error->set_error('lockout_reached');
             $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
             LogicHook::initialize();
             $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
             self::$helperObject->setFaultObject($error);
             return;
         } else {
             if (function_exists('mcrypt_cbc')) {
                 $password = self::$helperObject->decrypt_string($user_auth['password']);
                 if ($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id'])) {
                     $success = true;
                 }
             }
         }
     }
     if ($success) {
         session_start();
         global $current_user;
         //$current_user = $user;
         self::$helperObject->login_success($name_value_list);
         $current_user->loadPreferences();
         $_SESSION['is_valid_session'] = true;
         $_SESSION['ip_address'] = query_client_ip();
         $_SESSION['user_id'] = $current_user->id;
         $_SESSION['type'] = 'user';
         $_SESSION['avail_modules'] = self::$helperObject->get_user_module_list($current_user);
         $_SESSION['authenticated_user_id'] = $current_user->id;
         $_SESSION['unique_key'] = $sugar_config['unique_key'];
         $current_user->call_custom_logic('after_login');
         $GLOBALS['log']->info('End: SugarWebServiceImpl->login - succesful login');
         $nameValueArray = array();
         global $current_language;
         $nameValueArray['user_id'] = self::$helperObject->get_name_value('user_id', $current_user->id);
         $nameValueArray['user_name'] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
         $nameValueArray['user_language'] = self::$helperObject->get_name_value('user_language', $current_language);
         $cur_id = $current_user->getPreference('currency');
         $nameValueArray['user_currency_id'] = self::$helperObject->get_name_value('user_currency_id', $cur_id);
         $nameValueArray['user_is_admin'] = self::$helperObject->get_name_value('user_is_admin', is_admin($current_user));
         $nameValueArray['user_default_team_id'] = self::$helperObject->get_name_value('user_default_team_id', $current_user->default_team);
         $nameValueArray['user_default_dateformat'] = self::$helperObject->get_name_value('user_default_dateformat', $current_user->getPreference('datef'));
         $nameValueArray['user_default_timeformat'] = self::$helperObject->get_name_value('user_default_timeformat', $current_user->getPreference('timef'));
         $currencyObject = new Currency();
         $currencyObject->retrieve($cur_id);
         $nameValueArray['user_currency_name'] = self::$helperObject->get_name_value('user_currency_name', $currencyObject->name);
         $_SESSION['user_language'] = $current_language;
         return array('id' => session_id(), 'module_name' => 'Users', 'name_value_list' => $nameValueArray);
     }
     LogicHook::initialize();
     $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
     $error->set_error('invalid_login');
     self::$helperObject->setFaultObject($error);
     $GLOBALS['log']->info('End: SugarWebServiceImpl->login - failed login');
 }
示例#21
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());
}
/**
 * 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
}
示例#23
0
function handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE)
{
    global $beanList, $beanFiles, $app_list_strings, $current_user;
    $error = new SoapError();
    $ret_values = array();
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('ids' => array(), 'error' => $error->get_soap_array());
    }
    if (!check_modules_access($current_user, $module_name, 'write')) {
        $error->set_error('no_access');
        return array('ids' => -1, 'error' => $error->get_soap_array());
    }
    $class_name = $beanList[$module_name];
    require_once $beanFiles[$class_name];
    $ids = array();
    $count = 1;
    $total = sizeof($name_value_lists);
    foreach ($name_value_lists as $name_value_list) {
        $seed = new $class_name();
        $seed->update_vcal = false;
        //See if we can retrieve the seed by a given id value
        foreach ($name_value_list as $value) {
            if ($value['name'] == 'id') {
                $seed->retrieve($value['value']);
                break;
            }
        }
        $dataValues = array();
        foreach ($name_value_list as $value) {
            $val = $value['value'];
            if ($seed->field_name_map[$value['name']]['type'] == 'enum' || $seed->field_name_map[$value['name']]['type'] == 'radioenum') {
                $vardef = $seed->field_name_map[$value['name']];
                if (isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$val])) {
                    if (in_array($val, $app_list_strings[$vardef['options']])) {
                        $val = array_search($val, $app_list_strings[$vardef['options']]);
                    }
                }
            } else {
                if ($seed->field_name_map[$value['name']]['type'] == 'multienum') {
                    $vardef = $seed->field_name_map[$value['name']];
                    if (isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$value])) {
                        $items = explode(",", $val);
                        $parsedItems = array();
                        foreach ($items as $item) {
                            if (in_array($item, $app_list_strings[$vardef['options']])) {
                                $keyVal = array_search($item, $app_list_strings[$vardef['options']]);
                                array_push($parsedItems, $keyVal);
                            }
                        }
                        if (!empty($parsedItems)) {
                            $val = encodeMultienumValue($parsedItems);
                        }
                    }
                }
            }
            //Apply the non-empty values now since this will be used for duplicate checks
            //allow string or int of 0 to be updated if set.
            if (!empty($val) || ($val === '0' || $val === 0)) {
                $seed->{$value['name']} = $val;
            }
            //Store all the values in dataValues Array to apply later
            $dataValues[$value['name']] = $val;
        }
        if ($count == $total) {
            $seed->update_vcal = false;
        }
        $count++;
        //Add the account to a contact
        if ($module_name == 'Contacts') {
            $GLOBALS['log']->debug('Creating Contact Account');
            add_create_account($seed);
            $duplicate_id = check_for_duplicate_contacts($seed);
            if ($duplicate_id == null) {
                if ($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))) {
                    //Now apply the values, since this is not a duplicate we can just pass false for the $firstSync argument
                    apply_values($seed, $dataValues, false);
                    $seed->save();
                    if ($seed->deleted == 1) {
                        $seed->mark_deleted($seed->id);
                    }
                    $ids[] = $seed->id;
                }
            } else {
                //since we found a duplicate we should set the sync flag
                if ($seed->ACLAccess('Save')) {
                    //Determine if this is a first time sync.  We find out based on whether or not a contacts_users relationship exists
                    $seed->id = $duplicate_id;
                    $seed->load_relationship("user_sync");
                    $beans = $seed->user_sync->getBeans();
                    $first_sync = empty($beans);
                    //Now apply the values and indicate whether or not this is a first time sync
                    apply_values($seed, $dataValues, $first_sync);
                    $seed->contacts_users_id = $current_user->id;
                    $seed->save();
                    $ids[] = $duplicate_id;
                    //we have a conflict
                }
            }
        } else {
            if ($module_name == 'Meetings' || $module_name == 'Calls') {
                //we are going to check if we have a meeting in the system
                //with the same outlook_id. If we do find one then we will grab that
                //id and save it
                if ($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))) {
                    // Check if we're updating an old record, or creating a new
                    if (empty($seed->id)) {
                        // If it's a new one, and we have outlook_id set
                        // which means we're syncing from OPI check if it already exists
                        if (!empty($seed->outlook_id)) {
                            $GLOBALS['log']->debug('Looking for ' . $module_name . ' with outlook_id ' . $seed->outlook_id);
                            $fields = array('outlook_id' => $seed->outlook_id);
                            // Try to fetch a bean with this outlook_id
                            $temp = BeanFactory::getBean($module_name);
                            $temp = $temp->retrieve_by_string_fields($fields);
                            // If we fetched one, just copy the ID to the one we're syncing
                            if (!empty($temp)) {
                                $seed->id = $temp->id;
                            } else {
                                $GLOBALS['log']->debug('Looking for ' . $module_name . ' with name/date_start/duration_hours/duration_minutes ' . $seed->name . '/' . $seed->date_start . '/' . $seed->duration_hours . '/' . $seed->duration_minutes);
                                // If we didn't, try to find the meeting by comparing the passed
                                // Subject, start date and duration
                                $fields = array('name' => $seed->name, 'date_start' => $seed->date_start, 'duration_hours' => $seed->duration_hours, 'duration_minutes' => $seed->duration_minutes);
                                $temp = BeanFactory::getBean($module_name);
                                $temp = $temp->retrieve_by_string_fields($fields);
                                if (!empty($temp)) {
                                    $seed->id = $temp->id;
                                }
                            }
                            $GLOBALS['log']->debug($module_name . ' found: ' . !empty($seed->id));
                        }
                    }
                    if (empty($seed->reminder_time)) {
                        $seed->reminder_time = -1;
                    }
                    if ($seed->reminder_time == -1) {
                        $defaultRemindrTime = $current_user->getPreference('reminder_time');
                        if ($defaultRemindrTime != -1) {
                            $seed->reminder_checked = '1';
                            $seed->reminder_time = $defaultRemindrTime;
                        }
                    }
                    $seed->save();
                    if ($seed->deleted == 1) {
                        $seed->mark_deleted($seed->id);
                    }
                    $ids[] = $seed->id;
                }
                //fi
            } else {
                if ($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))) {
                    $seed->save();
                    $ids[] = $seed->id;
                }
            }
        }
        // if somebody is calling set_entries_detail() and wants fields returned...
        if ($select_fields !== FALSE) {
            $ret_values[$count] = array();
            foreach ($select_fields as $select_field) {
                if (isset($seed->{$select_field})) {
                    $ret_values[$count][] = get_name_value($select_field, $seed->{$select_field});
                }
            }
        }
    }
    // handle returns for set_entries_detail() and set_entries()
    if ($select_fields !== FALSE) {
        return array('name_value_lists' => $ret_values, 'error' => $error->get_soap_array());
    } else {
        return array('ids' => $ids, 'error' => $error->get_soap_array());
    }
}
 /**
  * get_modified_relationships
  *
  * Get a list of the relationship records that have a date_modified value set within a specified date range.  This is used to
  * help facilitate sync operations.  The module_name should be "Users" and the related_module one of "Meetings", "Calls" and
  * "Contacts".
  *
  * @param xsd:string $session String of the session id
  * @param xsd:string $module_name String value of the primary module to retrieve relationship against
  * @param xsd:string $related_module String value of the related module to retrieve records off of
  * @param xsd:string $from_date String value in YYYY-MM-DD HH:MM:SS format of date_start range (required)
  * @param xsd:string $to_date String value in YYYY-MM-DD HH:MM:SS format of ending date_start range (required)
  * @param xsd:int $offset Integer value of the offset to begin returning records from
  * @param xsd:int $max_results Integer value of the max_results to return; -99 for unlimited
  * @param xsd:int $deleted Integer value indicating deleted column value search (defaults to 0).  Set to 1 to find deleted records
  * @param xsd:string $module_user_id String value of the user id (optional, but defaults to SOAP session user id anyway)  The module_user_id value
  * here ought to be the user id of the user initiating the SOAP session
  * @param tns:select_fields $select_fields Array value of fields to select and return as name/value pairs
  * @param xsd:string $relationship_name String value of the relationship name to search on
  * @param xsd:string $deletion_date String value in YYYY-MM-DD HH:MM:SS format for filtering on deleted records whose date_modified falls within range
  * this allows deleted records to be returned as well
  *
  * @return Array records that match search criteria
  */
 function get_modified_relationships($session, $module_name, $related_module, $from_date, $to_date, $offset, $max_results, $deleted = 0, $module_user_id = '', $select_fields = array(), $relationship_name = '', $deletion_date = '')
 {
     global $beanList, $beanFiles, $current_user;
     $error = new SoapError();
     $output_list = array();
     if (empty($from_date)) {
         $error->set_error('invalid_call_error, missing from_date');
         return array('result_count' => 0, 'next_offset' => 0, 'field_list' => $select_fields, 'entry_list' => array(), 'error' => $error->get_soap_array());
     }
     if (empty($to_date)) {
         $error->set_error('invalid_call_error, missing to_date');
         return array('result_count' => 0, 'next_offset' => 0, 'field_list' => $select_fields, 'entry_list' => array(), 'error' => $error->get_soap_array());
     }
     self::$helperObject = new SugarWebServiceUtilv4_1();
     if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
         Log::info('End: SugarWebServiceImpl->get_modified_relationships');
         return;
     }
     // if
     if (empty($beanList[$module_name]) || empty($beanList[$related_module])) {
         $error->set_error('no_module');
         return array('result_count' => 0, 'next_offset' => 0, 'field_list' => $select_fields, 'entry_list' => array(), 'error' => $error->get_soap_array());
     }
     global $current_user;
     if (!self::$helperObject->check_modules_access($current_user, $module_name, 'read') || !self::$helperObject->check_modules_access($current_user, $related_module, 'read')) {
         $error->set_error('no_access');
         return array('result_count' => 0, 'next_offset' => 0, 'field_list' => $select_fields, 'entry_list' => array(), 'error' => $error->get_soap_array());
     }
     if ($max_results > 0 || $max_results == '-99') {
         global $sugar_config;
         $sugar_config['list_max_entries_per_page'] = $max_results;
     }
     // Cast to integer
     $deleted = (int) $deleted;
     $query = "(m1.date_modified > " . db_convert("'" . $GLOBALS['db']->quote($from_date) . "'", 'datetime') . " AND m1.date_modified <= " . db_convert("'" . $GLOBALS['db']->quote($to_date) . "'", 'datetime') . " AND {0}.deleted = {$deleted})";
     if (isset($deletion_date) && !empty($deletion_date)) {
         $query .= " OR ({0}.date_modified > " . db_convert("'" . $GLOBALS['db']->quote($deletion_date) . "'", 'datetime') . " AND {0}.date_modified <= " . db_convert("'" . $GLOBALS['db']->quote($to_date) . "'", 'datetime') . " AND {0}.deleted = 1)";
     }
     if (!empty($current_user->id)) {
         $query .= " AND m2.id = '" . $GLOBALS['db']->quote($current_user->id) . "'";
     }
     //if($related_module == 'Meetings' || $related_module == 'Calls' || $related_module = 'Contacts'){
     $query = string_format($query, array('m1'));
     //}
     require_once 'soap/SoapRelationshipHelper.php';
     $results = retrieve_modified_relationships($module_name, $related_module, $query, $deleted, $offset, $max_results, $select_fields, $relationship_name);
     $list = $results['result'];
     foreach ($list as $value) {
         $output_list[] = self::$helperObject->array_get_return_value($value, $results['table_name']);
     }
     $next_offset = $offset + count($output_list);
     return array('result_count' => count($output_list), 'next_offset' => $next_offset, 'entry_list' => $output_list, 'error' => $error->get_soap_array());
 }
示例#25
0
function get_attendee_list($session, $module_name, $id)
{
    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
    $xml = '<?xml version="1.0" encoding="utf-8"?>';
    if ($module_name == 'Meetings' || $module_name == 'Calls') {
        //if we find a meeting or call we want to send back the attendees
        $l_module_name = strtolower($module_name);
        $table_name = $l_module_name . "_users";
        if ($module_name == 'Meetings') {
            $join_field = "meeting";
        } else {
            $join_field = "call";
        }
        $xml .= '<attendees>';
        $result = $seed->db->query("SELECT users.id, {$table_name}.date_modified, first_name, last_name FROM users INNER JOIN {$table_name} ON {$table_name}.user_id = users.id WHERE " . $table_name . "." . $join_field . "_id = '" . $GLOBALS['db']->quote($id) . "' AND {$table_name}.deleted = 0");
        $user = new User();
        while ($row = $seed->db->fetchByAssoc($result)) {
            $user->id = $row['id'];
            $email = $user->emailAddress->getPrimaryAddress($user);
            $xml .= '<attendee>';
            $xml .= '<id>' . $user->id . '</id>';
            $xml .= '<first_name>' . $row['first_name'] . '</first_name>';
            $xml .= '<last_name>' . $row['last_name'] . '</last_name>';
            $xml .= '<email1>' . $email . '</email1>';
            $xml .= '</attendee>';
        }
        //now get contacts
        $table_name = $l_module_name . "_contacts";
        $result = $seed->db->query("SELECT contacts.id, {$table_name}.date_modified, first_name, last_name FROM contacts INNER JOIN {$table_name} ON {$table_name}.contact_id = contacts.id INNER JOIN {$seed->table_name} ON " . $seed->table_name . ".id = " . $table_name . "." . $join_field . "_id WHERE " . $table_name . "." . $join_field . "_id = '" . $GLOBALS['db']->quote($id) . "' AND " . $table_name . ".deleted = 0 AND (contacts.id != " . $seed->table_name . ".parent_id OR " . $seed->table_name . ".parent_id IS NULL)");
        $contact = new Contact();
        while ($row = $seed->db->fetchByAssoc($result)) {
            $contact->id = $row['id'];
            $email = $contact->emailAddress->getPrimaryAddress($contact);
            $xml .= '<attendee>';
            $xml .= '<id>' . $contact->id . '</id>';
            $xml .= '<first_name>' . $row['first_name'] . '</first_name>';
            $xml .= '<last_name>' . $row['last_name'] . '</last_name>';
            $xml .= '<email1>' . $email . '</email1>';
            $xml .= '</attendee>';
        }
        $xml .= '</attendees>';
    }
    $xml = base64_encode($xml);
    return array('result' => $xml, 'error' => $error->get_soap_array());
}
function portal_get_module_fields($session, $module_name)
{
    global $beanList, $beanFiles, $portal_modules, $valid_modules_for_contact;
    $error = new SoapError();
    $module_fields = array();
    if (!portal_validate_authenticated($session)) {
        $error->set_error('invalid_session');
        $error->description .= $session;
        return array('module_name' => $module_name, 'module_fields' => $module_fields, 'error' => $error->get_soap_array());
    }
    if ($_SESSION['type'] == 'lead' && $module_name != 'Leads') {
        $error->set_error('no_access');
        return array('module_name' => $module_name, 'module_fields' => $module_fields, 'error' => $error->get_soap_array());
    }
    if (empty($beanList[$module_name])) {
        $error->set_error('no_module');
        return array('module_name' => $module_name, 'module_fields' => $module_fields, 'error' => $error->get_soap_array());
    }
    if (($_SESSION['type'] == 'portal' || $_SESSION['type'] == 'contact') && !key_exists($module_name, $valid_modules_for_contact)) {
        $error->set_error('no_module');
        return array('module_name' => $module_name, 'module_fields' => $module_fields, 'error' => $error->get_soap_array());
    }
    $class_name = $beanList[$module_name];
    require_once $beanFiles[$class_name];
    $seed = new $class_name();
    $seed->fill_in_additional_detail_fields();
    return get_return_module_fields($seed, $module_name, $error->get_soap_array());
}
示例#27
0
 /**
  * Get OAuth access token
  */
 public function oauth_access_token()
 {
     $GLOBALS['log']->info('Begin: SugarWebServiceImpl->oauth_access_token');
     require_once "include/SugarOAuthServer.php";
     try {
         $oauth = new SugarOAuthServer();
         $result = $oauth->accessToken();
     } catch (OAuthException $e) {
         $GLOBALS['log']->debug("OAUTH Exception: {$e}");
         $errorObject = new SoapError();
         $errorObject->set_error('invalid_login');
         self::$helperObject->setFaultObject($errorObject);
         $result = null;
     }
     $GLOBALS['log']->info('End: SugarWebServiceImpl->oauth_access_token');
     return $result;
 }
/**
 * Retrieve vardef information on the fields of the specified 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)..
 * @return Array    'module_fields' -- The vardef information on the selected fields.
 *                  'error' -- The SOAP error, if any
 */
function get_module_fields($session, $module_name)
{
    global $db;
    $error = new SoapError();
    $module_fields = array();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_session');
        return array('module_name' => $module_name, 'module_fields' => $module_fields, '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('module_name' => $module_name, 'module_fields' => $module_fields, '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('module_name' => $module_name, 'module_fields' => $module_fields, 'error' => $error->get_soap_array());
    }
    $module_fields = $db->MetaColumns($module_name);
    if (empty($module_fields)) {
        $error->set_error('no_records');
        return array('module_name' => $module_name, 'module_fields' => $module_fields, 'error' => $error->get_soap_array());
    }
    return array('module_name' => $module_name, 'module_fields' => get_field_list($module_fields), 'error' => $error->get_soap_array());
}