Example #1
0
function clean_save_data($target_module, $action_array)
{
    global $app_list_strings;
    if (empty($app_list_strings)) {
        global $sugar_config;
        $app_list_strings = return_app_list_strings_language($sugar_config['default_language']);
    }
    foreach ($target_module->column_fields as $field) {
        if (empty($target_module->{$field})) {
            $data_cleaned = false;
            if ($target_module->field_defs[$field]['type'] == 'bool') {
                $target_module->{$field} = 0;
                $data_cleaned = true;
            }
            if (isset($target_module->field_defs[$field]['auto_increment']) && $target_module->field_defs[$field]['auto_increment']) {
                $target_module->{$field} = null;
                $data_cleaned = true;
            }
            // make sure there are options, some enums based on functions don't have options set
            if ($target_module->field_defs[$field]['type'] == 'enum' && isset($target_module->field_defs[$field]['options'])) {
                $options_array_name = $target_module->field_defs[$field]['options'];
                $target_module->{$field} = key($app_list_strings[$options_array_name]);
                $data_cleaned = true;
                //end if type is enum
            }
            if ($target_module->field_defs[$field]['name'] == 'duration_hours' || $target_module->field_defs[$field]['name'] == 'duration_minutes') {
                $target_module->{$field} = '0';
                $data_cleaned = true;
                //end if duration hours or minutes from calls module
            }
            if (($target_module->field_defs[$field]['name'] == 'date_start' || $target_module->field_defs[$field]['name'] == 'time_start') && ($target_module->object_name == "Call" || $target_module->object_name == "Meeting")) {
                $target_module->{$field} = get_expiry_date(get_field_type($target_module->field_defs[$field]), 0);
                if ($target_module->field_defs[$field]['type'] == 'date' && !empty($target_module->field_defs[$field]['rel_field'])) {
                    $rel_field = $target_module->field_defs[$field]['rel_field'];
                    $target_module->{$rel_field} = get_expiry_date('time', $action_array['basic'][$field]);
                }
                $data_cleaned = true;
            }
            if ($target_module->field_defs[$field]['name'] == 'date_entered') {
                $data_cleaned = true;
            }
            if ($target_module->field_defs[$field]['name'] == "name") {
                //make sure you set the 'name' to blank, otherwise you won't be able
                //to go into the record
                $target_module->{$field} = " - blank - ";
                $data_cleaned = true;
            }
            if ($data_cleaned == false) {
                //try to fill with default if available
                if (!empty($target_module->field_defs[$field]['default'])) {
                    $target_module->{$field} = $target_module->field_defs[$field]['default'];
                } else {
                    //fill in with blank value
                    $target_module->{$field} = "";
                }
            }
            //end if not empty
        }
        //end foreach
    }
    //end function clean_save_data
}
 /**
  * @deprecated
  */
 function get_expiry_date($bean_object, $time_interval, $is_update = false, $target_field = "none")
 {
     $target_stamp = null;
     if ($is_update) {
         if ($target_field == "none") {
             $target_stamp = TimeDate::getInstance()->nowDb();
         } else {
             if (!empty($bean_object->{$target_field})) {
                 //Date fields need to be reformated to datetimes to be used with scheduler
                 if ($bean_object->field_defs[$target_field]['type'] == "date" && is_string($bean_object->{$target_field})) {
                     $date = TimeDate::getInstance()->fromDbDate($bean_object->{$target_field});
                     $target_stamp = TimeDate::getInstance()->asDb($date);
                 } else {
                     $target_stamp = $bean_object->{$target_field};
                 }
             }
         }
     }
     return get_expiry_date("datetime", $time_interval, false, $is_update, $target_stamp);
 }