mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 16:44:20 +01:00
Refractured eTemplate to use:
- the etemplate_request object which stores the request data in the a) session (as before) or b) compressed and encrypted in the form transmitted to the user Benefit of b) is that the session does not grow and the form can be submitted as long as the session exists, as we need no garbadge collection. Of cause more data needs to be submitt between browser and webserver. b) is choosen automatic if mcrypt and gzcompress are available, but can be turned off via setting etemplate_request::$request_class = 'etemplate_request_session'; - static class variables instead of the before used global ones --> This new version of eTemplate is fully backward compatible with 1.6!
This commit is contained in:
parent
97126e417f
commit
486a32e86d
@ -1,134 +1,208 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* eGroupWare eTemplate Extension - AJAX Select Widget
|
* eGroupWare eTemplate Extension - AJAX Select Widget
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
* @package etemplate
|
* @package etemplate
|
||||||
* @subpackage extensions
|
* @subpackage extensions
|
||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
* @author Nathan Gray <nathangray@sourceforge.net>
|
* @author Nathan Gray <nathangray@sourceforge.net>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AJAX Select Widget
|
* AJAX Select Widget
|
||||||
*
|
*
|
||||||
* Using AJAX, this widget allows a type-ahead find similar to a ComboBox, where as the user enters information,
|
* Using AJAX, this widget allows a type-ahead find similar to a ComboBox, where as the user enters information,
|
||||||
* a drop-down box is populated with the n closest matches. If the user clicks on an item in the drop-down, that
|
* a drop-down box is populated with the n closest matches. If the user clicks on an item in the drop-down, that
|
||||||
* value is selected.
|
* value is selected.
|
||||||
* n is the maximum number of results set in the user's preferences.
|
* n is the maximum number of results set in the user's preferences.
|
||||||
* The user is restricted to selecting values in the list.
|
* The user is restricted to selecting values in the list.
|
||||||
* This widget can get data from any function that can provide data to a nextmatch widget.
|
* This widget can get data from any function that can provide data to a nextmatch widget.
|
||||||
* This widget is generating html, so it does not work (without an extra implementation) in an other UI
|
* This widget is generating html, so it does not work (without an extra implementation) in an other UI
|
||||||
*/
|
*/
|
||||||
class ajax_select_widget
|
class ajax_select_widget
|
||||||
|
{
|
||||||
|
var $public_functions = array(
|
||||||
|
'pre_process' => True,
|
||||||
|
'post_process' => True,
|
||||||
|
'ajax_search' => True,
|
||||||
|
);
|
||||||
|
var $human_name = 'AJAX Select'; // this is the name for the editor
|
||||||
|
|
||||||
|
private $debug = false;
|
||||||
|
|
||||||
|
function ajax_select_widget($ui='')
|
||||||
{
|
{
|
||||||
var $public_functions = array(
|
|
||||||
'pre_process' => True,
|
|
||||||
'post_process' => True,
|
|
||||||
'ajax_search' => True,
|
|
||||||
);
|
|
||||||
var $human_name = 'AJAX Select'; // this is the name for the editor
|
|
||||||
|
|
||||||
private $debug = false;
|
switch($ui)
|
||||||
|
|
||||||
function ajax_select_widget($ui='')
|
|
||||||
{
|
{
|
||||||
|
case '':
|
||||||
|
case 'html':
|
||||||
|
$this->ui = 'html';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
echo "UI='$ui' not implemented";
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pre-processing of the extension
|
||||||
|
*
|
||||||
|
* This function is called before the extension gets rendered
|
||||||
|
*
|
||||||
|
* @param string $name form-name of the control
|
||||||
|
* @param mixed &$value value / existing content, can be modified
|
||||||
|
* @param array &$cell array with the widget, can be modified for ui-independent widgets
|
||||||
|
* @param array &$readonlys names of widgets as key, to be made readonly
|
||||||
|
* @param mixed &$extension_data data the extension can store persisten between pre- and post-process
|
||||||
|
* @param object &$tmpl reference to the template we belong too
|
||||||
|
* @return boolean true if extra label is allowed, false otherwise
|
||||||
|
*/
|
||||||
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
||||||
|
{
|
||||||
|
if($this->debug) {
|
||||||
|
echo __METHOD__ . '<br />';
|
||||||
|
printf("Name:%20s<br />", $name);
|
||||||
|
echo 'Value:';
|
||||||
|
_debug_array($value);
|
||||||
|
echo 'Cell:';
|
||||||
|
_debug_array($cell);
|
||||||
|
|
||||||
|
echo 'Readonlys:';
|
||||||
|
_debug_array($readonlys);
|
||||||
|
|
||||||
|
echo 'Extension_data:';
|
||||||
|
_debug_array($extension_data);
|
||||||
|
|
||||||
switch($ui)
|
|
||||||
{
|
|
||||||
case '':
|
|
||||||
case 'html':
|
|
||||||
$this->ui = 'html';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
echo "UI='$ui' not implemented";
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Get Options
|
||||||
* pre-processing of the extension
|
$options = array();
|
||||||
*
|
if(!is_array($cell['size'])) {
|
||||||
* This function is called before the extension gets rendered
|
list(
|
||||||
*
|
$options['get_rows'],
|
||||||
* @param string $name form-name of the control
|
$options['get_title'],
|
||||||
* @param mixed &$value value / existing content, can be modified
|
$options['id_field'],
|
||||||
* @param array &$cell array with the widget, can be modified for ui-independent widgets
|
$options['template'],
|
||||||
* @param array &$readonlys names of widgets as key, to be made readonly
|
$options['filter'],
|
||||||
* @param mixed &$extension_data data the extension can store persisten between pre- and post-process
|
$options['filter2'],
|
||||||
* @param object &$tmpl reference to the template we belong too
|
$options['link'],
|
||||||
* @return boolean true if extra label is allowed, false otherwise
|
$options['icon']
|
||||||
*/
|
) = explode(',', $cell['size']);
|
||||||
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
} else {
|
||||||
{
|
$options = $cell['size'];
|
||||||
if($this->debug) {
|
}
|
||||||
echo __METHOD__ . '<br />';
|
|
||||||
printf("Name:%20s<br />", $name);
|
|
||||||
echo 'Value:';
|
|
||||||
_debug_array($value);
|
|
||||||
echo 'Cell:';
|
|
||||||
_debug_array($cell);
|
|
||||||
|
|
||||||
echo 'Readonlys:';
|
if(is_array($value)) {
|
||||||
_debug_array($readonlys);
|
$options = array_merge($options, $value);
|
||||||
|
}
|
||||||
|
|
||||||
echo 'Extension_data:';
|
if(!$options['template']) {
|
||||||
_debug_array($extension_data);
|
$options['template'] = 'etemplate.ajax_select_widget.row';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
$onchange = ($cell['onchange'] ? $cell['onchange'] : 'false');
|
||||||
|
|
||||||
// Get Options
|
// Set current value
|
||||||
$options = array();
|
if(!is_array($value)) {
|
||||||
if(!is_array($cell['size'])) {
|
$current_value = $value;
|
||||||
list(
|
} elseif($value[$options['id_field']]) {
|
||||||
$options['get_rows'],
|
$current_value = $value[$options['id_field']];
|
||||||
$options['get_title'],
|
}
|
||||||
$options['id_field'],
|
$extension_data['old_value'] = $value;
|
||||||
$options['template'],
|
|
||||||
$options['filter'],
|
list($title_app, $title_class, $title_method) = explode('.', $options['get_title']);
|
||||||
$options['filter2'],
|
if($title_app && $title_class) {
|
||||||
$options['link'],
|
if (is_object($GLOBALS[$title_class])) { // use existing instance (put there by a previous CreateObject)
|
||||||
$options['icon']
|
$title_obj =& $GLOBALS[$title_class];
|
||||||
) = explode(',', $cell['size']);
|
|
||||||
} else {
|
} else {
|
||||||
$options = $cell['size'];
|
$title_obj =& CreateObject($title_app . '.' . $title_class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!is_object($title_obj) || !method_exists($title_obj,$title_method)) {
|
||||||
|
echo "$entry_app.$entry_class.$entry_method is not a valid method for getting the title";
|
||||||
|
} elseif($current_value) {
|
||||||
|
$title = $title_obj->$title_method($current_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check get_rows method
|
||||||
|
list($get_rows_app, $get_rows_class, $get_rows_method) = explode('.', $options['get_rows']);
|
||||||
|
if($get_rows_app && $get_rows_class) {
|
||||||
|
if (is_object($GLOBALS[$get_rows_class])) { // use existing instance (put there by a previous CreateObject)
|
||||||
|
$get_rows_obj =& $GLOBALS[$get_rows_class];
|
||||||
|
} else {
|
||||||
|
$get_rows_obj =& CreateObject($get_rows_app . '.' . $get_rows_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_array($value)) {
|
if(!is_object($get_rows_obj) || !method_exists($get_rows_obj, $get_rows_method)) {
|
||||||
$options = array_merge($options, $value);
|
echo "$get_rows_app.$get_rows_class.$get_rows_method is not a valid method for getting the rows";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!$options['template']) {
|
|
||||||
$options['template'] = 'etemplate.ajax_select_widget.row';
|
// Set up widget
|
||||||
|
$cell['type'] = 'template';
|
||||||
|
$cell['size'] = $cell['name'];
|
||||||
|
$value = array('value' => $current_value, 'search' => $title);
|
||||||
|
$widget =& new etemplate('etemplate.ajax_select_widget');
|
||||||
|
$widget->no_onclick = True;
|
||||||
|
|
||||||
|
// Link if readonly & link is set
|
||||||
|
$search =& $widget->get_widget_by_name('search');
|
||||||
|
if(($cell['readonly'] || $readonlys['search']) && $options['link']) {
|
||||||
|
$cell['readonly'] = false;
|
||||||
|
if(!is_array($readonlys)) {
|
||||||
|
$readonlys = array('search' => true);
|
||||||
|
} else {
|
||||||
|
$readonlys['search'] = true;
|
||||||
}
|
}
|
||||||
|
$search['type'] = 'label';
|
||||||
|
$search['no_lang'] = 1;
|
||||||
|
$search['size'] = ',' . $options['link'];
|
||||||
|
$extension_data['readonly'] = true;
|
||||||
|
} else {
|
||||||
|
$search['type'] = 'text';
|
||||||
|
$search['size'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
$onchange = ($cell['onchange'] ? $cell['onchange'] : 'false');
|
// Icon
|
||||||
|
$icon =& $widget->get_widget_by_path('/0/1A');
|
||||||
|
$icon['name'] = $options['icon'];
|
||||||
|
|
||||||
// Set current value
|
$cell['obj'] = &$widget;
|
||||||
if(!is_array($value)) {
|
|
||||||
$current_value = $value;
|
|
||||||
} elseif($value[$options['id_field']]) {
|
|
||||||
$current_value = $value[$options['id_field']];
|
|
||||||
}
|
|
||||||
$extension_data['old_value'] = $value;
|
|
||||||
|
|
||||||
list($title_app, $title_class, $title_method) = explode('.', $options['get_title']);
|
// Save options for post_processing
|
||||||
if($title_app && $title_class) {
|
$extension_data['options'] = $options;
|
||||||
if (is_object($GLOBALS[$title_class])) { // use existing instance (put there by a previous CreateObject)
|
$extension_data['needed'] = $cell['needed'];
|
||||||
$title_obj =& $GLOBALS[$title_class];
|
|
||||||
} else {
|
|
||||||
$title_obj =& CreateObject($title_app . '.' . $title_class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!is_object($title_obj) || !method_exists($title_obj,$title_method)) {
|
|
||||||
echo "$entry_app.$entry_class.$entry_method is not a valid method for getting the title";
|
|
||||||
} elseif($current_value) {
|
|
||||||
$title = $title_obj->$title_method($current_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check get_rows method
|
// xajax
|
||||||
list($get_rows_app, $get_rows_class, $get_rows_method) = explode('.', $options['get_rows']);
|
$GLOBALS['egw_info']['flags']['include_xajax'] = True;
|
||||||
|
|
||||||
|
// JavaScript
|
||||||
|
$options = $GLOBALS['egw']->js->convert_phparray_jsarray("options['$name']", $options, true);
|
||||||
|
$GLOBALS['egw']->js->set_onload("if(!options) {
|
||||||
|
var options = new Object();
|
||||||
|
}\n
|
||||||
|
$options;\n
|
||||||
|
ajax_select_widget_setup('$name', '$onchange', options['$name'], '" . $GLOBALS['egw_info']['flags']['currentapp'] . "');
|
||||||
|
");
|
||||||
|
$GLOBALS['egw']->js->validate_file('', 'ajax_select', 'etemplate');
|
||||||
|
|
||||||
|
return True; // no extra label
|
||||||
|
}
|
||||||
|
|
||||||
|
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
||||||
|
{
|
||||||
|
//echo "<p>ajax_select_widget.post_process: $name = "; _debug_array($value_in);_debug_array($extension_data);
|
||||||
|
if(!is_array($value_in)) {
|
||||||
|
$value_in = $extension_data['old_value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// They typed something in, but didn't choose a result
|
||||||
|
if(!$value_in['value'] && $value_in['search']) {
|
||||||
|
list($get_rows_app, $get_rows_class, $get_rows_method) = explode('.', $extension_data['options']['get_rows']);
|
||||||
if($get_rows_app && $get_rows_class) {
|
if($get_rows_app && $get_rows_class) {
|
||||||
if (is_object($GLOBALS[$get_rows_class])) { // use existing instance (put there by a previous CreateObject)
|
if (is_object($GLOBALS[$get_rows_class])) { // use existing instance (put there by a previous CreateObject)
|
||||||
$get_rows_obj =& $GLOBALS[$get_rows_class];
|
$get_rows_obj =& $GLOBALS[$get_rows_class];
|
||||||
@ -138,198 +212,120 @@
|
|||||||
|
|
||||||
if(!is_object($get_rows_obj) || !method_exists($get_rows_obj, $get_rows_method)) {
|
if(!is_object($get_rows_obj) || !method_exists($get_rows_obj, $get_rows_method)) {
|
||||||
echo "$get_rows_app.$get_rows_class.$get_rows_method is not a valid method for getting the rows";
|
echo "$get_rows_app.$get_rows_class.$get_rows_method is not a valid method for getting the rows";
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Set up widget
|
|
||||||
$cell['type'] = 'template';
|
|
||||||
$cell['size'] = $cell['name'];
|
|
||||||
$value = array('value' => $current_value, 'search' => $title);
|
|
||||||
$widget =& new etemplate('etemplate.ajax_select_widget');
|
|
||||||
$widget->no_onclick = True;
|
|
||||||
|
|
||||||
// Link if readonly & link is set
|
|
||||||
$search =& $widget->get_widget_by_name('search');
|
|
||||||
if(($cell['readonly'] || $readonlys['search']) && $options['link']) {
|
|
||||||
$cell['readonly'] = false;
|
|
||||||
if(!is_array($readonlys)) {
|
|
||||||
$readonlys = array('search' => true);
|
|
||||||
} else {
|
} else {
|
||||||
$readonlys['search'] = true;
|
$query = array_merge($extension_data['options'], $value_in);
|
||||||
}
|
$count = $get_rows_obj->$get_rows_method($query, $results);
|
||||||
$search['type'] = 'label';
|
|
||||||
$search['no_lang'] = 1;
|
|
||||||
$search['size'] = ',' . $options['link'];
|
|
||||||
$extension_data['readonly'] = true;
|
|
||||||
} else {
|
|
||||||
$search['type'] = 'text';
|
|
||||||
$search['size'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Icon
|
if($count == 1) {
|
||||||
$icon =& $widget->get_widget_by_path('/0/1A');
|
$value = $results[0][$extension_data['options']['id_field']];
|
||||||
$icon['name'] = $options['icon'];
|
return true;
|
||||||
|
} elseif ($count > 1) {
|
||||||
$cell['obj'] = &$widget;
|
etemplate::set_validation_error($name,lang("More than 1 match for '%1'",$value_in['search']));
|
||||||
|
$loop = true;
|
||||||
// Save options for post_processing
|
return false;
|
||||||
$extension_data['options'] = $options;
|
|
||||||
$extension_data['needed'] = $cell['needed'];
|
|
||||||
|
|
||||||
// xajax
|
|
||||||
$GLOBALS['egw_info']['flags']['include_xajax'] = True;
|
|
||||||
|
|
||||||
// JavaScript
|
|
||||||
$options = $GLOBALS['egw']->js->convert_phparray_jsarray("options['$name']", $options, true);
|
|
||||||
$GLOBALS['egw']->js->set_onload("if(!options) {
|
|
||||||
var options = new Object();
|
|
||||||
}\n
|
|
||||||
$options;\n
|
|
||||||
ajax_select_widget_setup('$name', '$onchange', options['$name'], '" . $GLOBALS['egw_info']['flags']['currentapp'] . "');
|
|
||||||
");
|
|
||||||
$GLOBALS['egw']->js->validate_file('', 'ajax_select', 'etemplate');
|
|
||||||
|
|
||||||
return True; // no extra label
|
|
||||||
}
|
|
||||||
|
|
||||||
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
|
||||||
{
|
|
||||||
//echo "<p>ajax_select_widget.post_process: $name = "; _debug_array($value_in);_debug_array($extension_data);
|
|
||||||
if(!is_array($value_in)) {
|
|
||||||
$value_in = $extension_data['old_value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// They typed something in, but didn't choose a result
|
|
||||||
if(!$value_in['value'] && $value_in['search']) {
|
|
||||||
list($get_rows_app, $get_rows_class, $get_rows_method) = explode('.', $extension_data['options']['get_rows']);
|
|
||||||
if($get_rows_app && $get_rows_class) {
|
|
||||||
if (is_object($GLOBALS[$get_rows_class])) { // use existing instance (put there by a previous CreateObject)
|
|
||||||
$get_rows_obj =& $GLOBALS[$get_rows_class];
|
|
||||||
} else {
|
} else {
|
||||||
$get_rows_obj =& CreateObject($get_rows_app . '.' . $get_rows_class);
|
$value = $value_in['search'];
|
||||||
}
|
return true;
|
||||||
|
|
||||||
if(!is_object($get_rows_obj) || !method_exists($get_rows_obj, $get_rows_method)) {
|
|
||||||
echo "$get_rows_app.$get_rows_class.$get_rows_method is not a valid method for getting the rows";
|
|
||||||
} else {
|
|
||||||
$query = array_merge($extension_data['options'], $value_in);
|
|
||||||
$count = $get_rows_obj->$get_rows_method($query, $results);
|
|
||||||
|
|
||||||
if($count == 1) {
|
|
||||||
$value = $results[0][$extension_data['options']['id_field']];
|
|
||||||
return true;
|
|
||||||
} elseif ($count > 1) {
|
|
||||||
$GLOBALS['egw_info']['etemplate']['validation_errors'][$name] = lang("More than 1 match for '%1'",$value_in['search']);
|
|
||||||
$loop = true;
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
$value = $value_in['search'];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($extension_data['readonly']) {
|
}
|
||||||
|
} elseif ($extension_data['readonly']) {
|
||||||
|
$value = $extension_data['old_value'];
|
||||||
|
return true;
|
||||||
|
} elseif ($value_in['search'] == '') {
|
||||||
|
// They're trying to clear the form
|
||||||
|
$value = null;
|
||||||
|
|
||||||
|
// True if not needed, false if needed and they gave no value
|
||||||
|
$return = !($extension_data['needed'] && trim($value_in['value']) == '');
|
||||||
|
|
||||||
|
if(!$return) {
|
||||||
$value = $extension_data['old_value'];
|
$value = $extension_data['old_value'];
|
||||||
return true;
|
etemplate::set_validation_error($name,lang('Required'));
|
||||||
} elseif ($value_in['search'] == '') {
|
$loop = true;
|
||||||
// They're trying to clear the form
|
|
||||||
$value = null;
|
|
||||||
|
|
||||||
// True if not needed, false if needed and they gave no value
|
|
||||||
$return = !($extension_data['needed'] && trim($value_in['value']) == '');
|
|
||||||
|
|
||||||
if(!$return) {
|
|
||||||
$value = $extension_data['old_value'];
|
|
||||||
$GLOBALS['egw_info']['etemplate']['validation_errors'][$name] = lang('Required');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop if some other widget wants to loop, or if this is required and they gave no value
|
|
||||||
$loop = $GLOBALS['egw_info']['etemplate']['loop'] || !$return;
|
|
||||||
|
|
||||||
if($this->debug && $loop) {
|
|
||||||
echo 'Looping...<br />Returning ' . $return . '<br />';
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
} else {
|
|
||||||
$value = $value_in['value'];
|
|
||||||
$loop = $GLOBALS['egw_info']['etemplate']['loop'] || false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function ajax_search($id, $value, $set_id, $query) {
|
|
||||||
$base_id = substr($id, 0, strrpos($id, '['));
|
|
||||||
$result_id = ($set_id ? $set_id : $base_id . '[results]');
|
|
||||||
$response = new xajaxResponse();
|
|
||||||
if($query['get_rows']) {
|
|
||||||
list($app, $class, $method) = explode('.', $query['get_rows']);
|
|
||||||
$this->bo = CreateObject($app . '.' . $class);
|
|
||||||
unset($query['get_rows']);
|
|
||||||
} else {
|
|
||||||
return $response->getXML();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand lists
|
if($this->debug && $loop) {
|
||||||
foreach($query as $key => &$row) {
|
echo 'Looping...<br />Returning ' . $return . '<br />';
|
||||||
if(strpos($row, ',')) {
|
|
||||||
$query[$key] = explode(',', $row);
|
|
||||||
}
|
|
||||||
|
|
||||||
// sometimes it sends 'null' (not null)
|
|
||||||
if($row == 'null') {
|
|
||||||
unset($query[$key]);
|
|
||||||
} elseif (is_string($row) && strtolower($row) == 'false') {
|
|
||||||
$row = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$query['search'] = $value;
|
return $return;
|
||||||
|
} else {
|
||||||
$result_list = array();
|
$value = $value_in['value'];
|
||||||
$readonlys = array();
|
return true;
|
||||||
if(is_object($this->bo)) {
|
|
||||||
$count = $this->bo->$method($query, $result_list, $readonlys);
|
|
||||||
}
|
|
||||||
if(is_array($count)) {
|
|
||||||
$count = count($result_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
$response->addScript("remove_ajax_results('$result_id')");
|
|
||||||
if($count > 0) {
|
|
||||||
$response->addScript("add_ajax_result('$result_id', '', '', '" . lang('Select') ."');");
|
|
||||||
$count = 0;
|
|
||||||
|
|
||||||
if(!$query['template'] || $query['template'] == 'etemplate.ajax_select_widget.row') {
|
|
||||||
$query['template'] = 'etemplate.ajax_select_widget.row';
|
|
||||||
}
|
|
||||||
foreach($result_list as $key => &$row) {
|
|
||||||
if(!is_array($row)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if($query['id_field'] && $query['get_title']) {
|
|
||||||
if($row[$query['id_field']]) {
|
|
||||||
$row['title'] = ExecMethod($query['get_title'], $row[$query['id_field']]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = ($query['nextmatch_template']) ? array(1=>$row) : $row;
|
|
||||||
$widget =& CreateObject('etemplate.etemplate', $query['template']);
|
|
||||||
$html = addslashes(str_replace("\n", '', $widget->show($data, '', $readonlys)));
|
|
||||||
|
|
||||||
// If we use htmlspecialchars, it causes issues with mixed quotes. addslashes() seems to handle it.
|
|
||||||
$row['id_field'] = addslashes($row[$query['id_field']]);
|
|
||||||
$row['title'] = addslashes($row['title']);
|
|
||||||
$response->addScript("add_ajax_result('$result_id', '${row['id_field']}', '" . $row['title'] . "', '$html');");
|
|
||||||
$count++;
|
|
||||||
if($count > $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']) {
|
|
||||||
$response->addScript("add_ajax_result('$result_id', '', '', '" . lang("%1 more...", (count($result_list) - $count)) . "');");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$response->addScript("add_ajax_result('$result_id', '', '', '" . lang('No matches found') ."');");
|
|
||||||
}
|
|
||||||
return $response->getXML();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
function ajax_search($id, $value, $set_id, $query) {
|
||||||
|
$base_id = substr($id, 0, strrpos($id, '['));
|
||||||
|
$result_id = ($set_id ? $set_id : $base_id . '[results]');
|
||||||
|
$response = new xajaxResponse();
|
||||||
|
if($query['get_rows']) {
|
||||||
|
list($app, $class, $method) = explode('.', $query['get_rows']);
|
||||||
|
$this->bo = CreateObject($app . '.' . $class);
|
||||||
|
unset($query['get_rows']);
|
||||||
|
} else {
|
||||||
|
return $response->getXML();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expand lists
|
||||||
|
foreach($query as $key => &$row) {
|
||||||
|
if(strpos($row, ',')) {
|
||||||
|
$query[$key] = explode(',', $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
// sometimes it sends 'null' (not null)
|
||||||
|
if($row == 'null') {
|
||||||
|
unset($query[$key]);
|
||||||
|
} elseif (is_string($row) && strtolower($row) == 'false') {
|
||||||
|
$row = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$query['search'] = $value;
|
||||||
|
|
||||||
|
$result_list = array();
|
||||||
|
$readonlys = array();
|
||||||
|
if(is_object($this->bo)) {
|
||||||
|
$count = $this->bo->$method($query, $result_list, $readonlys);
|
||||||
|
}
|
||||||
|
if(is_array($count)) {
|
||||||
|
$count = count($result_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response->addScript("remove_ajax_results('$result_id')");
|
||||||
|
if($count > 0) {
|
||||||
|
$response->addScript("add_ajax_result('$result_id', '', '', '" . lang('Select') ."');");
|
||||||
|
$count = 0;
|
||||||
|
|
||||||
|
if(!$query['template'] || $query['template'] == 'etemplate.ajax_select_widget.row') {
|
||||||
|
$query['template'] = 'etemplate.ajax_select_widget.row';
|
||||||
|
}
|
||||||
|
foreach($result_list as $key => &$row) {
|
||||||
|
if(!is_array($row)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if($query['id_field'] && $query['get_title']) {
|
||||||
|
if($row[$query['id_field']]) {
|
||||||
|
$row['title'] = ExecMethod($query['get_title'], $row[$query['id_field']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = ($query['nextmatch_template']) ? array(1=>$row) : $row;
|
||||||
|
$widget =& CreateObject('etemplate.etemplate', $query['template']);
|
||||||
|
$html = addslashes(str_replace("\n", '', $widget->show($data, '', $readonlys)));
|
||||||
|
|
||||||
|
// If we use htmlspecialchars, it causes issues with mixed quotes. addslashes() seems to handle it.
|
||||||
|
$row['id_field'] = addslashes($row[$query['id_field']]);
|
||||||
|
$row['title'] = addslashes($row['title']);
|
||||||
|
$response->addScript("add_ajax_result('$result_id', '${row['id_field']}', '" . $row['title'] . "', '$html');");
|
||||||
|
$count++;
|
||||||
|
if($count > $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']) {
|
||||||
|
$response->addScript("add_ajax_result('$result_id', '', '', '" . lang("%1 more...", (count($result_list) - $count)) . "');");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response->addScript("add_ajax_result('$result_id', '', '', '" . lang('No matches found') ."');");
|
||||||
|
}
|
||||||
|
return $response->getXML();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||||
* @copyright 2002-8 by RalfBecker@outdoor-training.de
|
* @copyright 2002-9 by RalfBecker@outdoor-training.de
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
* @package etemplate
|
* @package etemplate
|
||||||
* @subpackage api
|
* @subpackage api
|
||||||
@ -12,13 +12,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Business Object for eTemplates, extending the Storage Object
|
* Business Object for eTemplates, extending the Storage Object
|
||||||
*
|
*/
|
||||||
* Not so much so far, as the most logic is still in the UI-class
|
|
||||||
*/
|
|
||||||
class boetemplate extends soetemplate
|
class boetemplate extends soetemplate
|
||||||
{
|
{
|
||||||
var $types = array(
|
static public $types = array(
|
||||||
'label' => 'Label', // Label $cell['label'] is (to be translated) textual content
|
'label' => 'Label', // Label $cell['label'] is (to be translated) textual content
|
||||||
'text' => 'Text', // Textfield 1 Line (size = [length][,maxlength])
|
'text' => 'Text', // Textfield 1 Line (size = [length][,maxlength])
|
||||||
'int' => 'Integer', // like text, but only numbers (size = [min][,max])
|
'int' => 'Integer', // like text, but only numbers (size = [min][,max])
|
||||||
@ -45,7 +43,22 @@ class boetemplate extends soetemplate
|
|||||||
'deck' => 'Deck', // a container of elements where only one is visible, size = # of elem.
|
'deck' => 'Deck', // a container of elements where only one is visible, size = # of elem.
|
||||||
'passwd' => 'Password' // a text of type password
|
'passwd' => 'Password' // a text of type password
|
||||||
);
|
);
|
||||||
private static $garbage_collection_done;
|
|
||||||
|
/**
|
||||||
|
* Flag if form validation requires to loop
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
static public $loop = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request object of the currecntly created request
|
||||||
|
*
|
||||||
|
* It's a static variable as etemplates can contain further etemplates (rendered by a different object)
|
||||||
|
*
|
||||||
|
* @var etemplate_request
|
||||||
|
*/
|
||||||
|
static public $request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor of class
|
* constructor of class
|
||||||
@ -55,9 +68,9 @@ class boetemplate extends soetemplate
|
|||||||
* @param string/array $name name of etemplate or array with name and other keys
|
* @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
|
* @param string/array $load_via name or array with keys of other etemplate to load in order to get $name
|
||||||
*/
|
*/
|
||||||
function boetemplate($name='',$load_via='')
|
function __construct($name='',$load_via='')
|
||||||
{
|
{
|
||||||
$this->soetemplate();
|
parent::__construct();
|
||||||
|
|
||||||
$tname = &$name;
|
$tname = &$name;
|
||||||
if (is_array($name))
|
if (is_array($name))
|
||||||
@ -223,107 +236,6 @@ class boetemplate extends soetemplate
|
|||||||
return $Ok;
|
return $Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* creates a new appsession-id via microtime()
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected static function appsession_id()
|
|
||||||
{
|
|
||||||
list($msec,$sec) = explode(' ',microtime());
|
|
||||||
$time = 100 * $sec + (int)(100 * $msec); // gives precision of 1/100 sec
|
|
||||||
$id = $GLOBALS['egw_info']['flags']['currentapp'] .':'. $time;
|
|
||||||
//echo "<p>microtime()=".microtime().", sec=$sec, msec=$msec, id=$id</p>\n";
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* @param array $data the data to save
|
|
||||||
* @param string $id the id to use or '' to generate a new id
|
|
||||||
* @return string location-id
|
|
||||||
*/
|
|
||||||
protected static function save_appsession($data,$id='')
|
|
||||||
{
|
|
||||||
if (!$id)
|
|
||||||
{
|
|
||||||
$id = self::appsession_id();
|
|
||||||
}
|
|
||||||
$GLOBALS['egw']->session->appsession($id,'etemplate',$data);
|
|
||||||
|
|
||||||
if (substr($GLOBALS['egw_info']['server']['sessions_type'],0,4) == 'php4' && !self::$garbage_collection_done)
|
|
||||||
{
|
|
||||||
return self::php_session_garbage_collection();
|
|
||||||
}
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets content,readonlys,template-keys, ... back from the appsession function
|
|
||||||
*
|
|
||||||
* @param string $id the location-id
|
|
||||||
* @return array with session-data
|
|
||||||
*/
|
|
||||||
protected function get_appsession($id)
|
|
||||||
{
|
|
||||||
$data = egw_session::appsession($id,'etemplate');
|
|
||||||
//echo "boetemplate::get_appsession('$id')"; _debug_array($data);
|
|
||||||
|
|
||||||
self::php_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
|
|
||||||
*/
|
|
||||||
static private function php_session_garbage_collection($id_used='')
|
|
||||||
{
|
|
||||||
// now we are on php4 sessions and do a bit of garbage collection
|
|
||||||
$app_sessions =& $_SESSION[egw_session::EGW_APPSESSION_VAR]['etemplate'];
|
|
||||||
$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
|
|
||||||
}
|
|
||||||
self::$garbage_collection_done = true;
|
|
||||||
|
|
||||||
if (count($app_sessions) < 20) return $data; // 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)
|
|
||||||
{
|
|
||||||
list($app,$time) = explode(':',$id);
|
|
||||||
|
|
||||||
if (!$time) continue; // other data, no session
|
|
||||||
|
|
||||||
//echo ++$n.') '.$id.': '.(($now-$time)/100.0)."secs old, used=".$session_used[$id].", size=".egw_vfs::hsize(strlen(serialize($app_sessions[$id])))."<br>\n";
|
|
||||||
|
|
||||||
if ($session_used[$id] == 1 && $time < $now - 10*6000 || // session used and older then 10min
|
|
||||||
$time < $now - 30*6000) // session not used and older then 30min
|
|
||||||
{
|
|
||||||
//echo "<p>boetemplate::php_session_garbage_collection('$id_used'): unsetting session '$id' (now=$now)</p>\n";
|
|
||||||
unset($app_sessions[$id]);
|
|
||||||
unset($session_used[$id]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets an attribute in a named cell
|
* gets an attribute in a named cell
|
||||||
*
|
*
|
||||||
@ -453,6 +365,13 @@ class boetemplate extends soetemplate
|
|||||||
$this->set_column_attributes($c,0,!$enable,$path);
|
$this->set_column_attributes($c,0,!$enable,$path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache for extension objects
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
static private $extensions = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* trys to load the Extension / Widget-class from the app or etemplate
|
* trys to load the Extension / Widget-class from the app or etemplate
|
||||||
*
|
*
|
||||||
@ -482,12 +401,12 @@ class boetemplate extends soetemplate
|
|||||||
if (!file_exists(EGW_SERVER_ROOT."/$app/inc/class.$class.inc.php"))
|
if (!file_exists(EGW_SERVER_ROOT."/$app/inc/class.$class.inc.php"))
|
||||||
{
|
{
|
||||||
//echo "<p>boetemplate::loadExtension($type) extension not found</p>\n";
|
//echo "<p>boetemplate::loadExtension($type) extension not found</p>\n";
|
||||||
return $GLOBALS['egw_info']['etemplate']['extension'][$type] = False;
|
return self::$extensions[$type] = False;
|
||||||
}
|
}
|
||||||
$GLOBALS['egw_info']['etemplate']['extension'][$type] =& CreateObject($app.'.'.$class,$ui='html');
|
self::$extensions[$type] =& CreateObject($app.'.'.$class,$ui='html');
|
||||||
|
|
||||||
//echo "<p>boetemplate::loadExtension($type) extension found in App. $app</p>\n";
|
//echo "<p>boetemplate::loadExtension($type) extension found in App. $app</p>\n";
|
||||||
return $GLOBALS['egw_info']['etemplate']['extension'][$type]->human_name;
|
return self::$extensions[$type]->human_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -500,8 +419,8 @@ class boetemplate extends soetemplate
|
|||||||
*/
|
*/
|
||||||
protected function haveExtension($type,$function='')
|
protected function haveExtension($type,$function='')
|
||||||
{
|
{
|
||||||
return ($GLOBALS['egw_info']['etemplate']['extension'][$type] || $this->loadExtension($type,$ui)) &&
|
return (self::$extensions[$type] || $this->loadExtension($type,$ui)) &&
|
||||||
($function == '' || $GLOBALS['egw_info']['etemplate']['extension'][$type]->public_functions[$function]);
|
($function == '' || self::$extensions[$type]->public_functions[$function]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -522,11 +441,11 @@ class boetemplate extends soetemplate
|
|||||||
}
|
}
|
||||||
// only supply extension data for non-readonly widgets or if it's already set
|
// only supply extension data for non-readonly widgets or if it's already set
|
||||||
// otherwise lists store >10k unnecessary data in each etemplate-session
|
// otherwise lists store >10k unnecessary data in each etemplate-session
|
||||||
if (!($cell['readonly'] || $readonlys && !is_array($readonlys)) || isset($GLOBALS['egw_info']['etemplate']['extension_data'][$name]))
|
if (!($cell['readonly'] || $readonlys && !is_array($readonlys)) || isset(self::$request->extension_data[$name]))
|
||||||
{
|
{
|
||||||
$extension_data =& $GLOBALS['egw_info']['etemplate']['extension_data'][$name];
|
$extension_data =& self::$request->extension_data[$name];
|
||||||
}
|
}
|
||||||
return $GLOBALS['egw_info']['etemplate']['extension'][$type]->pre_process($name,$value,$cell,$readonlys,$extension_data,$this);
|
return self::$extensions[$type]->pre_process($name,$value,$cell,$readonlys,$extension_data,$this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -544,9 +463,9 @@ class boetemplate extends soetemplate
|
|||||||
{
|
{
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
return $GLOBALS['egw_info']['etemplate']['extension'][$type]->post_process($name,$value,
|
return self::$extensions[$type]->post_process($name,$value,
|
||||||
$GLOBALS['egw_info']['etemplate']['extension_data'][$name],
|
self::$request->extension_data[$name],
|
||||||
$GLOBALS['egw_info']['etemplate']['loop'],$this,$value_in);
|
self::$loop,$this,$value_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -565,8 +484,8 @@ class boetemplate extends soetemplate
|
|||||||
{
|
{
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
return $GLOBALS['egw_info']['etemplate']['extension'][$type]->render($cell,$name,$value,$readonly,
|
return self::$extensions[$type]->render($cell,$name,$value,$readonly,
|
||||||
$GLOBALS['egw_info']['etemplate']['extension_data'][$name],$this);
|
self::$request->extension_data[$name],$this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -798,12 +717,19 @@ class boetemplate extends soetemplate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stores the etemplate in the cache in phpgw_info
|
* Cache for already read etemplates
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $template_cache = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stores the etemplate in the cache in egw_info
|
||||||
*/
|
*/
|
||||||
private function store_in_cache()
|
private function store_in_cache()
|
||||||
{
|
{
|
||||||
//echo "<p>store_in_cache('$this->name','$this->template','$this->lang','$this->version')</p>\n";
|
//echo "<p>store_in_cache('$this->name','$this->template','$this->lang','$this->version')</p>\n";
|
||||||
$GLOBALS['egw_info']['etemplate']['cache'][$this->cache_name()] = $this->as_array(1);
|
self::$template_cache[$this->cache_name()] = $this->as_array(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -812,7 +738,7 @@ class boetemplate extends soetemplate
|
|||||||
private function delete_in_cache()
|
private function delete_in_cache()
|
||||||
{
|
{
|
||||||
//echo "<p>delete_in_cache('$this->name','$this->template','$this->lang','$this->version')</p>\n";
|
//echo "<p>delete_in_cache('$this->name','$this->template','$this->lang','$this->version')</p>\n";
|
||||||
unset($GLOBALS['egw_info']['etemplate']['cache'][$this->cache_name()]);
|
unset(self::$template_cache[$this->cache_name()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -833,8 +759,8 @@ class boetemplate extends soetemplate
|
|||||||
$version = $name['version'];
|
$version = $name['version'];
|
||||||
$name = $name['name'];
|
$name = $name['name'];
|
||||||
}
|
}
|
||||||
if (!isset($GLOBALS['egw_info']['etemplate']['cache'][$cname]) ||
|
if (!isset(self::$template_cache[$cname]) ||
|
||||||
!empty($version) && $GLOBALS['egw_info']['etemplate']['cache'][$cname]['version'] != $version)
|
!empty($version) && self::$template_cache[$cname]['version'] != $version)
|
||||||
{
|
{
|
||||||
//echo " NOT found in cache</p>\n";
|
//echo " NOT found in cache</p>\n";
|
||||||
return False;
|
return False;
|
||||||
@ -860,7 +786,7 @@ class boetemplate extends soetemplate
|
|||||||
//if (is_array($name)) $version = $name['version']; echo "<p>read_from_cache(,,,version='$version'): ";
|
//if (is_array($name)) $version = $name['version']; echo "<p>read_from_cache(,,,version='$version'): ";
|
||||||
if ($cname = $this->in_cache($name,$template,$lang,$group))
|
if ($cname = $this->in_cache($name,$template,$lang,$group))
|
||||||
{
|
{
|
||||||
$this->init($GLOBALS['egw_info']['etemplate']['cache'][$cname]);
|
$this->init(self::$template_cache[$cname]);
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
@ -956,7 +882,6 @@ class boetemplate extends soetemplate
|
|||||||
*/
|
*/
|
||||||
static function _init_static()
|
static function _init_static()
|
||||||
{
|
{
|
||||||
self::$garbage_collection_done =& $GLOBALS['egw_info']['etemplate']['garbage_collection_done'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boetemplate::_init_static();
|
boetemplate::_init_static();
|
||||||
@ -997,3 +922,5 @@ if (!function_exists('set_cell_attribute_helper'))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// just in case someone still uses the old var
|
||||||
|
$GLOBALS['egw_info']['flags']['etemplate']['loop'] =& boetemplate::$loop;
|
@ -5,7 +5,7 @@
|
|||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
* @copyright 2002-8 by RalfBecker@outdoor-training.de
|
* @copyright 2002-9 by RalfBecker@outdoor-training.de
|
||||||
* @package etemplate
|
* @package etemplate
|
||||||
* @subpackage extensions
|
* @subpackage extensions
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
@ -231,10 +231,9 @@ class date_widget
|
|||||||
}
|
}
|
||||||
if ($cell['needed'])
|
if ($cell['needed'])
|
||||||
{
|
{
|
||||||
$GLOBALS['egw_info']['etemplate']['to_process'][$name] = array(
|
etemplate::$request->set_to_process($name,'ext-'.$type,array(
|
||||||
'type' => 'ext-'.$type,
|
|
||||||
'needed' => $cell['needed'],
|
'needed' => $cell['needed'],
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
$tpl =& new etemplate;
|
$tpl =& new etemplate;
|
||||||
$tpl->init('*** generated fields for date','','',0,'',0,0); // make an empty template
|
$tpl->init('*** generated fields for date','','',0,'',0,0); // make an empty template
|
||||||
@ -539,7 +538,7 @@ class date_widget
|
|||||||
}
|
}
|
||||||
elseif (!preg_match('/^-?[0-9]*[,.]?[0-9]*'.($extension_data['percent_allowed'] ? '%?' : '').'$/',$value_in))
|
elseif (!preg_match('/^-?[0-9]*[,.]?[0-9]*'.($extension_data['percent_allowed'] ? '%?' : '').'$/',$value_in))
|
||||||
{
|
{
|
||||||
$GLOBALS['egw_info']['etemplate']['validation_errors'][$name] = lang("'%1' is not a valid floatingpoint number !!!",$value_in);
|
etemplate::set_validation_error($name,lang("'%1' is not a valid floatingpoint number !!!",$value_in));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -613,8 +612,8 @@ class date_widget
|
|||||||
// checking the date is a correct one
|
// checking the date is a correct one
|
||||||
if (!checkdate($value['m'],$value['d'],$value['Y']))
|
if (!checkdate($value['m'],$value['d'],$value['Y']))
|
||||||
{
|
{
|
||||||
$GLOBALS['egw_info']['etemplate']['validation_errors'][$name] .= lang("'%1' is not a valid date !!!",
|
etemplate::set_validation_error($name,lang("'%1' is not a valid date !!!",
|
||||||
$GLOBALS['egw']->common->dateformatorder($value['Y'],$value['m'],$value['d'],true));
|
common::dateformatorder($value['Y'],$value['m'],$value['d'],true)));
|
||||||
}
|
}
|
||||||
$data_format = $extension_data['data_format'];
|
$data_format = $extension_data['data_format'];
|
||||||
if (empty($data_format))
|
if (empty($data_format))
|
||||||
|
@ -430,7 +430,7 @@ class editor
|
|||||||
$additional = array();
|
$additional = array();
|
||||||
if ($app == 'etemplate')
|
if ($app == 'etemplate')
|
||||||
{
|
{
|
||||||
$additional = $this->etemplate->types + $this->extensions + $this->aligns + $this->valigns +
|
$additional = etemplate::$types + $this->extensions + $this->aligns + $this->valigns +
|
||||||
$this->edit_menu + $this->box_menu + $this->row_menu + $this->column_menu + $this->onclick_types + $this->onchange_types;
|
$this->edit_menu + $this->box_menu + $this->row_menu + $this->column_menu + $this->onclick_types + $this->onchange_types;
|
||||||
}
|
}
|
||||||
else // try to call the writeLangFile function of the app's ui-layer
|
else // try to call the writeLangFile function of the app's ui-layer
|
||||||
@ -1360,7 +1360,7 @@ class editor
|
|||||||
$GLOBALS['egw_info']['flags']['java_script'] = "<script>window.focus();</script>\n";
|
$GLOBALS['egw_info']['flags']['java_script'] = "<script>window.focus();</script>\n";
|
||||||
$GLOBALS['egw_info']['flags']['app_header'] = lang('Editable Templates - Editor');
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('Editable Templates - Editor');
|
||||||
$editor->exec('etemplate.editor.widget',$content,array(
|
$editor->exec('etemplate.editor.widget',$content,array(
|
||||||
'type' => array_merge($this->etemplate->types,$this->extensions),
|
'type' => array_merge(etemplate::$types,$this->extensions),
|
||||||
'align' => &$this->aligns,
|
'align' => &$this->aligns,
|
||||||
'valign' => &$this->valigns,
|
'valign' => &$this->valigns,
|
||||||
'part' => $allowed_parts,
|
'part' => $allowed_parts,
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,36 +1,54 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* eGroupWare - eTemplate request object
|
* eGroupWare - eTemplate request object storing request-data directly in the form itself
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
* @package etemplate
|
* @package etemplate
|
||||||
|
* @subpackage api
|
||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||||
* @copyright (c) 2007 by Ralf Becker <RalfBecker@outdoor-training.de>
|
* @copyright (c) 2007-9 by Ralf Becker <RalfBecker@outdoor-training.de>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to represent the persitent information stored on the server for each eTemplate request
|
* Class to represent the persitent information of an eTemplate request
|
||||||
*
|
*
|
||||||
* The information is stored in the users session
|
* This class stores the request-data direct in a hidden var in the form.
|
||||||
*
|
* As this would allow an evil user to manipulate it and therefore compromise the security
|
||||||
* There are two ways to instanciate a request object:
|
* of an EGroupware instance, this class should only be used, if mcrypt is available
|
||||||
*
|
* to encrypt that data. The factory method etemplate_request::read() ensures that,
|
||||||
* a) a new request:
|
* by using etemplate_request_session instead.
|
||||||
*
|
*
|
||||||
* $request = new etemplate_request(); $id = $request->id();
|
* The key used to encrypt the request can be set in header.inc.php by setting
|
||||||
*
|
*
|
||||||
* b) open or modify an existing request:
|
* $GLOBALS['egw_info']['server']['etemplate_form_key'] = 'something secret';
|
||||||
*
|
*
|
||||||
* if (!($request = etemplate_request::read($id)))
|
* if this var is not set, the db_pass and EGW_SERVER_ROOT is used instead.
|
||||||
|
*
|
||||||
|
* The request object should be instancated only via the factory method etemplate::request($id=null)
|
||||||
|
*
|
||||||
|
* $request = etemplate::request();
|
||||||
|
*
|
||||||
|
* // add request data
|
||||||
|
*
|
||||||
|
* $id = $request->id();
|
||||||
|
*
|
||||||
|
* b) open or modify an existing request:
|
||||||
|
*
|
||||||
|
* if (!($request = etemplate::request($id)))
|
||||||
* {
|
* {
|
||||||
* // request not found
|
* // request not found
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Ajax request can use this object to open the original request by using the id, they have to transmitt back,
|
* Ajax requests can use this object to open the original request by using the id, they have to transmitt back,
|
||||||
* and register further variables, modify the registered ones or delete them.
|
* and register further variables, modify the registered ones or delete them AND then update the id, if it changed:
|
||||||
*
|
*
|
||||||
|
* if (($new_id = $request->id()) != $id)
|
||||||
|
* {
|
||||||
|
* $response->addAssign('etemplate_exec_id','value',$new_id);
|
||||||
|
* }
|
||||||
|
*
|
||||||
* For an example look in link_widget::ajax_search()
|
* For an example look in link_widget::ajax_search()
|
||||||
*/
|
*/
|
||||||
class etemplate_request
|
class etemplate_request
|
||||||
@ -40,61 +58,132 @@ class etemplate_request
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $data=array();
|
protected $data=array();
|
||||||
/**
|
/**
|
||||||
* Flag if data has been modified and therefor need to be stored again in the session
|
* Flag if data has been modified and therefor need to be stored again in the session
|
||||||
*
|
*
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
private $data_modified=false;
|
protected $data_modified=false;
|
||||||
/**
|
/**
|
||||||
* request id
|
* mcrypt resource
|
||||||
|
*
|
||||||
|
* @var resource
|
||||||
|
*/
|
||||||
|
static protected $mcrypt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See gzcompress, set it to 0 to not compress
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
static public $compression_level = 6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of request class used
|
||||||
|
*
|
||||||
|
* Can be set here to force a certain class, otherwise the factory method chooses one
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $id;
|
static public $request_class;// = 'etemplate_request_session';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Factory method to get a new request object or the one for an existing request
|
||||||
*
|
*
|
||||||
* @param array $id_data
|
* If mcrypt AND gzcompress is available this factory method chooses etemplate_request,
|
||||||
|
* which stores the request data encrypted in a hidden var directly in the form,
|
||||||
|
* over etemplate_request_session, which stores the data in the session (and causing
|
||||||
|
* the sesison to constantly grow).
|
||||||
|
*
|
||||||
|
* @param string $id=null
|
||||||
* @return etemplate_request
|
* @return etemplate_request
|
||||||
*/
|
*/
|
||||||
function __construct($id=null)
|
public static function read($id=null)
|
||||||
{
|
{
|
||||||
if (!$id) $id = self::request_id();
|
if (is_null(self::$request_class))
|
||||||
|
{
|
||||||
$this->id = $id;
|
self::$request_class = extension_loaded('mcrypt') && function_exists('gzcompress') &&
|
||||||
|
self::init_crypt() ? __CLASS__ : 'etemplate_request_session';
|
||||||
|
}
|
||||||
|
if (self::$request_class != __CLASS__)
|
||||||
|
{
|
||||||
|
return call_user_method('read',self::$request_class,$id);
|
||||||
|
}
|
||||||
|
$request = new etemplate_request();
|
||||||
|
|
||||||
|
if (!is_null($id))
|
||||||
|
{
|
||||||
|
$id = base64_decode($id);
|
||||||
|
|
||||||
|
// decrypt the data if available
|
||||||
|
if (self::init_crypt())
|
||||||
|
{
|
||||||
|
$id = trim(mdecrypt_generic(self::$mcrypt,$id));
|
||||||
|
}
|
||||||
|
// uncompress the data if available
|
||||||
|
if (self::$compression_level && function_exists('gzcompress'))
|
||||||
|
{
|
||||||
|
//$len_compressed = bytes($id);
|
||||||
|
//$time = microtime(true);
|
||||||
|
$id = gzuncompress($id);
|
||||||
|
//$time = number_format(1000.0 * (microtime(true) - $time),1);
|
||||||
|
//$len_uncompressed = bytes($id);
|
||||||
|
//error_log(__METHOD__."() uncompressed from $len_compressed to $len_uncompressed bytes $time ms");
|
||||||
|
}
|
||||||
|
$request->data = unserialize($id);
|
||||||
|
|
||||||
|
if (!$request->data)
|
||||||
|
{
|
||||||
|
error_log(__METHOD__."() id not valid!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//error_log(__METHOD__."() size of request = ".bytes($id));
|
||||||
|
}
|
||||||
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor to force the instancation of this class only via it's static factory method read
|
||||||
|
*
|
||||||
|
* @param string $id=null
|
||||||
|
*/
|
||||||
|
private function __construct($id=null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the id of this request
|
* return the id of this request
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function id()
|
public function &id()
|
||||||
{
|
{
|
||||||
return $this->id;
|
$id = serialize($this->data);
|
||||||
}
|
|
||||||
|
// compress the data if available
|
||||||
/**
|
if (self::$compression_level && function_exists('gzcompress'))
|
||||||
* Read the request via it's id, returns a request_object or false
|
|
||||||
*
|
|
||||||
* @param string $id
|
|
||||||
* @return etempalte_request|boolean the object or false if $id is not found
|
|
||||||
*/
|
|
||||||
static function read($id)
|
|
||||||
{
|
|
||||||
if (!($data = $GLOBALS['egw']->session->appsession($id,'etemplate')))
|
|
||||||
{
|
{
|
||||||
return false; // request not found
|
//$len_uncompressed = bytes($id);
|
||||||
|
//$time = microtime(true);
|
||||||
|
$id = gzcompress($id,self::$compression_level);
|
||||||
|
//$time = number_format(1000.0 * (microtime(true) - $time),1);
|
||||||
|
//$len_compressed = bytes($id);
|
||||||
|
//error_log(__METHOD__."() compressed from $len_uncompressed to $len_compressed bytes in $time ms");
|
||||||
}
|
}
|
||||||
$request = new etemplate_request($id);
|
// encrypt the data if available
|
||||||
$request->data = $data;
|
if (self::init_crypt())
|
||||||
|
{
|
||||||
return $request;
|
$id = mcrypt_generic(self::$mcrypt,$id);
|
||||||
|
}
|
||||||
|
$id = base64_encode($id);
|
||||||
|
|
||||||
|
//error_log(__METHOD__."() #$this->id: size of request = ".bytes($id));//.", id='$id'");
|
||||||
|
//self::debug();
|
||||||
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a form-variable to be processed
|
* Register a form-variable to be processed
|
||||||
*
|
*
|
||||||
@ -105,13 +194,36 @@ class etemplate_request
|
|||||||
public function set_to_process($form_name,$type,$data=array())
|
public function set_to_process($form_name,$type,$data=array())
|
||||||
{
|
{
|
||||||
if (!$form_name || !$type) return;
|
if (!$form_name || !$type) return;
|
||||||
|
|
||||||
$data['type'] = $type;
|
$data['type'] = $type;
|
||||||
|
|
||||||
$this->data['to_process'][$form_name] = $data;
|
$this->data['to_process'][$form_name] = $data;
|
||||||
$this->data_modified = true;
|
$this->data_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an attribute of a to-process record
|
||||||
|
*
|
||||||
|
* @param string $form_name form-name
|
||||||
|
* @param string $attribute etemplate type
|
||||||
|
* @param array $value
|
||||||
|
* @param boolean $add_to_array=false should $value be added to the attribute array
|
||||||
|
*/
|
||||||
|
public function set_to_process_attribute($form_name,$attribute,$value,$add_to_array=false)
|
||||||
|
{
|
||||||
|
if (!$form_name) return;
|
||||||
|
|
||||||
|
if ($add_to_array)
|
||||||
|
{
|
||||||
|
$this->data['to_process'][$form_name][$attribute][] = $value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->data['to_process'][$form_name][$attribute] = $value;
|
||||||
|
}
|
||||||
|
$this->data_modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister a form-variable to be no longer processed
|
* Unregister a form-variable to be no longer processed
|
||||||
*
|
*
|
||||||
@ -122,7 +234,7 @@ class etemplate_request
|
|||||||
unset($this->data['to_process'][$form_name]);
|
unset($this->data['to_process'][$form_name]);
|
||||||
$this->data_modified = true;
|
$this->data_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the data of a form-var to process or the whole array
|
* return the data of a form-var to process or the whole array
|
||||||
*
|
*
|
||||||
@ -133,7 +245,7 @@ class etemplate_request
|
|||||||
{
|
{
|
||||||
return $form_name ? $this->data['to_process'][$form_name] : $this->data['to_process'];
|
return $form_name ? $this->data['to_process'][$form_name] : $this->data['to_process'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if something set for a given $form_name
|
* check if something set for a given $form_name
|
||||||
*
|
*
|
||||||
@ -144,14 +256,14 @@ class etemplate_request
|
|||||||
{
|
{
|
||||||
return isset($this->data['to_process'][$form_name]);
|
return isset($this->data['to_process'][$form_name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* magic function to set all request-vars, used eg. as $request->method = 'app.class.method';
|
* magic function to set all request-vars, used eg. as $request->method = 'app.class.method';
|
||||||
*
|
*
|
||||||
* @param string $var
|
* @param string $var
|
||||||
* @param mixed $val
|
* @param mixed $val
|
||||||
*/
|
*/
|
||||||
function __set($var,$val)
|
public function __set($var,$val)
|
||||||
{
|
{
|
||||||
if ($this->data[$var] !== $val)
|
if ($this->data[$var] !== $val)
|
||||||
{
|
{
|
||||||
@ -159,90 +271,112 @@ class etemplate_request
|
|||||||
$this->data_modified = true;
|
$this->data_modified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* magic function to access the request-vars, used eg. as $method = $request->method;
|
* magic function to access the request-vars, used eg. as $method = $request->method;
|
||||||
*
|
*
|
||||||
* @param string $var
|
* @param string $var
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function __get($var)
|
public function &__get($var)
|
||||||
{
|
{
|
||||||
return $this->data[$var];
|
return $this->data[$var];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new request-id via microtime()
|
* Get the names / keys of existing variables
|
||||||
*
|
*
|
||||||
* @return string
|
* @return array
|
||||||
*/
|
*/
|
||||||
static function request_id()
|
public function names()
|
||||||
{
|
{
|
||||||
list($msec,$sec) = explode(' ',microtime());
|
return array_keys($this->data);
|
||||||
$time = 100 * $sec + (int)(100 * $msec); // gives precision of 1/100 sec
|
|
||||||
$id = $GLOBALS['egw_info']['flags']['currentapp'] .':'. $time;
|
|
||||||
|
|
||||||
return $id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saves content,readonlys,template-keys, ... via eGW's appsession function
|
* Output the size-wise important parts of a request
|
||||||
*
|
*
|
||||||
* As a user may open several windows with the same content/template wie generate a location-id from microtime
|
* @param double $min_share minimum share to be reported (in percent of the whole request)
|
||||||
* which is used as location for request to descriminate between the different windows. This location-id
|
* @param double $dump_share minimum share from which on a variable get output
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
function __destruct()
|
public function debug($min_share=1.0,$dump_share=25.0)
|
||||||
{
|
{
|
||||||
if ($this->data_modified) $GLOBALS['egw']->session->appsession($this->id,'etemplate',$this->data);
|
echo "<p><b>total size request data = ".($total=strlen(serialize($this->data)))."</b></p>\n";
|
||||||
|
echo "<p>shares bigger then $min_share% percent of it:</p>\n";
|
||||||
if (substr($GLOBALS['egw_info']['server']['sessions_type'],0,4) == 'php4' && !$this->garbage_collection_done)
|
foreach($this->data as $key => $val)
|
||||||
{
|
{
|
||||||
$this->_php4_request_garbage_collection();
|
$len = strlen(is_array($val) ? serialize($val) : $val);
|
||||||
}
|
$len .= ' ('.sprintf('%2.1lf',($percent = 100.0 * $len / $total)).'%)';
|
||||||
}
|
if ($percent < $min_share) continue;
|
||||||
|
echo "<p><b>$key</b>: strlen(\$val)=$len</p>\n";
|
||||||
/**
|
if ($percent >= $dump_share) _debug_array($val);
|
||||||
* a little bit of garbage collection for php4 sessions (their size is limited by memory_limit)
|
if (is_array($val) && $len > 2000)
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
private function _php4_request_garbage_collection()
|
|
||||||
{
|
|
||||||
// now we are on php4 sessions and do a bit of garbage collection
|
|
||||||
$appsessions =& $_SESSION[EGW_SESSION_VAR]['appsessions']['etemplate'];
|
|
||||||
$session_used =& $appsessions['session_used'];
|
|
||||||
|
|
||||||
if ($this->id)
|
|
||||||
{
|
|
||||||
//echo "session_used[$id_used]='".$session_used[$id_used]."'<br/>\n";
|
|
||||||
++$session_used[$this->id]; // count the number of times a session got used
|
|
||||||
}
|
|
||||||
$this->garbage_collection_done = true;
|
|
||||||
|
|
||||||
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($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($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";
|
foreach($val as $k => $v)
|
||||||
unset($appsessions[$id]);
|
{
|
||||||
unset($session_used[$id]);
|
$l = strlen(is_array($v) ? serialize($v) : $v);
|
||||||
|
$l .= ' ('.sprintf('%2.1lf',($p = 100.0 * $l / $total)).'%)';
|
||||||
|
if ($p < $min_share) continue;
|
||||||
|
echo "<p> - {$key}[$k]: strlen(\$v)=$l</p>\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if session encryption is configured, possible and initialise it
|
||||||
|
*
|
||||||
|
* @param string $algo='tripledes'
|
||||||
|
* @param string $mode='ecb'
|
||||||
|
* @return boolean true if encryption is used, false otherwise
|
||||||
|
*/
|
||||||
|
static public function init_crypt($algo='tripledes',$mode='ecb')
|
||||||
|
{
|
||||||
|
if (is_null(self::$mcrypt))
|
||||||
|
{
|
||||||
|
if (isset($GLOBALS['egw_info']['server']['etemplate_form_key']))
|
||||||
|
{
|
||||||
|
$key = $GLOBALS['egw_info']['server']['etemplate_form_key'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$key = $GLOBALS['egw_info']['server']['db_pass'].EGW_SERVER_ROOT;
|
||||||
|
}
|
||||||
|
if (!extension_loaded('mcrypt') && (!function_exists('dl') || !@dl(PHP_SHLIB_PREFIX.'mcrypt'.'.'.PHP_SHLIB_SUFFIX)))
|
||||||
|
{
|
||||||
|
error_log(__METHOD__."() required PHP extension mcrypt not loaded and can not be loaded, eTemplate requests get NOT encrypted!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!(self::$mcrypt = mcrypt_module_open($algo, '', $mode, '')))
|
||||||
|
{
|
||||||
|
error_log(__METHOD__."() could not mcrypt_module_open(algo='$algo','',mode='$mode',''), eTemplate requests get NOT encrypted!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$iv_size = mcrypt_enc_get_iv_size(self::$mcrypt);
|
||||||
|
$iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ?
|
||||||
|
mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size);
|
||||||
|
|
||||||
|
$key_size = mcrypt_enc_get_key_size(self::$mcrypt);
|
||||||
|
if (strlen($key) > $key_size) $key = substr($key,0,$key_size);
|
||||||
|
|
||||||
|
if (mcrypt_generic_init(self::$mcrypt,$key, $iv) < 0)
|
||||||
|
{
|
||||||
|
error_log(__METHOD__."() could not initialise mcrypt, sessions get NOT encrypted!");
|
||||||
|
return self::$mcrypt = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return is_resource(self::$mcrypt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor
|
||||||
|
*/
|
||||||
|
function __destruct()
|
||||||
|
{
|
||||||
|
if (self::$mcrypt)
|
||||||
|
{
|
||||||
|
mcrypt_generic_deinit(self::$mcrypt);
|
||||||
|
self::$mcrypt = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
171
etemplate/inc/class.etemplate_request_session.inc.php
Normal file
171
etemplate/inc/class.etemplate_request_session.inc.php
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* eGroupWare - eTemplate request object storing the data in the session
|
||||||
|
*
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
|
* @package etemplate
|
||||||
|
* @subpackage api
|
||||||
|
* @link http://www.egroupware.org
|
||||||
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||||
|
* @copyright (c) 2007-9 by Ralf Becker <RalfBecker@outdoor-training.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to represent the persitent information stored on the server for each eTemplate request
|
||||||
|
*
|
||||||
|
* The information is stored in the users session, which causes the session to constantly grow.
|
||||||
|
* We implement here some garbadge collection to remove old requests.
|
||||||
|
*
|
||||||
|
* The request object should be instancated only via the factory method etemplate_request::read($id=null)
|
||||||
|
*
|
||||||
|
* $request = etemplate_request::read();
|
||||||
|
*
|
||||||
|
* // add request data
|
||||||
|
*
|
||||||
|
* $id = $request->id();
|
||||||
|
*
|
||||||
|
* b) open or modify an existing request:
|
||||||
|
*
|
||||||
|
* if (!($request = etemplate_request::read($id)))
|
||||||
|
* {
|
||||||
|
* // request not found
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* Ajax requests can use this object to open the original request by using the id, they have to transmitt back,
|
||||||
|
* and register further variables, modify the registered ones or delete them AND then update the id, if it changed:
|
||||||
|
*
|
||||||
|
* if (($new_id = $request->id()) != $id)
|
||||||
|
* {
|
||||||
|
* $response->addAssign('etemplate_exec_id','value',$new_id);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* For an example look in link_widget::ajax_search()
|
||||||
|
*/
|
||||||
|
class etemplate_request_session extends etemplate_request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* request id
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor to force the instancation of this class only via it's static factory method read
|
||||||
|
*
|
||||||
|
* @param array $id
|
||||||
|
*/
|
||||||
|
private function __construct($id=null)
|
||||||
|
{
|
||||||
|
if (!$id) $id = self::request_id();
|
||||||
|
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return the id of this request
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function id()
|
||||||
|
{
|
||||||
|
//error_log(__METHOD__."() id=$this->id");
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to get a new request object or the one for an existing request
|
||||||
|
*
|
||||||
|
* @param string $id=null
|
||||||
|
* @return etemplate_request|boolean the object or false if $id is not found
|
||||||
|
*/
|
||||||
|
static function read($id=null)
|
||||||
|
{
|
||||||
|
$request = new etemplate_request_session($id);
|
||||||
|
|
||||||
|
if (!is_null($id))
|
||||||
|
{
|
||||||
|
if (!($data = $GLOBALS['egw']->session->appsession($id,'etemplate')))
|
||||||
|
{
|
||||||
|
return false; // request not found
|
||||||
|
}
|
||||||
|
$request->data = $data;
|
||||||
|
}
|
||||||
|
//error_log(__METHOD__."(id=$id");
|
||||||
|
return $request;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a new request-id via microtime()
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static function request_id()
|
||||||
|
{
|
||||||
|
$time = (int) (100 * microtime(true)); // gives precision of 1/100 sec
|
||||||
|
$id = $GLOBALS['egw_info']['flags']['currentapp'] .':'. $time;
|
||||||
|
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
function __destruct()
|
||||||
|
{
|
||||||
|
if ($this->data_modified) $GLOBALS['egw']->session->appsession($this->id,'etemplate',$this->data);
|
||||||
|
|
||||||
|
if (!$this->garbage_collection_done)
|
||||||
|
{
|
||||||
|
$this->_php4_request_garbage_collection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
protected function _php4_request_garbage_collection()
|
||||||
|
{
|
||||||
|
// now we are on php4 sessions and do a bit of garbage collection
|
||||||
|
$appsessions =& $_SESSION[egw_session::EGW_APPSESSION_VAR]['etemplate'];
|
||||||
|
$session_used =& $appsessions['session_used'];
|
||||||
|
|
||||||
|
if ($this->id)
|
||||||
|
{
|
||||||
|
//echo "session_used[$id_used]='".$session_used[$id_used]."'<br/>\n";
|
||||||
|
++$session_used[$this->id]; // count the number of times a session got used
|
||||||
|
}
|
||||||
|
$this->garbage_collection_done = true;
|
||||||
|
|
||||||
|
if (count($appsessions) < 20) return; // we dont need to care
|
||||||
|
|
||||||
|
$now = (int) (100 * microtime(true)); // gives precision of 1/100 sec
|
||||||
|
|
||||||
|
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($appsessions[$id])."<br>\n";
|
||||||
|
|
||||||
|
if ($session_used[$id] == 1 && $time < $now - 10*6000 || // session used and older then 10min
|
||||||
|
$time < $now - 30*6000) // session not used and older then 30min
|
||||||
|
{
|
||||||
|
//echo "<p>boetemplate::php4_session_garbage_collection('$id_used'): unsetting session '$id' (now=$now)</p>\n";
|
||||||
|
unset($appsessions[$id]);
|
||||||
|
unset($session_used[$id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
* @subpackage extensions
|
* @subpackage extensions
|
||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||||
|
* @copyright 2002-9 by RalfBecker@outdoor-training.de
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -114,6 +115,7 @@ class link_widget
|
|||||||
// readonly ==> omit the whole widget
|
// readonly ==> omit the whole widget
|
||||||
$value = '';
|
$value = '';
|
||||||
$cell = $tmpl->empty_cell();
|
$cell = $tmpl->empty_cell();
|
||||||
|
$extension_data = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!is_array($value) && in_array($type,array('link-to','link-list','link-add')))
|
if (!is_array($value) && in_array($type,array('link-to','link-list','link-add')))
|
||||||
@ -133,6 +135,7 @@ class link_widget
|
|||||||
{
|
{
|
||||||
case 'link':
|
case 'link':
|
||||||
$cell['readonly'] = True; // set it readonly to NOT call our post_process function
|
$cell['readonly'] = True; // set it readonly to NOT call our post_process function
|
||||||
|
$extension_data = null;
|
||||||
$cell['no_lang'] = 1;
|
$cell['no_lang'] = 1;
|
||||||
$link = $target = $popup = '';
|
$link = $target = $popup = '';
|
||||||
if (!is_array($value) && $value && isset($GLOBALS['egw_info']['apps'][$cell['size']]))
|
if (!is_array($value) && $value && isset($GLOBALS['egw_info']['apps'][$cell['size']]))
|
||||||
@ -152,7 +155,7 @@ class link_widget
|
|||||||
$link .= '&'.$var.'='.$val;
|
$link .= '&'.$var.'='.$val;
|
||||||
}
|
}
|
||||||
if (!($popup = egw_link::is_popup($value['app'],'view')) &&
|
if (!($popup = egw_link::is_popup($value['app'],'view')) &&
|
||||||
$GLOBALS['egw_info']['etemplate']['output_mode'] == 2) // we are in a popup
|
etemplate::$request->output_mode == 2) // we are in a popup
|
||||||
{
|
{
|
||||||
$target = '_blank';
|
$target = '_blank';
|
||||||
}
|
}
|
||||||
@ -166,6 +169,7 @@ class link_widget
|
|||||||
{
|
{
|
||||||
$cell = $tmpl->empty_cell();
|
$cell = $tmpl->empty_cell();
|
||||||
$cell['readonly'] = True; // set it readonly to NOT call our post_process function
|
$cell['readonly'] = True; // set it readonly to NOT call our post_process function
|
||||||
|
$extension_data = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$cell['type'] = 'label';
|
$cell['type'] = 'label';
|
||||||
@ -208,7 +212,7 @@ class link_widget
|
|||||||
list($w,$h) = explode('x',$popup);
|
list($w,$h) = explode('x',$popup);
|
||||||
$options = ' onclick="window.open(this,this.target,\'width='.(int)$w.',height='.(int)$h.',location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\'); return false;"';
|
$options = ' onclick="window.open(this,this.target,\'width='.(int)$w.',height='.(int)$h.',location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\'); return false;"';
|
||||||
}
|
}
|
||||||
elseif ($GLOBALS['egw_info']['etemplate']['output_mode'] == 2 || // we are in a popup
|
elseif (etemplate::$request->output_mode == 2 || // we are in a popup
|
||||||
$link['app'] == egw_link::VFS_APPNAME) // or it's a link to an attachment
|
$link['app'] == egw_link::VFS_APPNAME) // or it's a link to an attachment
|
||||||
{
|
{
|
||||||
$options = ' target="_blank"';
|
$options = ' target="_blank"';
|
||||||
@ -220,6 +224,7 @@ class link_widget
|
|||||||
}
|
}
|
||||||
$cell['type'] = 'html';
|
$cell['type'] = 'html';
|
||||||
$cell['readonly'] = True; // set it readonly to NOT call our post_process function
|
$cell['readonly'] = True; // set it readonly to NOT call our post_process function
|
||||||
|
$extension_data = null;
|
||||||
$value = $str;
|
$value = $str;
|
||||||
return True;
|
return True;
|
||||||
|
|
||||||
@ -292,7 +297,7 @@ class link_widget
|
|||||||
{
|
{
|
||||||
$value[$row]['view'] = egw_link::view($link['app'],$link['id'],$link);
|
$value[$row]['view'] = egw_link::view($link['app'],$link['id'],$link);
|
||||||
if (!($value[$row]['popup'] = egw_link::is_popup($link['app'],'view')) &&
|
if (!($value[$row]['popup'] = egw_link::is_popup($link['app'],'view')) &&
|
||||||
$GLOBALS['egw_info']['etemplate']['output_mode'] == 2) // we are in a popup
|
etemplate::$request->output_mode == 2) // we are in a popup
|
||||||
{
|
{
|
||||||
$value[$row]['target'] = '_blank'; // we create a new window as the linked page is no popup
|
$value[$row]['target'] = '_blank'; // we create a new window as the linked page is no popup
|
||||||
}
|
}
|
||||||
@ -656,12 +661,17 @@ class link_widget
|
|||||||
$response->addScript($script);
|
$response->addScript($script);
|
||||||
}
|
}
|
||||||
// store new allowed id's in the eT request
|
// store new allowed id's in the eT request
|
||||||
if ($etemplate_exec_id && ($et_request = etemplate_request::read($etemplate_exec_id)))
|
if ($etemplate_exec_id && ($request = etemplate_request::read($etemplate_exec_id)))
|
||||||
{
|
{
|
||||||
$data = $et_request->get_to_process($id_res);
|
$data = $request->get_to_process($id_res);
|
||||||
//error_log($id_res.'='.array2string($data));
|
//error_log($id_res.'='.array2string($data));
|
||||||
$data['allowed'] = $found ? array_keys($found) : array();
|
$data['allowed'] = $found ? array_keys($found) : array();
|
||||||
$et_request->set_to_process($id_res,$data);
|
$request->set_to_process($id_res,$data);
|
||||||
|
// update id, if request changed it (happens if the request data is stored direct in the form)
|
||||||
|
if ($etemplate_exec_id != ($new_id = $request->id()))
|
||||||
|
{
|
||||||
|
$response->addAssign('etemplate_exec_id','value',$new_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $response->getXML();
|
return $response->getXML();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* eGroupWare eTemplate Extension - Nextmatch Widget
|
* eGroupWare eTemplate Extension - Nextmatch Widget
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
* @copyright 2002-8 by RalfBecker@outdoor-training.de
|
* @copyright 2002-9 by RalfBecker@outdoor-training.de
|
||||||
* @package etemplate
|
* @package etemplate
|
||||||
* @subpackage extensions
|
* @subpackage extensions
|
||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
@ -11,8 +11,6 @@
|
|||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(EGW_INCLUDE_ROOT. '/etemplate/inc/class.etemplate.inc.php');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eTemplate Extension: Widget that show only a certain number of data-rows and allows to modifiy the rows shown (scroll).
|
* eTemplate Extension: Widget that show only a certain number of data-rows and allows to modifiy the rows shown (scroll).
|
||||||
*
|
*
|
||||||
@ -313,7 +311,7 @@ class nextmatch_widget
|
|||||||
$rows = array();
|
$rows = array();
|
||||||
if (!is_object($obj) || !method_exists($obj,$method))
|
if (!is_object($obj) || !method_exists($obj,$method))
|
||||||
{
|
{
|
||||||
$GLOBALS['egw_info']['etemplate']['validation_errors'][$name] = "nextmatch_widget::pre_process($cell[name]): '$value[get_rows]' is no valid method !!!";
|
etemplate::set_validation_error($name,"nextmatch_widget::pre_process($cell[name]): '$value[get_rows]' is no valid method !!!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -393,7 +391,7 @@ class nextmatch_widget
|
|||||||
{
|
{
|
||||||
// make each letter internally behave like a button
|
// make each letter internally behave like a button
|
||||||
$form_name = $name.'[searchletter]['.($key === 'all' ? $key : $letter).']';
|
$form_name = $name.'[searchletter]['.($key === 'all' ? $key : $letter).']';
|
||||||
$GLOBALS['egw_info']['etemplate']['to_process'][$form_name] = 'button';
|
etemplate::$request->set_to_process($form_name,'button');
|
||||||
|
|
||||||
if (!$key) $letterbox =& $lettersearch[1]; // to re-use the first child
|
if (!$key) $letterbox =& $lettersearch[1]; // to re-use the first child
|
||||||
$letterbox = etemplate::empty_cell('label',$letter,array(
|
$letterbox = etemplate::empty_cell('label',$letter,array(
|
||||||
@ -402,13 +400,13 @@ class nextmatch_widget
|
|||||||
$key === 'all' && !$value['searchletter'] ? '_active' : ''),
|
$key === 'all' && !$value['searchletter'] ? '_active' : ''),
|
||||||
'no_lang' => 2,
|
'no_lang' => 2,
|
||||||
'align' => $key == 'all' ? 'right' : '',
|
'align' => $key == 'all' ? 'right' : '',
|
||||||
'onclick' => "return submitit($tmpl->name_form,'$form_name');",
|
'onclick' => 'return submitit('.etemplate::$name_form.",'$form_name');",
|
||||||
));
|
));
|
||||||
// if not the first (re-used) child, add it to the parent
|
// if not the first (re-used) child, add it to the parent
|
||||||
if ($key) etemplate::add_child($lettersearch,$letterbox);
|
if ($key) etemplate::add_child($lettersearch,$letterbox);
|
||||||
unset($letterbox);
|
unset($letterbox);
|
||||||
}
|
}
|
||||||
//_debug_array($GLOBALS['egw_info']['etemplate']['to_process']);
|
//_debug_array(etemplate::$request->to_process);
|
||||||
}
|
}
|
||||||
if(isset($value['no_search'])) $value['no_start_search'] = $value['no_search'];
|
if(isset($value['no_search'])) $value['no_start_search'] = $value['no_search'];
|
||||||
foreach(array('no_cat'=>'cat_id','no_filter'=>'filter','no_filter2'=>'filter2', 'no_search' => 'search', 'no_start_search' => 'start_search' ) as $val_name => $cell_name)
|
foreach(array('no_cat'=>'cat_id','no_filter'=>'filter','no_filter2'=>'filter2', 'no_search' => 'search', 'no_start_search' => 'start_search' ) as $val_name => $cell_name)
|
||||||
@ -896,7 +894,7 @@ class nextmatch_widget
|
|||||||
}
|
}
|
||||||
if (!is_object($obj) || !method_exists($obj,$method))
|
if (!is_object($obj) || !method_exists($obj,$method))
|
||||||
{
|
{
|
||||||
$GLOBALS['egw_info']['etemplate']['validation_errors'][$name] = "nextmatch_widget::pre_process($cell[name]): '$value[get_rows]' is no valid method !!!";
|
etemplate::set_validation_error($name,"nextmatch_widget::pre_process($cell[name]): '$value[get_rows]' is no valid method !!!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->charset = $this->charset_out = $GLOBALS['egw']->translation->charset();
|
$this->charset = $this->charset_out = $GLOBALS['egw']->translation->charset();
|
||||||
@ -922,7 +920,7 @@ class nextmatch_widget
|
|||||||
}
|
}
|
||||||
if ($export_limit && (!is_numeric($export_limit) || $export_limit < $total))
|
if ($export_limit && (!is_numeric($export_limit) || $export_limit < $total))
|
||||||
{
|
{
|
||||||
$GLOBALS['egw_info']['etemplate']['validation_errors'][$name] = lang('You are not allowed to export more then %1 entries!',$export_limit);
|
etemplate::set_validation_error($name,lang('You are not allowed to export more then %1 entries!',$export_limit));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!isset($value['no_csv_support'])) $value['no_csv_support'] = !is_array($value['csv_fields']);
|
if (!isset($value['no_csv_support'])) $value['no_csv_support'] = !is_array($value['csv_fields']);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||||
* @copyright 2002-8 by RalfBecker@outdoor-training.de
|
* @copyright 2002-9 by RalfBecker@outdoor-training.de
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
* @package etemplate
|
* @package etemplate
|
||||||
* @subpackage api
|
* @subpackage api
|
||||||
@ -30,20 +30,20 @@
|
|||||||
*/
|
*/
|
||||||
class soetemplate
|
class soetemplate
|
||||||
{
|
{
|
||||||
var $debug; // =1 show some debug-messages, = 'app.name' show messages only for eTemplate 'app.name'
|
public $debug; // =1 show some debug-messages, = 'app.name' show messages only for eTemplate 'app.name'
|
||||||
var $name; // name of the template, e.g. 'infolog.edit'
|
public $name; // name of the template, e.g. 'infolog.edit'
|
||||||
var $template; // '' = default (not 'default')
|
public $template; // '' = default (not 'default')
|
||||||
var $lang; // '' if general template else language short, e.g. 'de'
|
public $lang; // '' if general template else language short, e.g. 'de'
|
||||||
var $group; // 0 = not specific else groupId or if < 0 userId
|
public $group; // 0 = not specific else groupId or if < 0 userId
|
||||||
var $version; // like 0.9.13.001
|
public $version; // like 0.9.13.001
|
||||||
var $style; // embeded CSS style-sheet
|
public $style; // embeded CSS style-sheet
|
||||||
var $children; // array with children
|
public $children; // array with children
|
||||||
var $data; // depricated: first grid of the children
|
public $data; // depricated: first grid of the children
|
||||||
var $size; // depricated: witdh,height,border of first grid
|
public $size; // depricated: witdh,height,border of first grid
|
||||||
/**
|
/**
|
||||||
* private reference to the global db-object
|
* private reference to the global db-object
|
||||||
*
|
*
|
||||||
* @var egw_db
|
* @public egw_db
|
||||||
*/
|
*/
|
||||||
private $db;
|
private $db;
|
||||||
/**
|
/**
|
||||||
@ -68,7 +68,7 @@ class soetemplate
|
|||||||
* widgets that contain other widgets, eg. for tree_walk method
|
* widgets that contain other widgets, eg. for tree_walk method
|
||||||
* widget-type is the key, the value specifys how the children are stored.
|
* widget-type is the key, the value specifys how the children are stored.
|
||||||
*
|
*
|
||||||
* @var array
|
* @public array
|
||||||
*/
|
*/
|
||||||
static $widgets_with_children = array(
|
static $widgets_with_children = array(
|
||||||
'template' => 'template',
|
'template' => 'template',
|
||||||
@ -94,9 +94,9 @@ class soetemplate
|
|||||||
* @param int $cols initial size of the template, default 1, only used if no name given !!!
|
* @param int $cols initial size of the template, default 1, only used if no name given !!!
|
||||||
* @return soetemplate
|
* @return soetemplate
|
||||||
*/
|
*/
|
||||||
function soetemplate($name='',$template='',$lang='',$group=0,$version='',$rows=1,$cols=1)
|
function __construct($name='',$template='',$lang='',$group=0,$version='',$rows=1,$cols=1)
|
||||||
{
|
{
|
||||||
if (is_object($GLOBALS['egw']->db))
|
if (isset($GLOBALS['egw']->db))
|
||||||
{
|
{
|
||||||
$this->db = $GLOBALS['egw']->db;
|
$this->db = $GLOBALS['egw']->db;
|
||||||
}
|
}
|
||||||
@ -674,6 +674,8 @@ class soetemplate
|
|||||||
$this->set_rows_cols();
|
$this->set_rows_cols();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static private $compress_array_recursion = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* all empty values and objects in the array got unset (to save space in the db )
|
* all empty values and objects in the array got unset (to save space in the db )
|
||||||
*
|
*
|
||||||
@ -686,6 +688,8 @@ class soetemplate
|
|||||||
*/
|
*/
|
||||||
function compress_array($arr,$remove_objs=false)
|
function compress_array($arr,$remove_objs=false)
|
||||||
{
|
{
|
||||||
|
static $recursion = array();
|
||||||
|
|
||||||
if (!is_array($arr))
|
if (!is_array($arr))
|
||||||
{
|
{
|
||||||
return $arr;
|
return $arr;
|
||||||
@ -702,7 +706,7 @@ class soetemplate
|
|||||||
}
|
}
|
||||||
elseif (!$remove_objs && $key == 'obj' && is_object($val) && method_exists($val,'as_array') &&
|
elseif (!$remove_objs && $key == 'obj' && is_object($val) && method_exists($val,'as_array') &&
|
||||||
// this test prevents an infinit recursion of templates calling itself, atm. etemplate.editor.new
|
// this test prevents an infinit recursion of templates calling itself, atm. etemplate.editor.new
|
||||||
$GLOBALS['egw_info']['etemplate']['as_array'][$this->name]++ < 2)
|
self::$compress_array_recursion[$this->name]++ < 2)
|
||||||
{
|
{
|
||||||
$arr['obj'] = $val->as_array(2);
|
$arr['obj'] = $val->as_array(2);
|
||||||
}
|
}
|
||||||
@ -1077,6 +1081,8 @@ class soetemplate
|
|||||||
return lang("%1 new eTemplates imported for Application '%2'",$n,$app);
|
return lang("%1 new eTemplates imported for Application '%2'",$n,$app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static private $import_tested = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test if new template-import necessary for app and does the import
|
* test if new template-import necessary for app and does the import
|
||||||
*
|
*
|
||||||
@ -1090,11 +1096,11 @@ class soetemplate
|
|||||||
{
|
{
|
||||||
list($app) = explode('.',$app);
|
list($app) = explode('.',$app);
|
||||||
|
|
||||||
if (!$app || $GLOBALS['egw_info']['etemplate']['import_tested'][$app])
|
if (!$app || self::$import_tested[$app])
|
||||||
{
|
{
|
||||||
return ''; // ensure test is done only once per call and app
|
return ''; // ensure test is done only once per call and app
|
||||||
}
|
}
|
||||||
$GLOBALS['egw_info']['etemplate']['import_tested'][$app] = True; // need to be done before new ...
|
self::$import_tested[$app] = True; // need to be done before new ...
|
||||||
|
|
||||||
$path = EGW_SERVER_ROOT."/$app/setup/etemplates.inc.php";
|
$path = EGW_SERVER_ROOT."/$app/setup/etemplates.inc.php";
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eTemplate Extension: widget that shows one row of tabs and an other row with the eTemplate of the selected tab
|
* eTemplate Extension: widget that shows one row of tabs and an other row with the eTemplate of the selected tab
|
||||||
*
|
*
|
||||||
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
class tab_widget
|
class tab_widget
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* exported methods of this class
|
* exported methods of this class
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -32,7 +32,7 @@
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $human_name = 'Tabs'; // this is the name for the editor
|
var $human_name = 'Tabs'; // this is the name for the editor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of the extension
|
* Constructor of the extension
|
||||||
*
|
*
|
||||||
@ -41,7 +41,7 @@
|
|||||||
function tab_widget($ui)
|
function tab_widget($ui)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pre-processing of the extension
|
* pre-processing of the extension
|
||||||
*
|
*
|
||||||
@ -49,7 +49,7 @@
|
|||||||
*
|
*
|
||||||
* @param string $name form-name of the control
|
* @param string $name form-name of the control
|
||||||
* @param mixed &$value value / existing content, can be modified
|
* @param mixed &$value value / existing content, can be modified
|
||||||
* @param array &$cell array with the widget, can be modified for ui-independent widgets
|
* @param array &$cell array with the widget, can be modified for ui-independent widgets
|
||||||
* @param array &$readonlys names of widgets as key, to be made readonly
|
* @param array &$readonlys names of widgets as key, to be made readonly
|
||||||
* @param mixed &$extension_data data the extension can store persisten between pre- and post-process
|
* @param mixed &$extension_data data the extension can store persisten between pre- and post-process
|
||||||
* @param object &$tmpl reference to the template we belong too
|
* @param object &$tmpl reference to the template we belong too
|
||||||
@ -58,10 +58,10 @@
|
|||||||
function pre_process($form_name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
function pre_process($form_name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
||||||
{
|
{
|
||||||
//echo "<p>tab_widget::pre_process('$form_name',$value,,$extension_data)</p>\n";
|
//echo "<p>tab_widget::pre_process('$form_name',$value,,$extension_data)</p>\n";
|
||||||
|
|
||||||
if (!$cell['onchange']) // onchange allows to use the old behavior (submit for each new tab)
|
if (!$cell['onchange']) // onchange allows to use the old behavior (submit for each new tab)
|
||||||
{
|
{
|
||||||
$dom_enabled = isset($GLOBALS['egw_info']['etemplate']['dom_enabled']) ? $GLOBALS['egw_info']['etemplate']['dom_enabled'] : true;
|
$dom_enabled = true;
|
||||||
}
|
}
|
||||||
$labels = explode('|',$cell['label']);
|
$labels = explode('|',$cell['label']);
|
||||||
$helps = explode('|',$cell['help']);
|
$helps = explode('|',$cell['help']);
|
||||||
@ -85,10 +85,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$all_names = implode('|',$names);
|
$all_names = implode('|',$names);
|
||||||
|
|
||||||
$tab_widget =& new etemplate('etemplate.tab_widget');
|
$tab_widget =& new etemplate('etemplate.tab_widget');
|
||||||
$tab_widget->no_onclick = true;
|
$tab_widget->no_onclick = true;
|
||||||
|
|
||||||
if ($value && strpos($value,'.') === false)
|
if ($value && strpos($value,'.') === false)
|
||||||
{
|
{
|
||||||
$value = $tmpl->name . '.' . $value;
|
$value = $tmpl->name . '.' . $value;
|
||||||
@ -109,7 +109,7 @@
|
|||||||
$value = $selected_tab = $names[0];
|
$value = $selected_tab = $names[0];
|
||||||
}
|
}
|
||||||
$extension_data = $value; // remember the active tab in the extension_data
|
$extension_data = $value; // remember the active tab in the extension_data
|
||||||
|
|
||||||
foreach($names as $k => $name)
|
foreach($names as $k => $name)
|
||||||
{
|
{
|
||||||
if (strpos($name,'.') === false)
|
if (strpos($name,'.') === false)
|
||||||
@ -138,13 +138,13 @@
|
|||||||
}
|
}
|
||||||
$tcell['label'] = $labels[$k];
|
$tcell['label'] = $labels[$k];
|
||||||
$tcell['help'] = $helps[$k];
|
$tcell['help'] = $helps[$k];
|
||||||
|
|
||||||
$tab_widget->set_cell_attribute('tabs',1+$k,$tcell);
|
$tab_widget->set_cell_attribute('tabs',1+$k,$tcell);
|
||||||
}
|
}
|
||||||
$tab_widget->set_cell_attribute('tabs','type','hbox');
|
$tab_widget->set_cell_attribute('tabs','type','hbox');
|
||||||
$tab_widget->set_cell_attribute('tabs','size',count($names));
|
$tab_widget->set_cell_attribute('tabs','size',count($names));
|
||||||
$tab_widget->set_cell_attribute('tabs','name','');
|
$tab_widget->set_cell_attribute('tabs','name','');
|
||||||
|
|
||||||
if ($dom_enabled)
|
if ($dom_enabled)
|
||||||
{
|
{
|
||||||
foreach($names as $n => $name)
|
foreach($names as $n => $name)
|
||||||
@ -166,14 +166,14 @@
|
|||||||
$tab_widget->set_cell_attribute('body','obj',$stab);
|
$tab_widget->set_cell_attribute('body','obj',$stab);
|
||||||
}
|
}
|
||||||
$tab_widget->set_cell_attribute('body','name',$selected_tab);
|
$tab_widget->set_cell_attribute('body','name',$selected_tab);
|
||||||
|
|
||||||
$cell['type'] = 'template';
|
$cell['type'] = 'template';
|
||||||
$cell['obj'] = &$tab_widget;
|
$cell['obj'] = &$tab_widget;
|
||||||
$cell['label'] = $cell['help'] = '';
|
$cell['label'] = $cell['help'] = '';
|
||||||
|
|
||||||
return False; // NO extra Label
|
return False; // NO extra Label
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* postprocessing method, called after the submission of the form
|
* postprocessing method, called after the submission of the form
|
||||||
*
|
*
|
||||||
@ -194,7 +194,7 @@
|
|||||||
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
||||||
{
|
{
|
||||||
//echo "<p>tab_widget::post_process($name): value_in = "; _debug_array($value_in);
|
//echo "<p>tab_widget::post_process($name): value_in = "; _debug_array($value_in);
|
||||||
|
|
||||||
if (is_array($value_in))
|
if (is_array($value_in))
|
||||||
{
|
{
|
||||||
foreach ($value_in as $tab => $button_pressed)
|
foreach ($value_in as $tab => $button_pressed)
|
||||||
@ -213,7 +213,7 @@
|
|||||||
// if value not set (other button pressed), set the value we remembered in the extension_data
|
// if value not set (other button pressed), set the value we remembered in the extension_data
|
||||||
if (!$value)
|
if (!$value)
|
||||||
{
|
{
|
||||||
$value = $extension_data;
|
$value = $extension_data;
|
||||||
}
|
}
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
* @param $debug enables debug messages: 0=no, 1=calls to show and process_show, 2=content of process_show
|
* @param $debug enables debug messages: 0=no, 1=calls to show and process_show, 2=content of process_show
|
||||||
* @param 3=calls to show_cell OR template- or cell-type name
|
* @param 3=calls to show_cell OR template- or cell-type name
|
||||||
*/
|
*/
|
||||||
class etemplate extends boetemplate
|
class gtk_etemplate extends boetemplate
|
||||||
{
|
{
|
||||||
var $debug;//='etemplate.editor.edit'; // 1=calls to show and process_show, 2=content after process_show,
|
var $debug;//='etemplate.editor.edit'; // 1=calls to show and process_show, 2=content after process_show,
|
||||||
// 3=calls to show_cell and process_show_cell, or template-name or cell-type
|
// 3=calls to show_cell and process_show_cell, or template-name or cell-type
|
||||||
|
@ -508,7 +508,7 @@
|
|||||||
// save tmpl to the cache, as the file may contain more then one tmpl
|
// save tmpl to the cache, as the file may contain more then one tmpl
|
||||||
$cname = ($etempl->template == '' ? 'default' : $etempl->template).'/'.$etempl->name.
|
$cname = ($etempl->template == '' ? 'default' : $etempl->template).'/'.$etempl->name.
|
||||||
($etempl->lang == '' ? '' : '.'.$etempl->lang);
|
($etempl->lang == '' ? '' : '.'.$etempl->lang);
|
||||||
$GLOBALS['egw_info']['etemplate']['cache'][$cname] = $etempl->as_array(1);
|
boetemplate::$template_cache[$cname] = $etempl->as_array(1);
|
||||||
if ($this->debug)
|
if ($this->debug)
|
||||||
{
|
{
|
||||||
$etempl->echo_tmpl();
|
$etempl->echo_tmpl();
|
||||||
|
Loading…
Reference in New Issue
Block a user