function save_lines($post_data, $parent, $key = '') { $line_count = count($post_data[$key . 'action']); $j = 0; for ($i = 0; $i < $line_count; ++$i) { if ($post_data[$key . 'deleted'][$i] == 1) { $this->mark_deleted($post_data[$key . 'id'][$i]); } else { $action = new AOW_Action(); foreach ($this->field_defs as $field_def) { if (isset($post_data[$key . $field_def['name']][$i])) { $action->{$field_def}['name'] = $post_data[$key . $field_def['name']][$i]; } } $params = array(); foreach ($post_data[$key . 'param'][$i] as $param_name => $param_value) { if ($param_name == 'value') { foreach ($param_value as $p_id => $p_value) { if ($post_data[$key . 'param'][$i]['value_type'][$p_id] == 'Value' && is_array($p_value)) { $param_value[$p_id] = encodeMultienumValue($p_value); } } } $params[$param_name] = $param_value; } $action->parameters = base64_encode(serialize($params)); if (trim($action->action) != '') { $action->action_order = ++$j; $action->assigned_user_id = $parent->assigned_user_id; $action->aow_workflow_id = $parent->id; $action->save(); } } } }
public function save(&$bean, $params, $field, $properties, $prefix = '') { if (isset($params[$prefix . $field])) { if ($params[$prefix . $field][0] === '' && !empty($params[$prefix . $field][1])) { unset($params[$prefix . $field][0]); } $bean->{$field} = encodeMultienumValue($params[$prefix . $field]); } }
function populateFromPost($prefix, &$focus, $skipRetrieve = false) { global $current_user; if (!empty($_REQUEST[$prefix . 'record']) && !$skipRetrieve) { $focus->retrieve($_REQUEST[$prefix . 'record']); } if (!empty($_POST['assigned_user_id']) && $focus->assigned_user_id != $_POST['assigned_user_id'] && $_POST['assigned_user_id'] != $current_user->id) { $GLOBALS['check_notify'] = true; } require_once 'include/SugarFields/SugarFieldHandler.php'; $sfh = new SugarFieldHandler(); foreach ($focus->field_defs as $field => $def) { $type = !empty($def['custom_type']) ? $def['custom_type'] : $def['type']; $sf = $sfh->getSugarField(ucfirst($type), true); if ($sf != null) { $sf->save($focus, $_POST, $field, $def); } if (isset($_POST[$prefix . $field])) { if (is_array($_POST[$prefix . $field]) && !empty($focus->field_defs[$field]['isMultiSelect'])) { if (empty($_POST[$prefix . $field][0])) { unset($_POST[$prefix . $field][0]); } $_POST[$prefix . $field] = encodeMultienumValue($_POST[$prefix . $field]); } $focus->{$field} = $_POST[$prefix . $field]; /* * overrides the passed value for booleans. * this will be fully deprecated when the change to binary booleans is complete. */ if (isset($focus->field_defs[$prefix . $field]) && $focus->field_defs[$prefix . $field]['type'] == 'bool' && isset($focus->field_defs[$prefix . $field]['options'])) { $opts = explode("|", $focus->field_defs[$prefix . $field]['options']); $bool = $_POST[$prefix . $field]; if (is_int($bool) || ($bool === "0" || $bool === "1" || $bool === "2")) { // 1=on, 2=off $selection = $_POST[$prefix . $field] == "0" ? 1 : 0; } elseif (is_bool($_POST[$prefix . $field])) { // true=on, false=off $selection = $_POST[$prefix . $field] ? 0 : 1; } $focus->{$field} = $opts[$selection]; } } else { if (!empty($focus->field_defs[$field]['isMultiSelect']) && !isset($_POST[$prefix . $field]) && isset($_POST[$prefix . $field . '_multiselect'])) { $focus->{$field} = ''; } } } foreach ($focus->additional_column_fields as $field) { if (isset($_POST[$prefix . $field])) { $value = $_POST[$prefix . $field]; $focus->{$field} = $value; } } return $focus; }
function requestToUserParameters() { $params = array(); foreach ($_REQUEST['parameter_id'] as $key => $parameterId) { if ($_REQUEST['parameter_type'][$key] === 'Multi') { $_REQUEST['parameter_value'][$key] = encodeMultienumValue(explode(',', $_REQUEST['parameter_value'][$key])); } $params[$parameterId] = array('id' => $parameterId, 'operator' => $_REQUEST['parameter_operator'][$key], 'type' => $_REQUEST['parameter_type'][$key], 'value' => $_REQUEST['parameter_value'][$key]); } return $params; }
function save_lines($post_data, $parent, $key = '') { require_once 'modules/AOW_WorkFlow/aow_utils.php'; $line_count = count($post_data[$key . 'field']); $j = 0; for ($i = 0; $i < $line_count; ++$i) { if ($post_data[$key . 'deleted'][$i] == 1) { $this->mark_deleted($post_data[$key . 'id'][$i]); } else { $condition = new AOR_Condition(); foreach ($this->field_defs as $field_def) { if (isset($post_data[$key . $field_def['name']][$i])) { if (is_array($post_data[$key . $field_def['name']][$i])) { switch ($condition->value_type) { case 'Date': $post_data[$key . $field_def['name']][$i] = base64_encode(serialize($post_data[$key . $field_def['name']][$i])); default: $post_data[$key . $field_def['name']][$i] = encodeMultienumValue($post_data[$key . $field_def['name']][$i]); } } else { if ($field_def['name'] == 'value') { $post_data[$key . $field_def['name']][$i] = fixUpFormatting($_REQUEST['report_module'], $condition->field, $post_data[$key . $field_def['name']][$i]); } else { if ($field_def['name'] == 'parameter') { $post_data[$key . $field_def['name']][$i] = isset($post_data[$key . $field_def['name']][$i]); } else { if ($field_def['name'] == 'module_path') { $post_data[$key . $field_def['name']][$i] = base64_encode(serialize(explode(":", $post_data[$key . $field_def['name']][$i]))); } } } } $condition->{$field_def}['name'] = $post_data[$key . $field_def['name']][$i]; } else { if ($field_def['name'] == 'parameter') { $condition->{$field_def}['name'] = 0; } } } // Period must be saved as a string instead of a base64 encoded datetime. // Overwriting value if ($condition->value_type == 'Period') { $condition->value = base64_encode($_POST['aor_conditions_value'][$i]); // $condition->value = $_POST['aor_conditions_value'][$i]; } if (trim($condition->field) != '') { $condition->condition_order = ++$j; $condition->aor_report_id = $parent->id; $condition->save(); } } } }
function save_lines($post_data, $parent, $key = '') { require_once 'modules/AOW_WorkFlow/aow_utils.php'; $line_count = count($post_data[$key . 'field']); $j = 0; for ($i = 0; $i < $line_count; ++$i) { if ($post_data[$key . 'deleted'][$i] == 1) { $this->mark_deleted($post_data[$key . 'id'][$i]); } else { $condition = new AOW_Condition(); foreach ($this->field_defs as $field_def) { if (isset($post_data[$key . $field_def['name']][$i])) { if (is_array($post_data[$key . $field_def['name']][$i])) { if ($field_def['name'] == 'module_path') { $post_data[$key . $field_def['name']][$i] = base64_encode(serialize($post_data[$key . $field_def['name']][$i])); } else { switch ($condition->value_type) { case 'Date': $post_data[$key . $field_def['name']][$i] = base64_encode(serialize($post_data[$key . $field_def['name']][$i])); default: $post_data[$key . $field_def['name']][$i] = encodeMultienumValue($post_data[$key . $field_def['name']][$i]); } } } else { if ($field_def['name'] === 'value' && $post_data[$key . 'value_type'][$i] === 'Value') { $post_data[$key . $field_def['name']][$i] = fixUpFormatting($_REQUEST['flow_module'], $condition->field, $post_data[$key . $field_def['name']][$i]); } } $condition->{$field_def}['name'] = $post_data[$key . $field_def['name']][$i]; } } if (trim($condition->field) != '') { $condition->condition_order = ++$j; $condition->assigned_user_id = $parent->assigned_user_id; $condition->aow_workflow_id = $parent->id; $condition->save(); } } } }
function requestToUserParameters() { $params = array(); if (isset($_REQUEST['parameter_id']) && $_REQUEST['parameter_id']) { foreach ($_REQUEST['parameter_id'] as $key => $parameterId) { if ($_REQUEST['parameter_type'][$key] === 'Multi') { $_REQUEST['parameter_value'][$key] = encodeMultienumValue(explode(',', $_REQUEST['parameter_value'][$key])); } $params[$parameterId] = array('id' => $parameterId, 'operator' => $_REQUEST['parameter_operator'][$key], 'type' => $_REQUEST['parameter_type'][$key], 'value' => $_REQUEST['parameter_value'][$key]); // Fix for issue #1272 - AOR_Report module cannot update Date type parameter. if ($_REQUEST['parameter_type'][$key] === 'Date') { $values = array(); $values[] = $_REQUEST['parameter_value'][0]; $values[] = $_REQUEST['parameter_value'][1]; $values[] = $_REQUEST['parameter_value'][2]; $values[] = $_REQUEST['parameter_value'][3]; $params[$parameterId] = array('id' => $parameterId, 'operator' => $_REQUEST['parameter_operator'][$key], 'type' => $_REQUEST['parameter_type'][$key], 'value' => $values); } } } return $params; }
function save($df) { if (isset($this->default)) { if (is_array($this->default)) { $this->default = encodeMultienumValue($this->default); } $this->ext4 = isset($this->dependency) ? serialize(array('default' => $this->default, 'dependency' => $this->dependency)) : $this->default; } else { if (isset($this->dependency)) { $this->ext4 = serialize(array('dependency' => $this->dependency)); } } parent::save($df); }
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()); } }
/** * @ticket 37842 */ public function testValidMultiEnumWhenSpacesExistInTheValue() { $vardefs = array('options' => 'salutation_dom'); $this->assertEquals($this->_ifs->multienum('Mr., Mrs.', $vardefs), encodeMultienumValue(array('Mr.', 'Mrs.'))); }
protected function populateDefaultMapValue($field, $fieldValue, $fieldDef) { global $timedate, $current_user; if (is_array($fieldValue)) { $defaultRowValue = encodeMultienumValue($fieldValue); } else { $defaultRowValue = $_REQUEST[$field]; } // translate default values to the date/time format for the import file if ($fieldDef['type'] == 'date' && $this->ifs->dateformat != $timedate->get_date_format()) { $defaultRowValue = $timedate->swap_formats($defaultRowValue, $this->ifs->dateformat, $timedate->get_date_format()); } if ($fieldDef['type'] == 'time' && $this->ifs->timeformat != $timedate->get_time_format()) { $defaultRowValue = $timedate->swap_formats($defaultRowValue, $this->ifs->timeformat, $timedate->get_time_format()); } if (($fieldDef['type'] == 'datetime' || $fieldDef['type'] == 'datetimecombo') && $this->ifs->dateformat . ' ' . $this->ifs->timeformat != $timedate->get_date_time_format()) { $defaultRowValue = $timedate->swap_formats($defaultRowValue, $this->ifs->dateformat . ' ' . $this->ifs->timeformat, $timedate->get_date_time_format()); } if (in_array($fieldDef['type'], array('currency', 'float', 'int', 'num')) && $this->ifs->num_grp_sep != $current_user->getPreference('num_grp_sep')) { $defaultRowValue = str_replace($current_user->getPreference('num_grp_sep'), $this->ifs->num_grp_sep, $defaultRowValue); } if (in_array($fieldDef['type'], array('currency', 'float')) && $this->ifs->dec_sep != $current_user->getPreference('dec_sep')) { $defaultRowValue = str_replace($current_user->getPreference('dec_sep'), $this->ifs->dec_sep, $defaultRowValue); } $user_currency_symbol = $this->defaultUserCurrency->symbol; if ($fieldDef['type'] == 'currency' && $this->ifs->currency_symbol != $user_currency_symbol) { $defaultRowValue = str_replace($user_currency_symbol, $this->ifs->currency_symbol, $defaultRowValue); } return $defaultRowValue; }
/** * Creates proper representation of multienum value from actions_array.php * * @param string $value * @return string */ function workflow_convert_multienum_value($value) { // this is weird, but new value is stored in workflow definition as a partially // encoded string — without leading and trailing ^s, but with delimiting ^s and commas. // thus we pretend it's a single value and wrap it into array in order to get the leading and trailing ^s // @see parse_multi_array() return encodeMultienumValue(array($value)); }
function saveField($field, $id, $module, $value) { $bean = BeanFactory::getBean($module, $id); if (is_object($bean) && $bean->id != "") { if ($bean->field_defs[$field]['type'] == "multienum") { $bean->{$field} = encodeMultienumValue($value); } else { if ($bean->field_defs[$field]['type'] == "relate") { $save_field = $bean->field_defs[$field]['id_name']; $bean->{$save_field} = $value; } else { $bean->{$field} = $value; } } $bean->save(); return getDisplayValue($bean, $field); } else { return false; } }
function saveField($field, $id, $module, $value) { $bean = BeanFactory::getBean($module, $id); if (is_object($bean) && $bean->id != "") { if ($bean->field_defs[$field]['type'] == "multienum") { $bean->{$field} = encodeMultienumValue($value); } else { if ($bean->field_defs[$field]['type'] == "relate" || $bean->field_defs[$field]['type'] == 'parent') { $save_field = $bean->field_defs[$field]['id_name']; $bean->{$save_field} = $value; if ($bean->field_defs[$field]['type'] == 'parent') { $bean->parent_type = $_REQUEST['parent_type']; $bean->fill_in_additional_parent_fields(); // get up to date parent info as need it to display name } } else { $bean->{$field} = $value; } } $bean->save(); return getDisplayValue($bean, $field); } else { return false; } }
} $value = encodeMultienumValue($value); } $focus->merge_bean->{$field} = $value; } elseif (isset($focus->merge_bean->field_name_map[$field]['type']) && $focus->merge_bean->field_name_map[$field]['type'] == 'bool') { $focus->merge_bean->{$field} = 0; } } foreach ($focus->merge_bean->additional_column_fields as $field) { if (isset($_POST[$field])) { $value = $_POST[$field]; if (is_array($value) && !empty($focus->merge_bean->field_defs[$field]->properties['isMultiSelect'])) { if (empty($value[0])) { unset($value[0]); } $value = encodeMultienumValue($value); } $focus->merge_bean->{$field} = $value; } } global $check_notify; $_REQUEST['useEmailWidget'] = true; if (isset($_POST['date_entered'])) { // set this to true so we won't unset date_entered when saving $focus->merge_bean->update_date_entered = true; } $focus->merge_bean->save($check_notify); unset($_REQUEST['useEmailWidget']); $return_id = $focus->merge_bean->id; $return_module = $focus->merge_module; $return_action = 'DetailView';
/** * Do some processing before saving the bean to the database. */ public function pre_save() { if (!empty($_POST['assigned_user_id']) && $_POST['assigned_user_id'] != $this->bean->assigned_user_id && $_POST['assigned_user_id'] != $GLOBALS['current_user']->id && empty($GLOBALS['sugar_config']['exclude_notifications'][$this->bean->module_dir])) { $this->bean->notify_on_save = true; } $GLOBALS['log']->debug("SugarController:: performing pre_save."); require_once 'include/SugarFields/SugarFieldHandler.php'; $sfh = new SugarFieldHandler(); foreach ($this->bean->field_defs as $field => $properties) { $type = !empty($properties['custom_type']) ? $properties['custom_type'] : $properties['type']; $sf = $sfh->getSugarField(ucfirst($type), true); if (isset($_POST[$field])) { if (is_array($_POST[$field]) && !empty($properties['isMultiSelect'])) { if (empty($_POST[$field][0])) { unset($_POST[$field][0]); } $_POST[$field] = encodeMultienumValue($_POST[$field]); } $this->bean->{$field} = $_POST[$field]; } else { if (!empty($properties['isMultiSelect']) && !isset($_POST[$field]) && isset($_POST[$field . '_multiselect'])) { $this->bean->{$field} = ''; } } if ($sf != null) { $sf->save($this->bean, $_POST, $field, $properties); } } foreach ($this->bean->relationship_fields as $field => $link) { if (!empty($_POST[$field])) { $this->bean->{$field} = $_POST[$field]; } } if (!$this->bean->ACLAccess('save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } $this->bean->unformat_all_fields(); }
/** * Validate multienum fields * * @param $value string * @param $vardef array * @return string sanitized and validated value on success, bool false on failure */ public function multienum($value, $vardef) { if (!empty($value) && is_array($value)) { $enum_list = $value; } else { // If someone was using the old style multienum import technique $value = str_replace("^", "", $value); // We will need to break it apart to put test it. $enum_list = explode(",", $value); } // parse to see if all the values given are valid foreach ($enum_list as $enum_value) { if ($this->enum($enum_value, $vardef) === false) { return false; } } $value = encodeMultienumValue($enum_list); return $value; }
function saveField($field, $id, $module, $value) { global $current_user; $bean = BeanFactory::getBean($module, $id); if (is_object($bean) && $bean->id != "") { if ($bean->field_defs[$field]['type'] == "multienum") { $bean->{$field} = encodeMultienumValue($value); } else { if ($bean->field_defs[$field]['type'] == "relate" || $bean->field_defs[$field]['type'] == 'parent') { $save_field = $bean->field_defs[$field]['id_name']; $bean->{$save_field} = $value; if ($bean->field_defs[$field]['type'] == 'parent') { $bean->parent_type = $_REQUEST['parent_type']; $bean->fill_in_additional_parent_fields(); // get up to date parent info as need it to display name } } else { $bean->{$field} = $value; } } $check_notify = FALSE; if (isset($bean->fetched_row['assigned_user_id']) && $field == "assigned_user_name") { $old_assigned_user_id = $bean->fetched_row['assigned_user_id']; if (!empty($value) && $old_assigned_user_id != $value && $value != $current_user->id) { $check_notify = TRUE; } } $bean->save($check_notify); return getDisplayValue($bean, $field); } else { return false; } }
$contactForm = new ContactFormBase(); require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); require_once 'modules/Opportunities/OpportunityFormBase.php'; $oppForm = new OpportunityFormBase(); require_once 'modules/Leads/LeadFormBase.php'; $leadForm = new LeadFormBase(); $lead = new Lead(); $lead->retrieve($_REQUEST['record']); $linked_beans[] = $lead->get_linked_beans('calls', 'Call'); $linked_beans[] = $lead->get_linked_beans('meetings', 'Meeting'); $linked_beans[] = $lead->get_linked_beans('emails', 'Email'); $GLOBALS['check_notify'] = FALSE; foreach ($_POST as $k => $v) { if (is_array($v)) { $val = encodeMultienumValue($_POST[$k]); $_POST[$k] = $val; } } $formbody = array(); $sugar_smarty->assign('SAVE_BUTTON_DISPLAY', 'style="display:none;"'); $sugar_smarty->assign('CANCEL_BUTTON_DISPLAY', 'style="display:none;"'); if (!isset($_POST['selectedContact']) && !isset($_POST['ContinueContact'])) { $duplicateContacts = $contactForm->checkForDuplicates('Contacts'); if (isset($duplicateContacts)) { $sugar_smarty->assign('DUPLICATEFORMBODY', $contactForm->buildTableForm($duplicateContacts, 'Contacts')); $selected_menu = 'form'; echo $sugar_smarty->fetch('modules/Leads/ConvertLead.tpl'); return; } }
/** * Function checks if the multienum field is custom, and escapes it with carets (^) if it is * @param array $layout_def field layout definition * @param string $value value to be escaped * @return string */ private function encodeMultienumCustom($layout_def, $value) { $field_def = $this->reporter->getFieldDefFromLayoutDef($layout_def); // Check if it is a custom field if (!empty($field_def['source']) && ($field_def['source'] == 'custom_fields' || $field_def['source'] == 'non-db' && !empty($field_def['ext2']) && !empty($field_def['id'])) && !empty($field_def['real_table'])) { $value = encodeMultienumValue(array($value)); } return $value; }
/** * @see SugarView::display() */ public function display() { global $sugar_config; // Increase the max_execution_time since this step can take awhile ini_set("max_execution_time", max($sugar_config['import_max_execution_time'], 3600)); // stop the tracker TrackerManager::getInstance()->pause(); // use our own error handler set_error_handler('handleImportErrors', E_ALL); global $mod_strings, $app_strings, $current_user, $import_bean_map; global $app_list_strings, $timedate; $update_only = isset($_REQUEST['import_type']) && $_REQUEST['import_type'] == 'update'; $firstrow = unserialize(base64_decode($_REQUEST['firstrow'])); // All the Look Up Caches are initialized here $enum_lookup_cache = array(); // Let's try and load the import bean $focus = loadImportBean($_REQUEST['import_module']); if (!$focus) { trigger_error($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'], E_USER_ERROR); } // setup the importable fields array. $importable_fields = $focus->get_importable_fields(); // loop through all request variables $importColumns = array(); foreach ($_REQUEST as $name => $value) { // only look for var names that start with "fieldNum" if (strncasecmp($name, "colnum_", 7) != 0) { continue; } // pull out the column position for this field name $pos = substr($name, 7); if (isset($importable_fields[$value])) { // now mark that we've seen this field $importColumns[$pos] = $value; } } // set the default locale settings $ifs = new ImportFieldSanitize(); $ifs->dateformat = $_REQUEST['importlocale_dateformat']; $ifs->timeformat = $_REQUEST['importlocale_timeformat']; $ifs->timezone = $_REQUEST['importlocale_timezone']; $currency = new Currency(); $currency->retrieve($_REQUEST['importlocale_currency']); $ifs->currency_symbol = $currency->symbol; $ifs->default_currency_significant_digits = $_REQUEST['importlocale_default_currency_significant_digits']; $ifs->num_grp_sep = $_REQUEST['importlocale_num_grp_sep']; $ifs->dec_sep = $_REQUEST['importlocale_dec_sep']; $ifs->default_locale_name_format = $_REQUEST['importlocale_default_locale_name_format']; // Check to be sure we are getting an import file that is in the right place if (realpath(dirname($_REQUEST['tmp_file']) . '/') != realpath($sugar_config['upload_dir'])) { trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR); } // Open the import file $importFile = new ImportFile($_REQUEST['tmp_file'], $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES)); if (!$importFile->fileExists()) { trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR); } $fieldDefs = $focus->getFieldDefinitions(); unset($focus); while ($row = $importFile->getNextRow()) { $focus = loadImportBean($_REQUEST['import_module']); $focus->unPopulateDefaultValues(); $focus->save_from_post = false; $focus->team_id = null; $ifs->createdBeans = array(); $do_save = true; for ($fieldNum = 0; $fieldNum < $_REQUEST['columncount']; $fieldNum++) { // loop if this column isn't set if (!isset($importColumns[$fieldNum])) { continue; } // get this field's properties $field = $importColumns[$fieldNum]; $fieldDef = $focus->getFieldDefinition($field); $fieldTranslated = translate(isset($fieldDef['vname']) ? $fieldDef['vname'] : $fieldDef['name'], $_REQUEST['module']) . " (" . $fieldDef['name'] . ")"; // Bug 37241 - Don't re-import over a field we already set during the importing of another field if (!empty($focus->{$field})) { continue; } //DETERMINE WHETHER OR NOT $fieldDef['name'] IS DATE_MODIFIED AND SET A VAR, USE DOWN BELOW // translate strings global $locale; if (empty($locale)) { $locale = new Localization(); } if (isset($row[$fieldNum])) { $rowValue = $locale->translateCharset(strip_tags(trim($row[$fieldNum])), $_REQUEST['importlocale_charset'], $sugar_config['default_charset']); } else { $rowValue = ''; } // If there is an default value then use it instead if (!empty($_REQUEST[$field])) { if (is_array($_REQUEST[$field])) { $defaultRowValue = encodeMultienumValue($_REQUEST[$field]); } else { $defaultRowValue = $_REQUEST[$field]; } // translate default values to the date/time format for the import file if ($fieldDef['type'] == 'date' && $ifs->dateformat != $timedate->get_date_format()) { $defaultRowValue = $timedate->swap_formats($defaultRowValue, $ifs->dateformat, $timedate->get_date_format()); } if ($fieldDef['type'] == 'time' && $ifs->timeformat != $timedate->get_time_format()) { $defaultRowValue = $timedate->swap_formats($defaultRowValue, $ifs->timeformat, $timedate->get_time_format()); } if (($fieldDef['type'] == 'datetime' || $fieldDef['type'] == 'datetimecombo') && $ifs->dateformat . ' ' . $ifs->timeformat != $timedate->get_date_time_format()) { $defaultRowValue = $timedate->swap_formats($defaultRowValue, $ifs->dateformat . ' ' . $ifs->timeformat, $timedate->get_date_time_format()); } if (in_array($fieldDef['type'], array('currency', 'float', 'int', 'num')) && $ifs->num_grp_sep != $current_user->getPreference('num_grp_sep')) { $defaultRowValue = str_replace($current_user->getPreference('num_grp_sep'), $ifs->num_grp_sep, $defaultRowValue); } if (in_array($fieldDef['type'], array('currency', 'float')) && $ifs->dec_sep != $current_user->getPreference('dec_sep')) { $defaultRowValue = str_replace($current_user->getPreference('dec_sep'), $ifs->dec_sep, $defaultRowValue); } $currency->retrieve('-99'); $user_currency_symbol = $currency->symbol; if ($fieldDef['type'] == 'currency' && $ifs->currency_symbol != $user_currency_symbol) { $defaultRowValue = str_replace($user_currency_symbol, $ifs->currency_symbol, $defaultRowValue); } if (empty($rowValue)) { $rowValue = $defaultRowValue; unset($defaultRowValue); } } // Bug 22705 - Don't update the First Name or Last Name value if Full Name is set if (in_array($field, array('first_name', 'last_name')) && !empty($focus->full_name)) { continue; } // loop if this value has not been set if (!isset($rowValue)) { continue; } // If the field is required and blank then error out if (array_key_exists($field, $focus->get_import_required_fields()) && empty($rowValue) && $rowValue != '0') { $importFile->writeError($mod_strings['LBL_REQUIRED_VALUE'], $fieldTranslated, 'NULL'); $do_save = false; } // Handle the special case "Sync to Outlook" if ($focus->object_name == "Contacts" && $field == 'sync_contact') { $bad_names = array(); $returnValue = $ifs->synctooutlook($rowValue, $fieldDef, $bad_names); // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $ifs->synctooutlook($defaultRowValue, $fieldDef, $bad_names); } if (!$returnValue) { $importFile->writeError($mod_strings['LBL_ERROR_SYNC_USERS'], $fieldTranslated, explode(",", $bad_names)); $do_save = 0; } } // Handle email1 and email2 fields ( these don't have the type of email ) if ($field == 'email1' || $field == 'email2') { $returnValue = $ifs->email($rowValue, $fieldDef); // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $ifs->email($defaultRowValue, $fieldDef); } if ($returnValue === FALSE) { $do_save = 0; $importFile->writeError($mod_strings['LBL_ERROR_INVALID_EMAIL'], $fieldTranslated, $rowValue); } else { $rowValue = $returnValue; // check for current opt_out and invalid email settings for this email address // if we find any, set them now $emailres = $focus->db->query("SELECT opt_out, invalid_email FROM email_addresses \n WHERE email_address = '" . $focus->db->quote($rowValue) . "'"); if ($emailrow = $focus->db->fetchByAssoc($emailres)) { $focus->email_opt_out = $emailrow['opt_out']; $focus->invalid_email = $emailrow['invalid_email']; } } } // Handle splitting Full Name into First and Last Name parts if ($field == 'full_name' && !empty($rowValue)) { $ifs->fullname($rowValue, $fieldDef, $focus); } // to maintain 451 compatiblity if (!isset($fieldDef['module']) && $fieldDef['type'] == 'relate') { $fieldDef['module'] = ucfirst($fieldDef['table']); } if (isset($fieldDef['custom_type']) && !empty($fieldDef['custom_type'])) { $fieldDef['type'] = $fieldDef['custom_type']; } // If the field is empty then there is no need to check the data if (!empty($rowValue)) { switch ($fieldDef['type']) { case 'enum': case 'multienum': if (isset($fieldDef['type']) && $fieldDef['type'] == "multienum") { $returnValue = $ifs->multienum($rowValue, $fieldDef); } else { $returnValue = $ifs->enum($rowValue, $fieldDef); } // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { if (isset($fieldDef['type']) && $fieldDef['type'] == "multienum") { $returnValue = $ifs->multienum($defaultRowValue, $fieldDef); } else { $returnValue = $ifs->enum($defaultRowValue, $fieldDef); } } if ($returnValue === FALSE) { $importFile->writeError($mod_strings['LBL_ERROR_NOT_IN_ENUM'] . implode(",", $app_list_strings[$fieldDef['options']]), $fieldTranslated, $rowValue); $do_save = 0; } else { $rowValue = $returnValue; } break; case 'relate': case 'parent': $returnValue = $ifs->relate($rowValue, $fieldDef, $focus, empty($defaultRowValue)); if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $ifs->relate($defaultRowValue, $fieldDef, $focus); } // Bug 33623 - Set the id value found from the above method call as an importColumn if ($returnValue !== false) { $importColumns[] = $fieldDef['id_name']; } break; case 'teamset': $returnValue = $ifs->teamset($rowValue, $fieldDef, $focus); $importColumns[] = 'team_set_id'; $importColumns[] = 'team_id'; break; case 'fullname': break; default: if (method_exists('ImportFieldSanitize', $fieldDef['type'])) { $fieldtype = $fieldDef['type']; $returnValue = $ifs->{$fieldtype}($rowValue, $fieldDef); // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $ifs->{$fieldtype}($defaultRowValue, $fieldDef); } if (!$returnValue) { $do_save = 0; $importFile->writeError($mod_strings['LBL_ERROR_INVALID_' . strtoupper($fieldDef['type'])], $fieldTranslated, $rowValue); } else { $rowValue = $returnValue; } } } } $focus->{$field} = $rowValue; unset($defaultRowValue); } // Now try to validate flex relate fields if (isset($focus->field_defs['parent_name']) && isset($focus->parent_name) && $focus->field_defs['parent_name']['type'] == 'parent') { // populate values from the picker widget if the import file doesn't have them $parent_idField = $focus->field_defs['parent_name']['id_name']; if (empty($focus->{$parent_idField}) && !empty($_REQUEST[$parent_idField])) { $focus->{$parent_idField} = $_REQUEST[$parent_idField]; } $parent_typeField = $focus->field_defs['parent_name']['type_name']; if (empty($focus->{$parent_typeField}) && !empty($_REQUEST[$parent_typeField])) { $focus->{$parent_typeField} = $_REQUEST[$parent_typeField]; } // now validate it $returnValue = $ifs->parent($focus->parent_name, $focus->field_defs['parent_name'], $focus, empty($_REQUEST['parent_name'])); if (!$returnValue && !empty($_REQUEST['parent_name'])) { $returnValue = $ifs->parent($_REQUEST['parent_name'], $focus->field_defs['parent_name'], $focus); } } // check to see that the indexes being entered are unique. if (isset($_REQUEST['display_tabs_def']) && $_REQUEST['display_tabs_def'] != "") { $idc = new ImportDuplicateCheck($focus); if ($idc->isADuplicateRecord(explode('&', $_REQUEST['display_tabs_def']))) { $importFile->markRowAsDuplicate(); $this->_undoCreatedBeans($ifs->createdBeans); continue; } } // if the id was specified $newRecord = true; if (!empty($focus->id)) { $focus->id = $this->_convertId($focus->id); // check if it already exists $query = "SELECT * FROM {$focus->table_name} WHERE id='" . $focus->db->quote($focus->id) . "'"; $result = $focus->db->query($query) or sugar_die("Error selecting sugarbean: "); $dbrow = $focus->db->fetchByAssoc($result); if (isset($dbrow['id']) && $dbrow['id'] != -1) { // if it exists but was deleted, just remove it if (isset($dbrow['deleted']) && $dbrow['deleted'] == 1 && $update_only == false) { $query2 = "DELETE FROM {$focus->table_name} WHERE id='" . $focus->db->quote($focus->id) . "'"; $result2 = $focus->db->query($query2) or sugar_die($mod_strings['LBL_ERROR_DELETING_RECORD'] . " " . $focus->id); if ($focus->hasCustomFields()) { $query3 = "DELETE FROM {$focus->table_name}_cstm WHERE id_c='" . $focus->db->quote($focus->id) . "'"; $result2 = $focus->db->query($query3); } $focus->new_with_id = true; } else { if (!$update_only) { $do_save = 0; $importFile->writeError($mod_strings['LBL_ID_EXISTS_ALREADY'], 'ID', $focus->id); $this->_undoCreatedBeans($ifs->createdBeans); continue; } $existing_focus = loadImportBean($_REQUEST['import_module']); $newRecord = false; if (!$existing_focus->retrieve($dbrow['id']) instanceof SugarBean) { $do_save = 0; $importFile->writeError($mod_strings['LBL_RECORD_CANNOT_BE_UPDATED'], 'ID', $focus->id); $this->_undoCreatedBeans($ifs->createdBeans); continue; } else { $newData = $focus->toArray(); foreach ($newData as $focus_key => $focus_value) { if (in_array($focus_key, $importColumns)) { $existing_focus->{$focus_key} = $focus_value; } } $focus = $existing_focus; } unset($existing_focus); } } else { $focus->new_with_id = true; } } if ($do_save) { // Populate in any default values to the bean $focus->populateDefaultValues(); if (!isset($focus->assigned_user_id) || $focus->assigned_user_id == '' && $newRecord) { $focus->assigned_user_id = $current_user->id; } /* * Bug 34854: Added all conditions besides the empty check on date modified. Currently, if * we do an update to a record, it doesn't update the date_modified value. * Hack note: I'm doing a to_display and back to_db on the fetched row to make sure that any truncating that happens * when $focus->date_modified goes to_display and back to_db also happens on the fetched db value. Otherwise, * in some cases we truncate the seconds on one and not the other, and the comparison fails when it should pass */ if (!empty($focus->new_with_id) && !empty($focus->date_modified) || empty($focus->new_with_id) && $timedate->to_db($focus->date_modified) != $timedate->to_db($timedate->to_display_date_time($focus->fetched_row['date_modified']))) { $focus->update_date_modified = false; } $focus->optimistic_lock = false; if ($focus->object_name == "Contacts" && isset($focus->sync_contact)) { //copy the potential sync list to another varible $list_of_users = $focus->sync_contact; //and set it to false for the save $focus->sync_contact = false; } else { if ($focus->object_name == "User" && !empty($current_user) && $focus->is_admin && !is_admin($current_user) && is_admin_for_module($current_user, 'Users')) { sugar_die($GLOBALS['mod_strings']['ERR_IMPORT_SYSTEM_ADMININSTRATOR']); } } //bug# 40260 setting it true as the module in focus is involved in an import $focus->in_import = true; // call any logic needed for the module preSave $focus->beforeImportSave(); $focus->save(false); // call any logic needed for the module postSave $focus->afterImportSave(); if ($focus->object_name == "Contacts" && isset($list_of_users)) { $focus->process_sync_to_outlook($list_of_users); } // Update the created/updated counter $importFile->markRowAsImported($newRecord); // Add ID to User's Last Import records if ($newRecord) { ImportFile::writeRowToLastImport($_REQUEST['import_module'], $focus->object_name == 'Case' ? 'aCase' : $focus->object_name, $focus->id); } } else { $this->_undoCreatedBeans($ifs->createdBeans); } } // save mapping if requested if (isset($_REQUEST['save_map_as']) && $_REQUEST['save_map_as'] != '') { $mapping_file = new ImportMap(); if (isset($_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on') { $header_to_field = array(); foreach ($importColumns as $pos => $field_name) { if (isset($firstrow[$pos]) && isset($field_name)) { $header_to_field[$firstrow[$pos]] = $field_name; } } $mapping_file->setMapping($header_to_field); } else { $mapping_file->setMapping($importColumns); } // save default fields $defaultValues = array(); for ($i = 0; $i < $_REQUEST['columncount']; $i++) { if (isset($importColumns[$i]) && !empty($_REQUEST[$importColumns[$i]])) { $field = $importColumns[$i]; $fieldDef = $focus->getFieldDefinition($field); if (!empty($fieldDef['custom_type']) && $fieldDef['custom_type'] == 'teamset') { require_once 'include/SugarFields/Fields/Teamset/SugarFieldTeamset.php'; $sugar_field = new SugarFieldTeamset('Teamset'); $teams = $sugar_field->getTeamsFromRequest($field); if (isset($_REQUEST['primary_team_name_collection'])) { $primary_index = $_REQUEST['primary_team_name_collection']; } //If primary_index was selected, ensure that the first Array entry is the primary team if (isset($primary_index)) { $count = 0; $new_teams = array(); foreach ($teams as $id => $name) { if ($primary_index == $count++) { $new_teams[$id] = $name; unset($teams[$id]); break; } } foreach ($teams as $id => $name) { $new_teams[$id] = $name; } $teams = $new_teams; } //if $json = getJSONobj(); $defaultValues[$field] = $json->encode($teams); } else { $defaultValues[$field] = $_REQUEST[$importColumns[$i]]; } } } $mapping_file->setDefaultValues($defaultValues); $result = $mapping_file->save($current_user->id, $_REQUEST['save_map_as'], $_REQUEST['import_module'], $_REQUEST['source'], isset($_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on', $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES)); } $importFile->writeStatus(); }
/** * @see SugarFieldBase::importSanitize() */ public function importSanitize($value, $vardef, $focus, ImportFieldSanitize $settings) { if (!empty($value) && is_array($value)) { $enum_list = $value; } else { // If someone was using the old style multienum import technique $value = str_replace("^", "", $value); // We will need to break it apart to put test it. $enum_list = explode(",", $value); } // parse to see if all the values given are valid foreach ($enum_list as $key => $enum_value) { $enum_list[$key] = $enum_value = trim($enum_value); $sanitizedValue = parent::importSanitize($enum_value, $vardef, $focus, $settings); if ($sanitizedValue === false) { return false; } else { $enum_list[$key] = $sanitizedValue; } } $value = encodeMultienumValue($enum_list); return $value; }
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()); } }
function save_lines($post_data, $parent, $key = '') { require_once 'modules/AOW_WorkFlow/aow_utils.php'; $line_count = count($post_data[$key . 'field']); $j = 0; for ($i = 0; $i < $line_count; ++$i) { if ($post_data[$key . 'deleted'][$i] == 1) { $this->mark_deleted($post_data[$key . 'id'][$i]); } else { $condition = new AOR_Condition(); foreach ($this->field_defs as $field_def) { $field_name = $field_def['name']; if (isset($post_data[$key . $field_name][$i])) { if (is_array($post_data[$key . $field_name][$i])) { switch ($condition->value_type) { case 'Date': $post_data[$key . $field_name][$i] = base64_encode(serialize($post_data[$key . $field_name][$i])); break; default: $post_data[$key . $field_name][$i] = encodeMultienumValue($post_data[$key . $field_name][$i]); } } else { if ($field_name == 'value' && $post_data[$key . 'value_type'][$i] === 'Value') { $post_data[$key . $field_name][$i] = fixUpFormatting($_REQUEST['report_module'], $condition->field, $post_data[$key . $field_name][$i]); } else { if ($field_name == 'parameter') { $post_data[$key . $field_name][$i] = isset($post_data[$key . $field_name][$i]); } else { if ($field_name == 'module_path') { $post_data[$key . $field_name][$i] = base64_encode(serialize(explode(":", $post_data[$key . $field_name][$i]))); } } } } if ($field_name == 'parenthesis' && $post_data[$key . $field_name][$i] == 'END') { if (!isset($lastParenthesisStartConditionId)) { throw new Exception('a closure parenthesis has no starter pair'); } $condition->parenthesis = $lastParenthesisStartConditionId; } else { $condition->{$field_name} = $post_data[$key . $field_name][$i]; } } else { if ($field_name == 'parameter') { $condition->{$field_name} = 0; } } } // Period must be saved as a string instead of a base64 encoded datetime. // Overwriting value if ((!isset($condition->parenthesis) || !$condition->parenthesis) && isset($condition->value_type) && $condition->value_type == 'Period') { $condition->value = base64_encode($_POST['aor_conditions_value'][$i]); } if (trim($condition->field) != '' || $condition->parenthesis) { if (isset($_POST['aor_conditions_order'][$i])) { $condition->condition_order = (int) $_POST['aor_conditions_order'][$i]; } else { $condition->condition_order = ++$j; } $condition->aor_report_id = $parent->id; $conditionId = $condition->save(); if ($condition->parenthesis == 'START') { $lastParenthesisStartConditionId = $conditionId; } } } } }
/** * @param $field * @param $value * @return string */ function addToColumns($field, $value) { if (!is_array($value) || is_array($value) && count($value) == 1) { if (is_array($value)) { $finalValue = implode("", $value); } else { $finalValue = $value; } $result = "{$field}='{$finalValue}'"; } else { $multiEnumValue = encodeMultienumValue($value); $result = "{$field}='{$multiEnumValue}'"; } return $result; }