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

Contents of /contributions/modules/rsvp/rsvp.admin.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: +14 -6 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2
3 // $Id: rsvp.admin.inc,v 1.2 2009/02/05 02:25:27 ulf1 Exp $
4
5 /**
6 * @module rsvp_admin
7 * @package rsvp - A drupal module developed for civicspace - a distribution of drupal.
8 * @description Provides admin functionality
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 // Pre Loading files that will be required in this module
18 foreach (array('mailer','form') as $file) {
19 module_load_include("inc", "rsvp", "rsvp.{$file}");
20 }
21
22 /**
23 * Menu callback: rsvp admin general form for rsvp.
24 *
25 * @see rsvp_admin_settings_general_submit()
26 * @ingroup rsvp_admin
27 */
28
29 function rsvp_admin_settings_general(&$form_state) {
30 $form = array();
31
32 $pick_address = RSVP_EMAIL_SITEADDRESS;
33 $from_address = '';
34
35 $emailfrom = variable_get('rsvp_from_address', NULL);
36 if (isset($emailfrom)) {
37 foreach ($emailfrom as $pick => $email) {
38 $pick_address = $pick;
39 $from_address = $email;
40 }
41 }
42
43
44 $form['rsvp_admin_settings_general'] = array(
45 '#type' => 'fieldset',
46 '#title' => t('Sender information'),
47 '#collapsible' => FALSE,
48 '#description' => t('Default sender address that will be used for sending every email by rsvp.'),
49 );
50
51 $form['rsvp_admin_settings_general']['pick_from_address'] = array(
52 '#type' => 'select',
53 '#title' => t('Pick which email address to use for emails'),
54 '#default_value' => $pick_address,
55 '#options' => array(RSVP_EMAIL_SITEADDRESS => t('The sites default address (ignore email address below)'), RSVP_EMAIL_SETTINGS => t('Use the email address below'), RSVP_EMAIL_CREATOR => t('Use the email address of user initiating the email (ignore email address below)')),
56 );
57
58 $form['rsvp_admin_settings_general']['rsvp_from_address'] = array(
59 '#type' => 'textfield',
60 '#title' => t('From email address'),
61 '#size' => 60,
62 '#maxlength' => 128,
63 '#required' => false,
64 '#default_value' => $from_address,
65 );
66
67 $expired = variable_get('rsvp_for_expired_event', RSVP_OPTION_NO);
68
69 $form['rsvp_for_expired_event'] = array(
70 '#type' => 'select',
71 '#title' => t('Create invitations for expired events'),
72 '#default_value' => $expired,
73 '#options' => array(RSVP_OPTION_YES => t('Yes'), RSVP_OPTION_NO => t('No')),
74 '#description' => t('Can users create invitations on already expired events (default is \'No\')'),
75 );
76
77 //print the email template functions
78 $form['mail'] = array(
79 '#type' => 'fieldset',
80 '#title' => t('Email Options'),
81 );
82
83 global $rsvp_mailer_ops;
84 //compose a list of possible replacement keys for email templates
85 $replacement_keys = array_keys(rsvp_mailer_replacements(NULL, NULL, NULL, NULL, NULL));
86 //these two are added per-receipient in user_relationship_mailer_send_email()
87 $macro_replacements = array('%macros' => implode(', ', $replacement_keys));
88
89 foreach ($rsvp_mailer_ops as $op => $op_name) {
90 $defaults_function = "rsvp_mailer_{$op}_default";
91 $defaults = $defaults_function();
92
93 $form['mail'][$op] = array(
94 '#type' => 'fieldset',
95 '#title' => t($op_name),
96 '#collapsible' => TRUE,
97 '#collapsed' => TRUE
98 );
99 $form['mail'][$op]["rsvp_mailer_{$op}_subject"] = array(
100 '#type' => 'textfield',
101 '#title' => t('\'@Op_name\' email subject', array('@Op_name' => t($op_name))),
102 '#default_value' => variable_get("rsvp_default_mailer_{$op}_subject", $defaults['subject']),
103 );
104 $form['mail'][$op]["rsvp_mailer_{$op}_message"] = array(
105 '#type' => 'textarea',
106 '#title' => t('\'@Op_name\' email message', array('@Op_name' => $op_name)),
107 '#default_value' => variable_get("rsvp_default_mailer_{$op}_message", $defaults['message']),
108 '#description' => t('Replacement strings are: %macros', $macro_replacements),
109 );
110 }
111
112
113 $form['submit'] = array(
114 '#type' => 'submit',
115 '#value' => t('Save'),
116 '#weight' => 25,
117 '#name' => 'op'
118 );
119 $form['reset_defaults'] = array(
120 '#type' => 'submit',
121 '#value' => t('Reset to defaults'),
122 '#weight' => 25,
123 '#name' => 'op'
124 );
125
126 return $form;
127 }
128
129 /*
130 * @ingroup rsvp_admin
131 */
132 function rsvp_admin_settings_general_validate($form, &$form_state) {
133
134 if ($form_state['values']['pick_from_address'] == '1') {
135 if (!valid_email_address($form_state['values']['rsvp_from_address'])) {
136 form_set_error('rsvp_from_address', t("The sender's email address you supplied is not valid."));
137 }
138 }
139 }
140
141 /*
142 * @ingroup rsvp_admin
143 */
144 function rsvp_admin_settings_general_submit($form, &$form_state) {
145
146 global $rsvp_mailer_ops;
147
148 $op = $form_state['values']['op'];
149
150 if ($op == t('Save')) {
151
152 $pick = $form_state['values']['pick_from_address'];
153 $email = $form_state['values']['rsvp_from_address'];
154
155 //always store emailaddress, even if not used
156 variable_set('rsvp_from_address', array($pick => $email));
157
158 variable_set('rsvp_for_expired_event', $form_state['values']['rsvp_for_expired_event']);
159
160 foreach ($rsvp_mailer_ops as $op => $op_name) {
161 variable_set("rsvp_default_mailer_{$op}_subject", $form_state['values']["rsvp_mailer_{$op}_subject"]);
162 variable_set("rsvp_default_mailer_{$op}_message", $form_state['values']["rsvp_mailer_{$op}_message"]);
163 }
164
165
166 drupal_set_message('Settings have been stored.');
167 }
168 elseif ($op == t('Reset to defaults')) {
169
170 variable_del('rsvp_from_address');
171 variable_del('rsvp_for_expired_event');
172
173 foreach ($rsvp_mailer_ops as $op => $op_name) {
174 variable_del("rsvp_default_mailer_{$op}_subject");
175 variable_del("rsvp_default_mailer_{$op}_message");
176 }
177
178 drupal_set_message('General settings have been reset to their default values.');
179 }
180
181
182
183 }
184
185 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
186
187 /**
188 * Menu callback: rsvp admin set default values for invitations.
189 *
190 * @see rsvp_admin_settings_default_submit()
191 * @ingroup rsvp_admin
192 */
193
194 function rsvp_admin_settings_default(&$form_state) {
195
196 //create a rsvp and use it to set the default values.
197 $rsvp = rsvp_function_initialize_default_rsvp();
198
199 $form = array();
200
201 $form[] = array(
202 '#value' => t('Please set default values for the following advanced options.<br />'),
203 );
204
205
206 $form['rsvp_field_6'] = array(
207 '#type' => 'fieldset',
208 '#title' => t('Invitation style'),
209 );
210
211 $form['rsvp_field_6']['theme'] = rsvp_form_element_theme($rsvp);
212 $form['rsvp_field_6']['stylesheet'] = rsvp_form_element_stylesheet($rsvp->theme, $rsvp->stylesheet);
213 $form['rsvp_field_6']['rsvp_addedit_form']['image'] = rsvp_form_element_image($rsvp->image);
214 $form['rsvp_field_6']['rsvp_addedit_form']['backgroundimage'] = rsvp_form_element_backgroundimage($rsvp->backgroundimage);
215 $form['rsvp_field_6']['iconset'] = rsvp_form_element_iconset($rsvp->iconset);
216
217 $form['rsvp_view_roles'] = rsvp_form_element_rsvp_view_roles($rsvp);
218
219 $form['open_invitation'] = rsvp_form_element_open_invitation($rsvp);
220 $form['max_guests'] = rsvp_form_element_max_guests($rsvp);
221
222 $form['rsvp_field_5'] = array(
223 '#type' => 'fieldset',
224 '#title' => t('Notification options'),
225 );
226
227 $form['rsvp_field_5']['send_conf_owner'] = rsvp_form_element_send_conf_owner($rsvp);
228 $form['rsvp_field_5']['send_conf_guest'] = rsvp_form_element_send_conf_guest($rsvp);
229 $form['rsvp_field_5']['send_privatemsg'] = rsvp_form_element_send_privatemsg($rsvp);
230
231 $form['rsvp_field_2'] = array(
232 '#type' => 'fieldset',
233 '#title' => t('Guest list options'),
234 );
235
236 $form['rsvp_field_2']['response_blind'] = rsvp_form_element_response_blind($rsvp);
237 $form['rsvp_field_2']['attendees_visible'] = rsvp_form_element_attendees_visible($rsvp);
238 $form['rsvp_field_2']['response_blind_node'] = rsvp_form_element_response_blind_node($rsvp);
239 $form['rsvp_field_2']['response_view_roles'] = rsvp_form_element_response_view_roles($rsvp);
240 $form['rsvp_field_2']['text_whoiscoming'] = rsvp_form_element_text_whoiscoming($rsvp);
241 $form['rsvp_field_2']['text_yes'] = rsvp_form_element_text_yes($rsvp);
242 $form['rsvp_field_2']['text_no'] = rsvp_form_element_text_no($rsvp);
243 $form['rsvp_field_2']['text_maybe'] = rsvp_form_element_text_maybe($rsvp);
244
245
246 $form['rsvp_field_3'] = array(
247 '#type' => 'fieldset',
248 '#title' => t('Guest options'),
249 );
250
251 $form['rsvp_field_3']['list_email'] = rsvp_form_element_list_email($rsvp);
252 $form['rsvp_field_3']['allow_invite'] = rsvp_form_element_allow_invite($rsvp);
253
254
255 $form['rsvp_field_4'] = array(
256 '#type' => 'fieldset',
257 '#title' => t('Reply options'),
258 );
259
260 $form['rsvp_field_4']['disable_maybe'] = rsvp_form_element_disable_maybe($rsvp);
261 $form['rsvp_field_4']['reply_blind_node'] = rsvp_form_element_reply_blind_node($rsvp);
262
263
264
265 $form['submit'] = array(
266 '#type' => 'submit',
267 '#value' => t('Save'),
268 '#weight' => 25,
269 );
270
271 return $form;
272 }
273
274 /*
275 * @ingroup rsvp_admin
276 */
277 function rsvp_admin_settings_default_submit($form, &$form_state) {
278
279 //array_diff removes all '0' values from the returned selection
280 $vals_response_view_roles = implode(";", array_diff($form_state['values']['response_view_roles'], array('0')));
281
282 //array_diff removes all '0' values from the returned selection
283 $vals_rsvp_view_roles = implode(";", array_diff($form_state['values']['rsvp_view_roles'], array('0')));
284
285
286 foreach (array('max_guests', 'open_invitation', 'disable_maybe', 'send_privatemsg',
287 'send_conf_guest', 'send_conf_owner',
288 'response_blind', 'response_blind_node',
289 'reply_blind_node', 'attendees_visible', 'list_email', 'allow_invite',
290 'text_whoiscoming', 'text_yes', 'text_no', 'text_maybe', 'theme', 'stylesheet', 'iconset', 'backgroundimage', 'image') as $key) {
291
292 variable_set('rsvp_default_' . $key, $form_state['values'][$key]);
293 }
294
295 variable_set('rsvp_default_response_view_roles', $vals_response_view_roles);
296 variable_set('rsvp_default_rsvp_view_roles', $vals_rsvp_view_roles);
297
298 }
299
300
301 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
302
303 /**
304 * @ingroup rsvp_admin
305 *
306 * Menu callback: rsvp admin current associations form for rsvp.
307 *
308 */
309 function rsvp_admin_settings_types(&$form_state) {
310
311 $form = array();
312
313
314 $connector = new RsvpConnector();
315 if (!$connector->isTypesAreSelectable()) {
316 return $form;
317 }
318
319 // The table with all associations
320
321 $header = array(t('Content type'), t('Field'), t('Description'), t('Operation'));
322
323 $rsvp_content_types = variable_get('rsvp_content_types', array());
324
325 $rows = array();
326 foreach ( $rsvp_content_types as $contenttype => $field ) {
327 $ct = content_types($contenttype);
328
329 $rows[] = array(l($ct['name'], 'admin/content/node-type/'. $contenttype),
330 t($field),
331 t($ct['description']),
332 l(t('delete'), 'admin/settings/rsvp/types/delete/'. $contenttype, array(), drupal_get_destination())
333 );
334 }
335
336
337 if ($pager = theme('pager', NULL, 10, 0)) {
338 $rows[] = array(array('data' => $pager, 'colspan' => '4'));
339 }
340 if (!$rows) {
341 $rows[] = array(array('data' => t('No associations available.'), 'colspan' => '4'));
342 }
343
344 $table = theme('table', $header, $rows);
345
346 $form['table'] = array('#value' => $table);
347
348
349 return $form;
350
351 }
352
353
354 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
355
356 /**
357 * @ingroup rsvp_admin
358 *
359 * Menu callback: rsvp admin add new association for rsvp.
360 *
361 */
362 function rsvp_admin_settings_types_add(&$form_state) {
363
364 $form = array();
365
366 $connector = new RsvpConnector();
367 if (!$connector->isTypesAreSelectable()) {
368 return $form;
369 }
370
371 // The table with all Content Types
372
373 $header = array(t('Content type'), t('Description'), t('Operation'));
374
375 $rsvp_content_types = variable_get('rsvp_content_types', array());
376 $contenttypes = node_get_types('types');
377
378 //remove all types from $contenttypes that we already selected
379 foreach ( $rsvp_content_types as $contenttype => $field ) {
380 unset($contenttypes[$contenttype]);
381 }
382
383 //var_dump($contenttypes);
384
385 $rows = array();
386 foreach ($contenttypes as $ct) {
387 $rows[] = array(l($ct->name, 'admin/content/node-type/'. $ct->type),
388 t($ct->description),
389 l(t('add'), 'admin/settings/rsvp/types/add/'. $ct->type, array(), drupal_get_destination())
390 );
391 }
392
393
394 if ($pager = theme('pager', NULL, 10, 0)) {
395 $rows[] = array(array('data' => $pager, 'colspan' => '3'));
396 }
397 if (!$rows) {
398 $rows[] = array(array('data' => t('No associations available.'), 'colspan' => '3'));
399 }
400
401 $table = theme('table', $header, $rows);
402
403 $form['table'] = array('#value' => $table);
404
405
406 return $form;
407 }
408
409 //////////////////////////////////////////////////////////////////////////////////////
410
411 /**
412 * @ingroup rsvp_admin
413 *
414 * Menu callback: Delete association entry.
415 *
416 * @see rsvp_admin_settings_types_delete_submit()
417 */
418
419 function rsvp_admin_settings_types_delete(&$form_state, $contenttype = NULL) {
420
421 if (!isset($contenttype)) {
422 drupal_not_found();
423 return;
424 }
425
426 $form = array();
427
428 $connector = new RsvpConnector();
429 if (!$connector->isTypesAreSelectable()) {
430 drupal_goto($return_url);
431 }
432
433 $form['contenttype'] = array( '#type' => 'value', '#value' => $contenttype);
434
435 $ct = content_types($contenttype);
436
437 $form['notice'] = array(
438 '#value' => '<p><strong>'. t('Note: All invitations using this content type will be lost.') .'</strong></p>',
439 );
440
441 return confirm_form($form,
442 t('Are you sure you want to delete the association of the RSVP module with %type?', array('%type' => $ct['name'])),
443 'admin/settings/rsvp/types',
444 t('This action cannot be undone.'),
445 t('Delete'),
446 t('Cancel')
447 );
448 }
449
450 function rsvp_admin_settings_types_delete_submit($form, &$form_state) {
451 if ($form_state['values']['confirm']) {
452
453 // TODO: remove Invitations related to this field from the db
454
455 $contenttype = $form_state['values']['contenttype'];
456
457 $ct = content_types($contenttype);
458
459 $rsvp_content_types = variable_get('rsvp_content_types', array());
460 unset($rsvp_content_types[$contenttype]);
461 variable_set('rsvp_content_types', $rsvp_content_types);
462
463 drupal_set_message(t('Association with content type %type and field %field has been removed.', array('%type' => $ct['name'], '%field' => $field)));
464
465 }
466
467 $form_state['redirect'] = 'admin/settings/rsvp/types';
468
469 }
470
471
472
473 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
474
475 /**
476 * Menu callback: rsvp admin add new association form for rsvp.
477 *
478 * @see rsvp_admin_settings_types_add_field_submit()
479 */
480 function rsvp_admin_settings_types_add_field(&$form_state, $contenttype = NULL) {
481
482 if (!isset($contenttype)) {
483 drupal_not_found();
484 return;
485 }
486
487 $form = array();
488 $fields = array();
489
490 $connector = new RsvpConnector();
491
492 if (!$connector->hasMultipleDatesPerField()) {
493 //return e.g. for event connector here because we have exactly one field, and the connector knows its name
494 $rsvp_content_types = variable_get('rsvp_content_types', array());
495 $rsvp_content_types[$contenttype] = '';
496 variable_set('rsvp_content_types', $rsvp_content_types);
497 drupal_set_message(t('Association for content type %type has been added.', array(type => '$contenttype')));
498 drupal_goto('admin/settings/rsvp/types');
499 return $form;
500 }
501
502 // collect cck fields
503 $ct = content_types($contenttype);
504
505 // Loop the fields for the given type
506 foreach ( $ct['fields'] as $field_name => $field ) {
507 $fields[$field_name] = $field['field_name'];
508 }
509
510 $form['rsvp_admin_settings_types_add_field']['event_contenttype'] = array(
511 '#type' => 'item',
512 '#title' => t('For content type'),
513 '#value' => t($ct['name']),
514 );
515
516
517 $form['rsvp_admin_settings_types_add_field']['event_start_field'] = array(
518 '#type' => 'select',
519 '#title' => t('Event start field'),
520 '#required' => TRUE,
521 '#options' => array_map('check_plain', $fields),
522 // '#default_value' => isset($vocabulary) ? $vocabulary->nodes : array(),
523 '#description' => t('%contenttype field to be used as rsvp start date.', array('%contenttype' => $contenttype)),
524 );
525
526 $form['rsvp_admin_settings_types_add_field']['submit'] = array(
527 '#type' => 'submit',
528 '#value' => t('Save'),
529 '#weight' => 25,
530 );
531
532 $form['contenttype'] = array('#type' => 'value', '#value' => $contenttype);
533
534 return $form;
535 }
536
537 function rsvp_admin_settings_types_add_field_submit($form, &$form_state) {
538
539 $contenttype = $form_state['values']['contenttype'];
540 $field = $form_state['values']['event_start_field'];
541
542 $ct = content_types($contenttype);
543
544 $rsvp_content_types = variable_get('rsvp_content_types', array());
545 $rsvp_content_types[$contenttype] = $field;
546 variable_set('rsvp_content_types', $rsvp_content_types);
547
548 drupal_set_message(t('Association with content type %type and field %field has been added.', array('%type' => $ct['name'], '%field' => $field)));
549
550 // Return to Association list page after submit
551 $form_state['redirect'] = 'admin/settings/rsvp/types';
552 }
553
554 /*
555 * Access function for the admin/settings section to determine if the logged-in user
556 * 1) has admin permissions and
557 * 2) the current connector supports content-type associations or not
558 *
559 * @param $connector The connector you are using.
560 * @return true or false.
561 *
562 */
563 function rsvp_admin_type_access($connector) {
564
565 if (!$connector->isTypesAreSelectable())
566 return false;
567
568 return (user_access(RSVP_PERM_ADMIN));
569 }
570
571
572 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
573

  ViewVC Help
Powered by ViewVC 1.1.2