Step #2: Redering and importing (xml) are working now with any tree.

Export and editing still need to be reworked.
More to come ...
This commit is contained in:
Ralf Becker 2005-02-08 12:29:06 +00:00
parent bff130735c
commit 84e89d31be
8 changed files with 376 additions and 161 deletions

View File

@ -630,7 +630,7 @@ implement only a subset of XUL. Here are the main differences:</p>
</td>
</tr>
<tr>
<td><b>VBox, HBox</b></td>
<td><b>VBox, HBox, Box</b></td>
<td>
&lt;vbox><br>
&nbsp; &lt;widget ...><br>
@ -639,13 +639,18 @@ implement only a subset of XUL. Here are the main differences:</p>
&lt;hbox span="all"><br>
&nbsp; &lt;widget ...><br>
&nbsp; &lt;widget ...><br>
&lt;/hbox>
&lt;/hbox><p>
&lt;box><br>
&nbsp; &lt;widget ...><br>
&nbsp; &lt;widget ...><br>
&lt;/box>
</td>
<td>yes</td>
<td>vbox, hbox</td>
<td>vbox, hbox, box</td>
<td>
<b>vertical or horizontal container</b> to contain other widgets. This is useful if one needs more
widgets or widgets outside the column- / row-order of a grid.<br>
vertical or horizontal <b>container</b> for child widgets. This is useful if one needs more
widgets or widgets outside the column- / row-order of a grid. HBox or VBox is rendered as Grid/html:table
with only one row or colum. Box is rendered as a html:div containing all child-widgets.<br>
Disabled child-cells are completly left out (no empty cells or rows get generated).<p>
<b>Options</b> <i>in the editor</i>: the number of cells in the box (does NOT need to be set in xml).
</td>
@ -662,7 +667,7 @@ implement only a subset of XUL. Here are the main differences:</p>
<td>yes</td>
<td>groupbox</td>
<td>
container to <b>group other widgets</b> by putting a border around them.<br>
container to visualy <b>group other widgets</b> by putting a border around them.<br>
The upper line may contain a legend. The widgets are ordered vertical, like a VBox.
Disabled child-cells are completly left out (no empty cells or rows get generated).<p>
<b>Options</b> <i>in the editor</i>: the number of cells in the box (does NOT need to be set in xml).

View File

@ -48,6 +48,7 @@
'vbox' => 'VBox', // a (vertical) box to contain widgets in rows, size = # of rows
'hbox' => 'HBox', // a (horizontal) box to contain widgets in cols, size = # of cols
'groupbox' => 'GroupBox', // a box with a label containing other elements to group them (html: fieldset)
'box' => 'Box', // just a container for widgets (html: div)
// 'grid' => 'Grid', // tabular widget containing rows with columns of widgets
'deck' => 'Deck' // a container of elements where only one is visible, size = # of elem.
);
@ -77,6 +78,40 @@
}
}
/**
* checks if a grid row or column is disabled
*
* Expression: [!][@]val[=[@]check]
* Parts in square brackets are optional, a ! negates the expression, @val evaluates to $content['val']
* if no =check is given all set non-empty and non-zero strings are true (standard php behavior)
*
* @param string $disabled expression to check, eg. "!@var" for !$content['var']
* @param array $content the content-array in the context of the grid
* @return boolean true if the row/col is disabled or false if not
*/
function check_disabled($disabled,$content)
{
//return False;
if ($not = $disabled[0] == '!')
{
$disabled = substr($disabled,1);
}
list($val,$check_val) = $vals = explode('=',$disabled);
if ($val[0] == '@')
{
$val = $this->get_array($content,substr($val,1));
}
if ($check_val[0] == '@')
{
$check_val = $this->get_array($content,substr($check_val,1));
}
$result = count($vals) == 1 ? $val != '' : $val == $check_val;
if ($not) $result = !$result;
//echo "<p>check_disabled: '".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False')."</p>\n";
return $result;
}
/**
* allows a few variables (eg. row-number) to be used in field-names
*
@ -348,6 +383,11 @@
$n = False;
foreach($this->data as $row => $cols)
{
if (!is_array($cols)) // should never happen
{
echo "<p>set_cell_attribute(tpl->name=$this->name, name='$name', attr='$attr',val='$val') <b>cols not set for row '$row'</b></p>\n";
$this->echo_tmpl();
}
foreach($cols as $col => $cell)
{
if ($cell['name'] == $name)
@ -381,6 +421,8 @@
break;
case 'vbox':
case 'hbox':
case 'groupbox':
case 'box':
for ($i = 0; $i < (int)$cell['size']; ++$i)
{
if ($cell[$i]['name'] == $name)

View File

@ -144,6 +144,7 @@
case 'vbox':
case 'hbox':
case 'deck':
case 'box':
$cell['cell_tpl'] = '.vbox';
break;
case 'groupbox':
@ -227,8 +228,9 @@
case 'hbox':
case 'deck':
case 'groupbox':
// default size for all boxes is 2, minimum size is 1 for a groupbox and 2 for the others
if ($cell['size'] < 2 && ($cell['type'] != 'groupbox' || !$cell['size']))
case 'box':
// default size for all boxes is 2, minimum size is 1 for a (group)box and 2 for the others
if ($cell['size'] < 2 && ($cell['type'] != 'groupbox' || $cell['type'] != 'box' || !$cell['size']))
{
$cell['size'] = 2;
}

View File

@ -41,10 +41,10 @@
var $lang; // '' if general template else language short, e.g. 'de'
var $group; // 0 = not specific else groupId or if < 0 userId
var $version; // like 0.9.13.001
var $size; // witdh,height,border of table
var $style; // embeded CSS style-sheet
var $children; // array with children
var $data; // depricated: first grid of the children
var $size; // depricated: witdh,height,border of first grid
var $db,$db_name = 'phpgw_etemplate'; // DB name
var $db_key_cols = array(
'et_name' => 'name',
@ -113,6 +113,7 @@
*
* nothing fancy so far
*
* @static
* @return array the cell
*/
function empty_cell($type='label',$name='')
@ -169,19 +170,90 @@
}
/**
* initialises internal vars rows & cols from the size of the data-array
* adds $cell to it's parent at the parent-type spezific location for childs
*
* @static
* @param array &$parent referenc to the parent
* @param array &$cell cell to add (need to be unset after the call to add_child, as it's a referenc !)
*/
function add_child(&$parent,&$cell)
{
switch($parent['type'])
{
case 'vbox':
case 'hbox':
case 'groupbox':
case 'box':
case 'deck':
list($n,$options) = explode(',',$parent['size'],2);
$parent[++$n] = &$cell;
$parent['size'] = $n . ($options ? ','.$options : '');
break;
case 'grid':
$data = &$parent['data'];
$cols = &$parent['cols'];
$rows = &$parent['rows'];
$row = &$data[$rows];
$col = count($row);
if (is_array($cell)) // real cell to add
{
$row[soetemplate::num2chrs($col++)] = &$cell;
list($spanned) = explode(',',$cell['span']);
$spanned = $spanned == 'all' ? 1 + $cols - $col : $spanned;
while (--$spanned > 0)
{
$row[soetemplate::num2chrs($col++)] = soetemplate::empty_cell();
}
if ($col > $cols) $cols = $col;
}
else // create a new row
{
$data[++$rows] = array();
}
break;
default: // parent is the template itself
$parent[] = &$cell;
break;
}
}
/**
* initialises internal vars rows & cols from the data of a grid
*/
function set_grid_rows_cols(&$grid)
{
$grid['rows'] = count($grid['data']) - 1;
$grid['cols'] = 0;
for($r = 1; $r <= $grid['rows']; ++$r)
{
$cols = count($grid['data'][$r]);
if ($grid['cols'] < $cols)
{
$grid['cols'] = $cols;
}
}
}
/**
* initialises internal vars rows & cols from the data of the first (!) grid
*
* @depricated
*/
function set_rows_cols()
{
$this->rows = count($this->data) - 1;
$this->cols = 0;
for($r = 1; $r <= $this->rows; ++$r)
if (is_null($this->data)) // tmpl contains no grid
{
$cols = count($this->data[$r]);
if ($this->cols < $cols)
{
$this->cols = $cols;
}
$this->rows = $this->cols = 0;
}
else
{
$grid['data'] = &$this->data;
$grid['rows'] = &$this->rows;
$grid['cols'] = &$this->cols;
$this->set_grid_rows_cols($grid);
unset($grid);
}
}
@ -239,6 +311,7 @@
$this->children[0]['data'] = &$this->data;
$this->children[0]['rows'] = &$this->rows;
$this->children[0]['cols'] = &$this->cols;
$this->children[0]['size'] = &$this->size;
}
}
@ -495,6 +568,7 @@
$this->children[0]['data'] = &$this->data;
$this->children[0]['rows'] = &$this->rows;
$this->children[0]['cols'] = &$this->cols;
$this->children[0]['size'] = &$this->size;
// that code fixes a bug in very old templates, not sure if it's still needed
if ($this->name[0] != '.' && is_array($this->data))
@ -520,6 +594,7 @@
}
else
{
unset($this->data);
// for the moment we make $this->data as a referenz to the first grid
foreach($this->children as $key => $child)
{
@ -528,6 +603,14 @@
$this->data = &$this->children[$key]['data'];
$this->rows = &$this->children[$key]['rows'];
$this->cols = &$this->children[$key]['cols'];
if (!isset($this->children[$key]['size']) && !empty($this->size))
{
$this->children[$key]['size'] = &$this->size;
}
else
{
$this->size = &$this->children[$key]['size'];
}
break;
}
}
@ -638,9 +721,8 @@
}
$this->delete(); // so we have always a new insert
if ($this->name[0] != '.') // correct old messed up templates
if ($this->name[0] != '.' && is_array($data)) // correct old messed up templates
{
if (!is_array($this->data)) { $db = &$this->db; unset($this->db); echo function_backtrace()."\ndata is no array in<pre>".print_r($this,true)."</pre>\n"; $this->db = &$db; unset($db); }
reset($this->data); each($this->data);
while (list($row,$cols) = each($this->data))
{
@ -972,23 +1054,31 @@ if (!is_array($this->data)) { $db = &$this->db; unset($this->db); echo function_
/**
* prints/echos the template's content, eg. for debuging
* @param boolean $backtrace = true give a function backtrace
* @param boolean $no_db_obj = true dump the db-obj too
* @param boolean $no_other_objs = true dump other objs (db, html, ...) too
*/
function echo_tmpl($backtrace=true,$no_db_obj=true)
function echo_tmpl($backtrace=true,$no_other_objs=true)
{
static $objs = array('db','html','xul_io');
if ($backtrace) echo "<p>".function_backtrace(1)."</p>\n";
if ($no_db_obj)
if ($no_other_objs)
{
$db = &$this->db;
unset($this->db);
foreach($objs as $obj)
{
$$obj = &$this->$obj;
unset($this->$obj);
}
}
_debug_array($this);
if ($no_db_obj)
if ($no_other_objs)
{
$this->db = &$db;
unset($db);
foreach($objs as $obj)
{
$this->$obj = &$$obj;
unset($$obj);
}
}
}
};

View File

@ -207,8 +207,9 @@
*
* This function is only to submit forms to, create with exec.
* All eTemplates / forms executed with exec are submited to this function
* (via the global index.php and menuaction). It then calls process_show
* for the eTemplate (to adjust the content of the _POST) and
* via /etemplate/process_exec.php?menuaction=<callback>. We cant use the global index.php as
* it would set some constants to etemplate instead of the calling app.
* process_exec then calls process_show for the eTemplate (to adjust the content of the _POST) and
* ExecMethod's the given callback from the app with the content of the form as first argument.
*/
function process_exec()
@ -279,39 +280,16 @@
}
}
function check_disabled($disabled,$content)
{
//return False;
if ($not = $disabled[0] == '!')
{
$disabled = substr($disabled,1);
}
list($val,$check_val) = $vals = explode('=',$disabled);
if ($val[0] == '@')
{
$val = $this->get_array($content,substr($val,1));
}
if ($check_val[0] == '@')
{
$check_val = $this->get_array($content,substr($check_val,1));
}
$result = count($vals) == 1 ? $val != '' : $val == $check_val;
if ($not) $result = !$result;
//echo "<p>check_disabled: '".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False')."</p>\n";
return $result;
}
/**
* creates HTML from an eTemplate
*
* This is done by calling show_cell for each cell in the form. show_cell itself
* calls show recursivly for each included eTemplate.
* You can use it in the UI-layer of an app, just make shure to call process_show !!!
* You could use it in the UI-layer of an app, just make shure to call process_show !!!
* This is intended as internal function and should NOT be called by new app's direct,
* as it deals with HTML and is so UI-dependent, use exec instead.
*
* @param internal
* @internal
* @param $content array with content for the cells, keys are the names given in the cells/form elements
* @param $sel_options array with options for the selectboxes, keys are the name of the selectbox
* @param $readonlys array with names of cells/form-elements to be not allowed to change
@ -322,8 +300,7 @@
* @param $show_row string name/index for name expansion
* @return string the generated HTML
*/
function show($content,$sel_options='',$readonlys='',$cname='',$show_c=0,$show_row=0,
$no_table_tr=False,$tr_class='')
function show($content,$sel_options='',$readonlys='',$cname='',$show_c=0,$show_row=0/*TEST-RB,$no_table_tr=False,$tr_class=''*/)
{
if (!$sel_options)
{
@ -333,7 +310,7 @@
{
$readonlys = array();
}
if (is_int($this->debug) && $this->debug >= 1 || $this->debug == $this->name && $this->name)
if (is_int($this->debug) && $this->debug >= 1 || $this->name && $this->debug == $this->name)
{
echo "<p>etemplate.show($this->name): $cname =\n"; _debug_array($content);
}
@ -341,23 +318,76 @@
{
$content = array(); // happens if incl. template has no content
}
$html = "\n\n<!-- BEGIN eTemplate $this->name -->\n\n";
if (!$GLOBALS['phpgw_info']['etemplate']['styles_included'][$this->name])
{
$GLOBALS['phpgw_info']['etemplate']['styles_included'][$this->name] = True;
$html .= $this->html->style($this->style)."\n\n";
}
foreach ($this->children as $child)
{
$html .= $this->show_cell($child,$content,$sel_options,$readonlys,$cname,$show_c,$show_row,$nul,$nul);
}
return $html."<!-- END eTemplate $this->name -->\n\n";
}
/**
* creates HTML from an eTemplate
*
* This is done by calling show_cell for each cell in the form. show_cell itself
* calls show recursivly for each included eTemplate.
* You can use it in the UI-layer of an app, just make shure to call process_show !!!
* This is intended as internal function and should NOT be called by new app's direct,
* as it deals with HTML and is so UI-dependent, use exec instead.
*
* @internal
* @param $grid array representing a grid
* @param $content array with content for the cells, keys are the names given in the cells/form elements
* @param $sel_options array with options for the selectboxes, keys are the name of the selectbox
* @param $readonlys array with names of cells/form-elements to be not allowed to change
* @param This is to facilitate complex ACL's which denies access on field-level !!!
* @param $cname string basename of names for form-elements, means index in $_POST
* eg. $cname='cont', element-name = 'name' returned content in $_POST['cont']['name']
* @param $show_c string name/index for name expansion
* @param $show_row string name/index for name expansion
* @return string the generated HTML
*/
function show_grid(&$grid,$content,$sel_options='',$readonlys='',$cname='',$show_c=0,$show_row=0/*TEST-RB,$no_table_tr=False,$tr_class=''*/)
{
if (!$sel_options)
{
$sel_options = array();
}
if (!$readonlys)
{
$readonlys = array();
}
if (is_int($this->debug) && $this->debug >= 2 || $grid['name'] && $this->debug == $grid['name'])
{
echo "<p>etemplate.show_grid($grid[name]): $cname =\n"; _debug_array($content);
}
if (!is_array($content))
{
$content = array(); // happens if incl. template has no content
}
$content += array( // for var-expansion in names in show_cell
'.c' => $show_c,
'.col' => $this->num2chrs($show_c-1),
'.row' => $show_row
);
reset($this->data);
if (isset($this->data[0]))
$data = &$grid['data'];
reset($data);
if (isset($data[0]))
{
list(,$opts) = each($this->data);
list(,$opts) = each($data);
}
else
{
$opts = array();
}
for ($r = 0; $row = 1+$r /*list($row,$cols) = each($this->data)*/; ++$r)
for ($r = 0; $row = 1+$r /*list($row,$cols) = each($data)*/; ++$r)
{
if (!(list($r_key) = each($this->data))) // no further row
if (!(list($r_key) = each($data))) // no further row
{
if (!(($this->autorepeat_idx($cols['A'],0,$r,$idx,$idx_cname) && $idx_cname) ||
(substr($cols['A']['type'],1) == 'box' && $this->autorepeat_idx($cols['A'][1],0,$r,$idx,$idx_cname) && $idx_cname) ||
@ -369,9 +399,9 @@
}
else
{
$cols = &$this->data[$r_key];
$cols = &$data[$r_key];
list($height,$disabled) = explode(',',$opts["h$row"]);
$class = $no_table_tr ? $tr_class : $opts["c$row"];
$class = /*TEST-RB$no_table_tr ? $tr_class :*/ $opts["c$row"];
}
if ($disabled != '' && $this->check_disabled($disabled,$content))
{
@ -422,16 +452,16 @@
}
}
}
/*TEST-RB
if ($cell['type'] == 'template' && $cell['onchange'])
{
$cell['tr_class'] = $cl;
}
}*/
if ($col_disabled != '' && $this->check_disabled($col_disabled,$content))
{
continue; // col is disabled
}
$row_data[$col] = $this->show_cell($cell,$content,$sel_options,$readonlys,$cname,
$c,$r,$span,$cl);
$row_data[$col] = $this->show_cell($cell,$content,$sel_options,$readonlys,$cname,$c,$r,$span,$cl);
if ($row_data[$col] == '' && $this->rows == 1)
{
@ -472,19 +502,14 @@
}
$rows[$row] = $row_data;
}
if (!$GLOBALS['phpgw_info']['etemplate']['styles_included'][$this->name])
{
$style = $this->html->style($this->style);
$GLOBALS['phpgw_info']['etemplate']['styles_included'][$this->name] = True;
}
$html = $this->html->table($rows,$this->html->formatOptions($this->size,'WIDTH,HEIGHT,BORDER,CLASS,CELLSPACING,CELLPADDING'),$no_table_tr);
$html = $this->html->table($rows,$this->html->formatOptions($grid['size'],'WIDTH,HEIGHT,BORDER,CLASS,CELLSPACING,CELLPADDING')/*TEST-RB,$no_table_tr*/);
list($width,$height,,,,,$overflow) = explode(',',$this->size);
list($width,$height,,,,,$overflow) = explode(',',$grid['size']);
if (!empty($overflow)) {
$div_style=' STYLE="'.($width?"width: $width; ":'').($height ? "height: $height; ":'')."overflow: $overflow\"";
$html = $this->html->div($html,$div_style);
}
return "\n\n<!-- BEGIN $this->name -->\n$style\n".$html."<!-- END $this->name -->\n\n";
return "\n\n<!-- BEGIN grid $grid[name] -->\n$html<!-- END grid $grid[name] -->\n\n";
}
/**
@ -763,13 +788,25 @@
case 'hrule':
$html .= $this->html->hr($cell_options);
break;
case 'grid':
if ($readonly)
{
if (!is_array($readonlys)) $readonlys = array();
$readonlys['__ALL__'] = True;
}
if ($name != '')
{
$cname .= $cname == '' ? $name : '['.str_replace('[','][',str_replace(']','',$name)).']';
}
$html .= $this->show_grid($cell,$name ? $value : $content,$sel_options,$readonlys,$cname,$show_c,$show_row);
break;
case 'template': // size: index in content-array (if not full content is past further on)
if (is_object($cell['name']))
{
$cell['obj'] = &$cell['name'];
unset($cell['name']);
$cell['name'] = 'was Object';
echo "<p>Object in Name in tpl '$this->name': "; _debug_array($this->data);
echo "<p>Object in Name in tpl '$this->name': "; _debug_array($grid);
}
$obj_read = 'already loaded';
if (!is_object($cell['obj']))
@ -785,7 +822,7 @@
}
else
{ $obj_read = 'obj read';
$cell['obj'] = new etemplate(/*** TESTWEISE ***$cell['name']*/$name,$this->as_array());
$cell['obj'] = new etemplate($name,$this->as_array());
}
}
if (is_int($this->debug) && $this->debug >= 3 || $this->debug == $cell['type'])
@ -815,7 +852,7 @@
if (!is_array($readonlys)) $readonlys = array();
$readonlys['__ALL__'] = True;
}
$html = $cell['obj']->show($content,$sel_options,$readonlys,$cname,$show_c,$show_row,$cell['onchange'],$cell['tr_class']);
$html = $cell['obj']->show($content,$sel_options,$readonlys,$cname,$show_c,$show_row/*TEST-RB,$cell['onchange'],$cell['tr_class']*/);
break;
case 'select': // size:[linesOnMultiselect]
$sels = array();
@ -898,11 +935,12 @@
case 'vbox':
case 'hbox':
case 'groupbox':
case 'box':
$rows = array();
$box_row = 1;
$box_col = 'A';
$box_anz = 0;
for ($n = 1; $n <= intval($cell_options); ++$n)
for ($n = 1; $n <= (int) $cell_options; ++$n)
{
$h = $this->show_cell($cell[$n],$content,$sel_options,$readonlys,$cname,$show_c,$show_row,$nul,$cl);
if ($h != '' && $h != '&nbsp;')
@ -915,7 +953,14 @@
{
$box_col = $this->num2chrs($n);
}
$rows[$box_row][$box_col] = $html = $h;
if ($cell['type'] == 'box')
{
$html .= $h;
}
else
{
$rows[$box_row][$box_col] = $html = $h;
}
$box_anz++;
if ($cell[$n]['align'])
{
@ -926,7 +971,7 @@
$rows[$box_row]['.'.$box_col] .= $this->html->formatOptions($cl,'CLASS');
}
}
if ($box_anz > 1) // a single cell is NOT placed into a table
if ($box_anz > 1 && $cell['type'] != 'box') // a single cell is NOT placed into a table
{
$html = $this->html->table($rows,$this->html->formatOptions($cell_options,',CELLPADDING,CELLSPACING').
($cell['align'] && $type != 'hbox' ? ' WIDTH="100%"' : '')); // alignment only works if table has full width
@ -939,7 +984,15 @@
}
$html = $this->html->fieldset($html,$label);
}
if ($box_anz > 1) // a single cell is NOT placed into a table
elseif ($cell['type'] == 'box')
{
$html = $this->html->div($html,$this->html->formatOptions(array(
$cell['height'],
$cell['width'],
$cell['class'],
),'HEIGHT,WIDTH,CLASS'));
}
if ($box_anz > 1) // small docu in the html-source
{
$html = "\n\n<!-- BEGIN $cell[type] -->\n\n".$html."\n\n<!-- END $cell[type] -->\n\n";
}
@ -1057,7 +1110,7 @@
* This is only an internal function, dont call it direct use only exec
* Process_show uses a list of input-fields/widgets generated by show.
*
* @param internal
* @internal
* @param $content array $_POST[$cname], on return the adjusted content
* @param $to_process array list of widgets/form-fields to process
* @param $cname string basename of our returnt content (same as in call to show)

View File

@ -82,7 +82,7 @@
'size' => 'rows,options'
),
'template' => array(
'.name' => 'grid',
'.name' => 'template',
'size' => 'content'
),
'image' => array(
@ -229,6 +229,7 @@
// fall-through
case 'vbox':
case 'hbox':
case 'box':
case 'deck':
list($anz,$options) = split(',',$cell['size'],2);
for ($n = 1; $n <= $anz; ++$n)
@ -369,31 +370,6 @@
return $xml;
}
function add_cell(&$etempl,$cell,&$box,&$col,$node_level)
{
if (!isset($box[$node_level-1]))
{
list($spanned) = explode(',',$cell['span']);
$spanned = $spanned == 'all' ? $etempl->cols - $col : $spanned;
$etempl->data[$etempl->rows][$etempl->num2chrs($col++)] = $cell;
/* if ($attr['type'] == 'template' && !empty($attr['name']) && $attr['name'][0] != '@')
{
$etempl->data[$etempl->rows][$etempl->num2chrs($col++)]['obj'] = new etemplate($attr['name']);
} */
while (--$spanned > 0)
{
$etempl->data[$etempl->rows][$etempl->num2chrs($col++)] = $etempl->empty_cell();
}
}
else
{
$pcell = &$box[$node_level-1];
$pcell[++$pcell['anz']] = $cell;
}
}
function import(&$etempl,$data)
{
if ($this->debug)
@ -417,8 +393,14 @@
{
return $err;
}
while (list($n,$node) = each($vals))
$parents = array();
$parent = null;
foreach($vals as $n => $node)
{
if ($this->debug)
{
echo "<h1>$n</h1><pre>".print_r($node,true)."</pre>";
}
$type = $node['type'];
$tag = $node['tag'];
$attr = is_array($node['attributes']) ? $node['attributes'] : array();
@ -430,10 +412,6 @@
{
$attr['size'] = $attr['options']; unset($attr['options']);
}
if ($tag == 'grid' && $type == 'complete' && !is_array($tab_attr))
{
$tag = 'template';
}
if ($tag != 'textbox' && !isset($attr['type']))
{
$attr['type'] = $this->xul2widget[$tag] ? $this->xul2widget[$tag] : $tag;
@ -446,37 +424,76 @@
{
case 'overlay':
break;
case 'template':
case 'grid':
if ($type != 'close' && is_array($tab_attr))
if ($type != 'open' && is_array($tab_attr)) // templates/grids in a tabpanel
{
$tab_names[] = $attr['name'];
break;
}
if ($node['level'] > 2) // level 1 is the overlay
if ($tag == 'template' && $node['level'] > 2) // level 1 is the overlay
{
return "Can't import nested $node[tag]'s !!!";
return "Can't import nested $tag's !!!";
}
if ($type != 'open')
switch ($type)
{
break;
case 'close':
if (!count($parents) || $parent['.is_root']) // templ import complet => save it
{
unset($parent['.is_root']);
unset($parent); $parents = array();
$etempl->fix_old_template_format(); // set the depricated compat vars
// save tmpl to the cache, as the file may contain more then one tmpl
$cname = ($etempl->template == '' ? 'default' : $etempl->template).'/'.$etempl->name.
($etempl->lang == '' ? '' : '.'.$etempl->lang);
$GLOBALS['phpgw_info']['etemplate']['cache'][$cname] = $etempl->as_array(1);
if ($this->debug)
{
$etempl->echo_tmpl();
}
$imported[] = $etempl->name;
}
else
{
// poping the last used parent from the end of the parents array (array_pop does not work with references)
$parent = &$parents[count($parents)-1];
unset($parents[count($parents)-1]);
}
break;
case 'open':
if (($is_root = is_null($parent))) // starting a new templ
{
$etempl->init($attr);
$etempl->children = array(); // init adds one grid by default
$parent = &$etempl->children;
}
if ($tag == 'grid')
{
$size_opts = array('padding','spacing','class','border','height','width');
for ($size = ''; list(,$opt) = each($size_opts); )
{
$size = $attr[$opt] . ($size != '' ? ",$size" : '');
}
$grid = array( // empty grid
'type' => 'grid',
'data' => array(),
'cols' => 0,
'rows' => 0,
'size' => $size,
);
if ($is_root) $grid['.is_root'] = true; // we need to remember we have no template as parent
soetemplate::add_child($parent,$grid);
$parents[count($parents)] = &$parent;
$parent = &$grid;
unset($grid);
}
break;
case 'complete': // reference to an other template
$attr['type'] = 'template'; // might be grid in old xet-files
soetemplate::add_child($parent,$attr);
unset($attr);
break;
}
if ($grid_started) // more than one grid in the file --> place it into the cache
{
$cname = ($etempl->template == '' ? 'default' : $etempl->template).'/'.$etempl->name.
($etempl->lang == '' ? '' : '.'.$etempl->lang);
$imported[] = $etempl->name;
$GLOBALS['phpgw_info']['etemplate']['cache'][$cname] = $etempl->as_array(1);
}
$grid_started = True;
$etempl->init($attr);
$size_opts = array('padding','spacing','class','border','height','width');
for ($size = ''; list(,$opt) = each($size_opts); )
{
$size = $attr[$opt] . ($size != '' ? ",$size" : '');
}
$etempl->size = $size;
$etempl->cols = $etempl->rows = 0;
$etempl->data = array();
break;
case 'columns':
case 'rows':
@ -486,7 +503,7 @@
{
return 'place widgets in <row> and not in <column> !!!';
}
$etempl->data[0][$etempl->num2chrs($etempl->cols++)] = $attr['width'] .
$parent['data'][0][$etempl->num2chrs($parent['cols']++)] = $attr['width'] .
($attr['disabled'] ? ','.$attr['disabled'] : '');
break;
case 'row':
@ -494,10 +511,9 @@
{
break;
}
$r = ++$etempl->rows;
$col = 0;
$etempl->data[0]["c$r"] = $attr['class'] . ($attr['valign'] ? ','.$attr['valign'] : '');
$etempl->data[0]["h$r"] = $attr['height'] .
$nul = null; soetemplate::add_child($parent,$nul); // null = new row
$parent['data'][0]['c'.$parent['rows']] = $attr['class'] . ($attr['valign'] ? ','.$attr['valign'] : '');
$parent['data'][0]['h'.$parent['rows']] = $attr['height'] .
($attr['disabled'] ? ','.$attr['disabled'] : '');
break;
case 'styles':
@ -518,7 +534,7 @@
$tab_attr['span'] .= $tab_attr['class'] ? ','.$tab_attr['class'] : '';
unset($tab_attr['class']);
$this->add_cell($etempl,$tab_attr,$box,$col,$node['level']);
soetemplate::add_child($parent,$tab_attr);
unset($tab_attr);
}
break;
@ -547,7 +563,7 @@
}
else
{
$this->add_cell($etempl,$menulist_attr,$box,$col,$node['level']);
soetemplate::add_child($parent,$menulist_attr);
unset($menulist_attr);
}
break;
@ -555,28 +571,32 @@
case 'hbox':
case 'deck':
case 'groupbox':
if ($type == 'open')
case 'box':
if ($type != 'close') // open or complete
{
$box[$node['level']] = $attr;
soetemplate::add_child($parent,$attr);
$parents[count($parents)] = &$parent; // $parents[] does not always the same - strange
$parent = &$attr;
unset($attr);
}
else
if ($type != 'open') // close or complete
{
$cell = &$box[$node['level']];
$cell['size'] = $cell['anz'] . ($cell['size'] != '' ? ','.$cell['size'] : '');
unset($cell['anz']);
$this->add_cell($etempl,$cell,$box,$col,$node['level']);
unset($box[$node['level']]);
// poping the last used parent from the end of the parents array (array_pop does not work with references)
$parent = &$parents[count($parents)-1];
unset($parents[count($parents)-1]);
}
break;
case 'caption': // caption of (group)box
if (isset($box[$node['level']-1]))
if ($parent['type'] == 'groupbox')
{
$box[$node['level']-1]['label'] = $attr['label'];
$parent['label'] = $attr['label'];
}
break;
// the following labels create automaticaly a child-entry in their parent
case 'textbox':
if ($attr['multiline'])
{
unset($attr['multiline']);
$attr['type'] = 'textarea';
$attr['size'] = $attr['rows'] . ($attr['cols'] ? ','.$attr['cols'] : '');
unset($attr['cols']);
@ -629,16 +649,17 @@
{
break;
}
$this->add_cell($etempl,$attr,$box,$col,$node['level']);
soetemplate::add_child($parent,$attr);
unset($attr);
break;
}
if ($this->debug)
{
echo "<b>parent</b><pre>".print_r($parent,true)."</pre>";
echo "<b>parents</b><pre>".print_r($parents,true)."</pre>";
echo "<b>children</b><pre>".print_r($etempl->children,true)."</pre>";
}
}
if ($this->debug)
{
_debug_array($etempl->data);
}
$imported[] = $etempl->name;
return $imported;
}
}

View File

@ -31,6 +31,7 @@ attach file etemplate de Datei anh
blurtext etemplate de blurText
border etemplate de Rand
border-line-thickness for the table-tag etemplate de Randbreite (border) für die Tabelle
box etemplate de Box
can not have special sql-value null etemplate de darf nicht den speziellen SQL Wert NULL annehmen
cancel etemplate de Abbruch
category etemplate de Kategorie

View File

@ -31,6 +31,7 @@ attach file etemplate en attach file
blurtext etemplate en blurText
border etemplate en Border
border-line-thickness for the table-tag etemplate en Border-line-thickness for the table-tag
box etemplate en Box
can not have special sql-value null etemplate en can not have special SQL-value NULL
cancel etemplate en Cancel
category etemplate en Category