diff --git a/etemplate/inc/class.boetemplate.inc.php b/etemplate/inc/class.boetemplate.inc.php
index f343d8d9a4..09b066086c 100644
--- a/etemplate/inc/class.boetemplate.inc.php
+++ b/etemplate/inc/class.boetemplate.inc.php
@@ -54,7 +54,11 @@
{
$this->public_functions += array(
'disable_cells' => True,
- 'set_cell_attribute' => True
+ 'set_cell_attribute' => True,
+ 'get_cell_attribute' => True,
+ 'get_array' => True,
+ 'set_array' => True,
+ 'unset_array' => True
);
$this->soetemplate();
@@ -401,46 +405,49 @@
return isset($arr[$idx]);
}
- function set_array(&$arr,$idx,$val,$set=True)
+ function set_array(&$arr,$idx,$val)
{
- if (ereg('^([^[]*)(\\[.*\\])$',$idx,$regs)) // idx contains array-index
+ if (!is_array($arr))
{
- $arr_idx = '['.$regs[1].']'.$regs[2];
+ die('set_array() $arr is no array');
}
- else
+ $idxs = explode('[',str_replace(']','',$idx));
+ $pos = &$arr;
+ while (list($n,$idx) = each($idxs))
{
- $arr_idx = "[$idx]";
+ $pos = &$pos[$idx];
}
- if ($set)
- {
- $code = '$arr'.$arr_idx.' = $val;';
- }
- else
- {
- $code = 'unset($arr'.$arr_idx.');';
- }
- eval($code = str_replace(']',"']",str_replace('[',"['",$code)));
-
- //echo "set_array: $code = '$val'
\n";
- }
-
- function unset_array(&$arr,$idx)
- {
- $this->set_array($arr,$idx,0,False);
+ $pos = $val;
}
function &get_array(&$arr,$idx)
{
- if (ereg('^([^[]*)(\\[.*\\])$',$idx,$regs)) // idx contains array-index
+ if (!is_array($arr))
{
- eval($code = str_replace(']',"']",str_replace('[',"['",'$val = &$arr['.$regs[1].']'.$regs[2].';')));
- //echo "get_array: $code = '$val'
\n";
+ die('set_array() $arr is no array');
}
- else
+ $idxs = explode('[',str_replace(']','',$idx));
+ $pos = &$arr;
+ while (list($n,$idx) = each($idxs))
{
- $val = &$arr[$idx];
+ $pos = &$pos[$idx];
}
- return $val;
+ return $pos;
+ }
+
+ function unset_array(&$arr,$idx)
+ {
+ if (!is_array($arr))
+ {
+ die('set_array() $arr is no array');
+ }
+ $idxs = explode('[',str_replace(']','',$idx));
+ $pos = &$arr;
+ while ((list($n,$idx) = each($idxs)) && $n < count($idxs)-1)
+ {
+ $pos = &$pos[$idx];
+ }
+ unset($pos[$idx]);
}
/*!
diff --git a/etemplate/inc/class.uietemplate.inc.php b/etemplate/inc/class.uietemplate.inc.php
index 7f0b4c80d0..26ed30f05f 100644
--- a/etemplate/inc/class.uietemplate.inc.php
+++ b/etemplate/inc/class.uietemplate.inc.php
@@ -340,18 +340,18 @@
}
$name = $this->expand_name($cell['name'],$show_c,$show_row,$content['.c'],$content['.row'],$content);
- if (ereg('^([^[]*)(\\[.*\\])$',$name,$regs)) // name contains array-index
+ $name_parts = explode('[',str_replace(']','',$name));
+ if (!empty($cname))
{
- $form_name = $cname == '' ? $name : $cname.'['.$regs[1].']'.$regs[2];
- eval(str_replace(']',"']",str_replace('[',"['",'$value = $content['.$regs[1].']'.$regs[2].';')));
- $org_name = substr($regs[2],1,-1);
+ array_unshift($name_parts,$cname);
}
- else
+ $form_name = array_shift($name_parts);
+ if (count($name_parts))
{
- $form_name = $cname == '' ? $name : $cname.'['.$name.']';
- $value = $content[$name];
- $org_name = $name;
+ $form_name .= '['.implode('][',$name_parts).']';
}
+ $value = $this->get_array($content,$name);
+
if ($readonly = $cell['readonly'] || $readonlys[$name] || $readonlys['__ALL__'])
{
$options .= ' READONLY';
@@ -372,14 +372,7 @@
$ext_type = $type;
$extra_label = $this->extensionPreProcess($ext_type,$form_name,$value,$cell,$readonlys[$name]);
- if (!$regs)
- {
- $content[$name] = $value; // set result for template
- }
- else
- {
- eval(str_replace(']',"']",str_replace('[',"['",'$content['.$regs[1].']'.$regs[2].' = $value;')));
- }
+ $this->set_array($content,$name,$value);
}
$label = $cell['label'];
if ($label[0] == '@')
@@ -592,9 +585,17 @@
{
$sels += $sel_options[$name];
}
- elseif (isset($sel_options[$org_name]))
+ elseif (count($name_parts))
{
- $sels += $sel_options[$org_name];
+ $org_name = array_shift($name_parts);
+ if (count($name_parts))
+ {
+ $org_name .= '['.implode('][',$name_parts).']';
+ }
+ if (isset($sel_options[$org_name]))
+ {
+ $sels += $sel_options[$org_name];
+ }
}
if (isset($content["options-$name"]))
{