Index: trunk/globals.php =================================================================== diff -u -N -r4077 -r4120 --- trunk/globals.php (.../globals.php) (revision 4077) +++ trunk/globals.php (.../globals.php) (revision 4120) @@ -2062,5 +2062,51 @@ { return preg_match('/(a|A)/', GetTimeFormat() ); } + + /** + * Saves custom fields for old in-portal items + * + * @param string $prefix K4 prefix of item + * @param int $resource_id resource id of item + * @param int $item_type type of custom fields + */ + function saveCustomFields($prefix, $resource_id, $item_type) + { + $objCustomEdit = new clsCustomDataList(); + $CustomFields = new clsCustomFieldList($item_type); + + $data_changed = false; + for ($i = 0; $i < $CustomFields->NumItems(); $i++) { + $objField =& $CustomFields->GetItemRefByIndex($i); + $field_name = $objField->Get('FieldName'); + + $value = getCustomValue($field_name); + if ($value !== false) { + $objCustomEdit->SetFieldValue($objField->Get('CustomFieldId'), $resource_id, $value); + $data_changed = true; + } + } + + if ($data_changed) { + $objCustomEdit->SaveData($prefix, $resource_id); + } + } + + /** + * Returns custom field value from submit + * + * @param string $field_name + * @return mixed + */ + function getCustomValue($field_name) + { + if (IsAdmin()) { + $field_name = '_'.$field_name; + } + elseif (isset($_POST[strtolower($field_name)])) { + $field_name = strtolower($field_name); + } + return GetVar($field_name); + } ?>