2002-09-12 02:35:20 +02:00
|
|
|
<?php
|
2006-04-20 19:12:30 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare - eTemplates - XUL/XML Import & Export
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2002-09-12 02:35:20 +02:00
|
|
|
|
2002-10-04 01:46:28 +02:00
|
|
|
if (!function_exists('var2xml'))
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
if (file_exists(EGW_API_INC.'class.xmltool.inc.php'))
|
2002-10-04 01:46:28 +02:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
include_once(EGW_API_INC.'class.xmltool.inc.php');
|
2002-10-04 01:46:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
include_once('class.xmltool.inc.php');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* XUL/XML Import & Export for eTemplates
|
|
|
|
*
|
|
|
|
* used only internaly
|
|
|
|
*
|
|
|
|
* @package etemplate
|
2005-02-18 23:44:42 +01:00
|
|
|
* @subpackage api
|
2004-10-07 23:53:10 +02:00
|
|
|
* @author RalfBecker-AT-outdoor-training.de
|
|
|
|
* @license GPL
|
|
|
|
*/
|
2002-09-12 02:35:20 +02:00
|
|
|
class xul_io
|
|
|
|
{
|
|
|
|
var $widget2xul;
|
|
|
|
var $attr2xul;
|
|
|
|
var $xul2widget;
|
|
|
|
|
|
|
|
function xul_io()
|
|
|
|
{
|
2005-02-13 14:03:36 +01:00
|
|
|
/**
|
|
|
|
* @var array $attr2xul how to translate attr, common to all widgets
|
|
|
|
*/
|
|
|
|
$this->attr2xul = array(
|
2002-09-12 02:35:20 +02:00
|
|
|
'name' => 'id',
|
|
|
|
'help' => 'statustext',
|
|
|
|
'span' => 'span,class',
|
|
|
|
'type' => '', // this is the widget-name => dont write as attr
|
|
|
|
'disabled' => 'disabled=true',
|
2002-09-17 11:13:29 +02:00
|
|
|
'readonly' => 'readonly=true',
|
|
|
|
'size' => 'options'
|
2002-09-12 02:35:20 +02:00
|
|
|
);
|
2005-02-13 14:03:36 +01:00
|
|
|
/**
|
|
|
|
* @var array $widget2xul how to widget-names and widget-spec. attr., not set ones are identical
|
|
|
|
*/
|
|
|
|
$this->widget2xul = array(
|
2002-09-12 02:35:20 +02:00
|
|
|
'label' => array(
|
2002-09-12 23:43:41 +02:00
|
|
|
'.name' => 'description',
|
2002-09-12 02:35:20 +02:00
|
|
|
'label' => 'value'
|
|
|
|
),
|
|
|
|
'text' => array(
|
|
|
|
'.name' => 'textbox',
|
2004-04-05 03:33:23 +02:00
|
|
|
'size' => 'size,maxlength,validator'
|
2002-09-12 02:35:20 +02:00
|
|
|
),
|
|
|
|
'textarea' => array(
|
|
|
|
'.name' => 'textbox',
|
|
|
|
'.set' => 'multiline=true',
|
2002-09-25 00:05:01 +02:00
|
|
|
'size' => 'rows,cols'
|
2002-09-12 02:35:20 +02:00
|
|
|
),
|
|
|
|
'integer' => array(
|
|
|
|
'.name' => 'textbox',
|
|
|
|
'.set' => 'type=integer',
|
|
|
|
'size' => 'min,max,size'
|
|
|
|
),
|
|
|
|
'float' => array(
|
|
|
|
'.name' => 'textbox',
|
|
|
|
'.set' => 'type=float',
|
2006-03-27 14:21:29 +02:00
|
|
|
'size' => 'min,max,size,precision'
|
2002-09-12 02:35:20 +02:00
|
|
|
),
|
|
|
|
'select' => array(
|
2002-09-17 11:13:29 +02:00
|
|
|
'.name' => 'menulist,menupopup',
|
|
|
|
),
|
|
|
|
'select-multi' => array( // multiselection, if size > 0
|
|
|
|
'.name' => 'listbox',
|
2002-10-03 18:48:17 +02:00
|
|
|
'size' => 'rows,options'
|
2002-09-12 19:57:27 +02:00
|
|
|
),
|
|
|
|
'template' => array(
|
2005-02-08 13:29:06 +01:00
|
|
|
'.name' => 'template',
|
2002-09-12 19:57:27 +02:00
|
|
|
'size' => 'content'
|
2002-09-12 23:43:41 +02:00
|
|
|
),
|
|
|
|
'image' => array(
|
|
|
|
'.name' => 'image',
|
2002-10-12 18:37:44 +02:00
|
|
|
'name' => 'src'
|
2002-09-12 23:43:41 +02:00
|
|
|
),
|
|
|
|
'tab' => array(
|
|
|
|
'.name' => 'tabbox,tabs,tabpanels'
|
2002-09-17 14:29:01 +02:00
|
|
|
),
|
|
|
|
'button' => array(
|
|
|
|
'.name' => 'button',
|
|
|
|
'size' => 'image,ro_image'
|
2004-08-21 10:04:23 +02:00
|
|
|
),
|
|
|
|
'htmlarea' => array(
|
|
|
|
'size' => 'style,plugins',
|
|
|
|
),
|
2002-09-12 02:35:20 +02:00
|
|
|
);
|
2005-02-13 14:03:36 +01:00
|
|
|
/**
|
|
|
|
* @var array $xul2widget how to xul-widget names to our internal ones, not set ones are identical
|
|
|
|
*/
|
2002-09-12 02:35:20 +02:00
|
|
|
$this->xul2widget = array(
|
2002-10-12 18:37:44 +02:00
|
|
|
'menulist' => 'select',
|
2002-09-17 11:13:29 +02:00
|
|
|
'listbox' => 'select',
|
2005-02-18 23:44:42 +01:00
|
|
|
'menupopup' => 'select',
|
2002-09-12 23:43:41 +02:00
|
|
|
'description' => 'label'
|
2002-09-12 02:35:20 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:36 +01:00
|
|
|
/**
|
|
|
|
* sets an attribute in the xml object representing a widget
|
|
|
|
*
|
|
|
|
* @param object &$widget widget to set the attribute in
|
|
|
|
* @param string $attr comma delimited attr = default-value pairs, eg. "type=int,min=0"
|
|
|
|
* @param array $val array with values to set
|
|
|
|
*/
|
2004-03-09 22:46:25 +01:00
|
|
|
function set_attributes(&$widget,$attr,$val)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
2006-01-06 05:50:56 +01:00
|
|
|
if ($attr != '' && !is_numeric($attr))
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
|
|
|
$attrs = explode(',',$attr);
|
|
|
|
|
|
|
|
if (count($attrs))
|
|
|
|
{
|
2005-02-08 15:59:41 +01:00
|
|
|
$vals = count($attrs) > 1 ? explode(',',$val,count($attrs)) : array($val);
|
|
|
|
foreach($attrs as $n => $attr)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
2002-09-18 00:52:24 +02:00
|
|
|
if (($val = $vals[$n]) != '')
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
|
|
|
list($attr,$set) = explode('=',$attr);
|
|
|
|
$widget->set_attribute($attr,$set != '' ? $set : $val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:36 +01:00
|
|
|
/**
|
|
|
|
* add a widget to a parent
|
|
|
|
*
|
|
|
|
* @param object &$parent parten to add the widget
|
|
|
|
* @param array $cell widget to add
|
|
|
|
* @param array &$embeded_too already embeded eTemplates
|
|
|
|
* @return object reference (!) the the xml object representing the widget, so other children can be added
|
|
|
|
*/
|
2005-02-08 15:59:41 +01:00
|
|
|
function &add_widget(&$parent,$cell,&$embeded_too)
|
2002-10-12 18:37:44 +02:00
|
|
|
{
|
|
|
|
$type = $cell['type'];
|
|
|
|
if (is_array($type))
|
|
|
|
{
|
|
|
|
list(,$type) = each($type);
|
|
|
|
}
|
2005-02-18 23:44:42 +01:00
|
|
|
if (!$type) $cell['type'] = $type = 'hugo';
|
2002-10-12 18:37:44 +02:00
|
|
|
if (substr($type,0,6) == 'select')
|
|
|
|
{
|
|
|
|
$type = $cell['size'] > 1 ? 'select-multi' : 'select';
|
|
|
|
}
|
|
|
|
$widgetattr2xul = isset($this->widget2xul[$type]) ? $this->widget2xul[$type] : array();
|
|
|
|
$type = isset($widgetattr2xul['.name']) ? $widgetattr2xul['.name'] : $type;
|
2005-02-08 15:59:41 +01:00
|
|
|
list($type,$child,$child2) = explode(',',$type);
|
2005-11-09 21:50:45 +01:00
|
|
|
$widget =& new xmlnode($type);
|
2002-10-12 18:37:44 +02:00
|
|
|
$attr_widget = &$widget;
|
|
|
|
if ($child)
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$child =& new xmlnode($child);
|
2005-02-08 15:59:41 +01:00
|
|
|
if ($type != 'tabbox') $attr_widget = &$child;
|
2002-10-12 18:37:44 +02:00
|
|
|
}
|
|
|
|
if ($child2)
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$child2 =& new xmlnode($child2);
|
2002-10-12 18:37:44 +02:00
|
|
|
}
|
|
|
|
if (isset($widgetattr2xul['.set'])) // set default-attr for type
|
|
|
|
{
|
|
|
|
$attrs = explode(',',$widgetattr2xul['.set']);
|
2005-02-08 15:59:41 +01:00
|
|
|
foreach($attrs as $attr)
|
2002-10-12 18:37:44 +02:00
|
|
|
{
|
|
|
|
list($attr,$val) = explode('=',$attr);
|
|
|
|
$widget->set_attribute($attr,$val);
|
|
|
|
}
|
|
|
|
}
|
2005-02-08 15:59:41 +01:00
|
|
|
switch ($type)
|
2002-10-12 18:37:44 +02:00
|
|
|
{
|
|
|
|
case 'nextmatch':
|
2002-10-18 00:13:18 +02:00
|
|
|
list($tpl) = explode(',',$cell['size']);
|
2005-11-09 21:50:45 +01:00
|
|
|
$embeded =& new etemplate($tpl,$this->load_via);
|
2002-10-14 02:39:47 +02:00
|
|
|
if ($embeded_too)
|
|
|
|
{
|
2005-02-08 15:59:41 +01:00
|
|
|
$this->add_etempl($embeded,$embeded_too);
|
2002-10-14 02:39:47 +02:00
|
|
|
}
|
|
|
|
$cell['size'] = $embeded->name;
|
2002-10-12 18:37:44 +02:00
|
|
|
unset($embeded);
|
|
|
|
break;
|
|
|
|
case 'tabbox':
|
|
|
|
$labels = explode('|',$cell['label']); unset($cell['label']);
|
|
|
|
$helps = explode('|',$cell['help']); unset($cell['help']);
|
|
|
|
$names = explode('|',$cell['name']); unset($cell['name']);
|
|
|
|
for ($n = 0; $n < count($labels); ++$n)
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$tab =& new xmlnode('tab');
|
2002-10-12 18:37:44 +02:00
|
|
|
$tab->set_attribute('label',$labels[$n]);
|
|
|
|
$tab->set_attribute('statustext',$helps[$n]);
|
|
|
|
$child->add_node($tab);
|
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
$embeded =& new etemplate($names[$n],$this->load_via);
|
2002-10-14 02:39:47 +02:00
|
|
|
if ($embeded_too)
|
|
|
|
{
|
2005-02-08 15:59:41 +01:00
|
|
|
$this->add_etempl($embeded,$embeded_too);
|
2002-10-14 02:39:47 +02:00
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
$template =& new xmlnode('template');
|
2005-02-08 15:59:41 +01:00
|
|
|
$template->set_attribute('id',$embeded->name);
|
|
|
|
$child2->add_node($template);
|
2002-10-12 18:37:44 +02:00
|
|
|
unset($embeded);
|
2005-02-08 15:59:41 +01:00
|
|
|
unset($template);
|
2002-10-12 18:37:44 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'menulist': // id,options belongs to the 'menupopup' child
|
|
|
|
if ($cell['span'])
|
|
|
|
{
|
|
|
|
$widget->set_attribute('span',$cell['span']);
|
|
|
|
unset($cell['span']);
|
|
|
|
}
|
|
|
|
// fall-trought
|
|
|
|
case 'listbox':
|
|
|
|
if ($cell['type'] != 'select') // one of the sub-types
|
|
|
|
{
|
|
|
|
$attr_widget->set_attribute('type',$cell['type']);
|
|
|
|
}
|
|
|
|
break;
|
2005-02-06 16:49:50 +01:00
|
|
|
case 'groupbox':
|
|
|
|
if ($cell['label'])
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$caption =& new xmlnode('caption');
|
2005-02-06 16:49:50 +01:00
|
|
|
$caption->set_attribute('label',$cell['label']);
|
|
|
|
$widget->add_node($caption);
|
|
|
|
unset($cell['label']);
|
|
|
|
}
|
|
|
|
// fall-through
|
2002-10-12 18:37:44 +02:00
|
|
|
case 'vbox':
|
|
|
|
case 'hbox':
|
2005-02-08 13:29:06 +01:00
|
|
|
case 'box':
|
2005-02-06 16:49:50 +01:00
|
|
|
case 'deck':
|
2005-02-18 23:44:42 +01:00
|
|
|
list($anz,$orient,$options) = split(',',$cell['size'],2);
|
2002-10-14 02:39:47 +02:00
|
|
|
for ($n = 1; $n <= $anz; ++$n)
|
2002-10-12 18:37:44 +02:00
|
|
|
{
|
2005-02-08 15:59:41 +01:00
|
|
|
$this->add_widget($widget,$cell[$n],$embeded_too);
|
2002-10-12 18:37:44 +02:00
|
|
|
unset($cell[$n]);
|
|
|
|
}
|
2005-02-18 23:44:42 +01:00
|
|
|
$cell['orient'] = $orient;
|
2002-10-14 02:39:47 +02:00
|
|
|
$cell['size'] = $options;
|
|
|
|
break;
|
|
|
|
|
2005-02-08 15:59:41 +01:00
|
|
|
case 'template':
|
2002-10-14 02:39:47 +02:00
|
|
|
if ($cell['name'][0] != '@' && $embeded_too)
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$templ =& new etemplate();
|
2005-02-08 15:59:41 +01:00
|
|
|
if ($templ->read(boetemplate::expand_name($cell['name'],0,0),'default','default',0,'',$this->load_via))
|
2002-10-14 02:39:47 +02:00
|
|
|
{
|
2005-02-08 15:59:41 +01:00
|
|
|
$this->add_etempl($templ,$embeded_too);
|
2002-10-14 02:39:47 +02:00
|
|
|
}
|
2005-02-08 15:59:41 +01:00
|
|
|
$cell['name'] = $templ->name;
|
|
|
|
unset($templ);
|
2002-10-14 02:39:47 +02:00
|
|
|
}
|
2002-10-12 18:37:44 +02:00
|
|
|
break;
|
2005-02-08 15:59:41 +01:00
|
|
|
|
|
|
|
case 'grid':
|
|
|
|
$this->add_grid($parent,$cell,$embeded_too);
|
|
|
|
return; // grid is already added
|
2002-10-12 18:37:44 +02:00
|
|
|
}
|
2005-02-08 15:59:41 +01:00
|
|
|
foreach($cell as $attr => $val)
|
2002-10-12 18:37:44 +02:00
|
|
|
{
|
|
|
|
if (is_array($val)) // correct old buggy etemplates
|
|
|
|
{
|
|
|
|
list(,$val) = each($val);
|
|
|
|
}
|
|
|
|
if (isset($widgetattr2xul[$attr]))
|
|
|
|
{
|
|
|
|
$attr = $widgetattr2xul[$attr];
|
|
|
|
}
|
|
|
|
elseif (isset($this->attr2xul[$attr]))
|
|
|
|
{
|
|
|
|
$attr = $this->attr2xul[$attr];
|
|
|
|
}
|
2005-02-08 15:59:41 +01:00
|
|
|
$this->set_attributes($attr_widget,$attr,$val);
|
2002-10-12 18:37:44 +02:00
|
|
|
}
|
|
|
|
if ($child)
|
|
|
|
{
|
|
|
|
$widget->add_node($child);
|
|
|
|
}
|
|
|
|
if ($child2)
|
|
|
|
{
|
|
|
|
$widget->add_node($child2);
|
|
|
|
}
|
2005-02-08 15:59:41 +01:00
|
|
|
$parent->add_node($widget);
|
2002-10-12 18:37:44 +02:00
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:36 +01:00
|
|
|
/**
|
|
|
|
* add a grid to $parent (xml object)
|
|
|
|
*
|
|
|
|
* @param object &$parent where to add the grid
|
|
|
|
* @param array $grid grid to add
|
|
|
|
* @param array &embeded_too array with already embeded eTemplates
|
|
|
|
*/
|
2005-02-08 15:59:41 +01:00
|
|
|
function add_grid(&$parent,$grid,&$embeded_too)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$xul_grid =& new xmlnode('grid');
|
2005-04-20 19:25:06 +02:00
|
|
|
$this->set_attributes($xul_grid,'width,height,border,class,spacing,padding,overflow',$grid['size']);
|
2002-09-12 02:35:20 +02:00
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
$xul_columns =& new xmlnode('columns');
|
|
|
|
$xul_rows =& new xmlnode('rows');
|
2002-09-12 02:35:20 +02:00
|
|
|
|
2005-02-08 15:59:41 +01:00
|
|
|
reset($grid['data']);
|
|
|
|
list(,$opts) = each ($grid['data']); // read over options-row
|
|
|
|
while (list($r,$row) = each ($grid['data']))
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$xul_row =& new xmlnode('row');
|
2002-09-12 02:35:20 +02:00
|
|
|
$this->set_attributes($xul_row,'class,valign',$opts["c$r"]);
|
2002-10-10 13:29:36 +02:00
|
|
|
$this->set_attributes($xul_row,'height,disabled',$opts["h$r"]);
|
2002-09-12 02:35:20 +02:00
|
|
|
|
|
|
|
$spanned = 0;
|
2005-02-08 15:59:41 +01:00
|
|
|
foreach($row as $c => $cell)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
|
|
|
if ($r == '1') // write columns only once in the first row
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$xul_column =& new xmlnode('column');
|
2002-10-10 13:29:36 +02:00
|
|
|
$this->set_attributes($xul_column,'width,disabled',$opts[$c]);
|
2002-09-12 02:35:20 +02:00
|
|
|
$xul_columns->add_node($xul_column);
|
|
|
|
}
|
2005-02-08 15:59:41 +01:00
|
|
|
if ($spanned-- > 1)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
|
|
|
continue; // spanned cells are not written
|
|
|
|
}
|
2005-02-08 15:59:41 +01:00
|
|
|
$this->add_widget($xul_row,$cell,$embeded_too);
|
|
|
|
|
|
|
|
$spanned = $cell['span'] == 'all' ? 999 : $cell['span'];
|
2002-09-12 02:35:20 +02:00
|
|
|
}
|
|
|
|
$xul_rows->add_node($xul_row);
|
|
|
|
}
|
|
|
|
$xul_grid->add_node($xul_columns);
|
|
|
|
$xul_grid->add_node($xul_rows);
|
|
|
|
|
2005-02-08 15:59:41 +01:00
|
|
|
$parent->add_node($xul_grid);
|
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:36 +01:00
|
|
|
/**
|
|
|
|
* add / embed an eTemplate into the global $xul_overlay object (used by export)
|
|
|
|
*
|
|
|
|
* @param object &$etempl eTemplate to embed
|
|
|
|
* @param array &embeded_too array with already embeded templates
|
|
|
|
*/
|
2005-02-08 15:59:41 +01:00
|
|
|
function add_etempl(&$etempl,&$embeded_too)
|
|
|
|
{
|
|
|
|
if (is_array($embeded_too))
|
|
|
|
{
|
|
|
|
if (isset($embeded_too[$etempl->name]))
|
|
|
|
{
|
|
|
|
return; // allready embeded
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$embeded_too = array();
|
|
|
|
}
|
|
|
|
$embeded_too[$etempl->name] = True;
|
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
$template =& new xmlnode('template');
|
2005-02-08 15:59:41 +01:00
|
|
|
$template->set_attribute('id',$etempl->name);
|
|
|
|
$template->set_attribute('template',$etempl->template);
|
|
|
|
$template->set_attribute('lang',$etempl->lang);
|
|
|
|
$template->set_attribute('group',$etempl->group);
|
|
|
|
$template->set_attribute('version',$etempl->version);
|
|
|
|
|
|
|
|
foreach($etempl->children as $child)
|
|
|
|
{
|
|
|
|
$this->add_widget($template,$child,$embeded_too);
|
|
|
|
}
|
2002-09-12 02:35:20 +02:00
|
|
|
if ($etempl->style != '')
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$styles =& new xmlnode('styles');
|
2002-09-24 10:42:51 +02:00
|
|
|
$styles->set_value($etempl->style);
|
2005-02-08 15:59:41 +01:00
|
|
|
$template->add_node($styles);
|
2002-09-12 02:35:20 +02:00
|
|
|
}
|
2005-02-08 15:59:41 +01:00
|
|
|
$this->xul_overlay->add_node($template);
|
2002-09-22 19:56:48 +02:00
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:36 +01:00
|
|
|
/**
|
|
|
|
* create an XML representation of an eTemplate
|
|
|
|
*
|
|
|
|
* @param object $etempl eTemplate object to export
|
|
|
|
* @return string the XML
|
|
|
|
*/
|
2002-09-22 19:56:48 +02:00
|
|
|
function export($etempl)
|
|
|
|
{
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>etempl->data = "; _debug_array($etempl->data);
|
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
$doc =& new xmldoc();
|
2002-10-03 21:53:47 +02:00
|
|
|
$doc->add_comment('$'.'Id$');
|
2002-09-22 19:56:48 +02:00
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
$this->xul_overlay =& new xmlnode('overlay'); // global for all add_etempl calls
|
2005-02-08 15:59:41 +01:00
|
|
|
$this->load_via = $etempl->as_array();
|
2002-09-22 19:56:48 +02:00
|
|
|
|
2002-10-14 02:39:47 +02:00
|
|
|
$embeded_too = True;
|
2005-02-08 15:59:41 +01:00
|
|
|
$this->add_etempl($etempl,$embeded_too);
|
2002-09-12 19:57:27 +02:00
|
|
|
|
2005-02-08 15:59:41 +01:00
|
|
|
$doc->add_root($this->xul_overlay);
|
2002-09-24 10:42:51 +02:00
|
|
|
$xml = $doc->export_xml();
|
2002-09-12 02:35:20 +02:00
|
|
|
|
2005-02-06 19:12:26 +01:00
|
|
|
if ($this->debug)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
|
|
|
echo "<pre>\n" . htmlentities($xml) . "\n</pre>\n";
|
|
|
|
}
|
|
|
|
return $xml;
|
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:36 +01:00
|
|
|
/**
|
|
|
|
* create an eTemplate from it's XML representation
|
|
|
|
*
|
|
|
|
* @param object &$etempl eTemplate object to set
|
|
|
|
* @param string $data the XML
|
|
|
|
* @param array/string array with names of imported templates or error-message
|
|
|
|
*/
|
2002-09-12 02:35:20 +02:00
|
|
|
function import(&$etempl,$data)
|
|
|
|
{
|
2002-09-12 12:04:22 +02:00
|
|
|
if ($this->debug)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
|
|
|
echo "<pre>\n" . htmlentities($data) . "\n</pre><p>\n";
|
|
|
|
}
|
|
|
|
$parser = xml_parser_create();
|
|
|
|
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
|
|
|
|
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
|
2002-09-12 12:04:22 +02:00
|
|
|
$vals = $index = '';
|
2002-09-22 19:56:48 +02:00
|
|
|
$ok = xml_parse_into_struct($parser, $data, $vals, $index);
|
2002-09-12 02:35:20 +02:00
|
|
|
|
2002-09-22 19:56:48 +02:00
|
|
|
if (!$ok || !is_array($vals))
|
2002-09-12 12:04:22 +02:00
|
|
|
{
|
2002-09-22 19:56:48 +02:00
|
|
|
$err = 'Error Line '.xml_get_current_line_number($parser).', Column '.xml_get_current_column_number($parser).
|
2005-11-09 21:50:45 +01:00
|
|
|
': '.xml_error_string(xml_get_error_code($parser));
|
2002-09-12 12:04:22 +02:00
|
|
|
}
|
2002-09-12 02:35:20 +02:00
|
|
|
xml_parser_free($parser);
|
|
|
|
|
2002-09-12 12:04:22 +02:00
|
|
|
if ($err != '')
|
|
|
|
{
|
|
|
|
return $err;
|
|
|
|
}
|
2005-02-08 13:29:06 +01:00
|
|
|
$parents = array();
|
|
|
|
$parent = null;
|
|
|
|
foreach($vals as $n => $node)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
2005-02-08 13:29:06 +01:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<h1>$n</h1><pre>".print_r($node,true)."</pre>";
|
|
|
|
}
|
2002-09-12 02:35:20 +02:00
|
|
|
$type = $node['type'];
|
|
|
|
$tag = $node['tag'];
|
|
|
|
$attr = is_array($node['attributes']) ? $node['attributes'] : array();
|
|
|
|
if ($attr['id'])
|
|
|
|
{
|
|
|
|
$attr['name'] = $attr['id']; unset($attr['id']);
|
|
|
|
}
|
2002-09-17 11:13:29 +02:00
|
|
|
if (isset($attr['options']) && $attr['options'] != '')
|
|
|
|
{
|
|
|
|
$attr['size'] = $attr['options']; unset($attr['options']);
|
|
|
|
}
|
|
|
|
if ($tag != 'textbox' && !isset($attr['type']))
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
|
|
|
$attr['type'] = $this->xul2widget[$tag] ? $this->xul2widget[$tag] : $tag;
|
|
|
|
}
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
2002-09-22 19:56:48 +02:00
|
|
|
echo "<p>$node[level]: $tag/$type: value='$node[value]' attr=\n"; _debug_array($attr);
|
2002-09-12 02:35:20 +02:00
|
|
|
}
|
|
|
|
switch ($tag)
|
|
|
|
{
|
2002-09-22 19:56:48 +02:00
|
|
|
case 'overlay':
|
|
|
|
break;
|
2005-02-08 13:29:06 +01:00
|
|
|
case 'template':
|
2002-09-12 02:35:20 +02:00
|
|
|
case 'grid':
|
2005-02-08 13:29:06 +01:00
|
|
|
if ($type != 'open' && is_array($tab_attr)) // templates/grids in a tabpanel
|
2002-09-12 23:43:41 +02:00
|
|
|
{
|
|
|
|
$tab_names[] = $attr['name'];
|
|
|
|
break;
|
|
|
|
}
|
2005-02-18 23:44:42 +01:00
|
|
|
if ($tag == 'template' && $type != 'complete' && $node['level'] > 2) // level 1 is the overlay
|
2002-09-22 19:56:48 +02:00
|
|
|
{
|
2005-02-08 13:29:06 +01:00
|
|
|
return "Can't import nested $tag's !!!";
|
2002-09-22 19:56:48 +02:00
|
|
|
}
|
2005-02-08 13:29:06 +01:00
|
|
|
switch ($type)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
2005-02-08 13:29:06 +01:00
|
|
|
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.
|
2005-11-09 21:50:45 +01:00
|
|
|
($etempl->lang == '' ? '' : '.'.$etempl->lang);
|
|
|
|
$GLOBALS['egw_info']['etemplate']['cache'][$cname] = $etempl->as_array(1);
|
2005-02-08 13:29:06 +01:00
|
|
|
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')
|
|
|
|
{
|
2005-02-08 15:59:41 +01:00
|
|
|
$size = '';
|
2005-04-20 19:25:06 +02:00
|
|
|
foreach(array('overflow','padding','spacing','class','border','height','width') as $opt)
|
2005-02-08 13:29:06 +01:00
|
|
|
{
|
|
|
|
$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;
|
2002-09-12 02:35:20 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'columns':
|
|
|
|
case 'rows':
|
|
|
|
break;
|
|
|
|
case 'column':
|
|
|
|
if ($type != 'complete')
|
|
|
|
{
|
|
|
|
return 'place widgets in <row> and not in <column> !!!';
|
|
|
|
}
|
2005-02-08 13:29:06 +01:00
|
|
|
$parent['data'][0][$etempl->num2chrs($parent['cols']++)] = $attr['width'] .
|
2002-10-10 13:29:36 +02:00
|
|
|
($attr['disabled'] ? ','.$attr['disabled'] : '');
|
2002-09-12 02:35:20 +02:00
|
|
|
break;
|
|
|
|
case 'row':
|
|
|
|
if ($type != 'open')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
$nul = null; soetemplate::add_child($parent,$nul); // null =& new row
|
2005-02-08 13:29:06 +01:00
|
|
|
$parent['data'][0]['c'.$parent['rows']] = $attr['class'] . ($attr['valign'] ? ','.$attr['valign'] : '');
|
|
|
|
$parent['data'][0]['h'.$parent['rows']] = $attr['height'] .
|
2002-10-10 13:29:36 +02:00
|
|
|
($attr['disabled'] ? ','.$attr['disabled'] : '');
|
2002-09-12 02:35:20 +02:00
|
|
|
break;
|
|
|
|
case 'styles':
|
2002-09-12 23:43:41 +02:00
|
|
|
$etempl->style = trim($node['value']);
|
|
|
|
break;
|
|
|
|
case 'tabbox':
|
|
|
|
if ($type == 'open')
|
|
|
|
{
|
|
|
|
$tab_labels = $tab_helps = $tab_names = array();
|
|
|
|
$tab_attr = $attr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tab_attr['type'] = 'tab';
|
|
|
|
$tab_attr['label'] = implode('|',$tab_labels);
|
|
|
|
$tab_attr['name'] = implode('|',$tab_names);
|
|
|
|
$tab_attr['help'] = implode('|',$tab_helps);
|
|
|
|
$tab_attr['span'] .= $tab_attr['class'] ? ','.$tab_attr['class'] : '';
|
|
|
|
unset($tab_attr['class']);
|
2002-10-12 18:37:44 +02:00
|
|
|
|
2005-02-08 13:29:06 +01:00
|
|
|
soetemplate::add_child($parent,$tab_attr);
|
2002-09-12 23:43:41 +02:00
|
|
|
unset($tab_attr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'tabs':
|
|
|
|
case 'tabpanels':
|
|
|
|
break;
|
|
|
|
case 'tab':
|
|
|
|
if ($type != 'close')
|
|
|
|
{
|
|
|
|
$tab_labels[] = $attr['label'];
|
|
|
|
$tab_helps[] = $attr['statustext'];
|
|
|
|
}
|
2002-09-12 19:57:27 +02:00
|
|
|
break;
|
2002-10-12 18:37:44 +02:00
|
|
|
case 'menupopup':
|
|
|
|
if (is_array($menulist_attr))
|
|
|
|
{
|
|
|
|
$attr['help'] = $attr['statustext']; unset($attr['statustext']);
|
2002-10-13 00:39:01 +02:00
|
|
|
unset($menulist_attr['type']);
|
2002-10-12 18:37:44 +02:00
|
|
|
$menulist_attr += $attr;
|
|
|
|
}
|
|
|
|
break;
|
2002-09-17 11:13:29 +02:00
|
|
|
case 'menulist':
|
2002-10-12 18:37:44 +02:00
|
|
|
if ($type == 'open')
|
|
|
|
{
|
|
|
|
$menulist_attr = $attr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-08 13:29:06 +01:00
|
|
|
soetemplate::add_child($parent,$menulist_attr);
|
2002-10-12 18:37:44 +02:00
|
|
|
unset($menulist_attr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'vbox':
|
|
|
|
case 'hbox':
|
2005-02-06 16:49:50 +01:00
|
|
|
case 'deck':
|
|
|
|
case 'groupbox':
|
2005-02-08 13:29:06 +01:00
|
|
|
case 'box':
|
|
|
|
if ($type != 'close') // open or complete
|
2002-10-12 18:37:44 +02:00
|
|
|
{
|
2005-02-18 23:44:42 +01:00
|
|
|
$attr['size'] = '0'.($attr['orient'] || $attr['size'] ? ','.$attr['orient'].
|
|
|
|
($attr['size'] ? ','.$attr['size'] : '') : '');
|
2005-02-08 13:29:06 +01:00
|
|
|
soetemplate::add_child($parent,$attr);
|
|
|
|
$parents[count($parents)] = &$parent; // $parents[] does not always the same - strange
|
|
|
|
$parent = &$attr;
|
|
|
|
unset($attr);
|
2002-10-12 18:37:44 +02:00
|
|
|
}
|
2005-02-08 13:29:06 +01:00
|
|
|
if ($type != 'open') // close or complete
|
2002-10-12 18:37:44 +02:00
|
|
|
{
|
2005-02-08 13:29:06 +01:00
|
|
|
// 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]);
|
2002-10-12 18:37:44 +02:00
|
|
|
}
|
2002-09-17 11:13:29 +02:00
|
|
|
break;
|
2005-02-06 16:49:50 +01:00
|
|
|
case 'caption': // caption of (group)box
|
2005-02-08 13:29:06 +01:00
|
|
|
if ($parent['type'] == 'groupbox')
|
2005-02-06 16:49:50 +01:00
|
|
|
{
|
2005-02-08 13:29:06 +01:00
|
|
|
$parent['label'] = $attr['label'];
|
2005-02-06 16:49:50 +01:00
|
|
|
}
|
|
|
|
break;
|
2005-02-08 13:29:06 +01:00
|
|
|
// the following labels create automaticaly a child-entry in their parent
|
2002-09-12 02:35:20 +02:00
|
|
|
case 'textbox':
|
|
|
|
if ($attr['multiline'])
|
|
|
|
{
|
2005-02-08 13:29:06 +01:00
|
|
|
unset($attr['multiline']);
|
2002-09-12 02:35:20 +02:00
|
|
|
$attr['type'] = 'textarea';
|
2002-09-25 00:05:01 +02:00
|
|
|
$attr['size'] = $attr['rows'] . ($attr['cols'] ? ','.$attr['cols'] : '');
|
2002-09-12 02:35:20 +02:00
|
|
|
unset($attr['cols']);
|
|
|
|
unset($attr['rows']);
|
|
|
|
}
|
|
|
|
elseif ($attr['type']) // integer,float
|
|
|
|
{
|
|
|
|
$attr['size'] = $attr['min'] . ($attr['max'] ? ','.$attr['max'] : ($attr['size'] ? ',':'')) . ','.$attr['size'];
|
|
|
|
unset($attr['min']);
|
|
|
|
unset($attr['max']);
|
|
|
|
}
|
|
|
|
else // input
|
|
|
|
{
|
|
|
|
$attr['type'] = 'text';
|
|
|
|
$attr['size'] .= $attr['maxlength']!='' ? ','.$attr['maxlength'] : '';
|
|
|
|
unset($attr['maxlength']);
|
|
|
|
}
|
|
|
|
// fall-through
|
|
|
|
default:
|
2002-09-12 19:57:27 +02:00
|
|
|
switch ($tag)
|
2002-09-12 02:35:20 +02:00
|
|
|
{
|
2002-09-12 23:43:41 +02:00
|
|
|
case 'description':
|
2002-09-12 23:46:11 +02:00
|
|
|
case 'label':
|
2002-09-12 19:57:27 +02:00
|
|
|
$attr['label'] = $attr['value'];
|
|
|
|
unset($attr['value']);
|
|
|
|
break;
|
|
|
|
case 'template':
|
|
|
|
$attr['size'] = $attr['content'];
|
|
|
|
unset($attr['content']);
|
|
|
|
break;
|
2002-09-12 23:43:41 +02:00
|
|
|
case 'image':
|
2002-10-12 18:37:44 +02:00
|
|
|
$attr['name'] = $attr['src'];
|
2002-09-12 23:43:41 +02:00
|
|
|
unset($attr['src']);
|
|
|
|
break;
|
2002-09-17 11:13:29 +02:00
|
|
|
case 'listbox':
|
2002-10-03 18:48:17 +02:00
|
|
|
$attr['size'] = ereg_replace(',*$','',$attr['rows'].','.$attr['size']);
|
2002-09-17 11:13:29 +02:00
|
|
|
unset($attr['rows']);
|
|
|
|
break;
|
2002-09-17 14:29:01 +02:00
|
|
|
case 'button':
|
|
|
|
if ($attr['image'] || $attr['ro_image'])
|
|
|
|
{
|
|
|
|
$attr['size'] = $attr['image'] . ($attr['ro_image'] ? ','.$attr['ro_image'] : '');
|
|
|
|
unset($attr['image']); unset($attr['ro_image']);
|
|
|
|
}
|
|
|
|
break;
|
2002-09-12 02:35:20 +02:00
|
|
|
}
|
|
|
|
$attr['help'] = $attr['statustext']; unset($attr['statustext']);
|
|
|
|
$attr['span'] .= $attr['class'] ? ','.$attr['class'] : ''; unset($attr['class']);
|
|
|
|
if ($type == 'close')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2005-02-08 13:29:06 +01:00
|
|
|
soetemplate::add_child($parent,$attr);
|
|
|
|
unset($attr);
|
2002-09-12 02:35:20 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-02-08 13:29:06 +01:00
|
|
|
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>";
|
|
|
|
}
|
2002-09-12 02:35:20 +02:00
|
|
|
}
|
2002-09-24 10:42:51 +02:00
|
|
|
return $imported;
|
2002-09-12 02:35:20 +02:00
|
|
|
}
|
|
|
|
}
|