mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 16:44:20 +01:00
first version of xml/xul import & export of etemplates
This commit is contained in:
parent
0d7f3ed630
commit
849a0e3835
@ -351,6 +351,10 @@
|
||||
}
|
||||
$msg = $this->etemplate->writeLangFile($content['name'],'en',$additional);
|
||||
}
|
||||
elseif ($content['export_xml'])
|
||||
{
|
||||
$msg = $this->export_xml();
|
||||
}
|
||||
elseif ($content['db_tools'])
|
||||
{
|
||||
ExecMethod('etemplate.db_tools.edit');
|
||||
@ -359,6 +363,52 @@
|
||||
$this->edit($msg);
|
||||
}
|
||||
|
||||
function export_xml()
|
||||
{
|
||||
$name = $this->etemplate->name;
|
||||
$template = $this->etemplate->template != '' ? $this->etemplate->template : 'default';
|
||||
|
||||
list($app) = explode('.',$name);
|
||||
|
||||
$dir = PHPGW_SERVER_ROOT . "/$app/templates/$template";
|
||||
if ($create_it = !is_dir($dir))
|
||||
{
|
||||
$dir = PHPGW_SERVER_ROOT . "/$app/templates";
|
||||
}
|
||||
if (!is_writeable($dir))
|
||||
{
|
||||
return "Error: webserver is not allowed to write into '$dir' !!!";
|
||||
}
|
||||
if ($create)
|
||||
{
|
||||
mkdir($dir .= "/$template");
|
||||
}
|
||||
$file = "$dir/$name";
|
||||
if ($this->etemplate->lang)
|
||||
{
|
||||
$file .= '.' . $this->etemplate->lang;
|
||||
}
|
||||
$old_file = $file . '.old.xul';
|
||||
$file .= '.xul';
|
||||
if (file_exists($file))
|
||||
{
|
||||
rename($file,$old_file);
|
||||
}
|
||||
|
||||
if (!($f = fopen($file,'w')))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
$xul_io = CreateObject('etemplate.xul_io');
|
||||
$xul = $xul_io->export(&$this->etemplate);
|
||||
|
||||
fwrite($f,$xul);
|
||||
fclose($f);
|
||||
|
||||
return $xul_io->import(&$this->etemplate,$xul);
|
||||
return "eTemplate '$name' written to '$file'";
|
||||
}
|
||||
|
||||
function delete($post_vars='',$back = 'edit')
|
||||
{
|
||||
if ($this->debug)
|
||||
@ -508,7 +558,8 @@
|
||||
'show' => True,
|
||||
'dump' => True,
|
||||
'langfile' => True,
|
||||
'size' => True
|
||||
'size' => True,
|
||||
'export_xml' => True
|
||||
);
|
||||
if (!$msg && isset($post_vars['values']) && !isset($post_vars['vals']))
|
||||
{
|
||||
|
@ -545,7 +545,7 @@
|
||||
default:
|
||||
if (!isset($this->extension[$cell['type']]))
|
||||
{
|
||||
$html .= '<i>unknown type</i>';
|
||||
$html .= "<i>unknown type '$cell[type]'</i>";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
324
etemplate/inc/class.xul_io.inc.php
Normal file
324
etemplate/inc/class.xul_io.inc.php
Normal file
@ -0,0 +1,324 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* phpGroupWare - eTemplates - XUL/XML Import & Export *
|
||||
* http://www.phpgroupware.org *
|
||||
* Written by Ralf Becker <RalfBecker@outdoor-training.de> *
|
||||
* -------------------------------------------- *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU General Public License as published by the *
|
||||
* Free Software Foundation; either version 2 of the License, or (at your *
|
||||
* option) any later version. *
|
||||
\**************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
include(PHPGW_SERVER_ROOT . '/etemplate/inc/xmltools.php');
|
||||
|
||||
|
||||
class xul_io
|
||||
{
|
||||
var $widget2xul;
|
||||
var $attr2xul;
|
||||
var $xul2widget;
|
||||
|
||||
function xul_io()
|
||||
{
|
||||
$this->attr2xul = array( // how to translate attr, common to all widgets
|
||||
'name' => 'id',
|
||||
'help' => 'statustext',
|
||||
'span' => 'span,class',
|
||||
'type' => '', // this is the widget-name => dont write as attr
|
||||
'disabled' => 'disabled=true',
|
||||
'readonly' => 'readonly=true'
|
||||
);
|
||||
$this->widget2xul = array( // how to translate widget-names ( 0 => ) and widget-spec. attr.
|
||||
'label' => array(
|
||||
'.name' => 'label',
|
||||
'label' => 'value'
|
||||
),
|
||||
'text' => array(
|
||||
'.name' => 'textbox',
|
||||
'size' => 'size,maxlength'
|
||||
),
|
||||
'textarea' => array(
|
||||
'.name' => 'textbox',
|
||||
'.set' => 'multiline=true',
|
||||
'size' => 'cols,rows'
|
||||
),
|
||||
'integer' => array(
|
||||
'.name' => 'textbox',
|
||||
'.set' => 'type=integer',
|
||||
'size' => 'min,max,size'
|
||||
),
|
||||
'float' => array(
|
||||
'.name' => 'textbox',
|
||||
'.set' => 'type=float',
|
||||
'size' => 'min,max,size'
|
||||
),
|
||||
'select' => array(
|
||||
'.name' => 'menulist,menupopup'
|
||||
)
|
||||
);
|
||||
$this->xul2widget = array(
|
||||
'menupopup' => 'select'
|
||||
);
|
||||
}
|
||||
|
||||
function set_attributes(&$widget,$attr,$val,$spanned='')
|
||||
{
|
||||
if ($attr != '')
|
||||
{
|
||||
$attrs = explode(',',$attr);
|
||||
|
||||
if (count($attrs))
|
||||
{
|
||||
$vals = count($attrs) > 1 ? explode(',',$val) : array($val);
|
||||
while (list($n,$attr) = each($attrs))
|
||||
{
|
||||
if ($val = $vals[$n])
|
||||
{
|
||||
if ($attr == 'span')
|
||||
{
|
||||
$spanned = $val == 'all' ? 999 : $val - 1;
|
||||
}
|
||||
list($attr,$set) = explode('=',$attr);
|
||||
$widget->set_attribute($attr,$set != '' ? $set : $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function export($etempl)
|
||||
{
|
||||
if ($this->debug)
|
||||
{
|
||||
echo "<p>etempl->data = "; _debug_array($etempl->data);
|
||||
}
|
||||
$doc = new xmldoc();
|
||||
|
||||
$xul_grid = new xmlnode('grid');
|
||||
$xul_grid->set_attribute('id',$etempl->name);
|
||||
$xul_grid->set_attribute('template',$etempl->template);
|
||||
$xul_grid->set_attribute('lang',$etempl->lang);
|
||||
$xul_grid->set_attribute('group',$etempl->group);
|
||||
$xul_grid->set_attribute('version',$etempl->version);
|
||||
$this->set_attributes($xul_grid,'width,height,border,class,spacing,padding',$etempl->size);
|
||||
|
||||
$xul_columns = new xmlnode('columns');
|
||||
$xul_rows = new xmlnode('rows');
|
||||
|
||||
reset($etempl->data);
|
||||
list(,$opts) = each ($etempl->data); // read over options-row
|
||||
while (list($r,$row) = each ($etempl->data))
|
||||
{
|
||||
$xul_row = new xmlnode('row');
|
||||
$this->set_attributes($xul_row,'class,valign',$opts["c$r"]);
|
||||
$this->set_attributes($xul_row,'height',$opts["h$r"]);
|
||||
|
||||
$spanned = 0;
|
||||
while (list($c,$cell) = each($row))
|
||||
{
|
||||
if ($r == '1') // write columns only once in the first row
|
||||
{
|
||||
$xul_column = new xmlnode('column');
|
||||
$this->set_attributes($xul_column,'width',$opts[$c]);
|
||||
$xul_columns->add_node($xul_column);
|
||||
}
|
||||
if ($spanned)
|
||||
{
|
||||
--$spanned;
|
||||
continue; // spanned cells are not written
|
||||
}
|
||||
$type = $cell['type'];
|
||||
if (is_array($type))
|
||||
{
|
||||
list(,$type) = each($type);
|
||||
}
|
||||
$widgetattr2xul = isset($this->widget2xul[$type]) ? $this->widget2xul[$type] : array();
|
||||
$type = isset($widgetattr2xul['.name']) ? $widgetattr2xul['.name'] : $type;
|
||||
list($parent,$child) = explode(',',$type);
|
||||
$widget = new xmlnode($child ? $child : $parent);
|
||||
|
||||
if (isset($widgetattr2xul['.set'])) // set default-attr for type
|
||||
{
|
||||
$attrs = explode(',',$widgetattr2xul[1]);
|
||||
while (list(,$attr) = each($attr))
|
||||
{
|
||||
list($attr,$val) = explode('=',$attr);
|
||||
$widget->set_attribute($attr,$val);
|
||||
}
|
||||
}
|
||||
while (list($attr,$val) = each($cell))
|
||||
{
|
||||
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];
|
||||
}
|
||||
$this->set_attributes($widget,$attr,$val,&$spanned);
|
||||
}
|
||||
if ($child)
|
||||
{
|
||||
$parent = new xmlnode($parent);
|
||||
$parent->add_node($widget);
|
||||
$xul_row->add_node($parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
$xul_row->add_node($widget);
|
||||
}
|
||||
}
|
||||
$xul_rows->add_node($xul_row);
|
||||
}
|
||||
$xul_grid->add_node($xul_columns);
|
||||
$xul_grid->add_node($xul_rows);
|
||||
|
||||
if ($etempl->style != '')
|
||||
{
|
||||
$styles = new xmlnode('styles');
|
||||
$styles->set_text($etempl->style);
|
||||
$xul_grid->add_node($styles);
|
||||
}
|
||||
$doc->add_root($xul_grid);
|
||||
$xml = $doc->dump_mem();
|
||||
|
||||
if ($this->debug)
|
||||
{
|
||||
echo "<pre>\n" . htmlentities($xml) . "\n</pre>\n";
|
||||
}
|
||||
return $xml;
|
||||
}
|
||||
|
||||
function import(&$etempl,$data)
|
||||
{
|
||||
//if ($this->debug)
|
||||
{
|
||||
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);
|
||||
xml_parse_into_struct($parser, $data, $vals, $index);
|
||||
|
||||
xml_parser_free($parser);
|
||||
|
||||
while (list($n,$node) = each($vals))
|
||||
{
|
||||
$type = $node['type'];
|
||||
$tag = $node['tag'];
|
||||
$attr = is_array($node['attributes']) ? $node['attributes'] : array();
|
||||
if ($attr['id'])
|
||||
{
|
||||
$attr['name'] = $attr['id']; unset($attr['id']);
|
||||
}
|
||||
if ($tag != 'textbox')
|
||||
{
|
||||
$attr['type'] = $this->xul2widget[$tag] ? $this->xul2widget[$tag] : $tag;
|
||||
}
|
||||
if ($this->debug)
|
||||
{
|
||||
echo "<p>$node[level]: $tag/$type: value='$node[value]' attr="; _debug_array($attr);
|
||||
}
|
||||
switch ($tag)
|
||||
{
|
||||
case 'grid':
|
||||
if ($type != 'open')
|
||||
{
|
||||
break;
|
||||
}
|
||||
if ($node['level'] > 1)
|
||||
{
|
||||
return "Can't import nested $node[type]'s !!!";
|
||||
}
|
||||
$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':
|
||||
case 'menulist':
|
||||
break;
|
||||
case 'column':
|
||||
if ($type != 'complete')
|
||||
{
|
||||
return 'place widgets in <row> and not in <column> !!!';
|
||||
}
|
||||
$etempl->data[0][$etempl->num2chrs($etempl->cols++)] = $attr['width'];
|
||||
break;
|
||||
case 'row':
|
||||
if ($type != 'open')
|
||||
{
|
||||
break;
|
||||
}
|
||||
$r = ++$etempl->rows;
|
||||
$col = 0;
|
||||
$etempl->data[0]["c$r"] = $attr['class'] . ($attr['valign'] ? ','.$attr['valign'] : '');
|
||||
$etempl->data[0]["h$r"] = $attr['height'];
|
||||
break;
|
||||
case 'styles':
|
||||
$etempl->style = $node['value'];
|
||||
case 'textbox':
|
||||
if ($attr['multiline'])
|
||||
{
|
||||
$attr['type'] = 'textarea';
|
||||
$attr['size'] = $attr['cols'] . ($attr['rows'] ? ','.$attr['rows'] : '');
|
||||
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:
|
||||
if ($tag == 'label')
|
||||
{
|
||||
$attr['label'] = $attr['value']; unset($attr['value']);
|
||||
}
|
||||
$attr['help'] = $attr['statustext']; unset($attr['statustext']);
|
||||
$spanned = $attr['span'] == 'all' ? $etempl->cols - $col : $attr['span'];
|
||||
$attr['span'] .= $attr['class'] ? ','.$attr['class'] : ''; unset($attr['class']);
|
||||
if ($type == 'close')
|
||||
{
|
||||
break;
|
||||
}
|
||||
$etempl->data[$etempl->rows][$etempl->num2chrs($col++)] = $attr;
|
||||
|
||||
while (--$spanned > 0)
|
||||
{
|
||||
$etempl->data[$etempl->rows][$etempl->num2chrs($col++)] = $etempl->empty_cell();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//if ($this->debug)
|
||||
{
|
||||
_debug_array($etempl->data);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
476
etemplate/inc/xmltools.php
Normal file
476
etemplate/inc/xmltools.php
Normal file
@ -0,0 +1,476 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* phpGroupWare - xmltools *
|
||||
* http://www.phpgroupware.org *
|
||||
* Written by Seek3r *
|
||||
* -------------------------------------------- *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU General Public License as published by the *
|
||||
* Free Software Foundation; either version 2 of the License, or (at your *
|
||||
* option) any later version. *
|
||||
\**************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
function xml_get_children($vals, &$i)
|
||||
{
|
||||
$children = array();
|
||||
if (isset($vals[$i]['value']))
|
||||
{
|
||||
$children[] = $vals[$i]['value'];
|
||||
}
|
||||
|
||||
while (++$i < count($vals))
|
||||
{
|
||||
switch ($vals[$i]['type'])
|
||||
{
|
||||
case 'cdata':
|
||||
$children[] = $vals[$i]['value'];
|
||||
break;
|
||||
case 'complete':
|
||||
$children[] = array(
|
||||
'tag' => $vals[$i]['tag'],
|
||||
'attributes' => isset($vals[$i]['attributes']) ? $vals[$i]['attributes'] : null,
|
||||
'value' => $vals[$i]['value'],
|
||||
);
|
||||
break;
|
||||
case 'open':
|
||||
$children[] = array(
|
||||
'tag' => $vals[$i]['tag'],
|
||||
'attributes' => isset($vals[$i]['attributes']) ? $vals[$i]['attributes'] : null,
|
||||
'children' => xml_get_children($vals, $i),
|
||||
);
|
||||
break;
|
||||
case 'close':
|
||||
return $children;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function xml_get_tree($data)
|
||||
{
|
||||
$parser = xml_parser_create();
|
||||
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
|
||||
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
|
||||
xml_parse_into_struct($parser, $data, $vals, $index);
|
||||
xml_parser_free($parser);
|
||||
|
||||
return array(
|
||||
'tag' => $vals[0]['tag'],
|
||||
'attributes' => isset($vals[0]['attributes']) ? $vals[0]['attributes'] : null,
|
||||
'children' => xml_get_children($vals, $i = 0),
|
||||
);
|
||||
}
|
||||
|
||||
function xml2array ($xmldata,$is_start = True)
|
||||
{
|
||||
if($is_start)
|
||||
{
|
||||
$xmldata = xml_get_tree($xmldata);
|
||||
}
|
||||
|
||||
if(!is_array($xmldata['children']))
|
||||
{
|
||||
$found_at = strstr($xmldata['value'],'PHP_SERIALIZED_OBJECT:');
|
||||
if($found_at != False)
|
||||
{
|
||||
$xmldata['value'] = str_replace ('PHP_SERIALIZED_OBJECT:', '', $xmldata['value']);
|
||||
$xmldata['value'] = unserialize ($xmldata['value']);
|
||||
}
|
||||
if($is_start)
|
||||
{
|
||||
$xml_array[$xmldata['tag']] = $xmldata['value'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $xmldata['value'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$new_index = False;
|
||||
reset($xmldata['children']);
|
||||
while(list($key,$val) = each($xmldata['children']))
|
||||
{
|
||||
if(!isset($found_keys[$val['tag']]))
|
||||
{
|
||||
$found_keys[$val['tag']] = True;
|
||||
}
|
||||
else
|
||||
{
|
||||
$new_index = True;
|
||||
}
|
||||
}
|
||||
|
||||
if($new_index)
|
||||
{
|
||||
reset($xmldata['children']);
|
||||
while(list($key,$val) = each($xmldata['children']))
|
||||
{
|
||||
$xml_array[$val['tag']][] = xml2array($val,False);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reset($xmldata['children']);
|
||||
while(list($key,$val) = each($xmldata['children']))
|
||||
{
|
||||
$xml_array[$val['tag']] = xml2array($val,False);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $xml_array;
|
||||
}
|
||||
|
||||
function var2xml ($name, $value,$is_root=True)
|
||||
{
|
||||
$node = new xmlnode($name);
|
||||
switch (gettype($value))
|
||||
{
|
||||
case 'string':
|
||||
case 'integer':
|
||||
case 'double':
|
||||
case 'NULL':
|
||||
$node->set_text($value);
|
||||
break;
|
||||
case 'boolean':
|
||||
if($value == True)
|
||||
{
|
||||
$node->set_text('1');
|
||||
}
|
||||
else
|
||||
{
|
||||
$node->set_text('0');
|
||||
}
|
||||
break;
|
||||
case 'array':
|
||||
$new_index = False;
|
||||
while (list ($idxkey, $idxval) = each ($value))
|
||||
{
|
||||
if(is_array($idxval))
|
||||
{
|
||||
while (list ($k, $i) = each ($idxval))
|
||||
{
|
||||
if (is_int($k))
|
||||
{
|
||||
$new_index = True;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
reset($value);
|
||||
while (list ($key, $val) = each ($value))
|
||||
{
|
||||
if($new_index)
|
||||
{
|
||||
$keyname = $name;
|
||||
$nextkey = $key;
|
||||
}
|
||||
else
|
||||
{
|
||||
$keyname = $key;
|
||||
$nextkey = $key;
|
||||
}
|
||||
switch (gettype($val))
|
||||
{
|
||||
case 'string':
|
||||
case 'integer':
|
||||
case 'double':
|
||||
case 'NULL':
|
||||
$subnode = new xmlnode($nextkey);
|
||||
$subnode->set_text($val);
|
||||
$node->add_node($subnode);
|
||||
break;
|
||||
case 'boolean':
|
||||
$subnode = new xmlnode($nextkey);
|
||||
if($val == True)
|
||||
{
|
||||
$subnode->set_text('1');
|
||||
}
|
||||
else
|
||||
{
|
||||
$subnode->set_text('0');
|
||||
}
|
||||
$node->add_node($subnode);
|
||||
break;
|
||||
case 'array':
|
||||
if($new_index)
|
||||
{
|
||||
while (list ($subkey, $subval) = each ($val))
|
||||
{
|
||||
$node->add_node(var2xml ($nextkey, $subval, False));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$subnode = var2xml ($nextkey, $val, False);
|
||||
$node->add_node($subnode);
|
||||
}
|
||||
break;
|
||||
case 'object':
|
||||
$subnode = new xmlnode($nextkey);
|
||||
$subnode->set_cdata('PHP_SERIALIZED_OBJECT:'.serialize($val));
|
||||
$node->add_node($subnode);
|
||||
break;
|
||||
case 'resource':
|
||||
echo 'Halt: Cannot package PHP resource pointers into XML<br>';
|
||||
exit;
|
||||
default:
|
||||
echo 'Halt: Invalid or unknown data type<br>';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'object':
|
||||
$node->set_cdata('PHP_SERIALIZED_OBJECT:'.serialize($value));
|
||||
break;
|
||||
case 'resource':
|
||||
echo 'Halt: Cannot package PHP resource pointers into XML<br>';
|
||||
exit;
|
||||
default:
|
||||
echo 'Halt: Invalid or unknown data type<br>';
|
||||
exit;
|
||||
}
|
||||
|
||||
if($is_root)
|
||||
{
|
||||
$xmldoc = new xmldoc();
|
||||
$xmldoc->add_root($node);
|
||||
return $xmldoc;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
||||
class xmldoc
|
||||
{
|
||||
var $xmlversion = '';
|
||||
var $root_node;
|
||||
var $doctype = Array();
|
||||
var $comments = Array();
|
||||
|
||||
function xmldoc ($version = '1.0')
|
||||
{
|
||||
$this->xmlversion = $version;
|
||||
}
|
||||
|
||||
function add_root ($node_object)
|
||||
{
|
||||
if(is_object($node_object))
|
||||
{
|
||||
$this->root_node = $node_object;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo 'Not a valid xmlnode object<br>';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function set_doctype ($name, $uri = '')
|
||||
{
|
||||
$this->doctype[$name] = $uri;
|
||||
}
|
||||
|
||||
function add_comment ($comment)
|
||||
{
|
||||
$this->comments[] = $comment;
|
||||
}
|
||||
|
||||
function dump_mem()
|
||||
{
|
||||
$result = '<?xml version="'.$this->xmlversion.'"?>'."\n";
|
||||
if(count($this->doctype) == 1)
|
||||
{
|
||||
list($doctype_name,$doctype_uri) = each($this->doctype);
|
||||
$result .= '<!DOCTYPE '.$doctype_name.' SYSTEM "'.$doctype_uri.'">'."\n";
|
||||
}
|
||||
if(count($this->comments) > 0 )
|
||||
{
|
||||
reset($this->comments);
|
||||
while(list($key,$val) = each ($this->comments))
|
||||
{
|
||||
$result .= "<!-- $val -->\n";
|
||||
}
|
||||
}
|
||||
|
||||
if(is_object($this->root_node))
|
||||
{
|
||||
$indent = 0;
|
||||
$result .= $this->root_node->dump_mem($indent);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
class xmlnode
|
||||
{
|
||||
var $name = '';
|
||||
var $data;
|
||||
var $data_type;
|
||||
var $attributes = Array();
|
||||
var $comments = Array();
|
||||
var $indentstring = " ";
|
||||
|
||||
function xmlnode ($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
function add_node ($node_object , $name = '')
|
||||
{
|
||||
if (is_object($node_object))
|
||||
{
|
||||
if(!is_array($this->data))
|
||||
{
|
||||
$this->data = Array();
|
||||
$this->data_type = 'node';
|
||||
}
|
||||
if ($name != '')
|
||||
{
|
||||
$this->data[$name] = $node_object;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->data[] = $node_object;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!is_array($this->data))
|
||||
{
|
||||
$this->data = Array();
|
||||
$this->data_type = 'node';
|
||||
}
|
||||
$this->data[$name] = var2xml ($name, $node_object, False);
|
||||
//echo 'Not a valid xmlnode object<br>';
|
||||
//exit;
|
||||
}
|
||||
}
|
||||
|
||||
function set_text ($string)
|
||||
{
|
||||
$this->data = $string;
|
||||
$this->data_type = 'text';
|
||||
}
|
||||
|
||||
function set_cdata ($string)
|
||||
{
|
||||
$this->data = $string;
|
||||
$this->data_type = 'cdata';
|
||||
}
|
||||
|
||||
function set_attribute ($name, $value = '')
|
||||
{
|
||||
$this->attributes[$name] = $value;
|
||||
}
|
||||
|
||||
function add_comment ($comment)
|
||||
{
|
||||
$this->comments[] = $comment;
|
||||
}
|
||||
|
||||
function dump_mem($indent = 1)
|
||||
{
|
||||
for ($i = 0; $i < $indent; $i++)
|
||||
{
|
||||
$indentstring .= $this->indentstring;
|
||||
}
|
||||
|
||||
$result = $indentstring.'<'.$this->name;
|
||||
if(count($this->attributes) > 0 )
|
||||
{
|
||||
reset($this->attributes);
|
||||
while(list($key,$val) = each ($this->attributes))
|
||||
{
|
||||
$result .= ' '.$key.'="'.$val.'"';
|
||||
}
|
||||
}
|
||||
|
||||
$endtag_indent = $indentstring;
|
||||
if (empty($this->data_type))
|
||||
{
|
||||
$result .= '/>'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$result .= '>';
|
||||
|
||||
switch ($this->data_type)
|
||||
{
|
||||
case 'text':
|
||||
if(is_array($this->data))
|
||||
{
|
||||
$type_error = True;
|
||||
break;
|
||||
}
|
||||
|
||||
if(strlen($this->data) > 30)
|
||||
{
|
||||
$result .= "\n".$indentstring.$this->indentstring.$this->data."\n";
|
||||
$endtag_indent = $indentstring;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result .= $this->data;
|
||||
$endtag_indent = '';
|
||||
}
|
||||
break;
|
||||
case 'cdata':
|
||||
if(is_array($this->data))
|
||||
{
|
||||
$type_error = True;
|
||||
break;
|
||||
}
|
||||
$result .= '<![CDATA['.$this->data.']]>';
|
||||
$endtag_indent = '';
|
||||
break;
|
||||
case 'node':
|
||||
$result .= "\n";
|
||||
if(!is_array($this->data))
|
||||
{
|
||||
$type_error = True;
|
||||
break;
|
||||
}
|
||||
|
||||
$subindent = $indent+1;
|
||||
while(list($key,$val) = each ($this->data))
|
||||
{
|
||||
if(is_object($val))
|
||||
{
|
||||
$result .= $val->dump_mem($subindent);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($this->data != '')
|
||||
{
|
||||
echo 'Invalid or unset data type ('.$this->data_type.'). This should not be possible if using the class as intended<br>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($type_error)
|
||||
{
|
||||
echo 'Invalid data type. Tagged as '.$this->data_type.' but data is '.gettype($this->data).'<br>';
|
||||
}
|
||||
|
||||
$result .= $endtag_indent.'</'.$this->name.'>';
|
||||
if($indent != 0)
|
||||
{
|
||||
$result .= "\n";
|
||||
}
|
||||
}
|
||||
if(count($this->comments) > 0 )
|
||||
{
|
||||
reset($this->comments);
|
||||
while(list($key,$val) = each ($this->comments))
|
||||
{
|
||||
$result .= $endtag_indent."<!-- $val -->\n";
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// eTemplates for Application 'etemplate', generated by etemplate.dump() 2002-09-04 01:01
|
||||
// eTemplates for Application 'etemplate', generated by etemplate.dump() 2002-09-12 02:41
|
||||
|
||||
$templ_data[] = array('name' => 'etemplate.editor','template' => '','lang' => '','group' => '0','version' => '0.9.13.004','data' => 'a:8:{i:0;a:1:{s:1:\"A\";s:2:\"5%\";}i:1;a:1:{s:1:\"A\";a:4:{s:4:\"type\";s:5:\"label\";s:4:\"size\";s:2:\"bi\";s:5:\"label\";s:27:\"Editable Templates - Editor\";s:4:\"name\";s:3:\"msg\";}}i:2;a:1:{s:1:\"A\";a:2:{s:4:\"type\";s:5:\"hrule\";s:4:\"span\";s:3:\"all\";}}i:3;a:1:{s:1:\"A\";a:3:{s:4:\"type\";s:8:\"template\";s:4:\"span\";s:3:\"all\";s:4:\"name\";s:21:\"etemplate.editor.keys\";}}i:4;a:1:{s:1:\"A\";a:3:{s:4:\"type\";s:8:\"template\";s:4:\"span\";s:3:\"all\";s:4:\"name\";s:24:\"etemplate.editor.buttons\";}}i:5;a:1:{s:1:\"A\";a:3:{s:4:\"type\";s:8:\"template\";s:4:\"span\";s:3:\"all\";s:4:\"name\";s:21:\"etemplate.editor.edit\";}}i:6;a:1:{s:1:\"A\";a:3:{s:4:\"type\";s:5:\"label\";s:4:\"span\";s:3:\"all\";s:5:\"label\";s:10:\"CSS-styles\";}}i:7;a:1:{s:1:\"A\";a:5:{s:4:\"type\";s:8:\"textarea\";s:4:\"size\";s:5:\"10,80\";s:4:\"span\";s:3:\"all\";s:4:\"name\";s:5:\"style\";s:4:\"help\";s:155:\"embeded CSS styles, eg. \'.red { background: red; }\' (note the \'.\' before the class-name) or \'@import url(...)\' (class names are global for the whole page!)\";}}}','size' => '100%','style' => '',);
|
||||
|
||||
@ -95,7 +95,9 @@ $templ_data[] = array('name' => 'etemplate.tab_widget.test.note','template' => '
|
||||
|
||||
$templ_data[] = array('name' => 'etemplate.tab_widget.tab_active','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:2:{i:0;a:1:{s:2:\"c1\";s:3:\"nmh\";}i:1;a:1:{s:1:\"A\";a:4:{s:4:\"type\";s:5:\"label\";s:4:\"span\";s:21:\",etemplate_tab_active\";s:5:\"label\";s:6:\"@label\";s:4:\"help\";s:5:\"@help\";}}}','size' => ',,,,0,0','style' => '.etemplate_tab_active { border-style:solid; border-width:2px 2px 0px; border-color:black; padding:6px; }',);
|
||||
|
||||
$templ_data[] = array('name' => 'etemplate.editor.list_result.list','template' => '','lang' => '','group' => '0','version' => '0.9.15.001','data' => 'a:3:{i:0;a:2:{s:2:\"c1\";s:3:\"nmh\";s:2:\"c2\";s:3:\"nmr\";}i:1;a:6:{s:1:\"A\";a:2:{s:4:\"type\";s:5:\"label\";s:5:\"label\";s:4:\"Name\";}s:1:\"B\";a:2:{s:4:\"type\";s:5:\"label\";s:5:\"label\";s:8:\"Template\";}s:1:\"C\";a:2:{s:4:\"type\";s:5:\"label\";s:5:\"label\";s:4:\"Lang\";}s:1:\"D\";a:3:{s:4:\"type\";s:5:\"label\";s:5:\"label\";s:7:\"Version\";s:5:\"align\";s:6:\"center\";}s:1:\"E\";a:6:{s:4:\"type\";s:6:\"button\";s:4:\"span\";s:3:\"all\";s:5:\"label\";s:6:\"Search\";s:5:\"align\";s:6:\"center\";s:4:\"name\";s:6:\"search\";s:4:\"help\";s:38:\"start new search for the above pattern\";}s:1:\"F\";a:1:{s:4:\"type\";s:5:\"label\";}}i:2;a:6:{s:1:\"A\";a:3:{s:4:\"type\";s:5:\"label\";s:7:\"no_lang\";s:1:\"1\";s:4:\"name\";s:15:\"${row}[et_name]\";}s:1:\"B\";a:3:{s:4:\"type\";s:5:\"label\";s:7:\"no_lang\";s:1:\"1\";s:4:\"name\";s:19:\"${row}[et_template]\";}s:1:\"C\";a:3:{s:4:\"type\";s:5:\"label\";s:7:\"no_lang\";s:1:\"1\";s:4:\"name\";s:15:\"${row}[et_lang]\";}s:1:\"D\";a:3:{s:4:\"type\";s:5:\"label\";s:7:\"no_lang\";s:1:\"1\";s:4:\"name\";s:18:\"${row}[et_version]\";}s:1:\"E\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:4:\"Edit\";s:4:\"name\";s:10:\"read[$row]\";s:4:\"help\";s:34:\"load this template into the editor\";}s:1:\"F\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:6:\"Delete\";s:4:\"name\";s:12:\"delete[$row]\";s:4:\"help\";s:21:\"delete this eTemplate\";}}}','size' => '','style' => '',);
|
||||
|
||||
$templ_data[] = array('name' => 'etemplate.editor.list_result','template' => '','lang' => '','group' => '0','version' => '0.9.15.001','data' => 'a:5:{i:0;a:0:{}i:1;a:1:{s:1:\"A\";a:6:{s:4:\"type\";s:5:\"label\";s:4:\"size\";s:2:\"bi\";s:4:\"span\";s:3:\"all\";s:5:\"label\";s:27:\"Editable Templates - Search\";s:7:\"no_lang\";s:1:\"1\";s:4:\"name\";s:3:\"msg\";}}i:2;a:1:{s:1:\"A\";a:2:{s:4:\"type\";s:5:\"hrule\";s:4:\"span\";s:3:\"all\";}}i:3;a:1:{s:1:\"A\";a:2:{s:4:\"type\";s:8:\"template\";s:4:\"name\";s:21:\"etemplate.editor.keys\";}}i:4;a:1:{s:1:\"A\";a:3:{s:4:\"type\";s:8:\"template\";s:4:\"span\";s:3:\"all\";s:4:\"name\";s:33:\"etemplate.editor.list_result.list\";}}}','size' => '100%','style' => '',);
|
||||
|
||||
$templ_data[] = array('name' => 'etemplate.editor.list_result.list','template' => '','lang' => '','group' => '0','version' => '0.9.15.001','data' => 'a:3:{i:0;a:2:{s:2:\"c1\";s:3:\"nmh\";s:2:\"c2\";s:3:\"nmr\";}i:1;a:6:{s:1:\"A\";a:2:{s:4:\"type\";s:5:\"label\";s:5:\"label\";s:4:\"Name\";}s:1:\"B\";a:2:{s:4:\"type\";s:5:\"label\";s:5:\"label\";s:8:\"Template\";}s:1:\"C\";a:2:{s:4:\"type\";s:5:\"label\";s:5:\"label\";s:4:\"Lang\";}s:1:\"D\";a:3:{s:4:\"type\";s:5:\"label\";s:5:\"label\";s:7:\"Version\";s:5:\"align\";s:6:\"center\";}s:1:\"E\";a:6:{s:4:\"type\";s:6:\"button\";s:4:\"span\";s:3:\"all\";s:5:\"label\";s:6:\"Search\";s:5:\"align\";s:6:\"center\";s:4:\"name\";s:6:\"search\";s:4:\"help\";s:38:\"start new search for the above pattern\";}s:1:\"F\";a:1:{s:4:\"type\";s:5:\"label\";}}i:2;a:6:{s:1:\"A\";a:3:{s:4:\"type\";s:5:\"label\";s:7:\"no_lang\";s:1:\"1\";s:4:\"name\";s:15:\"${row}[et_name]\";}s:1:\"B\";a:3:{s:4:\"type\";s:5:\"label\";s:7:\"no_lang\";s:1:\"1\";s:4:\"name\";s:19:\"${row}[et_template]\";}s:1:\"C\";a:3:{s:4:\"type\";s:5:\"label\";s:7:\"no_lang\";s:1:\"1\";s:4:\"name\";s:15:\"${row}[et_lang]\";}s:1:\"D\";a:3:{s:4:\"type\";s:5:\"label\";s:7:\"no_lang\";s:1:\"1\";s:4:\"name\";s:18:\"${row}[et_version]\";}s:1:\"E\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:4:\"Edit\";s:4:\"name\";s:10:\"read[$row]\";s:4:\"help\";s:34:\"load this template into the editor\";}s:1:\"F\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:6:\"Delete\";s:4:\"name\";s:12:\"delete[$row]\";s:4:\"help\";s:21:\"delete this eTemplate\";}}}','size' => '','style' => '',);
|
||||
|
||||
$templ_data[] = array('name' => 'etemplate.editor.buttons','template' => '','lang' => '','group' => '0','version' => '0.9.15.001','data' => 'a:2:{i:0;a:0:{}i:1;a:11:{s:1:\"A\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:4:\"Read\";s:4:\"name\";s:4:\"read\";s:4:\"help\";s:49:\"read eTemplate from database (for the keys above)\";}s:1:\"B\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:14:\"Show (no save)\";s:4:\"name\";s:4:\"show\";s:4:\"help\";s:61:\"shows/displays eTemplate for testing, does NOT save it before\";}s:1:\"C\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:11:\"Show Values\";s:4:\"name\";s:6:\"values\";s:4:\"help\";s:65:\"shows / allows you to enter values into the eTemplate for testing\";}s:1:\"D\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:4:\"Save\";s:4:\"name\";s:4:\"save\";s:4:\"help\";s:77:\"save the eTemplate under the above keys (name, ...), change them for a SaveAs\";}s:1:\"E\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:4:\"Edit\";s:4:\"name\";s:4:\"edit\";s:4:\"help\";s:30:\"edit the eTemplate spez. above\";}s:1:\"F\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:6:\"Delete\";s:4:\"name\";s:6:\"delete\";s:4:\"help\";s:33:\"deletes the eTemplate spez. above\";}s:1:\"G\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:10:\"Dump4Setup\";s:4:\"name\";s:4:\"dump\";s:4:\"help\";s:88:\"writes a \'etemplates.inc.php\' file (for application in Name) in the setup-dir of the app\";}s:1:\"H\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:14:\"Write Langfile\";s:4:\"name\";s:8:\"langfile\";s:4:\"help\";s:85:\"creates an english (\'en\') langfile from label and helptexts (for application in Name)\";}s:1:\"I\";a:4:{s:4:\"type\";s:6:\"button\";s:5:\"label\";s:10:\"Export XML\";s:4:\"name\";s:10:\"export_xml\";s:4:\"help\";s:43:\"export the loaded eTemplate into a xml-file\";}s:1:\"J\";a:1:{s:4:\"type\";s:5:\"label\";}s:1:\"K\";a:5:{s:4:\"type\";s:4:\"text\";s:4:\"size\";s:2:\"20\";s:5:\"label\";s:46:\"Width, Height, Border, class, Spacing, Padding\";s:4:\"name\";s:4:\"size\";s:4:\"help\";s:96:\"width, height, border-line-thickness, CSS-class name, Celspaceing, Cellpadding (for TABLE tag), \";}}}','size' => '','style' => '',);
|
||||
|
||||
|
@ -71,6 +71,8 @@ error: while saveing !!! etemplate en Error: while saveing !!!
|
||||
etemplate editor etemplate en eTemplate Editor
|
||||
exchange this two columns etemplate en exchange this two columns
|
||||
exchange this two rows etemplate en exchange this two rows
|
||||
export the loaded etemplate into a xml-file etemplate en export the loaded eTemplate into a xml-file
|
||||
export xml etemplate en Export XML
|
||||
extensions loaded: etemplate en Extensions loaded:
|
||||
familyname etemplate en Familyname
|
||||
fax etemplate en Fax
|
||||
|
49
etemplate/templates/default/etemplate.db-tools.cols.xul
Normal file
49
etemplate/templates/default/etemplate.db-tools.cols.xul
Normal file
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0"?>
|
||||
<grid id="etemplate.db-tools.cols" template="" lang="" group="" version="0.9.13.001">
|
||||
<columns>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row class="nmh">
|
||||
<label value="#" no_lang="1" align="center"/>
|
||||
<label value="ColumnName"/>
|
||||
<label value="Type"/>
|
||||
<label value="Precision"/>
|
||||
<label value="Scale"/>
|
||||
<label value="Nullable"/>
|
||||
<label value="Unique"/>
|
||||
<label value="Primary Key"/>
|
||||
<label value="Indexed"/>
|
||||
<label value="Foreign Key"/>
|
||||
<label value="Default"/>
|
||||
<button label="Add Column" align="center" id="add_column"/>
|
||||
</row>
|
||||
<row class="nmr">
|
||||
<label no_lang="1" align="center" id="Row${row}[n]"/>
|
||||
<textbox size="20" no_lang="1" id="Row${row}[name]" statustext="need to be unique in the table and no reseved word from SQL, best prefix all with a common 2-digit short for the app, eg. 'et_'"/>
|
||||
<menulist>
|
||||
<menupopup no_lang="1" id="Row${row}[type]" statustext="type of the column"/>
|
||||
</menulist>
|
||||
<int align="center" id="Row${row}[precision]" statustext="length for char+varchar, precisions int: 2, 4, 8 and float: 4, 8"/>
|
||||
<int id="Row${row}[scale]" statustext="scale for float"/>
|
||||
<checkbox align="center" id="Row${row}[nullable]" statustext="can have special SQL-value NULL"/>
|
||||
<checkbox align="center" id="Row${row}[uc]" statustext="DB ensures that every row has a unique value in that column"/>
|
||||
<checkbox align="center" id="Row${row}[pk]" statustext="Primary key for the table, gets automaticaly indexed"/>
|
||||
<checkbox align="center" id="Row${row}[ix]" statustext="an indexed column speeds up querys using that column (cost space on the disk !!!)"/>
|
||||
<textbox size="20" align="center" id="Row${row}[fk]" statustext="name of other table where column is a key from"/>
|
||||
<textbox size="20" id="Row${row}[default]" statustext="enter '' for an empty default, nothing mean no default"/>
|
||||
<button label="Delete Column" align="center" id="delete[$row]"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
40
etemplate/templates/default/etemplate.db-tools.edit.xul
Normal file
40
etemplate/templates/default/etemplate.db-tools.edit.xul
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0"?>
|
||||
<grid id="etemplate.db-tools.edit" template="" lang="" group="" version="0.9.13.001" width="100%">
|
||||
<columns>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column width="1%"/>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<label size="bi" span="6" value="Editable Templates - DB-Tools" no_lang="1" id="msg"/>
|
||||
<button label="eTemplate Editor" align="right" id="editor" statustext="to start the eTemplate editor"/>
|
||||
</row>
|
||||
<row>
|
||||
<hrule span="all"/>
|
||||
</row>
|
||||
<row>
|
||||
<label span="all"/>
|
||||
</row>
|
||||
<row>
|
||||
<menulist>
|
||||
<menupopup label="Application" no_lang="1" id="app" onchange="1" statustext="Select an application"/>
|
||||
</menulist>
|
||||
<menulist>
|
||||
<menupopup label="TableName" no_lang="1" id="table_name" onchange="1" statustext="Select an table of the application"/>
|
||||
</menulist>
|
||||
<textbox size="20" align="right" id="new_table_name" statustext="Name of table to add"/>
|
||||
<button label="Add Table" id="add_table" statustext="Create a new table for the application"/>
|
||||
<button label="Import" id="import" statustext="Import table-definitions from existing db-table"/>
|
||||
<button label="Drop Table" id="drop_table" disabled="true" statustext="Drop a table - this can NOT be undone"/>
|
||||
<button label="Write Tables" id="write_tables" statustext="Write <app>/setup/tables_current.inc.php"/>
|
||||
</row>
|
||||
<row>
|
||||
<template span="all" id="etemplate.db-tools.cols"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
Loading…
Reference in New Issue
Block a user