Index: trunk/kernel/include/item.php =================================================================== diff -u -r1201 -r1347 --- trunk/kernel/include/item.php (.../item.php) (revision 1201) +++ trunk/kernel/include/item.php (.../item.php) (revision 1347) @@ -124,21 +124,55 @@ /* item custom fields */ - function LoadCustomFields() - { - if(!$this->CustomLoaded && $this->Get("ResourceId")>0) + function LoadCustomFields($force = null) + { + if((!is_null($force) || !$this->CustomLoaded) && $this->Get("ResourceId")>0) { $this->FieldClass = new clsCustomFieldList(); $this->FieldClass->Type = $this->type; $this->FieldClass->LoadFieldsAndValues($this->Get("ResourceId")); foreach($this->FieldClass->Items as $f) { - $this->CustomFields[$f->Get("FieldName")] = $f->HasField('Value') ? $f->Get('Value') : ''; + if (strlen($f->Get("ValueList") && (($f->Get("ElementType") == "select") || ($f->Get("ElementType") == "radio")))) + { + if ($f->HasField('Value')) + { + $ValueList = explode(",", $f->Get("ValueList")); + if (is_array($ValueList)) + { + foreach ($ValueList as $curr => $value) + { + $c_data = explode("=", $value); + if ($c_data[0] == $f->Get('Value')) + { + $this->CustomFields[$f->Get("FieldName")]['value'] = $f->Get('Value'); + $this->CustomFields[$f->Get("FieldName")]['lang_value'] = language($c_data[1]); + } + } + } + else + { + $this->CustomFields[$f->Get("FieldName")]['value'] = $f->HasField('Value') ? $f->Get('Value') : ''; + $this->CustomFields[$f->Get("FieldName")]['lang_value'] = ''; + } + } + else + { + $this->CustomFields[$f->Get("FieldName")]['value'] = strlen($f->HasField('Value')) ? $f->Get('Value') : ''; + $this->CustomFields[$f->Get("FieldName")]['lang_value'] = ''; + } + } + else + { + $this->CustomFields[$f->Get("FieldName")]['value'] = strlen($f->HasField('Value')) ? $f->Get('Value') : ''; + $this->CustomFields[$f->Get("FieldName")]['lang_value'] = ''; + + } } $this->CustomLoaded = 1; } } - + function SetCustomField($fieldname,$value) { // echo "Setting CF [$fieldname] = [$value]
"; @@ -167,6 +201,7 @@ unset($data); } + /* function GetCustomFieldValue($fieldname,$default="") { if(!$this->CustomLoaded) @@ -189,8 +224,28 @@ $ret = $default; return $ret; } - - + */ + + function GetCustomFieldValue($fieldname, $default="", $ListValue = 0) + { + if(!$this->CustomLoaded) + $this->LoadCustomFields(null); + elseif (is_array($this->CustomFields) && empty($this->CustomFields)) + $this->LoadCustomFields(1); + + $fieldname = strtolower($fieldname); + + foreach($this->CustomFields as $k => $v) + { + if(strtolower($k) == $fieldname) + { + return $ListValue? $v['lang_value'] : $v['value']; + } + } + + return $default; + } + function DeleteCustomData() { $cdata = new clsCustomDataList();