Parent Directory
|
Revision Log
|
Revision Graph
*** empty log message ***
| 1 | <?php |
| 2 | // $Id$ |
| 3 | |
| 4 | /** |
| 5 | * @module rsvp |
| 6 | * @package rsvp - A drupal module developed for civicspace - a distribution of drupal. |
| 7 | * @description Provides email invite and tracking functionality for nodes. Requires event.module or date.module. |
| 8 | * @author crunchywelch (welch@advomatic.com) |
| 9 | * @author Omar Abdel-Wahab (owahab@gmail.com) |
| 10 | * @author Ulf Schenk (ulf@schenkunlimited.net) |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | |
| 15 | // Pre Loading files that will be required in this module |
| 16 | foreach (array('functions', 'api', 'blocks', 'form', 'mailer', 'admin', 'actions') as $file) { |
| 17 | module_load_include("inc", "rsvp", "rsvp.{$file}"); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @defgroup rsvp_core core functions for rsvp. |
| 22 | */ |
| 23 | |
| 24 | /** |
| 25 | * Implementations of hook_views_api(). |
| 26 | * |
| 27 | * @ingroup rsvp_core |
| 28 | * |
| 29 | */ |
| 30 | function rsvp_views_api() { |
| 31 | return array( |
| 32 | 'api' => 2, |
| 33 | 'path' => drupal_get_path('module','rsvp'), |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Implementation of hook_theme. |
| 39 | * |
| 40 | * @ingroup rsvp_core |
| 41 | * |
| 42 | */ |
| 43 | function rsvp_theme($existing, $type, $theme, $path) { |
| 44 | return array( |
| 45 | 'rsvp_status' => array( |
| 46 | 'file' => 'rsvp.theme', |
| 47 | 'arguments' => array('statusin' => NULL), |
| 48 | ), |
| 49 | 'rsvp_help' => array( |
| 50 | 'file' => 'rsvp.theme', |
| 51 | 'arguments' => array('content' => NULL), |
| 52 | ), |
| 53 | 'rsvp_invitation_page' => array( |
| 54 | 'theme paths' => array(file_directory_path()), |
| 55 | 'template' => 'themes/default/rsvp-invitation-page', |
| 56 | 'arguments' => array('connector' => NULL, 'rsvp' => NULL, 'invite_target' => NULL, 'params' => NULL), |
| 57 | ), |
| 58 | |
| 59 | 'rsvp_invitation' => array( |
| 60 | 'theme paths' => array(file_directory_path()), |
| 61 | 'template' => 'themes/default/rsvp-invitation', |
| 62 | 'arguments' => array('connector' => NULL, 'rsvp' => NULL, 'invite_target' => NULL, 'node' => NULL, 'params' => NULL), |
| 63 | ), |
| 64 | |
| 65 | 'rsvp_guestlist' => array( |
| 66 | 'theme paths' => array(file_directory_path()), |
| 67 | 'template' => 'themes/default/rsvp-guestlist', |
| 68 | 'arguments' => array('connector' => NULL, 'rsvp' => NULL, 'invite_target' => NULL, 'params' => NULL), |
| 69 | ), |
| 70 | |
| 71 | 'rsvp_guestlist_block' => array( |
| 72 | 'theme paths' => array(file_directory_path()), |
| 73 | 'template' => 'themes/default/rsvp-guestlist-block', |
| 74 | 'arguments' => array('connector' => NULL, 'rsvp' => NULL, 'invite_target' => NULL, 'params' => NULL), |
| 75 | ), |
| 76 | |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Provides a pathetically small amount of help information for the rsvp module. |
| 82 | * |
| 83 | * @ingroup rsvp_forms |
| 84 | */ |
| 85 | function rsvp_help($path, $arg) { |
| 86 | switch ($path) { |
| 87 | case 'admin/help#rsvp': |
| 88 | |
| 89 | global $user; |
| 90 | $output = '<p>'. t('The RSVP module lets users invite people by email to events and track a list of people who will be attending. The RSVP module requires either the event module or the date module because it is necessary to specify a content type to invite people to first.') .'</p>'; |
| 91 | $output .= '<p>'. t('The RSVP module also lets users invite users subscribed to newsletters, which requires !simplenews installed, as well as invite other registered users.', array('!simplenews' => l(t('Simplenews module'), 'http://drupal.org/project/simplenews'))) .'</p>'; |
| 92 | $output .= '<p>'. t('The RSVP page shows an <em>Invitation</em> tab in the content type page and in the users <em>My account</em> page. There are confirmation screens for creating and editing invitations. Email addresses which are input for invitations have input validation. RSVP also creates an invitation url by hash value access so that invitees can click a URL and be taken directly to their invitation. For each invitation there are view, edit, manage, and send tabs. Users can manage guests through the "manage guests" tab. Users can also send attendees a message through the send message tab.') .'</p>'; |
| 93 | $output .= t('<p>You can:</p> |
| 94 | <ul> |
| 95 | <li>Enable the RSVP module at !admin-modules.</li> |
| 96 | <li>Create an invitation by clicking the <strong>Create invitation</strong> link in the Invitation tab when displying your event.</li> |
| 97 | <li>View your invitations in your !rsvp-user.</li> |
| 98 | <li>View, edit, and invite more people to each invitation.</li> |
| 99 | <li>Manage all invitations at !rsvp-content.</li> |
| 100 | ', array('!admin-modules' => l(t('Administer >> modules'), 'admin/build/modules'), |
| 101 | '!rsvp-user' => l(t('user profile'), 'user/'. $user->uid .'/rsvp'), |
| 102 | '!rsvp-content' => l(t('Administer >> Content management >> RSVP management'),'admin/content/rsvp')) ) .'</ul>'; |
| 103 | |
| 104 | $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="!rsvp">RSVP page</a>.', array('!rsvp' => url('http://www.drupal.org/handbook/modules/rsvp/', array('external' => TRUE)))) .'</p>'; |
| 105 | return $output; |
| 106 | case 'admin/modules#description' : |
| 107 | return t('Provides rsvp functionality for node types enabled in the rsvp system.'); |
| 108 | case 'rsvp/'. arg(1) .'/message' : |
| 109 | return t('You can send a message to the attendees of this invitation here.'); |
| 110 | case 'rsvp/'. arg(1) .'/attendees' : |
| 111 | return t('You can add more persons to the invitation, remove invitees, or view the status of an invitees\'s invitation here.'); |
| 112 | case 'rsvp' : |
| 113 | global $user; |
| 114 | if (!$user->uid) { |
| 115 | return t('You must %login or %register in order to manage your invitations from this site. Otherwise, please use the link provided in your email to reply. If the link does not work, contact the sender of the invitation to see if the event has been deleted.', array('%login' => l('login', 'user'), '%register' => l('create a user account', 'user/register'))); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Provides the rsvp permission information for the drupal system. |
| 122 | * |
| 123 | * @ingroup rsvp_core |
| 124 | */ |
| 125 | function rsvp_perm() { |
| 126 | return array(RSVP_PERM_ADMIN, |
| 127 | RSVP_PERM_MAINTAIN, |
| 128 | RSVP_PERM_ONEVENTS, |
| 129 | RSVP_PERM_ONOWNEVENTS); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Implementation of hook_cron |
| 134 | * @ingroup rsvp_core |
| 135 | * |
| 136 | * Processing assuring that new users get their invitations associated with their account. |
| 137 | */ |
| 138 | function rsvp_cron() { |
| 139 | db_query('UPDATE {rsvp_invite} r, {users} u SET r.uid = u.uid WHERE r.uid = 0 AND r.email = u.mail'); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Implementation of hook_init(). |
| 144 | */ |
| 145 | function rsvp_init() { |
| 146 | // drupal_add_css(drupal_get_path('module', 'rsvp') .'/rsvp.css', 'module', 'all', TRUE); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Implementation of hook_menu(). |
| 151 | * |
| 152 | * @ingroup rsvp_core |
| 153 | * |
| 154 | */ |
| 155 | function rsvp_menu() { |
| 156 | |
| 157 | $connector = new RsvpConnector(); |
| 158 | |
| 159 | $items = array(); |
| 160 | |
| 161 | //admin settings tab |
| 162 | $items['admin/settings/rsvp'] = array( |
| 163 | 'title' => 'RSVP settings', |
| 164 | 'type' => MENU_NORMAL_ITEM, |
| 165 | 'description' => 'Set up RSVP related options.', |
| 166 | 'page callback' => 'drupal_get_form', |
| 167 | 'page arguments' => array('rsvp_admin_settings_general'), |
| 168 | 'access arguments' => array(RSVP_PERM_ADMIN), |
| 169 | 'description' => 'Configure general RSVP settings.', |
| 170 | 'file' => 'rsvp.admin.inc', |
| 171 | ); |
| 172 | |
| 173 | $items['admin/settings/rsvp/general'] = array( |
| 174 | 'title' => 'General', |
| 175 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 176 | 'page callback' => 'drupal_get_form', |
| 177 | 'page arguments' => array('rsvp_admin_settings_general'), |
| 178 | 'access arguments' => array(RSVP_PERM_ADMIN), |
| 179 | 'weight' => -10, |
| 180 | 'description' => 'Configure general RSVP settings.', |
| 181 | 'file' => 'rsvp.admin.inc', |
| 182 | ); |
| 183 | |
| 184 | $items['admin/settings/rsvp/defaults'] = array( |
| 185 | 'title' => 'Default settings', |
| 186 | 'type' => MENU_LOCAL_TASK, |
| 187 | 'page callback' => 'drupal_get_form', |
| 188 | 'page arguments' => array('rsvp_admin_settings_default'), |
| 189 | 'access arguments' => array(RSVP_PERM_ADMIN), |
| 190 | 'weight' => -9, |
| 191 | 'description' => 'Configure default options for invitations', |
| 192 | 'file' => 'rsvp.admin.inc', |
| 193 | ); |
| 194 | |
| 195 | $items['admin/settings/rsvp/types'] = array( |
| 196 | 'title' => 'Associations', |
| 197 | 'type' => MENU_LOCAL_TASK, |
| 198 | 'page callback' => 'drupal_get_form', |
| 199 | 'page arguments' => array('rsvp_admin_settings_types'), |
| 200 | 'access callback' => 'rsvp_admin_type_access', |
| 201 | 'access arguments' => array($connector), |
| 202 | 'weight' => -9, |
| 203 | 'description' => 'Manage associations with content types that you want to use within invitations.', |
| 204 | 'file' => 'rsvp.admin.inc', |
| 205 | ); |
| 206 | |
| 207 | $items['admin/settings/rsvp/types/list'] = array( |
| 208 | 'title' => 'List associations', |
| 209 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 210 | 'page callback' => 'drupal_get_form', |
| 211 | 'page arguments' => array('rsvp_admin_settings_types'), |
| 212 | 'access callback' => 'rsvp_admin_type_access', |
| 213 | 'access arguments' => array($connector), |
| 214 | 'weight' => -8, |
| 215 | 'description' => 'Manage associations with content types that you want to use within invitations.', |
| 216 | 'file' => 'rsvp.admin.inc', |
| 217 | ); |
| 218 | |
| 219 | $items['admin/settings/rsvp/types/add'] = array( |
| 220 | 'title' => 'Add association', |
| 221 | 'type' => MENU_LOCAL_TASK, |
| 222 | 'page callback' => 'drupal_get_form', |
| 223 | 'page arguments' => array('rsvp_admin_settings_types_add'), |
| 224 | 'access callback' => 'rsvp_admin_type_access', |
| 225 | 'access arguments' => array($connector), |
| 226 | 'weight' => -7, |
| 227 | 'description' => 'Add a association with a content type that you want to use within invitations.', |
| 228 | 'file' => 'rsvp.admin.inc', |
| 229 | ); |
| 230 | |
| 231 | $items['admin/settings/rsvp/types/add/%'] = array( |
| 232 | 'title' => 'Select field for association', |
| 233 | 'type' => MENU_CALLBACK, |
| 234 | 'page callback' => 'drupal_get_form', |
| 235 | 'page arguments' => array('rsvp_admin_settings_types_add_field', 5), |
| 236 | 'access callback' => 'rsvp_admin_type_access', |
| 237 | 'access arguments' => array($connector), |
| 238 | 'file' => 'rsvp.admin.inc', |
| 239 | ); |
| 240 | |
| 241 | $items['admin/settings/rsvp/types/delete/%'] = array( |
| 242 | 'title' => 'Delete association', |
| 243 | 'type' => MENU_CALLBACK, |
| 244 | 'page callback' => 'drupal_get_form', |
| 245 | 'page arguments' => array('rsvp_admin_settings_types_delete', 5), |
| 246 | 'access callback' => 'rsvp_admin_type_access', |
| 247 | 'access arguments' => array($connector), |
| 248 | 'file' => 'rsvp.admin.inc', |
| 249 | ); |
| 250 | |
| 251 | //admin content tab |
| 252 | $items['admin/content/rsvp'] = array( |
| 253 | 'title' => 'RSVP management', |
| 254 | 'type' => MENU_NORMAL_ITEM, |
| 255 | 'description' => 'Manage all invitations.', |
| 256 | 'page callback' => 'drupal_get_form', |
| 257 | 'page arguments' => array('rsvp_overview_created_form', NULL, NULL), |
| 258 | 'access callback' => 'rsvp_overview_created_form_access', |
| 259 | 'access arguments' => array($connector, NULL, NULL), |
| 260 | 'description' => 'Manage all invitations.', |
| 261 | ); |
| 262 | |
| 263 | |
| 264 | // user account tabs |
| 265 | $items['user/%user/rsvp'] = array( |
| 266 | 'title' => 'Invitations', |
| 267 | 'type' => MENU_LOCAL_TASK, |
| 268 | 'page callback' => 'drupal_get_form', |
| 269 | 'page arguments' => array('rsvp_overview_form', NULL, 1), |
| 270 | 'access callback' => 'rsvp_overview_form_access', |
| 271 | 'access arguments' => array($connector, 1, NULL), |
| 272 | ); |
| 273 | |
| 274 | // email response path (for guest access) |
| 275 | $items['rsvp/email/%rsvp_hash/edit'] = array( |
| 276 | 'title' => 'Edit guests reply', |
| 277 | 'type' => MENU_CALLBACK, |
| 278 | 'page callback' => 'drupal_get_form', |
| 279 | 'page arguments' => array('rsvp_guest_editreply_form', 2), |
| 280 | 'access callback' => 'rsvp_guest_editreply_form_access', |
| 281 | 'access arguments' => array($connector, 2), |
| 282 | 'weight' => 0, |
| 283 | ); |
| 284 | $items['rsvp/email/%rsvp_hash'] = array( |
| 285 | 'title' => 'View invitation', |
| 286 | 'type' => MENU_NORMAL_ITEM, |
| 287 | 'page callback' => 'drupal_get_form', |
| 288 | 'page arguments' => array('rsvp_invite_view_form', NULL, 2), |
| 289 | 'access callback' => 'rsvp_invite_view_form_access', |
| 290 | 'access arguments' => array($connector, NULL, 2), |
| 291 | ); |
| 292 | $items['rsvp/email/%rsvp_hash/view'] = array( |
| 293 | 'title' => 'View invitation', |
| 294 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 295 | 'page callback' => 'drupal_get_form', |
| 296 | 'page arguments' => array('rsvp_invite_view_form', NULL, 2), |
| 297 | 'access callback' => 'rsvp_invite_view_form_access', |
| 298 | 'access arguments' => array($connector, NULL, 2), |
| 299 | 'weight' => 0, |
| 300 | ); |
| 301 | $items['rsvp/email/%rsvp_hash/attendees'] = array( |
| 302 | 'title' => 'Add guests', |
| 303 | 'type' => MENU_LOCAL_TASK, |
| 304 | 'description' => 'Add more guests to the invitation.', |
| 305 | 'page callback' => 'drupal_get_form', |
| 306 | 'page arguments' => array('rsvp_attendee_hash_form', 2), |
| 307 | 'access callback' => 'rsvp_attendee_hash_form_access', |
| 308 | 'access arguments' => array($connector, 2), |
| 309 | 'weight' => 1, |
| 310 | ); |
| 311 | $items['rsvp/email/%rsvp_hash/message'] = array( |
| 312 | 'title' => 'Send message', |
| 313 | 'type' => MENU_LOCAL_TASK, |
| 314 | 'page callback' => 'drupal_get_form', |
| 315 | 'page arguments' => array('rsvp_message_hash_form', 2), |
| 316 | 'access callback' => 'rsvp_hash_sendmessage_access', |
| 317 | 'access arguments' => array($connector, 2), |
| 318 | 'weight' => 2, |
| 319 | ); |
| 320 | $items['rsvp/email/%rsvp_hash/csv'] = array( |
| 321 | 'type' => MENU_CALLBACK, |
| 322 | 'page callback' => 'drupal_get_form', |
| 323 | 'page arguments' => array('rsvp_csv_hash_form', NULL, 2), |
| 324 | 'access callback' => 'rsvp_csv_hash_form_access', |
| 325 | 'access arguments' => array($connector, NULL, 2), |
| 326 | ); |
| 327 | $items['rsvp/email/%rsvp_hash/realname'] = array( |
| 328 | 'type' => MENU_CALLBACK, |
| 329 | 'page callback' => 'drupal_get_form', |
| 330 | 'page arguments' => array('rsvp_changerealname_form', 2), |
| 331 | 'access callback' => 'rsvp_changerealname_form_access', |
| 332 | 'access arguments' => array($connector, 2), |
| 333 | ); |
| 334 | $items['node/%node/rsvp'] = array( |
| 335 | 'title' => 'Invitations', |
| 336 | 'type' => MENU_LOCAL_TASK, |
| 337 | 'page callback' => 'drupal_get_form', |
| 338 | 'page arguments' => array('rsvp_overview_form', 1, NULL), |
| 339 | 'access callback' => 'rsvp_overview_form_access', |
| 340 | 'access arguments' => array($connector, NULL, 1), |
| 341 | 'weight' => 3, |
| 342 | ); |
| 343 | $items['node/%node/rsvp/create'] = array( |
| 344 | 'title' => 'Create invitation', |
| 345 | 'type' => MENU_CALLBACK, |
| 346 | 'page callback' => 'drupal_get_form', |
| 347 | 'page arguments' => array('rsvp_addedit_form', 1, NULL), |
| 348 | 'access callback' => 'rsvp_addedit_form_access', |
| 349 | 'access arguments' => array($connector, NULL, 1, RSVP_ACCESS_CREATE), |
| 350 | 'description' => 'Create a new invitation.', |
| 351 | ); |
| 352 | |
| 353 | // rsvp management tabs |
| 354 | $items['rsvp/%rsvp'] = array( |
| 355 | 'title' => 'View', |
| 356 | 'type' => MENU_NORMAL_ITEM, |
| 357 | 'page callback' => 'drupal_get_form', |
| 358 | 'page arguments' => array('rsvp_invite_viewonly_form', 1, NULL), |
| 359 | 'access callback' => 'rsvp_invite_viewonly_form_access', |
| 360 | 'access arguments' => array($connector, 1, NULL), |
| 361 | 'weight' => '0', |
| 362 | ); |
| 363 | $items['rsvp/%rsvp/view'] = array( |
| 364 | 'title' => 'View', |
| 365 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 366 | 'page callback' => 'drupal_get_form', |
| 367 | 'page arguments' => array('rsvp_invite_viewonly_form', 1, NULL), |
| 368 | 'access callback' => 'rsvp_invite_viewonly_form_access', |
| 369 | 'access arguments' => array($connector, 1, NULL), |
| 370 | 'weight' => '0', |
| 371 | ); |
| 372 | $items['rsvp/%rsvp/owner'] = array( |
| 373 | 'title' => 'Change the owner of the invitation', |
| 374 | 'type' => MENU_CALLBACK, |
| 375 | 'page callback' => 'drupal_get_form', |
| 376 | 'page arguments' => array('rsvp_changeowner_form', 1), |
| 377 | 'access callback' => 'rsvp_changeowner_form_access', |
| 378 | 'access arguments' => array($connector, 1), |
| 379 | ); |
| 380 | $items['rsvp/%rsvp/msg_moderator'] = array( |
| 381 | 'title' => 'Send me a message when guests reply', |
| 382 | 'type' => MENU_CALLBACK, |
| 383 | 'page callback' => 'drupal_get_form', |
| 384 | 'page arguments' => array('rsvp_msg_moderator_form', 1), |
| 385 | 'access callback' => 'rsvp_msg_moderator_form_access', |
| 386 | 'access arguments' => array($connector, 1), |
| 387 | ); |
| 388 | |
| 389 | $items['rsvp/%rsvp/edit'] = array( |
| 390 | 'title' => 'Edit', |
| 391 | 'type' => MENU_LOCAL_TASK, |
| 392 | 'page callback' => 'drupal_get_form', |
| 393 | 'page arguments' => array('rsvp_addedit_form', NULL, 1), |
| 394 | 'access callback' => 'rsvp_addedit_form_access', |
| 395 | 'access arguments' => array($connector, 1, NULL, RSVP_ACCESS_EDIT), |
| 396 | 'weight' => '1', |
| 397 | 'description' => 'Modify an existing invitation.', |
| 398 | ); |
| 399 | $items['rsvp/%rsvp/attendees'] = array( |
| 400 | 'title' => 'Manage guests', |
| 401 | 'type' => MENU_LOCAL_TASK, |
| 402 | 'page callback' => 'drupal_get_form', |
| 403 | 'page arguments' => array('rsvp_attendee_form', 1, NULL, NULL), |
| 404 | 'access callback' => 'rsvp_attendee_form_access', |
| 405 | 'access arguments' => array($connector, 1, NULL), |
| 406 | 'weight' => '2', |
| 407 | ); |
| 408 | $items['rsvp/%rsvp/attendees/send'] = array( |
| 409 | 'title' => 'Send invitation email', |
| 410 | 'type' => MENU_CALLBACK, |
| 411 | 'page callback' => 'drupal_get_form', |
| 412 | 'page arguments' => array('rsvp_attendees_send_invitation_form', 1, NULL), |
| 413 | 'access callback' => 'rsvp_attendees_send_invitation_form_access', |
| 414 | 'access arguments' => array($connector, 1, NULL), |
| 415 | 'weight' => '2', |
| 416 | ); |
| 417 | $items['rsvp/%rsvp/attendees/send/%'] = array( |
| 418 | 'title' => 'Send invitation email', |
| 419 | 'type' => MENU_CALLBACK, |
| 420 | 'page callback' => 'drupal_get_form', |
| 421 | 'page arguments' => array('rsvp_attendees_send_invitation_form', 1, 4), |
| 422 | 'access callback' => 'rsvp_attendees_send_invitation_form_access', |
| 423 | 'access arguments' => array($connector, 1, NULL), |
| 424 | 'weight' => '2', |
| 425 | ); |
| 426 | $items['rsvp/%rsvp/attendees/csv'] = array( |
| 427 | 'type' => MENU_CALLBACK, |
| 428 | 'page callback' => 'drupal_get_form', |
| 429 | 'page arguments' => array('rsvp_csv_hash_form', 1, NULL), |
| 430 | 'access callback' => 'rsvp_csv_hash_form_access', |
| 431 | 'access arguments' => array($connector, 1, NULL), |
| 432 | ); |
| 433 | $items['rsvp/%rsvp/attendees/remove/%'] = array( |
| 434 | 'title' => 'Remove guest from guest list', |
| 435 | 'type' => MENU_CALLBACK, |
| 436 | 'page callback' => 'drupal_get_form', |
| 437 | 'page arguments' => array('rsvp_remove_guest_form', 1, 4), |
| 438 | 'access callback' => 'rsvp_function_invitation_by_invite_access', |
| 439 | 'access arguments' => array($connector, 1, NULL, NULL, RSVP_ACCESS_EDIT), |
| 440 | ); |
| 441 | $items['rsvp/%rsvp/attendees/status/%'] = array( |
| 442 | 'title' => 'Status of attendee', |
| 443 | 'type' => MENU_CALLBACK, |
| 444 | 'page callback' => 'drupal_get_form', |
| 445 | 'page arguments' => array('rsvp_guest_status_form', 1, 4), |
| 446 | 'access callback' => 'rsvp_function_invitation_by_invite_access', |
| 447 | 'access arguments' => array($connector, 1, NULL, NULL, RSVP_ACCESS_EDIT), |
| 448 | ); |
| 449 | |
| 450 | $items['rsvp/%rsvp/message'] = array( |
| 451 | 'title' => 'Send message', |
| 452 | 'type' => MENU_LOCAL_TASK, |
| 453 | 'page callback' => 'drupal_get_form', |
| 454 | 'page arguments' => array('rsvp_message_form', 1, NULL), |
| 455 | 'access callback' => 'rsvp_function_invitation_by_invite_access', |
| 456 | 'access arguments' => array($connector, 1, NULL, NULL, RSVP_ACCESS_EDIT), |
| 457 | 'weight' => '3', |
| 458 | ); |
| 459 | $items['rsvp/%rsvp/message/%'] = array( |
| 460 | 'title' => 'Send message', |
| 461 | 'type' => MENU_CALLBACK, |
| 462 | 'page callback' => 'drupal_get_form', |
| 463 | 'page arguments' => array('rsvp_message_form', 1, 3), |
| 464 | 'access callback' => 'rsvp_function_invitation_by_invite_access', |
| 465 | 'access arguments' => array($connector, 1, NULL, NULL, RSVP_ACCESS_EDIT), |
| 466 | ); |
| 467 | $items['rsvp/%rsvp/delete'] = array( |
| 468 | 'title' => 'Delete invitation', |
| 469 | 'type' => MENU_CALLBACK, |
| 470 | 'page callback' => 'drupal_get_form', |
| 471 | 'page arguments' => array('rsvp_delete_form', 1), |
| 472 | 'access callback' => 'rsvp_function_invitation_by_invite_access', |
| 473 | 'access arguments' => array($connector, 1, NULL, NULL, RSVP_ACCESS_DELETE), |
| 474 | ); |
| 475 | $items['rsvp/%rsvp/register'] = array( |
| 476 | 'title' => 'Open Signup to invitation', |
| 477 | 'type' => MENU_LOCAL_TASK, |
| 478 | 'page callback' => 'drupal_get_form', |
| 479 | 'page arguments' => array('rsvp_register_form', 1), |
| 480 | 'access callback' => 'rsvp_register_form_access', |
| 481 | 'access arguments' => array($connector, 1), |
| 482 | 'description' => 'Allows to signup for open invitation', |
| 483 | ); |
| 484 | |
| 485 | //javascript calls |
| 486 | $items['rsvp/js/stylesheet'] = array( |
| 487 | 'page callback' => 'rsvp_stylesheet_options_update', |
| 488 | 'access callback' => 'rsvp_function_invitation_by_invite_access', |
| 489 | 'access arguments' => array($connector, 1, NULL, NULL, RSVP_ACCESS_EDIT), |
| 490 | 'type' => MENU_CALLBACK, |
| 491 | 'file' => 'rsvp.form.inc', |
| 492 | ); |
| 493 | |
| 494 | |
| 495 | return $items; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Provides the links that should be displayed when viewing rsvp. |
| 500 | * |
| 501 | * @ingroup rsvp_forms |
| 502 | * |
| 503 | * @param $type the type of link (for example, 'node', 'page', or 'system') being requested |
| 504 | * @param $node the node that is requesting the link. This is used in conjunction with $type to further determine |
| 505 | * what sort of link to display. |
| 506 | * @return an array of links, or an empty array if no links apply for the criteria passed to this method. |
| 507 | */ |
| 508 | function rsvp_link($type, $node = NULL, $teaser = FALSE) { |
| 509 | $links = array(); |
| 510 | |
| 511 | if ($type == 'node') { |
| 512 | |
| 513 | $connector = new RsvpConnector(); |
| 514 | |
| 515 | if ($connector->is_event_enabled($node->type) == true) { |
| 516 | global $user; |
| 517 | |
| 518 | $print_startdate = false; |
| 519 | |
| 520 | // node links |
| 521 | $field = rsvp_function_getFieldforContentType($node->type); |
| 522 | |
| 523 | //first collect all invitations that the user received for the node |
| 524 | $num_invites = db_result(rsvp_function_load_invitations_node2($node->nid, $user->uid, true)); |
| 525 | if ($num_invites > 0) { |
| 526 | if ($num_invites > 1) { |
| 527 | $print_startdate = true; |
| 528 | } |
| 529 | |
| 530 | $invitations = rsvp_function_load_invitations_node2($node->nid, $user->uid); |
| 531 | while ($invite_target = db_fetch_object($invitations)) { |
| 532 | $rsvp = rsvp_function_load_rsvp($invite_target->rid); |
| 533 | $text = 'Reply to invitation'; |
| 534 | |
| 535 | if ($print_startdate == true) { |
| 536 | $pos = $connector->get_posByHash($node, $field, $rsvp->startdate ); |
| 537 | if ($pos >= 0) { |
| 538 | $startdate = $connector->get_startdateAsString($node, $field, $pos); |
| 539 | } |
| 540 | else { |
| 541 | $startdate = 'UNKNOWN STARTDATE:' . $rsvp->startdate; |
| 542 | } |
| 543 | $text .= '(' . $startdate . ')'; |
| 544 | } |
| 545 | $links['rsvp_invite_' . $invite_target->hash] = array('title' => t($text), |
| 546 | 'href' => 'rsvp/email/'. $invite_target->hash . '/view', |
| 547 | ); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | //In a second step collect all invitations for the node that a user has view permissions to. |
| 552 | $rsvps = rsvp_function_load_invitations_owner($node->nid, NULL, NULL); |
| 553 | while ($rsvp = db_fetch_object($rsvps)) { |
| 554 | list($perm_view, $perm_reply, $perm_moderator) = rsvp_function_invitation_by_invite_accessarray($connector, $rsvp, NULL, NULL, array(RSVP_ACCESS_VIEW, RSVP_ACCESS_REPLY, RSVP_ACCESS_EDIT), NULL); |
| 555 | |
| 556 | if ($perm_view == true) { |
| 557 | |
| 558 | $text = 'View invitation'; |
| 559 | |
| 560 | //never print startdate for the invitations you have view permissions. Assume we have only one. |
| 561 | if (false) { |
| 562 | $pos = $connector->get_posByHash($node, $field, $rsvp->startdate /*derived by query*/); |
| 563 | if ($pos >= 0) { |
| 564 | $startdate = $connector->get_startdateAsString($node, $field, $pos); |
| 565 | } |
| 566 | else { |
| 567 | $startdate = 'UNKNOWN STARTDATE:' . $rsvp->startdate; |
| 568 | } |
| 569 | |
| 570 | $text .= '(' . $startdate . ')'; |
| 571 | } |
| 572 | |
| 573 | if ($perm_reply == false) { |
| 574 | //access because of view by role permission.(perm_view = true and perm_reply = false) |
| 575 | $links['rsvp_rsvp_' . $rsvp->rid] = array('title' => t($text), 'href' => 'rsvp/'. $rsvp->rid . '/view'); |
| 576 | if (rsvp_register_form_access($connector, $rsvp) == true) { |
| 577 | $links['rsvp_rsvpregister_' . $rsvp->rid] = array('title' => t('Signup to invitation'), 'href' => 'rsvp/'. $rsvp->rid . '/register'); |
| 578 | } |
| 579 | } |
| 580 | else { |
| 581 | //if we are a moderator, display link as well. |
| 582 | if ($perm_moderator == true) |
| 583 | $links['rsvp_rsvp_' . $rsvp->rid] = array('title' => t($text), 'href' => 'rsvp/'. $rsvp->rid . '/view'); |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | return $links; |
| 590 | } |
| 591 | |
| 592 | |
| 593 | /** |
| 594 | * Act on nodes defined by other modules. |
| 595 | * |
| 596 | * @ingroup rsvp_forms |
| 597 | * @param $node The requested node. |
| 598 | * @param $op The requested operation. |
| 599 | * @return dbresultset of the requested rsvp. |
| 600 | */ |
| 601 | function rsvp_nodeapi(&$node, $op, $teaser, $page) { |
| 602 | |
| 603 | |
| 604 | $connector = new RsvpConnector(); |
| 605 | |
| 606 | if ($op == 'view') { |
| 607 | |
| 608 | if (!$teaser && $page) { |
| 609 | //do not show guestlist for anonymous users |
| 610 | if (user_is_anonymous()) |
| 611 | return; |
| 612 | |
| 613 | global $user; |
| 614 | |
| 615 | $content = ''; |
| 616 | $display = false; |
| 617 | //In a first step collect all invitations for the node that a user has view permissions to. |
| 618 | $invitations = rsvp_function_load_invitations_user($user->uid, $node->nid); |
| 619 | while ($invite_target = db_fetch_object($invitations)) { |
| 620 | $rsvp = rsvp_function_load_rsvp($invite_target->rid); |
| 621 | |
| 622 | if ($rsvp->response_blind_node == RSVP_RESPONSE_SHOW) { |
| 623 | |
| 624 | $params = array(); |
| 625 | list($perm_view, $perm_guestonly) = rsvp_function_invitation_by_invite_accessarray($connector, $rsvp, $invite_target, NULL, array(RSVP_ACCESS_VIEW, RSVP_ACCESS_GUESTONLY), NULL); |
| 626 | if (($perm_guestonly == true) || ($perm_view == true)) { |
| 627 | if ($perm_guestonly == true) { |
| 628 | $params['replybox'] = drupal_get_form('rsvp_reply_form', $rsvp, $invite_target); |
| 629 | $display = true; |
| 630 | } |
| 631 | if ($perm_view == true) { |
| 632 | $params['guestlist'] = rsvp_show_guestlist($rsvp, NULL); |
| 633 | $display = true; |
| 634 | } |
| 635 | $content .= theme('rsvp_invitation_page', $connector, $rsvp, $invite_target, $params); |
| 636 | |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | if ($display == true) { |
| 642 | $node->content['rsvp_guestlist'] = array( |
| 643 | '#type' => 'item', |
| 644 | '#value' => $content, |
| 645 | '#weight' => 50, |
| 646 | ); |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | elseif ($op == 'delete') { |
| 651 | // delete all Invitations associated with a node when the node is deleted |
| 652 | rsvp_api_remove_invitation(NULL, $node->nid); |
| 653 | } |
| 654 | else if ($op == 'presave') { |
| 655 | //load old version of node, and check if startdate has changed. If that is the case update invitation as well. |
| 656 | //$old_node = node_load($node->nid); |
| 657 | } |
| 658 | |
| 659 | } |
| 660 | //- automatic update of invitations startdate when startdate in node changes. |
| 661 | //- automatic remove guests uid from invitations if user is being removed. |
| 662 | |
| 663 | /** |
| 664 | * Implementation of hook_user(). |
| 665 | * |
| 666 | * Checks whether an email address is subscribed to the newsletter when a new |
| 667 | * user signs up. If so, changes uid from 0 to the new uid in |
| 668 | * simplenews_subscriptions so that the user's subscription status is known when |
| 669 | * he logs in. |
| 670 | */ |
| 671 | function rsvp_user($op, &$edit, &$account, $category = NULL) { |
| 672 | switch ($op) { |
| 673 | case 'insert': |
| 674 | //Processing assuring that new users get their invitations associated with their account. |
| 675 | db_query("UPDATE {rsvp_invite} SET uid = %d WHERE uid = 0 AND email = '%s'", $edit['uid'], $edit['mail']); |
| 676 | break; |
| 677 | case 'delete': |
| 678 | // Only remove uid from invitation data when account is removed |
| 679 | db_query("UPDATE {rsvp_invite} SET uid = 0 WHERE uid = %d", $account->uid); |
| 680 | break; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | /** |
| 688 | * hook_load |
| 689 | * Retrieves an rsvp from the database. |
| 690 | * |
| 691 | * @ingroup rsvp_forms |
| 692 | * |
| 693 | * @param $rid The rid of the rsvp instance. |
| 694 | * @return The rsvp instance or false. |
| 695 | */ |
| 696 | function rsvp_load($rid) { |
| 697 | return rsvp_function_load_rsvp($rid); |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * hook_load |
| 702 | * Retrieves an invitation from the database based on a hash. |
| 703 | * |
| 704 | * @ingroup rsvp_forms |
| 705 | * @param $hash_target The hash of a invite instance we want to load. |
| 706 | * @return The invite instance or false. |
| 707 | */ |
| 708 | function rsvp_hash_load($hash_target) { |
| 709 | |
| 710 | $invite_target = rsvp_function_load_invitation_hash($hash_target); |
| 711 | return $invite_target; |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * Shows the list of created invitations for a particular user/node. |
| 716 | * This form is being called only for moderator purposes. |
| 717 | * |
| 718 | * @ingroup rsvp_forms |
| 719 | * |
| 720 | * @param $node The node object you want to manage the rsvp instances for, or NULL for all nodes. |
| 721 | * @param $usr The user. If NULL show invitations for the logged in user. |
| 722 | * @return themed rsvp manage response. |
| 723 | * |
| 724 | * This form is being called from three places: |
| 725 | * - Through "rsvp_overview_form" (user/%uid/rsvp): The current user wants to displays all Invitations of a particular user that he is entitled to |
| 726 | * params: NULL, $user |
| 727 | * |
| 728 | * - Through "rsvp_overview_form" (node/%node/rsvp): A User selects a node and then clicks the "Invitation" tab if visible |
| 729 | * params: $node, NULL |
| 730 | * |
| 731 | * - The RSVP management page (admin/content/rsvp): A maintainer displays all generated invitations |
| 732 | * params: NULL, NULL |
| 733 | * |
| 734 | */ |
| 735 | function rsvp_overview_created_form(&$form_state, $node = NULL, $usr = NULL) { |
| 736 | |
| 737 | $allNodes = (is_null($node)); |
| 738 | $allUsers = (is_null($usr) && ($allNodes == true)); |
| 739 | |
| 740 | if ($allUsers == true) { |
| 741 | rsvp_function_session_parent('admin/content/rsvp'); |
| 742 | } |
| 743 | else if ($allNodes == true) { |
| 744 | rsvp_function_session_parent('user/'. $usr->uid .'/rsvp'); |
| 745 | } |
| 746 | else { |
| 747 | rsvp_function_session_parent('node/'. $node->nid .'/rsvp'); |
| 748 | } |
| 749 | |
| 750 | $form = array(); |
| 751 | |
| 752 | |
| 753 | $allExpired = true; //are all dates for a node are expired? |
| 754 | |
| 755 | |
| 756 | $connector = new RsvpConnector(); |
| 757 | |
| 758 | //create header |
| 759 | $header = array(); |
| 760 | |
| 761 | if ($allNodes == true) { |
| 762 | $header[] = array('data' => t('Event'), 'field' => 'title'); |
| 763 | } |
| 764 | $header[] = array('data' => t('Title'), 'field' => 'name', 'sort' => 'asc', 'width' => '20%'); |
| 765 | $header[] = t('Owner'); |
| 766 | |
| 767 | $header[] = t('Startdate'); |
| 768 | $header[] = t('Inv.'); |
| 769 | $header[] = t('Yes'); |
| 770 | $header[] = t('No'); |
| 771 | $header[] = t('Maybe'); |
| 772 | $header[] = t('No resp.'); |
| 773 | $header[] = array('data' => t('Operations'), 'colspan' => 4); |
| 774 | |
| 775 | |
| 776 | //check if there is at least one date that has not been expired. |
| 777 | if (!$allNodes) { |
| 778 | $allExpired = rsvp_function_is_expired($node); |
| 779 | |
| 780 | if (variable_get('rsvp_for_expired_event', RSVP_OPTION_NO) == RSVP_OPTION_YES) |
| 781 | $allExpired = false; |
| 782 | } |
| 783 | |
| 784 | //fill array with invitations |
| 785 | $rows = array(); |
| 786 | |
| 787 | //load rsvp always for all users. We later have to check if we have edit/view or no rights. |
| 788 | $rsvps = rsvp_function_load_invitations_owner(($allNodes == true) ? NULL : $node->nid, NULL, tablesort_sql($header)); |
| 789 | |
| 790 | while ($rsvp = db_fetch_object($rsvps)) { |
| 791 | $field = NULL; |
| 792 | if ($allNodes) { |
| 793 | $node = rsvp_function_load_node($rsvp); |
| 794 | } |
| 795 | $_owner = user_load($rsvp->uid); |
| 796 | if ($rsvp->uid_moderator != 0) { |
| 797 | $_co_owner = user_load($rsvp->uid_moderator); |
| 798 | $co_owner_link = ' / ' . l($_co_owner->name, 'user/'. $_co_owner->uid, array('attributes' => array('title' => 'View moderator'))); |
| 799 | } |
| 800 | else { |
| 801 | $co_owner_link = ''; |
| 802 | } |
| 803 | |
| 804 | $perm_edit = rsvp_function_invitation_by_invite_access($connector, $rsvp, NULL, NULL, RSVP_ACCESS_EDIT, NULL); |
| 805 | |
| 806 | if ($perm_edit == true) { |
| 807 | $field = rsvp_function_getFieldforContentType($node->type); |
| 808 | |
| 809 | $row = array(); |
| 810 | ($allNodes == true) ? $row[] = l($node->title, 'node/'. $rsvp->nid, array('attributes' => array('title' => 'View node'))) : ''; |
| 811 | $row[] = l($rsvp->name, 'rsvp/'. $rsvp->rid .'/view', array('attributes' => array('title' => 'View invitation'))); |
| 812 | |
| 813 | $row[] = l($_owner->name, 'user/'. $rsvp->uid, array('attributes' => array('title' => 'View owner'))) . $co_owner_link; |
| 814 | |
| 815 | $pos = $connector->get_posByHash($node, $field, $rsvp->startdate); |
| 816 | if ($pos >= 0) |
| 817 | $row[] = $connector->get_startdateAsString($node, $field, $pos); |
| 818 | else |
| 819 | $row[] = 'UNKNOWN STARTDATE:' . $rsvp->startdate; |
| 820 | |
| 821 | // add statistics |
| 822 | $row[] = (int) db_result(rsvp_function_load_guests($rsvp->rid, RSVP_ATT_ALL, TRUE)); |
| 823 | $row[] = (int) db_result(rsvp_function_load_guests($rsvp->rid, RSVP_ATT_YES, TRUE)); |
| 824 | $row[] = (int) db_result(rsvp_function_load_guests($rsvp->rid, RSVP_ATT_NO, TRUE)); |
| 825 | $row[] = (int) db_result(rsvp_function_load_guests($rsvp->rid, RSVP_ATT_MAYBE, TRUE)); |
| 826 | $row[] = (int) db_result(rsvp_function_load_guests($rsvp->rid, RSVP_ATT_NONE, TRUE)); |
| 827 | $row[] = l(t('View'), 'rsvp/'. $rsvp->rid .'/view', array('attributes' => array('title' => 'View invitation'))); |
| 828 | $row[] = l(t('Edit'), 'rsvp/'. $rsvp->rid .'/edit', array('attributes' => array('title' => 'Edit invitation'))); |
| 829 | $row[] = l(t('Manage guests'), 'rsvp/'. $rsvp->rid .'/attendees', array('attributes' => array('title' => 'Invite more people to attend your event'))); |
| 830 | $row[] = l(t('Send message'), 'rsvp/'. $rsvp->rid .'/message', array('attributes' => array('title' => 'Send people you invited a message'))); |
| 831 | $rows[] = $row; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | if ($pager = theme('pager', NULL, 10, 0)) { |
| 836 | $rows[] = array(array('data' => $pager, 'colspan' => count($header))); |
| 837 | } |
| 838 | |
| 839 | //after collecting the input data, |
| 840 | //now start creating meaningful output depending on the situation in the right order. |
| 841 | |
| 842 | //display breadcrumbs, title and header line |
| 843 | $header_text = NULL; |
| 844 | $notfound_text = NULL; |
| 845 | if ($allUsers == true) { |
| 846 | $header_text = 'All invitations by all users'; |
| 847 | $notfound_text = 'No invitations available.'; |
| 848 | } |
| 849 | else if ($allNodes == true) { |
| 850 | $header_text = 'Your invitations that you created for all events'; |
| 851 | $notfound_text = 'You have not created any active invitations.'; |
| 852 | drupal_set_title(check_plain($usr->name)); |
| 853 | drupal_set_breadcrumb(array(l(t('Home'), NULL), l('My account', 'user/'. $usr->uid))); |
| 854 | } |
| 855 | else { |
| 856 | $header_text = 'Invitations that you have created for this event'; |
| 857 | $notfound_text = 'You have not created any invitations for this event.'; |
| 858 | drupal_set_title(check_plain($node->title)); |
| 859 | drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/'. $node->nid))); |
| 860 | } |
| 861 | |
| 862 | $form['rsvp_overview_created_form'] = array( |
| 863 | '#type' => 'fieldset', |
| 864 | '#title' => ' ', //avoids Iexplorer display problem of empty box(frame) |
| 865 | ); |
| 866 | |
| 867 | $form['rsvp_overview_created_form']['title'] = array('#value' => '<br /><div><h3>' . t($header_text) . '</h3><br /></div>'); |
| 868 | //TODO output needs to be improoved in version 2.0. |
| 869 | //Avoid displaying box if $rows is 0 and user is not allowed to create invitation. |
| 870 | |
| 871 | //display the invitations or an appropriate message. |
| 872 | if (!$rows) { |
| 873 | $form['rsvp_overview_created_form']['not_found'] = array('#value' => '<p>'. t($notfound_text) .'</p>'); |
| 874 | } |
| 875 | else { |
| 876 | $table = theme('table', $header, $rows); |
| 877 | $form['rsvp_overview_created_form']['table'] = array('#value' => $table); |
| 878 | } |
| 879 | |
| 880 | //display if the user is allowed to create an rsvp for an event. |
| 881 | $content = NULL; |
| 882 | if ($allNodes == false) { |
| 883 | if ($allExpired == true) { |
| 884 | $content = t('This event has expired. Invitations can only be created for events <br />that have not expired yet.'); |
| 885 | } |
| 886 | else { |
| 887 | if (_rsvp_rsvp_by_node_access($connector, $node, RSVP_ACCESS_CREATE)) |
| 888 | $content = l(t('Create invitation'), 'node/'. $node->nid .'/rsvp/create'); |
| 889 | } |
| 890 | |
| 891 | } |
| 892 | else { |
| 893 | $content = t('(To create an invitation, select and view an !event, then select tab "Invitation" and click on "Create invitation").', |
| 894 | array('!event'=> l(t('event'), 'tracker')) |
| 895 | ); |
| 896 | |
| 897 | } |
| 898 | $form['rsvp_overview_created_form']['content_message'] = array('#value' => '<p>'. $content .'</p>'); |
| 899 | |
| 900 | return $form; |
| 901 | } |
| 902 | |
| 903 | /* |
| 904 | * Access function to determine if the current user is allowed to see rsvp_overview_created_form |
| 905 | * |
| 906 | * |
| 907 | * @ingroup rsvp_forms |
| 908 | * |
| 909 | * @param $usr The user object that the current user wants to check for or NULL. |
| 910 | * @param $node The node object you want to check for or NULL. |
| 911 | * @return true or false. |
| 912 | * |
| 913 | * could be the user, admin or moderator. Verify that the current user is one of those persons. |
| 914 | * |
| 915 | * Used for menus |
| 916 | * - Through rsvp_overview_form (user/%uid/rsvp): Current user displays %uid's invitations (can be the same or not, e.g. moderator!) |
| 917 | * params: NULL, $user |
| 918 | * |
| 919 | * - Through rsvp_overview_form (node/%node/rsvp): Current user selects a node and then clicks the "Invitation" tab if visible |
| 920 | * params: $node, NULL |
| 921 | * |
| 922 | * - The RSVP management page (admin/content/rsvp): Current user displays all generated invitations (must be maintainer) |
| 923 | * params: NULL, NULL |
| 924 | * |
| 925 | */ |
| 926 | function rsvp_overview_created_form_access($connector, $node, $usr) { |
| 927 | |
| 928 | //don't show the frame for anonymous users. |
| 929 | if (user_is_anonymous()) |
| 930 | return false; |
| 931 | |
| 932 | $display = false; |
| 933 | if (!is_null($usr) && is_null($node)) { |
| 934 | //verify that current user is usr. |
| 935 | $perm_view = _rsvp_user_access($connector, $usr, RSVP_ACCESS_VIEW, NULL); |
| 936 | if ($perm_view == true) |
| 937 | $display = true; |
| 938 | } |
| 939 | else if (is_null($usr) && !is_null($node)) { |
| 940 | if (!$connector->is_event_enabled($node->type)) |
| 941 | return false; |
| 942 | |
| 943 | //checking for RSVP_ACCESS_VIEW takes too long. So assume we can see it, and then print a message if no RSVPs are available |
| 944 | //if (/*(_rsvp_rsvp_by_node_access($connector, $node, RSVP_ACCESS_VIEW) == true)*/true || |
| 945 | //TODO missing parameter |
| 946 | //(_rsvp_rsvp_by_node_access($connector, $node, RSVP_ACCESS_CREATE) == true)) |
| 947 | //check internally inside the form |
| 948 | $display = true; |
| 949 | } |
| 950 | else if (is_null($usr) && is_null($node)) { |
| 951 | $display = user_access(RSVP_PERM_MAINTAIN); |
| 952 | } |
| 953 | |
| 954 | return $display; |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * Shows the invitations that a user has been invited to. |
| 959 | * |
| 960 | * @ingroup rsvp_form |
| 961 | * |
| 962 | * @param $node A node. Shows invitations to the current user for a particular node or NULL. If NULL, show for all nodes. |
| 963 | * @param $usr A user. Shows invitations to the current user for a particular user or NULL. If NULL show invitations for the logged in user. |
| 964 | |
| 965 | * @return themed response. |
| 966 | * |
| 967 | * This form is being called from three places: |
| 968 | * - Through "rsvp_overview_form" (user/%uid/rsvp): The current user wants to displays all Invitations of a particular user that he is entitled to |
| 969 | * params: NULL, $user |
| 970 | * |
| 971 | * - Through "rsvp_overview_form" (node/%node/rsvp): A User selects a node and then clicks the "Invitation" tab if visible |
| 972 | * params: $node, NULL |
| 973 | */ |
| 974 | function rsvp_overview_invited_form(&$form_state, $node, $usr) { |
| 975 | |
| 976 | $form = array(); |
| 977 | |
| 978 | $connector = new RsvpConnector(); |
| 979 | |
| 980 | $displays_for_user = NULL; |
| 981 | $_user = NULL; |
| 982 | $_node = NULL; |
| 983 | |
| 984 | if (is_null($usr)) { |
| 985 | //implies that $node must be valid. |
| 986 | $displays_for_user = false; |
| 987 | global $user; |
| 988 | |
| 989 | //anonymous user is not allowed to see this form. |
| 990 | if (user_is_anonymous()) |
| 991 | return $form; |
| 992 | |
| 993 | $_user = $user; |
| 994 | $_node = $node; |
| 995 | } |
| 996 | else { |
| 997 | $displays_for_user = true; |
| 998 | $_user = $usr; |
| 999 | $_node = NULL; |
| 1000 | |
| 1001 | } |
| 1002 | |
| 1003 | $title = ''; |
| 1004 | $display = false; |
| 1005 | |
| 1006 | //when we list invitations only for a particular node, $node is set. Otherwise $node is NULL. |
| 1007 | $invitations = rsvp_function_load_invitations_user($_user->uid, $_node->nid); |
| 1008 | |
| 1009 | $nid2inviteslist = array(); |
| 1010 | while ($invite_target = db_fetch_object($invitations)) { |
| 1011 | $nid2inviteslist[$invite_target->nid][] = $invite_target; |
| 1012 | } |
| 1013 | |
| 1014 | foreach ($nid2inviteslist as $nid => $inviteslist) { |
| 1015 | $links = array(); |
| 1016 | if ($displays_for_user == true) { |
| 1017 | $_node = rsvp_function_load_node($nid); |
| 1018 | } |
| 1019 | |
| 1020 | foreach ($inviteslist as $invite_target) { |
| 1021 | //In order to see this invitation, the current user should be either moderator or the user. |
| 1022 | $perm_reply = rsvp_function_invitation_by_invite_access($connector, NULL, $invite_target, $_user->uid, RSVP_ACCESS_REPLY, NULL); |
| 1023 | if ($perm_reply == true) { |
| 1024 | |
| 1025 | if ($_node) { |
| 1026 | $field = rsvp_function_getFieldforContentType($_node->type); |
| 1027 | $rsvp = rsvp_function_load_rsvp($invite_target->rid); |
| 1028 | $pos = $connector->get_posByHash($_node, $field, $rsvp->startdate); |
| 1029 | if ($pos >= 0) { |
| 1030 | $startdate = $connector->get_startdateAsString($_node, $field, $pos); |
| 1031 | } |
| 1032 | else { |
| 1033 | $startdate = 'UNKNOWN STARTDATE:' . $rsvp->startdate; |
| 1034 | } |
| 1035 | $links[] = l($rsvp->name . ' (' . $startdate . ')', "rsvp/email/". $invite_target->hash . "/view", array('attributes' => array('title' => t('View invitation')))); |
| 1036 | $display = true; |
| 1037 | } |
| 1038 | else { |
| 1039 | // node has been deleted |
| 1040 | $links[] = l($invite_target->name, "rsvp/email/". $invite_target->hash. "/view", array('attributes' => array('title' => t('View invitation')))); |
| 1041 | $display = true; |
| 1042 | } |
| 1043 | |
| 1044 | } |
| 1045 | } |
| 1046 | if ($_node) { |
| 1047 | if ($displays_for_user == true) { |
| 1048 | $title = t('For event: ') . l($_node->title, 'node/'. $_node->nid, array('attributes' => array('title' => t('View this node/event')))); |
| 1049 | } |
| 1050 | else { |
| 1051 | $title = NULL; |
| 1052 | } |
| 1053 | } |
| 1054 | else { |
| 1055 | $title = t('Deleted events:'); |
| 1056 | } |
| 1057 | |
| 1058 | $itemlist .= theme('item_list', $links, $title); |
| 1059 | } |
| 1060 | |
| 1061 | //after collecting the data, print all information in the right order to the screen. |
| 1062 | //setting breadcrumbs and title is not neccessary because form is always embedded and the outer form has to set the breadcrumbs |
| 1063 | if ($displays_for_user == true) { |
| 1064 | $header_text = 'Invitations that you have been invited to'; |
| 1065 | } |
| 1066 | else { |
| 1067 | $header_text = 'Invitations for this event that you have been invited to'; |
| 1068 | } |
| 1069 | |
| 1070 | //display invitation box only if we have to display invitations. |
| 1071 | if ($display == true) { |
| 1072 | |
| 1073 | $form['rsvp_overview_invited_form'] = array( |
| 1074 | '#type' => 'fieldset', |
| 1075 | '#title' => ' ', //avoids Iexplorer display problem of empty box(frame) |
| 1076 | ); |
| 1077 | |
| 1078 | $form['rsvp_overview_invited_form']['title'] = array('#value' => '<br /><div><h3>' . t($header_text) . '</h3><br /><br /></div>'); |
| 1079 | |
| 1080 | $form['rsvp_overview_invited_form']['item_lists'] = array('#value' => $itemlist); |
| 1081 | |
| 1082 | /* |
| 1083 | if (count($nid2inviteslist) == 0) { |
| 1084 | if ($displays_for_user == true) { |
| 1085 | $output = '<p>'. t('You have not been invited to any events yet.') .'</p>'; |
| 1086 | } |
| 1087 | else { |
| 1088 | $output = '<p>'. t('You have not been invited to this event.') .'</p>'; |
| 1089 | } |
| 1090 | |
| 1091 | $form['rsvp_overview_form']['content'] = array( '#value' => $output ); |
| 1092 | } |
| 1093 | */ |
| 1094 | } |
| 1095 | |
| 1096 | return $form; |
| 1097 | } |
| 1098 | |
| 1099 | /** |
| 1100 | * Shows the invitations that a user has view access to by role (set by setting "Invitation message - view permissions"). |
| 1101 | * |
| 1102 | * @ingroup rsvp_form |
| 1103 | * |
| 1104 | * @param $node A node. Shows invitations to the current user for a particular node or NULL. If NULL, show for all nodes. |
| 1105 | * @param $usr A user. Shows invitations to the current user for a particular user or NULL. If NULL show invitations for the logged in user. |