receivers.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // $Id: receivers.php 7727 2006-02-09 13:37:04Z turboke $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004-2005 Dokeos S.A.
  7. Copyright (c) Bart Mollet, Hogeschool Gent
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. require_once 'HTML/QuickForm/group.php';
  20. require_once 'HTML/QuickForm/radio.php';
  21. require_once 'HTML/QuickForm/advmultiselect.php';
  22. /**
  23. * Form element to select receivers
  24. * This element contains 1 radio-buttons. One with label 'everybody' and one
  25. * with label 'select users/groups'. Only if the second radio-button is
  26. * selected, 2 select-list show up. The user can move items between the 2
  27. * checkboxes.
  28. */
  29. class HTML_QuickForm_receivers extends HTML_QuickForm_group
  30. {
  31. /**
  32. * Array of all receivers
  33. */
  34. var $receivers;
  35. /**
  36. * Array of selected receivers
  37. */
  38. var $receivers_selected;
  39. /**
  40. * Constructor
  41. * @param string $elementName
  42. * @param string $elementLabel
  43. * @param array $attributes This should contain the keys 'receivers' and
  44. * 'receivers_selected'
  45. */
  46. function HTML_QuickForm_receivers($elementName = null, $elementLabel = null, $attributes = null)
  47. {
  48. $this->receivers = $attributes['receivers'];
  49. $this->receivers_selected = $attributes['receivers_selected'];
  50. unset($attributes['receivers']);
  51. unset($attributes['receivers_selected']);
  52. $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  53. $this->_persistantFreeze = true;
  54. $this->_appendName = true;
  55. $this->_type = 'receivers';
  56. }
  57. /**
  58. * Create the form elements to build this element group
  59. */
  60. function _createElements()
  61. {
  62. $this->_elements[] = new HTML_QuickForm_Radio('receivers', '', get_lang('Everybody'), '0', array ('onclick' => 'javascript:receivers_hide(\'receivers_to\')'));
  63. $this->_elements[0]->setChecked(true);
  64. $this->_elements[] = new HTML_QuickForm_Radio('receivers', '', get_lang('SelectGroupsUsers'), '1', array ('onclick' => 'javascript:receivers_show(\'receivers_to\')'));
  65. $this->_elements[] = new HTML_QuickForm_advmultiselect('to', '', $this->receivers);
  66. $this->_elements[2]->setSelected($this->receivers_selected);
  67. }
  68. /**
  69. * HTML representation
  70. */
  71. function toHtml()
  72. {
  73. include_once ('HTML/QuickForm/Renderer/Default.php');
  74. $this->_separator = '<br/>';
  75. $renderer = & new HTML_QuickForm_Renderer_Default();
  76. $renderer->setElementTemplate('{element}');
  77. $select_boxes = $this->_elements[2];
  78. $select_boxes->setElementTemplate('<div style="margin-left:20px;display:block;" id="receivers_'.$select_boxes->getName().'">'.$select_boxes->_elementTemplate.'</div>');
  79. parent :: accept($renderer);
  80. $js = $this->getElementJS();
  81. return $renderer->toHtml().$js;
  82. }
  83. /**
  84. * Get the necessary javascript
  85. */
  86. function getElementJS()
  87. {
  88. $js = "<script type=\"text/javascript\">
  89. /* <![CDATA[ */
  90. receivers_hide('receivers_to');
  91. function receivers_show(item) {
  92. el = document.getElementById(item);
  93. el.style.display='';
  94. }
  95. function receivers_hide(item) {
  96. el = document.getElementById(item);
  97. el.style.display='none';
  98. }
  99. /* ]]> */
  100. </script>\n";
  101. return $js;
  102. }
  103. /**
  104. * accept renderer
  105. */
  106. function accept(& $renderer, $required = false, $error = null)
  107. {
  108. $renderer->renderElement($this, $required, $error);
  109. }
  110. }
  111. ?>