2002-02-06 10:03:11 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - eTemplates - Editor *
|
|
|
|
* 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$ */
|
|
|
|
|
|
|
|
class editor
|
|
|
|
{
|
|
|
|
var $debug;
|
|
|
|
var $etemplate; // eTemplate we edit
|
|
|
|
var $editor; // editor eTemplate
|
|
|
|
var $messages = array(
|
|
|
|
'not_found' => 'Error: Template not found !!!',
|
|
|
|
'deleted' => 'Template deleted',
|
|
|
|
'saved' => 'Template saved',
|
2002-02-14 15:06:53 +01:00
|
|
|
'error_writing' => 'Error: while saveing !!!',
|
2002-09-03 12:21:44 +02:00
|
|
|
'other_version' => 'only an other Version found !!!',
|
2002-09-04 00:59:47 +02:00
|
|
|
'ext_loaded' => 'Extensions loaded:',
|
2002-09-12 12:04:22 +02:00
|
|
|
'x_found' => '%d eTemplates found',
|
|
|
|
'imported' => "eTemplate '%s' imported, use Save to put it in the database",
|
|
|
|
'no_filename'=> 'no filename given or selected via Browse...',
|
|
|
|
'not_writeable' => "Error: webserver is not allowed to write into '%s' !!!",
|
2002-09-12 12:58:20 +02:00
|
|
|
'exported' => "eTemplate '%s' written to '%s'",
|
2002-10-03 18:46:18 +02:00
|
|
|
'newer_version' => "newer version '%s' exists !!!",
|
|
|
|
'need_name' => 'Application name needed to write a langfile !!!'
|
2002-02-06 10:03:11 +01:00
|
|
|
);
|
2002-05-13 23:30:46 +02:00
|
|
|
var $aligns = array(
|
|
|
|
'' => 'Left',
|
|
|
|
'right' => 'Right',
|
|
|
|
'center' => 'Center'
|
|
|
|
);
|
2002-09-29 15:01:40 +02:00
|
|
|
var $options = array(
|
|
|
|
'width',
|
|
|
|
'height',
|
|
|
|
'border',
|
|
|
|
'class',
|
2002-10-03 15:24:45 +02:00
|
|
|
'spacing',
|
2002-09-29 15:01:40 +02:00
|
|
|
'padding',
|
|
|
|
'overflow'
|
|
|
|
);
|
|
|
|
var $overflows = array(
|
|
|
|
'' => 'visible',
|
|
|
|
'hidden' => 'hidden',
|
|
|
|
'scroll' => 'scroll',
|
|
|
|
'auto' => 'auto'
|
|
|
|
);
|
2002-05-13 23:30:46 +02:00
|
|
|
var $extensions = '';
|
2002-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
var $public_functions = array
|
|
|
|
(
|
|
|
|
'edit' => True,
|
|
|
|
'process_edit' => True,
|
|
|
|
'delete' => True,
|
|
|
|
'show' => True,
|
|
|
|
//'admin' => True,
|
|
|
|
//'preferences' => True
|
|
|
|
);
|
|
|
|
|
2002-02-14 15:06:53 +01:00
|
|
|
function editor($lang_on_messages=True)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
$this->etemplate = CreateObject('etemplate.etemplate');
|
|
|
|
//echo '$HTTP_POST_VARS='; _debug_array($HTTP_POST_VARS);
|
|
|
|
|
|
|
|
$this->editor = new etemplate('etemplate.editor');
|
2002-02-14 15:06:53 +01:00
|
|
|
|
|
|
|
if ($lang_on_messages)
|
|
|
|
{
|
|
|
|
reset($this->messages);
|
|
|
|
while (list($key,$msg) = each($this->messages))
|
|
|
|
$this->messages[$key] = lang($msg);
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function edit($msg = '')
|
|
|
|
{
|
|
|
|
$get_vars = $GLOBALS['HTTP_GET_VARS'];
|
|
|
|
if (isset($get_vars['name']) && !$this->etemplate->read($get_vars))
|
|
|
|
{
|
|
|
|
$msg .= $this->messages['not_found'];
|
|
|
|
}
|
2002-05-13 23:30:46 +02:00
|
|
|
if ($this->extensions == '')
|
|
|
|
{
|
|
|
|
$this->extensions = $this->scan_for_extensions();
|
2002-09-03 12:21:44 +02:00
|
|
|
if (count($this->extensions))
|
|
|
|
{
|
2002-09-04 00:59:47 +02:00
|
|
|
$msg .= $this->messages['ext_loaded'] . ' ' . implode(', ',$this->extensions);
|
2002-09-03 12:21:44 +02:00
|
|
|
$msg_ext_loaded = True;
|
|
|
|
}
|
2002-09-02 19:09:49 +02:00
|
|
|
}
|
|
|
|
list($app) = explode('.',$this->etemplate->name);
|
|
|
|
if ($app && $app != 'etemplate' && is_array($this->extensions) &&
|
|
|
|
(!is_array($this->extensions['**loaded**']) || !$this->extensions['**loaded**'][$app]))
|
|
|
|
{
|
2002-09-03 12:21:44 +02:00
|
|
|
$extensions = $this->scan_for_extensions($app);
|
|
|
|
if (count($extensions))
|
|
|
|
{
|
2002-09-04 00:59:47 +02:00
|
|
|
$msg .= (!$msg_ext_loaded?$this->messages['ext_loaded'].' ':', ') . implode(', ',$extensions);
|
2002-09-03 12:21:44 +02:00
|
|
|
$this->extensions += $extensions;
|
|
|
|
}
|
2002-09-02 19:09:49 +02:00
|
|
|
$this->extensions['**loaded**'][$app] = True;
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$content = $this->etemplate->as_array() + array(
|
|
|
|
'cols' => $this->etemplate->cols,
|
|
|
|
'msg' => $msg
|
|
|
|
);
|
2002-09-29 15:01:40 +02:00
|
|
|
$options = explode(',',$this->etemplate->size);
|
|
|
|
reset($this->options);
|
|
|
|
while (list($n,$opt) = each($this->options))
|
|
|
|
{
|
|
|
|
$content['options'][$opt] = $options[$n];
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$cols_spanned = array();
|
|
|
|
reset($this->etemplate->data);
|
2002-02-14 15:06:53 +01:00
|
|
|
if (isset($this->etemplate->data[0]))
|
|
|
|
{
|
|
|
|
each($this->etemplate->data);
|
|
|
|
}
|
2002-09-12 12:58:20 +02:00
|
|
|
$no_button = array();
|
2002-02-06 10:03:11 +01:00
|
|
|
while (list($row,$cols) = each($this->etemplate->data))
|
|
|
|
{
|
|
|
|
if ($this->etemplate->rows <= 1)
|
|
|
|
{
|
|
|
|
$no_button["Row$row"]['delete_row[1]'] = True;
|
|
|
|
}
|
|
|
|
if ($row > 1)
|
|
|
|
{
|
|
|
|
$no_button["Row$row"]['insert_row[0]'] = True;
|
|
|
|
}
|
|
|
|
$content["Row$row"] = array(
|
|
|
|
'height' => array("h$row" => $this->etemplate->data[0]["h$row"]),
|
|
|
|
'class' => array("c$row" => $this->etemplate->data[0]["c$row"])
|
|
|
|
);
|
|
|
|
for ($spanned = $c = 0; $c < $this->etemplate->cols; ++$c)
|
|
|
|
{
|
|
|
|
if (!(list($col,$cell) = each($cols)))
|
|
|
|
{
|
|
|
|
$cell = $this->etemplate->empty_cell(); // if cell gots lost, create it empty
|
|
|
|
$col = $this->etemplate->num2chrs($c);
|
|
|
|
}
|
|
|
|
if (--$spanned > 0) // preserv spanned cells
|
|
|
|
{
|
|
|
|
while(list($k,$v) = each($cell)) // so spanned (not shown) cells got
|
|
|
|
{ // reported back like regular one
|
2002-02-17 20:09:15 +01:00
|
|
|
$cols_spanned[$col.$row][$k] = $v;
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$spanned = $cell['span'] == 'all' ? $this->etemplate->cols-$c : 0+$cell['span'];
|
|
|
|
$content[$col.$row] = $cell;
|
|
|
|
}
|
|
|
|
if ($row == 1)
|
|
|
|
{
|
|
|
|
$content["Col$col"] = array('width' => array($col => $this->etemplate->data[0][$col]));
|
|
|
|
if ($this->etemplate->cols <= 1)
|
|
|
|
{
|
|
|
|
$no_button["Col$col"]['delete_col[1]'] = True;
|
|
|
|
}
|
|
|
|
if ($c > 0)
|
|
|
|
{
|
|
|
|
$no_button["Col$col"]['insert_col[0]'] = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$no_button['ColA']['exchange_col[1]'] = $no_button['Row1']['exchange_row[1]'] = True;
|
|
|
|
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo 'editor.edit: content ='; _debug_array($content);
|
|
|
|
}
|
2002-09-02 19:09:49 +02:00
|
|
|
$types = array_merge($this->etemplate->types,$this->extensions);
|
|
|
|
unset($types['**loaded**']);
|
2002-02-06 10:03:11 +01:00
|
|
|
$this->editor->exec('etemplate.editor.process_edit',$content,
|
|
|
|
array(
|
2002-09-02 19:09:49 +02:00
|
|
|
'type' => $types,
|
2002-09-29 15:01:40 +02:00
|
|
|
'align' => $this->aligns,
|
|
|
|
'overflow' => $this->overflows
|
2002-02-06 10:03:11 +01:00
|
|
|
),
|
2002-05-13 23:30:46 +02:00
|
|
|
$no_button,$cols_spanned + array('**extensions**' => $this->extensions));
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function swap(&$a,&$b)
|
|
|
|
{
|
|
|
|
$t = $a; $a = $b; $b = $t;
|
|
|
|
}
|
|
|
|
|
2002-02-17 20:09:15 +01:00
|
|
|
function process_edit($content)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "editor.process_edit: content ="; _debug_array($content);
|
|
|
|
}
|
2002-05-13 23:30:46 +02:00
|
|
|
$this->extensions = $content['**extensions**']; unset($content['**extensions**']);
|
2002-02-06 10:03:11 +01:00
|
|
|
$this->etemplate->init($content);
|
|
|
|
|
2002-09-25 18:27:11 +02:00
|
|
|
$opts = array();
|
2002-09-29 15:01:40 +02:00
|
|
|
reset($this->options);
|
|
|
|
while (list(,$opt) = each($this->options))
|
|
|
|
{
|
|
|
|
$opts[$opt] = $content['options'][$opt];
|
|
|
|
}
|
|
|
|
$this->etemplate->size = ereg_replace(',*$','',implode(',',$opts));
|
|
|
|
$this->etemplate->style = $content['style'];
|
|
|
|
|
2002-09-25 18:27:11 +02:00
|
|
|
$names = array('width','height','class');
|
2002-09-29 15:01:40 +02:00
|
|
|
$opts = array();
|
2002-09-25 18:27:11 +02:00
|
|
|
while (list(,$opt) = each($names))
|
|
|
|
{
|
|
|
|
if (is_array($content[$opt]))
|
|
|
|
{
|
|
|
|
$opts += $content[$opt];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->etemplate->data = array($opts);
|
2002-02-06 10:03:11 +01:00
|
|
|
$row = 1; $col = 0;
|
|
|
|
while (isset($content[$name = $this->etemplate->num2chrs($col) . $row]))
|
|
|
|
{
|
|
|
|
$row_data[$this->etemplate->num2chrs($col++)] = $content[$name];
|
|
|
|
if (!isset($content[$name = $this->etemplate->num2chrs($col) . $row])) // try new row
|
|
|
|
{
|
|
|
|
if ($col > $cols)
|
|
|
|
{
|
|
|
|
$cols = $col;
|
|
|
|
}
|
|
|
|
$this->etemplate->data[$row] = $row_data;
|
2002-02-14 15:06:53 +01:00
|
|
|
++$row; $col = 0; $row_data = array();
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->etemplate->rows = $row - 1;
|
|
|
|
$this->etemplate->cols = $cols;
|
|
|
|
|
|
|
|
if (isset($content['insert_row']))
|
|
|
|
{
|
|
|
|
list($row) = each($content['insert_row']);
|
|
|
|
$opts = $this->etemplate->data[0]; // move height + class options of rows
|
|
|
|
for ($r = $this->etemplate->rows; $r > $row; --$r)
|
|
|
|
{
|
|
|
|
$opts['c'.(1+$r)] = $opts["c$r"]; unset($opts["c$r"]);
|
|
|
|
$opts['h'.(1+$r)] = $opts["h$r"]; unset($opts["h$r"]);
|
|
|
|
}
|
|
|
|
$this->etemplate->data[0] = $opts;
|
|
|
|
$old = $this->etemplate->data; // move rows itself
|
|
|
|
$row_data = array();
|
|
|
|
for ($col = 0; $col < $this->etemplate->cols; ++$col)
|
|
|
|
{
|
|
|
|
$row_data[$this->etemplate->num2chrs($col)] = $this->etemplate->empty_cell();
|
|
|
|
}
|
|
|
|
$this->etemplate->data[++$row] = $row_data;
|
|
|
|
for (; $row <= $this->etemplate->rows; ++$row)
|
|
|
|
{
|
|
|
|
$this->etemplate->data[1+$row] = $old[$row];
|
|
|
|
}
|
|
|
|
++$this->etemplate->rows;
|
|
|
|
}
|
|
|
|
elseif (isset($content['insert_col']))
|
|
|
|
{
|
|
|
|
list($insert_col) = each($content['insert_col']);
|
|
|
|
for ($row = 1; $row <= $this->etemplate->rows; ++$row)
|
|
|
|
{
|
|
|
|
$old = $row_data = $this->etemplate->data[$row];
|
|
|
|
$row_data[$this->etemplate->num2chrs($insert_col)] = $this->etemplate->empty_cell();
|
|
|
|
for ($col = $insert_col; $col < $this->etemplate->cols; ++$col)
|
|
|
|
{
|
|
|
|
$row_data[$this->etemplate->num2chrs(1+$col)] = $old[$this->etemplate->num2chrs($col)];
|
|
|
|
}
|
|
|
|
$this->etemplate->data[$row] = $row_data;
|
|
|
|
}
|
|
|
|
$width = $this->etemplate->data[0];
|
|
|
|
for ($col = $this->etemplate->cols; $col > $insert_col; --$col)
|
|
|
|
{
|
|
|
|
$width[$this->etemplate->num2chrs($col)] = $width[$this->etemplate->num2chrs($col-1)];
|
|
|
|
}
|
|
|
|
unset($width[$this->etemplate->num2chrs($insert_col)]);
|
|
|
|
$this->etemplate->data[0] = $width;
|
|
|
|
|
|
|
|
++$this->etemplate->cols;
|
|
|
|
}
|
|
|
|
elseif (isset($content['exchange_col']))
|
|
|
|
{
|
|
|
|
list($exchange_col) = each($content['exchange_col']);
|
|
|
|
$right = $this->etemplate->num2chrs($exchange_col-1);
|
|
|
|
$left = $this->etemplate->num2chrs($exchange_col-2);
|
|
|
|
|
|
|
|
for ($row = 1; $row <= $this->etemplate->rows; ++$row)
|
|
|
|
{
|
|
|
|
$this->swap($this->etemplate->data[$row][$left],$this->etemplate->data[$row][$right]);
|
|
|
|
}
|
|
|
|
$this->swap($this->etemplate->data[0][$left],$this->etemplate->data[0][$right]);
|
|
|
|
}
|
|
|
|
elseif (isset($content['exchange_row']))
|
|
|
|
{
|
|
|
|
list($er2) = each($content['exchange_row']); $er1 = $er2-1;
|
|
|
|
$this->swap($this->etemplate->data[$er1],$this->etemplate->data[$er2]);
|
|
|
|
$this->swap($this->etemplate->data[0]["c$er1"],$this->etemplate->data[0]["c$er2"]);
|
|
|
|
$this->swap($this->etemplate->data[0]["h$er1"],$this->etemplate->data[0]["h$er2"]);
|
|
|
|
}
|
|
|
|
elseif (isset($content['delete_row']))
|
|
|
|
{
|
|
|
|
list($delete_row) = each($content['delete_row']);
|
|
|
|
$opts = $this->etemplate->data[0];
|
|
|
|
for ($row = $delete_row; $row < $this->etemplate->rows; ++$row)
|
|
|
|
{
|
|
|
|
$this->etemplate->data[$row] = $this->etemplate->data[1+$row];
|
|
|
|
$opts["c$row"] = $opts['c'.(1+$row)];
|
|
|
|
$opts["h$row"] = $opts['h'.(1+$row)];
|
|
|
|
}
|
|
|
|
unset($this->etemplate->data[$this->etemplate->rows--]);
|
|
|
|
$this->etemplate->data[0] = $opts;
|
|
|
|
}
|
|
|
|
elseif (isset($content['delete_col']))
|
|
|
|
{
|
|
|
|
list($delete_col) = each($content['delete_col']);
|
|
|
|
for ($row = 1; $row <= $this->etemplate->rows; ++$row)
|
|
|
|
{
|
|
|
|
$row_data = $this->etemplate->data[$row];
|
|
|
|
for ($col = $delete_col; $col < $this->etemplate->cols; ++$col)
|
|
|
|
{
|
|
|
|
$row_data[$this->etemplate->num2chrs($col-1)] = $row_data[$this->etemplate->num2chrs($col)];
|
|
|
|
}
|
|
|
|
unset($row_data[$this->etemplate->num2chrs($this->etemplate->cols-1)]);
|
|
|
|
$this->etemplate->data[$row] = $row_data;
|
|
|
|
}
|
|
|
|
$width = $this->etemplate->data[0];
|
|
|
|
for ($col = $delete_col; $col < $this->etemplate->cols; ++$col)
|
|
|
|
{
|
|
|
|
$width[$this->etemplate->num2chrs($col-1)] = $width[$this->etemplate->num2chrs($col)];
|
|
|
|
}
|
|
|
|
$this->etemplate->data[0] = $width;
|
|
|
|
--$this->etemplate->cols;
|
|
|
|
}
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo 'editor.process_edit: rows='.$this->etemplate->rows.', cols='.
|
|
|
|
$this->etemplate->cols.', data ='; _debug_array($this->etemplate->data);
|
|
|
|
}
|
|
|
|
// Execute the action resulting from the submit-button
|
|
|
|
if ($content['read'])
|
|
|
|
{
|
2002-09-12 12:58:20 +02:00
|
|
|
if ($content['version'] != '')
|
|
|
|
{
|
|
|
|
$save_version = $content['version'];
|
|
|
|
unset($content['version']);
|
|
|
|
$this->etemplate->read($content);
|
|
|
|
$newest_version = $this->etemplate->version;
|
|
|
|
$content['version'] = $save_version;
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
if (!$this->etemplate->read($content))
|
|
|
|
{
|
2002-02-14 15:06:53 +01:00
|
|
|
$content['version'] = ''; // trying it without version
|
2002-09-04 00:59:47 +02:00
|
|
|
if ($this->etemplate->read($content))
|
2002-02-14 15:06:53 +01:00
|
|
|
{
|
2002-09-04 00:59:47 +02:00
|
|
|
$msg = $this->messages['other_version'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$result = $this->etemplate->search($content);
|
|
|
|
if (count($result) > 1)
|
|
|
|
{
|
|
|
|
return $this->list_result(array('result' => $result));
|
|
|
|
}
|
2002-09-24 11:58:07 +02:00
|
|
|
elseif (!count($result) || !$this->etemplate->read($result[0]))
|
2002-09-04 00:59:47 +02:00
|
|
|
{
|
|
|
|
$msg = $this->messages['not_found'];
|
|
|
|
}
|
2002-09-24 11:58:07 +02:00
|
|
|
elseif ($content['name'] == $result[0]['name'])
|
|
|
|
{
|
|
|
|
$msg = $this->messages['other_version'];
|
|
|
|
}
|
2002-02-14 15:06:53 +01:00
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
2002-09-12 12:58:20 +02:00
|
|
|
elseif ($newest_version != '' && $this->etemplate->version != $newest_version)
|
|
|
|
{
|
|
|
|
$msg = sprintf($this->messages['newer_version'],$newest_version);
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
elseif ($content['delete'])
|
|
|
|
{
|
|
|
|
$this->delete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elseif ($content['dump'])
|
|
|
|
{
|
|
|
|
$msg = $this->etemplate->dump2setup($content['name']);
|
|
|
|
}
|
|
|
|
elseif ($content['save'])
|
|
|
|
{
|
2002-09-29 15:01:40 +02:00
|
|
|
if (!$this->etemplate->modified_set || !$this->etemplate->modified)
|
|
|
|
{
|
|
|
|
$this->etemplate->modified = time();
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$ok = $this->etemplate->save($content['name'],$content['template'],$content['lang'],$content['group'],$content['version']);
|
|
|
|
$msg = $this->messages[$ok ? 'saved' : 'error_writing'];
|
|
|
|
}
|
|
|
|
elseif ($content['show'])
|
|
|
|
{
|
|
|
|
$this->show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elseif ($content['langfile'])
|
|
|
|
{
|
2002-10-03 18:46:18 +02:00
|
|
|
list($name) = explode('.',$content['name']);
|
|
|
|
if (empty($name) || !@is_dir(PHPGW_SERVER_ROOT.'/'.$name))
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-10-03 18:46:18 +02:00
|
|
|
$msg = $this->messages['need_name'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$additional = array();
|
|
|
|
if ($name == 'etemplate')
|
|
|
|
{
|
|
|
|
$m = new editor(False);
|
|
|
|
$additional = $m->messages + $this->etemplate->types + $this->extensions + $this->aligns;
|
|
|
|
}
|
|
|
|
$msg = $this->etemplate->writeLangFile($name,'en',$additional);
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
2002-09-12 02:35:20 +02:00
|
|
|
elseif ($content['export_xml'])
|
|
|
|
{
|
|
|
|
$msg = $this->export_xml();
|
|
|
|
}
|
2002-09-12 12:04:22 +02:00
|
|
|
elseif ($content['import_xml'])
|
|
|
|
{
|
|
|
|
$msg = $this->import_xml($content['file']);
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
elseif ($content['db_tools'])
|
|
|
|
{
|
|
|
|
ExecMethod('etemplate.db_tools.edit');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->edit($msg);
|
|
|
|
}
|
|
|
|
|
2002-09-12 02:35:20 +02:00
|
|
|
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))
|
|
|
|
{
|
2002-09-12 14:21:27 +02:00
|
|
|
return sprintf($this->messages['not_writeable'],$dir);
|
2002-09-12 02:35:20 +02:00
|
|
|
}
|
|
|
|
if ($create)
|
|
|
|
{
|
|
|
|
mkdir($dir .= "/$template");
|
|
|
|
}
|
2002-09-17 15:27:37 +02:00
|
|
|
$file = $dir . '/' . substr($name,strlen($app)+1);
|
2002-09-12 02:35:20 +02:00
|
|
|
if ($this->etemplate->lang)
|
|
|
|
{
|
|
|
|
$file .= '.' . $this->etemplate->lang;
|
|
|
|
}
|
2002-09-30 20:19:50 +02:00
|
|
|
$old_file = $file . '.old.xet';
|
|
|
|
$file .= '.xet';
|
2002-09-12 02:35:20 +02:00
|
|
|
if (file_exists($file))
|
|
|
|
{
|
|
|
|
rename($file,$old_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!($f = fopen($file,'w')))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2002-09-17 15:27:37 +02:00
|
|
|
if (!is_object($this->etemplate->xul_io))
|
|
|
|
{
|
|
|
|
$this->etemplate->xul_io = CreateObject('etemplate.xul_io');
|
|
|
|
}
|
|
|
|
$xul = $this->etemplate->xul_io->export(&$this->etemplate);
|
2002-09-12 02:35:20 +02:00
|
|
|
|
|
|
|
fwrite($f,$xul);
|
|
|
|
fclose($f);
|
|
|
|
|
2002-09-12 12:04:22 +02:00
|
|
|
return sprintf($this->messages['exported'],$name,$file);
|
|
|
|
}
|
|
|
|
|
|
|
|
function import_xml($file)
|
|
|
|
{
|
|
|
|
if ($file == 'none' || $file == '' || !($f = fopen($file,'r')))
|
|
|
|
{
|
|
|
|
return $this->messages['no_filename'];
|
|
|
|
}
|
|
|
|
$xul = fread ($f, filesize ($file));
|
|
|
|
fclose($f);
|
|
|
|
|
2002-09-17 15:27:37 +02:00
|
|
|
if (!is_object($this->etemplate->xul_io))
|
|
|
|
{
|
|
|
|
$this->etemplate->xul_io = CreateObject('etemplate.xul_io');
|
|
|
|
}
|
2002-09-24 11:58:07 +02:00
|
|
|
$imported = $this->etemplate->xul_io->import(&$this->etemplate,$xul);
|
2002-09-29 15:01:40 +02:00
|
|
|
$this->etemplate->modified = filemtime($f);
|
|
|
|
$this->etemplate->modified_set = 'xul-import';
|
2002-09-12 12:04:22 +02:00
|
|
|
|
2002-09-24 11:58:07 +02:00
|
|
|
if (is_array($imported))
|
2002-09-12 12:04:22 +02:00
|
|
|
{
|
2002-09-24 11:58:07 +02:00
|
|
|
if (count($imported) == 1)
|
|
|
|
{
|
|
|
|
$imported = sprintf($this->messages['imported'],$this->etemplate->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$imported = 'File contains more than one etemplates, last one is shown !!!';
|
|
|
|
}
|
2002-09-12 12:04:22 +02:00
|
|
|
}
|
2002-09-24 11:58:07 +02:00
|
|
|
return $imported;
|
2002-09-12 02:35:20 +02:00
|
|
|
}
|
|
|
|
|
2002-02-17 20:09:15 +01:00
|
|
|
function delete($post_vars='',$back = 'edit')
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-09-04 00:59:47 +02:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "delete(back='$back') cont = "; _debug_array($post_vars);
|
|
|
|
}
|
2002-02-17 20:09:15 +01:00
|
|
|
if (!$post_vars)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-02-17 20:09:15 +01:00
|
|
|
$post_vars = array();
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
2002-02-17 20:09:15 +01:00
|
|
|
if (isset($post_vars['name']))
|
|
|
|
{
|
|
|
|
$read_ok = $this->etemplate->read($post_vars);
|
|
|
|
}
|
|
|
|
if (isset($post_vars['yes'])) // Delete
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
if ($read_ok)
|
|
|
|
{
|
|
|
|
$read_ok = $this->etemplate->delete();
|
|
|
|
}
|
2002-09-04 00:59:47 +02:00
|
|
|
$msg = $this->messages[$read_ok ? 'deleted' : 'not_found'];
|
|
|
|
|
|
|
|
if ($post_vars['back'] == 'list_result')
|
|
|
|
{
|
|
|
|
$this->list_result($post_vars['preserv'],$msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->edit($msg);
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
return;
|
|
|
|
}
|
2002-02-17 20:09:15 +01:00
|
|
|
if (isset($post_vars['no'])) // Back to ...
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-09-04 00:59:47 +02:00
|
|
|
switch ($back = $post_vars['back'])
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-09-04 00:59:47 +02:00
|
|
|
case 'list_result':
|
|
|
|
$this->$back($post_vars['preserv']);
|
|
|
|
return;
|
|
|
|
case 'show':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$back = 'edit';
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
$this->$back();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isset($GLOBALS['HTTP_GET_VARS']['name']) && !$this->etemplate->read($GLOBALS['HTTP_GET_VARS']))
|
|
|
|
{
|
|
|
|
$this->edit($this->messages['not_found']);
|
|
|
|
return;
|
|
|
|
}
|
2002-09-04 00:59:47 +02:00
|
|
|
$content = $this->etemplate->as_array();
|
2002-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
$delete = new etemplate('etemplate.editor.delete');
|
2002-09-04 00:59:47 +02:00
|
|
|
$delete->exec('etemplate.editor.delete',$content,array(),array(),$content+ array(
|
|
|
|
'back' => $back,
|
|
|
|
'preserv' => $post_vars['preserv']
|
|
|
|
),'');
|
|
|
|
}
|
|
|
|
|
|
|
|
function list_result($cont='',$msg='')
|
|
|
|
{
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>etemplate.editor.list_result: cont="; _debug_array($cont);
|
|
|
|
}
|
|
|
|
if (!$cont || !is_array($cont))
|
|
|
|
{
|
|
|
|
return $this->edit('error');
|
|
|
|
}
|
|
|
|
if (!isset($cont['result']) || isset($cont['search']))
|
|
|
|
{
|
|
|
|
$cont['result'] = $this->etemplate->search($cont);
|
|
|
|
}
|
|
|
|
$result = $cont['result'];
|
2002-02-06 10:03:11 +01:00
|
|
|
|
2002-09-04 00:59:47 +02:00
|
|
|
if (isset($cont['delete']))
|
|
|
|
{
|
|
|
|
list($delete) = each($cont['delete']);
|
|
|
|
$read = $result[$delete-1];
|
|
|
|
$this->etemplate->read($read['et_name'],$read['et_template'],$read['et_lang'],$read['group'],$read['et_version']);
|
|
|
|
unset($cont['delete']);
|
|
|
|
unset($cont['result']);
|
|
|
|
$this->delete(array('preserv' => $cont),'list_result');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isset($cont['read']))
|
|
|
|
{
|
|
|
|
list($read) = each($cont['read']);
|
|
|
|
$read = $result[$read-1];
|
|
|
|
$this->etemplate->read($read['et_name'],$read['et_template'],$read['et_lang'],$read['group'],$read['et_version']);
|
|
|
|
$this->edit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!$msg)
|
|
|
|
{
|
|
|
|
$msg = sprintf($this->messages['x_found'],count($result));
|
|
|
|
}
|
|
|
|
unset($cont['result']);
|
|
|
|
if (!isset($cont['name']))
|
|
|
|
{
|
|
|
|
$cont += $this->etemplate->as_array();
|
|
|
|
}
|
|
|
|
$content = $cont + array('msg' => $msg);
|
|
|
|
|
|
|
|
reset($result);
|
|
|
|
for ($row=1; list(,$param) = each($result); ++$row)
|
|
|
|
{
|
|
|
|
$content[$row] = $param;
|
|
|
|
}
|
|
|
|
$list_result = new etemplate('etemplate.editor.list_result');
|
|
|
|
//$list_result->debug=1;
|
|
|
|
$list_result->exec('etemplate.editor.list_result',$content,'','',array('result' => $result),'');
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
2002-02-17 20:09:15 +01:00
|
|
|
function show($post_vars='')
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-06-09 23:33:07 +02:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>etemplate.editor.show: content="; _debug_array($post_vars);
|
|
|
|
}
|
2002-02-17 20:09:15 +01:00
|
|
|
if (!$post_vars)
|
|
|
|
{
|
|
|
|
$post_vars = array();
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
if (isset($GLOBALS['HTTP_GET_VARS']['name']) && !$this->etemplate->read($GLOBALS['HTTP_GET_VARS']) ||
|
|
|
|
isset($post_vars['name']) && !$this->etemplate->read($post_vars))
|
|
|
|
{
|
|
|
|
$msg = $this->messages['not_found'];
|
2002-09-12 12:58:20 +02:00
|
|
|
|
|
|
|
if (isset($post_vars['name']))
|
|
|
|
{
|
|
|
|
$post_vars['version'] = ''; // trying it without version
|
|
|
|
if ($this->etemplate->read($post_vars))
|
|
|
|
{
|
|
|
|
$msg = $this->messages['other_version'];
|
|
|
|
}
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
if (!$msg && isset($post_vars['delete']))
|
|
|
|
{
|
2002-02-17 20:09:15 +01:00
|
|
|
$this->delete(array(),'show');
|
2002-02-06 10:03:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isset($post_vars['edit']))
|
|
|
|
{
|
|
|
|
$this->edit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$content = $this->etemplate->as_array() + array('msg' => $msg);
|
|
|
|
|
|
|
|
$show = new etemplate('etemplate.editor.show');
|
2002-02-17 20:09:15 +01:00
|
|
|
if (!$msg && isset($post_vars['values']) && !isset($post_vars['vals']))
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-05-13 20:17:44 +02:00
|
|
|
$cont = $post_vars['cont'];
|
2002-02-17 20:09:15 +01:00
|
|
|
for ($r = 1; list($key,$val) = @each($cont); ++$r)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-05-13 20:17:44 +02:00
|
|
|
$vals["@$r"] = $key;
|
2002-09-24 23:55:16 +02:00
|
|
|
$vals["A$r"] = is_array($val) ? htmlspecialchars(serialize($val)).'#SeR#' : $val;
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
$show->data[$show->rows]['A']['name'] = 'etemplate.editor.values';
|
|
|
|
$show->data[$show->rows]['A']['size'] = 'vals';
|
|
|
|
$content['vals'] = $vals;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-09-27 18:17:39 +02:00
|
|
|
$show->data[$show->rows]['A']['obj'] = &$this->etemplate;
|
2002-02-17 20:09:15 +01:00
|
|
|
$vals = $post_vars['vals'];
|
2002-06-09 23:33:07 +02:00
|
|
|
$olds = $post_vars['olds'];
|
2002-02-06 10:03:11 +01:00
|
|
|
|
2002-05-13 20:17:44 +02:00
|
|
|
for ($r = 1; isset($vals["A$r"]); ++$r)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-09-24 23:55:16 +02:00
|
|
|
$content['cont'][$olds["@$r"]] = substr($vals["A$r"],-5)=='#SeR#' ?
|
|
|
|
unserialize(substr($vals["A$r"],0,-5)) : $vals["A$r"];
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
2002-09-12 12:58:20 +02:00
|
|
|
$show->exec('etemplate.editor.show',$content,array(),'',array('olds' => $vals),'');
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
2002-05-13 23:30:46 +02:00
|
|
|
|
|
|
|
/*!
|
2002-09-02 13:14:30 +02:00
|
|
|
@function scan_for_extensions
|
2002-09-02 19:09:49 +02:00
|
|
|
@syntax scan_for_extensions( $app )
|
2002-09-02 13:14:30 +02:00
|
|
|
@author ralfbecker
|
2002-05-13 23:30:46 +02:00
|
|
|
@abstract search the inc-dirs of etemplate and the app whichs template is edited for extensions / custom widgets
|
2002-09-02 13:14:30 +02:00
|
|
|
@discussion extensions are class-files in $app/inc/class.${name}_widget.inc.php
|
|
|
|
@result array with name => human_name of the extensions found
|
2002-05-13 23:30:46 +02:00
|
|
|
*/
|
|
|
|
function scan_for_extensions($app='etemplate')
|
|
|
|
{
|
|
|
|
$extensions = array();
|
|
|
|
|
|
|
|
$dir = @opendir(PHPGW_SERVER_ROOT.'/'.$app.'/inc');
|
|
|
|
|
|
|
|
while ($dir && ($file = readdir($dir)))
|
|
|
|
{
|
|
|
|
if (ereg('class\\.([a-zA-Z0-9_]*)_widget.inc.php',$file,$regs) &&
|
|
|
|
($ext = $this->etemplate->loadExtension($regs[1].'.'.$app,$this->etemplate)))
|
|
|
|
{
|
2002-10-02 02:44:33 +02:00
|
|
|
if (is_array($ext))
|
|
|
|
{
|
|
|
|
if (!is_array($extensions))
|
|
|
|
{
|
|
|
|
$extensions = $ext;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$extensions += $ext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$extensions[$regs[1]] = $ext;
|
|
|
|
}
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $extensions;
|
|
|
|
}
|
2002-02-14 15:06:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|