merged bugfixes from trunk, for details see the changelog/commit-messages there

This commit is contained in:
Ralf Becker 2007-07-05 05:01:44 +00:00
commit f1b2d5dc1b
5 changed files with 181 additions and 27 deletions

View File

@ -83,7 +83,7 @@ class etemplate_request
*/
static function read($id)
{
if (!($data = $GLOBALS['egw']->session->request($id,'etemplate')))
if (!($data = $GLOBALS['egw']->session->appsession($id,'etemplate')))
{
return false; // request not found
}
@ -184,7 +184,7 @@ class etemplate_request
}
/**
* saves content,readonlys,template-keys, ... via eGW's app_session function
* saves content,readonlys,template-keys, ... via eGW's 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 request to descriminate between the different windows. This location-id
@ -193,11 +193,11 @@ class etemplate_request
*/
function __destruct()
{
if ($this->data_modified) $GLOBALS['egw']->session->app_session($this->id,'etemplate',$this->data);
if ($this->data_modified) $GLOBALS['egw']->session->appsession($this->id,'etemplate',$this->data);
if (substr($GLOBALS['egw_info']['server']['sessions_type'],0,4) == 'php4' && !$this->garbage_collection_done)
{
$this->php4_request_garbage_collection();
$this->_php4_request_garbage_collection();
}
}
@ -211,8 +211,8 @@ class etemplate_request
private function _php4_request_garbage_collection()
{
// now we are on php4 sessions and do a bit of garbage collection
$app_sessions =& $_SESSION[EGW_SESSION_VAR]['app_sessions']['etemplate'];
$session_used =& $app_sessions['session_used'];
$appsessions =& $_SESSION[EGW_SESSION_VAR]['appsessions']['etemplate'];
$session_used =& $appsessions['session_used'];
if ($this->id)
{
@ -221,24 +221,24 @@ class etemplate_request
}
$this->garbage_collection_done = true;
if (count($app_sessions) < 20) return; // we dont need to care
if (count($appsessions) < 20) return; // we dont need to care
list($msec,$sec) = explode(' ',microtime());
$now = 100 * $sec + (int)(100 * $msec); // gives precision of 1/100 sec
foreach(array_keys($app_sessions) as $id)
foreach(array_keys($appsessions) as $id)
{
list(,$time) = explode(':',$id);
if (!$time) continue; // other data, no session
//echo ++$n.') '.$id.': '.(($now-$time)/100.0)."secs old, used=".$session_used[$id].", size=".strlen($app_sessions[$id])."<br>\n";
//echo ++$n.') '.$id.': '.(($now-$time)/100.0)."secs old, used=".$session_used[$id].", size=".strlen($appsessions[$id])."<br>\n";
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($appsessions[$id]);
unset($session_used[$id]);
}
}

View File

@ -41,10 +41,6 @@ class historylog_widget
// 'historylog-helper' => '',
);
function customfields_widget($ui)
{
}
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
{
$status_widgets =& $GLOBALS['egw_info']['flags']['etemplate']['historylog-helper'];

View File

@ -201,14 +201,14 @@ class so_sql
}
foreach($this->db_cols as $db_col => $col)
{
if (isset($new[$col]))
if (array_key_exists($col,$new))
{
$this->data[$col] = $new[$col];
}
}
foreach($this->non_db_cols as $db_col => $col)
{
if (isset($new[$col]))
if (array_key_exists($col,$new))
{
$this->data[$col] = $new[$col];
}
@ -446,6 +446,40 @@ class so_sql
return $this->db->Errno;
}
/**
* Update only the given fields, if the primary key is not given, it will be taken from $this->data
*
* @param array $fields
* @param boolean $merge=true if true $fields will be merged with $this->data (after update!), otherwise $this->data will be just $fields
* @return int 0 on success, errno != 0 otherwise
*/
function update($fields,$merge=true)
{
if ($merge) $backup_data = $this->data ? $this->data : array();
if ($this->autoinc_id && !isset($fields[$this->autoinc_id]) ||
$this->db_key_cols && count(array_intersect(array_keys($this->db_key_cols),array_keys($fields)) != count($this->db_key_cols)))
{
foreach($this->db_key_cols as $col => $name)
{
if (!isset($fields[$name]))
{
$fields[$name] = $this->data[$name];
}
}
}
$this->init($fields);
$ret = $this->save();
if ($merge)
{
$this->init($backup_data);
$this->data_merge($fields);
}
return $ret;
}
/**
* deletes row representing keys in internal data or the supplied $keys if != null
*

View File

@ -0,0 +1,114 @@
<?php
/**
* eGroupWare generalized SQL Storage Object Version 2 - requires PHP5.1.2+!!!
*
* @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$
*/
require_once(EGW_INCLUDE_ROOT.'/etemplate/inc/class.so_sql.inc.php');
/**
* generalized SQL Storage Object
*
* the class can be used in following ways:
* 1) by calling the constructor with an app and table-name or
* 2) by setting the following documented class-vars in a class derifed from this one
* Of cause can you derife the class and call the constructor with params.
*
* The so_sql2 class uses a privat $data array and __get and __set methods to set its data.
* Please note:
* You have to explicitly declare other object-properties of derived classes, which should NOT
* be handled by that mechanism!
*
* @package etemplate
* @subpackage api
* @author RalfBecker-AT-outdoor-training.de
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
*/
class so_sql2 extends so_sql
{
/**
* Private array containing all the object-data
*
* Colides with the original definition in so_sql and I dont want to change it there at the moment.
*
* @var array
*/
//private $data;
/**
* constructor of the class
*
* NEED to be called from the constructor of the derived class !!!
*
* @param string $app should be set if table-defs to be read from <app>/setup/tables_current.inc.php
* @param string $table should be set if table-defs to be read from <app>/setup/tables_current.inc.php
* @param object/db $db database object, if not the one in $GLOBALS['egw']->db should be used, eg. for an other database
* @param string $colum_prefix='' column prefix to automatic remove from the column-name, if the column name starts with it
*
* @return so_sql2
*/
function so_sql2($app='',$table='',$db=null,$column_prefix='')
{
$this->so_sql($app,$table,$db,$column_prefix);
}
/**
* magic method to read a property from $this->data
*
* The special property 'id' always refers to the auto-increment id of the object, independent of its name.
*
* @param string $property
* @return mixed
*/
function __get($property)
{
switch($property)
{
case 'id':
$property = $this->autoinc_id;
break;
}
if (in_array($property,$this->db_cols))
{
return $this->data[$property];
}
}
/**
* magic method to set a property in $this->data
*
* The special property 'id' always refers to the auto-increment id of the object, independent of its name.
*
* @param string $property
* @param mixed $value
* @return mixed
*/
function __set($property,$value)
{
switch($property)
{
case 'id':
$property = $this->autoinc_id;
break;
}
if (in_array($property,$this->db_cols))
{
$this->data[$property] = $value;
}
}
/**
* Return the whole object-data as array, it's a cast of the object to an array
*
* @return array
*/
function as_array()
{
return $this->data;
}
}

View File

@ -191,13 +191,17 @@
$GLOBALS['egw']->translation->add_app('etemplate'); // some extensions have own texts
}
$id = $this->appsession_id();
//echo "<p>unsetting existing egw_info[etemplate] which had keys=".implode(',',array_keys($GLOBALS['egw_info']['etemplate']))."</p>\n";
// initialise $GLOBALS['egw_info']['etemplate'], in case there are multiple eTemplates on a page
$GLOBALS['egw_info']['etemplate'] = array(
'name_forms' => $GLOBALS['egw_info']['etemplate']['name_forms'],
'validation_errors' => $GLOBALS['egw_info']['etemplate']['validation_errors'],
'hooked' => $GLOBALS['egw_info']['etemplate']['hooked'],
'content' => $GLOBALS['egw_info']['etemplate']['content'],
'hook_content' => $GLOBALS['egw_info']['etemplate']['hook_content'],
'hook_app' => $GLOBALS['egw_info']['etemplate']['hook_app'],
);
//echo "<p>hooked=".(int)!!$GLOBALS['egw_info']['etemplate']['hooked'].", content=".(int)!!$GLOBALS['egw_info']['etemplate']['content'].", hook_content=".(int)!!$GLOBALS['egw_info']['etemplate']['hook_content'].", hook_app={$GLOBALS['egw_info']['etemplate']['hook_app']}</p>\n";
$this->name_form =& $GLOBALS['egw_info']['etemplate']['name_form'];
$this->name_forms =& $GLOBALS['egw_info']['etemplate']['name_forms'];
if (!is_array($this->name_forms)) $this->name_forms = array();
@ -324,7 +328,7 @@
'java_script_body_tags' => $GLOBALS['egw']->js->body,
'include_xajax' => $GLOBALS['egw_info']['flags']['include_xajax'],
'dom_enabled' => $GLOBALS['egw_info']['etemplate']['dom_enabled'],
'hooked' => $hooked != '' ? $hooked : $GLOBALS['egw_info']['etemplate']['hook_content'],
'hooked' => $hooked ? $hooked : $GLOBALS['egw_info']['etemplate']['hook_content'],
'hook_app' => $hooked ? $GLOBALS['egw_info']['flags']['currentapp'] : $GLOBALS['egw_info']['etemplate']['hook_app'],
'app_header' => $GLOBALS['egw_info']['flags']['app_header'],
'output_mode' => $output_mode != -1 ? $output_mode : 0,
@ -333,6 +337,8 @@
'method' => $method,
'name_vars' => $this->name_vars,
),$id);
//echo "<p>hooked=".(int)!!$hooked.", content=".(int)!!$GLOBALS['egw_info']['etemplate']['content'].", hook_content=".(int)!!$GLOBALS['egw_info']['etemplate']['hook_content'].", hook_app={$GLOBALS['egw_info']['etemplate']['hook_app']}</p>\n";
//echo "<p>session: "; foreach($sess as $key => $val) echo "$key=$val, "; echo "</p>\n";
/*
echo "<p><b>total size session data = ".($total=strlen(serialize($sess)))."</b></p>\n";
echo "<p>shares bigger then 1.0% percent of it:</p>\n";
@ -736,10 +742,14 @@ foreach($sess as $key => $val)
unset($row_data[$col]); // omit empty/disabled cells if only one row
continue;
}
// can only be set via source at the moment
if (strlen($cell['onclick']) > 1 && $cell['type'] != 'button')
if (strlen($cell['onclick']) > 1 && !in_array($cell['type'],array('button','buttononly')))
{
$row_data[".$col"] .= ' onclick="'.$this->js_pseudo_funcs($cell['onclick'],$cname).'"' .
$onclick = $cell['onclick'];
if (strpos($onclick,'$') !== false || $onclick{0} == '@')
{
$onclick = $this->expand_name($onclick,$c,$r,$content['.c'],$content['.row'],$content);
}
$row_data[".$col"] .= ' onclick="'.$this->js_pseudo_funcs($onclick,$cname).'"' .
($cell['id'] ? ' id="'.$cell['id'].'"' : '');
}
$colspan = $span == 'all' ? $this->cols-$c : 0+$span;
@ -885,7 +895,7 @@ foreach($sess as $key => $val)
if ($this->rows == 1) {
return ''; // if only one row omit cell
}
$cell = $this->empty_cell(); // show nothing
$cell = $this->empty_cell('label','',array('span' => $cell['span'])); // show nothing (keep the css class!)
$value = '';
}
$extra_label = True;
@ -1719,7 +1729,7 @@ foreach($sess as $key => $val)
}
foreach($var as $key => $val)
{
$var[$key] = is_array($val) ? $this->array_stripslashes($val) : stripslashes($val);
$var[$key] = is_array($val) ? etemplate::array_stripslashes($val) : stripslashes($val);
}
return $var;
}
@ -1751,7 +1761,7 @@ foreach($sess as $key => $val)
$content = array();
if (get_magic_quotes_gpc())
{
$content_in = $this->array_stripslashes($content_in);
$content_in = etemplate::array_stripslashes($content_in);
}
$GLOBALS['egw_info']['etemplate']['validation_errors'] = array();
$this->canceled = $this->button_pressed = False;
@ -1767,7 +1777,7 @@ foreach($sess as $key => $val)
{
$attr = array();
}
$value = $this->get_array($content_in,$form_name,True,$GLOBALS['egw_info']['flags']['currentapp'] == 'etemplate' ? false : true );
$value = etemplate::get_array($content_in,$form_name,True,$GLOBALS['egw_info']['flags']['currentapp'] == 'etemplate' ? false : true );
// The comment below does only aplay to normal posts, not for xajax. Files are not supported anyway by xajax atm.
// not checked checboxes are not returned in HTML and file is in $_FILES and not in $content_in
if($value === false && $type == 'xajaxResponse' /*!in_array($type,array('checkbox','file'))*/) continue;
@ -1781,7 +1791,7 @@ foreach($sess as $key => $val)
switch ($type)
{
case 'ext':
$_cont = &$this->get_array($content,$form_name,True);
$_cont = &etemplate::get_array($content,$form_name,True);
if (!$this->extensionPostProcess($sub,$form_name,$_cont,$value))
{
//echo "\n<p><b>unsetting content[$form_name] !!!</b></p>\n";
@ -1791,7 +1801,7 @@ foreach($sess as $key => $val)
// $form_name of $content, but under some circumstances a set/changed $_cont
// does not result in a change in $content -- RalfBecker 2004/09/18
// seems to depend on the number of (not existing) dimensions of the array -- -- RalfBecker 2005/04/06
elseif (!$this->isset_array($content,$form_name))
elseif (!etemplate::isset_array($content,$form_name))
{
//echo "<p>setting content[$form_name]='$_cont' because is was unset !!!</p>\n";
$this->set_array($content,$form_name,$_cont);