2011-08-18 23:56:37 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware - eTemplate serverside button widget
|
|
|
|
*
|
|
|
|
* @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 2002-11 by RalfBecker@outdoor-training.de
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eTemplate button widget
|
|
|
|
*/
|
|
|
|
class etemplate_widget_button extends etemplate_widget
|
|
|
|
{
|
|
|
|
/**
|
2012-05-03 16:17:47 +02:00
|
|
|
* Validate buttons
|
2011-08-18 23:56:37 +02:00
|
|
|
*
|
2012-05-03 16:17:47 +02:00
|
|
|
* Readonly buttons can NOT be pressed!
|
2011-08-18 23:56:37 +02:00
|
|
|
*
|
2011-08-20 12:27:38 +02:00
|
|
|
* @param string $cname current namespace
|
2012-05-03 16:17:47 +02:00
|
|
|
* @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
|
2011-08-18 23:56:37 +02:00
|
|
|
* @param array $content
|
|
|
|
* @param array &$validated=array() validated content
|
|
|
|
* @return boolean true if no validation error, false otherwise
|
|
|
|
*/
|
2012-05-03 16:17:47 +02:00
|
|
|
public function validate($cname, array $expand, array $content, &$validated=array())
|
2011-08-18 23:56:37 +02:00
|
|
|
{
|
2012-05-03 16:17:47 +02:00
|
|
|
$form_name = self::form_name($cname, $this->id, $expand);
|
|
|
|
//error_log(__METHOD__."('$cname', ".array2string($expand).", ...) $this: get_array(\$content, '$form_name')=".array2string(self::get_array($content, $form_name)));
|
2011-08-18 23:56:37 +02:00
|
|
|
|
2012-06-11 20:14:43 +02:00
|
|
|
if (!$this->is_readonly($cname, $form_name))
|
2011-08-18 23:56:37 +02:00
|
|
|
{
|
2012-06-11 20:14:43 +02:00
|
|
|
$value = self::get_array($content, $form_name);
|
2011-08-18 23:56:37 +02:00
|
|
|
|
2012-06-11 20:14:43 +02:00
|
|
|
if(
|
|
|
|
// Handle case of not existing $row_cont[id], eg: create[]
|
|
|
|
is_array($value) && count($value) == 1 ||
|
|
|
|
// check === true, as get_array() ignores a "[]" postfix and returns array() eg. for a not existing $row_cont[id] in "delete[$row_cont[id]]"
|
|
|
|
$value == true
|
|
|
|
)
|
2011-08-18 23:56:37 +02:00
|
|
|
{
|
2012-06-11 20:14:43 +02:00
|
|
|
$valid =& self::get_array($validated, $form_name, true);
|
|
|
|
$valid = is_array($value) ? $value : 'pressed';
|
|
|
|
|
|
|
|
// recored pressed button globally, was in the template object before, not sure self::$request is the right place ...
|
|
|
|
if ($this->type == 'cancel' || $form_name == 'cancel' || substr($form_name,-10) == '[cancel]')
|
|
|
|
{
|
|
|
|
self::$request->canceled = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self::$request->button_pressed = true;
|
|
|
|
}
|
2011-08-18 23:56:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|