|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Form element to select receivers |
|
6
|
|
|
* This element contains 1 radio-buttons. One with label 'everybody' and one |
|
7
|
|
|
* with label 'select users/groups'. Only if the second radio-button is |
|
8
|
|
|
* selected, 2 select-list show up. The user can move items between the 2 |
|
9
|
|
|
* checkboxes. |
|
10
|
|
|
*/ |
|
11
|
|
|
class HTML_QuickForm_receivers extends HTML_QuickForm_group |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Array of all receivers |
|
15
|
|
|
*/ |
|
16
|
|
|
var $receivers; |
|
17
|
|
|
/** |
|
18
|
|
|
* Array of selected receivers |
|
19
|
|
|
*/ |
|
20
|
|
|
var $receivers_selected; |
|
21
|
|
|
/** |
|
22
|
|
|
* Constructor |
|
23
|
|
|
* @param string $elementName |
|
24
|
|
|
* @param string $elementLabel |
|
25
|
|
|
* @param array $attributes This should contain the keys 'receivers' and |
|
26
|
|
|
* 'receivers_selected' |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct($elementName = null, $elementLabel = null, $attributes = null) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->receivers = $attributes['receivers']; |
|
31
|
|
|
$this->receivers_selected = $attributes['receivers_selected']; |
|
32
|
|
|
unset($attributes['receivers']); |
|
33
|
|
|
unset($attributes['receivers_selected']); |
|
34
|
|
|
parent::__construct($elementName, $elementLabel, $attributes); |
|
|
|
|
|
|
35
|
|
|
$this->_persistantFreeze = true; |
|
36
|
|
|
$this->_appendName = true; |
|
37
|
|
|
$this->_type = 'receivers'; |
|
38
|
|
|
} |
|
39
|
|
|
/** |
|
40
|
|
|
* Create the form elements to build this element group |
|
41
|
|
|
*/ |
|
42
|
|
|
function _createElements() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->_elements[] = new HTML_QuickForm_Radio('receivers', '', get_lang('Everybody'), '0', array ('onclick' => 'javascript:receivers_hide(\'receivers_to\')')); |
|
45
|
|
|
$this->_elements[0]->setChecked(true); |
|
46
|
|
|
$this->_elements[] = new HTML_QuickForm_Radio('receivers', '', get_lang('SelectGroupsUsers'), '1', array ('onclick' => 'javascript:receivers_show(\'receivers_to\')')); |
|
47
|
|
|
$this->_elements[] = new HTML_QuickForm_advmultiselect('to', '', $this->receivers); |
|
48
|
|
|
$this->_elements[2]->setSelected($this->receivers_selected); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
/** |
|
51
|
|
|
* HTML representation |
|
52
|
|
|
*/ |
|
53
|
|
|
public function toHtml() |
|
54
|
|
|
{ |
|
55
|
|
|
include_once ('HTML/QuickForm/Renderer/Default.php'); |
|
56
|
|
|
$this->_separator = '<br/>'; |
|
57
|
|
|
$renderer = & new HTML_QuickForm_Renderer_Default(); |
|
58
|
|
|
$renderer->setElementTemplate('{element}'); |
|
59
|
|
|
$select_boxes = $this->_elements[2]; |
|
60
|
|
|
$select_boxes->setElementTemplate('<div style="margin-left:20px;display:block;" id="receivers_'.$select_boxes->getName().'">'.$select_boxes->_elementTemplate.'</div>'); |
|
61
|
|
|
parent :: accept($renderer); |
|
|
|
|
|
|
62
|
|
|
$js = $this->getElementJS(); |
|
63
|
|
|
return $renderer->toHtml().$js; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get the necessary javascript |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getElementJS() |
|
70
|
|
|
{ |
|
71
|
|
|
$js = "<script type=\"text/javascript\"> |
|
72
|
|
|
/* <![CDATA[ */ |
|
73
|
|
|
receivers_hide('receivers_to'); |
|
74
|
|
|
function receivers_show(item) { |
|
75
|
|
|
el = document.getElementById(item); |
|
76
|
|
|
el.style.display=''; |
|
77
|
|
|
} |
|
78
|
|
|
function receivers_hide(item) { |
|
79
|
|
|
el = document.getElementById(item); |
|
80
|
|
|
el.style.display='none'; |
|
81
|
|
|
} |
|
82
|
|
|
/* ]]> */ |
|
83
|
|
|
</script>\n"; |
|
84
|
|
|
return $js; |
|
85
|
|
|
} |
|
86
|
|
|
/** |
|
87
|
|
|
* accept renderer |
|
88
|
|
|
*/ |
|
89
|
|
|
function accept(& $renderer, $required = false, $error = null) |
|
90
|
|
|
{ |
|
91
|
|
|
$renderer->renderElement($this, $required, $error); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
?> |
|
|
|
|
|
|
95
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.