Index: trunk/core/kernel/db/dbitem.php =================================================================== diff -u -r3868 -r4029 --- trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 3868) +++ trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 4029) @@ -45,7 +45,7 @@ * @access public */ var $ID; - + function kDBItem() { parent::kDBBase(); @@ -372,7 +372,8 @@ if (!$system_update && $affected == 1){ $this->setModifiedFlag(); } - + + $this->saveCustomFields(); $this->raiseEvent('OnAfterItemUpdate'); return true; } @@ -651,7 +652,6 @@ $this->FieldValues[$this->IDField] = $this->generateID(); } - $fields_sql = ''; $values_sql = ''; foreach ($this->FieldValues as $field_name => $field_value) @@ -692,6 +692,7 @@ $this->setModifiedFlag(); } + $this->saveCustomFields(); $this->raiseEvent('OnAfterItemCreate'); return true; } @@ -889,6 +890,26 @@ } trigger_error('Query method is called in class '.get_class($this).' for prefix '.$this->getPrefixSpecial().'', E_USER_ERROR); } + + function saveCustomFields() + { + if (!$this->customFields) { + return true; + } + + $cdata_key = rtrim($this->Prefix.'-cdata.'.$this->Special, '.'); + $cdata =& $this->Application->recallObject($cdata_key, null, Array('skip_autoload' => true)); + + $resource_id = $this->GetDBField('ResourceId'); + $cdata->Load($resource_id, 'ResourceId'); + $cdata->SetDBField('ResourceId', $resource_id); + + $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + foreach ($this->customFields as $custom_id => $custom_name) { + $cdata->SetDBField($ml_formatter->LangFieldName('cust_'.$custom_id), $this->GetDBField('cust_'.$custom_name)); + } + return $cdata->isLoaded() ? $cdata->Update() : $cdata->Create(); + } }