newrsvp.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * RSVP for an event
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Event
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * RSVP for an event
  37. *
  38. * @category Event
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @copyright 2011 StatusNet, Inc.
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  43. * @link http://status.net/
  44. */
  45. class NewrsvpAction extends Action
  46. {
  47. protected $user = null;
  48. protected $event = null;
  49. protected $verb = null;
  50. /**
  51. * Returns the title of the action
  52. *
  53. * @return string Action title
  54. */
  55. function title()
  56. {
  57. // TRANS: Title for RSVP ("please respond") action.
  58. return _m('TITLE','New RSVP');
  59. }
  60. /**
  61. * For initializing members of the class.
  62. *
  63. * @param array $argarray misc. arguments
  64. *
  65. * @return boolean true
  66. */
  67. function prepare($argarray)
  68. {
  69. parent::prepare($argarray);
  70. if ($this->boolean('ajax')) {
  71. StatusNet::setApi(true); // short error results!
  72. }
  73. $eventId = $this->trimmed('event');
  74. if (empty($eventId)) {
  75. // TRANS: Client exception thrown when referring to a non-existing event.
  76. throw new ClientException(_m('No such event.'));
  77. }
  78. $this->event = Happening::getKV('id', $eventId);
  79. if (empty($this->event)) {
  80. // TRANS: Client exception thrown when referring to a non-existing event.
  81. throw new ClientException(_m('No such event.'));
  82. }
  83. $this->user = common_current_user();
  84. if (empty($this->user)) {
  85. // TRANS: Client exception thrown when trying to RSVP ("please respond") while not logged in.
  86. throw new ClientException(_m('You must be logged in to RSVP for an event.'));
  87. }
  88. common_debug(print_r($this->args, true));
  89. switch (strtolower($this->trimmed('submitvalue'))) {
  90. case 'yes':
  91. $this->verb = RSVP::POSITIVE;
  92. break;
  93. case 'no':
  94. $this->verb = RSVP::NEGATIVE;
  95. break;
  96. case 'maybe':
  97. $this->verb = RSVP::POSSIBLE;
  98. break;
  99. default:
  100. // TRANS: Client exception thrown when using an invalid value for RSVP ("please respond").
  101. throw new ClientException(_m('Unknown submit value.'));
  102. }
  103. return true;
  104. }
  105. /**
  106. * Handler method
  107. *
  108. * @param array $argarray is ignored since it's now passed in in prepare()
  109. *
  110. * @return void
  111. */
  112. function handle($argarray=null)
  113. {
  114. parent::handle($argarray);
  115. if ($this->isPost()) {
  116. $this->newRSVP();
  117. } else {
  118. $this->showPage();
  119. }
  120. return;
  121. }
  122. /**
  123. * Add a new event
  124. *
  125. * @return void
  126. */
  127. function newRSVP()
  128. {
  129. try {
  130. $saved = RSVP::saveNew($this->user->getProfile(),
  131. $this->event,
  132. $this->verb);
  133. } catch (ClientException $ce) {
  134. $this->error = $ce->getMessage();
  135. $this->showPage();
  136. return;
  137. }
  138. if ($this->boolean('ajax')) {
  139. $rsvp = RSVP::fromNotice($saved);
  140. $this->startHTML('text/xml;charset=utf-8');
  141. $this->elementStart('head');
  142. // TRANS: Page title after creating an event.
  143. $this->element('title', null, _m('Event saved'));
  144. $this->elementEnd('head');
  145. $this->elementStart('body');
  146. $cancel = new CancelRSVPForm($rsvp, $this);
  147. $cancel->show();
  148. $this->elementEnd('body');
  149. $this->endHTML();
  150. } else {
  151. common_redirect($saved->getUrl(), 303);
  152. }
  153. }
  154. /**
  155. * Show the event form
  156. *
  157. * @return void
  158. */
  159. function showContent()
  160. {
  161. if (!empty($this->error)) {
  162. $this->element('p', 'error', $this->error);
  163. }
  164. $form = new RSVPForm($this->event, $this);
  165. $form->show();
  166. return;
  167. }
  168. /**
  169. * Return true if read only.
  170. *
  171. * MAY override
  172. *
  173. * @param array $args other arguments
  174. *
  175. * @return boolean is read only action?
  176. */
  177. function isReadOnly($args)
  178. {
  179. if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
  180. $_SERVER['REQUEST_METHOD'] == 'HEAD') {
  181. return true;
  182. } else {
  183. return false;
  184. }
  185. }
  186. }