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) {
if ( $field == 'id' && !empty($focus->id) ) {
// Don't try and overwrite the ID
continue;
}
$type = !empty($def['custom_type']) ? $def['custom_type'] : $def['type'];
$sf = $sfh->getSugarField($type);
if($sf != null){
$sf->save($focus, $_POST, $field, $def, $prefix);
} else {
$GLOBALS['log']->fatal("Field '$field' does not have a SugarField handler");
}
/*
if(isset($_POST[$prefix.$field])) {
if(is_array($_POST[$prefix.$field]) && !empty($focus->field_defs[$field]['isMultiSelect'])) {
if($_POST[$prefix.$field][0] === '' && !empty($_POST[$prefix.$field][1]) ) {
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 add_hidden_elements($key, $value) {
$elements = '';
// if it's an array, we need to loop into the array and use square brackets []
if (is_array($value)) {
foreach ($value as $k=>$v) {
$elements .= "\n";
}
} else {
$elements = "\n";
}
return $elements;
}
function getPostToForm($ignore='', $isRegularExpression=false)
{
$fields = '';
if(!empty($ignore) && $isRegularExpression) {
foreach ($_POST as $key=>$value){
if(!preg_match($ignore, $key)) {
$fields .= add_hidden_elements($key, $value);
}
}
} else {
foreach ($_POST as $key=>$value){
if($key != $ignore) {
$fields .= add_hidden_elements($key, $value);
}
}
}
return $fields;
}
function getGetToForm($ignore='', $usePostAsAuthority = false)
{
$fields = '';
foreach ($_GET as $key=>$value)
{
if($key != $ignore){
if(!$usePostAsAuthority || !isset($_POST[$key])){
$fields.= "";
}
}
}
return $fields;
}
function getAnyToForm($ignore='', $usePostAsAuthority = false)
{
$fields = getPostToForm($ignore);
$fields .= getGetToForm($ignore, $usePostAsAuthority);
return $fields;
}
function handleRedirect($return_id='', $return_module='')
{
if(isset($_REQUEST['return_url']) && $_REQUEST['return_url'] != "")
{
header("Location: ". $_REQUEST['return_url']);
exit;
}
$url = buildRedirectURL($return_id, $return_module);
header($url);
exit;
}
//eggsurplus: abstract to simplify unit testing
function buildRedirectURL($return_id='', $return_module='')
{
if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "")
{
$return_module = $_REQUEST['return_module'];
}
else
{
$return_module = $return_module;
}
if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "")
{
//if we are doing a "Close and Create New"
if(isCloseAndCreateNewPressed())
{
$return_action = "EditView";
$isDuplicate = "true";
$status = "";
// Meeting Integration
if(isset($_REQUEST['meetingIntegrationFlag']) && $_REQUEST['meetingIntegrationFlag'] == 1) {
$additionalFlags = array('meetingIntegrationShowForm' => '1');
}
// END Meeting Integration
}
// if we create a new record "Save", we want to redirect to the DetailView
else if(isset($_REQUEST['action']) && $_REQUEST['action'] == "Save"
&& $_REQUEST['return_module'] != 'Activities'
&& $_REQUEST['return_module'] != 'Home'
&& $_REQUEST['return_module'] != 'Forecasts'
&& $_REQUEST['return_module'] != 'Calendar'
&& $_REQUEST['return_module'] != 'MailMerge'
)
{
$return_action = 'DetailView';
} elseif($_REQUEST['return_module'] == 'Activities' || $_REQUEST['return_module'] == 'Calendar') {
$return_module = $_REQUEST['module'];
$return_action = $_REQUEST['return_action'];
// wp: return action needs to be set for one-click close in task list
}
else
{
// if we "Cancel", we go back to the list view.
$return_action = $_REQUEST['return_action'];
}
}
else
{
$return_action = "DetailView";
}
if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "")
{
$return_id = $_REQUEST['return_id'];
}
if (!isset($isDuplicate) || !$isDuplicate)
{
//eggsurplus Bug 23816: maintain VCR after an edit/save. If it is a duplicate then don't worry about it. The offset is now worthless.
$redirect_url = "Location: index.php?action=$return_action&module=$return_module&record=$return_id&return_module=$return_module&return_action=$return_action";
if(isset($_REQUEST['offset']) && empty($_REQUEST['duplicateSave'])) {
$redirect_url .= "&offset=".$_REQUEST['offset'];
}
return $redirect_url;
} else {
$standard = "action=$return_action&module=$return_module&record=$return_id&isDuplicate=true&return_module=$return_module&return_action=$return_action&status=$status";
$add = '';
if(isset($additionalFlags) && !empty($additionalFlags)) {
foreach($additionalFlags as $k => $v) {
if(!empty($add)) {
$add .= "&";
}
$add .= "{$k}={$v}";
}
}
if(!empty($add)) {
$add = "&" . $add;
}
return "Location: index.php?{$standard}{$add}";
}
}
function getLikeForEachWord($fieldname, $value, $minsize=4)
{
$value = trim($value);
$values = explode(' ',$value);
$ret = '';
foreach($values as $val)
{
if(strlen($val) >= $minsize)
{
if(!empty($ret))
{
$ret .= ' or';
}
$ret .= ' '. $fieldname . ' LIKE %'.$val.'%';
}
}
}
function isCloseAndCreateNewPressed() {
return isset($_REQUEST['action']) &&
$_REQUEST['action'] == "Save" &&
isset($_REQUEST['isSaveAndNew']) &&
$_REQUEST['isSaveAndNew'] == 'true';
}
?>