1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
* @version $Id$
*
* @category Piwik
* @package Piwik
*/
/**
* Parent class for forms to be included in Smarty
*
* For an example, @see Piwik_Login_Form
*
* @package Piwik
* @see HTML_QuickForm, libs/HTML/QuickForm.php
* @link http://pear.php.net/package/HTML_QuickForm/
*/
abstract class Piwik_Form extends HTML_QuickForm
{
protected $a_formElements = array();
function __construct( $action = '', $attributes = '' )
{
if(empty($action))
{
$action = Piwik_Url::getCurrentQueryString();
}
parent::HTML_QuickForm('form', 'POST', $action, $target='', $attributes);
$this->registerRule( 'checkEmail', 'function', 'Piwik_Form_isValidEmailString');
$this->registerRule( 'fieldHaveSameValue', 'function', 'Piwik_Form_fieldHaveSameValue');
$this->init();
}
abstract function init();
function getElementList()
{
$listElements=array();
foreach($this->a_formElements as $title => $a_parameters)
{
foreach($a_parameters as $parameters)
{
if($parameters[1] != 'headertext'
&& $parameters[1] != 'submit')
{
// case radio : there are two labels but only record once, unique name
if( !isset($listElements[$title])
|| !in_array($parameters[1], $listElements[$title]))
{
$listElements[$title][] = $parameters[1];
}
}
}
}
return $listElements;
}
function addElements( $a_formElements, $sectionTitle = '' )
{
foreach($a_formElements as $parameters)
{
call_user_func_array(array(&$this , "addElement"), $parameters );
}
$this->a_formElements =
array_merge(
$this->a_formElements,
array(
$sectionTitle => $a_formElements
)
);
}
function addRules( $a_formRules)
{
foreach($a_formRules as $parameters)
{
call_user_func_array(array(&$this , "addRule"), $parameters );
}
}
function setChecked( $nameElement )
{
foreach( $this->_elements as $key => $value)
{
if($value->_attributes['name'] == $nameElement)
{
$this->_elements[$key]->_attributes['checked'] = 'checked';
}
}
}
function setSelected( $nameElement, $value )
{
foreach( $this->_elements as $key => $value)
{
if($value->_attributes['name'] == $nameElement)
{
$this->_elements[$key]->_attributes['selected'] = 'selected';
}
}
}
}
function Piwik_Form_fieldHaveSameValue($element, $value, $arg)
{
$value2 = Piwik_Common::getRequestVar( $arg, '', 'string');
$value2 = Piwik_Common::unsanitizeInputValue($value2);
return $value === $value2;
}
function Piwik_Form_isValidEmailString( $element, $value )
{
return Piwik::isValidEmailString($value);
}
|