whitelistinvite.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Fancy form for inviting collegues
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Form
  23. * @package StatusNet
  24. * @author Zach Copley <zach@status.net>
  25. * @copyright 2011 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/lib/util/form.php';
  33. /**
  34. * Form for inviting collegues and friends
  35. *
  36. * @category Form
  37. * @package StatusNet
  38. * @author Zach Copley <zach@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  40. * @link http://status.net/
  41. *
  42. */
  43. class WhitelistInviteForm extends Form
  44. {
  45. private $whitelist = null;
  46. /**
  47. * Constructor
  48. *
  49. * @param Action $out output channel
  50. */
  51. function __construct($out, $whitelist)
  52. {
  53. parent::__construct($out);
  54. $this->whitelist = $whitelist;
  55. }
  56. /**
  57. * ID of the form
  58. *
  59. * @return string ID of the form
  60. */
  61. function id()
  62. {
  63. return 'form_invite';
  64. }
  65. /**
  66. * Action of the form
  67. *
  68. * @return string URL of the action
  69. */
  70. function action()
  71. {
  72. return common_local_url('invite');
  73. }
  74. /**
  75. * Name of the form
  76. *
  77. * @return void
  78. */
  79. function formLegend()
  80. {
  81. // TRANS: Form legend.
  82. $this->out->element('legend', null, _m('Invite collegues'));
  83. }
  84. /**
  85. * Data elements of the form
  86. *
  87. * @return void
  88. */
  89. function formData()
  90. {
  91. $this->out->elementStart('ul', 'form_data');
  92. for ($i = 0; $i < 3; $i++) {
  93. $this->showEmailLI();
  94. }
  95. $this->out->elementStart('li');
  96. $this->out->textarea(
  97. // TRANS: Field label for a personal message to send to invitees.
  98. 'personal', _m('Personal message'),
  99. $this->out->trimmed('personal'),
  100. // TRANS: Field title for a personal message to send to invitees.
  101. _m('Optionally add a personal message to the invitation.')
  102. );
  103. $this->out->elementEnd('li');
  104. $this->out->elementEnd('ul');
  105. }
  106. function showEmailLI()
  107. {
  108. $this->out->elementStart('li');
  109. $this->out->input('username[]', '');
  110. $this->out->text('@');
  111. if (count($this->whitelist) == 1) {
  112. $this->out->element(
  113. 'span',
  114. array('class' => 'email_invite'),
  115. $this->whitelist[0]
  116. );
  117. $this->out->hidden('domain[]', $this->whitelist[0]);
  118. } else {
  119. $content = array();
  120. foreach($this->whitelist as $domain) {
  121. $content[$domain] = $domain;
  122. }
  123. $this->out->dropdown('domain[]', '', $content);
  124. }
  125. $this->showMultiControls();
  126. $this->out->elementEnd('li');
  127. }
  128. function showMultiControls()
  129. {
  130. $this->out->element(
  131. 'a',
  132. array(
  133. 'class' => 'remove_row',
  134. 'href' => 'javascript://',
  135. 'style' => 'display: none;'
  136. ),
  137. '-'
  138. );
  139. $this->out->element(
  140. 'a',
  141. array(
  142. 'class' => 'add_row',
  143. 'href' => 'javascript://',
  144. 'style' => 'display: none;'
  145. ),
  146. // TRANS: Link description to action to add another item to a list.
  147. _m('Add another item')
  148. );
  149. }
  150. /**
  151. * Action elements
  152. *
  153. * @return void
  154. */
  155. function formActions()
  156. {
  157. $this->out->submit(
  158. 'send',
  159. // TRANS: Send button for inviting friends.
  160. _m('BUTTON','Send'), 'submit form_action-primary',
  161. 'send',
  162. // TRANS: Submit button title.
  163. _m('Send invitations.')
  164. );
  165. }
  166. }