/[drupal]/contributions/modules/rsvp/rsvp.form.inc
ViewVC logotype

Contents of /contributions/modules/rsvp/rsvp.form.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Thu Feb 5 23:28:36 2009 UTC (9 months, 2 weeks ago) by ulf1
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.2: +56 -6 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2
3 // $Id: rsvp.form.inc,v 1.2 2009/02/05 02:25:27 ulf1 Exp $
4
5 /**
6 * @module rsvp_form
7 * @package rsvp - A drupal module developed for civicspace - a distribution of drupal.
8 * @description Provides form display helper functions.
9 * @author crunchywelch (welch@advomatic.com)
10 * @author Omar Abdel-Wahab (owahab@gmail.com)
11 * @author Ulf Schenk (ulf@schenkunlimited.net)
12 *
13 */
14
15 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
16
17 define('RSVP_STYLESHEET_WRAPPER', 'edit-stylesheet-wrapper');
18
19 /**
20 * Displays the 'Invitation message - view permissions' form element to set $rsvp->rsvp_view_roles
21 *
22 * @ingroup rsvp_form
23 * @param $rsvp The rsvp instance to display.
24 *
25 * @return $form array.
26 *
27 */
28 function rsvp_form_element_rsvp_view_roles($rsvp, $field_attr = array()) {
29
30 $role_query_result = db_query("SELECT rid,name FROM {role} order by name");
31 $role_options = array();
32 while ($role = db_fetch_object($role_query_result)) {
33 $role_options[$role->rid] = $role->name;
34 }
35
36 return array_merge($field_attr, array (
37 '#type' => 'checkboxes',
38 '#title' => t('Invitation message - view permissions'),
39 '#options' => $role_options,
40 '#description' => t('Select which roles have permissions to view the invitation besides the guests.'),
41 '#default_value' => explode(';', $rsvp->rsvp_view_roles),
42 ));
43
44 }
45
46 /**
47 * Displays the 'Guest list - view permissions' form element to set $rsvp->response_view_roles
48 *
49 * @ingroup rsvp_form
50 * @param $rsvp The rsvp instance to display.
51 *
52 * @return $form array.
53 *
54 */
55 function rsvp_form_element_response_view_roles($rsvp, $field_attr = array()) {
56
57 $role_query_result = db_query("SELECT rid,name FROM {role} order by name");
58 $role_options = array();
59 while ($role = db_fetch_object($role_query_result)) {
60 $role_options[$role->rid] = $role->name;
61 }
62
63 return array_merge($field_attr, array (
64 '#type' => 'checkboxes',
65 '#title' => t('Guest list - view permissions'),
66 '#options' => $role_options,
67 '#description' => t('Select which roles have permissions to see the guest list besides the guests.'),
68 '#default_value' => explode(';', $rsvp->response_view_roles),
69 ));
70 }
71
72
73 /**
74 * Displays the 'Display guest list' form element to set $rsvp->response_blind
75 *
76 * @ingroup rsvp_form
77 * @param $rsvp The rsvp instance to display.
78 *
79 * @return $form array.
80 *
81 */
82 function rsvp_form_element_response_blind($rsvp, $field_attr = array()) {
83
84 $response_blind = array(RSVP_RESPONSE_SHOW => t('Show guest list'),
85 RSVP_RESPONSE_HIDE => t('Hide guest list'),
86 RSVP_RESPONSE_SHOWWHENREPLIED => t('Hide guest list until replied'));
87
88 return array_merge($field_attr, array(
89 '#type' => 'select',
90 '#title' => t('Display guest list'),
91 '#options' => array_map('check_plain', $response_blind),
92 '#default_value' => $rsvp->response_blind,
93 '#description' => t('Select when guests are allowed to see the guest list.'),
94 ));
95 }
96
97 /**
98 * Displays the 'Detail level' form element to set $rsvp->attendees_visible
99 *
100 * @ingroup rsvp_form
101 * @param $rsvp The rsvp instance to display.
102 *
103 * @return $form array.
104 *
105 */
106 function rsvp_form_element_attendees_visible($rsvp, $field_attr = array()) {
107
108 $attendees_visible = array( RSVP_INVITEE_SHOW => t('Show invitees and responses'),
109 RSVP_INVITEE_SHOWRESPONSEWHENREPLIED => t('Show invitees but hide their responses until replied'),
110 RSVP_INVITEE_HIDE => t('Hide invitees'));
111
112 return array_merge($field_attr, array(
113 '#type' => 'select',
114 '#title' => t('Detail level'),
115 '#options' => array_map('check_plain', $attendees_visible),
116 '#default_value' => $rsvp->attendees_visible,
117 '#description' => t('Select the detail level guests are allowed to see of the guest list. Field "Display guest list" has precedence.'),
118 ));
119 }
120
121 /**
122 * Displays the 'Display guest list inside event/node' form element to set $rsvp->response_blind_node
123 *
124 * @ingroup rsvp_form
125 * @param $rsvp The rsvp instance to display.
126 *
127 * @return $form array.
128 *
129 */
130 function rsvp_form_element_response_blind_node($rsvp, $field_attr = array()) {
131
132 $response_blind_node = array( RSVP_RESPONSE_SHOW => t('Show'),
133 RSVP_RESPONSE_HIDE => t('Hide'));
134
135 return array_merge($field_attr, array(
136 '#type' => 'select',
137 '#title' => t('Display guest list inside event/node'),
138 '#options' => array_map('check_plain', $response_blind_node),
139 '#default_value' => $rsvp->response_blind_node,
140 '#description' => t('Select when guests are allowed to see the guest list below each event(node). Fields "Display guest list" and "Detail level" have precedence.'),
141 ));
142
143 }
144
145 /**
146 * Displays the 'Theme' form element to set $rsvp->theme
147 *
148 * @ingroup rsvp_form
149 * @param $rsvp The rsvp instance to display.
150 *
151 * @return $form array.
152 *
153 */
154 function rsvp_form_element_theme($rsvp, $field_attr = array()) {
155
156 $theme_keys = array_keys(rsvp_function_getThemepathes());
157
158 return array_merge($field_attr, array(
159 '#type' => 'select',
160 '#title' => t('Theme'),
161 '#required' => TRUE,
162 '#options' => array_map('check_plain', array_combine($theme_keys, $theme_keys)),
163 '#default_value' => check_plain($rsvp->theme),
164 '#description' => t('Select the theme that you want to use for your invitation.'),
165 '#ahah' => array(
166 'path' => 'rsvp/js/stylesheet',
167 'wrapper' => RSVP_STYLESHEET_WRAPPER,
168 'effect' => 'fade',
169 'method' => 'replace',
170 )
171
172 ));
173 }
174
175 /**
176 * Displays the 'Stylesheet' form element to set $rsvp->stylesheet
177 *
178 * @ingroup rsvp_form
179 * @param $theme The theme name instance to display.
180 * @param $stylesheet The stylesheet name instance to display.
181 * *
182 * @return $form array.
183 *
184 */
185 function rsvp_form_element_stylesheet($theme, $stylesheet, $field_attr = array()) {
186
187 $css_keys = array_keys(rsvp_function_getStylesheets($theme));
188
189 $arr = array_merge($field_attr, array(
190 '#type' => 'select',
191 '#title' => t('Style'),
192 '#required' => TRUE,
193 '#options' => array_map('check_plain', array_combine($css_keys, $css_keys)),
194 '#default_value' => check_plain($stylesheet),
195 '#description' => t('Select the style that you want to use with your invitation.'),
196
197 ));
198
199 $arr['#prefix'] .= '<div id="' . RSVP_STYLESHEET_WRAPPER . '">';
200 $arr['#suffix'] = '</div>' . $arr['#suffix'];
201
202 return $arr;
203 }
204
205 /**
206 * Displays the 'Iconset' form element to set $rsvp->iconset
207 *
208 * @ingroup rsvp_form
209 * @param $iconsetname The iconset name to display.
210 * *
211 * @return $form array.
212 *
213 */
214 function rsvp_form_element_iconset($iconset, $field_attr = array()) {
215
216 $iconset_keys = array_keys(rsvp_function_getIconsets());
217
218 return array_merge($field_attr, array(
219 '#type' => 'select',
220 '#title' => t('Icons'),
221 '#required' => TRUE,
222 '#options' => array_map('check_plain', array_combine($iconset_keys, $iconset_keys)),
223 '#default_value' => check_plain($iconset),
224 '#description' => t('Select the icons that you want to use with your invitation.'),
225 ));
226 }
227
228 /**
229 * Displays the 'Backgroundimage' form element to set $rsvp->backgroundimage
230 *
231 * @ingroup rsvp_form
232 * @param $backgroundimagename The image name to display.
233 * *
234 * @return $form array.
235 *
236 */
237 function rsvp_form_element_backgroundimage($backgroundimagename, $field_attr = array()) {
238
239 $images_keys = array_keys(rsvp_function_getBackgroundImages());
240 $images_keys = array_merge(array('none' => '-none-'), $images_keys);
241
242 return array_merge($field_attr, array(
243 '#type' => 'select',
244 '#title' => t('Background image'),
245 '#required' => TRUE,
246 '#options' => array_map('check_plain', (!empty($images_keys)) ? array_combine($images_keys, $images_keys) : array()),
247 '#default_value' => check_plain($backgroundimagename),
248 '#description' => t('Select the background image that you want to use for your invitation.'),
249 ));
250 }
251
252
253 /**
254 * Displays the 'Image' form element to set $rsvp->image
255 *
256 * @ingroup rsvp_form
257 * @param $imagename The image name to display.
258 * *
259 * @return $form array.
260 *
261 */
262 function rsvp_form_element_image($imagename, $field_attr = array()) {
263
264 $images_keys = array_keys(rsvp_function_getImages());
265 $images_keys = array_merge(array('none' => '-none-'), $images_keys);
266
267 return array_merge($field_attr, array(
268 '#type' => 'select',
269 '#title' => t('Background image'),
270 '#required' => TRUE,
271 '#options' => array_map('check_plain', (!empty($images_keys)) ? array_combine($images_keys, $images_keys) : array()),
272 '#default_value' => check_plain($imagename),
273 '#description' => t('Select the image that you want to use for your invitation.'),
274 ));
275 }
276
277
278 /**
279 * Displays the 'Responses' form element to set $rsvp->text_whoiscoming
280 *
281 * @ingroup rsvp_form
282 * @param $rsvp The rsvp instance to display.
283 *
284 * @return $form array.
285 *
286 */
287 function rsvp_form_element_text_whoiscoming($rsvp, $field_attr = array()) {
288
289 return array_merge($field_attr, array(
290 '#type' => 'textfield',
291 '#title' => t('Responses'),
292 '#default_value' => $rsvp->text_whoiscoming,
293 '#required' => TRUE,
294 '#size' => 80,
295 '#maxlength' => 128,
296 '#description' => t('The header text shown for the guest list.'),
297 ));
298
299 }
300
301 /**
302 * Displays the 'Yes' form element to set $rsvp->text_yes
303 *
304 * @ingroup rsvp_form
305 * @param $rsvp The rsvp instance to display.
306 *
307 * @return $form array.
308 *
309 */
310 function rsvp_form_element_text_yes($rsvp, $field_attr = array()) {
311
312 return array_merge($field_attr, array(
313 '#type' => 'textfield',
314 '#title' => t('Yes'),
315 '#default_value' => $rsvp->text_yes,
316 '#required' => TRUE,
317 '#size' => 80,
318 '#maxlength' => 128,
319 '#description' => t('Text displayed inside the guest list for guests that will attend.'),
320 ));
321 }
322
323 /**
324 * Displays the 'No' form element to set $rsvp->text_no
325 *
326 * @ingroup rsvp_form
327 * @param $rsvp The rsvp instance to display.
328 *
329 * @return $form array.
330 *
331 */
332 function rsvp_form_element_text_no($rsvp, $field_attr = array()) {
333
334 return array_merge($field_attr, array(
335 '#type' => 'textfield',
336 '#title' => t('No'),
337 '#default_value' => $rsvp->text_no,
338 '#required' => TRUE,
339 '#size' => 80,
340 '#maxlength' => 128,
341 '#description' => t('Text displyed inside the guest list for guests that will not attend.'),
342 ));
343 }
344
345 /**
346 * Displays the 'Maybe' form element to set $rsvp->text_maybe
347 *
348 * @ingroup rsvp_form
349 * @param $rsvp The rsvp instance to display.
350 *
351 * @return $form array.
352 *
353 */
354 function rsvp_form_element_text_maybe($rsvp, $field_attr = array()) {
355
356 return array_merge($field_attr, array(
357 '#type' => 'textfield',
358 '#title' => t('Maybe'),
359 '#default_value' => $rsvp->text_maybe,
360 '#required' => TRUE,
361 '#size' => 80,
362 '#maxlength' => 128,
363 '#description' => t('Text displyed inside the guest list for guests that might attend.'),
364 ));
365 }
366
367 /**
368 * Displays the 'Send messages' form element to set $rsvp->list_email
369 *
370 * @ingroup rsvp_form
371 * @param $rsvp The rsvp instance to display.
372 *
373 * @return $form array.
374 *
375 */
376 function rsvp_form_element_list_email($rsvp, $field_attr = array()) {
377
378 $response_send = array( RSVP_SEND_NONE => t('No'),
379 RSVP_SEND_INVITEE => t('Invitees'),
380 RSVP_SEND_RESPONDENT => t('Respondents'),
381 RSVP_SEND_ATTENDEE => t('Attendees'));
382
383 return array_merge($field_attr, array(
384 '#type' => 'select',
385 '#title' => t('Send messages'),
386 '#options' => array_map('check_plain', $response_send),
387 '#default_value' => $rsvp->list_email,
388 '#description' => t('Select which guests are allowed to send messages to other guests of the event.')
389 ));
390 }
391
392
393 /**
394 * Displays the 'Invite others' form element to set $rsvp->allow_invite
395 *
396 * @ingroup rsvp_form
397 * @param $rsvp The rsvp instance to display.
398 *
399 * @return $form array.
400 *
401 */
402 function rsvp_form_element_allow_invite($rsvp, $field_attr = array()) {
403
404 $response_invite = array( RSVP_INVITE_NONE => t('No'),
405 RSVP_INVITE_INVITEE => t('Invitees'),
406 RSVP_INVITE_RESPONDENT => t('Respondents'),
407 RSVP_INVITE_ATTENDEE => t('Attendees'));
408
409 return array_merge($field_attr, array(
410 '#type' => 'select',
411 '#title' => t('Invite other guests'),
412 '#options' => array_map('check_plain', $response_invite),
413 '#default_value' => $rsvp->allow_invite,
414 '#description' => t('Select which guests are allowed to invite more guests to the event.')
415 ));
416 }
417
418
419 /**
420 * Displays the 'Display reply box inside event/node' form element to set $rsvp->reply_blind_node
421 *
422 * @ingroup rsvp_form
423 * @param $rsvp The rsvp instance to display.
424 *
425 * @return $form array.
426 *
427 */
428 function rsvp_form_element_reply_blind_node($rsvp, $field_attr = array()) {
429
430 $reply_blind_node = array( RSVP_REPLY_SHOW => t('Show'),
431 RSVP_REPLY_HIDE => t('Hide'));
432
433 return array_merge($field_attr, array(
434 '#type' => 'select',
435 '#title' => t('Display reply box inside event/node'),
436 '#options' => array_map('check_plain', $reply_blind_node),
437 '#default_value' => $rsvp->reply_blind_node,
438 '#description' => t('Select if guests are allowed to see the reply box below each event/node.'),
439 ));
440 }
441
442 /////////////////////////
443 /**
444 * Displays the 'Send confirmation message to host when gues replies' form element to set $rsvp->send_conf_owner
445 *
446 * @ingroup rsvp_form
447 * @param $rsvp The rsvp instance to display.
448 *
449 * @return $form array.
450 *
451 */
452 function rsvp_form_element_send_conf_owner($rsvp, $field_attr = array()) {
453
454 $send_confimation = array( RSVP_OPTION_YES => t('Yes'),
455 RSVP_OPTION_NO => t('No'));
456
457 return array_merge($field_attr, array(
458 '#type' => 'select',
459 '#title' => t('Send confirmation message to host when guest replies'),
460 '#options' => array_map('check_plain', $send_confimation),
461 '#default_value' => $rsvp->send_conf_owner,
462 '#description' => t(''),
463 ));
464 }
465
466 /**
467 * Displays the 'Send confirmation message to guest when he replies' form element to set $rsvp->send_conf_guest
468 *
469 * @ingroup rsvp_form
470 * @param $rsvp The rsvp instance to display.
471 *
472 * @return $form array.
473 *
474 */
475 function rsvp_form_element_send_conf_guest($rsvp, $field_attr = array()) {
476
477 $send_confimation = array( RSVP_OPTION_YES => t('Yes'),
478 RSVP_OPTION_NO => t('No'));
479
480 return array_merge($field_attr, array(
481 '#type' => 'select',
482 '#title' => t('Send confirmation message to guest when he replies'),
483 '#options' => array_map('check_plain', $send_confimation),
484 '#default_value' => $rsvp->send_conf_guest,
485 '#description' => t(''),
486 ));
487 }
488
489 /**
490 * Displays the 'Send messages to registered guests by privatemsg' form element to set $rsvp->send_privatemsg
491 *
492 * @ingroup rsvp_form
493 * @param $rsvp The rsvp instance to display.
494 *
495 * @return $form array.
496 *
497 */
498 function rsvp_form_element_send_privatemsg($rsvp, $field_attr = array()) {
499
500 $send_privatemsg = array( RSVP_OPTION_YES => t('Yes'),
501 RSVP_OPTION_NO => t('No'));
502
503 return array_merge($field_attr, array(
504 '#type' => 'select',
505 '#title' => t('Send messages to registered guests by privatemsg if possible'),
506 '#options' => array_map('check_plain', $send_privatemsg),
507 '#default_value' => $rsvp->send_privatemsg,
508 '#description' => t(''),
509 ));
510 }
511
512 /**
513 * Displays the 'Answer \'Maybe\' disabled' form element to set $rsvp->disable_maybe
514 *
515 * @ingroup rsvp_form
516 * @param $rsvp The rsvp instance to display.
517 *
518 * @return $form array.
519 *
520 */
521 function rsvp_form_element_disable_maybe($rsvp, $field_attr = array()) {
522
523 $disable_maybe = array( RSVP_OPTION_YES => t('Yes'),
524 RSVP_OPTION_NO => t('No'));
525
526 return array_merge($field_attr, array(
527 '#type' => 'select',
528 '#title' => t('Answer \'Maybe\' disabled'),
529 '#options' => array_map('check_plain', $disable_maybe),
530 '#default_value' => $rsvp->disable_maybe,
531 '#description' => t('When guests reply to invitations, they may choose \'Yes\', \'No\', or \'Maybe\' as their response. If you do not wish to offer the \'Maybe\' option, set this option to \'Yes\''),
532
533
534 ));
535 }
536
537 /**
538 * Displays the 'Open invitation' form element to set $rsvp->open_invitation
539 *
540 * @ingroup rsvp_form
541 * @param $rsvp The rsvp instance to display.
542 *
543 * @return $form array.
544 *
545 */
546 function rsvp_form_element_open_invitation($rsvp, $field_attr = array()) {
547
548 $open_invitation = array( RSVP_OPTION_YES => t('Yes'),
549 RSVP_OPTION_NO => t('No'));
550
551 return array_merge($field_attr, array(
552 '#type' => 'select',
553 '#title' => t('Open invitation'),
554 '#options' => array_map('check_plain', $open_invitation),
555 '#default_value' => $rsvp->open_invitation,
556 '#description' => t('Select if invitation is open to uninvited guests. If you select \'yes\', you have to select roles under \'Invitation message - view permissions\' to make the invitation visible to those uninvited guests to begin with.'),
557 ));
558 }
559
560 /**
561 * Displays the 'Maximum guests allowed to the event' form element to set $rsvp->max_guests
562 *
563 * @ingroup rsvp_form
564 * @param $rsvp The rsvp instance to display.
565 *
566 * @return $form array.
567 *
568 */
569 function rsvp_form_element_max_guests($rsvp, $field_attr = array()) {
570
571 return array_merge($field_attr, array(
572 '#type' => 'textfield',
573 '#title' => t('Maximum guests allowed to the event'),
574 '#default_value' => $rsvp->max_guests,
575 '#size' => 5,
576 '#maxlength' => 5,
577 '#description' => t('Set upper limit for number of attending guests. Set to 0 for unlimited.'),
578 ));
579 }
580
581 /**
582 * Displays the 'Reply start date' form element to set $rsvp->reply_startdate
583 *
584 * @ingroup rsvp_form
585 * @param $rsvp The rsvp instance to display.
586 *
587 * @return $form array.
588 *
589 */
590 function rsvp_form_element_reply_startdate($rsvp, $field_attr = array()) {
591
592 $date_local = $rsvp->reply_startdate;
593 return array_merge($field_attr, array(
594 '#type' => 'date',
595 '#title' => t('Reply start date'),
596 '#default_value' => array('year' => (int) date('Y',$date_local ), 'month' => (int) date('m',$date_local ), 'day' => (int) date('d',$date_local ) ),
597 '#description' => t('Specify the start date of a time window guests can replying to the invitation.'),
598 /* '#description' => ' <br /> sd1:' . $rsvp->reply_startdate
599 . ' <br /> sd2:' . date('r', $rsvp->reply_startdate)
600 . ' <br /> sd3:' . format_date($rsvp->reply_startdate, 'custom', 'U')
601 . ' <br /> sd4:' . format_date($rsvp->reply_startdate, 'custom')
602 . ' <br /> sd5:' . format_date($rsvp->reply_startdate, 'custom', 'r')
603 . ' <br /> sd6:' . format_date($rsvp->reply_startdate, 'small', 'U')
604 . ' <br /> sd7:' . format_date($rsvp->reply_startdate, 'small'),
605 */
606
607
608 '#required' => FALSE
609 ));
610
611 }
612
613 /**
614 * Displays the 'Reply end date' form element to set $rsvp->reply_enddate
615 *
616 * @ingroup rsvp_form
617 * @param $rsvp The rsvp instance to display.
618 *
619 * @return $form array.
620 *
621 */
622 function rsvp_form_element_reply_enddate($rsvp, $field_attr = array()) {
623
624 $date_local = $rsvp->reply_enddate;
625
626 return array_merge($field_attr, array(
627 '#type' => 'date',
628 '#title' => t('Reply end date'),
629 '#default_value' => array('year' => (int) date('Y', $date_local ), 'month' => (int) date('m', $date_local ), 'day' => (int) date('d', $date_local )),
630 '#description' => t('Specify the end date of a time window guests can replying to the invitation.'),
631 '#required' => FALSE
632 ));
633
634 }
635
636
637 /**
638 * AJAX callback to replace the stylesheet select options.
639 *
640 * This function is called when the theme has changed. It updates the
641 * cached form addedit and returns rendered output to be used to replace the select containing the stylesheets.
642 *
643 * @param $build_id
644 * The form's build_id.
645 * @param $theme
646 * The selected theme name.
647 * @return
648 * Prints the replacement HTML in JSON format.
649 */
650 function rsvp_stylesheet_options_update() {
651 $theme = $_POST['theme'];
652 $stylesheet = $_POST['stylesheet'];
653 if ($form = form_get_cache($_POST['form_build_id'], $form_state)) {
654
655 // Validate the theme.
656 if (isset($form['rsvp_addedit_form']['rsvp_field_6']['theme']['#options'][$theme])) {
657
658 // Get the new options and update the cache.
659 $form['rsvp_addedit_form']['rsvp_field_6']['stylesheet'] = rsvp_form_element_stylesheet($theme, $stylesheet);
660
661 form_set_cache($_POST['form_build_id'], $form, $form_state);
662
663 // Build and render the new select element, then return it in JSON format.
664 $form_state = array();
665 $form['#post'] = array();
666 $form = form_builder($form['form_id']['#value'] , $form, $form_state);
667 $output = drupal_render($form['rsvp_addedit_form']['rsvp_field_6']['stylesheet']);
668 drupal_json(array('status' => TRUE, 'data' => $output));
669 }
670 else {
671 drupal_json(array('status' => FALSE, 'data' => ''));
672 }
673 }
674 else {
675 drupal_json(array('status' => FALSE, 'data' => ''));
676 }
677 exit();
678 }
679
680
681
682
683

  ViewVC Help
Powered by ViewVC 1.1.2