2002-06-09 23:36:37 +02:00
|
|
|
<?php
|
2006-04-20 19:12:30 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare - eTemplate Extension - Tab Widget
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
2009-01-29 19:31:40 +01:00
|
|
|
* @subpackage extensions
|
2006-04-20 19:12:30 +02:00
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
|
|
|
* eTemplate Extension: widget that shows one row of tabs and an other row with the eTemplate of the selected tab
|
|
|
|
*
|
2005-05-19 15:16:52 +02:00
|
|
|
* See the example in 'etemplate.tab_widget.test'
|
2005-02-22 23:11:00 +01:00
|
|
|
*
|
|
|
|
* This widget is independent of the UI as it only uses etemplate-widgets and has therefor no render-function
|
|
|
|
*/
|
2002-06-09 23:36:37 +02:00
|
|
|
class tab_widget
|
|
|
|
{
|
2009-03-16 13:58:24 +01:00
|
|
|
/**
|
2005-02-22 23:11:00 +01:00
|
|
|
* exported methods of this class
|
|
|
|
* @var array
|
|
|
|
*/
|
2002-06-09 23:36:37 +02:00
|
|
|
var $public_functions = array(
|
|
|
|
'pre_process' => True,
|
2009-10-15 10:48:47 +02:00
|
|
|
'post_process' => True,
|
|
|
|
'noReadonlysALL' => true, // mark extension as not to set readonly for $readonlys['__ALL__']
|
2002-06-09 23:36:37 +02:00
|
|
|
);
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
|
|
|
* availible extensions and there names for the editor
|
|
|
|
* @var string
|
|
|
|
*/
|
2002-06-09 23:36:37 +02:00
|
|
|
var $human_name = 'Tabs'; // this is the name for the editor
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
|
|
|
* Constructor of the extension
|
|
|
|
*
|
|
|
|
* @param string $ui '' for html
|
|
|
|
*/
|
2002-06-09 23:36:37 +02:00
|
|
|
function tab_widget($ui)
|
|
|
|
{
|
|
|
|
}
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2009-03-16 13:58:24 +01:00
|
|
|
* @param array &$cell array with the widget, can be modified for ui-independent widgets
|
2005-02-22 23:11:00 +01:00
|
|
|
* @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
|
2013-10-25 09:30:51 +02:00
|
|
|
* @param etemplate &$tmpl reference to the template we belong too
|
2005-02-22 23:11:00 +01:00
|
|
|
* @return boolean true if extra label is allowed, false otherwise
|
|
|
|
*/
|
2002-10-01 20:26:30 +02:00
|
|
|
function pre_process($form_name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
2002-06-09 23:36:37 +02:00
|
|
|
{
|
2009-10-15 10:48:47 +02:00
|
|
|
//echo "<p>tab_widget::pre_process('$form_name',".array2string($value).','.array2string($readonlys).','.array2string($extension_data).")</p>\n";
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2005-05-19 15:16:52 +02:00
|
|
|
if (!$cell['onchange']) // onchange allows to use the old behavior (submit for each new tab)
|
|
|
|
{
|
2009-03-16 13:58:24 +01:00
|
|
|
$dom_enabled = true;
|
2005-05-19 15:16:52 +02:00
|
|
|
}
|
2002-06-09 23:36:37 +02:00
|
|
|
$labels = explode('|',$cell['label']);
|
|
|
|
$helps = explode('|',$cell['help']);
|
2009-01-29 19:31:40 +01:00
|
|
|
if (strpos($cell_name=$tab_names=$cell['name'],'=') !== false)
|
|
|
|
{
|
|
|
|
list($cell_name,$tab_names) = explode('=',$cell['name']);
|
|
|
|
$cell['name'] = $cell_name;
|
|
|
|
}
|
|
|
|
$names = explode('|',$tab_names);
|
2005-05-19 15:16:52 +02:00
|
|
|
// disable tab mentioned in readonlys
|
|
|
|
foreach(is_array($readonlys) ? $readonlys : array($readonlys => true) as $name => $disable)
|
|
|
|
{
|
2013-10-25 09:30:51 +02:00
|
|
|
// check full name AND last component name
|
|
|
|
if (strpos($name, '.') === false)
|
|
|
|
{
|
|
|
|
$name2 = $tmpl->name.'.'.$name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$nparts = explode('.', $name);
|
|
|
|
$name2 = array_pop($nparts);
|
|
|
|
}
|
|
|
|
if ($name && $disable && (($key = array_search($name, $names)) !== false ||
|
|
|
|
($key = array_search($name2, $names)) !== false))
|
2005-05-19 15:16:52 +02:00
|
|
|
{
|
|
|
|
unset($names[$key]);
|
|
|
|
$names = array_values($names);
|
|
|
|
unset($helps[$key]);
|
|
|
|
$helps = array_values($helps);
|
|
|
|
unset($labels[$key]);
|
|
|
|
$labels = array_values($labels);
|
|
|
|
}
|
|
|
|
}
|
2009-06-08 18:21:14 +02:00
|
|
|
$tab_widget = new etemplate('etemplate.tab_widget');
|
2005-05-19 15:16:52 +02:00
|
|
|
$tab_widget->no_onclick = true;
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2007-04-29 16:25:19 +02:00
|
|
|
if ($value && strpos($value,'.') === false)
|
2005-05-25 16:10:27 +02:00
|
|
|
{
|
|
|
|
$value = $tmpl->name . '.' . $value;
|
|
|
|
}
|
2003-04-13 21:14:50 +02:00
|
|
|
foreach($names as $k => $name)
|
|
|
|
{
|
2007-04-29 16:25:19 +02:00
|
|
|
if (strpos($name,'.') === false)
|
2003-04-13 21:14:50 +02:00
|
|
|
{
|
|
|
|
$name = $names[$k] = $tmpl->name . '.' . $name;
|
|
|
|
}
|
2005-05-19 15:16:52 +02:00
|
|
|
if ($value == $name)
|
2003-04-13 21:14:50 +02:00
|
|
|
{
|
|
|
|
$selected_tab = $name;
|
|
|
|
}
|
|
|
|
}
|
2010-03-23 20:34:40 +01:00
|
|
|
$all_names = implode('|',$names);
|
|
|
|
|
2003-04-13 21:14:50 +02:00
|
|
|
if (empty($selected_tab))
|
|
|
|
{
|
2005-05-19 15:16:52 +02:00
|
|
|
$value = $selected_tab = $names[0];
|
2003-04-13 21:14:50 +02:00
|
|
|
}
|
2005-05-25 16:10:27 +02:00
|
|
|
$extension_data = $value; // remember the active tab in the extension_data
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2005-05-19 15:16:52 +02:00
|
|
|
foreach($names as $k => $name)
|
2002-06-09 23:36:37 +02:00
|
|
|
{
|
2007-04-29 16:25:19 +02:00
|
|
|
if (strpos($name,'.') === false)
|
2002-10-05 12:40:02 +02:00
|
|
|
{
|
|
|
|
$name = $names[$k] = $tmpl->name . '.' . $name;
|
|
|
|
}
|
2005-05-19 15:16:52 +02:00
|
|
|
$tcell =& $tab_widget->empty_cell();
|
|
|
|
if ($value == $name)
|
2002-06-09 23:36:37 +02:00
|
|
|
{
|
2007-03-09 12:25:08 +01:00
|
|
|
$tcell['span'] = ',etemplate_tab_active';
|
2002-06-09 23:36:37 +02:00
|
|
|
}
|
2002-06-10 23:36:22 +02:00
|
|
|
else
|
|
|
|
{
|
2007-03-09 12:25:08 +01:00
|
|
|
$tcell['span'] = ',etemplate_tab';
|
2002-06-10 23:36:22 +02:00
|
|
|
}
|
2003-04-13 21:14:50 +02:00
|
|
|
if ($dom_enabled)
|
|
|
|
{
|
2005-05-19 15:16:52 +02:00
|
|
|
$tcell['onclick'] = "activate_tab('$name','$all_names','$form_name');";
|
|
|
|
$tcell['id'] = $name.'-tab';
|
2003-04-13 21:14:50 +02:00
|
|
|
}
|
2005-05-19 15:16:52 +02:00
|
|
|
elseif ($value != $name)
|
|
|
|
{
|
|
|
|
$tcell['type'] = 'button';
|
|
|
|
$tcell['onchange'] = '1';
|
2009-01-29 19:31:40 +01:00
|
|
|
$tcell['name'] = $cell_name.'['.$name.']';
|
2005-05-19 15:16:52 +02:00
|
|
|
}
|
|
|
|
$tcell['label'] = $labels[$k];
|
|
|
|
$tcell['help'] = $helps[$k];
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2005-05-19 15:16:52 +02:00
|
|
|
$tab_widget->set_cell_attribute('tabs',1+$k,$tcell);
|
|
|
|
}
|
|
|
|
$tab_widget->set_cell_attribute('tabs','type','hbox');
|
|
|
|
$tab_widget->set_cell_attribute('tabs','size',count($names));
|
|
|
|
$tab_widget->set_cell_attribute('tabs','name','');
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2003-04-13 21:14:50 +02:00
|
|
|
if ($dom_enabled)
|
|
|
|
{
|
|
|
|
foreach($names as $n => $name)
|
|
|
|
{
|
2005-05-19 15:16:52 +02:00
|
|
|
$bcell = $tab_widget->empty_cell('template',$name);
|
2009-06-08 18:21:14 +02:00
|
|
|
$bcell['obj'] = new etemplate($name,$tmpl->as_array());
|
2005-05-19 15:16:52 +02:00
|
|
|
$tab_widget->set_cell_attribute('body',$n+1,$bcell);
|
2003-04-13 21:14:50 +02:00
|
|
|
}
|
2005-05-19 15:16:52 +02:00
|
|
|
$tab_widget->set_cell_attribute('body','type','deck');
|
|
|
|
$tab_widget->set_cell_attribute('body','size',count($names));
|
|
|
|
$tab_widget->set_cell_attribute('body','span',',tab_body');
|
2009-01-29 19:31:40 +01:00
|
|
|
$tab_widget->set_cell_attribute('body','name',$cell_name);
|
2003-04-13 21:14:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
$stab = new etemplate($selected_tab,$tmpl->as_array());
|
2005-05-19 15:16:52 +02:00
|
|
|
$tab_widget->set_cell_attribute('body','type','template');
|
|
|
|
$tab_widget->set_cell_attribute('body','size',''); // the deck has a '1' there
|
|
|
|
$tab_widget->set_cell_attribute('body','obj',$stab);
|
2003-04-13 21:14:50 +02:00
|
|
|
}
|
2005-05-19 15:16:52 +02:00
|
|
|
$tab_widget->set_cell_attribute('body','name',$selected_tab);
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2002-06-09 23:36:37 +02:00
|
|
|
$cell['type'] = 'template';
|
2002-09-27 18:17:39 +02:00
|
|
|
$cell['obj'] = &$tab_widget;
|
2002-06-09 23:36:37 +02:00
|
|
|
$cell['label'] = $cell['help'] = '';
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2002-06-15 14:54:38 +02:00
|
|
|
return False; // NO extra Label
|
2002-06-09 23:36:37 +02:00
|
|
|
}
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
|
|
|
* postprocessing method, called after the submission of the form
|
|
|
|
*
|
|
|
|
* It has to copy the allowed/valid data from $value_in to $value, otherwise the widget
|
|
|
|
* will return no data (if it has a preprocessing method). The framework insures that
|
|
|
|
* the post-processing of all contained widget has been done before.
|
|
|
|
*
|
|
|
|
* Only used by select-dow so far
|
|
|
|
*
|
|
|
|
* @param string $name form-name of the widget
|
|
|
|
* @param mixed &$value the extension returns here it's input, if there's any
|
|
|
|
* @param mixed &$extension_data persistent storage between calls or pre- and post-process
|
|
|
|
* @param boolean &$loop can be set to true to request a re-submision of the form/dialog
|
|
|
|
* @param object &$tmpl the eTemplate the widget belongs too
|
|
|
|
* @param mixed &value_in the posted values (already striped of magic-quotes)
|
|
|
|
* @return boolean true if $value has valid content, on false no content will be returned!
|
|
|
|
*/
|
2005-05-19 15:16:52 +02:00
|
|
|
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
2002-06-09 23:36:37 +02:00
|
|
|
{
|
2005-05-19 15:16:52 +02:00
|
|
|
//echo "<p>tab_widget::post_process($name): value_in = "; _debug_array($value_in);
|
2009-03-16 13:58:24 +01:00
|
|
|
|
2005-05-19 15:16:52 +02:00
|
|
|
if (is_array($value_in))
|
2002-06-15 21:59:07 +02:00
|
|
|
{
|
2005-05-19 15:16:52 +02:00
|
|
|
foreach ($value_in as $tab => $button_pressed)
|
2002-06-15 21:59:07 +02:00
|
|
|
{
|
2005-05-19 15:16:52 +02:00
|
|
|
if ($button_pressed)
|
|
|
|
{
|
|
|
|
$value = $tab;
|
|
|
|
$loop = True;
|
|
|
|
}
|
2002-06-15 21:59:07 +02:00
|
|
|
}
|
|
|
|
}
|
2005-05-19 15:16:52 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$value = $value_in;
|
|
|
|
}
|
2005-05-25 16:10:27 +02:00
|
|
|
// if value not set (other button pressed), set the value we remembered in the extension_data
|
|
|
|
if (!$value)
|
|
|
|
{
|
2009-03-16 13:58:24 +01:00
|
|
|
$value = $extension_data;
|
2005-05-25 16:10:27 +02:00
|
|
|
}
|
2002-06-09 23:36:37 +02:00
|
|
|
return True;
|
|
|
|
}
|
2002-10-09 02:32:04 +02:00
|
|
|
}
|