2002-02-06 10:03:11 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-01-27 17:58:19 +01:00
|
|
|
* eGroupWare - EditableTemplates - Storage Objects *
|
|
|
|
* http://www.egroupware.org *
|
2002-02-06 10:03:11 +01:00
|
|
|
* 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 soetemplate
|
2002-09-02 13:14:30 +02:00
|
|
|
@author ralfbecker
|
2002-02-06 10:03:11 +01:00
|
|
|
@abstract Storage Objects: Everything to store and retrive the eTemplates.
|
|
|
|
@discussion eTemplates are stored in the db in table 'phpgw_etemplate' and gets distributed
|
|
|
|
@discussion through the file 'etemplates.inc.php' in the setup dir of each app. That file gets
|
|
|
|
@discussion automatically imported in the db, whenever you show a eTemplate of the app. For
|
|
|
|
@discussion performace reasons the timestamp of the file is stored in the db, so 'new'
|
|
|
|
@discussion eTemplates need to have a newer file. The distribution-file is generated with the
|
|
|
|
@discussion function dump, usually by pressing a button in the editor.
|
|
|
|
@discussion writeLangFile writes an lang-file with all Labels, incorporating an existing one.
|
|
|
|
@discussion Beside a name eTemplates use the following keys to find the most suitable template
|
|
|
|
@discussion for an user (in order of precedence):
|
|
|
|
@discussion 1) User-/Group-Id (not yet implemented)
|
|
|
|
@discussion 2) preferd languages of the user (templates for all langs have $lang='')
|
|
|
|
@discussion 3) selected template: verdilak, ... (the default is called '' in the db, not default)
|
|
|
|
@discussion 4) a version-number of the form, eg: '0.9.13.001' (filled up with 0 same size)
|
|
|
|
*/
|
|
|
|
class soetemplate
|
|
|
|
{
|
|
|
|
var $public_functions = array(
|
2002-02-14 15:06:53 +01:00
|
|
|
'init' => True,
|
2003-08-28 16:31:11 +02:00
|
|
|
'empty_cell' => True,
|
|
|
|
'new_cell' => True,
|
2002-02-14 15:06:53 +01:00
|
|
|
'read' => True,
|
2002-09-04 00:59:47 +02:00
|
|
|
'search' => True,
|
2002-02-14 15:06:53 +01:00
|
|
|
'save' => True,
|
|
|
|
'delete' => True,
|
|
|
|
'dump2setup' => True,
|
|
|
|
'import_dump' => True,
|
2002-02-06 10:03:11 +01:00
|
|
|
'writeLangFile' => True
|
|
|
|
);
|
2002-09-24 12:00:58 +02:00
|
|
|
var $debug; // =1 show some debug-messages, = 'app.name' show messages only for eTemplate 'app.name'
|
2002-02-06 10:03:11 +01:00
|
|
|
var $name; // name of the template, e.g. 'infolog.edit'
|
|
|
|
var $template; // '' = default (not 'default')
|
|
|
|
var $lang; // '' if general template else language short, e.g. 'de'
|
|
|
|
var $group; // 0 = not specific else groupId or if < 0 userId
|
|
|
|
var $version; // like 0.9.13.001
|
|
|
|
var $size; // witdh,height,border of table
|
|
|
|
var $style; // embeded CSS style-sheet
|
|
|
|
var $db,$db_name = 'phpgw_etemplate'; // DB name
|
2002-02-14 15:06:53 +01:00
|
|
|
var $db_key_cols = array(
|
|
|
|
'et_name' => 'name',
|
|
|
|
'et_template' => 'template',
|
|
|
|
'et_lang' => 'lang',
|
|
|
|
'et_group' => 'group',
|
|
|
|
'et_version' => 'version'
|
|
|
|
);
|
|
|
|
var $db_data_cols = array(
|
|
|
|
'et_data' => 'data',
|
|
|
|
'et_size' => 'size',
|
2002-09-29 15:01:40 +02:00
|
|
|
'et_style' => 'style',
|
|
|
|
'et_modified' => 'modified'
|
2002-02-14 15:06:53 +01:00
|
|
|
);
|
2002-02-06 10:03:11 +01:00
|
|
|
var $db_cols;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function soetemplate
|
|
|
|
@abstract constructor of the class
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax soetemplate($name='',$template='',$lang='',$group=0,$version='',$rows=2,$cols=2)
|
2002-02-06 10:03:11 +01:00
|
|
|
@param as read
|
|
|
|
*/
|
|
|
|
function soetemplate($name='',$template='',$lang='',$group=0,$version='',$rows=2,$cols=2)
|
|
|
|
{
|
|
|
|
$this->db = $GLOBALS['phpgw']->db;
|
|
|
|
$this->db_cols = $this->db_key_cols + $this->db_data_cols;
|
|
|
|
|
2002-09-24 12:00:58 +02:00
|
|
|
if (empty($name))
|
|
|
|
{
|
|
|
|
$this->init($name,$template,$lang,$group,$version,$rows,$cols);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->read($name,$template,$lang,$group,$version,$rows,$cols);
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function num2chrs
|
|
|
|
@abstract generates column-names from index: 'A', 'B', ..., 'AA', 'AB', ..., 'ZZ' (not more!)
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax num2chrs($num)
|
2002-02-06 10:03:11 +01:00
|
|
|
@param $num index to generate name from 1 => 'A'
|
2002-09-02 13:14:30 +02:00
|
|
|
@result the name
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function num2chrs($num)
|
|
|
|
{
|
|
|
|
$min = ord('A');
|
|
|
|
$max = ord('Z') - $min + 1;
|
|
|
|
if ($num >= $max)
|
|
|
|
{
|
|
|
|
$chrs = chr(($num / $max) + $min - 1);
|
|
|
|
}
|
|
|
|
$chrs .= chr(($num % $max) + $min);
|
|
|
|
|
|
|
|
return $chrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function empty_cell
|
|
|
|
@abstracts constructor for a new / empty cell (nothing fancy so far)
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax empty_cell()
|
2002-09-02 13:14:30 +02:00
|
|
|
@result the cell
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
2003-08-28 16:31:11 +02:00
|
|
|
function empty_cell($type='label',$name='')
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
return array(
|
|
|
|
'type' => $type,
|
|
|
|
'name' => $name,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function new_cell
|
|
|
|
@abstract constructs a new cell in a give row or the last row, not existing rows will be created
|
|
|
|
@syntax new_cell( $row=False )
|
|
|
|
@param int $row row-number starting with 1 (!)
|
|
|
|
@param string $type type of the cell
|
|
|
|
@param string $label label for the cell
|
|
|
|
@param string $name name of the cell (index in the content-array)
|
|
|
|
@param array $attributes other attributes for the cell
|
|
|
|
@returns a reference to the new cell, use $new_cell = &$tpl->new_cell(); (!)
|
|
|
|
*/
|
|
|
|
function &new_cell($row=False,$type='label',$label='',$name='',$attributes=False)
|
|
|
|
{
|
|
|
|
$row = $row >= 0 ? intval($row) : 0;
|
|
|
|
if ($row && !isset($this->data[$row]) || !isset($this->data[1])) // new row ?
|
|
|
|
{
|
|
|
|
if (!$row) $row = 1;
|
|
|
|
|
|
|
|
$this->data[$row] = array();
|
|
|
|
}
|
|
|
|
if (!$row) // use last row
|
|
|
|
{
|
|
|
|
$row = count($this->data);
|
|
|
|
while (!isset($this->data[$row]))
|
|
|
|
{
|
|
|
|
--$row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$row = &$this->data[$row];
|
|
|
|
$col = $this->num2chrs(count($row));
|
|
|
|
$cell = &$row[$col];
|
|
|
|
$cell = $this->empty_cell($type,$name);
|
|
|
|
if ($label !== '')
|
|
|
|
{
|
|
|
|
$attributes['label'] = $label;
|
|
|
|
}
|
|
|
|
if (is_array($attributes))
|
|
|
|
{
|
|
|
|
foreach($attributes as $name => $value)
|
|
|
|
{
|
|
|
|
$cell[$name] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $cell;
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
2002-09-25 18:36:07 +02:00
|
|
|
/*!
|
|
|
|
@function set_rows_cols()
|
|
|
|
@abstract initialises rows & cols from the size of the data-array
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax set_rows_cols()
|
2002-09-25 18:36:07 +02:00
|
|
|
*/
|
|
|
|
function set_rows_cols()
|
|
|
|
{
|
|
|
|
$this->rows = count($this->data) - 1;
|
2003-11-03 16:43:55 +01:00
|
|
|
$this->cols = 0;
|
|
|
|
for($r = 1; $r <= $this->rows; ++$r)
|
|
|
|
{
|
|
|
|
$cols = count($this->data[$r]);
|
|
|
|
if ($this->cols < $cols)
|
|
|
|
{
|
|
|
|
$this->cols = $cols;
|
|
|
|
}
|
|
|
|
}
|
2002-09-25 18:36:07 +02:00
|
|
|
}
|
|
|
|
|
2002-02-06 10:03:11 +01:00
|
|
|
/*!
|
|
|
|
@function init
|
|
|
|
@abstract initialises all internal data-structures of the eTemplate and sets the keys
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax init($name='',$template='',$lang='',$group=0,$version='',$rows=1,$cols=1)
|
2002-06-09 23:31:01 +02:00
|
|
|
@param $name name of the eTemplate or array with the keys or all data
|
2002-02-06 10:03:11 +01:00
|
|
|
@param $template,$lang,$group,$version see class
|
|
|
|
@param $rows,$cols initial size of the template
|
|
|
|
*/
|
|
|
|
function init($name='',$template='',$lang='',$group=0,$version='',$rows=1,$cols=1)
|
|
|
|
{
|
2002-06-09 23:31:01 +02:00
|
|
|
reset($this->db_cols);
|
|
|
|
while (list($db_col,$col) = each($this->db_cols))
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
$this->$col = is_array($name) ? $name[$col] : $$col;
|
|
|
|
}
|
|
|
|
if ($this->template == 'default')
|
|
|
|
{
|
|
|
|
$this->template = '';
|
|
|
|
}
|
|
|
|
if ($this->lang == 'default')
|
|
|
|
{
|
|
|
|
$this->lang = '';
|
|
|
|
}
|
2002-09-25 18:36:07 +02:00
|
|
|
$this->tpls_in_file = is_array($name) ? $name['tpls_in_file'] : 0;
|
|
|
|
|
2002-06-09 23:31:01 +02:00
|
|
|
if (is_array($name) && isset($name['data']))
|
|
|
|
{
|
2002-09-25 18:36:07 +02:00
|
|
|
$this->set_rows_cols();
|
2002-06-09 23:31:01 +02:00
|
|
|
return; // data already set
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$this->size = $this->style = '';
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->data = array(0 => array());
|
2002-02-06 10:03:11 +01:00
|
|
|
$this->rows = $rows < 0 ? 1 : $rows;
|
|
|
|
$this->cols = $cols < 0 ? 1 : $cols;
|
|
|
|
for ($row = 1; $row <= $rows; ++$row)
|
|
|
|
{
|
|
|
|
for ($col = 0; $col < $cols; ++$col)
|
|
|
|
{
|
|
|
|
$this->data[$row][$this->num2chrs($col)] = $this->empty_cell();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function read
|
|
|
|
@abstract Reads an eTemplate from the database
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax read($name,$template='default',$lang='default',$group=0,$version='')
|
2002-02-06 10:03:11 +01:00
|
|
|
@param as discripted with the class, with the following exeptions
|
|
|
|
@param $template as '' loads the prefered template 'default' loads the default one '' in the db
|
|
|
|
@param $lang as '' loads the pref. lang 'default' loads the default one '' in the db
|
|
|
|
@param $group is NOT used / implemented yet
|
2002-09-02 13:14:30 +02:00
|
|
|
@result True if a fitting template is found, else False
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function read($name,$template='default',$lang='default',$group=0,$version='')
|
|
|
|
{
|
|
|
|
$this->init($name,$template,$lang,$group,$version);
|
2002-09-24 12:00:58 +02:00
|
|
|
if ($this->debug == 1 || $this->debug == $this->name)
|
|
|
|
{
|
2002-09-27 18:17:39 +02:00
|
|
|
echo "<p>soetemplate::read('$this->name','$this->template','$this->lang',$this->group,'$this->version')</p>\n";
|
2002-09-24 12:00:58 +02:00
|
|
|
}
|
2002-09-30 21:06:29 +02:00
|
|
|
if (($GLOBALS['phpgw_info']['server']['eTemplate-source'] == 'files' ||
|
|
|
|
$GLOBALS['phpgw_info']['server']['eTemplate-source'] == 'xslt') && $this->readfile())
|
2002-09-17 15:27:37 +02:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
if ($this->name)
|
|
|
|
{
|
|
|
|
$this->test_import($this->name); // import updates in setup-dir
|
|
|
|
}
|
|
|
|
$pref_lang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
|
|
|
|
$pref_templ = $GLOBALS['phpgw_info']['server']['template_set'];
|
|
|
|
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql = "SELECT * FROM $this->db_name WHERE et_name='".$this->db->db_addslashes($this->name)."' AND ";
|
2002-02-06 10:03:11 +01:00
|
|
|
if (is_array($name))
|
|
|
|
{
|
|
|
|
$template = $name['template'];
|
|
|
|
}
|
|
|
|
if ($template == 'default')
|
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql .= "(et_template='".$this->db->db_addslashes($pref_templ)."' OR et_template='')";
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql .= "et_template='".$this->db->db_addslashes($this->template)."'";
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
$sql .= ' AND ';
|
|
|
|
if (is_array($name))
|
|
|
|
{
|
|
|
|
$lang = $name['lang'];
|
|
|
|
}
|
|
|
|
if ($lang == 'default' || $name['lang'] == 'default')
|
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql .= "(et_lang='".$this->db->db_addslashes($pref_lang)."' OR et_lang='')";
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql .= "et_lang='".$this->db->db_addslashes($this->lang)."'";
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
if ($this->version != '')
|
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql .= "AND et_version='".$this->db->db_addslashes($this->version)."'";
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
$sql .= " ORDER BY et_lang DESC,et_template DESC,et_version DESC";
|
|
|
|
|
2002-09-24 12:00:58 +02:00
|
|
|
if ($this->debug == $this->name)
|
|
|
|
{
|
|
|
|
echo "<p>soetemplate::read: sql='$sql'</p>\n";
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
if (!$this->db->next_record())
|
|
|
|
{
|
2002-09-24 12:00:58 +02:00
|
|
|
$version = $this->version;
|
|
|
|
return $this->readfile() && (empty($version) || $version == $this->version);
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
$this->db2obj();
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2002-09-17 15:27:37 +02:00
|
|
|
/*!
|
|
|
|
@function readfile
|
|
|
|
@abstract Reads an eTemplate from the filesystem, the keys are already set by init in read
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax readfile()
|
2002-09-17 15:27:37 +02:00
|
|
|
@result True if a template is found, else False
|
|
|
|
*/
|
|
|
|
function readfile()
|
|
|
|
{
|
|
|
|
list($app,$name) = split("\.",$this->name,2);
|
|
|
|
$template = $this->template == '' ? 'default' : $this->template;
|
2002-09-30 21:06:29 +02:00
|
|
|
|
2002-09-17 15:27:37 +02:00
|
|
|
if ($this->lang)
|
|
|
|
{
|
2002-09-30 21:06:29 +02:00
|
|
|
$lang = '.' . $this->lang;
|
2002-09-17 15:27:37 +02:00
|
|
|
}
|
2002-09-30 21:06:29 +02:00
|
|
|
$first_try = $ext = $GLOBALS['phpgw_info']['server']['eTemplate-source'] == 'xslt' ? '.xsl' : '.xet';
|
2002-09-17 15:27:37 +02:00
|
|
|
|
2002-09-30 21:06:29 +02:00
|
|
|
while ((!$lang || !@file_exists($file = PHPGW_SERVER_ROOT . "/$app/templates/$template/$name$lang$ext") &&
|
|
|
|
!@file_exists($file = PHPGW_SERVER_ROOT . "/$app/templates/default/$name$lang$ext")) &&
|
|
|
|
!@file_exists($file = PHPGW_SERVER_ROOT . "/$app/templates/$template/$name$ext") &&
|
|
|
|
!@file_exists($file = PHPGW_SERVER_ROOT . "/$app/templates/default/$name$ext"))
|
|
|
|
{
|
|
|
|
if ($ext == $first_try)
|
|
|
|
{
|
|
|
|
$ext = $ext == '.xet' ? '.xsl' : '.xet';
|
|
|
|
|
|
|
|
if ($this->debug == 1 || $this->name != '' && $this->debug == $this->name)
|
|
|
|
{
|
|
|
|
echo "<p>tried '$file' now trying it with extension '$ext' !!!</p>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-09-17 17:38:34 +02:00
|
|
|
if ($this->name == '' || $app == '' || $name == '' || !@file_exists($file) || !($f = @fopen($file,'r')))
|
2002-09-17 15:27:37 +02:00
|
|
|
{
|
2002-09-29 15:01:40 +02:00
|
|
|
if ($this->debug == 1 || $this->name != '' && $this->debug == $this->name)
|
2002-09-24 12:00:58 +02:00
|
|
|
{
|
2002-09-30 21:06:29 +02:00
|
|
|
echo "<p>Can't open template '$this->name' / '$file' !!!</p>\n";
|
2002-09-24 12:00:58 +02:00
|
|
|
}
|
2002-09-17 15:27:37 +02:00
|
|
|
return False;
|
|
|
|
}
|
2002-09-30 21:06:29 +02:00
|
|
|
$xml = fread ($f, filesize ($file));
|
2002-09-17 15:27:37 +02:00
|
|
|
fclose($f);
|
|
|
|
|
2002-09-30 21:06:29 +02:00
|
|
|
if ($ext == '.xsl')
|
2002-09-17 15:27:37 +02:00
|
|
|
{
|
2002-09-30 21:06:29 +02:00
|
|
|
$cell = $this->empty_cell();
|
|
|
|
$cell['type'] = 'xslt';
|
|
|
|
$cell['size'] = $this->name;
|
|
|
|
//$cell['xslt'] = &$xml; xslttemplate class cant use it direct at the moment
|
|
|
|
$cell['name'] = '';
|
|
|
|
$this->data = array(0 => array(),1 => array('A' => &$cell));
|
|
|
|
$this->rows = $this->cols = 1;
|
2002-09-17 15:27:37 +02:00
|
|
|
}
|
2002-09-30 21:06:29 +02:00
|
|
|
else
|
2002-09-17 15:27:37 +02:00
|
|
|
{
|
2002-09-30 21:06:29 +02:00
|
|
|
if (!is_object($this->xul_io))
|
|
|
|
{
|
|
|
|
$this->xul_io = CreateObject('etemplate.xul_io');
|
|
|
|
}
|
|
|
|
$loaded = $this->xul_io->import(&$this,$xml);
|
2002-09-17 15:27:37 +02:00
|
|
|
|
2002-09-30 21:06:29 +02:00
|
|
|
if (!is_array($loaded))
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$this->name = $app . '.' . $name; // if template was copied or app was renamed
|
2002-09-25 18:36:07 +02:00
|
|
|
|
2002-09-30 21:06:29 +02:00
|
|
|
$this->tpls_in_file = count($loaded);
|
|
|
|
}
|
2002-09-17 15:27:37 +02:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2002-09-04 00:59:47 +02:00
|
|
|
/*!
|
|
|
|
@function search
|
|
|
|
@syntax search($name,$template='default',$lang='default',$group=0,$version='')
|
|
|
|
@author ralfbecker
|
|
|
|
@abstract Lists the eTemplates matching the given criteria
|
|
|
|
@param as discripted with the class, with the following exeptions
|
|
|
|
@param $template as '' loads the prefered template 'default' loads the default one '' in the db
|
|
|
|
@param $lang as '' loads the pref. lang 'default' loads the default one '' in the db
|
|
|
|
@param $group is NOT used / implemented yet
|
|
|
|
@result array of arrays with the template-params
|
|
|
|
*/
|
|
|
|
function search($name,$template='default',$lang='default',$group=0,$version='')
|
|
|
|
{
|
|
|
|
if ($this->name)
|
|
|
|
{
|
|
|
|
$this->test_import($this->name); // import updates in setup-dir
|
|
|
|
}
|
|
|
|
$pref_lang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
|
|
|
|
$pref_templ = $GLOBALS['phpgw_info']['server']['template_set'];
|
|
|
|
|
|
|
|
if (is_array($name))
|
|
|
|
{
|
|
|
|
$template = $name['template'];
|
|
|
|
$lang = $name['lang'];
|
|
|
|
$group = $name['group'];
|
|
|
|
$version = $name['version'];
|
|
|
|
$name = $name['name'];
|
|
|
|
}
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql = "SELECT et_name,et_template,et_lang,et_group,et_version FROM $this->db_name WHERE et_name LIKE '".$this->db->db_addslashes($name)."%'";
|
2002-09-04 00:59:47 +02:00
|
|
|
|
|
|
|
if ($template != '' && $template != 'default')
|
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql .= " AND et_template LIKE '".$this->db->db_addslashes($template)."%'";
|
2002-09-04 00:59:47 +02:00
|
|
|
}
|
|
|
|
if ($lang != '' && $lang != 'default')
|
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql .= " AND et_lang LIKE '".$this->db->db_addslashes($lang)."%'";
|
2002-09-04 00:59:47 +02:00
|
|
|
}
|
|
|
|
if ($this->version != '')
|
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
$sql .= " AND et_version LIKE '".$this->db->db_addslashes($version)."%'";
|
2002-09-04 00:59:47 +02:00
|
|
|
}
|
|
|
|
$sql .= " ORDER BY et_name DESC,et_lang DESC,et_template DESC,et_version DESC";
|
|
|
|
|
2002-10-28 02:17:32 +01:00
|
|
|
$tpl = new soetemplate;
|
|
|
|
$tpl->db->query($sql,__LINE__,__FILE__);
|
2002-09-04 00:59:47 +02:00
|
|
|
$result = array();
|
2002-10-28 02:17:32 +01:00
|
|
|
while ($tpl->db->next_record())
|
2002-09-04 00:59:47 +02:00
|
|
|
{
|
2002-10-28 02:17:32 +01:00
|
|
|
if ($tpl->db->f('et_lang') != '##') // exclude or import-time-stamps
|
2002-09-29 15:01:40 +02:00
|
|
|
{
|
2002-10-28 02:17:32 +01:00
|
|
|
$tpl->db2obj();
|
|
|
|
|
|
|
|
$result[] = $tpl->as_array();
|
2002-09-29 15:01:40 +02:00
|
|
|
}
|
2002-09-04 00:59:47 +02:00
|
|
|
}
|
2003-03-28 00:43:37 +01:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>soetemplate::search('$name') sql='$sql'</p>\n<pre>\n";
|
|
|
|
print_r($result);
|
|
|
|
echo "</pre>\n";
|
|
|
|
}
|
2002-09-04 00:59:47 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2002-02-06 10:03:11 +01:00
|
|
|
/*!
|
|
|
|
@function db2obj
|
|
|
|
@abstract copies all cols into the obj and unserializes the data-array
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax db2obj()
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function db2obj()
|
|
|
|
{
|
|
|
|
for (reset($this->db_cols); list($db_col,$name) = each($this->db_cols); )
|
|
|
|
{
|
|
|
|
$this->$name = $this->db->f($db_col);
|
|
|
|
}
|
|
|
|
$this->data = unserialize(stripslashes($this->data));
|
2002-10-28 02:17:32 +01:00
|
|
|
if (!is_array($this->data)) $this->data = array();
|
2002-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
if ($this->name[0] != '.')
|
|
|
|
{
|
|
|
|
reset($this->data); each($this->data);
|
|
|
|
while (list($row,$cols) = each($this->data))
|
|
|
|
{
|
|
|
|
while (list($col,$cell) = each($cols))
|
|
|
|
{
|
|
|
|
if (is_array($cell['type']))
|
|
|
|
{
|
|
|
|
$this->data[$row][$col]['type'] = $cell['type'][0];
|
|
|
|
//echo "corrected in $this->name cell $col$row attribute type<br>\n";
|
|
|
|
}
|
|
|
|
if (is_array($cell['align']))
|
|
|
|
{
|
|
|
|
$this->data[$row][$col]['align'] = $cell['align'][0];
|
|
|
|
//echo "corrected in $this->name cell $col$row attribute align<br>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-25 18:36:07 +02:00
|
|
|
$this->set_rows_cols();
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2002-09-02 13:14:30 +02:00
|
|
|
@function compress_array
|
|
|
|
@syntax compress_array( $arr )
|
|
|
|
@author ralfbecker
|
2002-02-06 10:03:11 +01:00
|
|
|
@abstract to save space in the db all empty values in the array got unset
|
|
|
|
@discussion The never-'' type field ensures a cell does not disapear completely.
|
|
|
|
@discussion Calls it self recursivly for arrays / the rows
|
|
|
|
@param $arr the array to compress
|
2002-09-02 13:14:30 +02:00
|
|
|
@result the compressed array
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function compress_array($arr)
|
|
|
|
{
|
|
|
|
if (!is_array($arr))
|
|
|
|
{
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
while (list($key,$val) = each($arr))
|
|
|
|
{
|
|
|
|
if (is_array($val))
|
|
|
|
{
|
|
|
|
$arr[$key] = $this->compress_array($val);
|
|
|
|
}
|
2002-10-03 18:46:18 +02:00
|
|
|
elseif ($val == '')
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
unset($arr[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function as_array
|
|
|
|
@abstract returns obj-data as array
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax as_array($data_too=0)
|
2002-02-06 10:03:11 +01:00
|
|
|
@param $data_too 0 = no data array, 1 = data array too, 2 = serialize data array
|
2002-09-02 13:14:30 +02:00
|
|
|
@result the array
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function as_array($data_too=0)
|
|
|
|
{
|
|
|
|
$arr = array();
|
|
|
|
reset($this->db_cols);
|
|
|
|
while (list($db_col,$col) = each($this->db_cols))
|
|
|
|
{
|
|
|
|
if ($col != 'data' || $data_too)
|
|
|
|
{
|
|
|
|
$arr[$col] = $this->$col;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($data_too == 2)
|
|
|
|
{
|
|
|
|
$arr['data'] = serialize($arr['data']);
|
|
|
|
}
|
2002-09-25 18:36:07 +02:00
|
|
|
if ($this->tpls_in_file) {
|
|
|
|
$arr['tpls_in_file'] = $this->tpls_in_file;
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function save
|
|
|
|
@abstract saves eTemplate-object to db, can be used as saveAs by giving keys as params
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax save($name='',$template='.',$lang='.',$group='',$version='.')
|
2002-02-06 10:03:11 +01:00
|
|
|
@params keys see class
|
2002-09-02 13:14:30 +02:00
|
|
|
@result the number of affected rows, 1 should be ok, 0 somethings wrong
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function save($name='',$template='.',$lang='.',$group='',$version='.')
|
|
|
|
{
|
2002-09-27 18:17:39 +02:00
|
|
|
if (is_array($name))
|
|
|
|
{
|
|
|
|
$template = $name['template'];
|
|
|
|
$lang = $name['lang'];
|
|
|
|
$group = $name['group'];
|
|
|
|
$version = $name['version'];
|
|
|
|
$name = $name['name'];
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
if ($name != '')
|
|
|
|
{
|
|
|
|
$this->name = $name;
|
|
|
|
}
|
|
|
|
if ($lang != '.')
|
|
|
|
{
|
|
|
|
$this->lang = $lang;
|
|
|
|
}
|
|
|
|
if ($template != '.')
|
|
|
|
{
|
|
|
|
$this->template = $template;
|
|
|
|
}
|
|
|
|
if ($group != '')
|
|
|
|
{
|
|
|
|
$this->group = $group;
|
|
|
|
}
|
|
|
|
if ($version != '.')
|
|
|
|
{
|
|
|
|
$this->version = $version;
|
|
|
|
}
|
2002-02-14 15:06:53 +01:00
|
|
|
if ($this->name == '') // name need to be set !!!
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2002-09-27 18:17:39 +02:00
|
|
|
if ($this->debug > 0 || $this->debug == $this->name)
|
|
|
|
{
|
|
|
|
echo "<p>soetemplate::save('$this->name','$this->template','$this->lang',$this->group,'$this->version')</p>\n";
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$this->delete(); // so we have always a new insert
|
|
|
|
|
|
|
|
if ($this->name[0] != '.') // correct up old messed up templates
|
|
|
|
{
|
|
|
|
reset($this->data); each($this->data);
|
|
|
|
while (list($row,$cols) = each($this->data))
|
|
|
|
{
|
|
|
|
while (list($col,$cell) = each($cols))
|
|
|
|
{
|
|
|
|
if (is_array($cell['type'])) {
|
|
|
|
$this->data[$row][$col]['type'] = $cell['type'][0];
|
|
|
|
//echo "corrected in $this->name cell $col$row attribute type<br>\n";
|
|
|
|
}
|
|
|
|
if (is_array($cell['align'])) {
|
|
|
|
$this->data[$row][$col]['align'] = $cell['align'][0];
|
|
|
|
//echo "corrected in $this->name cell $col$row attribute align<br>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-29 15:01:40 +02:00
|
|
|
if (!$this->modified)
|
|
|
|
{
|
|
|
|
$this->modified = time();
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$data = $this->as_array(1);
|
|
|
|
$data['data'] = serialize($this->compress_array($data['data']));
|
|
|
|
|
|
|
|
$sql = "INSERT INTO $this->db_name (";
|
2003-07-09 02:00:37 +02:00
|
|
|
foreach ($this->db_cols as $db_col => $col)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
$sql .= $db_col . ',';
|
2003-07-09 02:00:37 +02:00
|
|
|
$vals .= $db_col == 'et_group' ? intval($data[$col]).',' : "'" . addslashes($data[$col]) . "',";
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
$sql[strlen($sql)-1] = ')';
|
|
|
|
$sql .= " VALUES ($vals";
|
|
|
|
$sql[strlen($sql)-1] = ')';
|
|
|
|
|
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
|
|
|
|
return $this->db->affected_rows();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function delete
|
|
|
|
@abstract Deletes the eTemplate from the db, object itself is unchanged
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax delete()
|
2002-09-02 13:14:30 +02:00
|
|
|
@result the number of affected rows, 1 should be ok, 0 somethings wrong
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function delete()
|
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
foreach ($this->db_key_cols as $db_col => $col)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2003-07-09 02:00:37 +02:00
|
|
|
$vals .= ($vals ? ' AND ' : '') . $db_col . '=' . ($db_col == 'et_group' ? intval($this->$col) : "'".$this->$col."'");
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
$this->db->query("DELETE FROM $this->db_name WHERE $vals",__LINE__,__FILE__);
|
|
|
|
|
|
|
|
return $this->db->affected_rows();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function dump2setup
|
|
|
|
@abstract dumps all eTemplates to <app>/setup/etemplates.inc.php for distribution
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax dump2setup($app)
|
2002-02-06 10:03:11 +01:00
|
|
|
@param $app app- or template-name
|
2002-09-02 13:14:30 +02:00
|
|
|
@result the number of templates dumped as message
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function dump2setup($app)
|
|
|
|
{
|
|
|
|
list($app) = explode('.',$app);
|
|
|
|
|
|
|
|
$this->db->query("SELECT * FROM $this->db_name WHERE et_name LIKE '$app%'");
|
|
|
|
|
2002-02-15 06:27:30 +01:00
|
|
|
$dir = PHPGW_SERVER_ROOT . "/$app/setup";
|
|
|
|
if (!is_writeable($dir))
|
|
|
|
{
|
2003-08-08 18:20:16 +02:00
|
|
|
return lang("Error: webserver is not allowed to write into '%1' !!!",$dir);
|
2002-02-15 06:27:30 +01:00
|
|
|
}
|
|
|
|
$file = "$dir/etemplates.inc.php";
|
|
|
|
if (file_exists($file))
|
|
|
|
{
|
2003-07-21 18:09:33 +02:00
|
|
|
$old_file = "$dir/etemplates.old.inc.php";
|
|
|
|
if (file_exists($old_file))
|
|
|
|
{
|
|
|
|
unlink($old_file);
|
|
|
|
}
|
|
|
|
rename($file,$old_file);
|
2002-02-15 06:27:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!($f = fopen($file,'w')))
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-03 13:10:52 +02:00
|
|
|
fwrite($f,"<?php\n// eTemplates for Application '$app', generated by etemplate.dump() ".date('Y-m-d H:i')."\n\n".
|
2002-10-03 21:53:47 +02:00
|
|
|
'/* $'.'Id$ */'."\n\n");
|
2002-10-03 13:10:52 +02:00
|
|
|
|
2002-02-06 10:03:11 +01:00
|
|
|
for ($n = 0; $this->db->next_record(); ++$n)
|
|
|
|
{
|
|
|
|
$str = '$templ_data[] = array(';
|
|
|
|
for (reset($this->db_cols); list($db_col,$name) = each($this->db_cols); )
|
|
|
|
{
|
|
|
|
$str .= "'$name' => '".addslashes($this->db->f($db_col))."',";
|
|
|
|
}
|
|
|
|
$str .= ");\n\n";
|
|
|
|
fwrite($f,$str);
|
|
|
|
}
|
|
|
|
fclose($f);
|
|
|
|
|
2003-08-08 18:20:16 +02:00
|
|
|
return lang("%1 eTemplates for Application '%2' dumped to '%3'",$n,$app,$file);
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
2002-10-12 18:37:44 +02:00
|
|
|
function getToTranslateCell($cell,&$to_trans)
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$strings = explode('|',$cell['help']);
|
|
|
|
|
|
|
|
if ($cell['type'] != 'image')
|
|
|
|
{
|
2003-12-19 03:20:59 +01:00
|
|
|
$strings = array_merge($strings,explode('|',$cell['label']));
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2002-10-12 18:37:44 +02:00
|
|
|
list($extra_row) = explode(',',$cell['size']);
|
2003-08-28 16:31:11 +02:00
|
|
|
if (substr($cell['type'],0,6) == 'select' && !empty($extra_row) && !intval($extra_row))
|
|
|
|
{
|
|
|
|
$strings[] = $extra_row;
|
|
|
|
}
|
|
|
|
if (!empty($cell['blur']))
|
|
|
|
{
|
|
|
|
$strings[] = $cell['blur'];
|
|
|
|
}
|
|
|
|
foreach($strings as $str)
|
2002-10-12 18:37:44 +02:00
|
|
|
{
|
|
|
|
if (strlen($str) > 1 && $str[0] != '@')
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$to_trans[trim(strtolower($str))] = $str;
|
2002-10-12 18:37:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-06 10:03:11 +01:00
|
|
|
/*!
|
|
|
|
@function getToTranslate
|
|
|
|
@abstract extracts all texts: labels and helptexts from an eTemplate-object
|
2002-09-02 13:14:30 +02:00
|
|
|
@discussion some extensions use a '|' to squezze multiple texts in a label or help field
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax getToTranslate()
|
2002-09-02 13:14:30 +02:00
|
|
|
@result array with messages as key AND value
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function getToTranslate()
|
|
|
|
{
|
|
|
|
$to_trans = array();
|
|
|
|
|
|
|
|
reset($this->data); each($this->data); // skip width
|
|
|
|
while (list($row,$cols) = each($this->data))
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
foreach($cols as $col => $cell)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-10-12 18:37:44 +02:00
|
|
|
$this->getToTranslateCell($cell,$to_trans);
|
|
|
|
|
|
|
|
if ($cell['type'] == 'vbox' || $cell['type'] == 'hbox')
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-10-12 18:37:44 +02:00
|
|
|
for ($n = 1; $n <= $cell['size']; ++$n)
|
2002-06-10 23:30:09 +02:00
|
|
|
{
|
2002-10-12 18:37:44 +02:00
|
|
|
$this->getToTranslateCell($cell[$n],$to_trans);
|
2002-06-10 23:30:09 +02:00
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $to_trans;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function getToTranslateApp
|
|
|
|
@abstract Read all eTemplates of an app an extracts the texts to an array
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax getToTranslateApp($app)
|
2002-02-06 10:03:11 +01:00
|
|
|
@param $app name of the app
|
2002-09-02 13:14:30 +02:00
|
|
|
@result the array with texts
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function getToTranslateApp($app)
|
|
|
|
{
|
|
|
|
$to_trans = array();
|
|
|
|
|
2002-10-28 02:17:32 +01:00
|
|
|
$tpls = $this->search($app);
|
2002-02-06 10:03:11 +01:00
|
|
|
|
2002-10-28 02:17:32 +01:00
|
|
|
$tpl = new soetemplate; // to not alter our own data
|
|
|
|
|
|
|
|
while (list(,$keys) = each($tpls))
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-10-28 02:17:32 +01:00
|
|
|
if (($keys['name'] != $last['name'] || // write only newest version
|
|
|
|
$keys['template'] != $last['template']) &&
|
|
|
|
!strstr($keys['name'],'test'))
|
|
|
|
{
|
|
|
|
$tpl->read($keys);
|
|
|
|
$to_trans += $tpl->getToTranslate();
|
|
|
|
$last = $keys;
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
return $to_trans;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function writeLangFile
|
|
|
|
@abstract Write new lang-file using the existing one and all text from the eTemplates
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax writeLangFile($app,$lang='en',$additional='')
|
2002-02-06 10:03:11 +01:00
|
|
|
@param $app app- or template-name
|
|
|
|
@param $lang language the messages in the template are, defaults to 'en'
|
|
|
|
@param $additional extra texts to translate, if you pass here an array with all messages and
|
|
|
|
@param select-options they get writen too (form is <unique key> => <message>)
|
2002-09-02 13:14:30 +02:00
|
|
|
@result message with number of messages written (total and new)
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function writeLangFile($app,$lang='en',$additional='')
|
|
|
|
{
|
2002-02-14 15:06:53 +01:00
|
|
|
if (!$additional)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-02-14 15:06:53 +01:00
|
|
|
$addtional = array();
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
list($app) = explode('.',$app);
|
|
|
|
|
2002-10-03 18:46:18 +02:00
|
|
|
if (!file_exists(PHPGW_SERVER_ROOT.'/developer_tools/inc/class.solangfile.inc.php'))
|
|
|
|
{
|
2002-10-28 02:17:32 +01:00
|
|
|
$solangfile = CreateObject('etemplate.solangfile');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$solangfile = CreateObject('developer_tools.solangfile');
|
2002-10-03 18:46:18 +02:00
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$langarr = $solangfile->load_app($app,$lang);
|
2002-10-14 02:39:47 +02:00
|
|
|
if (!is_array($langarr))
|
|
|
|
{
|
|
|
|
$langarr = array();
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
$commonarr = $solangfile->load_app('phpgwapi',$lang) + $solangfile->load_app('etemplate',$lang);
|
|
|
|
|
2002-02-06 10:03:11 +01:00
|
|
|
$to_trans = $this->getToTranslateApp($app);
|
|
|
|
if (is_array($additional))
|
|
|
|
{
|
2002-02-14 15:06:53 +01:00
|
|
|
//echo "writeLangFile: additional ="; _debug_array($additional);
|
2003-08-28 16:31:11 +02:00
|
|
|
foreach($additional as $msg)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$to_trans[trim(strtolower($msg))] = $msg;
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
2002-10-12 18:37:44 +02:00
|
|
|
unset($to_trans['']);
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
for ($new = $n = 0; list($message_id,$content) = each($to_trans); ++$n)
|
|
|
|
{
|
|
|
|
if (!isset($langarr[$message_id]) && !isset($commonarr[$message_id]))
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
if (@isset($langarr[$content])) // caused by not lowercased-message_id's
|
2002-10-14 02:39:47 +02:00
|
|
|
{
|
|
|
|
unset($langarr[$content]);
|
|
|
|
}
|
2002-02-14 15:06:53 +01:00
|
|
|
$langarr[$message_id] = array(
|
|
|
|
'message_id' => $message_id,
|
2003-08-28 16:31:11 +02:00
|
|
|
'app_name' => $app,
|
|
|
|
'content' => $content
|
2002-02-14 15:06:53 +01:00
|
|
|
);
|
2002-02-06 10:03:11 +01:00
|
|
|
++$new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ksort($langarr);
|
2002-02-14 15:06:53 +01:00
|
|
|
|
|
|
|
$dir = PHPGW_SERVER_ROOT . "/$app/setup";
|
|
|
|
if (!is_writeable($dir))
|
|
|
|
{
|
2003-08-08 18:20:16 +02:00
|
|
|
return lang("Error: webserver is not allowed to write into '%1' !!!",$dir);
|
2002-02-14 15:06:53 +01:00
|
|
|
}
|
|
|
|
$file = "$dir/phpgw_$lang.lang";
|
|
|
|
if (file_exists($file))
|
|
|
|
{
|
2003-07-21 18:09:33 +02:00
|
|
|
$old_file = "$dir/phpgw_$lang.old.lang";
|
|
|
|
if (file_exists($old_file))
|
|
|
|
{
|
|
|
|
unlink($old_file);
|
|
|
|
}
|
|
|
|
rename($file,$old_file);
|
2002-02-14 15:06:53 +01:00
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$solangfile->write_file($app,$langarr,$lang);
|
|
|
|
$solangfile->loaddb($app,$lang);
|
|
|
|
|
2003-08-08 18:20:16 +02:00
|
|
|
return lang("%1 (%2 new) Messages writen for Application '%3' and Languages '%4'",$n,$new,$app,$lang);
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function import_dump
|
|
|
|
@abstract Imports the dump-file /$app/setup/etempplates.inc.php unconditional (!)
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax import_dump($app)
|
2002-02-06 10:03:11 +01:00
|
|
|
@param $app app name
|
2002-09-02 13:14:30 +02:00
|
|
|
@result message with number of templates imported
|
2002-02-06 10:03:11 +01:00
|
|
|
*/
|
|
|
|
function import_dump($app)
|
|
|
|
{
|
2002-09-29 15:01:40 +02:00
|
|
|
include($path = PHPGW_SERVER_ROOT."/$app/setup/etemplates.inc.php");
|
2002-02-06 10:03:11 +01:00
|
|
|
$templ = new etemplate($app);
|
|
|
|
|
|
|
|
for ($n = 0; isset($templ_data[$n]); ++$n)
|
|
|
|
{
|
|
|
|
for (reset($this->db_cols); list($db_col,$name) = each($this->db_cols); )
|
|
|
|
{
|
|
|
|
$templ->$name = $templ_data[$n][$name];
|
|
|
|
}
|
|
|
|
$templ->data = unserialize(stripslashes($templ->data));
|
2002-09-29 15:01:40 +02:00
|
|
|
if (!$templ->modified)
|
|
|
|
{
|
|
|
|
$templ->modified = filemtime($path);
|
|
|
|
}
|
2002-02-06 10:03:11 +01:00
|
|
|
$templ->save();
|
|
|
|
}
|
2003-08-08 18:20:16 +02:00
|
|
|
return lang("%1 new eTemplates imported for Application '%2'",$n,$app);
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function test_import
|
|
|
|
@abstract test if new template-import necessary for app and does the import
|
|
|
|
@discussion Get called on every read of a eTemplate, caches the result in phpgw_info.
|
|
|
|
@discussion The timestamp of the last import for app gets written into the db.
|
2003-02-22 13:25:46 +01:00
|
|
|
@syntax test_import($app)
|
2002-02-06 10:03:11 +01:00
|
|
|
@param $app app- or template-name
|
|
|
|
*/
|
|
|
|
function test_import($app) // should be done from the setup-App
|
|
|
|
{
|
|
|
|
list($app) = explode('.',$app);
|
|
|
|
|
2002-02-19 19:04:46 +01:00
|
|
|
if (!$app || $GLOBALS['phpgw_info']['etemplate']['import_tested'][$app])
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
return ''; // ensure test is done only once per call and app
|
|
|
|
}
|
|
|
|
$GLOBALS['phpgw_info']['etemplate']['import_tested'][$app] = True; // need to be done before new ...
|
|
|
|
|
|
|
|
$path = PHPGW_SERVER_ROOT."/$app/setup/etemplates.inc.php";
|
|
|
|
|
2002-09-22 19:55:17 +02:00
|
|
|
if ($time = @filemtime($path))
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-09-27 18:17:39 +02:00
|
|
|
$templ = new soetemplate(".$app",'','##');
|
2002-09-29 15:01:40 +02:00
|
|
|
if ($templ->lang != '##' || $templ->modified < $time) // need to import
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
$ret = $this->import_dump($app);
|
2002-09-29 15:01:40 +02:00
|
|
|
$templ->modified = $time;
|
2002-02-06 10:03:11 +01:00
|
|
|
$templ->save(".$app",'','##');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
2002-02-14 15:06:53 +01:00
|
|
|
};
|