nid != $invite->nid) { drupal_set_message(t("This URL is invalid (iid/nid mismatch)"), 'error'); return; } node_invite_specific_info($invite, $node); if ($inline) { $form['rsvp'] = array( '#type' => 'fieldset', '#title' => t('RSVP to this @type', array('@type' => $node->type)), '#description' => '', '#collapsed' => FALSE, '#collapsible' => TRUE, ); } $form['rsvp']['intro'] = array( '#value' => token_replace( variable_get('node_invite_rsvp_page_intro', NODE_INVITE_RSVP_PAGE_INTRO), 'node', $node ), '#weight' => 0, ); if (variable_get('node_invite_rsvp_email', 0)) { $form['rsvp']['email'] = array( '#type' => 'textfield', '#title' => t('Your Email'), '#description' => t('Please enter the email address to which the original invite was sent. This allows us to make sure you are the actual recipient of the invite.'), '#required' => TRUE, '#weight' => 1, ); } $form['rsvp']['attend'] = array( '#weight' => 2, ); $form['rsvp']['attend']['pretext'] = array( '#value' => token_replace( variable_get('node_invite_rsvp_page_submit_pretext', NODE_INVITE_RSVP_PAGE_SUBMIT_PRETEXT), 'node', $node ), '#prefix' => '
', '#suffix' => '
', '#weight' => 19, ); } elseif ($invite->email_invitee) { $name = $invite->email_invitee; if ($invite->name_invitee) { $name = $invite->name_invitee . " ($name)"; } $form['rsvp']['current_user'] = array( '#value' => t('You are RSVPing as !current_user. If this is not you, please click here.', array('!current_user' => $name, '!logout' => url('node_invite/clear_rsvp_session/' . $node->nid))), '#prefix' => '', '#suffix' => '
', '#weight' => 19, ); } $form['rsvp']['submit'] = array( '#type' => 'submit', '#value' => t('Reply'), '#weight' => 20, ); // hidden vars for tracking $form['node'] = array( '#type' => 'value', '#value' => $node, ); $form['invite'] = array( '#type' => 'value', '#value' => $invite, ); $form['#redirect'] = 'node/' . $node->nid; return $form; } function node_invite_rsvp_validate($form, &$form_state) { if (intval(variable_get('node_invite_rsvp_email', '0'))) { $email = $form_state['values']['email']; if (!valid_email_address($email)) { // email is not valid.... regardless of whether or not it matches. // send them back. form_set_error('email', t("$email is not a valid email. Please try again.")); } else { $invite = $form_state['values']['invite']; if ($email != $invite->email_invitee) { form_set_error('email', t("$email is not the address to which this invite was sent. Please use the exact email to which this invite was sent.")); } } } } function node_invite_rsvp_submit($form, &$form_state) { $invite = $form_state['values']['invite']; // Need to double check the status to be translation safe. $status = $form_state['values']['status']; node_invite_save($invite, array('status' => $status, 'notes_invitee' => $form_state['values']['comments'])); $node = $form_state['values']['node']; $admin_notify_setting = variable_get('node_invite_nots_admin', 'site_admin_all'); if ($admin_notify_setting == 'site_admin_all') { /* $from = $to = $GLOBALS['conf']['site_mail']; $subject = token_replace( variable_get('node_invite_notify_site_admin_all_subject',NODE_INVITE_NOTIFY_SITE_ADMIN_ALL_SUBJECT), 'node', $node ); $the_message = token_replace( variable_get('node_invite_notify_site_admin_all',NODE_INVITE_NOTIFY_SITE_ADMIN_ALL), 'node', $node ); $msg = drupal_mail( // module 'node_invite', // key 'rsvp_site_admin_all', // to $to, // language language_default(), // params array( 'subject' => $subject, 'body' => $the_message, ), // from $from, // send TRUE ); */ } elseif ($admin_notify_setting == 'site_admin_yes' && $form_state['values']['op'] == t(NODE_INVITE_RESPONSE_YES)) { /* $the_message = token_replace( variable_get('node_invite_notify_site_admin_yes',NODE_INVITE_NOTIFY_SITE_ADMIN_YES), 'node', $node ); $subject = token_replace( variable_get('node_invite_notify_site_admin_yes_subject',NODE_INVITE_NOTIFY_SITE_ADMIN_YES_SUBJECT), 'node', $node ); $from = $to = $GLOBALS['conf']['site_mail']; $msg = drupal_mail( // module 'node_invite', // key 'rsvp_site_admin_yes', // to $to, // language language_default(), // params array( 'subject' => $subject, 'body' => $the_message, ), // from $from, // send TRUE ); */ } // notify the inviter $notify_settings = variable_get('node_invite_nots_rsvps', array('inviter', 'invitee')); if (in_array('inviter', $notify_settings)) { $the_message = token_replace( variable_get('node_invite_notify_inviter_notify', NODE_INVITE_NOTIFY_INVITER_NOTIFY), 'node', $node ); $from = $GLOBALS['conf']['site_mail']; $to = db_result(db_query("SELECT u.mail FROM {users} u JOIN {node_invites} ni ON u.uid = ni.uid_inviter WHERE iid = %d", $invite->iid)); $subject = token_replace( variable_get('node_invite_notify_inviter_notify_subject', NODE_INVITE_NOTIFY_INVITER_NOTIFY_SUBJECT), 'node', $node ); $msg = drupal_mail( // module 'node_invite', // key 'rsvp_inviter', // to $to, // language language_default(), // params array( 'subject' => $subject, 'body' => $the_message, ), // from $from, // send TRUE ); } // To allow for redirection unset($form_state['storage']); } function node_invite_rsvp_new($form_state, $node, $inline = FALSE) { global $user; $form = array(); $invite = new stdClass(); $invite->iid = 0; $invite->nid = $node->nid; $invite->uid_invitee = $user->uid; $invite->email_invitee = $user->mail; $invite->status = NODE_INVITE_NEW; $invite->notes_invitee = ''; $default_rsvp_form = node_invite_rsvp($form_state, $node, $invite); if ($inline) { $form['rsvp'] = array( '#type' => 'fieldset', '#title' => t('RSVP to this @type', array('@type' => $node->type)), '#description' => '', '#collapsed' => TRUE, '#collapsible' => TRUE, ); } if ($user->uid) { $form['rsvp']['email'] = array( '#type' => 'value', '#value' => $user->mail, ); $form['rsvp']['name'] = array( '#type' => 'value', '#value' => $user->name, ); } else { $form['rsvp']['email'] = array( '#type' => 'textfield', '#title' => t('Your Email'), '#default_value' => '', '#required' => TRUE, ); $form['rsvp']['name'] = array( '#type' => 'textfield', '#title' => t('Your Name'), '#default_value' => '', ); } $form['rsvp']['attend'] = $default_rsvp_form['rsvp']['attend']; $form['rsvp']['comments'] = $default_rsvp_form['rsvp']['comments']; $form['rsvp']['submit'] = $default_rsvp_form['rsvp']['submit']; $form['node'] = $default_rsvp_form['node']; $form['#validate'][] = 'node_invite_rsvp_validate'; $form['#validate'][] = 'node_invite_rsvp_new_validate'; $form['#redirect'] = 'node/' . $node->nid; return $form; } function node_invite_rsvp_new_validate($form, &$form_state) { // Does the email address match an existing anonymous invitation? $node = $form_state['values']['node']; if ($iid = db_result(db_query("SELECT iid FROM {node_invites} WHERE email_invitee = '%s' AND nid = %d", $form_state['values']['email'], $node->nid))) { $invite = node_invite_load($iid); if ($invite->uid_invitee) { form_set_error('email', t('An invitation for a user with that email already exists. Please login to the site to edit your RSVP')); } $form_state['values']['invite'] = $invite; } } function node_invite_rsvp_new_submit($form, &$form_state) { global $user; $node = $form_state['values']['node']; $params = array( 'nid' => $node->nid, 'email_invitee' => $form_state['values']['email'], 'name_invitee' => $form_state['values']['name'], 'uid_invitee' => $user->uid, 'uid_inviter' => $user->uid, 'status' => $form_state['values']['status'], 'notes_invitee' => $form_state['values']['comments'], ); if (isset($form_state['values']['invite'])) { $invite = node_invite_save($form_state['values']['invite'], $params); } else { $invite = node_invite_save(NULL, $params); } // Set a cookie for the user if they're anon so that we can track their // response for this session. if (!$user->uid) { $_SESSION['node_invites'][$node->nid] = $invite->iid; } drupal_set_message(t('Your response has been recorded')); } function node_invite_find_invite($node, $redir = TRUE) { global $user; $invite = FALSE; if (($iid = db_result(db_query("SELECT iid FROM {node_invites} WHERE uid_invitee = %d AND nid = %d", $user->uid, $node->nid))) && $user->uid) { $invite = node_invite_load($iid); } elseif ($_SESSION['node_invites'][$node->nid]) { $invite = node_invite_load($_SESSION['node_invites'][$node->nid]); } if (!$redir) { return $invite; } if ($invite) { drupal_goto(url(node_invite_rsvp_path($invite))); } elseif ($node->node_invite_settings['open']) { drupal_goto(url("node_invite/rsvp_new/$node->nid")); } drupal_access_denied(); } /** * Used by anonymous users to clear their RSVP session data if they need * to RSVP under a different email address */ function node_invite_clear_rsvp_session($node) { unset($_SESSION['node_invites']); drupal_goto('node/' . $node->nid); }