event.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Form for entering 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. * Form for adding 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 EventForm extends Form
  46. {
  47. /**
  48. * ID of the form
  49. *
  50. * @return int ID of the form
  51. */
  52. function id()
  53. {
  54. return 'form_new_event';
  55. }
  56. /**
  57. * class of the form
  58. *
  59. * @return string class of the form
  60. */
  61. function formClass()
  62. {
  63. return 'form_settings ajax-notice';
  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('newevent');
  73. }
  74. /**
  75. * Data elements of the form
  76. *
  77. * @return void
  78. */
  79. function formData()
  80. {
  81. $this->out->elementStart('fieldset', array('id' => 'new_event_data'));
  82. // Passing in the URL of the Ajax action that the .js for this form hits
  83. // when selecting event start and end times. JavaScript will try to
  84. // use a relative path, unless explicitely told where an action is,
  85. // and that's a bit difficult to calculate since the event form is on
  86. // so many pages with different paths. It might be worth solving this
  87. // globally by putting the base site path in the Identifier-URL meta tag
  88. // or something similar, so it would be easy to calculate the exact path
  89. // for actions and other things in JavaScripts. -z
  90. $this->out->hidden('timelist_action_url', common_local_url('timelist'));
  91. $this->out->elementStart('ul', 'form_data');
  92. $this->li();
  93. $this->out->input('event-title',
  94. // TRANS: Field label on event form.
  95. _m('LABEL','Title'),
  96. null,
  97. // TRANS: Field title on event form.
  98. _m('Title of the event.'),
  99. 'title',
  100. true); // HTML5 "required" attribute
  101. $this->unli();
  102. $this->li();
  103. $today = new DateTime('now');
  104. $today->setTimezone(new DateTimeZone(common_timezone()));
  105. $this->out->input('event-startdate',
  106. // TRANS: Field label on event form.
  107. _m('LABEL','Start date'),
  108. $today->format('m/d/Y'),
  109. // TRANS: Field title on event form.
  110. _m('Date the event starts.'),
  111. 'startdate');
  112. $this->unli();
  113. $this->li();
  114. $times = EventTimeList::getTimes($today->format('m/d/Y 12:00') . ' am ' . $today->format('T'));
  115. $start = EventTimeList::nearestHalfHour($today->format('c'));
  116. $start->setTimezone(new DateTimeZone(common_timezone()));
  117. $this->out->dropdown(
  118. 'event-starttime',
  119. // TRANS: Field label on event form.
  120. _m('LABEL','Start time'),
  121. $times,
  122. // TRANS: Field title on event form. %s is the abbreviated timezone
  123. sprintf(_m("Time the event starts (%s)."), $today->format('T')),
  124. false,
  125. $start->format('g:ia')
  126. );
  127. // Need to keep JavaScript TZ in sync with PHP TZ
  128. $this->out->hidden('tz', $today->format('T'));
  129. $this->out->hidden('now', $today->format('F d, Y H:i:s T'));
  130. $this->unli();
  131. $this->li();
  132. $this->out->input('event-enddate',
  133. // TRANS: Field label on event form.
  134. _m('LABEL','End date'),
  135. $today->format('m/d/Y'),
  136. // TRANS: Field title on event form.
  137. _m('Date the event ends.'),
  138. 'enddate');
  139. $this->unli();
  140. $this->li();
  141. $this->out->dropdown(
  142. 'event-endtime',
  143. // TRANS: Field label on event form.
  144. _m('LABEL','End time'),
  145. EventTimeList::getTimes($start->format('c'), true),
  146. // TRANS: Field title on event form.
  147. _m('Time the event ends.'),
  148. false,
  149. null
  150. );
  151. $this->unli();
  152. $this->li();
  153. $this->out->input('event-location',
  154. // TRANS: Field label on event form.
  155. _m('LABEL','Where?'),
  156. null,
  157. // TRANS: Field title on event form.
  158. _m('Event location.'),
  159. 'location');
  160. $this->unli();
  161. $this->li();
  162. $this->out->input('event-url',
  163. // TRANS: Field label on event form.
  164. _m('LABEL','URL'),
  165. null,
  166. // TRANS: Field title on event form.
  167. _m('URL for more information.'),
  168. 'url');
  169. $this->unli();
  170. $this->li();
  171. $this->out->input('event-description',
  172. // TRANS: Field label on event form.
  173. _m('LABEL','Description'),
  174. null,
  175. // TRANS: Field title on event form.
  176. _m('Description of the event.'),
  177. 'description',
  178. true); // HTML5 "required" attribute
  179. $this->unli();
  180. $this->out->elementEnd('ul');
  181. $toWidget = new ToSelector($this->out,
  182. common_current_user(),
  183. null);
  184. $toWidget->show();
  185. $this->out->elementEnd('fieldset');
  186. }
  187. /**
  188. * Action elements
  189. *
  190. * @return void
  191. */
  192. function formActions()
  193. {
  194. // TRANS: Button text to save an event..
  195. $this->out->submit('event-submit', _m('BUTTON', 'Save'), 'submit', 'submit');
  196. }
  197. }