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

Diff of /contributions/modules/nf_handshake/nf_handshake.module

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

revision 1.1.2.5, Tue Sep 18 04:22:20 2007 UTC revision 1.1.2.6, Fri Oct 26 19:49:25 2007 UTC
# Line 12  Line 12 
12   * @link none yet   * @link none yet
13   * TODO fix date presentation   * TODO fix date presentation
14   * TODO remove all handshake menu items/user profile items from user 1 and other 'administer handshake' people if the settings match   * TODO remove all handshake menu items/user profile items from user 1 and other 'administer handshake' people if the settings match
15   * TODO allow admin to designate some fields as always viewable (handshake not needed); display above handshake/contact option   * TODO allow admin to designate some fields as always viewable (handshake not needed); display above handshake/contact option if have permission to view this
16   * TODO user search - by username, by address, by ???; allow admin to specify fields that are searchable; make as a separate,   * TODO allow users to designate some fields as always viewable (handshake not needed); display above handshake/contact option
17     * TODO user search - by address, by ???; allow admin to specify fields that are searchable; make as a separate,
18   * companion module like nf_handshake_user_search.module; if search field is 'always viewable' then results would include everyone who meets   * companion module like nf_handshake_user_search.module; if search field is 'always viewable' then results would include everyone who meets
19   * the criteria, otherwise, only those where a handshake exists and that data is exposed.   * the criteria, otherwise, only those where a handshake exists and that data is exposed.
20   * TODO Add tab in admin UI so admin can selectively place sub-fields of complex CCK fields into either a separate effective field   * TODO Add tab in admin UI so admin can selectively place sub-fields of complex CCK fields into either a separate effective field
# Line 106  function nf_handshake_perm() { Line 107  function nf_handshake_perm() {
107  function nf_handshake_menu($may_cache) {  function nf_handshake_menu($may_cache) {
108    $items = array();    $items = array();
109    global $user;    global $user;
110    if (!$may_cache) {    if ($may_cache) {
111      //-----------------------admin ui menu items----------------------------------      //-----------------------admin ui menu items----------------------------------
112      $items[] = array( //setup which data can be exchanged in the handshake process      $items[] = array( //setup which data can be exchanged in the handshake process
113      'path' => 'admin/user/nf_handshake',      'path' => 'admin/user/nf_handshake',
# Line 281  someone that has another field type in t Line 282  someone that has another field type in t
282      'access' => user_access('intitiate handshake')|| user_access('accept handshake'),      'access' => user_access('intitiate handshake')|| user_access('accept handshake'),
283      'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
284      );      );
285    //}    }
286    //else {//TODO remove the comments here before final version    else {
287      //-----------------------user-viewable menu itmes----------------------------------      //-----------------------user-viewable menu itmes----------------------------------
288      $admin_access = user_access('administer users');      $admin_access = user_access('administer users');
289      $access_access = user_access('administer access control');      $access_access = user_access('administer access control');
# Line 321  someone that has another field type in t Line 322  someone that has another field type in t
322      $flags_to_attend += nf_handshake_get_read_handshake_flags_auid($user->uid);      $flags_to_attend += nf_handshake_get_read_handshake_flags_auid($user->uid);
323      $new = $new_handshakes + $flags_to_attend;      $new = $new_handshakes + $flags_to_attend;
324      $items[] = array(      $items[] = array(
325      'path' => 'user/' .$user->uid. '/nf_handshake/inbox',      'path' => 'user/' .$user->uid. '/nf_handshake',
326      'title' => t('Handshakes'). ($new ? ' (' .$new. ')' : ' -') . ($unanswered_handshakes ? ' (' .$unanswered_handshakes. ')' : ' -'),      'title' => t('Handshakes'),
327      'callback' => 'drupal_get_form',      'callback' => 'drupal_get_form',
328      'callback arguments' => array('nf_handshake_inbox'),      'callback arguments' => array('nf_handshake_view_contacts'),
329      'access' => user_access('accept handshake'),      'access' => user_access('view own handshakes'),
330      'type' => MENU_LOCAL_TASK|MENU_DYNAMIC_ITEM,      'type' => MENU_LOCAL_TASK,
331      );      );
   
332      //view handshake list      //view handshake list
333      $items[] = array(      $items[] = array(
334      'path' => 'user/' .$user->uid. '/nf_handshake/view_contacts',      'path' => 'user/' .$user->uid. '/nf_handshake/view_contacts',
335      'title' => t('Handshake contacts'),      'title' => t('Contacts'),
     'callback' => 'drupal_get_form',  
     'callback arguments' => array('nf_handshake_view_contacts'),  
336      'access' => user_access('view own handshakes'),      'access' => user_access('view own handshakes'),
337      'type' => MENU_LOCAL_TASK|MENU_DYNAMIC_ITEM,      'type' => MENU_DEFAULT_LOCAL_TASK,
338        'weight' => -10,
339        );
340        $items[] = array(
341        'path' => 'user/' .$user->uid. '/nf_handshake/inbox',
342        'title' => t('Handshake inbox'). ($new ? ' (' .$new. ')' : ' -') . ($unanswered_handshakes ? ' (' .$unanswered_handshakes. ')' : ' -'),
343        'callback' => 'drupal_get_form',
344        'callback arguments' => array('nf_handshake_inbox'),
345        'access' => user_access('accept handshake'),
346        'type' => MENU_LOCAL_TASK,
347        'weight' => -6,
348        );
349        $items[] = array(
350        'path' => 'user/' .$user->uid. '/nf_handshake/search',
351        'title' => t('User search'),
352        'callback' => 'nf_handshake_search_view',
353        'access' => user_access('access user profiles'),
354        'type' => MENU_LOCAL_TASK,
355        'weight' => -4,
356      );      );
357    
358      //view a handshake request      //view a handshake request
# Line 375  function nf_handshake_cron() { Line 391  function nf_handshake_cron() {
391        $unit = 60*60*24*365;        $unit = 60*60*24*365;
392        break;        break;
393    }    }
394    $sql = "SELECT auid, iuid, datestamp FROM {nf_handshake} WHERE hstatus = '%s' OR hstatus = '%s' AND duration < %d";  
395      $sql = "SELECT auid, iuid, datestamp, duration FROM {nf_handshake} WHERE (hstatus = %d OR hstatus = %d) AND duration < %d";
396    $results = db_query($sql, NFHANDSHAKE_PENDING, NFHANDSHAKE_REVIEWED, time());    $results = db_query($sql, NFHANDSHAKE_PENDING, NFHANDSHAKE_REVIEWED, time());
397    while ($result = db_fetch_object($results)) {    while ($result = db_fetch_object($results)) {
398      $entries['auid'][] = $result->auid;      $entries['auid'][] = $result->auid;
# Line 384  function nf_handshake_cron() { Line 401  function nf_handshake_cron() {
401    }    }
402    $sql1 = "UPDATE {nf_handshake} SET duration = %d, hstatus = %d WHERE iuid= %d AND auid = %d";    $sql1 = "UPDATE {nf_handshake} SET duration = %d, hstatus = %d WHERE iuid= %d AND auid = %d";
403    $sql2 = "DELETE FROM {nf_handshake_manage} WHERE iuid= %d AND auid = %d";    $sql2 = "DELETE FROM {nf_handshake_manage} WHERE iuid= %d AND auid = %d";
404    foreach ($entries['auid'] as $key => $value) {    if (!empty($entries['auid'])) {
405      $duration = $entries['datestamp'][$key] + ($unit*$number);      foreach ($entries['auid'] as $key => $value) {
406      $success1 = db_query($sql1, $duration, NFHANDSHAKE_REJECTED, $entries['iuid'][$key], $entries['auid'][$key]);        $duration = $entries['datestamp'][$key] + ($unit*$number);
407      $success2 = db_query($sql2, $entries['iuid'][$key], $entries['auid'][$key]);        $success1 = db_query($sql1, $duration, NFHANDSHAKE_REJECTED, $entries['iuid'][$key], $entries['auid'][$key]);
408          $success2 = db_query($sql2, $entries['iuid'][$key], $entries['auid'][$key]);
409        }
410    }    }
411    //Expire rejected handshakes NFHANDSHAKE_EXPIRED    //Expire rejected handshakes NFHANDSHAKE_EXPIRED
412    $sql3 = "UPDATE {nf_handshake} SET hstatus = %d WHERE duration < %d AND hstatus = %d";    $sql3 = "UPDATE {nf_handshake} SET hstatus = %d WHERE duration < %d AND hstatus = %d";
# Line 1466  function nf_handshake_flag_decisions() { Line 1485  function nf_handshake_flag_decisions() {
1485   *   *
1486   * If the user is an admin or is trying to view his own profile, call user_view so it's shown to him like normal.   * If the user is an admin or is trying to view his own profile, call user_view so it's shown to him like normal.
1487   * Otherwise, check if the current user has previously shaken hands with the user whose profile he's trying to   * Otherwise, check if the current user has previously shaken hands with the user whose profile he's trying to
1488   * view. If so and it was accepted, present the exposed data. If so and it the request is pending or some other   * view. If so and it was accepted, present the exposed data. If so and if the request is pending or some other
1489   * intermediate condition exists, show what that condition is. If no handshake has been made, present the user   * intermediate condition exists, show what that condition is. If no handshake has been made, present the user
1490   * with a form to request a handshake from the other user.   * with a form to request a handshake from the other user.
1491   *   *
# Line 2426  function theme_nf_handshake_inbox($form) Line 2445  function theme_nf_handshake_inbox($form)
2445      '#weight' => 0,      '#weight' => 0,
2446      );      );
2447    $output .= theme('fieldset', $fieldset2);    $output .= theme('fieldset', $fieldset2);
2448    $output .= '<br />' .l(t('View your handshake contacts'), 'user/' .$user->uid. '/nf_handshake/view_contacts', array('title' => t("View all of the people you have shaken hands with.")));    $output .= '<br />' .l(t('View your handshake contacts'), 'user/' .$user->uid. '/nf_handshake', array('title' => t("View all of the people you have shaken hands with.")));
2449    $output .= drupal_render($form);    $output .= drupal_render($form);
2450    return $output;    return $output;
2451  } // function theme_nf_handshake_inbox()  } // function theme_nf_handshake_inbox()
# Line 3754  function theme_nf_handshake_view_contact Line 3773  function theme_nf_handshake_view_contact
3773                   array('title' => t("You may revoke specific fields from the handshake at any time.")));                   array('title' => t("You may revoke specific fields from the handshake at any time.")));
3774      $rows[] = array(l($username, 'user/' .$uid), date('M j Y', $datestamp), date('M j Y', $duration), $contact, $revoke, $extend, $upgrade, $downgrade);      $rows[] = array(l($username, 'user/' .$uid), date('M j Y', $datestamp), date('M j Y', $duration), $contact, $revoke, $extend, $upgrade, $downgrade);
3775    }    }
   
3776    $output .= theme('table', $header, $rows, array('width' => '100%'));    $output .= theme('table', $header, $rows, array('width' => '100%'));
3777    $output .= drupal_render($form);    $output .= drupal_render($form);
3778    return $output;    return $output;
3779  } // function theme_nf_handshake_view_contacts()  } // function theme_nf_handshake_view_contacts()
3780    
3781    /**
3782     * Menu callback; presents the search form and/or search results.
3783     */
3784    function nf_handshake_search_view() {
3785      $type = 'username';
3786    
3787      // Search form submits with POST but redirects to GET. This way we can keep
3788      // the search query URL clean as a whistle:
3789      // search/type/keyword+keyword
3790      if (!isset($_POST['form_id'])) {
3791        if ($type == '') {
3792          // Note: search/node can not be a default tab because it would take on the
3793          // path of its parent (search). It would prevent remembering keywords when
3794          // switching tabs. This is why we drupal_goto to it from the parent instead.
3795          drupal_goto('search/node');
3796        }
3797    
3798        $keys = nf_handshake_search_get_keys();
3799        // Only perform search if there is non-whitespace search term:
3800        if (trim($keys)) {
3801          // Log the search keys:
3802          //watchdog('nf_handshake', t('%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name'))), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));
3803    
3804          // Collect the search results:
3805          $results = array();
3806          // Replace wildcards with MySQL/PostgreSQL wildcards.
3807          $keys = preg_replace('!\*+!', '%', $keys);
3808          $result = pager_query("SELECT name, uid FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);
3809          while ($account = db_fetch_object($result)) {
3810            $results[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, NULL, NULL, TRUE));
3811          }
3812          if (isset($results) && is_array($results) && count($results)) {
3813            $results = theme('search_page', $results, $type);
3814          }
3815    
3816          if ($results) {
3817            $results = theme('box', t('Search results'), $results);
3818          }
3819          else {
3820            $results = theme('box', t('Your search yielded no results'), search_help('search#noresults'));
3821          }
3822        }
3823    
3824        // Construct the search form.
3825        $output = drupal_get_form('nf_handshake_search_box', $keys);
3826        $output .= $results;
3827    
3828        return $output;
3829      }
3830    
3831      return drupal_get_form('nf_handshake_search_box', $keys);
3832    } // function nf_handshake_search_view()
3833    
3834    /**
3835     * Output a search form for the search block and the theme's search box.
3836     */
3837    function nf_handshake_search_box($keys = '') {
3838      // Add CSS
3839      drupal_add_css(drupal_get_path('module', 'search') .'/search.css', 'module', 'all', FALSE);
3840      // Use search_keys instead of keys to avoid ID conflicts with the search block.
3841      $form['nf_handshake_search_box_keys'] = array(
3842        '#type' => 'textfield',
3843        '#title' => t('Username search'),
3844        '#size' => 40,
3845        '#default_value' => $keys,
3846      );
3847      $form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
3848      if ($results !== '') {
3849        $form['results'] = $results;
3850      }
3851    
3852      return $form;
3853    } // function nf_handshake_search_box()
3854    
3855    /**
3856     * Process a block search form submission.
3857     */
3858    function nf_handshake_search_box_submit($form_id, $form_values) {
3859      global $user;
3860      $keys = $form_values['nf_handshake_search_box_keys'];
3861      if ($keys == '') {
3862        form_set_error('keys', t('Please enter some keywords.'));
3863        // Fall through to the drupal_goto() call.
3864      }
3865    
3866      return 'user/'. $user->uid .'/nf_handshake/search/'. $keys;
3867    } // function nf_handshake_search_box_form_submit()
3868    
3869    /**
3870     * Theme the theme search form.
3871     */
3872    function theme_nf_handshake_search_box($form) {
3873      $output = '<div class="search-form">'. drupal_render($form) .'</div>';
3874      if (isset($form['results']) && is_array($form['results']) && count($form['results'])) {
3875        $output .=  theme('search_page', $form['results'], 'user');
3876      }
3877      return;
3878    }
3879    
3880  //-----------------------------------------Helper Functions-----------------------------------------  //-----------------------------------------Helper Functions-----------------------------------------
3881  //-----------------------------------------Helper Functions-----------------------------------------  //-----------------------------------------Helper Functions-----------------------------------------
3882  //-----------------------------------------Helper Functions-----------------------------------------  //-----------------------------------------Helper Functions-----------------------------------------
3883  /**  /**
3884     * Helper function for grabbing search keys.
3885     */
3886    function nf_handshake_search_get_keys() {
3887      // Extract keys as remainder of path
3888      // Note: support old GET format of searches for existing links.
3889      $path = explode('/', $_GET['q'], 5);
3890      return count($path) == 5 ? $path[4] : $_REQUEST['keys'];
3891    }
3892    /**
3893   * return an array that can be used in a drop down selector and which corresponds to the constants for the user flags.   * return an array that can be used in a drop down selector and which corresponds to the constants for the user flags.
3894   */   */
3895  function nf_handshake_get_status_flags() {  function nf_handshake_get_status_flags() {

Legend:
Removed from v.1.1.2.5  
changed lines
  Added in v.1.1.2.6

  ViewVC Help
Powered by ViewVC 1.1.2