receivers.php 3.0 KB

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