/[drupal]/contributions/modules/node_invite/node_invite.module
ViewVC logotype

Diff of /contributions/modules/node_invite/node_invite.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.11.2.3, Thu Sep 3 00:17:30 2009 UTC revision 1.11.2.4, Fri Sep 4 08:40:48 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: node_invite.module,v 1.11.2.2 2009/09/02 07:35:01 hadsie Exp $  // $Id: node_invite.module,v 1.11.2.3 2009/09/03 00:17:30 hadsie Exp $
3  /**  /**
4   * @file   * @file
5   * Provides the overall functionality for the node_invite module.   * Provides the overall functionality for the node_invite module.
# Line 63  function node_invite_menu() { Line 63  function node_invite_menu() {
63    $items['admin/settings/node_invite'] = array(    $items['admin/settings/node_invite'] = array(
64      'title' => 'Node Invite',      'title' => 'Node Invite',
65      'description' => t('Node Invite module is similar to RSVP.  Invite people to nodes, manage your invites, etc.'),      'description' => t('Node Invite module is similar to RSVP.  Invite people to nodes, manage your invites, etc.'),
     'access arguments' => array('admin node invite settings'),  
66      'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
67      'page arguments' => array('node_invite_admin_settings_form'),      'page arguments' => array('node_invite_admin_settings_form'),
68        'access arguments' => array('admin node invite settings'),
69      'file' => 'node_invite.admin.inc',      'file' => 'node_invite.admin.inc',
70    );    );
71    $items['admin/settings/node_invite/settings'] = array(    $items['admin/settings/node_invite/settings'] = array(
72      'title' => 'Settings',      'title' => 'Settings',
     'type'  => MENU_DEFAULT_LOCAL_TASK,  
73      'weight' => 0,      'weight' => 0,
74        'type'  => MENU_DEFAULT_LOCAL_TASK,
75    );    );
76    $items['admin/settings/node_invite/notifications'] = array(    $items['admin/settings/node_invite/notifications'] = array(
77      'title' => 'Notifications',      'title' => 'Notifications',
     'type' => MENU_LOCAL_TASK,  
     'access arguments' => array('admin node invite settings'),  
78      'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
79      'page arguments' => array('node_invite_notifications_form'),      'page arguments' => array('node_invite_notifications_form'),
80      'weight' => 1,      'access arguments' => array('admin node invite settings'),
81      'file' => 'node_invite.admin.inc',      'file' => 'node_invite.admin.inc',
82        'weight' => 1,
83        'type' => MENU_LOCAL_TASK,
84    );    );
85    $items['admin/settings/node_invite/manage'] = array(    $items['admin/settings/node_invite/manage'] = array(
86      'title' => 'Manage Invites',      'title' => 'Manage Invites',
87      'type' => MENU_LOCAL_TASK,      'page callback' => 'node_invite_manage_page',
88      'access arguments' => array('manage all invites'),      'access arguments' => array('manage all invites'),
89      'page callback' => 'drupal_get_form',      'type' => MENU_LOCAL_TASK,
     'page arguments' => array('user_invites_form'),  
     'weight' => 2,  
90      'file' => 'node_invite.admin.inc',      'file' => 'node_invite.admin.inc',
91        'weight' => 2,
92    );    );
93    $items['node_invite/invite/%node'] = array(    $items['node_invite/invite/%node'] = array(
94      'title' => 'Invite',      'title' => 'Invite',
     'type' => MENU_CALLBACK,  
     'access arguments' => array('invite users to invite-enabled nodes'),  
95      'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
96      'page arguments' => array('node_invite_send', 2),      'page arguments' => array('node_invite_send', 2),
97        'access arguments' => array('invite users to invite-enabled nodes'),
98      'file' => 'node_invite.send.inc',      'file' => 'node_invite.send.inc',
99        'type' => MENU_CALLBACK,
100    );    );
101    $items['node_invite/rsvp/%node/%node_invite'] = array(    $items['node_invite/rsvp/%node/%node_invite'] = array(
102      'title arguments' => array(2, 3),      'title arguments' => array(2, 3),
103      'title callback' => 'node_invite_rsvp_title',      'title callback' => 'node_invite_rsvp_title',
     'type' => MENU_CALLBACK,  
     'access arguments' => array('respond to invites'),  
104      'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
105      'page arguments' => array('node_invite_rsvp', 2, 3),      'page arguments' => array('node_invite_rsvp', 2, 3),
106        'access arguments' => array('respond to invites'),
107      'file' => 'node_invite.rsvp.inc',      'file' => 'node_invite.rsvp.inc',
108        'type' => MENU_CALLBACK,
109    );    );
110    $items['node_invite/revoke/%'] = array(    $items['node_invite/revoke/%node_invite'] = array(
111      'title' => 'Revoke',      'title' => 'Revoke',
     'type' => MENU_CALLBACK,  
     'access callback' => 'node_invite_access_revoke',  
112      'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
113      'page arguments' => array('node_invite_revoke', 2),      'page arguments' => array('node_invite_revoke', 2),
114        'access callback' => 'node_invite_can_manage_invite',
115        'access arguments' => array(2),
116        'type' => MENU_CALLBACK,
117    );    );
118    $items['node_invite/resend/%'] = array(    $items['node_invite/resend/%node_invite'] = array(
119      'title' => 'Resend',      'title' => 'Resend',
     'type' => MENU_CALLBACK,  
     'access callback' => 'node_invite_access_resend',  
120      'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
121      'page arguments' => array('node_invite_resend', 2),      'page arguments' => array('node_invite_resend', 2),
122        'access callback' => 'node_invite_can_manage_invite',
123        'access arguments' => array(2),
124        'type' => MENU_CALLBACK,
125    );    );
126    $items['user/%user/invites'] = array(    $items['user/%user/invites'] = array(
127      'title' => 'My Invites',      'title' => 'My Invites',
128      'page callback' => 'node_invite_user_invites',      'page callback' => 'node_invite_user_invites',
129      'page arguments' => array(1),      'page arguments' => array(1),
     'type' => MENU_LOCAL_TASK,  
130      'access arguments' => array('manage own invites'),      'access arguments' => array('manage own invites'),
131      'weight' => 2,      'weight' => 2,
132        'type' => MENU_LOCAL_TASK,
133    );    );
134    
135    return $items;    return $items;
# Line 139  function node_invite_menu() { Line 140  function node_invite_menu() {
140   */   */
141  function node_invite_rsvp_title($node, $invite) {  function node_invite_rsvp_title($node, $invite) {
142    $account = user_load($invite->uid_inviter);    $account = user_load($invite->uid_inviter);
143    $node->invite_specific_info = array(    node_invite_specific_info($node, $invite, $account);
144      'node-invite-iid' => $invite->iid,  
     'node-invite-recip-name' => $invite->email_invitee,  
     'node-invite-recip-mail' => $invite->email_invitee,  
     'inviter-name' => $account->name,  
     'inviter-mail' => $account->mail,  
   );  
   
145    $page_title = token_replace(    $page_title = token_replace(
146      variable_get('node_invite_rsvp_page_title', NODE_INVITE_RSVP_PAGE_TITLE),      variable_get('node_invite_rsvp_page_title', NODE_INVITE_RSVP_PAGE_TITLE),
147      'node',      'node',
# Line 156  function node_invite_rsvp_title($node, $ Line 151  function node_invite_rsvp_title($node, $
151  }  }
152    
153  /**  /**
154   * Implementation of hook_load().   * Load an invite.
155   */   */
156  function node_invite_load($invite_id, $reset = NULL) {  function node_invite_load($invite_id, $reset = NULL) {
157    static $invite_cache = array();    static $invite_cache = array();
# Line 178  function node_invite_load($invite_id, $r Line 173  function node_invite_load($invite_id, $r
173  /**  /**
174   * Implementation of hook_link().   * Implementation of hook_link().
175   */   */
176  function node_invite_link( $type, $node = NULL, $teaser = FALSE ) {  function node_invite_link($type, $node = NULL, $teaser = FALSE) {
177    global $user;    global $user;
178    $links = array();    $links = array();
179    
# Line 192  function node_invite_link( $type, $node Line 187  function node_invite_link( $type, $node
187    return $links;    return $links;
188  }  }
189    
190  function _ni_node_is_enabled( $nid ) {  function _ni_node_is_enabled($nid) {
191    $sth = db_query("SELECT invites_enabled FROM {node_invite_settings} WHERE nid = %d", $nid);    $sth = db_query("SELECT invites_enabled FROM {node_invite_settings} WHERE nid = %d", $nid);
   
192    $enabled = variable_get('node_invite_default', NODE_INVITE_DEFAULT_FOR_ENABLED_NODES);    $enabled = variable_get('node_invite_default', NODE_INVITE_DEFAULT_FOR_ENABLED_NODES);
193    
194    if ($row = db_fetch_array($sth)) {    if ($row = db_fetch_array($sth)) {
195      // if there's a row in the table, then they're being explicit... override the default      // if there's a row in the table, then they're being explicit...
196        // override the default
197      $enabled = $row['invites_enabled'];      $enabled = $row['invites_enabled'];
198    }    }
199    
200    return $enabled;    return $enabled;
201  }  }
202    
203  function _node_invite_type_is_allowed( $type ) {  function _node_invite_type_is_allowed($type) {
204    if ( in_array( $type, variable_get('node_invite_node_types', array() ), TRUE ) ) {    return in_array($type, variable_get('node_invite_node_types', array()), TRUE);
     return TRUE;  
   }  
   return FALSE;  
205  }  }
206    
207  /**  /**
# Line 253  function node_invite_token_values($type, Line 245  function node_invite_token_values($type,
245   * Implementation of hook_token_list().   * Implementation of hook_token_list().
246   */   */
247  function node_invite_token_list( $type='all') {  function node_invite_token_list( $type='all') {
   /* global $user;  
   drupal_set_message("<PRE>" . sprint_r( $user )  . "</pre>"); */  
248    $tokens = array();    $tokens = array();
249    if (in_array($type, array('all', 'node_invite', 'node'))) {    if (in_array($type, array('all', 'node_invite', 'node'))) {
250      $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-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).');
# Line 283  function node_invite_content_extra_field Line 273  function node_invite_content_extra_field
273    return $extra;    return $extra;
274  }  }
275    
276  function node_invite_user_invites( $account ) {  function node_invite_user_invites($account) {
277    $headers = _node_invite_user_invites_headers();    return node_invite_list_invites($account);
278    $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 );  
279    
280    $destination = drupal_get_destination();  function node_invite_list_invites($account = NULL) {
281      // TODO:
282      // 4. Provide ajax(?) text links to alter status of invites
283      // 5. Provide csv export(?)
284    
285    $rows = array();    // Build the SQL Query
286    while ( $data = db_fetch_array($q) ) {    $sql = "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 u.uid = ni.uid_inviter";
     $row = array();  
     $row[] = $data['title'];  
     $row[] = check_plain($data['email_invitee']);  
287    
288      if ( user_access('manage all invites') ) {    $values = array();
289        $row[] = $data['name'];    if (isset($account)) {
290      }      $sql .= ' AND ni.uid_inviter = %d';
291        $values[] = $account->uid;
292      $row[] = date('m/d/Y g:i a', $data['sent'] );    }
293      $row[] = $data['status'];  
294      $row[] = $data['acted_upon'] ? date('m/d/Y g:i a', $row['acted_upon']) : '&nbsp;';    // Setup the table headers
295      $header = array(
296        array('data' => t('What'), 'field' => 'n.title'),
297        array('data' => t('Sent to'), 'field' => 'email_invitee'),
298        array('data' => t('Sent by'), 'field' => 'u.name'),
299        array('data' => t('Invite Sent'), 'field' => 'ni.sent'),
300        array('data' => t('Status'), 'field' => 'ni.status'),
301        array('data' => t('Acted Upon'), 'field' => 'acted_upon'),
302        array('data' => t('Actions')),
303      );
304      if (isset($account)) {
305        // Remove the 'Sent by' field, since it's redundant in this case
306        unset($header[2]);
307        $header = array_filter($header);
308      }
309    
310      // Execute the query and build the table row data
311      $sql .= tablesort_sql($header);
312      $result = pager_query($sql, 50, 0, NULL, $values);
313    
314      if ( $row['status'] != 'Yes' && $row['status'] != 'Revoked' && _node_invite_can_manage_this_invite($data['iid']) ) {    $destination = drupal_get_destination();
315        $row[] = l('Revoke', 'node_invite/revoke/' . $data['iid'], array('query' => $destination));    $rows = array();
316        $row[] = l('Resend', 'node_invite/resend/' . $data['iid'], array('query' => $destination));    while ($row = db_fetch_object($result)) {
317        $actions = "";
318        if (!in_array($row->status, array('Yes', 'Revoked'))) {
319          $actions .= l(t('Revoke'), 'node_invite/revoke/' . $row->iid, array('query' => $destination));
320          $actions .= ' ' . l(t('Resend'), 'node_invite/resend/' . $row->iid, array('query' => $destination));
321      }      }
322    
323      $rows[] = $row;      $acted_upon = $row->acted_upon ? format_date($row->acted_upon, 'small') : '';
324    }      if (isset($account)) {
325          // Don't list $row->name if this is for a specific account
326    return theme('table', $headers, $rows);        $rows[] = array($row->title, $row->email_invitee, format_date($row->sent, 'small'), $row->status, $acted_upon, $actions);
 }  
   
 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;  
327      }      }
328      elseif ( user_access('manage all invites') ) {      else {
329        return TRUE;        $rows[] = array($row->title, $row->email_invitee, $row->name, format_date($row->sent, 'small'), $row->status, $acted_upon, $actions);
330      }      }
331    }    }
332    return FALSE;  
333  }    return theme('table', $header, $rows);
   
 function node_invite_access_revoke() {  
   return TRUE;  
 }  
   
 function node_invite_access_resend() {  
   return TRUE;  
334  }  }
335    
336  function node_invite_revoke($form_state, $iid) {  /**
337    // ask for confirmation that they really want to revoke the invite.   * Access callback for determining if the current use can manage the given invite
338    if ( !intval($iid) ) {   */
339      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');  function node_invite_can_manage_invite($invite) {
340      return;    global $user;
   }  
341    
342    if (_node_invite_can_manage_this_invite($iid)) {    if ($invite->uid_inviter == $user->uid && user_access('manage own invites')) {
343      $form['iid'] = array(      return TRUE;
       '#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'] );  
344    }    }
345    else {    elseif (user_access('manage all invites')) {
346      drupal_set_message('Access denied', 'error');      return TRUE;
     return;  
347    }    }
348      return FALSE;
349  }  }
350    
351  function node_invite_revoke_submit( $form, &$form_state ) {  function node_invite_revoke($form_state, $invite) {
   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) {  
352    // ask for confirmation that they really want to revoke the invite.    // ask for confirmation that they really want to revoke the invite.
353    if ( !intval($iid) ) {  
354      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');    $form['invite'] = array(
355      return;      '#type' => 'value',
356    }      '#value' => $invite,
357      );
358    if (_node_invite_can_manage_this_invite($iid)) {  
359      $form['iid'] = array(    $form['#redirect'] = $_GET['destination'];
360        '#type' => 'value',  
361        '#value' => $iid,    return confirm_form($form, 'Are you sure you wish to revoke this invite?', $_GET['destination'] );
362      );  }
363      $form['referer'] = array(  
364        '#type' => 'hidden',  function node_invite_revoke_submit($form, &$form_state) {
365        '#value' => $_GET['destination'],    $invite = $form_state['values']['invite'];
366      );    node_invite_save($invite, array('status' => 'Revoked'));
367      return confirm_form($form, 'Are you sure you wish to resend this invite?', $_GET['destination']);  }
368    }  
369    else {  function node_invite_resend($form_state, $invite) {
370      drupal_set_message('Access denied', 'error');    // ask for confirmation that they really want to resend the invite.
371      return;    $form['invite'] = array(
372    }      '#type' => 'value',
373        '#value' => $invite,
374      );
375      $form['#redirect'] = $_GET['destination'];
376    
377      return confirm_form($form, 'Are you sure you wish to resend this invite?', $_GET['destination']);
378  }  }
379    
380  function node_invite_resend_submit($form, &$form_state) {  function node_invite_resend_submit($form, &$form_state) {
381    db_query("UPDATE {node_invites} SET status = '%s', acted_upon = NULL WHERE iid = %d", 'NEW', time(), $form_state['values']['iid']);    $invite = $form_state['values']['invite'];
382      $invite = node_invite_save($invite, array('status' => 'NEW', 'acted_upon' => NULL));
383    $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']);  
384      $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", $invite->iid);
385    if ($row = db_fetch_array($q)) {    if ($row = db_fetch_array($q)) {
386      $default_message = variable_get('node_invite_message_default', NODE_INVITE_MESSAGE_DEFAULT);      $default_message = variable_get('node_invite_message_default', NODE_INVITE_MESSAGE_DEFAULT);
387      $node = node_load($row['nid']);      $node = node_load($row['nid']);
# Line 488  function node_invite_resend_submit($form Line 421  function node_invite_resend_submit($form
421    
422    drupal_goto($form_state['values']['referer']);    drupal_goto($form_state['values']['referer']);
423  }  }
 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' => '<p>This form allows you to manage those invites you\'ve sent out.</p>',  
   );  
   
   $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 = "  
                 <table id='invites_form_table'>  
                         <tr id='invites_form_header'>  
                                 <th class='invites_form_header_th'><a href='" . url($sort_fields['existing_url'] . '/title/' . $sort_fields['order_new'] ) . "'>What</a></th>  
                                 <th class='invites_form_header_th'><a href='" . url($sort_fields['existing_url'] . '/email_invitee/' . $sort_fields['order_new'] ) . "'>Sent to</a></th>  
         ";  
   
   // if this is someone who can manage ALL then add a column for who sent it.  
   if (user_access('manage all invites')) {  
     $table_output .= "  
                                 <th class='invbites_form_header_th'><a href='" . url($sort_fields['existing_url'] . '/sent/' . $sort_fields['order_new'] ) . "'>Sent by</a></tH>  
                 ";  
   }  
   
   
   $table_output .= "  
                                 <th class='invites_form_header_th'><a href='" . url($sort_fields['existing_url'] . '/sent/' . $sort_fields['order_new'] ) . "'>Invite Sent</a></th>  
                                 <th class='invites_form_header_th'><a href='" . url($sort_fields['existing_url'] . '/status/' . $sort_fields['order_new'] ) . "'>Status</a></th>  
                                 <th class='invites_form_header_th'><a href='" . url($sort_fields['existing_url'] . '/acted_upon/' . $sort_fields['order_new'] ) . "'>Acted Upon</a></th>  
                                 <th class='invites_form_header_th' colspan=2 id='invites_form_header_actions_th'>Actions</tH>  
                         </tr>  
         ";  
   $counter = 0;  
   while ($row = db_fetch_array($sth)) {  
     $counter++;  
   
     // format the "actued upon" date field  
     if ($row['acted_upon'] == '' ) {  
       $acted_upon = '';  
     }  
     else {  
       $acted_upon = date('m/d/Y g:i a', $row['acted_upon']);  
     }  
   
     // zebra stripes  
     $trclass = 'odd';  
     if ( $counter % 2 == 0 ) {  
       $trclass = 'even';  
     }  
   
   
     // add a row to the table.  
     $table_output .= "  
                         <tr class=$trclass>  
                                 <td>" . $row['title'] . "</td>  
                                 <td>" . $row['email_invitee'] . "</td>  
                 ";  
   
     // if they can manage all, show who sent it  
     if (user_access('manage all invites')) {  
       $table_output .= "  
                                 <td>" . $row['name'] . "</td>  
                         ";  
     }  
   
     $table_output .= "  
                                 <td>" . date('m/d/Y g:i a', $row['sent'] ) . "</td>  
                                 <td>" . $row['status'] . "</td>  
                                 <td>$acted_upon</td>  
                 ";  
     // 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 .="  
                                 <td><a href='" . url( 'node_invite/revoke/' . $row['iid'] ) . "'>Revoke</a></td>  
                         ";  
       $table_output .="  
                                 <td><a href='" . url( 'node_invite/resend/' . $row['iid'] ) . "'>Resend</a></td>  
                         ";  
     }  
     else {  
       $table_output .= "  
                                 <td class='node_invite_greyed_out'>Revoke</td>  
                                 <td class='node_invite_greyed_out'>Resend</td>";  
     }  
     $table_output .= "  
                         </tr>  
                 ";  
   
   }  
   $table_output .= "  
                 </table>";  
   
   $form['ni_ui_table'] = array(  
     '#value' => $table_output,  
   );  
   
   return $form;  
 }  
   
 function _ni_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 _ni_sort_order_determine() {  
   global $user;  
   
   // defaults  
   $sort_fields = array(  
     'field' => 'sent',  
     'order' => '',  
     'order_new' => 'DESC',  
     'existing_url' => '',  
   );  
   
   // what fields can we sort by?  
   $acceptable_sort_fields = array('iid', 'email_invitee', 'sent', 'status', 'title', 'name', 'acted_upon');  
   
   // path will be of 2 formats:  
   //    A. user/$nid/invites/sort_field/sort_order  
   if ( ( arg(0) == 'user') && ( arg(2) == 'invites' ) ) {  
     if ( in_array( arg(3), $acceptable_sort_fields ))  {  
       $sort_fields['field'] = arg(3);  
     }  
     if ( arg(4) == 'DESC') {  
       $sort_fields['order'] = 'DESC';  
       $sort_fields['order_new'] = '';  
     }  
     $sort_fields['existing_url'] = 'user/' . $user->uid . '/invites';  
   }  
   //    B. admin/settings/node_invite/manage/sort_field/sort_order  
   elseif (arg(0) == 'admin' && arg(1) == 'settings' && arg(2) =='node_invite' && arg(3) == 'manage') {  
     if (in_array(arg(4), $acceptable_sort_fields))  {  
       $sort_fields['field'] = arg(4);  
     }  
     if (arg(5) == 'DESC') {  
       $sort_fields['order'] = 'DESC';  
       $sort_fields['order_new'] = '';  
     }  
     else {  
       $sort_fields['order'] = '';  
       $sort_fields['order_new'] = 'DESC';  
     }  
     $sort_fields['existing_url'] = 'admin/settings/node_invite/manage';  
   
   }  
   else {  
     drupal_set_message("_ni_sort_order_determine called with weird args.", 'error');  
   }  
   
   return $sort_fields;  
 }  
424    
425  function node_invite_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {  function node_invite_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
426    // decides whether or not to enable disable invites for this node.    // decides whether or not to enable disable invites for this node.
# Line 788  function node_invite_rsvp_path($invite) Line 523  function node_invite_rsvp_path($invite)
523    }    }
524    return $url;    return $url;
525  }  }
526    
527    function node_invite_save($invite, $params = array()) {
528      $ni_fields = array('iid', 'nid', 'email_invitee', 'uid_inviter', 'status', 'sent', 'acted_upon', 'notes_invitee', 'notes_inviter', 'hash');
529    
530      if (is_object($invite) && $invite->iid) {
531        $query = array();
532        $values = array();
533        foreach ($params as $key => $value) {
534          if (in_array($key, $ni_fields)) {
535            $query[] = "$key = '%s'";
536            $values[] = $value;
537          }
538        }
539    
540        // The status was changed, so acted_upon needs to be set to now()
541        $keys = array_keys($params);
542        if (!in_array('acted_upon', $keys) && in_array('status', $keys)) {
543          $query[] = "acted_upon = %d";
544          $values[] = time();
545        }
546    
547        $success = db_query('UPDATE {node_invites} SET ' . implode(', ', $query) . ' WHERE iid = %d', array_merge($values, array($invite->iid)));
548        if (!$success) {
549          return FALSE;
550        }
551    
552        // Refresh the invite object
553        $invite = node_invite_load($invite->iid);
554      }
555      else {
556        $fields = array();
557        $values = array();
558        $s = array();
559        foreach ($params as $key => $value) {
560          if (in_array($key, $ni_fields)) {
561            $fields[] = $key;
562            $values[] = $value;
563            $s[] = is_numeric($value) ? "%d" : "'%s'";
564          }
565        }
566        $sent = time();
567        $fields[] = 'sent';
568        $values[] = time();
569        $s[] = "%d";
570    
571        $hash = md5($email . $sent);
572        $fields[] = 'hash';
573        $values[] = $hash;
574        $s[] = "'%s'";
575    
576        $success = db_query('INSERT INTO {node_invites} (' . implode(', ', $fields) . ') VALUES ('. implode(', ', $s) . ')', $values);
577        if (!$success) {
578          return FALSE;
579        }
580        $iid = db_last_insert_id('node_invite', 'iid');
581        $invite = node_invite_load($iid);
582      }
583    
584      return $invite;
585    }
586    
587    function node_invite_specific_info(&$node, $invite, $account) {
588      $node->invite_specific_info = array(
589        'node-invite-iid' => $invite->iid,
590        'node-invite-hash' => $invite->hash,
591        'node-invite-recip-name' => $invite->email_invitee,
592        'node-invite-recip-mail' => $invite->email_invitee,
593        'inviter-name' => $account->name,
594        'inviter-mail' => $account->mail,
595      );
596    }

Legend:
Removed from v.1.11.2.3  
changed lines
  Added in v.1.11.2.4

  ViewVC Help
Powered by ViewVC 1.1.2