[inviter-name] at [site-name] has invited you to a [type] called [title]!\n
Use this form to confirm (or deny) attendance.
"); define('NODE_INVITE_MESSAGE_DEFAULT', '[inviter-name] invites you to rsvp for a [type]!
Visit [title] for more information or just check out the RSVP Page to confirm your attendance!
'); define('NODE_INVITE_SUBJECT_DEFAULT', "[inviter-name] at [site-name] has invited you to a [type] called [title]!"); define('NODE_INVITE_NOTIFY_SITE_ADMIN_YES_SUBJECT', '[site-name] - Invite ACCEPT notification'); define('NODE_INVITE_NOTIFY_SITE_ADMIN_YES', 'An invite was accepted for node [nid]. Login to the site to view it.'); define('NODE_INVITE_NOTIFY_SITE_ADMIN_ALL_SUBJECT', '[site-name] - Invite response notification'); define('NODE_INVITE_NOTIFY_SITE_ADMIN_ALL', 'An invite was acted upon for node [nid]. Login to the site to view it.'); define('NODE_INVITE_NOTIFY_INVITEE_CONFIRM_SUBJECT', '[site-name] - Invite response confirmation'); define('NODE_INVITE_NOTIFY_INVITEE_CONFIRM', 'Your invite selection for [title] has been processed. Thanks!'); define('NODE_INVITE_NOTIFY_INVITER_NOTIFY_SUBJECT', '[site-name] - Invite response!'); define('NODE_INVITE_NOTIFY_INVITER_NOTIFY', 'Your invite selection for [title] has been acted upon. Please login to the site and click "Invites" to view it. Thanks!'); /* added to enable per-node override with a checkbox */ define('NODE_INVITE_DEFAULT_FOR_ENABLED_NODES', 1); /** * Implementation of hook_help(). */ function node_invite_help( $path, $arg ) { $output = ''; switch ($path) { case 'admin/help/node_invite': $output .= t('Node Invite Provides a means to invite people to nodes. Customized email message is token enabled.
'); $output .= t('Here are tokens you can use:
'); $output .= theme('token_help'); break; case 'admin/settings/node_invite': $output .= 'Node invite allows you to invite people to nodes. The email they receive is token-enabled.
'; break; } return $output; } /** * Implementation of hook_perm(). */ function node_invite_perm() { return array( 'invite users to invite-enabled nodes', 'admin node invite settings', 'respond to invites', 'manage all invites', 'manage own invites', ); } /** * Implementation of hook_menu(). */ function node_invite_menu() { $items = array(); $items['admin/settings/node_invite'] = array( 'title' => t('Node Invite'), 'description' => t('Node Invite module is similar to RSVP. Invite people to nodes, manage your invites, etc.'), 'access arguments' => array('admin node invite settings'), 'page callback' => 'drupal_get_form', 'page arguments' => array('node_invite_admin_settings_form'), 'file' => 'node_invite.admin.inc', ); $items['admin/settings/node_invite/settings'] = array( 'title' => t('Settings'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => 0, ); $items['admin/settings/node_invite/notifications'] = array( 'title' => t('Notifications'), 'type' => MENU_LOCAL_TASK, 'access arguments' => array('admin node invite settings'), 'page callback' => 'drupal_get_form', 'page arguments' => array('node_invite_notifications_form'), 'weight' => 1, 'file' => 'node_invite.admin.inc', ); $items['admin/settings/node_invite/manage'] = array( 'title' => t('Manage Invites'), 'type' => MENU_LOCAL_TASK, 'access arguments' => array('manage all invites'), 'page callback' => 'drupal_get_form', 'page arguments' => array('user_invites_form'), 'weight' => 2, 'file' => 'node_invite.admin.inc', ); $items['node_invite/invite/%'] = array( 'title' => t('Invite'), 'type' => MENU_CALLBACK, 'access arguments' => array('invite users to invite-enabled nodes'), 'page callback' => 'drupal_get_form', 'page arguments' => array('node_invite_send', 2), 'file' => 'node_invite.send.inc', ); $items['node_invite/rsvp/%node/%'] = array( 'title' => t('Invite'), 'type' => MENU_CALLBACK, 'access arguments' => array('respond to invites'), 'page callback' => 'drupal_get_form', 'page arguments' => array('node_invite_rsvp', 2, 3), 'file' => 'node_invite.rsvp.inc', ); $items['node_invite/revoke/%'] = array( 'title' => t('Revoke'), 'type' => MENU_CALLBACK, 'access callback' => 'node_invite_access_revoke', 'page callback' => 'drupal_get_form', 'page arguments' => array('node_invite_revoke', 2), ); $items['node_invite/resend/%'] = array( 'title' => t('Resend'), 'type' => MENU_CALLBACK, 'access callback' => 'node_invite_access_resend', 'page callback' => 'drupal_get_form', 'page arguments' => array('node_invite_resend', 2), ); $items['user/%user/invites'] = array( 'title' => 'My Invites', 'page callback' => 'node_invite_user_invites', 'page arguments' => array(1), 'type' => MENU_LOCAL_TASK, 'access arguments' => array('manage own invites'), 'weight' => 2, ); /* $items['node_invite/resend'] = array( 'title' => t('Invite'), 'type' => MENU_CALLBACK, 'access arguments' => array('invite users to invite-enabled nodes'), 'page callback' => 'drupal_get_form', 'page arguments' => array('node_invite_resend'), ); */ return $items; } /** * Implementation of hook_link(). */ function node_invite_link( $type, $node = NULL, $teaser = FALSE ) { global $user; $links = array(); if ($type == 'node' && _node_invite_type_is_allowed($node->type) && user_access('invite users to invite-enabled nodes') && _ni_node_is_enabled($node->nid)) { $links['node_invite'] = array( 'title' => t('Invite people to this @type', array('@type' => $node->type)), 'href' => "node_invite/invite/$node->nid", ); } return $links; } function _ni_node_is_enabled( $nid ) { $sth = db_query("SELECT invites_enabled FROM {node_invite_settings} WHERE nid = %d", $nid); $enabled = variable_get('node_invite_default', NODE_INVITE_DEFAULT_FOR_ENABLED_NODES); if ($row = db_fetch_array($sth)) { // if there's a row in the table, then they're being explicit... override the default $enabled = $row['invites_enabled']; } return $enabled; } function _node_invite_type_is_allowed( $type ) { if ( in_array( $type, variable_get('node_invite_node_types', array() ), TRUE ) ) { return TRUE; } return FALSE; } /** * Implementation of hook_mail(). */ function node_invite_mail( $key, &$message, $params ) { $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed'; $message['subject'] = $params['subject']; $message['body'] = $params['body']; } /** * Implementation of hook_token_values(). */ function node_invite_token_values($type, $object = NULL) { $values = array(); if (in_array($type, array('all', 'node_invite', 'node'))) { global $user; $values['inviter-name'] = $user->name; $values['inviter-mail'] = $user->mail; $values['inviter-rsvp-url'] = url('node_invite/invite/' . $object->nid, array('absolute' => TRUE)); $values['inviter-node-url'] = url('node/' . $object->nid, array('absolute' => TRUE)); // this is hacked in for each invite sent. Won't exist other times if (isset($object->invite_specific_info)) { $values['node-invite-iid'] = $object->invite_specific_info['node-invite-iid']; $values['node-invite-recip-name'] = $object->invite_specific_info['node-invite-recip-name']; $values['node-invite-recip-mail'] = $object->invite_specific_info['node-invite-recip-mail']; // the above were defaults... this comes in if alternatives are available $values['inviter-name'] = $object->invite_specific_info['inviter-name']; $values['inviter-mail'] = $object->invite_specific_info['inviter-mail']; } //drupal_set_message("Token values =" . print_r( $values, TRUE ) . ""); } return $values; } /** * Implementation of hook_token_list(). */ function node_invite_token_list( $type='all') { /* global $user; drupal_set_message("
" . sprint_r( $user ) . ""); */ $tokens = array(); if (in_array($type, array('all', 'node_invite', 'node'))) { $tokens['node_invite']['inviter-name'] = t('The username of the person currently logged in (and thus sending the invite). This will not work as a page-title token since the person rendering the page title will be logged in as someone different (or anonymous).'); $tokens['node_invite']['inviter-mail'] = t('The email address of the person currently logged in (and thus sending the invite). This will not work as a page-title token since the person rendering the page title will be logged in as someone different (or anonymous).'); $tokens['node_invite']['inviter-rsvp-url'] = t('This is the URL of the RSVP form. Send users here to confirm or deny attendance.'); $tokens['node_invite']['inviter-node-url'] = t('This is the URL of the node to which they are being invited. Send them here "for more details."'); $tokens['node_invite']['node-invite-recip-mail'] = t('The email of the person receiving the invite'); $tokens['node_invite']['node-invite-recip-name'] = t('The name of the person receiving the invite'); $tokens['node_invite']['node-invite-iid'] = t('The invite_id (unique identifier) of the invite being sent'); } return $tokens; } /** * Implementation of hook_content_extra_fields(). */ function node_invite_content_extra_fields($type_name) { $extra = array(); if (_node_invite_type_is_allowed($type_name)) { $extra['node_invite_group'] = array( 'label' => t('Node invite settings'), 'description' => t('Node invite module form.'), 'weight' => 10, ); } return $extra; } function node_invite_user_invites( $account ) { $headers = _node_invite_user_invites_headers(); $q = db_query(" SELECT iid, ni.nid, email_invitee, uid_inviter, ni.status, ni.sent, acted_upon, notes_invitee, notes_inviter, n.title, u.name FROM {node_invites} AS ni JOIN {node} AS n ON ni.nid = n.nid JOIN {users} AS u ON ni.uid_inviter = u.uid WHERE uid_inviter = %d " . tablesort_sql($headers) . " ", $account->uid ); $destination = drupal_get_destination(); $rows = array(); while ( $data = db_fetch_array($q) ) { $row = array(); $row[] = $data['title']; $row[] = check_plain($data['email_invitee']); if ( user_access('manage all invites') ) { $row[] = $data['name']; } $row[] = date('m/d/Y g:i a', $data['sent'] ); $row[] = $data['status']; $row[] = $data['acted_upon'] ? date('m/d/Y g:i a', $row['acted_upon']) : ' '; if ( $row['status'] != 'Yes' && $row['status'] != 'Revoked' && _node_invite_can_manage_this_invite($data['iid']) ) { $row[] = l('Revoke', 'node_invite/revoke/' . $data['iid'], array('query' => $destination)); $row[] = l('Resend', 'node_invite/resend/' . $data['iid'], array('query' => $destination)); } $rows[] = $row; } return theme('table', $headers, $rows); } function _node_invite_user_invites_headers() { $headers = array(); $headers[] = array( 'data' => 'What', 'field' => 'title', ); $headers[] = array( 'data' => 'Sent to', 'field' => 'email_invitee', ); if ( user_access('manage all invites') ) { $headers[] = array( 'data' => 'Sent by', 'field' => 'name', ); } $headers[] = array( 'data' => 'Invite Sent', 'field' => 'sent', ); $headers[] = array( 'data' => 'Status', 'field' => 'status', ); $headers[] = array( 'data' => 'Acted Upon', 'field' => 'acted_upon', ); return $headers; } function _node_invite_can_manage_this_invite( $iid ) { global $user; $sth = db_query( "SELECT uid_inviter FROM {node_invites} WHERE iid = %d", $iid ); if ( $row = db_fetch_array($sth) ) { if ( ( $row['uid_inviter'] == $user->uid ) && user_access('manage own invites')) { return TRUE; } elseif ( user_access('manage all invites') ) { return TRUE; } } return FALSE; } function node_invite_access_revoke() { return TRUE; } function node_invite_access_resend() { return TRUE; } function node_invite_revoke($form_state, $iid) { // ask for confirmation that they really want to revoke the invite. if ( !intval($iid) ) { drupal_set_message("$iid is not a number. This form should only be called with a invite-id as the 3rd argument in the URL.", 'error'); return; } if (_node_invite_can_manage_this_invite($iid)) { $form['iid'] = array( '#type' => 'value', '#value' => $iid, ); $form['referer'] = array( '#type' => 'hidden', '#value' => $_GET['destination'], ); return confirm_form( $form, 'Are you sure you wish to revoke this invite?', $_GET['destination'] ); } else { drupal_set_message('Access denied', 'error'); return; } } function node_invite_revoke_submit( $form, &$form_state ) { db_query("UPDATE {node_invites} SET status = '%s', acted_upon = %d WHERE iid = %d", 'Revoked', time(), $form_state['values']['iid']); drupal_goto($form_state['values']['referer']); } function node_invite_resend($form_state, $iid) { // ask for confirmation that they really want to revoke the invite. if ( !intval($iid) ) { drupal_set_message("$iid is not a number. This form should only be called with a invite-id as the 3rd argument in the URL.", 'error'); return; } if (_node_invite_can_manage_this_invite($iid)) { $form['iid'] = array( '#type' => 'value', '#value' => $iid, ); $form['referer'] = array( '#type' => 'hidden', '#value' => $_GET['destination'], ); return confirm_form($form, 'Are you sure you wish to resend this invite?', $_GET['destination']); } else { drupal_set_message('Access denied', 'error'); return; } } function node_invite_resend_submit($form, &$form_state) { db_query("UPDATE {node_invites} SET status = '%s', acted_upon = NULL WHERE iid = %d", 'NEW', time(), $form_state['values']['iid']); $q = db_query("SELECT ni.*, u.mail FROM {node_invites} AS ni JOIN {users} AS u ON ni.uid_inviter = u.uid WHERE iid = %d", $form_state['values']['iid']); if ($row = db_fetch_array($q)) { $default_message = variable_get('node_invite_message_default', NODE_INVITE_MESSAGE_DEFAULT); $node = node_load($row['nid']); $inviter_rsvp_url = url('node_invite/rsvp/' . $row['nid'] . '/' . $row['iid'], array('absolute' => TRUE)); $new_default_message = str_replace("[inviter-rsvp-url]", $inviter_rsvp_url, $default_message); $replaced_message = token_replace($new_default_message, 'node', $node); $subj = token_replace( variable_get('node_invite_subject_default', NODE_INVITE_SUBJECT_DEFAULT), 'node', $node ); $msg = drupal_mail( // module 'node_invite', // key 'invite', // to $row['email_invitee'], // language language_default(), // params array( 'subject' => $subj, 'body' => $replaced_message, ), // from $row['mail'], // send TRUE ); } else { drupal_set_message('Unable to fetch information about this invite. Resend failed.', 'error'); } drupal_goto($form_state['values']['referer']); } function user_invites_form() { global $user; $uid_inviter = $user->uid; drupal_add_css(drupal_get_path('module', 'node_invite') . '/node_invite.css', 'module', 'all', TRUE); // 1. Who is this? (we're showing their stuff only, right?) // 2. Get their invites (where uid_inviter == $user->uid // 3. Make a table of results // 4. Provide ajax(?) text links to alter status of invites // 5. Provide csv export(?) $form['ni_ui_intro'] = array( '#value' => '
This form allows you to manage those invites you\'ve sent out.
', ); $statement = " SELECT iid ,ni.nid ,email_invitee ,uid_inviter ,ni.status ,ni.sent ,acted_upon ,notes_invitee ,notes_inviter ,n.title ,u.name FROM {node_invites} as ni ,{node} as n ,{users} as u WHERE uid_inviter = $uid_inviter AND n.nid = ni.nid AND u.uid = ni.uid_inviter "; $sort_fields = _ni_sort_order_determine(); $statement .= " ORDER BY " . $sort_fields['field'] . ' ' . $sort_fields['order'] . " , iid DESC "; $sth = db_query($statement); $table_output = "What | Sent to | "; // if this is someone who can manage ALL then add a column for who sent it. if (user_access('manage all invites')) { $table_output .= "Sent by | "; } $table_output .= "Invite Sent | Status | Acted Upon | Actions | |||
---|---|---|---|---|---|---|---|---|---|
" . $row['title'] . " | " . $row['email_invitee'] . " | "; // if they can manage all, show who sent it if (user_access('manage all invites')) { $table_output .= "" . $row['name'] . " | "; } $table_output .= "" . date('m/d/Y g:i a', $row['sent'] ) . " | " . $row['status'] . " | $acted_upon | "; // can they revoke/resend this invite? (depends on perms too...farm that out) if ($row['status'] != 'Yes' && $row['status'] != 'Revoked' && _ni_can_manage_this_invite($row['iid'])) { $table_output .="Revoke | "; $table_output .="Resend | "; } else { $table_output .= "Revoke | Resend | "; } $table_output .= "