Index: trunk/kernel/include/config.php
===================================================================
diff -u -N -r6093 -r8009
--- trunk/kernel/include/config.php (.../config.php) (revision 6093)
+++ trunk/kernel/include/config.php (.../config.php) (revision 8009)
@@ -196,12 +196,21 @@
var $TabIndex = 0;
+ /**
+ * Application instance
+ *
+ * @var kApplication
+ */
+ var $Application = null;
+
function clsConfigAdminItem($config_name=NULL)
{
+ $this->Application =& kApplication::Instance();
$this->adodbConnection = &GetADODBConnection();
- if($config_name)
+ if ($config_name) {
$this->LoadSetting($config_name);
}
+ }
function LoadSetting($config_name)
{
@@ -221,57 +230,14 @@
}
}
- function explode_sql($sql)
+ function GetValues($string)
{
- $s = "";
-
- $rs = $this->adodbConnection->Execute($sql);
-
- while ($rs && !$rs->EOF)
- {
- if(strlen(trim($rs->fields["OptionName"]))>0 && strlen(trim($rs->fields["OptionValue"]))>0)
- {
- if(strlen($s))
- $s .= ",";
- $s .= $rs->fields["OptionValue"]."="."+".$rs->fields["OptionName"];
- }
- $rs->MoveNext();
- }
- return $s;
+ $cf_helper =& $this->Application->recallObject('InpCustomFieldsHelper');
+ /* @var $cf_helper InpCustomFieldsHelper */
+
+ return $cf_helper->GetValuesHash($string);
}
- function replace_sql($string, $start_mark = '')
- {
- $mark_length = strlen($start_mark);
- $string = str_replace("",GetTablePrefix(),$string);
-
- $start = strpos($string, $start_mark);
-
- while($start)
- {
- $end = strpos($string,"");
- if(!$end)
- {
- $end = strlen($string);
- }
- $len = $end - $start;
- $sql = substr($string,$start + $mark_length,$len - $mark_length);
-
- $sql_val = $this->explode_sql($sql);
- $s = substr($string, 0, $start) . $sql_val . substr($string, $end + $mark_length + 1);
-
- $string = $s;
- $start = strpos($string, $start_mark);
- }
-
- if ($start_mark == '') {
- // to prevent recursion. check new style of sqls too
- $string = $this->replace_sql($string, '');
- }
-
- return preg_replace('/(.*)$,/','\\1', $string);
- }
-
function ItemFormElement($StartFrom=1)
{
global $objConfig;
@@ -328,44 +294,23 @@
case 'radio':
$radioname = $this->name;
- $ValList = $this->replace_sql($this->ValueList);
-
$this->TabIndex++;
- $val = explode(',',$ValList);
- for($i=0;$i<=count($val);$i++)
- {
- if(strlen($val[$i]))
- {
- $parts = explode('=',$val[$i]);
- $s = $parts[1];
- if(strlen($s)==0)
- $s = '';
- $o .= 'default_value == $parts[0]) ? ' checked>' : '>';
-
- $o .= (substr($s,0,1)=="+") ? substr($s,1) : prompt_language($s);
- }
+ $values = $this->GetValues($this->ValueList);
+ foreach ($values as $option_id => $option_name) {
+ $o .= 'default_value == $option_id) ? ' checked>' : '>';
+ $o .= $option_name;
}
$this->TabIndex++;
break;
case 'select':
$o .= '';
break;
Index: trunk/kernel/include/item.php
===================================================================
diff -u -N -r7391 -r8009
--- trunk/kernel/include/item.php (.../item.php) (revision 7391)
+++ trunk/kernel/include/item.php (.../item.php) (revision 8009)
@@ -134,42 +134,28 @@
{
if (strlen($f->Get("ValueList") && (($f->Get("ElementType") == "select") || ($f->Get("ElementType") == "radio"))))
{
- if ($f->HasField('Value'))
- {
+ if ($f->HasField('Value')) {
$objConfigDummy = new clsConfigAdminItem();
- $ValueList = explode(",", $objConfigDummy->replace_sql($f->Get("ValueList")));
- if (is_array($ValueList))
- {
- foreach ($ValueList as $curr => $value)
- {
- $c_data = explode("=", $value);
- if ($c_data[0] == $f->Get('Value'))
- {
+ $ValueList = $objConfigDummy->GetValues($f->Get('ValueList'));
+ if (is_array($ValueList)) {
+ foreach ($ValueList as $option_id => $option_title) {
+ if ($option_id == $f->Get('Value')) {
$this->CustomFields[$f->Get("FieldName")]['value'] = $f->Get('Value');
- // if option value starts with + then not a language variable
- if (eregi("^+", $c_data[1]))
- $c_data[1] = language($c_data[1]);
- else
- $c_data[1] = substr($c_data[1], 1);
-
- $this->CustomFields[$f->Get("FieldName")]['lang_value'] = $c_data[1];
+ $this->CustomFields[$f->Get("FieldName")]['lang_value'] = $option_title;
}
}
}
- else
- {
+ else {
$this->CustomFields[$f->Get("FieldName")]['value'] = $f->HasField('Value') ? $f->Get('Value') : '';
$this->CustomFields[$f->Get("FieldName")]['lang_value'] = null;
}
}
- else
- {
+ else {
$this->CustomFields[$f->Get("FieldName")]['value'] = strlen($f->HasField('Value')) ? $f->Get('Value') : '';
$this->CustomFields[$f->Get("FieldName")]['lang_value'] = null;
}
}
- else
- {
+ else {
$this->CustomFields[$f->Get("FieldName")]['value'] = strlen($f->HasField('Value')) ? $f->Get('Value') : '';
$this->CustomFields[$f->Get("FieldName")]['lang_value'] = null;
Index: trunk/kernel/parser.php
===================================================================
diff -u -N -r7867 -r8009
--- trunk/kernel/parser.php (.../parser.php) (revision 7867)
+++ trunk/kernel/parser.php (.../parser.php) (revision 8009)
@@ -618,29 +618,23 @@
// 2. replace any sqls found there
$objConfigDummy = new clsConfigAdminItem();
- $values = $objConfigDummy->replace_sql($values);
+ $values = $objConfigDummy->GetValues($values);
if(!$values) return '';
- if( GetVar($field) )
- {
+ if (GetVar($field)) {
$value = GetVar($field);
}
- else
- {
+ else {
$value = $FormValues[$form][$field];
if( is_array($value) ) $value = $value['value'];
}
$ret = '';
- $values = explode(',', $values);
$option_tpl = '';
- foreach($values as $mixed_value)
- {
- $mixed_value = explode('=', $mixed_value);
- $label = substr($mixed_value[1],0,1) == '+' ? substr($mixed_value[1],1,strlen($mixed_value[1])) : language($mixed_value[1]);
- $selected = $mixed_value[0] == $value ? ' selected' : '';
- $ret .= sprintf($option_tpl, $mixed_value[0], $selected, $label);
+ foreach ($values as $option_id => $option_title) {
+ $selected = $option_id == $value ? ' selected' : '';
+ $ret .= sprintf($option_tpl, $option_id, $selected, $option_title);
}
return $ret;
Index: trunk/kernel/include/custommetadata.php
===================================================================
diff -u -N -r7635 -r8009
--- trunk/kernel/include/custommetadata.php (.../custommetadata.php) (revision 7635)
+++ trunk/kernel/include/custommetadata.php (.../custommetadata.php) (revision 8009)
@@ -109,11 +109,12 @@
$d =& $this->GetItemRefByIndex($i);
if($d->Get("CustomFieldId")==$id)
{
- $found=TRUE;
+ $found = true;
break;
}
}
- return $found ? ($return_index ? $i : $d) : false;
+
+ return $found ? ($return_index ? $i : $d) : $found;
}
function SaveData($main_prefix, $resource_id)
Index: trunk/core/units/general/custom_fields.php
===================================================================
diff -u -N -r6093 -r8009
--- trunk/core/units/general/custom_fields.php (.../custom_fields.php) (revision 6093)
+++ trunk/core/units/general/custom_fields.php (.../custom_fields.php) (revision 8009)
@@ -34,7 +34,7 @@
*/
function ParseConfigSQL($valueString)
{
- $string = trim( str_replace('', TABLE_PREFIX, $valueString) );
+ $string = trim( str_replace(Array('', '%3$s'), Array (TABLE_PREFIX, $this->Application->GetVar('m_lang')), $valueString) );
preg_match_all("|\{(.*)\}|U", $string, $embedded_vars, PREG_SET_ORDER);