allow to use etemplate apps as sitemgr modules:

- extend etemplate's sitemgr_module class and set the $etemplate_method class-var to a method/menuaction of the app
- the app need to return etemplate::exec() (otherwise the content is empty)!!!
- the app need to avoid redirects or links, as this would leave sitemgr!!!
This commit is contained in:
Ralf Becker 2005-05-02 15:07:37 +00:00
parent ab20fb0a91
commit 434a91f041
2 changed files with 76 additions and 6 deletions

View File

@ -0,0 +1,59 @@
<?php
/**************************************************************************\
* eGroupWare SiteMgr - Baseclass for SiteMgr Modules written with eTemplate*
* http://www.egroupware.org *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
/**
* Baseclass for SiteMgr Modules written with eTemplate
*
* To create a SiteMgr module from an eTemplate app, you need to:
* - extend this class and set the $etemplate_method class-var to a method/menuaction of the app
* - the app need to return etemplate::exec (otherwise the content is empty)!!!
* - the app need to avoid redirects or links, as this would leave sitemgr!!!
*
* @package etemplate
* @subpackage extensions
* @author RalfBecker-AT-outdoor-training.de
* @license GPL
*/
class sitemgr_module extends Module // the Module class get automatic included by SiteMgr
{
/**
* @var string $etemplate_method Method/menuaction of an eTemplate app to be used as module
*/
var $etemplate_method;
/**
* generate the module content AND process submitted forms
*
* @param array &$arguments
* @param array $properties
* @return string the html content
*/
function get_content(&$arguments,$properties)
{
list($app) = explode('.',$this->etemplate_method);
$GLOBALS['egw']->translation->add_app($app);
$css = '';
if (file_exists(EGW_SERVER_ROOT.'/'.$app.'/templates/default/app.css'))
{
$css = "<style type=\"text/css\">\n<!--\n@import url(".
$GLOBALS['egw_info']['server']['webserver_url'].'/'.$app."/templates/default/app.css);\n-->\n</style>";
}
$ret = false;
if($_POST['etemplate_exec_id'])
{
$ret = ExecMethod('etemplate.etemplate.process_exec');
}
return $css.($ret ? $ret : ExecMethod($this->etemplate_method));
}
}

View File

@ -60,6 +60,8 @@
$this->boetemplate($name,$load_via);
$this->xslt = is_object($GLOBALS['phpgw']->xslttpl);
$this->sitemgr = is_object($GLOBALS['Common_BO']);
}
/**
@ -134,9 +136,14 @@
$this->html->input_hidden('submit_button','',False).
$this->show($this->complete_array_merge($content,$changes),$sel_options,$readonlys,'exec'),array(
'etemplate_exec_id' => $id
),'/etemplate/process_exec.php?menuaction='.$method,'','eTemplate',$GLOBALS['phpgw_info']['etemplate']['form_options']);
),$this->sitemgr ? '' : '/etemplate/process_exec.php?menuaction='.$method,
'','eTemplate',$GLOBALS['phpgw_info']['etemplate']['form_options']);
//_debug_array($GLOBALS['phpgw_info']['etemplate']['to_process']);
if (!$this->xslt)
if ($this->sitemgr)
{
}
elseif (!$this->xslt)
{
$hooked = $GLOBALS['phpgw']->template->get_var('phpgw_body');
if (!@$GLOBALS['phpgw_info']['etemplate']['hooked'] && (int) $output_mode != 1) // not just returning the html
@ -156,7 +163,7 @@
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('java_script' => $GLOBALS['phpgw_info']['flags']['java_script'].$this->include_java_script(2)));
}
if ((int) $output_mode != 1) // NOT returning html
if (!$this->sitemgr && (int) $output_mode != 1) // NOT returning html
{
if (!$this->xslt)
{
@ -204,9 +211,10 @@
'output_mode' => $output_mode,
'session_used' => 0,
'ignore_validation' => $ignore_validation,
'method' => $method,
),$id);
if ((int) $output_mode == 1) // return html
if ($this->sitemgr || (int) $output_mode == 1) // return html
{
return $html;
}
@ -247,6 +255,8 @@
* it would set some constants to etemplate instead of the calling app.
* process_exec then calls process_show for the eTemplate (to adjust the content of the _POST) and
* ExecMethod's the given callback from the app with the content of the form as first argument.
*
* @return mixed false if no sessiondata and $this->sitemgr, else the returnvalue of exec of the method-calls
*/
function process_exec()
{
@ -256,6 +266,7 @@
if (!$_POST['etemplate_exec_id'] || !is_array($session_data) || count($session_data) < 10)
{
if ($this->sitemgr) return false;
//echo "uitemplate::process_exec() id='$_POST[etemplate_exec_id]' invalid session-data !!!"; _debug_array($_SESSION);
// this prevents an empty screen, if the sessiondata gets lost somehow
$this->location(array('menuaction' => $_GET['menuaction']));
@ -308,13 +319,13 @@
$GLOBALS['phpgw_info']['flags']['app_header'] = $session_data['app_header'];
}
//echo "<p>process_exec($this->name): <font color=red>loop is set</font>, content=</p>\n"; _debug_array($content);
$this->exec($_GET['menuaction'],$session_data['content'],$session_data['sel_options'],
return $this->exec($session_data['method'],$session_data['content'],$session_data['sel_options'],
$session_data['readonlys'],$session_data['preserv'],$session_data['output_mode'],
$session_data['ignore_validation'],$content);
}
else
{
ExecMethod($_GET['menuaction'],$this->complete_array_merge($session_data['preserv'],$content));
return ExecMethod($session_data['method'],$this->complete_array_merge($session_data['preserv'],$content));
}
}