Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function rsvp_menu() {
- $items['invite'] = array (
- 'title' => 'Invite Guests',
- 'page callback' => 'rsvp_invite',
- 'access arguments' => array('administer content'),
- // TODO - set proper perms -
- // does this perm asffect the login_one_time link landing page??
- );
- $items['invite/send'] = array (
- 'title' => 'Send Invitations',
- 'page callback' => 'rsvp_send',
- 'access arguments' => array('administer rsvp'),
- 'type' => MENU_CALLBACK,
- );
- $items['rsvp/%/%/%'] = array (
- 'title' => 'RSVP',
- 'page arguments' => array(1,2,3),
- 'page callback' => 'rsvp_page',
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- /*
- * Implement hook_mail().
- */
- function rsvp_mail($key, &$message, $params) {
- $guests = rsvp_query();
- foreach ($guests as $account) {
- switch($key) {
- case "invite $account->name" :
- $message['subject'] = 'A different kind of invitation';
- $message['body'][] = 'Some bloody body text.';
- $message['body'][] = rsvp_get_link($account);
- break;
- }
- }
- }
- function rsvp_mail_send($guests) {
- global $user;
- foreach ($guests as $account) {
- $module = 'rsvp';
- $from = $user->mail;
- $key = "invite $account->name";
- $to = $account->mail;
- $language = language_default();
- $send = TRUE;
- $params = array();
- $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
- if ($result['result'] == 1) {
- $verify[] = "Mail to $account->name at $account->mail succesfull";
- } else {
- $verify[] = "Mail to $account->name at $account->mail NOT succesfull";
- }
- }
- return $verify; //This doesn't work.
- }
- /**
- * Return array of guests as user objects.
- */
- function rsvp_query() {
- $result = db_query('SELECT uid FROM {users_roles} WHERE rid = :rid', array(':rid' => 4));
- foreach ($result as $row) {
- $guests[] = user_load($row->uid);
- }
- return $guests;
- }
- /* menu callback */
- function rsvp_invite() {
- $guests = rsvp_query();
- foreach ($guests as $guest) {
- $item[] = $guest->name;
- }
- $vars = array(
- 'items' => $item,//$guests,
- 'title' => 'The following users have not received invitations',
- 'type' => 'ul',
- 'attributes' => array('class' => 'list-to-send'),
- );
- $output = theme('item_list',$vars);
- $output .= l('Send Invites', 'invite/send');
- return $output;
- }
- /* menu send */
- function rsvp_send() {
- $guests = rsvp_query();
- $mail = rsvp_mail_send($guests);
- return $mail;
- }
- /* generate info for one-time login link */
- function rsvp_get_link($account) {
- $path = "user/$account->uid/edit/Wedding";
- $timestamp = REQUEST_TIME;
- return url("rsvp/" . $account->uid . "/" . $timestamp . "/" .
- md5($account->pass . $timestamp) . "/" . $path, array('absolute' => TRUE));
- }
- /* TODO rsvp callback */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement