Advertisement
Guest User

Untitled

a guest
May 2nd, 2011
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. <?php
  2. function rsvp_menu() {
  3.   $items['invite'] = array (
  4.     'title' => 'Invite Guests',
  5.     'page callback' => 'rsvp_invite',
  6.     'access arguments' => array('administer content'),
  7.     // TODO - set proper perms -
  8.     // does this perm asffect the login_one_time link landing page??
  9.   );
  10.   $items['invite/send'] = array (
  11.     'title' => 'Send Invitations',
  12.     'page callback' => 'rsvp_send',
  13.     'access arguments' => array('administer rsvp'),
  14.     'type' => MENU_CALLBACK,
  15.   );    
  16.   $items['rsvp/%/%/%'] = array (
  17.     'title' => 'RSVP',
  18.     'page arguments' => array(1,2,3),
  19.     'page callback' => 'rsvp_page',
  20.     'access arguments' => array('access content'),
  21.     'type' => MENU_CALLBACK,
  22.   );
  23.   return $items;
  24. }
  25.  
  26. /*
  27.  * Implement hook_mail().
  28.  */
  29.  
  30. function rsvp_mail($key, &$message, $params) {
  31.   $guests = rsvp_query();
  32.   foreach ($guests as $account) {
  33.     switch($key) {
  34.       case "invite $account->name" :
  35.         $message['subject'] = 'A different kind of invitation';
  36.         $message['body'][] = 'Some bloody body text.';
  37.         $message['body'][] = rsvp_get_link($account);
  38.         break;
  39.     }
  40.   }
  41. }
  42.  
  43.  
  44.  
  45. function rsvp_mail_send($guests) {
  46.   global $user;
  47.   foreach ($guests as $account) {
  48.     $module = 'rsvp';
  49.     $from = $user->mail;
  50.     $key = "invite $account->name";
  51.     $to = $account->mail;
  52.     $language = language_default();
  53.     $send = TRUE;
  54.     $params = array();
  55.     $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
  56.     if ($result['result'] == 1) {
  57.       $verify[] = "Mail to $account->name at $account->mail succesfull";
  58.     } else {
  59.       $verify[] = "Mail to $account->name at $account->mail NOT succesfull";
  60.     }
  61.   }
  62.  
  63.  return $verify;  //This doesn't work.
  64. }
  65.  
  66. /**
  67.  * Return array of guests as user objects.
  68.  */
  69. function rsvp_query() {
  70.   $result = db_query('SELECT uid FROM {users_roles} WHERE rid = :rid', array(':rid' => 4));
  71.   foreach ($result as $row) {
  72.     $guests[] = user_load($row->uid);
  73.   }  
  74.   return $guests;
  75. }
  76.  
  77. /* menu callback */
  78. function rsvp_invite() {
  79.   $guests = rsvp_query();
  80.   foreach ($guests as $guest) {
  81.     $item[] = $guest->name;
  82.   }
  83.   $vars = array(
  84.     'items' => $item,//$guests,
  85.     'title' => 'The following users have not received invitations',
  86.     'type' => 'ul',
  87.     'attributes' => array('class' => 'list-to-send'),
  88.   );
  89.   $output = theme('item_list',$vars);
  90.   $output .= l('Send Invites', 'invite/send');
  91.   return $output;
  92.   }
  93.  
  94. /* menu send */
  95. function rsvp_send() {
  96.   $guests = rsvp_query();
  97.   $mail = rsvp_mail_send($guests);
  98.   return $mail;
  99.  }
  100.  
  101. /* generate info for one-time login link */
  102. function rsvp_get_link($account) {
  103.  
  104.   $path = "user/$account->uid/edit/Wedding";
  105.  
  106.   $timestamp = REQUEST_TIME;
  107.  
  108.   return url("rsvp/" . $account->uid . "/" . $timestamp . "/" .
  109.     md5($account->pass . $timestamp) . "/" . $path, array('absolute' => TRUE));
  110. }
  111.  
  112. /* TODO rsvp callback */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement