receivers.php 2.9 KB

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