2002-02-06 10:03:11 +01:00
|
|
|
<?php
|
2006-04-20 19:12:30 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare EditableTemplates - Business Objects
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2002-02-06 10:03:11 +01:00
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
include_once(EGW_INCLUDE_ROOT . '/etemplate/inc/class.soetemplate.inc.php');
|
2002-02-06 10:03:11 +01:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* Business Object for eTemplates, extending the Storage Object
|
|
|
|
*
|
|
|
|
* Not so much so far, as the most logic is still in the UI-class
|
|
|
|
*
|
|
|
|
* @package etemplate
|
2005-02-18 23:44:42 +01:00
|
|
|
* @subpackage api
|
2004-10-07 23:53:10 +02:00
|
|
|
* @author RalfBecker-AT-outdoor-training.de
|
|
|
|
* @license GPL
|
|
|
|
*/
|
2002-02-06 10:03:11 +01:00
|
|
|
class boetemplate extends soetemplate
|
|
|
|
{
|
2002-05-13 23:30:46 +02:00
|
|
|
var $extensions = array();
|
|
|
|
|
2002-02-06 10:03:11 +01:00
|
|
|
var $types = array(
|
2002-02-14 15:06:53 +01:00
|
|
|
'label' => 'Label', // Label $cell['label'] is (to be translated) textual content
|
|
|
|
'text' => 'Text', // Textfield 1 Line (size = [length][,maxlength])
|
2005-02-06 16:49:50 +01:00
|
|
|
'int' => 'Integer', // like text, but only numbers (size = [min][,max])
|
2002-02-14 15:06:53 +01:00
|
|
|
'float' => 'Floating Point', // --------------- " --------------------------
|
2002-10-09 02:31:01 +02:00
|
|
|
'textarea'=> 'Textarea', // Multiline Text Input (size = [rows][,cols])
|
2004-02-28 23:41:32 +01:00
|
|
|
'htmlarea' => 'Formatted Text (HTML)',
|
2002-02-06 10:03:11 +01:00
|
|
|
'checkbox'=> 'Checkbox',
|
|
|
|
'radio' => 'Radiobutton', // Radiobutton (size = value if checked)
|
2005-02-06 16:49:50 +01:00
|
|
|
'button'=> 'Submitbutton',
|
2007-01-20 09:55:26 +01:00
|
|
|
'buttononly' => 'Button', // input type="button"
|
2002-02-06 10:03:11 +01:00
|
|
|
'hrule' => 'Horizontal Rule',
|
2005-02-06 16:49:50 +01:00
|
|
|
'template' => 'Template', // $cell['name'] contains template-name, $cell['size'] index into $content,$cname,$readonlys
|
2002-10-09 02:31:01 +02:00
|
|
|
'image' => 'Image', // label = url, name=link or method, help=alt or title
|
|
|
|
'date' => '', // Datefield, size='' timestamp or size=format like 'm/d/Y'
|
2005-02-06 16:49:50 +01:00
|
|
|
'select'=> 'Selectbox', // Selectbox ($sel_options[$name] or $content[options-$name] is array with options)
|
|
|
|
// if size > 1 then multiple selections, size lines showed
|
2002-10-09 02:31:01 +02:00
|
|
|
'html' => 'Html', // Raw html in $content[$cell['name']]
|
2002-10-12 18:37:44 +02:00
|
|
|
'file' => 'FileUpload', // show an input type='file', set the local name as ${name}_path
|
|
|
|
'vbox' => 'VBox', // a (vertical) box to contain widgets in rows, size = # of rows
|
2003-03-28 00:47:03 +01:00
|
|
|
'hbox' => 'HBox', // a (horizontal) box to contain widgets in cols, size = # of cols
|
2005-02-06 16:49:50 +01:00
|
|
|
'groupbox' => 'GroupBox', // a box with a label containing other elements to group them (html: fieldset)
|
2005-02-08 13:29:06 +01:00
|
|
|
'box' => 'Box', // just a container for widgets (html: div)
|
2005-02-16 00:22:10 +01:00
|
|
|
'grid' => 'Grid', // tabular widget containing rows with columns of widgets
|
2006-12-06 21:09:22 +01:00
|
|
|
'deck' => 'Deck', // a container of elements where only one is visible, size = # of elem.
|
|
|
|
'passwd' => 'Password' // a text of type password
|
2002-02-06 10:03:11 +01:00
|
|
|
);
|
2005-02-18 23:44:42 +01:00
|
|
|
var $garbage_collection_done;
|
2005-02-13 14:03:01 +01:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* constructor of class
|
|
|
|
*
|
|
|
|
* Calls the constructor of soetemplate
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string/array $name name of etemplate or array with name and other keys
|
|
|
|
* @param string/array $load_via name or array with keys of other etemplate to load in order to get $name
|
2004-10-07 23:53:10 +02:00
|
|
|
*/
|
2002-09-25 18:36:07 +02:00
|
|
|
function boetemplate($name='',$load_via='')
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2002-09-25 18:36:07 +02:00
|
|
|
$this->soetemplate();
|
|
|
|
|
2002-10-06 10:50:23 +02:00
|
|
|
$tname = &$name;
|
|
|
|
if (is_array($name))
|
|
|
|
{
|
|
|
|
$tname = &$name['name'];
|
|
|
|
}
|
2006-12-07 13:46:46 +01:00
|
|
|
$tname = (strpos($tname,'.') === false && !empty($tname) ?
|
2002-10-08 02:06:14 +02:00
|
|
|
(is_array($load_via) ? $load_via['name'] : $load_via).'.':'').$tname;
|
2002-10-06 10:50:23 +02:00
|
|
|
|
2002-10-08 02:06:14 +02:00
|
|
|
if (empty($tname) || !$this->read($name,'','',0,'',$load_via))
|
2002-09-25 18:36:07 +02:00
|
|
|
{
|
|
|
|
$this->init($name);
|
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
$this->garbage_collection_done =& $GLOBALS['egw_info']['etemplate']['garbage_collection_done'];
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
|
2005-02-08 13:29:06 +01:00
|
|
|
/**
|
|
|
|
* checks if a grid row or column is disabled
|
|
|
|
*
|
|
|
|
* Expression: [!][@]val[=[@]check]
|
|
|
|
* Parts in square brackets are optional, a ! negates the expression, @val evaluates to $content['val']
|
|
|
|
* if no =check is given all set non-empty and non-zero strings are true (standard php behavior)
|
|
|
|
*
|
|
|
|
* @param string $disabled expression to check, eg. "!@var" for !$content['var']
|
|
|
|
* @param array $content the content-array in the context of the grid
|
|
|
|
* @return boolean true if the row/col is disabled or false if not
|
|
|
|
*/
|
|
|
|
function check_disabled($disabled,$content)
|
|
|
|
{
|
2005-02-18 23:44:42 +01:00
|
|
|
if ($this->onclick_handler && !$this->no_onclick)
|
|
|
|
{
|
|
|
|
return false; // we have an onclick handler
|
|
|
|
}
|
2005-02-08 13:29:06 +01:00
|
|
|
//return False;
|
|
|
|
if ($not = $disabled[0] == '!')
|
|
|
|
{
|
|
|
|
$disabled = substr($disabled,1);
|
|
|
|
}
|
|
|
|
list($val,$check_val) = $vals = explode('=',$disabled);
|
|
|
|
|
|
|
|
if ($val[0] == '@')
|
|
|
|
{
|
|
|
|
$val = $this->get_array($content,substr($val,1));
|
|
|
|
}
|
|
|
|
if ($check_val[0] == '@')
|
|
|
|
{
|
|
|
|
$check_val = $this->get_array($content,substr($check_val,1));
|
|
|
|
}
|
2006-04-24 22:42:42 +02:00
|
|
|
$result = count($vals) == 1 ? $val != '' : ($check_val{0} == '/' ? preg_match($check_val,$val) : $val == $check_val);
|
2005-02-08 13:29:06 +01:00
|
|
|
if ($not) $result = !$result;
|
|
|
|
//echo "<p>check_disabled: '".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False')."</p>\n";
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* allows a few variables (eg. row-number) to be used in field-names
|
|
|
|
*
|
|
|
|
* This is mainly used for autorepeat, but other use is possible.
|
|
|
|
* You need to be aware of the rules PHP uses to expand vars in strings, a name
|
|
|
|
* of "Row$row[length]" will expand to 'Row' as $row is scalar, you need to use
|
|
|
|
* "Row${row}[length]" instead. Only one indirection is allowd in a string by php !!!
|
|
|
|
* Out of that reason we have now the variable $row_cont, which is $cont[$row] too.
|
|
|
|
* Attention !!!
|
|
|
|
* Using only number as index in field-names causes a lot trouble, as depending
|
|
|
|
* on the variable type (which php determines itself) you used filling and later
|
|
|
|
* accessing the array it can by the index or the key of an array element.
|
|
|
|
* To make it short and clear, use "Row$row" or "$col$row" not "$row" or "$row$col" !!!
|
|
|
|
*
|
2007-03-07 13:30:17 +01:00
|
|
|
* @static
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param sring $name the name to expand
|
|
|
|
* @param int $c is the column index starting with 0 (if you have row-headers, data-cells start at 1)
|
|
|
|
* @param int $row is the row number starting with 0 (if you have col-headers, data-cells start at 1)
|
|
|
|
* @param int $c_ is the value of the previous template-inclusion,
|
2004-10-07 23:53:10 +02:00
|
|
|
* eg. the column-headers in the eTemplate-editor are templates itself,
|
|
|
|
* to show the column-name in the header you can not use $col as it will
|
|
|
|
* be constant as it is always the same col in the header-template,
|
|
|
|
* what you want is the value of the previous template-inclusion.
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param int $row_ is the value of the previous template-inclusion,
|
|
|
|
* @param array $cont content of the template, you might use it to generate button-names with id values in it:
|
2004-10-07 23:53:10 +02:00
|
|
|
* "del[$cont[id]]" expands to "del[123]" if $cont = array('id' => 123)
|
|
|
|
* @return string the expanded name
|
|
|
|
*/
|
2002-02-06 10:03:11 +01:00
|
|
|
function expand_name($name,$c,$row,$c_='',$row_='',$cont='')
|
|
|
|
{
|
2004-04-05 02:00:40 +02:00
|
|
|
$is_index_in_content = $name[0] == '@';
|
2006-12-07 13:46:46 +01:00
|
|
|
if (strpos($name,'$') !== false)
|
2002-10-14 02:39:47 +02:00
|
|
|
{
|
2002-10-18 00:10:12 +02:00
|
|
|
if (!$cont)
|
|
|
|
{
|
|
|
|
$cont = array();
|
|
|
|
}
|
2007-03-07 13:30:17 +01:00
|
|
|
if (!is_numeric($c)) $c = boetemplate::chrs2num($c);
|
2007-05-12 12:12:41 +02:00
|
|
|
$col = boetemplate::num2chrs($c-1); // $c-1 to get: 0:'@', 1:'A', ...
|
|
|
|
$col_ = boetemplate::num2chrs($c_-1);
|
2002-10-18 00:10:12 +02:00
|
|
|
$row_cont = $cont[$row];
|
|
|
|
$col_row_cont = $cont[$col.$row];
|
|
|
|
|
|
|
|
eval('$name = "'.$name.'";');
|
2002-10-14 02:39:47 +02:00
|
|
|
}
|
2004-04-05 02:00:40 +02:00
|
|
|
if ($is_index_in_content)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2007-03-07 13:30:17 +01:00
|
|
|
$name = boetemplate::get_array($cont,substr($name,1));
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* Checks if we have an row- or column autorepeat and sets the indexes for $content, etc.
|
|
|
|
*
|
|
|
|
* Autorepeat is important to allow a variable numer of rows or cols, eg. for a list.
|
|
|
|
* The eTemplate has only one (have to be the last) row or column, which gets
|
|
|
|
* automaticaly repeated as long as content is availible. To check this the content
|
|
|
|
* has to be in an sub-array of content. The index / subscript into content is
|
|
|
|
* determined by the content of size for templates or name for regular fields.
|
|
|
|
* An autorepeat is defined by an index which contains variables to expand.
|
|
|
|
* (vor variable expansion in names see expand_names). Usually I use the keys
|
|
|
|
* $row: 0, 1, 2, 3, ... for only rows, $col: '@', 'A', 'B', 'C', ... for only cols or
|
|
|
|
* $col$row: '@0','A0',... '@1','A1','B1',... '@2','A2','B2',... for both rows and cells.
|
|
|
|
* In general everything expand_names can generate is ok - see there.
|
|
|
|
* As you usually have col- and row-headers, data-cells start with '1' or 'A' !!!
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param array $cell with data of cell: name, type, size, ...
|
|
|
|
* @param int $c,$r col/row index starting from 0
|
|
|
|
* @param string &$idx returns the index in $content and $readonlys (NOT $sel_options !!!)
|
|
|
|
* @param string &$idx_cname returns the basename for the form-name: is $idx if only one value
|
|
|
|
* (no ',') is given in size (name (not template-fields) are always only one value)
|
|
|
|
* @param boolean $check_col to check for col- or row-autorepeat
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return boolean true if cell is autorepeat (has index with vars / '$') or false otherwise
|
|
|
|
*/
|
2007-09-06 13:59:35 +02:00
|
|
|
function autorepeat_idx($cell,$c,$r,&$idx,&$idx_cname,$check_col=False,$cont=null)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
$org_idx = $idx = $cell[ $cell['type'] == 'template' ? 'size' : 'name' ];
|
|
|
|
|
2007-09-06 13:59:35 +02:00
|
|
|
$idx = $this->expand_name($idx,$c,$r,'','',$cont);
|
2002-02-06 10:03:11 +01:00
|
|
|
if (!($komma = strpos($idx,',')))
|
|
|
|
{
|
|
|
|
$idx_cname = $idx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$idx_cname = substr($idx,1+$komma);
|
|
|
|
$idx = substr($idx,0,$komma);
|
|
|
|
}
|
|
|
|
$Ok = False;
|
|
|
|
$pat = $org_idx;
|
2007-04-29 22:30:15 +02:00
|
|
|
while (!$Ok && ($pat = @strstr($pat,'$')))
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
|
|
|
$pat = substr($pat,$pat[1] == '{' ? 2 : 1);
|
|
|
|
|
|
|
|
if ($check_col)
|
|
|
|
{
|
|
|
|
$Ok = $pat[0] == 'c' && !(substr($pat,0,4) == 'cont' ||
|
2002-02-14 15:06:53 +01:00
|
|
|
substr($pat,0,2) == 'c_' || substr($pat,0,4) == 'col_');
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-10-12 18:37:44 +02:00
|
|
|
$Ok = $pat[0] == 'r' && !(substr($pat,0,2) == 'r_' ||
|
2007-09-06 13:59:35 +02:00
|
|
|
substr($pat,0,4) == 'row_');
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
2002-02-18 14:50:24 +01:00
|
|
|
if ($this->name && $this->name == $this->debug)
|
2002-02-06 10:03:11 +01:00
|
|
|
{
|
2003-10-26 13:59:01 +01:00
|
|
|
echo "$this->name ".($check_col ? 'col' : 'row')."-check: c=$c, r=$r, idx='$org_idx'='$idx' idx_cname='$idx_cname' ==> ".($Ok?'True':'False')."<p>\n";
|
2002-02-06 10:03:11 +01:00
|
|
|
}
|
|
|
|
return $Ok;
|
|
|
|
}
|
2002-02-17 20:09:15 +01:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* creates a new appsession-id via microtime()
|
|
|
|
*/
|
2002-06-09 23:34:21 +02:00
|
|
|
function appsession_id()
|
|
|
|
{
|
|
|
|
list($msec,$sec) = explode(' ',microtime());
|
2005-02-18 23:44:42 +01:00
|
|
|
$time = 100 * $sec + (int)(100 * $msec); // gives precision of 1/100 sec
|
2005-11-09 21:50:45 +01:00
|
|
|
$id = $GLOBALS['egw_info']['flags']['currentapp'] .':'. $time;
|
2002-06-09 23:34:21 +02:00
|
|
|
//echo "<p>microtime()=".microtime().", sec=$sec, msec=$msec, id=$id</p>\n";
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* saves content,readonlys,template-keys, ... via the appsession function
|
|
|
|
*
|
|
|
|
* As a user may open several windows with the same content/template wie generate a location-id from microtime
|
|
|
|
* which is used as location for appsession to descriminate between the different windows. This location-id
|
|
|
|
* is then saved as a hidden-var in the form. The above mentions session-id has nothing to do / is different
|
|
|
|
* from the session-id which is constant for all windows opened in one session.
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param array $data the data to save
|
|
|
|
* @param string $id the id to use or '' to generate a new id
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return string location-id
|
|
|
|
*/
|
2002-06-09 23:34:21 +02:00
|
|
|
function save_appsession($data,$id='')
|
2002-02-17 20:09:15 +01:00
|
|
|
{
|
2002-06-09 23:34:21 +02:00
|
|
|
if (!$id)
|
|
|
|
{
|
2005-07-30 14:45:54 +02:00
|
|
|
$id = $this->appsession_id();
|
2002-06-09 23:34:21 +02:00
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
$GLOBALS['egw']->session->appsession($id,'etemplate',$data);
|
2002-02-17 20:09:15 +01:00
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
if (substr($GLOBALS['egw_info']['server']['sessions_type'],0,4) == 'php4' && !$this->garbage_collection_done)
|
2005-02-18 23:44:42 +01:00
|
|
|
{
|
|
|
|
return $this->php4_session_garbage_collection();
|
|
|
|
}
|
2002-02-17 20:09:15 +01:00
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* gets content,readonlys,template-keys, ... back from the appsession function
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string $id the location-id
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return array with session-data
|
|
|
|
*/
|
2002-02-17 20:09:15 +01:00
|
|
|
function get_appsession($id)
|
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$data = $GLOBALS['egw']->session->appsession($id,'etemplate');
|
2005-02-18 23:44:42 +01:00
|
|
|
//echo "boetemplate::get_appsession('$id')"; _debug_array($data);
|
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
if (substr($GLOBALS['egw_info']['server']['sessions_type'],0,4) == 'php4')
|
2005-02-18 23:44:42 +01:00
|
|
|
{
|
|
|
|
$this->php4_session_garbage_collection($id);
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* a little bit of garbage collection for php4 sessions (their size is limited by memory_limit)
|
|
|
|
*
|
|
|
|
* With constant eTemplate use it can grow quite big and lead to unusable sessions (php terminates
|
|
|
|
* before any output with "Allowed memory size of ... exhausted").
|
|
|
|
* We delete now sessions once used after 10min and sessions never or multiple used after 60min.
|
|
|
|
*
|
|
|
|
* @param string $id_used id of session just read by get_appsession to increment the usage counter
|
|
|
|
*/
|
|
|
|
function php4_session_garbage_collection($id_used='')
|
|
|
|
{
|
2005-05-21 09:56:02 +02:00
|
|
|
if (!defined('EGW_SESSION_VAR')) return; // for 1.0.0 compatibility
|
|
|
|
|
2005-02-18 23:44:42 +01:00
|
|
|
// now we are on php4 sessions and do a bit of garbage collection
|
2005-03-04 12:33:44 +01:00
|
|
|
$app_sessions =& $_SESSION[EGW_SESSION_VAR]['app_sessions']['etemplate'];
|
2005-02-18 23:44:42 +01:00
|
|
|
$session_used =& $app_sessions['session_used'];
|
|
|
|
|
|
|
|
if ($id_used)
|
|
|
|
{
|
|
|
|
//echo "session_used[$id_used]='".$session_used[$id_used]."'<br/>\n";
|
|
|
|
++$session_used[$id_used]; // count the number of times a session got used
|
|
|
|
}
|
|
|
|
$this->garbage_collection_done = true;
|
2002-02-17 20:09:15 +01:00
|
|
|
|
2005-02-20 22:45:24 +01:00
|
|
|
if (count($app_sessions) < 20) return $data; // we dont need to care
|
2002-02-17 20:09:15 +01:00
|
|
|
|
2005-02-18 23:44:42 +01:00
|
|
|
list($msec,$sec) = explode(' ',microtime());
|
|
|
|
$now = 100 * $sec + (int)(100 * $msec); // gives precision of 1/100 sec
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2005-02-20 22:45:24 +01:00
|
|
|
foreach(array_keys($app_sessions) as $id)
|
2005-02-18 23:44:42 +01:00
|
|
|
{
|
|
|
|
list($app,$time) = explode(':',$id);
|
|
|
|
|
|
|
|
if (!$time) continue; // other data, no session
|
|
|
|
|
2005-02-20 22:45:24 +01:00
|
|
|
//echo ++$n.') '.$id.': '.(($now-$time)/100.0)."secs old, used=".$session_used[$id].", size=".strlen($app_sessions[$id])."<br>\n";
|
2005-02-18 23:44:42 +01:00
|
|
|
|
|
|
|
if ($session_used[$id] == 1 && $time < $now - 10*6000 || // session used and older then 10min
|
|
|
|
$time < $now - 60*6000) // session not used and older then 1h
|
|
|
|
{
|
|
|
|
//echo "<p>boetemplate::php4_session_garbage_collection('$id_used'): unsetting session '$id' (now=$now)</p>\n";
|
|
|
|
unset($app_sessions[$id]);
|
|
|
|
unset($session_used[$id]);
|
|
|
|
}
|
|
|
|
}
|
2002-02-17 20:09:15 +01:00
|
|
|
}
|
2002-05-11 17:16:23 +02:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* gets an attribute in a named cell
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @static
|
|
|
|
* @param string $name cell-name
|
|
|
|
* @param string $attr attribute-name
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return mixed the attribute or False if named cell not found
|
|
|
|
*/
|
2005-02-13 14:03:01 +01:00
|
|
|
function &get_cell_attribute($name,$attr)
|
2002-06-15 14:52:33 +02:00
|
|
|
{
|
2004-04-12 14:29:40 +02:00
|
|
|
return $this->set_cell_attribute($name,$attr,NULL);
|
2002-06-15 14:52:33 +02:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* set an attribute in a named cell if val is not NULL else return the attribute
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @static
|
2005-12-19 05:26:34 +01:00
|
|
|
* @param string $name cell-name
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string $attr attribute-name
|
|
|
|
* @param mixed $val if not NULL sets attribute else returns it
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return mixed number of changed cells or False, if none changed
|
|
|
|
*/
|
2005-02-13 14:03:01 +01:00
|
|
|
function &set_cell_attribute($name,$attr,$val)
|
2002-06-15 14:52:33 +02:00
|
|
|
{
|
2002-09-18 16:15:04 +02:00
|
|
|
//echo "<p>set_cell_attribute(tpl->name=$this->name, name='$name', attr='$attr',val='$val')</p>\n";
|
|
|
|
|
2005-02-13 14:03:01 +01:00
|
|
|
$extra = array(false,$name,$attr,$val);
|
|
|
|
$result =& $this->widget_tree_walk('set_cell_attribute_helper',$extra);
|
|
|
|
|
|
|
|
if (is_null($val))
|
2002-06-15 14:52:33 +02:00
|
|
|
{
|
2005-02-13 14:03:01 +01:00
|
|
|
return $result;
|
2002-05-11 17:16:23 +02:00
|
|
|
}
|
2005-02-13 14:03:01 +01:00
|
|
|
return $extra[0];
|
2002-05-11 17:16:23 +02:00
|
|
|
}
|
2005-02-13 14:03:01 +01:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* disables all cells with name == $name
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param sting $name cell-name
|
2005-04-24 19:13:44 +02:00
|
|
|
* @param boolean $disabled=true disable or enable a cell, default true=disable
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return mixed number of changed cells or False, if none changed
|
|
|
|
*/
|
2005-04-24 19:13:44 +02:00
|
|
|
function disable_cells($name,$disabled=True)
|
2002-06-15 14:52:33 +02:00
|
|
|
{
|
2005-04-24 19:13:44 +02:00
|
|
|
return $this->set_cell_attribute($name,'disabled',$disabled);
|
2002-06-15 14:52:33 +02:00
|
|
|
}
|
2003-04-21 22:29:18 +02:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* set one or more attibutes for row $n
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param int $n numerical row-number starting with 1 (!)
|
|
|
|
* @param string $height percent or pixel or '' for no height
|
|
|
|
* @param string $class name of css class (without the leading '.') or '' for no class
|
|
|
|
* @param string $valign alignment (top,middle,bottom) or '' for none
|
|
|
|
* @param boolean $disabled True or expression or False to disable or enable the row (Only the number 0 means dont change the attribute !!!)
|
2007-03-07 13:30:17 +01:00
|
|
|
* @param string $path='/0' default is the first widget in the tree of children
|
|
|
|
* @return false if $path is no grid or array(height,class,valign,disabled) otherwise
|
2004-10-07 23:53:10 +02:00
|
|
|
*/
|
2007-03-07 13:30:17 +01:00
|
|
|
function set_row_attributes($n,$height=0,$class=0,$valign=0,$disabled=0,$path='/0')
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
2007-03-07 13:30:17 +01:00
|
|
|
$grid =& $this->get_widget_by_path($path);
|
|
|
|
if (is_null($grid) || $grid['type'] != 'grid') return false;
|
|
|
|
$grid_attr =& $grid['data'][0];
|
|
|
|
|
|
|
|
list($old_height,$old_disabled) = explode(',',$grid_attr["h$n"]);
|
2003-08-28 16:31:11 +02:00
|
|
|
$disabled = $disabled !== 0 ? $disabled : $old_disabled;
|
2007-03-07 13:30:17 +01:00
|
|
|
$grid_attr["h$n"] = ($height !== 0 ? $height : $old_height).
|
2003-08-28 16:31:11 +02:00
|
|
|
($disabled ? ','.$disabled : '');
|
2007-03-07 13:30:17 +01:00
|
|
|
list($old_class,$old_valign) = explode(',',$grid_attr["c$n"]);
|
2003-08-28 16:31:11 +02:00
|
|
|
$valign = $valign !== 0 ? $valign : $old_valign;
|
2007-03-07 13:30:17 +01:00
|
|
|
$grid_attr["c$n"] = ($class !== 0 ? $class : $old_class).
|
2003-08-28 16:31:11 +02:00
|
|
|
($valign ? ','.$valign : '');
|
2007-03-07 13:30:17 +01:00
|
|
|
|
|
|
|
list($height,$disabled) = explode(',',$grid_attr["h$n"]);
|
|
|
|
list($class,$valign) = explode(',',$grid_attr["c$n"]);
|
|
|
|
return array($height,$class,$valign,$disabled);
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* disables row $n
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param int $n numerical row-number starting with 1 (!)
|
|
|
|
* @param boolean $enable=false can be used to re-enable a row if set to True
|
2007-03-07 13:30:17 +01:00
|
|
|
* @param string $path='/0' default is the first widget in the tree of children
|
2004-10-07 23:53:10 +02:00
|
|
|
*/
|
2007-03-07 13:30:17 +01:00
|
|
|
function disable_row($n,$enable=False,$path='/0')
|
2003-04-21 22:29:18 +02:00
|
|
|
{
|
2007-03-07 13:30:17 +01:00
|
|
|
$this->set_row_attributes($n,0,0,0,!$enable,$path);
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* set one or more attibutes for column $c
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param int/string $c numerical column-number starting with 0 (!), or the char-code starting with 'A'
|
|
|
|
* @param string $width percent or pixel or '' for no height
|
|
|
|
* @param mixed $disabled=0 True or expression or False to disable or enable the column (Only the number 0 means dont change the attribute !!!)
|
2007-03-07 13:30:17 +01:00
|
|
|
* @param string $path='/0' default is the first widget in the tree of children
|
|
|
|
* @return false if $path specifies no grid or array(width,disabled) otherwise
|
2004-10-07 23:53:10 +02:00
|
|
|
*/
|
2007-03-07 13:30:17 +01:00
|
|
|
function set_column_attributes($c,$width=0,$disabled=0,$path='/0')
|
2003-08-28 16:31:11 +02:00
|
|
|
{
|
|
|
|
if (is_numeric($c))
|
|
|
|
{
|
|
|
|
$c = $this->num2chrs($c);
|
|
|
|
}
|
2007-03-07 13:30:17 +01:00
|
|
|
$grid =& $this->get_widget_by_path($path);
|
|
|
|
if (is_null($grid) || $grid['type'] != 'grid') return false;
|
|
|
|
$grid_attr =& $grid['data'][0];
|
|
|
|
|
|
|
|
list($old_width,$old_disabled) = explode(',',$grid_attr[$c]);
|
2003-08-28 16:31:11 +02:00
|
|
|
$disabled = $disabled !== 0 ? $disabled : $old_disabled;
|
2007-03-07 13:30:17 +01:00
|
|
|
$grid_attr[$c] = ($width !== 0 ? $width : $old_width).
|
2003-08-28 16:31:11 +02:00
|
|
|
($disabled ? ','.$disabled : '');
|
2007-03-07 13:30:17 +01:00
|
|
|
|
|
|
|
//echo "set_column_attributes('$c',,'$path'): ".$grid_attr[$c]."</p>\n"; _debug_array($grid_attr);
|
|
|
|
return explode(',',$grid_attr[$c]);
|
2003-04-21 22:29:18 +02:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* disables column $c
|
2005-02-13 14:03:01 +01:00
|
|
|
*
|
|
|
|
* @param int/string $c numerical column-number starting with 0 (!), or the char-code starting with 'A'
|
|
|
|
* @param boolean $enable can be used to re-enable a column if set to True
|
2007-03-07 13:30:17 +01:00
|
|
|
* @param string $path='/0' default is the first widget in the tree of children
|
|
|
|
*/
|
|
|
|
function disable_column($c,$enable=False,$path='/0')
|
2003-04-21 22:29:18 +02:00
|
|
|
{
|
2007-03-07 13:30:17 +01:00
|
|
|
$this->set_column_attributes($c,0,!$enable,$path);
|
2003-04-21 22:29:18 +02:00
|
|
|
}
|
2002-06-15 14:52:33 +02:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* trys to load the Extension / Widget-class from the app or etemplate
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string $name name of the extension, the classname should be class.${name}_widget.inc.php
|
2004-10-07 23:53:10 +02:00
|
|
|
* the $name might be "$name.$app" to give a app-name (default is the current app,or template-name)
|
|
|
|
* @return string/boolean human readable name or false if not found/loadable
|
|
|
|
*/
|
2002-09-27 18:17:39 +02:00
|
|
|
function loadExtension($type)
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
2002-09-27 18:17:39 +02:00
|
|
|
list($class,$app) = explode('.',$type);
|
2002-05-13 23:30:46 +02:00
|
|
|
$class .= '_widget';
|
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
if (!$app) $app = $GLOBALS['egw_info']['flags']['current_app'];
|
2005-06-12 14:32:59 +02:00
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
if (!file_exists(EGW_SERVER_ROOT."/$app/inc/class.$class.inc.php"))
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
2005-06-12 14:32:59 +02:00
|
|
|
list($app) = explode('_',$type);
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
if (!file_exists(EGW_SERVER_ROOT."/$app/inc/class.$class.inc.php"))
|
2002-09-02 19:09:49 +02:00
|
|
|
{
|
|
|
|
list($app) = explode('.',$this->name);
|
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
if (!file_exists(EGW_SERVER_ROOT."/$app/inc/class.$class.inc.php"))
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
|
|
|
$app = 'etemplate';
|
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
if (!file_exists(EGW_SERVER_ROOT."/$app/inc/class.$class.inc.php"))
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
2005-06-12 14:32:59 +02:00
|
|
|
//echo "<p>boetemplate::loadExtension($type) extension not found</p>\n";
|
2005-11-09 21:50:45 +01:00
|
|
|
return $GLOBALS['egw_info']['etemplate']['extension'][$type] = False;
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
$GLOBALS['egw_info']['etemplate']['extension'][$type] =& CreateObject($app.'.'.$class,$ui='html');
|
2002-05-13 23:30:46 +02:00
|
|
|
|
2005-06-12 14:32:59 +02:00
|
|
|
//echo "<p>boetemplate::loadExtension($type) extension found in App. $app</p>\n";
|
2005-11-09 21:50:45 +01:00
|
|
|
return $GLOBALS['egw_info']['etemplate']['extension'][$type]->human_name;
|
2002-09-27 18:17:39 +02:00
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:01 +01:00
|
|
|
/**
|
|
|
|
* checks if extension is loaded (load it if it isnt) and optional checks if it has a given method
|
2004-10-07 23:53:10 +02:00
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string $name name of the extension, the classname should be class.${name}_widget.inc.php
|
|
|
|
* the $name might be "$name.$app" to give a app-name (default is the current app,or template-name)
|
|
|
|
* @param string $function 'pre_process', 'post_process' or 'render'
|
|
|
|
* @return boolean true if the extension (incl. method) exists, else false
|
2004-10-07 23:53:10 +02:00
|
|
|
*/
|
2005-02-13 14:03:01 +01:00
|
|
|
function haveExtension($type,$function='')
|
2002-09-27 18:17:39 +02:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
return ($GLOBALS['egw_info']['etemplate']['extension'][$type] || $this->loadExtension($type,$ui)) &&
|
|
|
|
($function == '' || $GLOBALS['egw_info']['etemplate']['extension'][$type]->public_functions[$function]);
|
2002-09-27 18:17:39 +02:00
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:01 +01:00
|
|
|
/**
|
|
|
|
* executes the pre_process-function of the extension $cell[type]
|
2004-10-07 23:53:10 +02:00
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string $type type of the extension
|
|
|
|
* @param string $name form-name of this widget/field (used as a unique index into extension_data)
|
|
|
|
* @param mixed &$value value of the extensions content(-array)
|
|
|
|
* @param array &$cell table-cell on which the extension operates
|
|
|
|
* @param array &$readonlys value of the extensions readonly-setting(-array)
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return mixed the return-value of the extensions preprocess function
|
|
|
|
*/
|
2005-02-13 14:03:01 +01:00
|
|
|
function extensionPreProcess($type,$name,&$value,&$cell,&$readonlys)
|
2002-09-27 18:17:39 +02:00
|
|
|
{
|
2002-10-01 20:26:30 +02:00
|
|
|
if (!$this->haveExtension($type))
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
2002-09-27 18:17:39 +02:00
|
|
|
return False;
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
return $GLOBALS['egw_info']['etemplate']['extension'][$type]->pre_process($name,$value,$cell,$readonlys,
|
|
|
|
$GLOBALS['egw_info']['etemplate']['extension_data'][$name],$this);
|
2002-09-27 18:17:39 +02:00
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:01 +01:00
|
|
|
/**
|
2004-10-07 23:53:10 +02:00
|
|
|
* executes the post_process-function of the extension $cell[type]
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string $type name of the extension
|
|
|
|
* @param string $name form-name of this widget/field (used as a unique index into extension_data)
|
|
|
|
* @param mixed &$value returns the value of the extensions content(-array)
|
|
|
|
* @param mixed $value_in unprocessed value, eg. as posted by the browser
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return boolean True if a value should be returned (default for no postprocess fkt.), else False
|
|
|
|
*/
|
2005-02-13 14:03:01 +01:00
|
|
|
function extensionPostProcess($type,$name,&$value,$value_in)
|
2002-09-27 18:17:39 +02:00
|
|
|
{
|
2002-10-01 20:26:30 +02:00
|
|
|
if (!$this->haveExtension($type,'post_process'))
|
2002-09-27 18:17:39 +02:00
|
|
|
{
|
2003-12-09 01:03:41 +01:00
|
|
|
return True;
|
2002-09-27 18:17:39 +02:00
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
return $GLOBALS['egw_info']['etemplate']['extension'][$type]->post_process($name,$value,
|
|
|
|
$GLOBALS['egw_info']['etemplate']['extension_data'][$name],
|
|
|
|
$GLOBALS['egw_info']['etemplate']['loop'],$this,$value_in);
|
2002-09-27 18:17:39 +02:00
|
|
|
}
|
|
|
|
|
2005-02-13 14:03:01 +01:00
|
|
|
/**
|
2004-10-07 23:53:10 +02:00
|
|
|
* executes the render-function of the extension $cell[type]
|
2005-02-13 14:03:01 +01:00
|
|
|
*
|
|
|
|
* @param string $type name of the extension
|
|
|
|
* @param string $name form-name of this widget/field (used as a unique index into extension_data)
|
|
|
|
* @param mixed &$value value of the extensions content(-array)
|
|
|
|
* @param array &$cell table-cell on which the extension operates
|
|
|
|
* @param array &$readonlys value of the extensions readonly-setting(-array)
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return mixed return-value of the render function
|
|
|
|
*/
|
2005-02-13 14:03:01 +01:00
|
|
|
function extensionRender($type,$name,&$value,&$cell,$readonly)
|
2002-09-27 18:17:39 +02:00
|
|
|
{
|
2002-10-01 20:26:30 +02:00
|
|
|
if (!$this->haveExtension($type,'render'))
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
2002-09-27 18:17:39 +02:00
|
|
|
return False;
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
return $GLOBALS['egw_info']['etemplate']['extension'][$type]->render($cell,$name,$value,$readonly,
|
|
|
|
$GLOBALS['egw_info']['etemplate']['extension_data'][$name],$this);
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
2002-06-02 23:10:24 +02:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* checks if $idx is set in array $arr
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* for one level of subindes identical to isset($arr[$idx])
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param array $arr array to check
|
|
|
|
* @param string $idx may contain multiple subindex (eg.'x[y][z]')
|
|
|
|
* @return boolean true if set, else false
|
2004-10-07 23:53:10 +02:00
|
|
|
*/
|
2002-06-15 11:21:55 +02:00
|
|
|
function isset_array($arr,$idx)
|
2002-06-02 23:10:24 +02:00
|
|
|
{
|
2003-10-26 13:59:01 +01:00
|
|
|
$idxs = explode('[',str_replace(']','',$idx));
|
|
|
|
$last_idx = array_pop($idxs);
|
|
|
|
$pos = &$arr;
|
|
|
|
foreach($idxs as $idx)
|
2002-06-02 23:10:24 +02:00
|
|
|
{
|
2003-10-26 13:59:01 +01:00
|
|
|
if (!is_array($pos))
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$pos = &$pos[$idx];
|
2002-06-02 23:10:24 +02:00
|
|
|
}
|
2007-01-08 16:57:09 +01:00
|
|
|
// was return isset($pos[$last_idx]);
|
|
|
|
// array_key_exists also returns true for keys with value null, which fixes some problems with autorepeating rows
|
|
|
|
return is_array($pos) && array_key_exists($last_idx,$pos);
|
2002-06-02 23:10:24 +02:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* sets $arr[$idx] = $val
|
|
|
|
*
|
|
|
|
* This works for non-trival indexes like 'a[b][c]' too: $arr['a']['b']['c'] = $val;
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @static
|
|
|
|
* @param array &$arr the array to search
|
|
|
|
* @param string $idx the index, may contain sub-indices like a[b], see example below
|
|
|
|
* @param mixed $val value to set
|
2004-10-07 23:53:10 +02:00
|
|
|
*/
|
2002-10-04 01:47:14 +02:00
|
|
|
function set_array(&$arr,$idx,$val)
|
2002-06-02 23:10:24 +02:00
|
|
|
{
|
2002-10-04 01:47:14 +02:00
|
|
|
if (!is_array($arr))
|
2002-06-02 23:10:24 +02:00
|
|
|
{
|
2004-10-07 23:53:10 +02:00
|
|
|
die('set_array() $arr is no array<br>'.function_backtrace());
|
2002-06-02 23:10:24 +02:00
|
|
|
}
|
2002-10-04 01:47:14 +02:00
|
|
|
$idxs = explode('[',str_replace(']','',$idx));
|
|
|
|
$pos = &$arr;
|
2003-10-26 13:59:01 +01:00
|
|
|
foreach($idxs as $idx)
|
2002-06-02 23:10:24 +02:00
|
|
|
{
|
2002-10-04 01:47:14 +02:00
|
|
|
$pos = &$pos[$idx];
|
2002-06-02 23:10:24 +02:00
|
|
|
}
|
2002-10-04 01:47:14 +02:00
|
|
|
$pos = $val;
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* return a reference to $arr[$idx]
|
|
|
|
*
|
|
|
|
* This works for non-trival indexes like 'a[b][c]' too: it returns &$arr[a][b][c]
|
|
|
|
* $sub = get_array($arr,'a[b]'); $sub = 'c'; is equivalent to $arr['a']['b'] = 'c';
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @static
|
|
|
|
* @param array $arr the array to search, referenz as a referenz gets returned
|
|
|
|
* @param string $idx the index, may contain sub-indices like a[b], see example below
|
|
|
|
* @param boolean $reference_into default False, if True none-existing sub-arrays/-indices get created to be returned as referenz, else False is returned
|
2006-10-10 20:03:27 +02:00
|
|
|
* @param bool $skip_empty returns false if $idx is not present in $arr
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return mixed reference to $arr[$idx] or false if $idx is not set and not $reference_into
|
|
|
|
*/
|
2006-10-10 20:03:27 +02:00
|
|
|
function &get_array(&$arr,$idx,$reference_into=False,$skip_empty=False)
|
2002-10-04 01:47:14 +02:00
|
|
|
{
|
|
|
|
if (!is_array($arr))
|
2002-06-02 23:10:24 +02:00
|
|
|
{
|
2004-10-07 23:53:10 +02:00
|
|
|
die('set_array() $arr is no array<br>'.function_backtrace());
|
2002-06-02 23:10:24 +02:00
|
|
|
}
|
2006-11-07 15:22:49 +01:00
|
|
|
if (is_object($idx)) return false; // given an error in php5.2
|
|
|
|
|
2002-10-04 01:47:14 +02:00
|
|
|
$idxs = explode('[',str_replace(']','',$idx));
|
|
|
|
$pos = &$arr;
|
2003-10-26 13:59:01 +01:00
|
|
|
foreach($idxs as $idx)
|
2002-06-02 23:10:24 +02:00
|
|
|
{
|
2003-12-10 02:21:31 +01:00
|
|
|
if (!is_array($pos) && !$referenz_info)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2006-10-10 20:03:27 +02:00
|
|
|
if($skip_empty && !isset($pos[$idx])) return false;
|
2002-10-04 01:47:14 +02:00
|
|
|
$pos = &$pos[$idx];
|
2002-06-02 23:10:24 +02:00
|
|
|
}
|
2002-10-04 01:47:14 +02:00
|
|
|
return $pos;
|
2002-10-01 20:26:30 +02:00
|
|
|
}
|
2006-10-10 17:10:07 +02:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* unsets $arr[$idx]
|
|
|
|
*
|
|
|
|
* This works for non-trival indexes like 'a[b][c]' too
|
|
|
|
* unset_array($arr,'a[b]'); is equivalent to unset($arr['a']['b']);
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @static
|
|
|
|
* @param array $arr the array to search, referenz as a referenz gets returned
|
|
|
|
* @param string $idx the index, may contain sub-indices like a[b], see example below
|
2004-10-07 23:53:10 +02:00
|
|
|
*/
|
2002-10-01 20:26:30 +02:00
|
|
|
function unset_array(&$arr,$idx)
|
|
|
|
{
|
2002-10-04 01:47:14 +02:00
|
|
|
if (!is_array($arr))
|
2002-06-02 23:10:24 +02:00
|
|
|
{
|
2004-10-07 23:53:10 +02:00
|
|
|
die('set_array() $arr is no array<br>'.function_backtrace());
|
2002-06-02 23:10:24 +02:00
|
|
|
}
|
2002-10-04 01:47:14 +02:00
|
|
|
$idxs = explode('[',str_replace(']','',$idx));
|
2003-10-26 13:59:01 +01:00
|
|
|
$last_idx = array_pop($idxs);
|
2002-10-04 01:47:14 +02:00
|
|
|
$pos = &$arr;
|
2003-10-26 13:59:01 +01:00
|
|
|
foreach($idxs as $idx)
|
2002-06-02 23:10:24 +02:00
|
|
|
{
|
2002-10-04 01:47:14 +02:00
|
|
|
$pos = &$pos[$idx];
|
2002-06-02 23:10:24 +02:00
|
|
|
}
|
2003-10-26 13:59:01 +01:00
|
|
|
unset($pos[$last_idx]);
|
2002-06-02 23:10:24 +02:00
|
|
|
}
|
2002-06-09 23:34:21 +02:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* merges $old and $new, content of $new has precedence over $old
|
|
|
|
*
|
|
|
|
* THIS IS NOT THE SAME AS PHP4's functions:
|
|
|
|
* - array_merge, as it calls itself recursive for values which are arrays.
|
|
|
|
* - array_merge_recursive accumulates values with the same index and $new does NOT overwrite $old
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @static
|
|
|
|
* @param array $old
|
|
|
|
* @param array $new
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return array the merged array
|
|
|
|
*/
|
2002-06-09 23:34:21 +02:00
|
|
|
function complete_array_merge($old,$new)
|
|
|
|
{
|
2004-10-07 23:53:10 +02:00
|
|
|
if (is_array($new))
|
2002-06-09 23:34:21 +02:00
|
|
|
{
|
2005-08-02 10:52:47 +02:00
|
|
|
if (!is_array($old)) $old = (array) $old;
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
foreach($new as $k => $v)
|
2002-06-09 23:34:21 +02:00
|
|
|
{
|
2007-05-08 11:00:22 +02:00
|
|
|
if (!is_array($v) || !isset($old[$k]) || // no array or a new array
|
|
|
|
isset($v[0]) && isset($v[count($v)-1])) // or no associative array, eg. selecting multiple accounts
|
2004-10-07 23:53:10 +02:00
|
|
|
{
|
|
|
|
$old[$k] = $v;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$old[$k] = $this->complete_array_merge($old[$k],$v);
|
|
|
|
}
|
2002-06-09 23:34:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $old;
|
|
|
|
}
|
2005-02-16 00:22:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* returns a reference to a widget in the widget's children tree spezified by a path
|
|
|
|
*
|
|
|
|
* The path get's generated by the widget_tree_walk() methode and consists of the keys of the children arrays.
|
|
|
|
* For the 3. Column in the 2. row of a grid which is the only widget in the children-tree it is eg.: "/0/2C"
|
|
|
|
*
|
|
|
|
* @param string $path path in the widget tree
|
|
|
|
* @param int $ancestor=0 0: widget itself, 1: parent, 2: grand-parent, ...
|
|
|
|
* @return array referenz to the widget spezified or null, if it's not found
|
|
|
|
*/
|
|
|
|
function &get_widget_by_path($path,$ancestor=0)
|
|
|
|
{
|
|
|
|
//echo "<p>boetemplate::get_widget_by_path('$path',$ancestor)</p>\n";
|
|
|
|
$path_parts = explode('/',$path);
|
|
|
|
while($ancestor-- > 0)
|
|
|
|
{
|
|
|
|
if (array_pop($path_parts) === '') return null;
|
|
|
|
}
|
|
|
|
$path = implode('/',$path_parts);
|
|
|
|
if ($path == '/' || $path === '') return $this->children;
|
2007-03-07 13:30:17 +01:00
|
|
|
if (count($path_parts) == 2) return $this->children[$path_parts[1]];
|
2002-09-22 10:05:17 +02:00
|
|
|
|
2005-02-16 00:22:10 +01:00
|
|
|
return $this->widget_tree_walk('get_widget_by_path_helper',$path);
|
|
|
|
}
|
2002-09-24 12:00:58 +02:00
|
|
|
|
2005-11-05 17:09:10 +01:00
|
|
|
/**
|
|
|
|
* returns a reference to a widget in the widget's children tree spezified it's name
|
|
|
|
*
|
|
|
|
* It returns the first match!
|
|
|
|
*
|
|
|
|
* @param string $name name of the widget
|
|
|
|
* @return array referenz to the widget spezified or null, if it's not found
|
|
|
|
*/
|
|
|
|
function &get_widget_by_name($name)
|
|
|
|
{
|
|
|
|
return $this->widget_tree_walk('get_widget_by_name_helper',$name);
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* generated a file-name from an eTemplates, name, template(-set) and lang
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string/array $name name of template or array('name'=>$name,'template'=>$template,'lang'=>$lang)
|
|
|
|
* @param string $template template-set
|
|
|
|
* @param string $lang language to use
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2002-09-24 12:00:58 +02:00
|
|
|
function cache_name($name='',$template='default',$lang='default')
|
|
|
|
{
|
|
|
|
if (empty($name))
|
|
|
|
{
|
|
|
|
$name = $this->name;
|
|
|
|
$template = $this->template;
|
|
|
|
$lang = $this->lang;
|
|
|
|
}
|
|
|
|
elseif (is_array($name))
|
|
|
|
{
|
|
|
|
$template = $name['template'];
|
|
|
|
$lang = $name['lang'];
|
|
|
|
$name = $name['name'];
|
|
|
|
}
|
|
|
|
if (empty($template))
|
|
|
|
{
|
|
|
|
$template = 'default';
|
|
|
|
}
|
|
|
|
$cname = $template . '/' . $name . (!empty($lang) && $lang != 'default' ? '.' . $lang : '');
|
|
|
|
//echo "cache_name('$name','$template','$lang') = '$cname'";
|
|
|
|
|
|
|
|
return $cname;
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
2005-02-13 14:03:01 +01:00
|
|
|
* stores the etemplate in the cache in phpgw_info
|
2004-10-07 23:53:10 +02:00
|
|
|
*/
|
2002-09-24 12:00:58 +02:00
|
|
|
function store_in_cache()
|
2002-09-22 10:05:17 +02:00
|
|
|
{
|
2002-09-24 12:00:58 +02:00
|
|
|
//echo "<p>store_in_cache('$this->name','$this->template','$this->lang','$this->version')</p>\n";
|
2005-11-09 21:50:45 +01:00
|
|
|
$GLOBALS['egw_info']['etemplate']['cache'][$this->cache_name()] = $this->as_array(1);
|
2002-09-24 12:00:58 +02:00
|
|
|
}
|
|
|
|
|
2005-02-18 23:44:42 +01:00
|
|
|
/**
|
|
|
|
* deletes the etemplate in the cache in phpgw_info
|
|
|
|
*/
|
|
|
|
function delete_in_cache()
|
|
|
|
{
|
|
|
|
//echo "<p>delete_in_cache('$this->name','$this->template','$this->lang','$this->version')</p>\n";
|
2005-11-09 21:50:45 +01:00
|
|
|
unset($GLOBALS['egw_info']['etemplate']['cache'][$this->cache_name()]);
|
2005-02-18 23:44:42 +01:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/*
|
|
|
|
* returns true if a given eTemplate is in the cache
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string/array $name name of template or array('name'=>$name,'template'=>$template,'lang'=>$lang)
|
|
|
|
* @param string $template template-set
|
|
|
|
* @param string $lang language to use
|
|
|
|
* @param int $group to use the template for
|
|
|
|
* @param string $version of the template
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2002-09-24 12:00:58 +02:00
|
|
|
function in_cache($name,$template='default',$lang='default',$group=0,$version='')
|
|
|
|
{
|
|
|
|
$cname = $this->cache_name($name,$template,$lang);
|
|
|
|
if (is_array($name))
|
|
|
|
{
|
|
|
|
$version = $name['version'];
|
|
|
|
$name = $name['name'];
|
|
|
|
}
|
2005-11-09 21:50:45 +01:00
|
|
|
if (!isset($GLOBALS['egw_info']['etemplate']['cache'][$cname]) ||
|
|
|
|
!empty($version) && $GLOBALS['egw_info']['etemplate']['cache'][$cname]['version'] != $version)
|
2002-09-24 12:00:58 +02:00
|
|
|
{
|
|
|
|
//echo " NOT found in cache</p>\n";
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
//echo " found in cache</p>\n";
|
|
|
|
return $cname;
|
|
|
|
}
|
2002-09-22 10:05:17 +02:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/*
|
|
|
|
* reads the content of an eTemplate from the cache into the current object
|
|
|
|
*
|
|
|
|
* same as read but only via the cache
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string/array $name name of template or array('name'=>$name,'template'=>$template,'lang'=>$lang)
|
|
|
|
* @param string $template template-set
|
|
|
|
* @param string $lang language to use
|
|
|
|
* @param int $group to use the template for
|
|
|
|
* @param string $version of the template
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return boolean true if the eTemplate was found in the cache
|
|
|
|
*/
|
2002-09-24 12:00:58 +02:00
|
|
|
function read_from_cache($name,$template='default',$lang='default',$group=0,$version='')
|
|
|
|
{
|
|
|
|
//if (is_array($name)) $version = $name['version']; echo "<p>read_from_cache(,,,version='$version'): ";
|
|
|
|
if ($cname = $this->in_cache($name,$template,$lang,$group))
|
2002-09-22 10:05:17 +02:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$this->init($GLOBALS['egw_info']['etemplate']['cache'][$cname]);
|
2002-09-25 18:36:07 +02:00
|
|
|
|
2002-09-22 10:05:17 +02:00
|
|
|
return True;
|
|
|
|
}
|
2002-09-24 12:00:58 +02:00
|
|
|
return False;
|
|
|
|
}
|
2002-09-22 10:05:17 +02:00
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* reads an eTemplate from the cache or database / filesystem (and updates the cache)
|
|
|
|
*
|
|
|
|
* reimplementation of soetemplate::read to use and/or update the cache
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string $name name of the eTemplate or array with the values for all keys
|
|
|
|
* @param string $template template-set, '' loads the prefered template of the user, 'default' loads the default one '' in the db
|
|
|
|
* @param string $lang language, '' loads the pref. lang of the user, 'default' loads the default one '' in the db
|
|
|
|
* @param int $group id of the (primary) group of the user or 0 for none, not used at the moment !!!
|
|
|
|
* @param string $version version of the eTemplate
|
|
|
|
* @param mixed $load_via name/array of keys of etemplate to load in order to get $name (only as second try!)
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return boolean True if a fitting template is found, else False
|
|
|
|
*/
|
2002-09-25 18:36:07 +02:00
|
|
|
function read($name,$template='default',$lang='default',$group=0,$version='',$load_via='')
|
2002-09-24 12:00:58 +02:00
|
|
|
{
|
2002-10-14 02:39:47 +02:00
|
|
|
if (is_array($name)) {
|
|
|
|
$pname = &$name['name'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$pname = &$name;
|
|
|
|
}
|
|
|
|
if (empty($pname))
|
2002-09-29 18:12:52 +02:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2002-10-14 02:39:47 +02:00
|
|
|
$parent = is_array($load_via) ? $load_via['name'] : $load_via;
|
2004-10-07 23:53:10 +02:00
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
if (strstr($pname,'.') === False && !empty($parent))
|
2002-10-14 02:39:47 +02:00
|
|
|
{
|
|
|
|
$pname = $parent . '.' . $pname;
|
|
|
|
}
|
2002-09-24 12:00:58 +02:00
|
|
|
if (!$this->read_from_cache($name,$template,$lang,$group,$version))
|
|
|
|
{
|
|
|
|
if (!soetemplate::read($name,$template,$lang,$group,$version))
|
|
|
|
{
|
2002-09-25 18:36:07 +02:00
|
|
|
if ($load_via && (is_string($load_via) ||
|
2005-11-09 21:50:45 +01:00
|
|
|
!isset($load_via['tpls_in_file']) || $load_via['tpls_in_file'] > 1))
|
2002-09-25 18:36:07 +02:00
|
|
|
{
|
|
|
|
soetemplate::read($load_via);
|
|
|
|
return $this->read_from_cache($name,$template,$lang,$group,$version);
|
|
|
|
}
|
2002-09-24 12:00:58 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$this->store_in_cache();
|
|
|
|
}
|
|
|
|
return True;
|
2002-09-22 10:05:17 +02:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
/**
|
|
|
|
* saves eTemplate-object to db and update the cache
|
|
|
|
*
|
|
|
|
* reimplementation of soetemplate::save to update the cache
|
|
|
|
*
|
2005-02-13 14:03:01 +01:00
|
|
|
* @param string $name name of the eTemplate or array with the values for all keys
|
|
|
|
* @param string $template template-set or '' for the default one
|
|
|
|
* @param string $lang language or '' for the default one
|
|
|
|
* @param int $group id of the (primary) group of the user or 0 for none, not used at the moment !!!
|
|
|
|
* @param string $version version of the eTemplate
|
2004-10-07 23:53:10 +02:00
|
|
|
* @return the number of affected rows, 1 should be ok, 0 somethings wrong
|
|
|
|
*/
|
|
|
|
function save($name='',$template='.',$lang='.',$group=0,$version='.')
|
2002-09-22 10:05:17 +02:00
|
|
|
{
|
2002-09-24 12:00:58 +02:00
|
|
|
if ($result = soetemplate::save($name,$template,$lang,$group,$version))
|
2002-09-22 10:05:17 +02:00
|
|
|
{
|
2002-09-24 12:00:58 +02:00
|
|
|
$this->store_in_cache();
|
2002-09-22 10:05:17 +02:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2005-02-18 23:44:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes the eTemplate from the db, object itself is unchanged
|
|
|
|
*
|
|
|
|
* reimplementation of soetemplate::delete to update the cache
|
|
|
|
*
|
|
|
|
* @return int number of affected rows, 1 should be ok, 0 somethings wrong
|
|
|
|
*/
|
|
|
|
function delete()
|
|
|
|
{
|
|
|
|
$this->delete_in_cache();
|
|
|
|
|
|
|
|
return soetemplate::delete();
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:53:10 +02:00
|
|
|
}
|
2005-02-13 14:03:01 +01:00
|
|
|
|
|
|
|
if (!function_exists('set_cell_attribute_helper'))
|
|
|
|
{
|
|
|
|
function &set_cell_attribute_helper(&$widget,&$extra)
|
|
|
|
{
|
|
|
|
// extra = array(0=>n,1=>name,2=>attr,3=>value)
|
|
|
|
if ($widget['name'] == $extra[1])
|
|
|
|
{
|
|
|
|
if (is_null($extra[3]))
|
|
|
|
{
|
|
|
|
$extra['__RETURN_NOW__'] = true; // wouldnt work otherwise, if attr is not yet set == null
|
|
|
|
return $widget[$extra[2]];
|
|
|
|
}
|
|
|
|
$widget[$extra[2]] = $extra[3];
|
|
|
|
++$extra[0];
|
|
|
|
}
|
|
|
|
}
|
2005-02-16 00:22:10 +01:00
|
|
|
|
2005-11-05 17:09:10 +01:00
|
|
|
function &get_widget_by_name_helper(&$widget,$extra)
|
|
|
|
{
|
|
|
|
if ($widget['name'] == $extra) return $widget;
|
|
|
|
}
|
|
|
|
|
2005-02-16 00:22:10 +01:00
|
|
|
function &get_widget_by_path_helper(&$widget,$extra,$path)
|
|
|
|
{
|
|
|
|
//echo "<p>path_searched='$extra', widget-path($widget[type]:$widget[name])='$path'</p>\n";
|
|
|
|
if ($path == $extra) return $widget;
|
|
|
|
}
|
2005-02-13 14:03:01 +01:00
|
|
|
}
|