' . t("Changes the way users contact each other and what they can know about each other. Implements a handshake routine where one user offers to expose certain profile fields to another in exchange for the same consideration."). '

'; break; } return $output; } // function nf_handshake_help() /** * Implementation of hook_perm * * Why is there separate 'initiate handshake' and 'accept handshake' permissions? In the case where you've used another module of mine * that allows sub-accounts and you want to allow sub-accounts to initiate handshakes but only the main account holder to accept them. * This would be the case where a parent is the primary account holder and a child is a sub-account holder. 'View own handshakes' is a * separate permission for the same reason. The admin may wish for children to see that someone is trying to shake hands so that they * can pester their parent to look into it. 'View handshakes' may or may not be used in the future. * * Valid permissions for this module * @return array $items An array of menu items */ function nf_handshake_perm() { return array('administer handshakes', 'intitiate handshake', 'accept handshake', 'view own handshakes', 'view handshakes'); } // function nf_handshake_perm() /** * Implementation of hook_menu * * @return array An array of arrays, to add menu entries to the system menu. */ function nf_handshake_menu($may_cache) { $items = array(); global $user; if (!$may_cache) { //-----------------------admin ui menu items---------------------------------- $items[] = array( //setup which data can be exchanged in the handshake process 'path' => 'admin/user/nf_handshake', 'title' => t('Handshake setup'), 'callback' => 'nf_handshake_main', 'access' => user_access('administer handshakes'), 'description' => t('This is how you organize your nodeprofile CCK field types for user sharing. To begin, go to Choose CCK Fields, then move on to Make groupings. Those in groups are considered equivalent so that if a user has one field type in the group, but not another, they can still share that info with someone that has another field type in the same group.'), 'type' => MENU_NORMAL_ITEM, ); $items[] = array( //tab to take us to main administer page 'path' => 'admin/user/nf_handshake/overview', 'title' => t('Overview'), 'access' => user_access('administer handshakes'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/user/nf_handshake/edit', 'title' => t('Edit'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_edit'), 'access' => user_access('administer handshakes'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/user/nf_handshake/delete', 'title' => t('Delete'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_confirm_delete'), 'access' => user_access('administer handshakes'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/user/nf_handshake/choose_cck_fields', 'title' => t('Choose CCK fields'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_choose_cck_fields'), 'access' => user_access('administer handshakes'), 'type' => MENU_LOCAL_TASK, 'weight' => -8, ); $items[] = array( 'path' => 'admin/user/nf_handshake/delete_cck_fields', 'title' => t('Delete CCK field'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_confirm_cck_fields_delete'), 'access' => user_access('administer handshakes'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/user/nf_handshake/make_grouping', 'title' => t('Make groupings'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_make_groupings'), 'access' => user_access('administer handshakes'), 'type' => MENU_LOCAL_TASK, 'weight' => -4, ); $items[] = array( 'path' => 'admin/user/nf_handshake/edit_group', 'title' => t('Edit group'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_group_edit'), 'access' => user_access('administer handshakes'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/user/nf_handshake/delete_group', 'title' => t('Delete group'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_confirm_group_delete'), 'access' => user_access('administer handshakes'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/user/nf_handshake/settings', 'title' => t('Misc settings'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_settings'), 'access' => user_access('administer handshakes'), 'type' => MENU_LOCAL_TASK, 'weight' => -2, ); $items[] = array( //administer flags set by the users 'path' => 'admin/user/nf_handshake_flags', 'title' => t('Handshake flag admin'), 'callback' => 'nf_handshake_flags', 'access' => user_access('administer handshakes'), 'description' => t('Users can flag handshake requests as SPAM and other things. The admin can mediate these instances here.'), 'type' => MENU_NORMAL_ITEM, ); $items[] = array( //tab to take us to main flag administer page 'path' => 'admin/user/nf_handshake_flags/overview', 'title' => t('Overview'), 'access' => user_access('administer handshakes'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( //tab to take us to main flag administer page 'path' => 'admin/user/nf_handshake_flags/decisions', 'title' => t('Decisions'), 'callback' => 'nf_handshake_flag_decisions', 'access' => user_access('administer handshakes'), 'type' => MENU_LOCAL_TASK, 'weight' => -8, ); $items[] = array( 'path' => 'admin/user/nf_handshake_flags/view', 'title' => t('Administer flag'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_view_flag'), 'access' => user_access('administer handshakes'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'user/nf_handshake/initiate', 'title' => t('Initiate handshake'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_initiate'), 'access' => user_access('intitiate handshake'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'user/nf_handshake/revoke_confirm', 'title' => t('Confirm handshake revoke'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_revoke_confirm'), 'access' => user_access('view own handshakes'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'user/nf_handshake/extend_duration', 'title' => t('Extend handshake duration'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_extend_duration'), 'access' => user_access('accept handshake'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'user/nf_handshake/request_extension', 'title' => t('Extend handshake duration'), 'callback' => 'nf_handshake_request_extention', 'access' => user_access('intitiate handshake'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'user/nf_handshake/flag_reply', 'title' => t('Respond to flagging'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_flag_reply'), 'access' => user_access('intitiate handshake')|| user_access('accept handshake'), 'type' => MENU_CALLBACK, ); //} //else {//TODO remove the comments here before final version //-----------------------user-viewable menu itmes---------------------------------- $admin_access = user_access('administer users'); $access_access = user_access('administer access control'); $view_access = user_access('access user profiles'); if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) { $account = user_load(array('uid' => arg(1))); if ($user !== FALSE) { // Always let a user view their own account $view_access |= $user->uid == arg(1); // Only admins can view blocked accounts $view_access &= $account->status || $admin_access; $items[] = array( //reroute users away from standard user profile page 'path' => 'user/' .arg(1), 'title' => t('View a user'), 'callback' => 'nf_handshake_view_user', 'callback arguments' => array(arg(1)), 'access' => $view_access, 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'user/' .arg(1). '/view', 'title' => t('View'), 'access' => $view_access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); } } //additions to user's own admin pages $new_handshakes = nf_handshake_get_new_handshake_requests($user->uid); $unanswered_handshakes = nf_handshake_get_read_handshake_requests($user->uid); $flags_to_attend = nf_handshake_get_read_handshake_flags_iuid($user->uid); $flags_to_attend += nf_handshake_get_read_handshake_flags_auid($user->uid); $new = $new_handshakes + $flags_to_attend; $items[] = array( 'path' => 'user/' .$user->uid. '/nf_handshake/inbox', 'title' => t('Handshakes'). ($new ? ' (' .$new. ')' : ' -') . ($unanswered_handshakes ? ' (' .$unanswered_handshakes. ')' : ' -'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_inbox'), 'access' => user_access('accept handshake'), 'type' => MENU_LOCAL_TASK|MENU_DYNAMIC_ITEM, ); //view handshake list $items[] = array( 'path' => 'user/' .$user->uid. '/nf_handshake/view_contacts', 'title' => t('Handshake contacts'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_view_contacts'), 'access' => user_access('view own handshakes'), 'type' => MENU_LOCAL_TASK|MENU_DYNAMIC_ITEM, ); //view a handshake request $items[] = array( 'path' => 'user/' .$user->uid. '/nf_handshake/view_hsr', 'title' => t('View request'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nf_handshake_view_hsr'), 'access' => user_access('view own handshakes'), 'type' => MENU_CALLBACK, ); } return $items; } // function nf_handshake_menu() /** * CRON to reject requests automatically if the user doesn't respond within a week (or a set time by the admin). * CRON to expire old rejected requests; this will allow people to reinitiate handshakes with those that have rejected them. */ function nf_handshake_cron() { $settings = variable_get('nf_handshake_settings', array('initiate_expire_unit' => 'Weeks', 'initiate_expire_number' => 1, 'reject_expire_unit' => 'Months', 'reject_expire_number' => 6)); //Set unanswered handshake requests to rejected after the expiration date $number = $settings['reject_expire_number']; $unit = $settings['reject_expire_unit']; switch ($unit) { case 'Days': $unit = 60*60*24; break; case 'Weeks': $unit = 60*60*24*7; break; case 'Months': $unit = 60*60*24*30; break; case 'Years': $unit = 60*60*24*365; break; } $sql = "SELECT auid, iuid, datestamp FROM {nf_handshake} WHERE hstatus = '%s' OR hstatus = '%s' AND duration < %d"; $results = db_query($sql, NFHANDSHAKE_PENDING, NFHANDSHAKE_REVIEWED, time()); while ($result = db_fetch_object($results)) { $entries['auid'][] = $result->auid; $entries['iuid'][] = $result->iuid; $entries['datestamp'][] = $result->datestamp; } $sql1 = "UPDATE {nf_handshake} SET duration = %d, hstatus = %d WHERE iuid= %d AND auid = %d"; $sql2 = "DELETE FROM {nf_handshake_manage} WHERE iuid= %d AND auid = %d"; foreach ($entries['auid'] as $key => $value) { $duration = $entries['datestamp'][$key] + ($unit*$number); $success1 = db_query($sql1, $duration, NFHANDSHAKE_REJECTED, $entries['iuid'][$key], $entries['auid'][$key]); $success2 = db_query($sql2, $entries['iuid'][$key], $entries['auid'][$key]); } //Expire rejected handshakes NFHANDSHAKE_EXPIRED $sql3 = "UPDATE {nf_handshake} SET hstatus = %d WHERE duration < %d AND hstatus = %d"; $success3 = db_query($sql3, NFHANDSHAKE_EXPIRED, time(), NFHANDSHAKE_REJECTED); } // function nf_handshake_cron() /** * Implementation of hook_form_alter. * * Intercept the removal of a CCK field from a content type and make sure we get a change to react to it. * * @param string $form_id The ID of the form we need to adjust. * @param array &$form A reference to the form to adjust so that we change the actual form. */ function nf_handshake_form_alter($form_id, &$form) { if ($form_id == '_content_admin_field_remove') { $form['#submit'] = array('nf_handshake_remove_field_submit' => array(), '_content_admin_field_remove_submit' => array()); } } // function nf_handshake_form_alter() /** * Our submit function so we can deal with removal of CCK fields from content types. * * @param sting $form_id The ID of the form to process. * @param array $form_values The fields to process. */ function nf_handshake_remove_field_submit($form_id, $form_values) { if ($form_id == '_content_admin_field_remove') { //first update references in the handshakes themselves $sql = "SELECT * FROM {nf_handshake} ORDER BY iuid"; $results = db_query($sql); while ($result = db_fetch_object($results)) { $sql2 = "UPDATE {nf_handshake} SET hfields = '%s' WHERE iuid = %d and auid = %d"; $hfields = unserialize($result->hfields); foreach ($hfields as $field => $val) {//test to see if this entry is from the affected content type $exp_val = explode('::', $field); $type_name = $exp_val[0]; $field_name = $exp_val[1]; if ($type_name == $form_values['type_name'] && $field_name == $form_values['field_name']) { unset($hfields[$field]); } } ksort($hefields); $hfields = serialize($hfields); $success = db_query($sql2, $hfields, $result->iuid, $result->auid); } //then update the variables stored in the variables table $field_names_var = _nf_handshake_get_cckfieldnames(); $group_names_var = _nf_handshake_get_groupnames(); foreach ($field_names_var as $type => $the_rest) { if ($type == $form_values['type_name']) { foreach ($the_rest as $key => $value) { if ($key == $form_values['field_name']) { unset($field_names_var[$type][$key]); } } } } ksort($field_names_var); variable_set('nf_handshake_cckfieldnames', $field_names_var); foreach ($group_names_var as $group => $the_rest) { foreach ($the_rest as $type_field1 => $type_field2) { $exp_val = explode('::', $type_field1); $type = $exp_val[0]; $field = $exp_val[1]; if ($type == $form_values['type_name'] && $field == $form_values['field_name']) { unset($group_names_var[$group][$type_field1]); } } } ksort($group_names_var); variable_set('nf_handshake_groupnames', $group_names_var); drupal_set_message(t('Handshake module has updated its references to the content type you changed.')); } return; } /** * Respond to changes in content types. * * We don't do anything upon insertion of a new content type as we don't know if the user will turn it into a nodeprofile type or not. * We must delete references to fields in content types that are deleted. We must update fields we use from content types we use if they * are changed. Since we add a capital 'X' to the end of fieldnames that are part of an upgrade request, leave them intact. * * @param string $op The operation on the node type. Possibilities are 'insert', 'delete', and 'update'. * @param object The node type object on which $op is being performed. */ function nf_handshake_node_type($op, $info) { switch ($op){ case 'delete': //first update references in the handshakes themselves $sql = "SELECT * FROM {nf_handshake} ORDER BY iuid"; $results = db_query($sql); while ($result = db_fetch_object($results)) { $hfields = array(); $sql2 = "UPDATE {nf_handshake} SET hfields = '%s' WHERE iuid = %d and auid = %d"; $hfields = unserialize($result->hfields); foreach ($hfields as $field => $val) {//test to see if this entry is from the affected content type $exp_val = explode('::', $field); $type_name = $exp_val[0]; $field_name = $exp_val[1]; if ($type_name == $info->type) { unset($hfields[$field]); } } ksort($hefields); $hfields = serialize($hfields); $success = db_query($sql2, $hfields, $result->iuid, $result->auid); } //then update the variables stored in the variables table $field_names_var = _nf_handshake_get_cckfieldnames(); $group_names_var = _nf_handshake_get_groupnames(); foreach ($field_names_var as $type => $the_rest) { if ($type == $info->type) { unset($field_names_var[$type]); } } ksort($field_names_var); variable_set('nf_handshake_cckfieldnames', $field_names_var); foreach ($group_names_var as $group => $the_rest) { foreach ($the_rest as $type_field1 => $type_field2) { $exp_val = explode('::', $type_field1); $type = $exp_val[0]; $field = $exp_val[1]; if ($type == $info->type) { unset($group_names_var[$group][$type_field1]); } } } ksort($group_names_var); variable_set('nf_handshake_groupnames', $group_names_var); drupal_set_message(t('Handshake module has updated its references to the content type you changed.')); break; case 'update': if (!empty($info->old_type) && $info->old_type != $info->type) { //first update references in the handshakes themselves $sql = "SELECT * FROM {nf_handshake} ORDER BY iuid"; $results = db_query($sql); while ($result = db_fetch_object($results)) { $sql2 = "UPDATE {nf_handshake} SET hfields = '%s' WHERE iuid = %d and auid = %d"; $hfields = unserialize($result->hfields); foreach ($hfields as $field => $val) {//test to see if this entry is from the affected content type $exp_val = explode('::', $field); $type_name = $exp_val[0]; $field_name = $exp_val[1]; if ($type_name == $info->old_type) {//switch out the old name with the new $old_type_field = $info->old_type. '::' .$field_name; $new_type_field = $info->type. '::' .$field_name; $temp_val = $hfields[$old_type_field]; unset($hfields[$old_type_field]); if ($temp_val !== 0) {//leave any 'X' values intact. $exp_val2 = explode('::', $temp_val); $hfields[$new_type_field] = $info->type. '::' .$exp_val2[1]; } else { $hfields[$new_type_field] = 0; } } } ksort($hefields); $hfields = serialize($hfields); $success = db_query($sql2, $hfields, $result->iuid, $result->auid); } //then update the variables stored in the variables table $field_names_var = _nf_handshake_get_cckfieldnames(); $group_names_var = _nf_handshake_get_groupnames(); foreach ($field_names_var as $type => $the_rest) { if ($type == $info->old_type) { $temp_data = $field_names_var[$type]; unset($field_names_var[$type]); $field_names_var[$info->type] = $temp_data; } } ksort($field_names_var); variable_set('nf_handshake_cckfieldnames', $field_names_var); foreach ($group_names_var as $group => $the_rest) { foreach ($the_rest as $type_field1 => $type_field2) { $exp_val = explode('::', $type_field1); $type = $exp_val[0]; $field = $exp_val[1]; if ($type == $info->old_type) { unset($group_names_var[$group][$type_field1]); $group_names_var[$group][$info->type. '::' .$field] = $info->type. '::' .$field; } } } ksort($group_names_var); variable_set('nf_handshake_groupnames', $group_names_var); drupal_set_message(t('Handshake module has updated its references to the content type you changed.')); } break; } } //-----------------------------------------Administrative Hooks and Functions----------------------------------------- //-----------------------------------------Administrative Hooks and Functions----------------------------------------- //-----------------------------------------Administrative Hooks and Functions----------------------------------------- /** * Callback function: Add options for the . * * @return string $output The HTML to be displayed. */ function nf_handshake_main() { $all_nodeprofiles = nodeprofile_get_types('names'); $all_groups = _nf_handshake_get_groupnames(); $selected_cck_fields = _nf_handshake_get_cckfieldnames(); ksort($selected_cck_fields); ksort($all_groups); $output = ''; $header = array(t('Content type'), t('Selected CCK fields')); if (!empty($selected_cck_fields)) { if (!empty($all_groups)) { foreach ($all_groups as $key => $val) { $rows = array(); foreach ($val as $set => $value) { $split_value = explode('::', $value); $type = $split_value[0]; $type_name = $all_nodeprofiles[$type]; $field_name = $split_value[1]; $rows[] = array('' .$type_name. '', $field_name); unset($selected_cck_fields[$type][$field_name]); if (empty($selected_cck_fields[$type])) { unset($selected_cck_fields[$type]); } } $fieldset = array( '#type' => 'fieldset', '#value' => theme('table', $header, $rows), '#title' => t('Group: ') .$key, '#description' => t('Fields that can be exchanged as equivalent.'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight' => 0, ); $output .= theme('fieldset', $fieldset); } if (!empty($selected_cck_fields)) { $rows = array(); foreach ($selected_cck_fields as $type => $set) { $type_name = $all_nodeprofiles[$type]; foreach ($set as $key => $value) { $rows[] = array('' .$type_name. '', $value); } } $output .= theme('table', $header, $rows); } } else { $rows = array(); foreach ($selected_cck_fields as $type => $set) { $type_name = $all_nodeprofiles[$type]; foreach ($set as $key => $value) { $rows[] = array('' .$type_name. '', $value); } } $output .= theme('table', $header, $rows); } } else { $output = t('You first need to select CCK fields that users can share, then make groups of those fields if you wish.'); } return $output; } // function nf_handshake_main() /** * Present the admin with a drop down of nodeprofile-related cck fields and allow him/her to select those that users may share. * * @return array $form The form to be rendered. */ function nf_handshake_choose_cck_fields() { $all_cck_fields = array(); $all_nodeprofiles = nodeprofile_get_types('names'); ksort($all_nodeprofiles); $added_cck_fields = _nf_handshake_get_cckfieldnames(); $sql = "SELECT type_name, field_name FROM {node_field_instance} WHERE type_name = '%s' ORDER BY field_name"; foreach ($all_nodeprofiles as $key => $value) { $results = db_query($sql, $key); while ($result = db_fetch_object($results)) { if (!(key_exists($result->type_name, $added_cck_fields) && key_exists($result->field_name, $added_cck_fields[$result->type_name]))) { $all_cck_fields[$value][$result->type_name. '::' .$result->field_name] = $result->field_name; } } } $form['cck_fields'] = array( '#type' => 'select', '#title' => t('Add profile-related CCK fields'), '#options' => $all_cck_fields, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Add CCK field'), ); $form['options'] = array( '#type' => 'value', '#value' => $all_cck_fields, ); $form['info'] = array( '#type' => 'item', '#value' => t('Select the CCK fields that you would like to allow users to share with each other.'), ); return $form; } // function nf_handshake_choose_cck_fields() /** * Submit the table name to be saved to the table list. * * @param string $form_id * @param mixed $form_values * @return string The path to send the user to. */ function nf_handshake_choose_cck_fields_submit($form_id, $form_values) { if ($form_values['op'] == t('Add CCK field')) { $selection = explode('::', $form_values['cck_fields']); $added_cck_fields = _nf_handshake_get_cckfieldnames(); $added_cck_fields[$selection[0]][$selection[1]] = $selection[1]; variable_set('nf_handshake_cckfieldnames', $added_cck_fields); drupal_set_message(t('The CCK field list has been updated.')); } return 'admin/user/nf_handshake/choose_cck_fields'; } // function nf_handshake_choose_cck_fields_submit() /** * Theme for the cck field chooser. * * @param array $form The form to render. * @return string $output The HTML to be displayed. */ function theme_nf_handshake_choose_cck_fields($form) { $all_nodeprofiles = nodeprofile_get_types('names'); $header = array(t('Content type'), array('data' => t('Selected CCK fields'), 'colspan' => 2)); $selected_cck_fields = _nf_handshake_get_cckfieldnames(); ksort($selected_cck_fields); $rows = array(); if (!empty($selected_cck_fields)) { foreach ($selected_cck_fields as $type => $set) { $type_name = $all_nodeprofiles[$type]; foreach ($set as $key => $value) { $delete = l(t('delete'), 'admin/user/nf_handshake/delete_cck_fields/' .$type. '::' .$value); $rows[] = array('' .$type_name. '', $value, $delete); } } } $rows[] = array(drupal_render($form['cck_fields']), drupal_render($form['submit']), ''); $output = drupal_render($form['info']); $output .= theme('table', $header, $rows); $output .= drupal_render($form); return $output; } //function theme_nf_handshake_choose_cck_fields() /** * Returns a confirmation page for deleting a cck field from the list (not the actual field). * * @param integer $name Name of cck field to be deleted; passed in from path. * @return array $form The name is passed to the submit. */ function nf_handshake_confirm_cck_fields_delete($name = NULL) { if ($name == NULL) { drupal_goto('admin/user/nf_handshake/choose_cck_fields'); return; } if ($admin = user_access('administer handshakes')) { $type_and_field = explode('::', $name); $form['type'] = array( '#type' => 'value', '#value' => $type_and_field[0], ); $form['name'] = array( '#type' => 'value', '#value' => $type_and_field[1], ); $return_address = 'admin/user/nf_handshake/choose_cck_fields'; $form = confirm_form($form, t('Are you sure you want to delete the CCK field %name from the admin list?', array('%name' => $type_and_field[1])), $return_address, t('Deleting a CCK field from the list here will not delete the actual field. This action cannot be undone.'), t('Delete'), t('Cancel')); return $form; } } // function nf_handshake_confirm_cck_fields_delete() /** * Implementation of forms api _submit call. Deletes a cck field from the variable list after confirmation. * * @param string $form_id * @param mixed $form_values * @return string $return_address The path to return to after we've deleted the table. */ function nf_handshake_confirm_cck_fields_delete_submit($form_id, $form_values) { $added_cck_fields = _nf_handshake_get_cckfieldnames(); unset($added_cck_fields[$form_values['type']][$form_values['name']]); if (empty($added_cck_fields[$form_values['type']])) { unset($added_cck_fields[$form_values['type']]); } variable_set('nf_handshake_cckfieldnames', $added_cck_fields); if (!isset($added_cck_fields[$form_values['name']][$form_values['name']])) { drupal_set_message(t('The cck field %name has been removed from the administration list.', array('%name' => $form_values['name']))); watchdog('nf_handshake', t('nf_handshake: deleted %name from nf_handshake_cckfieldnames list.', array('%name' => $form_values['name']))); } $return_address = 'admin/user/nf_handshake/choose_cck_fields'; return $return_address; } // function nf_handshake_confirm_cck_fields_delete_submit() /** * Allow the admin to group fields together. * * If there are two fields that are related that may * not be in common between two nodeprofile sets, but which users should be able to share, they can be grouped together. For example, say * that nodeprofile A is set up for businesses and nodeprofile B is set up for customers and they each have addresses in their profile nodes, * but in a different format; without groupings, you would have to name one address field with one name and the other address field with another name. * Users would check the box stating they want to share their address with the other user, but would be unable to because the second user's field * had a different name. By grouping them together, an association is made such that this problem is overcome. * * @return array $form The form to be rendered. */ function nf_handshake_make_groupings() { $all_groups = _nf_handshake_get_groupnames(); $added_cck_fields = _nf_handshake_get_cckfieldnames(); $form['note'] = array( '#type' => 'item', '#title' => t('Group similar fields together'), '#description' => t('This allows you to group logical fields together for exchange as a group. See the README for details.'), ); $not_field_options = array(); foreach ($all_groups as $group => $types) { if (!empty($types)) { foreach ($types as $type => $field) { $not_field_options[$type] = $field; } } } $all_nodeprofiles = nodeprofile_get_types('names'); foreach ($added_cck_fields as $type => $the_rest) { if (!empty($the_rest)) { foreach ($the_rest as $field => $val) { if (!key_exists($type. '::' .$val, $not_field_options)) { $field_options[$type. '::' .$val] = $all_nodeprofiles[$type]. '::' .$val; } } } } if (empty($field_options)) { $field_options = array(); } foreach ($all_groups as $group => $types) { $form[$group] = array( '#tree' => TRUE, ); $form[$group]['new_field'] = array( '#type' => 'select', '#title' => t('fields'), '#options' => $field_options, '#default' => NULL, ); $form[$group]['submit'] = array( '#type' => 'submit', '#value' => t('Add fieldname to ') .$group, ); } $form['groupname'] = array( '#type' => 'textfield', '#size' => 20, '#maxlength' => 64, ); $form['gsubmit'] = array( '#type' => 'submit', '#value' => t('Add group'), ); return $form; } // function nf_handshake_make_groupings() /** * Submit the group name and any field associations. * * @param string $form_id * @param mixed $form_values * @return string The path to send the user to. */ function nf_handshake_make_groupings_submit($form_id, $form_values) { if ($form_values['op'] == t('Add group')) { $all_groups = _nf_handshake_get_groupnames(); $all_groups[$form_values['groupname']] = array(); variable_set('nf_handshake_groupnames', $all_groups); drupal_set_message(t('The group name has been added.')); } else { $op = substr($form_values['op'], 17); $all_groups = _nf_handshake_get_groupnames(); if (!in_array($form_values[$op]['new_field'], $all_groups[$op])) { $all_groups[$op][$form_values[$op]['new_field']] = $form_values[$op]['new_field']; } ksort($all_groups[$op]); variable_set('nf_handshake_groupnames', $all_groups); drupal_set_message(t('The group list has been updated.')); } return 'admin/user/nf_handshake/make_grouping'; } // function nf_handshake_make_groupings_submit() /** * Theme for the group maker. * *

The purpose of groups was explained elsewhere. Here we add new groups via a textfield and associated button. Groups are presented as fieldsets * and fields can be added to them. Also, the groups can be deleted. Fields not in a group are in the 'no_group' group.

* @param array $form The form to render. * @return string $output The HTML to render the page. */ function theme_nf_handshake_make_groupings($form) { $output = ''; $output_array = array(); $all_groups = _nf_handshake_get_groupnames(); $all_nodeprofiles = nodeprofile_get_types('names'); $header = array(array('data' => t('Selected fieldnames'), 'colspan' => 2)); $output .= drupal_render($form['note']); if (!empty($all_groups)) { foreach ($all_groups as $group => $name) { $rows = array(); if (!empty($name)) { foreach ($name as $key => $value) { $exp_val = explode('::', $value); $type = $exp_val[0]; $val = $exp_val[1]; $delete = l(t('delete'), 'admin/user/nf_handshake/delete_group/' .$group. '/' .$value); $rows[] = array($all_nodeprofiles[$type]. '::' .$val, $delete); } } $edit = l(t('edit group'), 'admin/user/nf_handshake/edit_group/' .$group); $delete = l(t('delete group'), 'admin/user/nf_handshake/delete_group/' .$group); $rows[] = array($edit, $delete); if ($form[$group]['new_field']['#options'] == array()) { unset($form[$group]['new_field']); unset($form[$group]['submit']); } else { $rows[] = array(drupal_render($form[$group]['new_field']), drupal_render($form[$group]['submit'])); } $fieldset = array( '#type' => 'fieldset', '#value' => theme('table', $header, $rows), '#title' => t('Group: ') .$group, '#description' => t('Place fields into this group that should be exchanged together.'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 0, ); $output_array[] = theme('fieldset', $fieldset); } ksort($output_array); foreach ($output_array as $out) { $output .= $out; } } $last_row[] = array(drupal_render($form['groupname']), drupal_render($form['gsubmit'])); $output .= theme('table', array(), $last_row); $output .= drupal_render($form); return $output; } //function theme_nf_handshake_make_groupings() /** * Edit the group name * * @param string $name The group to edit * @return mixed Blank if no group name specified, $form if specified */ function nf_handshake_group_edit($name = NULL) { if ($name == NULL) { drupal_goto('admin/user/nf_handshake/make_grouping'); return; } if ($admin = user_access('administer handshakes')) { $added_groups = _nf_handshake_get_groupnames(); $form['name'] = array( '#type' => 'textfield', '#title' => t('Group name'), '#default_value' => $name, '#size' => 20, '#required' => TRUE, '#maxlength' => 64, ); $form['old_name'] = array( '#type' => 'value', '#value' => $name, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save group name'), ); return $form; } } // function nf_handshake_group_edit() /** * Validate the group name before saving it * * @param string $form_id * @param mixed $form_values */ function nf_handshake_group_edit_validate($form_id, $form_values) { if ($form_values['name']) { if ($form_values['op'] == t('Save group name')) { if (!$form_values['name']) { form_set_error('name', t('You must specify a valid group name.')); } } } else { form_set_error('name', t('You must specify a valid group name.')); } } // function nf_handshake_group_edit_validate() /** * Submit the group name to be saved, to the variable. * * @param string $form_id * @param mixed $form_values * @return string The path to send the user to. */ function nf_handshake_group_edit_submit($form_id, $form_values) { if ($form_values['op'] == t('Save group name')) { $check_options = _nf_handshake_get_groupnames(); $temp_group = $check_options[$form_values['old_name']]; unset($check_options[$form_values['old_name']]); $check_options[$form_values['name']] = $temp_group; variable_set('nf_handshake_groupnames', $check_options); drupal_set_message(t('The group name and associated fields have been updated.')); $sql = "SELECT * FROM {nf_handshake} ORDER BY iuid"; $results = db_query($sql); while ($result = db_fetch_object($results)) { $sql2 = "UPDATE {nf_handshake} SET hfields = '%s' WHERE iuid = %d and auid = %d"; $hfields = unserialize($result->hfields); $temp_val = $hfields[$form_values['old_name']]; unset($hfields[$form_values['old_name']]); if ($temp_val === 0) { $hfields[$form_values['name']] = $temp_val; } else { $hfields[$form_values['name']] = $form_values['name']; } $hfields = serialize($hfields); $success = db_query($sql2, $hfields, $result->iuid, $result->auid); } } return 'admin/user/nf_handshake/make_grouping'; } // function nf_handshake_group_edit_submit() /** * Returns a confirmation page for deleting a group from the list or field from a group (not the underlying fields and data). * * @param integer $name Name of field to be deleted; passed in from path. * @return array $form The name is passed to the submit. */ function nf_handshake_confirm_group_delete($group = NULL, $name = NULL) { if ($name == NULL && $group == NULL) { drupal_goto('admin/user/nf_handshake/make_grouping'); return; } if ($admin = user_access('administer handshakes')) { if ($name != NULL) { $form['group'] = array( '#type' => 'value', '#value' => $group, ); $form['name'] = array( '#type' => 'value', '#value' => $name, ); $return_address = 'admin/user/nf_handshake/make_grouping'; $form = confirm_form($form, t('Are you sure you want to delete the field %name from the group admin list?', array('%name' => $name)), $return_address, t('Deleting a field from the group list here will not delete the field, nor the underlying data. This action cannot be undone.'), t('Delete'), t('Cancel')); return $form; } else { $form['group'] = array( '#type' => 'value', '#value' => $group, ); $return_address = 'admin/user/nf_handshake/make_grouping'; $form = confirm_form($form, t('Are you sure you want to delete the group %name from the admin list?', array('%name' => $group)), $return_address, t('Deleting a group from the list here will not delete the underlying fields nor their data, just the associations this group created. This action cannot be undone.'), t('Delete'), t('Cancel')); return $form; } } } // function nf_handshake_confirm_group_delete() /** * Implementation of forms api _submit call. Deletes a group from the variable list after confirmation. * * @param string $form_id * @param mixed $form_values * @return string $return_address The path to return to after we've deleted the group. */ function nf_handshake_confirm_group_delete_submit($form_id, $form_values) { $added_groups = _nf_handshake_get_groupnames(); if (isset($form_values['name'])) { unset($added_groups[$form_values['group']][$form_values['name']]); variable_set('nf_handshake_groupnames', $added_groups); if (!isset($added_groups[$form_values['group']][$form_values['name']])) { drupal_set_message(t('The group %name has been removed from the administration list.', array('%name' => $form_values['name']))); watchdog('nf_handshake', t('nf_handshake: deleted %name from nf_handshake_groupnames list.', array('%name' => $form_values['name']))); } } else { unset($added_groups[$form_values['group']]); variable_set('nf_handshake_groupnames', $added_groups); if (!isset($added_groups[$form_values['group']])) { drupal_set_message(t('The group %name has been removed from the administration list.', array('%name' => $form_values['group']))); watchdog('nf_handshake', t('nf_handshake: deleted %name from nf_handshake_groupnames list.', array('%name' => $form_values['group']))); } } return 'admin/user/nf_handshake/make_grouping'; } // function nf_handshake_confirm_group_delete_submit() /** * This is for general settings that don't fit elsewhere. * * There are two time/expiration settings. One is for how long a handshake request can be waiting for a user response before it expires. * The second is for how long a rejected handshake will remain in the database; this allows the person who rejected it to change their mind * and later accept it; it also prevents the original handshake initiator from sending a new handshake request until the time has passed. */ function nf_handshake_settings() { $values = variable_get('nf_handshake_settings', array()); $form['settings'] = array( '#tree' => TRUE, ); $form['settings']['initiate_expire'] = array( '#type' => 'fieldset', '#title' => t('Initiation expiration'), '#description' => t('The time a user has to respond to a handshake request before it expires. The initiator will be able to send a new request after expiration.'), ); $form['settings']['initiate_expire']['unit'] = array( '#type' => 'select', '#title' => t('Time unit'), '#default_value' => isset($values['initiate_expire_unit']) ? $values['initiate_expire_unit'] : 'Weeks', '#options' => array('Days' => 'Days', 'Weeks' => 'Weeks', 'Months' => 'Months', 'Years' => 'Years'), ); $form['settings']['initiate_expire']['number'] = array( '#type' => 'select', '#default_value' => isset($values['initiate_expire_number']) ? $values['initiate_expire_number'] : 1, '#options' => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31), ); $form['settings']['reject_expire'] = array( '#type' => 'fieldset', '#title' => t('Rejection expiration'), '#description' => t('The time a user has to reaccept a handshake request after they have revoked it. The other user will not be able to send a new request until this expiration period passes.'), ); $form['settings']['reject_expire']['unit'] = array( '#type' => 'select', '#title' => t('Time unit'), '#default_value' => isset($values['reject_expire_unit']) ? $values['reject_expire_unit'] : 'Months', '#options' => array('Days' => 'Days', 'Weeks' => 'Weeks', 'Months' => 'Months', 'Years' => 'Years'), ); $form['settings']['reject_expire']['number'] = array( '#type' => 'select', '#default_value' => isset($values['reject_expire_number']) ? $values['reject_expire_number'] : 6, '#options' => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31), ); $form['settings']['no_admin'] = array( '#type' => 'checkbox', '#title' => t('Exclude user 1 from handshakes'), '#default_value' => 1, '#description' => t('This prevents users from making a handshake with the administrator. They may contact the admin via the site\'s contact form.') ); $form['settings']['no_admin_role'] = array( '#type' => 'checkbox', '#title' => t('Exclude users with the administer handshakes role from handshakes'), '#default_value' => 1, '#description' => t('This prevents users from making a handshake with administrators that are not user 1. This would occur in the case where the site is able to employ additional help and/or when the site is run by someone other than the person that sets things up. Users with this permission and this box checked are assumed to not interact with other users as a normal user. If that is not the case, you may want to create two accounts for that user - a regular, and an administrative. Users may contact the admin via the site\'s contact form.') ); $form['settings']['submit'] = array( '#type' => 'submit', '#value' => t('Save settings'), ); $form['settings']['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); return $form; } // function nf_handshake_settings() /** * Store the settings from the admin. * * @param string $form_id * @param array $form_values * @return string The path to go to afterwards. */ function nf_handshake_settings_submit($form_id, $form_values) { $values = array('initiate_expire_unit' => $form_values['settings']['initiate_expire']['unit'], 'initiate_expire_number' => $form_values['settings']['initiate_expire']['number'], 'reject_expire_unit' => $form_values['settings']['reject_expire']['unit'], 'reject_expire_number' => $form_values['settings']['reject_expire']['number'], 'no_admin' => $form_values['settings']['no_admin'], 'no_admin_role' => $form_values['settings']['no_admin_role'],); variable_set('nf_handshake_settings', $values); return 'admin/user/nf_handshake/settings'; } // function nf_handshake_settings_submit() /** * Present an overview of the flags that need administering. */ function nf_handshake_flags() { $output = ''; $all_flags = nf_handshake_get_user_flags(); $header = array(array('data' => t('IUser'), 'field' => 'iuid'), array('data' => t('AUser'), 'field' => 'auid'), array('data' => t('Purpose'), 'field' => 'purpose'), array('data' => t('Flag'), 'field' => 'flags', 'sort' => 'asc'), array('data' => t('Explanation'), 'field' => 'userflagexplain'), t('Operations')); $rows = array(); $sql = "SELECT nh.*, nhm.purpose, nhm.userflagexplain FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE flags <> %d AND adminflag = %d OR adminflag = %d OR adminflag = %d OR adminflag = %d ORDER BY flags"; if ($results = db_query($sql, NFHANDSHAKE_NONE, NFHANDSHAKE_NONE, NFHANDSHAKE_FURTHER_REVIEW, NFHANDSHAKE_IUID_COMMENT, NFHANDSHAKE_AUID_COMMENT)) { while ($result = db_fetch_object($results)) { //PHP4 Modified: $iusername = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $result->iuid)); $iusername = $iusername->name; $ausername = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $result->auid)); $ausername = $ausername->name; $view = l(t('view'), 'admin/user/nf_handshake_flags/view/' .$result->iuid. '/' .$result->auid); $rows[] = array(array('data' => $iusername), array('data' => $ausername), array('data' => $result->purpose), array('data' => $all_flags[$result->flags]), array('data' => $result->userflagexplain), array('data' => $view)); } } else { $rows[] = t('There are no outstanding flags at this time.'); } $output = theme('table', $header, $rows); return $output; } // function nf_handshake_flags() /** * Show a single flag case. Allow the admin to make notes and determine the next course of action. * * @param int $iuid The initiator's UID * @param int $auid The acceptor's (reciever's) UID * @return array $form The form to render */ function nf_handshake_view_flag($iuid = NULL, $auid = NULL) {//TODO cron jobs for each admin flag applied? $all_flags = nf_handshake_get_user_flags(); $sql = "SELECT nh.*, nhm.* FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE nh.iuid = %d AND nh.auid = %d"; $result = db_fetch_object(db_query($sql, $iuid, $auid)); $form['user_flag'] = array( '#tree' => TRUE, ); $form['user_flag']['iuid'] = array( '#type' => 'value', '#value' => $iuid, ); $form['user_flag']['auid'] = array( '#type' => 'value', '#value' => $auid, ); $form['user_flag']['datestamp'] = array( '#type' => 'item', '#title' => t('Date initiated'), '#value' => date('M j Y', $result->datestamp), ); $form['user_flag']['duration'] = array( '#type' => 'item', '#title' => t('Expiration'), '#value' => date('M j Y', $result->duration), ); $form['user_flag']['initial'] = array( '#type' => 'item', '#title' => t('Initial admin date'), '#value' => ($result->initialdate == 0) ? date('M j Y', time()) : date('M j Y', $result->initialdate),//test this ); $form['user_flag']['time'] = array( '#type' => 'value', '#value' => ($result->initialdate == 0) ? time() : $result->initialdate, ); $form['user_flag']['purpose'] = array( '#type' => 'item', '#title' => t('Purpose'), '#value' => $result->purpose, ); $form['user_flag']['flag'] = array( '#type' => 'item', '#title' => t('User flag'), '#value' => $all_flags[$result->userflag], ); $form['user_flag']['flag_explain'] = array( '#type' => 'item', '#title' => t('User flag explanation'), '#value' => $result->userflagexplain, ); $form['user_flag']['admin_flag'] = array( '#type' => 'select', '#title' => t('Admin flag'), '#description' => t('Select the flag to be applied'), '#default_value' => 10, '#options' => nf_handshake_get_admin_flags(), ); if (!$admin_notes = unserialize($result->adminnotes)) { $admin_notes = array(); } if (!$iuid_notes = unserialize($result->iuidmessages)) { $iuid_notes = array(); } if (!$auid_notes = unserialize($result->auidmessages)) { $auid_notes = array(); } $form['user_flag']['admin_notes'] = array( '#type' => 'value', '#value' => $admin_notes, ); $form['user_flag']['new_admin_note'] = array( '#type' => 'textarea', '#title' => t('Add a comment'), '#description' => t('Add additional comments here. They will be added to others made.'), ); $form['user_flag']['iuid_notes'] = array( '#type' => 'value', '#value' => $iuid_notes, ); $form['user_flag']['auid_notes'] = array( '#type' => 'value', '#value' => $auid_notes, ); $all_notes = $admin_notes + $iuid_notes + $auid_notes; ksort($all_notes); $form['user_flag']['all_notes'] = array( '#type' => 'value', '#value' => $all_notes, ); $form['user_flag']['submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); $form['user_flag']['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); return $form; } // function nf_handshake_view_flag() /** * Save the new data with the old. * * @param string $form_id * @param array $form_values * @return string */ function nf_handshake_view_flag_submit($form_id, $form_values) { global $user; if (!user_access('administer handshakes')) { return ''; } switch ($form_values['op']) { case t('Save'): $all_admin_flags = nf_handshake_get_admin_flags(); $flag_text = $all_admin_flags[$form_values['user_flag']['admin_flag']]; $flag = $form_values['user_flag']['admin_flag']; $current_datestamp = time(); $initial_datestamp = $form_values['user_flag']['time']; $message = $flag_text. ': ' .$form_values['user_flag']['new_admin_note']; $all_admin_notes = $form_values['user_flag']['admin_notes']; $all_admin_notes[$current_datestamp] = array($user->uid => $message); $all_admin_notes = serialize($all_admin_notes); $sql = "UPDATE {nf_handshake_manage} SET adminflag = %d, initialdate = %d, adminnotes = '%s' WHERE iuid = %d and auid = %d"; if (!$success = db_query($sql, $flag, $initial_datestamp, $all_admin_notes, $form_values['user_flag']['iuid'], $form_values['user_flag']['auid'])) { drupal_set_message('Updating nf_handshake_manage table failed. Logging...', 'error'); watchdog('nf_handshake', t('Unable to update nf_handshake_manage for iuid = %iuid and auid = %auid', array('%iuid' => $form_values['user_flag']['iuid'], '%auid' => $form_values['user_flag']['auid'])), WATCHDOG_ERROR); } if ($form_values['user_flag']['admin_flag'] == NFHANDSHAKE_NONE) { $sql2 = "UPDATE {nf_handshake} SET hstatus = %d, flags = %d WHERE iuid = %d and auid = %d"; if (!$success = db_query($sql2, NFHANDSHAKE_PENDING, NFHANDSHAKE_NONE, $form_values['user_flag']['iuid'], $form_values['user_flag']['auid'])) { drupal_set_message('Updating nf_handshake table failed. Logging...', 'error'); watchdog('nf_handshake', t('Unable to update nf_handshake for iuid = %iuid and auid = %auid', array('%iuid' => $form_values['user_flag']['iuid'], '%auid' => $form_values['user_flag']['auid'])), WATCHDOG_ERROR); } } break; case t('Cancel'): break; } return 'admin/user/nf_handshake_flags'; } // function nf_handshake_view_flag_submit() /** * Present the form in a more usable manner. * * Display all data regarding the handshake including a table of all notes. Note that the UIDs that are not the parties involved will be * admins. * TODO maybe color rows depending on UID or IUID/AUID/Admin * @param array $form The form to be rendered. * @return string $output The HTML version of everything to render. */ function theme_nf_handshake_view_flag($form) { $output = ''; $rows = array(); $header = array(t('Datestamp'), t('UID'), t('Message')); $fake_rows = array(); $fake_header = array(); //PHP4 Modified: $iusername = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $form['user_flag']['iuid']['#value'])); $iusername = $iusername->name; $ausername = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $form['user_flag']['auid']['#value'])); $ausername = $ausername->name; $fake_rows[] = array('IUser: ' .$iusername, 'AUser: ' .$ausername, drupal_render($form['user_flag']['datestamp']), drupal_render($form['user_flag']['duration']), drupal_render($form['user_flag']['initial']), ); $output .= theme('table', $fake_header, $fake_rows); $output .= drupal_render($form['user_flag']['purpose']); $output .= drupal_render($form['user_flag']['flag']); $output .= drupal_render($form['user_flag']['flag_explain']); foreach ($form['user_flag']['all_notes']['#value'] as $date => $the_rest) { $the_date = date('M j Y - G:i:s A', $date); foreach ($the_rest as $uid => $message) { $rows[] = array($the_date, $uid, $message); } } if (empty($rows)) { $rows[] = array(t('No messages previously entered')); } $output .= theme('table', $header, $rows); $output .= drupal_render($form); return $output; } // function theme_nf_handshake_view_flag() /** * Present an overview of the flags that have been administered and a decision arrived at. */ function nf_handshake_flag_decisions() { $output = ''; $all_flags = nf_handshake_get_user_flags(); $all_admin_flags = nf_handshake_get_admin_flags(); $header = array(array('data' => t('IUser'), 'field' => 'iuid'), array('data' => t('AUser'), 'field' => 'auid'), array('data' => t('Purpose'), 'field' => 'purpose'), array('data' => t('Flag'), 'field' => 'flags', 'sort' => 'asc'), array('data' => t('Explanation'), 'field' => 'userflagexplain'), array('data' => t('Decision'), 'field' => 'adminflag'), t('Operations')); $rows = array(); $sql = "SELECT nh.*, nhm.adminflag, nhm.purpose, nhm.userflagexplain FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE nh.flags <> %d AND nhm.adminflag = %d OR nhm.adminflag = %d OR nhm.adminflag = %d OR nhm.adminflag = %d OR nhm.adminflag = %d ORDER BY nh.flags"; if ($results = db_query($sql, NFHANDSHAKE_NONE, NFHANDSHAKE_VIOLATION_OF_TS, NFHANDSHAKE_WARNING_1, NFHANDSHAKE_WARNING_2, NFHANDSHAKE_SUSPEND_USER, NFHANDSHAKE_ALERT_PARENTS)) { while ($result = db_fetch_object($results)) { //PHP4 Modified: $iusername = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $result->iuid)); $iusername = $iusername->name; $ausername = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $result->auid)); $ausername = $iusername->name; $view = l(t('view'), 'admin/user/nf_handshake_flags/view/' .$result->iuid. '/' .$result->auid); $rows[] = array(array('data' => $iusername), array('data' => $ausername), array('data' => $result->purpose), array('data' => $all_flags[$result->flags]), array('data' => $result->userflagexplain), array('data' => $all_admin_flags[$result->adminflag]), array('data' => $view)); } } else { $rows[] = t('There are no flags with decisions at this time.'); } $output = theme('table', $header, $rows); return $output; } // function nf_handshake_flag_decisions() //-----------------------------------------Worker Hooks and Functions----------------------------------------- //-----------------------------------------Worker Hooks and Functions----------------------------------------- //-----------------------------------------Worker Hooks and Functions----------------------------------------- //-----------------------------------------Initiate a handshake----------------------------------------- /** * Replace the standard call to user_view (see menu item above). * * 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. * Otherwise, check if the current user has previously shaken hands with the user whose profile he's trying to * view. If so and it was accepted, present the exposed data. If so and it the request is pending or some other * intermediate condition exists, show what that condition is. If no handshake has been made, present the user * with a form to request a handshake from the other user. * * Note: usernames are always shown. * @param integer $uid The user id of the profile to be seen. * $return mixed Call various functions depending... */ function nf_handshake_view_user($uid = 0) { global $user; if ($user->uid == 1 || $user->uid == $uid || user_access('administer users')) { return user_view($uid); } else { $sql = "SELECT * FROM {nf_handshake} WHERE (auid = %d AND iuid = %d) OR (auid = %d AND iuid = %d)"; $result = db_fetch_object(db_query($sql, $uid, $user->uid, $user->uid, $uid)); //if we have shaken hands with this person, show exposed fields - make sure there isn't a rejection, pending, expired, reviewed, or flagged status if ($result && (($result->hstatus == NFHANDSHAKE_ACCEPTED) || ($result->hstatus == NFHANDSHAKE_UPGRADE_REQUESTED) || (($result->hstatus == NFHANDSHAKE_EXTENSION_REQUESTED) && (time() < $result->duration)))) { return nf_handshake_view_user_data($uid); } //if we get a hit, but it isn't accepted elseif ($result && $result->hstatus != NFHANDSHAKE_ACCEPTED) { if ($result->hstatus == NFHANDSHAKE_EXPIRED) { //if handshake expired, both parties can try again return drupal_get_form('nf_handshake_initiate_or_contact', $user->uid, $uid); } elseif ($result->hstatus == NFHANDSHAKE_REJECTED && $result->auid == $user->uid) { //give auid a chance to change their mind in the case where they rejected a handshake return drupal_goto('user/' .$user->uid. '/nf_handshake/view_hsr/' .$result->iuid); } else { return nf_handshake_view_denied($result->hstatus, $uid); } } //otherwise, show handshake request form else { return drupal_get_form('nf_handshake_initiate_or_contact', $user->uid, $uid); } } } // function nf_handshake_view_user() /** * The user hasn't shaken hands with the user yet, ask whether they want to, or if they'd rather just send a message. * * @param int $from The user ID of the initiator. * @param int $to The user ID of the person that will accept or reject it. * @return array $form The form to be rendered. */ function nf_handshake_initiate_or_contact($from = 0, $to = 0) { $other_user = user_load(array('uid' => $to)); if ((module_exists('privatemsg') && $other_user->privatemsg_allow == 1) || (module_exists('contact') && $other_user->contact == 1)) { $allows_contact = 1; } $settings = variable_get('nf_handshake_settings', array()); $no_admin = $settings['no_admin']; $no_admin_role = $settings['no_admin_role']; //TODO show link for popup that explains what a handshake is if (($to == 1 && $no_admin == 1) || ($no_admin_role == 1 && user_access('administer handshakes', $other_user))) { $form['info'] = array( '#type' => 'item', '#value' => t('You are trying to view the profile of a system administrator. The profile does not exist. You may contact the administrator via the contact button below.'), ); } else { $form['info'] = array( '#type' => 'item', '#value' => t('You are trying to view the profile for someone you have not yet "shaken hands" with. Would you like to initiate a handshake or just send them a private message?'), ); $form['initiate'] = array( '#type' => 'submit', '#value' => t('Shake hands'), ); } if ($allows_contact) { $form['contact'] = array( '#type' => 'submit', '#value' => t('Private message'), ); } $form['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); $form['from'] = array( '#type' => 'value', '#value' => $from, ); $form['to'] = array( '#type' => 'value', '#value' => $to, ); return $form; } // function nf_handshake_initiate_or_contact() /** * Once the user has decided what to do, route them to the proper place. * * TODO maybe replace privatemsg with our own version and make it the first elseif... * * @param string $form_id * @param array $form_values * @return string The path to send the user to. */ function nf_handshake_initiate_or_contact_submit($form_id, $form_values) { if ($form_values['op'] == t('Shake hands')) { return 'user/nf_handshake/initiate/' .$form_values['from']. '/' .$form_values['to']; } elseif ($form_values['op'] == t('Private message')) { if (module_exists('privatemsg')) { return 'privatemsg/msgto/' .$form_values['to']; } elseif (module_exists('contact')) { return 'user/' .$form_values['to']. '/contact'; } } elseif ($form_values['op'] == t('Cancel')) { return ''; } } // function nf_handshake_initiate_or_contact_submit() /** * Present a form so that a user can initiate a new handshake. * * @param int $from The user ID of the initiator. * @param int $to The user ID of the person that will accept or reject it. * @return array $form The form to be rendered. */ function nf_handshake_initiate($from = 0, $to = 0, $upgrade = NULL) { global $user; //check for expired handshake; if found, delete it so we can continue; CRON sets the hstatus to 'expired' $sql = "SELECT * FROM {nf_handshake} WHERE (auid = %d AND iuid = %d) OR (auid = %d AND iuid = %d) AND hstatus = %d"; $result = db_fetch_object(db_query($sql, $uid, $user->uid, $user->uid, $uid, NFHANDSHAKE_EXPIRED)); if ($result) { $sql = "DELETE FROM {nf_handshake} WHERE auid = %d AND iuid = %d"; db_query($sql, $result->auid, $result->iuid); } //if user ID doesn't make sense... if ($user->uid != $from) { drupal_set_message(t('You are trying to initiate or upgrade a handshake while posing as someone else. The administrator has been notified.'), 'error'); watchdog('nf_handshake', t('User %user tried to initiate a handshake posing as another user.', array('%user' => $user->uid)), WATCHDOG_WARNING); return drupal_goto(''); } $form['handshake'] = array( '#tree' => TRUE, ); $form['handshake']['from'] = array( '#type' => 'value', '#value' => $from, ); $form['handshake']['to'] = array( '#type' => 'value', '#value' => $to, ); $form['handshake']['upgrade'] = array( '#type' => 'value', '#value' => $upgrade, ); if ($upgrade == 1) { $sql = "SELECT nh.*, nhm.purpose FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE nh.auid = %d AND nh.iuid = %d AND hstatus = %d"; if (!$request = db_fetch_object(db_query($sql, $to, $from, NFHANDSHAKE_ACCEPTED))) { if (!$request = db_fetch_object(db_query($sql, $from, $to, NFHANDSHAKE_ACCEPTED))) { drupal_set_message(t('No valid handshake found. You cannot upgrade a handshake which either does not exist, already has an upgrade request or has not been accepted.'), 'error'); return drupal_goto('user/' .$user->uid. '/nf_handshake/inbox'); } } drupal_set_title('Upgrade handshake'); $form['handshake']['purpose'] = array( '#type' => 'textarea', '#title' => t('Purpose'), '#required' => TRUE, '#description' => t('Write your reason for the handshake upgrade - why should the other person accept it?'), '#cols' => 25, '#rows' => 5, ); } else { $form['handshake']['purpose'] = array( '#type' => 'textarea', '#title' => t('Purpose'), '#required' => TRUE, '#description' => t('Write your reason for the handshake - why should the other person accept it?'), '#cols' => 25, '#rows' => 5, ); } $groups = _nf_handshake_get_groupnames(); $fields = _nf_handshake_get_cckfieldnames(); $not_options = array(); $options = array(); foreach ($groups as $group => $the_rest) { if (!empty($group)) { $options[$group] = $group; foreach ($the_rest as $key => $value) { $not_options[$key] = $value; } } } foreach ($fields as $type => $the_rest) { if (!empty($the_rest)) { foreach ($the_rest as $field => $val) { if (!key_exists($type. '::' .$val, $not_options)) { $val2 = substr($val, 6); $val2 = ucfirst($val2); $options[$type. '::' .$val] = $val2; } } } } if ($upgrade == 1) { $form['request'] = array( '#tree' => TRUE, ); //also get the existing handshake items $used_fields = unserialize($request->hfields); foreach ($used_fields as $key => $value) { if ($value !== 0) { $form['request']['fields'][$key] = array( '#type' => 'value', '#value' => $value, ); } } } $form['handshake']['fields'] = array( '#type' => 'fieldset', '#title' => t('Select fields to share'), '#collapsible' => FALSE, '#collapsed' => FALSE, '#required' => TRUE, ); if ($upgrade == 1) { $form['handshake']['fields']['#title'] = t('Select fields to share'); } foreach ($options as $key => $value) { $form['handshake']['fields'][$key] = array( '#type' => 'checkbox', '#title' => $value, '#return_value' => $key, '#attributes' => array(), ); if ($upgrade == 1 && isset($form['request']['fields'][$key])) { $form['handshake']['fields'][$key]['#default_value'] = $form['request']['fields'][$key]['#value']; if ($form['request']['fields'][$key]['#value'] !== 0) { $form['handshake']['fields'][$key]['#disabled'] = TRUE; $form['handshake']['fields'][$key]['#value'] = $form['request']['fields'][$key]['#value']; } } } $form['handshake']['options'] = array( '#type' => 'value', '#value' => $options, ); if ($upgrade == 1) { $form['handshake']['fields']['#description'] = t('Disabled, checked items are currently shared'); $form['handshake']['usubmit'] = array( '#type' => 'submit', '#value' => t('Submit handshake upgrade request'), ); } else { $form['handshake']['submit'] = array( '#type' => 'submit', '#value' => t('Submit handshake request'), ); } $form['handshake']['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); return $form; } // function nf_handshake_initiate() /** * Validate the fields checked by the initiator as those for which he/she has data to share * * @param string $form_id * @param mixed $form_values * @return string An empty string to return the user to the top level page of the site. */ function nf_handshake_initiate_validate($form_id, $form_values) { global $user; if ($form_values['handshake']['from'] != $user->uid) { drupal_set_message(t('You are trying to initiate a handshake while posing as someone else. The administrator has been notified. You have been returned to the site\'s front page.'), 'error'); watchdog('nf_handshake', t('User %user tried to initiate a handshake posing as another user.', array('%user' => $user->uid)), WATCHDOG_WARNING); return drupal_goto(''); } foreach ($form_values['handshake']['fields'] as $field => $value) { if ($value === 'NULL') { drupal_set_message(t('Invalid field selection. You have submitted a disabled field as not-disabled. The administrator has been notified. You have been returned to the site\'s front page.'), 'error'); watchdog('nf_handshake', t('User %user tried to submit a disabled handshake intiation field.', array('%user' => $user->uid)), WATCHDOG_WARNING); return drupal_goto(''); } if (!key_exists($field, $form_values['handshake']['options'])) { drupal_set_message(t('Invalid field selection. You have submitted an invalid field. The administrator has been notified. You have been returned to the site\'s front page.'), 'error'); watchdog('nf_handshake', t('User %user tried to submit an invalid key for a handshake intiation field.', array('%user' => $user->uid)), WATCHDOG_WARNING); return drupal_goto(''); } if ($field != $value) { drupal_set_message(t('Invalid field selection. You have submitted an unmatching value. The administrator has been notified. You have been returned to the site\'s front page.'), 'error'); watchdog('nf_handshake', t('User %user tried to submit an invalid value for a handshake intiation field.', array('%user' => $user->uid)), WATCHDOG_WARNING); return drupal_goto(''); } } } // function nf_handshake_initiate_validate() /** * Store the handshake request. * * @param string $form_id * @param mixed $form_values * @return string An empty string to return the user to the top level page of the site. */ function nf_handshake_initiate_submit($form_id, $form_values) { global $user; if ($form_values['op'] == t('Submit handshake request')) { $sql = "INSERT INTO {nf_handshake} (iuid, auid, hstatus, hfields, datestamp, duration, flags) VALUES (%d, %d, %d, '%s', '%s', '%s', %d)"; $iuid = $form_values['handshake']['from']; $auid = $form_values['handshake']['to']; $hfields = serialize($form_values['handshake']['fields']); $hstatus = NFHANDSHAKE_PENDING; $flags = NFHANDSHAKE_NONE; $datestamp = time(); $values = variable_get('nf_handshake_settings', array('initiate_expire_unit' => 'Weeks', 'initiate_expire_number' => 1, 'reject_expire_unit' => 'Months', 'reject_expire_number' => 6)); $number = $values['initiate_expire_number']; $unit = $values['initiate_expire_unit']; switch ($unit) { case 'Days': $unit = 60*60*24; break; case 'Weeks': $unit = 60*60*24*7; break; case 'Months': $unit = 60*60*24*30; break; case 'Years': $unit = 60*60*24*365; break; } $duration = time() + ($unit*$number); if (!$result = db_query($sql, $iuid, $auid, $hstatus, $hfields, $datestamp, $duration, $flags)) { drupal_set_message(t('There was a problem adding your request to the database. Please go back and try again. If the problem persists, please alert the administrator.'), 'error'); $error = 1; } $sql = "INSERT INTO {nf_handshake_manage} (iuid, auid, purpose, userflag, adminflag, initialdate) VALUES (%d, %d, '%s', %d, %d, %d)"; $purpose = $form_values['handshake']['purpose']; if ($error != 1) { if (!$result = db_query($sql, $iuid, $auid, $purpose, $flags, $flags, $datestamp)) { drupal_set_message(t('There was a problem adding your request to the database. Please go back and try again. If the problem persists, please alert the administrator.'), 'error'); db_query("DELETE FROM {nf_handshake} WHERE iuid = %d AND auid = %d", $iuid, $auid); $error = 1; } } if (!$error) { drupal_set_message(t('You have successfully initiated a handshake with the intended party. When they respond, you will be notified.')); } } if ($form_values['op'] == t('Submit handshake upgrade request')) { foreach ($form_values['handshake']['fields'] as $field => $value) { if (!key_exists($field, $form_values['request']['fields']) && $value !== 0) { $form_values['handshake']['fields'][$field] .= 'X'; } } $sql = "UPDATE {nf_handshake} SET iuid = %d, auid = %d, hstatus = %d, hfields = '%s' WHERE(auid = %d AND iuid = %d) OR (auid = %d AND iuid = %d)"; $iuid = $form_values['handshake']['from']; $auid = $form_values['handshake']['to']; $hfields = serialize($form_values['handshake']['fields']); $hstatus = NFHANDSHAKE_UPGRADE_REQUESTED; if (!$result = db_query($sql, $iuid, $auid, $hstatus, $hfields, $auid, $iuid, $iuid, $auid)) { drupal_set_message(t('There was a problem adding your request to the database. Please go back and try again. If the problem persists, please alert the administrator.'), 'error'); $error = 1; } $sql = "INSERT INTO {nf_handshake_manage} (iuid, auid, purpose, userflag, adminflag, initialdate) VALUES (%d, %d, '%s', %d, %d, %d)"; $purpose = $form_values['handshake']['purpose']; if ($error != 1) { if (!$result = db_query($sql, $iuid, $auid, $purpose, $flags, $flags, $datestamp)) { drupal_set_message(t('There was a problem adding your request to the database. Please go back and try again. If the problem persists, please alert the administrator.'), 'error'); db_query("DELETE FROM {nf_handshake} WHERE iuid = %d AND auid = %d", $iuid, $auid); $error = 1; } } if (!$error) { drupal_set_message(t('You have successfully initiated a handshake upgrade request with the intended party. When they respond, you will be notified.')); } } return 'user/' .$user->uid. '/nf_handshake/inbox'; } // function nf_handshake_initiate_submit() /** * Theme the presentation of the handshake initiation form. * * @param array $form The form to render. * @return string An HTML string to use as the contents of the page. */ function theme_nf_handshake_initiate($form) { $header = array(t('Field'), t('Your data to share')); $output = ''; $rows = array(); $user_data = array(); $user_data_location = array(); $groups = _nf_handshake_get_groupnames(); //determine which types the user has created nodes for; hold on to the node data for those types they've created. $all_fields = _nf_handshake_get_cckfieldnames(); $sql = "SELECT n.nid, n.vid, n.type, n.title FROM {node} n WHERE n.uid = %d AND n.type = '%s'"; foreach ($all_fields as $type => $field) { $results = db_query($sql, $form['handshake']['from']['#value'], $type); if (db_num_rows($results) > 1) { drupal_set_message('Error, you have more than one node of the content type ' .$type. '. Please contact the system administrator with this error message.', 'error'); return ''; } else { if (db_num_rows($results) < 1) { if (!module_exists('nf_registration_mod')) { drupal_set_message('You have not completed your own user profile. Some fields will be empty. You can not share information you do not provide.'); } $user_types[$type] = NULL; } else { $result = db_fetch_object($results); $user_types[$type] = $result; } } } //locate the user's data $sql2 = "SELECT type FROM {node_field} WHERE field_name = '%s'"; foreach ($all_fields as $type => $the_rest) { $type_data = content_types($type); foreach ($the_rest as $key => $value) { if ($user_types[$type] != NULL) { $result = db_fetch_object(db_query($sql2, $value)); $field = $type_data['fields'][$value]; $storage = content_database_info($field); $user_data_location[$type][$key] = $storage; } } } //retrieve the user's data and place it in rows foreach ($user_data_location as $type => $field_name) { foreach ($field_name as $key => $value) { foreach ($value as $key2 => $value2) { $table = $value['table']; if ($key2 == 'columns') { foreach ($value2 as $column_readable => $column_array) { $sql3 = "SELECT %s FROM {%s} WHERE nid = %d"; $result = db_fetch_object(db_query($sql3, $column_array['column'], $table, $user_types[$type]->nid)); $user_data[$type][$key][$column_readable] = $result->$column_array['column']; } } } } } foreach ($form['handshake']['options']['#value'] as $key4 => $value4) { if (strstr($key4, '::')) { $data_text = ''; $exp_val = explode('::', $key4); if (!empty($user_types[$exp_val[0]]) && $user_types[$exp_val[0]] != NULL) { foreach ($user_data[$exp_val[0]][$exp_val[1]] as $column => $data) { if (!empty($data)) { $data_text .= $data. '
'; } } } if ($data_text == '') { $data_text .= t('No Value Entered'); $form['handshake']['fields'][$key4]['#attributes'] = array('disabled' => 1); $form['handshake']['fields'][$key4]['#return_value'] = 'NULL'; } $rows[] = array(array('data' => drupal_render($form['handshake']['fields'][$key4]), 'width' => '20%'), array('data' => $data_text, 'width' => '*')); } else { foreach ($groups as $group => $the_rest) { if ($group == $key4) { $data_text = ''; foreach ($the_rest as $key3 => $value3) { $exp_val2 = explode('::', $key3); if (!empty($user_types[$exp_val2[0]]) && $user_types[$exp_val2[0]] != NULL) { foreach ($user_data[$exp_val2[0]][$exp_val2[1]] as $column => $data) { if (!empty($data)) { $data_text .= $data. '
'; } } } } if ($data_text == '') { $data_text .= t('No Value Entered'); $form['handshake']['fields'][$key4]['#attributes'] = array('disabled' => 1); $form['handshake']['fields'][$key4]['#return_value'] = 'NULL'; } $rows[] = array(array('data' => drupal_render($form['handshake']['fields'][$key4]), 'width' => '35%'), array('data' => $data_text, 'width' => '*')); } } } } $output .= drupal_render($form['handshake']['purpose']); $form['handshake']['fields']['#value'] = theme('table', $header, $rows, array('width' => '100%', 'required' => 'TRUE')); $output .= drupal_render($form['handshake']['fields']); $output .= '
'; $output .= drupal_render($form); return $output; } // function theme_nf_handshake_initiate() //-----------------------------------------Accept/Reject/Flag handshakes----------------------------------------- /** * Collect the new and unanswered handshake requests for display in tabular format. * * @return array $form The form to be rendered. */ function nf_handshake_inbox() {//TODO after makning cron jobs for admin flag changes, also adjust the message that says "nothing to do at this time" to show decisions global $user; //--------------------------Deal with all cases for which the user is the auid first and put them in an inbox-------------------------------- $new_num = nf_handshake_get_new_handshake_requests($user->uid); $unanswered_num = nf_handshake_get_read_handshake_requests($user->uid); $flagged_num = nf_handshake_get_read_handshake_flags_iuid($user->uid); $flagged_num += nf_handshake_get_read_handshake_flags_auid($user->uid); //collect handshakes that will still have an entry in nf_handshake_manage $sql = "SELECT nh.*, nhm.purpose, nhm.adminflag FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE nh.auid = %d AND nh.hstatus = %d ORDER BY nh.datestamp"; $new_results = db_query($sql, $user->uid, NFHANDSHAKE_PENDING); $unanswered_results = db_query($sql, $user->uid, NFHANDSHAKE_REVIEWED); $flagged_results = db_query($sql, $user->uid, NFHANDSHAKE_FLAGGED); $upgraded_results = db_query($sql, $user->uid, NFHANDSHAKE_UPGRADE_REQUESTED); while ($new_result = db_fetch_object($new_results)) { $form['new'][$new_result->datestamp] = array( '#type' => 'value', '#value' => $new_result, ); } while ($unanswered_result = db_fetch_object($unanswered_results)) { $form['unanswered'][$unanswered_result->datestamp] = array( '#type' => 'value', '#value' => $unanswered_result, ); } while ($flagged_result = db_fetch_object($flagged_results)) { $form['flagged'][$flagged_result->datestamp] = array( '#type' => 'value', '#value' => $flagged_result, ); } while ($upgraded_result = db_fetch_object($upgraded_results)) { $form['upgraded'][$upgraded_result->datestamp] = array( '#type' => 'value', '#value' => $upgraded_result, ); } $form['new_num'] = array( '#type' => 'value', '#value' => $new_num, ); $form['unanswered_num'] = array( '#type' => 'value', '#value' => $unanswered_num, ); $form['flag_num'] = array( '#type' => 'value', '#value' => $flagged_num, ); //now collect the handshakes that only have nf_handshake entries and no nf_handshake_manage entries $sql = "SELECT * FROM {nf_handshake} WHERE auid = %d AND hstatus = %d ORDER BY duration"; $extension_results = db_query($sql, $user->uid, NFHANDSHAKE_EXTENSION_REQUESTED); $rejected_results = db_query($sql, $user->uid, NFHANDSHAKE_REJECTED); while ($extension_result = db_fetch_object($extension_results)) { $form['extension'][$extension_result->duration] = array( '#type' => 'value', '#value' => $extension_result, ); } while ($rejected_result = db_fetch_object($rejected_results)) { $form['rejected'][$rejected_result->duration] = array( '#type' => 'value', '#value' => $rejected_result, ); } //--------------------------Deal with all cases for which the user is the iuid next and put them in an outbox-------------------------------- //collect handshakes that will still have an entry in nf_handshake_manage $sql = "SELECT nh.*, nhm.purpose, nhm.adminflag FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE nh.iuid = %d AND nh.hstatus = %d ORDER BY nh.datestamp"; $new_results_out = db_query($sql, $user->uid, NFHANDSHAKE_PENDING); $unanswered_results_out = db_query($sql, $user->uid, NFHANDSHAKE_REVIEWED); $flagged_results_out = db_query($sql, $user->uid, NFHANDSHAKE_FLAGGED); $upgraded_results_out = db_query($sql, $user->uid, NFHANDSHAKE_UPGRADE_REQUESTED); while ($new_result = db_fetch_object($new_results_out)) { $form['new_out'][$new_result->datestamp] = array( '#type' => 'value', '#value' => $new_result, ); } while ($unanswered_result = db_fetch_object($unanswered_results_out)) { $form['unanswered_out'][$unanswered_result->datestamp] = array( '#type' => 'value', '#value' => $unanswered_result, ); } while ($flagged_result = db_fetch_object($flagged_results_out)) { $form['flagged_out'][$flagged_result->datestamp] = array( '#type' => 'value', '#value' => $flagged_result, ); } while ($upgraded_result = db_fetch_object($upgraded_results_out)) { $form['upgraded_out'][$upgraded_result->datestamp] = array( '#type' => 'value', '#value' => $upgraded_result, ); } //now collect the handshakes that only have nf_handshake entries and no nf_handshake_manage entries $sql = "SELECT * FROM {nf_handshake} WHERE iuid = %d AND hstatus = %d ORDER BY duration"; $extension_results_out = db_query($sql, $user->uid, NFHANDSHAKE_EXTENSION_REQUESTED); $rejected_results_out = db_query($sql, $user->uid, NFHANDSHAKE_REJECTED); while ($extension_result = db_fetch_object($extension_results_out)) { $form['extension_out'][$extension_result->duration] = array( '#type' => 'value', '#value' => $extension_result, ); } while ($rejected_result = db_fetch_object($rejected_results_out)) { $form['rejected_out'][$rejected_result->duration] = array( '#type' => 'value', '#value' => $rejected_result, ); } return $form; } // function nf_handshake_inbox() /** * Display the handshake inbox and list the new and unanswered handshake requests. Also link to the contacts page. * * @param array $form The form to be rendered. * @return string $output The HTML to be displayed. */ function theme_nf_handshake_inbox($form) { global $user; $output = ''; $output1 = ''; $rows = array(); $rows2 = array(); $rows3 = array(); $rows4 = array(); //----------------------------------------display the inbox (auid) stuff first-------------------------------------------------- $header = array(array('data' => t('Status'), 'field' => 'hstatus', 'sort' => 'asc'), array('data' => t('Date Initiated'), 'field' => 'datestamp'), array('data' => t('From Username'), 'field' => 'name'), t('Stated Purpose'), t('Operation')); $rows[] = array(array('data' => t('These are the handshake requests you are currently working with or which need your attention.'), 'colspan' => 5)); if (!empty($form['new'])) { foreach (element_children($form['new']) as $key) { $obj = $form['new'][$key]['#value']; $submit_date = date('M j Y', $obj->datestamp); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->iuid)); $username = $username->name; $rows[] = array('' .t('new'). '', $submit_date, $username, substr($obj->purpose, 0, 25), l(t('reply'), 'user/' .$user->uid. '/nf_handshake/view_hsr', array('title' => t("Review this handshake request.")), 'iuid=' .$obj->iuid)); } } else { $rows[] = array(array('data' => t('      No new handshake requests.'), 'colspan' => 5)); } if (!empty($form['unanswered'])) { foreach (element_children($form['unanswered']) as $key) { $obj = $form['unanswered'][$key]['#value']; $submit_date = date('M j Y', $obj->datestamp); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->iuid)); $username = $username->name; $rows[] = array('' .t('unanswered'). '', $submit_date, $username, substr($obj->purpose, 0, 25), l(t('reply'), 'user/' .$user->uid. '/nf_handshake/view_hsr', array('title' => t("Review this handshake request.")), 'iuid=' .$obj->iuid)); } } else { $rows[] = array(array('data' => t('      No reviewed handshake requests.'), 'colspan' => 5)); } if (!empty($form['flagged'])) { foreach (element_children($form['flagged']) as $key) { $obj = $form['flagged'][$key]['#value']; if ($obj->adminflag <> NFHANDSHAKE_NONE && $obj->adminflag <> NFHANDSHAKE_FURTHER_REVIEW && $obj->adminflag <> NFHANDSHAKE_AUID_COMMENT && $obj->adminflag <> NFHANDSHAKE_IUID_COMMENT) { continue; } if ($obj->adminflag == NFHANDSHAKE_AUID_COMMENT) { $last_column = l(t('reply'), 'user/nf_handshake/flag_reply/' .$obj->iuid. '/' .$user->uid, array('title' => t("Reply to a handshake flag."))); } else { $last_column = t('nothing to do at this time'); } $submit_date = date('M j Y', $obj->datestamp); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->iuid)); $username = $username->name; $rows[] = array('' .t('flagged'). '', $submit_date, $username, substr($obj->purpose, 0, 25), $last_column); } } else { $rows[] = array(array('data' => t('      No flagged handshakes.'), 'colspan' => 5)); } if (!empty($form['upgraded'])) { foreach (element_children($form['upgraded']) as $key) { $obj = $form['upgraded'][$key]['#value']; $submit_date = date('M j Y', $obj->datestamp); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->iuid)); $username = $username->name; $rows[] = array('' .t('upgrade'). '', $submit_date, $username, substr($obj->purpose, 0, 25), l(t('reply'), 'user/' .$user->uid. '/nf_handshake/view_hsr', array('title' => t("Review this handshake upgrade request.")), 'iuid=' .$obj->iuid)); } } else { $rows[] = array(array('data' => t('      No handshake upgrade request.'), 'colspan' => 5)); } $output .= '
You have ' .$form['new_num']['#value']. ' new, and ' .$form['unanswered_num']['#value']. ' read but unanswered handshake requests.
'; $output .= 'You have ' .$form['flag_num']['#value']. ' flagged handshakes that require a comment from you.

'; $output1 .= theme('table', $header, $rows, array('width' => '99%')); $header2 = array(array('data' => t('Status'), 'field' => 'hstatus', 'sort' => 'asc'), array('data' => t('Expiration Date'), 'field' => 'duration'), array('data' => t('From Username'), 'field' => 'name'), t('Operation')); $rows2[] = array(array('data' => t('The initiators of these handshakes have requested expiration extensions.'), 'colspan' => 4)); if (!empty($form['extension'])) { foreach (element_children($form['extension']) as $key) { $obj = $form['extension'][$key]['#value']; $expire_date = date('M j Y', $obj->duration); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->iuid)); $username = $username->name; $rows2[] = array('' .t('extension requested'). '', $expire_date, $username, l(t('extend expiration'), 'user/nf_handshake/extend_duration/' .$user->uid. '/' .$obj->iuid, array('title' => t("Extend this handshake's expiration date.")))); } } else { $rows2[] = array(array('data' => t('      No outstanding handshake extension requests.'), 'colspan' => 4)); } $rows2[] = array(array('data' => t('You may change your mind regarding handhshakes you have rejected until they expire.'), 'colspan' => 4)); if (!empty($form['rejected'])) { foreach (element_children($form['rejected']) as $key) { $obj = $form['rejected'][$key]['#value']; $expire_date = date('M j Y', $obj->duration); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->iuid)); $username = $username->name; $rows2[] = array('' .t('rejected by you'). '', $expire_date, $username, l(t('modify'), 'user/' .$user->uid. '/nf_handshake/view_hsr', array('title' => t("Modify this handshake request.")), 'iuid=' .$obj->iuid)); } } else { $rows2[] = array(array('data' => t('      No rejected handshakes.'), 'colspan' => 4)); } $output1 .= '
'; $output1 .= theme('table', $header2, $rows2, array('width' => '99%')); $all_empty = empty($form['new']) && empty($form['unanswered']) && empty($form['flagged']) && empty($form['upgraded']) && empty($form['extension']) && empty($form['rejected']); $fieldset = array( '#type' => 'fieldset', '#value' => $output1, '#title' => t('Handshake inbox'), '#collapsible' => TRUE, '#collapsed' => $all_empty, '#weight' => -1, ); $output .= theme('fieldset', $fieldset); //----------------------------------------display the outbox (iuid) stuff second-------------------------------------------------- $header3 = array(array('data' => t('Status'), 'field' => 'hstatus', 'sort' => 'asc'), array('data' => t('Date Initiated'), 'field' => 'datestamp'), array('data' => t('To Username'), 'field' => 'name'), t('Stated Purpose')); if ($form['flag_num'] > 0) { $header3[] = t('Operations'); $rows3[] = array(array('data' => t('These are the handshake requests you have submitted and which have not been answered yet.'), 'colspan' => 5)); } else { $rows3[] = array(array('data' => t('These are the handshake requests you have submitted and which have not been answered yet.'), 'colspan' => 4)); } if (!empty($form['new_out'])) { foreach (element_children($form['new_out']) as $key) { $obj = $form['new_out'][$key]['#value']; $submit_date = date('M j Y', $obj->datestamp); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->auid)); $username = $username->name; $rows3[] = array('' .t('new'). '', $submit_date, $username, substr($obj->purpose, 0, 25), ''); } } else { if ($form['flag_num'] > 0) { $rows3[] = array(array('data' => t('      No new handshake requests.'), 'colspan' => 5)); } else { $rows3[] = array(array('data' => t('      No new handshake requests.'), 'colspan' => 4)); } } if (!empty($form['unanswered_out'])) { foreach (element_children($form['unanswered_out']) as $key) { $obj = $form['unanswered_out'][$key]['#value']; $submit_date = date('M j Y', $obj->datestamp); $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->auid)); $username = $username->name; $rows3[] = array('' .t('unanswered'). '', $submit_date, $username, substr($obj->purpose, 0, 25), ''); } } else { if ($form['flag_num'] > 0) { $rows3[] = array(array('data' => t('      No reviewed handshake requests.'), 'colspan' => 5)); } else { $rows3[] = array(array('data' => t('      No reviewed handshake requests.'), 'colspan' => 4)); } } if (!empty($form['flagged_out'])) { foreach (element_children($form['flagged_out']) as $key) { $obj = $form['flagged_out'][$key]['#value']; if ($obj->adminflag == NFHANDSHAKE_IUID_COMMENT) { $last_column = l(t('reply'), 'user/nf_handshake/flag_reply/' .$user->uid. '/' .$obj->auid, array('title' => t("Reply to a handshake flag."))); } else { $last_column = t('nothing to do at this time'); } $submit_date = date('M j Y', $obj->datestamp); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->auid)); $username = $username->name; $rows3[] = array('' .t('flagged'). '', $submit_date, $username, substr($obj->purpose, 0, 25), $last_column); } } else { if ($form['flag_num'] > 0) { $rows3[] = array(array('data' => t('      No flagged handshakes.'), 'colspan' => 5)); } else { $rows3[] = array(array('data' => t('      No flagged handshakes.'), 'colspan' => 4)); } } if (!empty($form['upgraded_out'])) { foreach (element_children($form['upgraded_out']) as $key) { $obj = $form['upgraded_out'][$key]['#value']; $submit_date = date('M j Y', $obj->datestamp); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->auid)); $username = $username->name; $rows3[] = array('' .t('upgrade'). '', $submit_date, $username, substr($obj->purpose, 0, 25)); } } else { if ($form['flag_num'] > 0) { $rows3[] = array(array('data' => t('      No handshake upgrade requests.'), 'colspan' => 5)); } else { $rows3[] = array(array('data' => t('      No handshake upgrade requests.'), 'colspan' => 4)); } } $output2 .= theme('table', $header3, $rows3, array('width' => '99%')); $header4 = array(array('data' => t('Status'), 'field' => 'hstatus', 'sort' => 'asc'), array('data' => t('Expiration Date'), 'field' => 'duration'), array('data' => t('To Username'), 'field' => 'name')); $rows4[] = array(array('data' => t('You have requested expiration extensions for these handshakes.'), 'colspan' => 3)); if (!empty($form['extension_out'])) { foreach (element_children($form['extension_out']) as $key) { $obj = $form['extension_out'][$key]['#value']; $expire_date = date('M j Y', $obj->duration); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->auid)); $username = $username->name; $rows4[] = array('' .t('extension requested'). '', $expire_date, $username); } } else { $rows4[] = array(array('data' => t('      No outstanding handshake extension requests.'), 'colspan' => 3)); } $rows4[] = array(array('data' => t('These are handshakes you initiated that have been rejected.'), 'colspan' => 3)); if (!empty($form['rejected_out'])) { foreach (element_children($form['rejected_out']) as $key) { $obj = $form['rejected_out'][$key]['#value']; $expire_date = date('M j Y', $obj->duration); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $obj->auid)); $username = $username->name; $rows4[] = array('' .t('rejected'). '', $expire_date, $username); } } else { $rows4[] = array(array('data' => t('      No rejected handshakes.'), 'colspan' => 3)); } $output2 .= '
'; $output2 .= theme('table', $header4, $rows4, array('width' => '99%')); $all_empty2 = empty($form['new_out']) && empty($form['unanswered_out']) && empty($form['flagged_out']) && empty($form['upgraded_out']) && empty($form['extension_out']) && empty($form['rejected_out']); $fieldset2 = array( '#type' => 'fieldset', '#value' => $output2, '#title' => t('Handshake outbox'), '#collapsible' => TRUE, '#collapsed' => $all_empty2, '#weight' => 0, ); $output .= theme('fieldset', $fieldset2); $output .= '
' .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 .= drupal_render($form); return $output; } // function theme_nf_handshake_inbox() /** * Show the user the handshake request he/she clicked on and present options. Also, set the hstatus to NFHANDSHAKE_REVIEWED. * * @param int $iuid This will either be passed in directly, or via a $_GET value. * @return array $form The form to render. */ function nf_handshake_view_hsr($iuid = NULL, $downgrade = 0) { global $user; if ($iuid === NULL) { $iuid = $_GET['iuid']; } if ($downgrade == 1) { drupal_set_title('Downgrade handshake'); } $auid = $user->uid; //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $iuid)); $username = $username->name; $sql = "SELECT nh.*, nhm.purpose FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE nh.auid = %d AND nh.iuid = %d"; $request = db_fetch_object(db_query($sql, $auid, $iuid)); if (!$request && $downgrade == 1) { $auid = $iuid; $iuid = $user->uid; $request = db_fetch_object(db_query($sql, $auid, $iuid)); } if ($request->hstatus == NFHANDSHAKE_PENDING) { $sql = "UPDATE {nf_handshake} SET hstatus = %d WHERE iuid= %d AND auid = %d"; $success = db_query($sql, NFHANDSHAKE_REVIEWED, $iuid, $auid); if (!$success) { watchdog('nf_handshake', t('nf_handshake: unable to update table for %iuid and %auid to %hstatus.', array('%iuid' => $iuid, '%auid' => $auid, '%hstatus' => NFHANDSHAKE_REVIEWED))); } } elseif ($request->hstatus == NFHANDSHAKE_REJECTED) { drupal_set_title('Reestablish handshake'); } nf_handshake_get_new_handshake_requests($auid); nf_handshake_get_read_handshake_requests($auid); $form['request'] = array( '#tree' => TRUE, ); $form['request']['from'] = array( '#type' => 'value', '#value' => $request->iuid, ); $form['request']['to'] = array( '#type' => 'value', '#value' => $request->auid, ); $form['request']['fields'] = array( '#type' => 'fieldset', '#title' => t('Select fields to share'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); $used_fields = unserialize($request->hfields); $fields = _nf_handshake_get_cckfieldnames(); foreach ($fields as $type => $the_rest) { if (!empty($the_rest)) { foreach ($the_rest as $field => $val) { if (key_exists($type. '::' .$val, $used_fields) && $used_fields[$type. '::' .$val] !== 0) { $val2 = substr($val, 6); $val2 = ucfirst($val2); $used_fields[$type. '::' .$val] = $val2; } } } } foreach ($used_fields as $key => $value) { if ($value !== 0) { if (substr($value, -1) == 'X' && $downgrade == 1) { unset($used_fields[$key]); continue; } if (substr($value, -1) == 'X') { $value = rtrim($value, 'X'); } $form['request']['fields'][$key] = array( '#type' => 'checkbox', '#title' => $value, '#return_value' => $key, '#attributes' => array(), ); } } $form['request']['options'] = array( '#type' => 'value', '#value' => $used_fields, ); if ($downgrade === 0) { $form['request']['downgrade'] = array( '#type' => 'value', '#value' => 0, ); if ($request->hstatus == NFHANDSHAKE_REJECTED) { //PHP4 Modified $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $form['request']['from']['#value'])); $username = $tusername->name; $form['request']['username'] = array( '#type' => 'item', '#title' => '' .$username.t(' formerly had a handshake with you. You previously rejected it. You may still change your mind until the handshake expires'), '#description' => t('Below you will see the fields that are requested to be shared. Your values are displayed. By checking the boxes, you select the fields you both will exchange. Leaving them all unchecked is the same as rejecting the handshake. You will find other options below the displayed values.'), ); } else { $form['request']['username'] = array( '#type' => 'item', '#title' => '' .$username. t(' has initiated a handshake with you.'), '#description' => t('Below you will see the fields that are requested to be shared. Your values are displayed. By checking the boxes, you select the fields you both will exchange. Leaving them all unchecked is the same as rejecting the handshake. You will find other options below the displayed values.'), ); } $form['request']['dateinitiated'] = array( '#type' => 'item', '#value' => date('M j, Y', $request->datestamp), ); $form['request']['expiration'] = array( '#type' => 'item', '#value' => date('M j, Y', $request->duration), ); $form['request']['duration'] = array( '#type' => 'fieldset', '#collapsible' => FALSE, '#title' => t('Duration'), ); $form['request']['duration']['note'] = array( '#type' => 'item', '#description' => t('If you choose to accept this handshake request, you may set a time limit during which your information is shared with the requesting person and their\'s with you. You may revoke a handshake at any time as may the other party. As expiration approaches, you will be given the chance to extend the duration.'), ); $form['request']['duration']['unit'] = array( '#type' => 'select', '#title' => t('Time unit'), '#default_value' => 'Forever', '#options' => array('Days' => 'Days', 'Weeks' => 'Weeks', 'Months' => 'Months', 'Years' => 'Years', 'Forever' => 'Forever'), ); $form['request']['duration']['number'] = array( '#type' => 'select', '#default_value' => 0, '#options' => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31), ); $form['request']['purpose'] = array( '#type' => 'textarea', '#title' => t('Purpose of request'), '#value' => $request->purpose, '#disabled' => TRUE, '#cols' => 25, '#rows' => 2, ); $form['request']['flag'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Flag this request?'), ); $form['request']['flag']['note'] = array( '#type' => 'item', '#description' => t('Rather than accept or reject this handshake request, you may flag it for review by the site administrators.'), ); $form['request']['flag']['choice'] = array( '#type' => 'select', '#default_value' => 0, '#options' => nf_handshake_get_user_flags(), ); $form['request']['flag']['reason'] = array( '#type' => 'textarea', '#title' => t('Reason for flag'), '#description' => t('*If you choose to flag this request, you must give a reason.') ); $form['request']['flag']['flag'] = array( '#type' => 'submit', '#value' => t('Flag handshake'), ); $form['request']['accept'] = array( '#type' => 'submit', '#value' => t('Accept handshake'), ); $form['request']['reject'] = array( '#type' => 'submit', '#value' => t('Reject handshake'), ); } else { $form['request']['downgrade'] = array( '#type' => 'value', '#value' => 1, ); $form['request']['username'] = array( '#type' => 'item', '#title' => 'You have an existing handshake with ' .$username. t(''), '#description' => t('Below you will see the fields that you now share. Your values are displayed. By checking the boxes, you select the fields that will be exchanged from now on. Hit cancel to not make any changes.'), ); $form['request']['username'] = array( '#type' => 'item', '#title' => 'You have an existing handshake with ' .$username. t(''), '#description' => t('Below you will see the fields that you now share. Your values are displayed. By checking the boxes, you select the fields that will be exchanged from now on. Hit cancel to not make any changes.'), ); $form['request']['accept'] = array( '#type' => 'submit', '#value' => t('Downgrade handshake'), ); $form['request']['reject'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); } return $form; } // function nf_handshake_view_hsr() /** * Validate the fields * * @param string $form_id * @param mixed $form_values * @return */ function nf_handshake_view_hsr_validate($form_id, $form_values) { global $user; if ($form_values['op'] == t('Reject handshake') || $form_values['op'] == t('Cancel')) { return; } if ($form_values['op'] == t('Flag handshake')) { if ($form_values['request']['flag']['choice'] == 0) { form_set_error("request][flag][choice", t('You flagged the request without selecting a flag. Try again.')); return; } elseif ($form_values['request']['flag']['choice'] != 0 && empty($form_values['request']['flag']['reason'])) { form_set_error("request][flag][reason", t('You flagged the request without specifying a reason. Please give a reason for the flag.')); return; } } if ($form_values['op'] == t('Accept handshake')) { $val_num = array_count_values($form_values['request']['fields']); if ($val_num[0] == count($form_values['request']['fields'])) { form_set_error("request][fields][Other", t('You accepted the request but failed to select any fields for the handshake. Try again.')); } if ($form_values['request']['duration']['unit'] != 'Forever' && $form_values['request']['duration']['number'] == 0) { form_set_error("request][duration][number", t('You accepted the request but failed to select a proper duration for the handshake. Try again.')); return; } } if ($form_values['op'] == t('Downgrade handshake')) { $val_num = array_count_values($form_values['request']['fields']); if ($val_num[0] == count($form_values['request']['fields'])) { form_set_error("request][fields][Other", t('You accepted the request but failed to select any fields for the handshake. Try again.')); } } } // function nf_handshake_view_hsr_validate() /** * Modify the db tables according to what the user chose to do about the handshake request. * * @param string $form_id * @param mixed $form_values * @return string Path where the user will be directed. */ function nf_handshake_view_hsr_submit($form_id, $form_values) { global $user; if ($form_values['op'] == t('Cancel')) { drupal_set_message('Changes cancelled.'); } if ($form_values['op'] == t('Reject handshake')) { foreach ($form_values['request']['options'] as $key => $value) { $fields[$key] = 0; } $fields = serialize($fields); $hstatus = NFHANDSHAKE_REJECTED; $duration = 0; $iuid = $form_values['request']['from']; $auid = $form_values['request']['to']; $sql1 = "UPDATE {nf_handshake} SET hfields = '%s', duration = %d, hstatus = %d WHERE iuid= %d AND auid = %d"; $success = db_query($sql1, $fields, $duration, $hstatus, $iuid, $auid); if (!$success) { watchdog('nf_handshake', t('nf_handshake: unable to update table for %iuid and %auid to %hstatus.', array('%iuid' => $iuid, '%auid' => $auid, '%hstatus' => 'NFHANDSHAKE_REVIEWED'))); } else { drupal_set_message('Handshake request successfully rejected.'); } $sql2 = "DELETE FROM {nf_handshake_manage} WHERE iuid= %d AND auid = %d"; $success2 = db_query($sql2, $iuid, $auid); if (!$success2) { watchdog('nf_handshake', t('nf_handshake: unable to delete row for %iuid and %auid in nf_handshake_manage.', array('%iuid' => $iuid, '%auid' => $auid))); } } if ($form_values['op'] == t('Flag handshake')) { $hstatus = NFHANDSHAKE_FLAGGED; $iuid = $form_values['request']['from']; $auid = $form_values['request']['to']; $flag = $form_values['request']['flag']['choice']; $reason = $form_values['request']['flag']['reason']; $sql1 = "UPDATE {nf_handshake} SET flags = %d, hstatus = %d WHERE iuid= %d AND auid = %d"; $success = db_query($sql1, $flag, $hstatus, $iuid, $auid); if (!$success) { watchdog('nf_handshake', t('nf_handshake: unable to update table %table for %iuid and %auid to %hstatus.', array('%table' => 'nf_handshake', '%iuid' => $iuid, '%auid' => $auid, '%hstatus' => 'NFHANDSHAKE_FLAGGED'))); } $sql2 = "UPDATE {nf_handshake_manage} SET userflag = %d, adminflag = %d, userflagexplain = '%s' WHERE iuid= %d AND auid = %d"; $success2 = db_query($sql2, $flag, NFHANDSHAKE_FURTHER_REVIEW, $reason, $iuid, $auid); if (!$success2) { watchdog('nf_handshake', t('nf_handshake: unable to update table %table for %iuid and %auid to %hstatus.', array('%table' => 'nf_handshake_manage', '%iuid' => $iuid, '%auid' => $auid, '%hstatus' => 'NFHANDSHAKE_FLAGGED'))); } if ($success && $success2) { drupal_set_message('Handshake request successfully flagged.'); } } if ($form_values['op'] == t('Accept handshake')) { $hstatus = NFHANDSHAKE_ACCEPTED; $iuid = $form_values['request']['from']; $auid = $form_values['request']['to']; foreach ($form_values['request']['options'] as $key => $value) { if (isset($form_values['request']['fields'][$key])) { $fields[$key] = $form_values['request']['fields'][$key]; } else { $fields[$key] = 0; } } $fields = serialize($fields); $number = $form_values['request']['duration']['number']; switch ($form_values['request']['duration']['unit']) { case 'Days': $unit = 60*60*24; break; case 'Weeks': $unit = 60*60*24*7; break; case 'Months': $unit = 60*60*24*30; break; case 'Years': $unit = 60*60*24*365; break; case 'Forever': $unit = 60*60*24*10000; $number = 1; break; } $duration = time() + ($unit*$number); $sql1 = "UPDATE {nf_handshake} SET hfields = '%s', hstatus = %d, duration = %d, flags = %d WHERE iuid= %d AND auid = %d"; $success = db_query($sql1, $fields, $hstatus, $duration, NFHANDSHAKE_NONE, $iuid, $auid); if (!$success) { watchdog('nf_handshake', t('nf_handshake: unable to update table %table for %iuid and %auid to %hstatus.', array('%table' => 'nf_handshake', '%iuid' => $iuid, '%auid' => $auid, '%hstatus' => 'NFHANDSHAKE_FLAGGED'))); } $sql2 = "DELETE FROM {nf_handshake_manage} WHERE iuid= %d AND auid = %d"; $success2 = db_query($sql2, $iuid, $auid); if (!$success2) { watchdog('nf_handshake', t('nf_handshake: unable to delete row for %iuid and %auid in nf_handshake_manage.', array('%iuid' => $iuid, '%auid' => $auid))); } } if ($form_values['op'] == t('Downgrade handshake')) { drupal_set_message('Inside'); $hstatus = NFHANDSHAKE_ACCEPTED; $iuid = $form_values['request']['from']; $auid = $form_values['request']['to']; foreach ($form_values['request']['options'] as $key => $value) { if (isset($form_values['request']['fields'][$key])) { $fields[$key] = $form_values['request']['fields'][$key]; } else { $fields[$key] = 0; } } $fields = serialize($fields); $sql1 = "UPDATE {nf_handshake} SET hfields = '%s', hstatus = %d WHERE iuid= %d AND auid = %d"; $success = db_query($sql1, $fields, $hstatus, $iuid, $auid); if (!$success) { watchdog('nf_handshake', t('nf_handshake: unable to update table %table for %iuid and %auid to %hstatus.', array('%table' => 'nf_handshake', '%iuid' => $iuid, '%auid' => $auid, '%hstatus' => 'NFHANDSHAKE_FLAGGED'))); } $sql3 = "SELECT * FROM {nf_hanshake_manage} WHERE iuid = %d AND auid = %d"; if ($result3 = db_fetch_object(db_query($sql3, $iuid, $auid))) { $sql2 = "DELETE FROM {nf_handshake_manage} WHERE iuid = %d AND auid = %d"; $success2 = db_query($sql2, $iuid, $auid); if (!$success2) { watchdog('nf_handshake', t('nf_handshake: unable to delete row for %iuid and %auid in nf_handshake_manage.', array('%iuid' => $iuid, '%auid' => $auid))); } } } return 'user/' .$user->uid. '/nf_handshake/inbox'; } // nf_handshake_view_hsr_submit() /** * Present the handshake request similar to the initiation form. Identify who sent it and the fields they requested. * * @param array $form The form to be rendered. * @return string $output The html to be displayed. */ function theme_nf_handshake_view_hsr($form) { $output = ''; $downgrade = $form['request']['downgrade']['#value']; //------------------before the exchange table---------------------- $output .= drupal_render($form['request']['username']); $output .= drupal_render($form['request']['purpose']); //------------------exchange table--------------------------------- $header = array(t('Field'), t('Your data to share')); $rows = array(); $user_data = array(); $user_data_location = array(); //-----------------figure out which data types the user has created that contain profile data-------------------- $groups = _nf_handshake_get_groupnames(); $all_fields = _nf_handshake_get_cckfieldnames(); $sql = "SELECT n.nid, n.vid, n.type, n.title FROM {node} n WHERE n.uid = %d AND n.type = '%s'"; foreach ($all_fields as $type => $field) { $results = db_query($sql, $form['request']['to']['#value'], $type); if (db_num_rows($results) > 1) { drupal_set_message('Error, you have more than one node of the content type ' .$type. '. Please contact the system administrator with this error message.', 'error'); return ''; } else { if (db_num_rows($results) < 1) { if (!module_exists('nf_registration_mod')) { drupal_set_message('You have not completed your own user profile. Some fields will be empty. You can not share information you do not provide.'); } $user_types[$type] = NULL; } else { $result = db_fetch_object($results); $user_types[$type] = $result; } } } //locate the user's data $sql2 = "SELECT type FROM {node_field} WHERE field_name = '%s'"; foreach ($all_fields as $type => $the_rest) { $type_data = content_types($type); foreach ($the_rest as $key => $value) { if ($user_types[$type] != NULL) { $result = db_fetch_object(db_query($sql2, $value)); $field = $type_data['fields'][$value]; $storage = content_database_info($field); $user_data_location[$type][$key] = $storage; } } } //retrieve the user's data and place it in rows foreach ($user_data_location as $type => $field_name) { foreach ($field_name as $key => $value) { foreach ($value as $key2 => $value2) { $table = $value['table']; if ($key2 == 'columns') { foreach ($value2 as $column_readable => $column_array) { $sql3 = "SELECT %s FROM {%s} WHERE nid = %d"; $result = db_fetch_object(db_query($sql3, $column_array['column'], $table, $user_types[$type]->nid)); $user_data[$type][$key][$column_readable] = $result->$column_array['column']; } } } } } foreach ($form['request']['options']['#value'] as $key4 => $value4) { if ($value4 === 0) { continue; } if (strstr($key4, '::')) { $data_text = ''; $exp_val = explode('::', $key4); if (!empty($user_types[$exp_val[0]]) && $user_types[$exp_val[0]] != NULL) { foreach ($user_data[$exp_val[0]][$exp_val[1]] as $column => $data) { if (!empty($data)) { $data_text .= $data. '
'; } } } if ($data_text == '') { $data_text .= t('No Value Entered'); $form['request']['fields'][$key4]['#attributes'] = array('disabled' => 1); $form['request']['fields'][$key4]['#return_value'] = 'NULL'; } $rows[] = array(array('data' => drupal_render($form['request']['fields'][$key4]), 'width' => '20%'), array('data' => $data_text, 'width' => '*')); } else { foreach ($groups as $group => $the_rest) { if ($group == $key4) { $data_text = ''; foreach ($the_rest as $key3 => $value3) { $exp_val2 = explode('::', $key3); if (!empty($user_types[$exp_val2[0]]) && $user_types[$exp_val2[0]] != NULL) { foreach ($user_data[$exp_val2[0]][$exp_val2[1]] as $column => $data) { if (!empty($data)) { $data_text .= $data. '
'; } } } } if ($data_text == '') { $data_text .= t('No Value Entered'); $form['request']['fields'][$key4]['#attributes'] = array('disabled' => 1); $form['request']['fields'][$key4]['#return_value'] = 'NULL'; } $rows[] = array(array('data' => drupal_render($form['request']['fields'][$key4]), 'width' => '35%'), array('data' => $data_text, 'width' => '*')); } } } } //----------------assemble the display--------------------------------------- $form['request']['fields']['#value'] = theme('table', $header, $rows, array('width' => '100%')); if ($downgrade === 0) { $head = array(t('Date handshake initiated'), t('Date request will expire')); $turkey[] = array(drupal_render($form['request']['dateinitiated']), drupal_render($form['request']['expiration'])); $turkey[] = array( array('data' => t('If you do not respond before the expiration date, this handshake will be marked as rejected with the reason of expired. The initiator may then choose to reinitiate and may do so again and again until you respond.'), 'colspan' => 2) ); $output .= theme('table', $head, $turkey); $output .= '
'; } $output .= drupal_render($form); return $output; } // function theme_nf_handshake_view_hsr() /** * Show a single flag case for the user to reply to. Allow the user to make notes to respond to the admin. * * @param int $iuid The initiator's UID * @param int $auid The acceptor's (reciever's) UID * @return array $form The form to render */ function nf_handshake_flag_reply($iuid = NULL, $auid = NULL) { global $user; if ($user->uid == $iuid) { $user_is = 'iuid'; } else { $user_is = 'auid'; } $all_flags = nf_handshake_get_user_flags(); $all_admin_flags = nf_handshake_get_admin_flags(); $sql = "SELECT nh.*, nhm.* FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE nh.iuid = %d AND nh.auid = %d"; $result = db_fetch_object(db_query($sql, $iuid, $auid)); $form['user_flag'] = array( '#tree' => TRUE, ); $form['user_flag']['iuid'] = array( '#type' => 'value', '#value' => $iuid, ); $form['user_flag']['auid'] = array( '#type' => 'value', '#value' => $auid, ); $form['user_flag']['datestamp'] = array( '#type' => 'item', '#title' => t('Date initiated'), '#value' => date('M j Y', $result->datestamp), ); $form['user_flag']['duration'] = array( '#type' => 'item', '#title' => t('Expiration date'), '#value' => date('M j Y', $result->duration), ); $form['user_flag']['initial'] = array( '#type' => 'item', '#title' => t('Initial admin involvement'), '#value' => ($result->initialdate == 0) ? date('M j Y', time()) : date('M j Y', $result->initialdate),//test this ); $form['user_flag']['purpose'] = array( '#type' => 'item', '#title' => t('Stated purpose of handshake'), '#value' => $result->purpose, ); $form['user_flag']['flag'] = array( '#type' => 'item', '#title' => t('User flag'), '#value' => $all_flags[$result->userflag], ); $form['user_flag']['flag_explain'] = array( '#type' => 'item', '#title' => t('User flag explanation'), '#value' => $result->userflagexplain, ); $form['user_flag']['admin_flag'] = array( '#type' => 'value', '#value' => $result->adminflag, ); $form['user_flag']['user_is'] = array( '#type' => 'value', '#value' => $user_is, ); if (!$admin_notes = unserialize($result->adminnotes)) { $admin_notes = array(); } if (!$iuid_notes = unserialize($result->iuidmessages)) { $iuid_notes = array(); } if (!$auid_notes = unserialize($result->auidmessages)) { $auid_notes = array(); } $form['user_flag']['iuid_notes'] = array( '#type' => 'value', '#value' => $iuid_notes, ); $form['user_flag']['auid_notes'] = array( '#type' => 'value', '#value' => $auid_notes, ); $form['user_flag']['new_user_note'] = array( '#type' => 'textarea', '#title' => t('Response'), '#description' => t('Add your response and any other comments you have for the administrator here.'), ); if ($user_is == 'iuid') { $all_notes = $admin_notes + $iuid_notes; } else { $all_notes = $admin_notes + $auid_notes; } ksort($all_notes); $form['user_flag']['all_notes'] = array( '#type' => 'value', '#value' => $all_notes, ); $form['user_flag']['submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); $form['user_flag']['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); return $form; } // function nf_handshake_flag_reply() /** * Save the new data with the old. * * @param string $form_id * @param array $form_values * @return string */ function nf_handshake_flag_reply_submit($form_id, $form_values) { global $user; if (!(user_access('initiate handshake') || (user_access('accept handshake')))) { return ''; } switch ($form_values['op']) { case t('Save'): $current_datestamp = time(); $message = $form_values['user_flag']['new_user_note']; $user_is = $form_values['user_flag']['user_is']; if ($user_is == 'iuid') { $all_user_notes = $form_values['user_flag']['iuid_notes']; } else { $all_user_notes = $form_values['user_flag']['auid_notes']; } $all_user_notes[$current_datestamp] = array($user->uid => $message); $all_user_notes = serialize($all_user_notes); $admin_flag = NFHANDSHAKE_FURTHER_REVIEW; if ($user_is == 'iuid') { $sql = "UPDATE {nf_handshake_manage} SET adminflag = %d, iuidmessages = '%s' WHERE iuid = %d and auid = %d"; } else { $sql = "UPDATE {nf_handshake_manage} SET adminflag = %d, auidmessages = '%s' WHERE iuid = %d and auid = %d"; } if (!$success = db_query($sql, $admin_flag, $all_user_notes, $form_values['user_flag']['iuid'], $form_values['user_flag']['auid'])) { drupal_set_message('Updating nf_handshake_manage table failed. Logging...', 'error'); watchdog('nf_handshake', t('Unable to update nf_handshake_manage for iuid = %iuid and auid = %auid', array('%iuid' => $form_values['user_flag']['iuid'], '%auid' => $form_values['user_flag']['auid'])), WATCHDOG_ERROR); } break; case t('Cancel'): break; } return 'user/' .$user->uid. '/nf_handshake/inbox'; } // function nf_handshake_flag_reply_submit() /** * Present the form in a more usable manner. * * Display all data regarding the handshake including a table of all notes. Note that the UIDs that are not the parties involved will be * admins. * TODO maybe color rows depending on UID or IUID/AUID/Admin * @param array $form The form to be rendered. * @return string $output The HTML version of everything to render. */ function theme_nf_handshake_flag_reply($form) { $output = ''; $rows = array(); $header = array(t('Datestamp'), t('UID'), t('Message')); $fake_rows = array(); $fake_header = array(); //PHP4 Modified $iusername = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $form['user_flag']['iuid']['#value'])); $iusername = $iusername->name; $ausername = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $form['user_flag']['auid']['#value'])); $ausername = $ausername->name; $fake_rows[] = array('From: ' .$iusername, 'To: ' .$ausername, drupal_render($form['user_flag']['datestamp']), drupal_render($form['user_flag']['duration']), drupal_render($form['user_flag']['initial']), ); $output .= theme('table', $fake_header, $fake_rows, array('width' => '100%')); $output .= drupal_render($form['user_flag']['purpose']); $output .= drupal_render($form['user_flag']['flag']); $output .= drupal_render($form['user_flag']['flag_explain']); foreach ($form['user_flag']['all_notes']['#value'] as $date => $the_rest) { $the_date = date('M j Y - G:i:s A', $date); foreach ($the_rest as $uid => $message) { $rows[] = array($the_date, $uid, $message); } } if (empty($rows)) { $rows[] = array(t('No messages previously entered')); } $output .= theme('table', $header, $rows); $output .= drupal_render($form); return $output; } // function theme_nf_handshake_flag_reply() //-----------------------------------------Present or Deny viewing user data from handshakes----------------------------------------- /** * Deny viewing the user's data and give a reason. * * @param int $hstatus The status of the handshake * @param int $uid The User ID of the other user. * @return string the html link to proceed to the user's inbox. */ function nf_handshake_view_denied($hstatus = NULL, $uid = NULL) { global $user; if ($hstatus === NULL || $uid === NULL) { drupal_set_message('Error: you have arrived at this page without the proper data. Redirecting you to the main page.'); return ''; } $all_flags = nf_handshake_get_status_flags(); $message = t('You cannot view this user. You have already established a handshake request at some point, or they have with you. The current status shows that the request is or has been ' .$all_flags[$hstatus]. '.'); $values = variable_get('nf_handshake_settings', array('initiate_expire_unit' => 'Weeks', 'initiate_expire_number' => 1, 'reject_expire_unit' => 'Months', 'reject_expire_number' => 6)); $retry = $values['reject_expire_number']. ' ' .strtolower($values['reject_expire_unit']). '.'; switch ($hstatus) { case 0: $message .= t('If you were the initiator, you will not be able to retry a handshake for ' .$retry); break; case 2: $message .= t('There is a one week window for the user to respond to the request, after which it will expire.'); break; case 3: $message .= t('The user has reviewed the request but has not responded.'); break; case 4: $message .= t('The user has flagged the handshake request for administrative review.'); break; default: break; } drupal_set_message($message, 'error'); return l(t('Visit your own handshake inbox'), 'user/' .$user->uid. '/nf_handshake/inbox'); } // function nf_handshake_view_denied() /** * Present the handshook data for viewing. * * @param int $uid User ID of the one to view * @return string $output The html that will be displayed. */ function nf_handshake_view_user_data($uid = NULL) { global $user; $other_user = user_load(array('uid' => $uid)); $output = ''; $sql = "SELECT * FROM {nf_handshake} WHERE (auid = %d AND iuid = %d) OR (auid = %d AND iuid = %d)"; $request = db_fetch_object(db_query($sql, $user->uid, $uid, $uid, $user->uid)); //PHP4 Modified: $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $uid)); $username = $username->name; $used_fields = unserialize($request->hfields); $header = array(t('Field'), t("$username's shared data")); $rows = array(); $user_data = array(); $user_data_location = array(); //-----------------figure out which data types the user has created that contain profile data-------------------- $groups = _nf_handshake_get_groupnames(); $all_fields = _nf_handshake_get_cckfieldnames(); $sql = "SELECT n.nid, n.vid, n.type, n.title FROM {node} n WHERE n.uid = %d AND n.type = '%s'"; foreach ($all_fields as $type => $field) { $results = db_query($sql, $uid, $type); if (db_num_rows($results) > 1) { drupal_set_message('Error, you have more than one node of the content type ' .$type. '. Please contact the system administrator with this error message.', 'error'); return ''; } else { if (db_num_rows($results) < 1) { if (!module_exists('nf_registration_mod')) { drupal_set_message('You have not completed your own user profile. Some fields will be empty. You can not share information you do not provide.'); } $user_types[$type] = NULL; } else { $result = db_fetch_object($results); $user_types[$type] = $result; } } } //locate the user's data $sql2 = "SELECT type FROM {node_field} WHERE field_name = '%s'"; foreach ($all_fields as $type => $the_rest) { $type_data = content_types($type); foreach ($the_rest as $key => $value) { if ($user_types[$type] != NULL) { $result = db_fetch_object(db_query($sql2, $value)); $field = $type_data['fields'][$value]; $storage = content_database_info($field); $user_data_location[$type][$key] = $storage; } } } //retrieve the user's data and place it in rows foreach ($user_data_location as $type => $field_name) { foreach ($field_name as $key => $value) { foreach ($value as $key2 => $value2) { $table = $value['table']; if ($key2 == 'columns') { foreach ($value2 as $column_readable => $column_array) { $sql3 = "SELECT %s FROM {%s} WHERE nid = %d"; $result = db_fetch_object(db_query($sql3, $column_array['column'], $table, $user_types[$type]->nid)); $user_data[$type][$key][$column_readable] = $result->$column_array['column']; } } } } } foreach ($used_fields as $key4 => $value4) { if (($value4 === 0) || (substr($value4, -1) == 'X')) { continue; } if (strstr($key4, '::')) { $data_text = ''; $exp_val = explode('::', $key4); if (!empty($user_types[$exp_val[0]]) && $user_types[$exp_val[0]] != NULL) { foreach ($user_data[$exp_val[0]][$exp_val[1]] as $column => $data) { if (!empty($data)) { $data_text .= $data. '
'; } } } $rows[] = array(array('data' => $key4, 'width' => '20%'), array('data' => $data_text, 'width' => '*')); } else { foreach ($groups as $group => $the_rest) { if ($group == $key4) { $data_text = ''; foreach ($the_rest as $key3 => $value3) { $exp_val2 = explode('::', $key3); if (!empty($user_types[$exp_val2[0]]) && $user_types[$exp_val2[0]] != NULL) { foreach ($user_data[$exp_val2[0]][$exp_val2[1]] as $column => $data) { if (!empty($data)) { $data_text .= $data. '
'; } } } } $rows[] = array(array('data' => $key4, 'width' => '35%'), array('data' => $data_text, 'width' => '*')); } } } } $output .= theme('table', $header, $rows, array('width' => '100%')); $output .= '
'; $output .= t('Handshake initiated on: ') .date('M j Y', $request->datestamp). '    '; $output .= t('Handshake expires on: ') .date('M j Y', $request->duration). ''; $output .= '

Operations:
'; if (module_exists('privatemsg') && $other_user->privatemsg_allow == 1) { $return = 'privatemsg/msgto/' .$uid; $message_allowed = 1; } elseif (module_exists('contact') && $other_user->contact == 1) { $return = 'user/' .$uid. '/contact'; $message_allowed = 1; } if ($message_allowed) { $output .= l(t('Send this user a message'), $return, array('title' => t("Contact this user via this site's messaging system."))); } $output .= '
'; $output .= l(t('Revoke this handshake'), 'user/nf_handshake/revoke_confirm/' .$user->uid. '/' .$uid, array('title' => t("Changes status of this handshake to Rejected as if you didn't accept it in the first place."))); //we grab this again, but only if the auid is for the current user as they have the priviledge of extending the duration at will $sql = "SELECT * FROM {nf_handshake} WHERE auid = %d AND iuid = %d"; $request = db_fetch_object(db_query($sql, $user->uid, $uid)); $output .= '
'; if ($request) { $output .= l(t('Extend expiration date'), 'user/nf_handshake/extend_duration/' .$user->uid. '/' .$uid, array('title' => t("Because you did not initiate this handshake, you may extend the duration at any time."))); } else { $output .= l(t('Request expiration date extension'), 'user/nf_handshake/request_extension/' .$user->uid. '/' .$uid, array('title' => t("You initiated this handshake, so you must request duration extension of the other user."))); } $output .= '
'; $output .= l(t('Request handshake upgrade (expose more fields)'), 'user/nf_handshake/initiate/' .$user->uid. '/' .$uid. '/1', array('title' => t("You may ask the other user to expose more fields."))); $output .= '
'; $output .= l(t('Downgrade handshake (hide fields)'), 'user/' .$user->uid. '/nf_handshake/view_hsr/' .$uid. '/1', array('title' => t("You may revoke specific fields from the handshake at any time."))); return $output; } // function nf_handshake_view_user_data() /** * Confirm that a handshake is meant to be revoked. * * Note that what a revokation does is 'Reject' the handshake and establish the revoker as the auid regardless of whether they were originally the * iuid or the auid. This is what grants them the privilege of reestablishing the handshake during the waiting period. The waiting period is the time * until the handshake duration time is met and the CRON deletes the entry from the table as if no handshake took place. * * @param int $user_active The User ID of the person revoking the handshake. * @param int $user_passive The User ID of the other party. * @return array $form The form to be rendered. */ function nf_handshake_revoke_confirm($user_active = NULL, $user_passive = NULL) { if ($user_active == NULL || $user_passive == NULL) { drupal_goto(''); return; } $sql = "SELECT * FROM {nf_handshake} WHERE (iuid = %d AND auid = %d) OR (iuid = %d AND auid = %d)"; $result = db_fetch_object(db_query($sql, $user_active, $user_passive, $user_passive, $user_active)); $form['auid'] = array('#type' => 'value', '#value' => $user_active); $form['iuid'] = array('#type' => 'value', '#value' => $user_passive); $return_address = 'user/' .$user_passive; $username = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = %d", $user_passive)); $form = confirm_form($form, t('Are you sure you want to delete your handshake with %name?', array('%name' => $username->name)), $return_address, t('Deleting a handshake causes the handshake\'s status to be set to Rejected. Only the person that revokes the handshake can reestablish it before a waiting period elapses. This action cannot be undone.'), t('Revoke handshake'), t('Cancel')); return $form; } // function nf_handshake_revoke_confirm() /** * Implementation of forms api _submit call. Revokes a handshake by setting its status to 'Rejected'. * * @param string $form_id * @param mixed $form_values * @return string $return_address The path to return to after we've deleted the record. */ function nf_handshake_revoke_confirm_submit($form_id, $form_values) { $sql = "SELECT hfields FROM {nf_handshake} WHERE (iuid= %d AND auid = %d) OR (iuid= %d AND auid = %d)"; $result = db_fetch_object(db_query($sql, $form_values['iuid'], $form_values['auid'], $form_values['auid'], $form_values['iuid'])); $fields = unserialize($result->hfields); foreach ($fields as $field => $value) { if (substr($value, -1) == 'X') { $fields[$field] = 0; } } $sql = "SELECT hfields FROM {nf_handshake_manage} WHERE (iuid= %d AND auid = %d) OR (iuid= %d AND auid = %d)"; $result = db_fetch_object(db_query($sql, $form_values['iuid'], $form_values['auid'], $form_values['auid'], $form_values['iuid'])); if ($result) { $sql = "DELETE {nf_handshake_manage} WHERE (iuid= %d AND auid = %d) OR (iuid= %d AND auid = %d)"; $result = db_query($sql, $form_values['iuid'], $form_values['auid'], $form_values['auid'], $form_values['iuid']); } $sql = "UPDATE {nf_handshake} SET hstatus = %d, hfields = '%s', iuid = %d, auid = %d WHERE (iuid= %d AND auid = %d) OR (iuid= %d AND auid = %d)"; $success = db_query($sql, NFHANDSHAKE_REJECTED, serialize($fields), $form_values['iuid'], $form_values['auid'], $form_values['iuid'], $form_values['auid'], $form_values['auid'], $form_values['iuid']); if (!$success) { drupal_set_message('There was an error revoking the handshake.', 'error'); watchdog('nf_handshake', t('nf_handshake: unable to update table for %iuid and %auid to %hstatus.', array('%iuid' => $form_values['iuid'], '%auid' => $form_values['auid'], '%hstatus' => NFHANDSHAKE_REJECTED))); } else { drupal_set_message('You have successfully revoked the handshake.'); } return 'user'; } // function nf_handshake_revoke_confirm_submit() /** * The accepting user has the option of extending the duration of the handshake. This function will be called to do so. * It will also be called to answer an extension request by the original initiator. * * @param int $user_active The User ID of the person extending the handshake duration. * @param int $user_passive The User ID of the other party. * @return array $form The form to be rendered. */ function nf_handshake_extend_duration($user_active = NULL, $user_passive = NULL) { $sql = "SELECT duration FROM {nf_handshake} WHERE iuid = %d AND auid = %d"; $result = db_fetch_object(db_query($sql, $user_passive, $user_active)); $duration = date('M j Y', $result->duration); $form['passive'] = array( '#type' => 'value', '#value' => $user_passive, ); $form['active'] = array( '#type' => 'value', '#value' => $user_active, ); $form['old_duration'] = array( '#type' => 'value', '#value' => $result->duration, ); $form['duration'] = array( '#tree' => TRUE, '#type' => 'fieldset', '#collapsible' => FALSE, '#title' => t('Duration'), ); $form['duration']['note'] = array( '#type' => 'item', '#description' => t("Current expiration: $duration
You may add to the duration of this handshake below. This is useful for making a short duration a little bit longer as expiration approaches. The only way to shorten the duration is to revoke the handshake. To keep things as they are if you are responding to an extension request, select 0 days and click on Extend handshake duration. Otherwise click Cancel"), ); $form['duration']['unit'] = array( '#type' => 'select', '#title' => t('Time unit'), '#default_value' => 'Forever', '#options' => array('Days' => 'Days', 'Weeks' => 'Weeks', 'Months' => 'Months', 'Years' => 'Years', 'Forever' => 'Forever'), ); $form['duration']['number'] = array( '#type' => 'select', '#default_value' => 0, '#options' => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31), ); $form['extend'] = array( '#type' => 'submit', '#value' => t('Extend handshake duration'), ); $form['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel'), ); return $form; } // function nf_handshake_extend_duration() /** * Record the new duration settings. * * @param string $form_id * @param mixed $form_values * @return string The path to go to */ function nf_handshake_extend_duration_submit($form_id, $form_values) { $user_active = $form_values['active']; $user_passive = $form_values['passive']; $number = $form_values['duration']['number']; switch ($form_values['duration']['unit']) { case 'Days': $unit = 60*60*24; break; case 'Weeks': $unit = 60*60*24*7; break; case 'Months': $unit = 60*60*24*30; break; case 'Years': $unit = 60*60*24*365; break; case 'Forever': $unit = 60*60*24*10000; $number = 1; break; } $duration = $form_values['old_duration'] + ($unit*$number); $new_duration = date('M j Y', $duration); $sql = "UPDATE {nf_handshake} SET hstatus = %d, duration = %d WHERE iuid = %d AND auid = %d"; $success = db_query($sql, NFHANDSHAKE_ACCEPTED, $duration, $user_passive, $user_active); if (!$success) { drupal_set_message('There was an error processing the handshake extension.', 'error'); watchdog('nf_handshake', t('nf_handshake: unable to update table for %iuid and %auid to %duration.', array('%iuid' => $user_passive, '%auid' => $user_active, '%duration' => $duration))); } else { drupal_set_message("You have successfully extended the handshake. The new expiration date is: $new_duration."); } return drupal_goto('user'); } // function nf_handshake_extend_duration_submit() /** * The initiator of the handshake cannot extend the duration of it, but can request that it be done. * * @param int $user_active The User ID of the person requesting the handshake extension. * @param int $user_passive The User ID of the other party. * @return string The path to return to */ function nf_handshake_request_extention($user_active = NULL, $user_passive = NULL) { $sql = "UPDATE {nf_handshake} SET hstatus = %d WHERE iuid = %d AND auid = %d"; $success = db_query($sql, NFHANDSHAKE_EXTENSION_REQUESTED, $user_active, $user_passive); if (!$success) { drupal_set_message('There was an error requesting the handshake extension.', 'error'); watchdog('nf_handshake', t('nf_handshake: unable to update table for %iuid and %auid to %hstatus.', array('%iuid' => $user_active, '%auid' => $user_passive, '%hstatus' => NFHANDSHAKE_EXTENSION_REQUESTED))); } else { drupal_set_message('You have successfully requested the handshake be extended.'); } return drupal_goto('user'); } // function nf_handshake_request_extention() /** * Present the user with a listing of user with which he/she has handshakes in the accepted category. * * @return array $form The form to be rendered */ function nf_handshake_view_contacts() { global $user; //first get instances where this user was the initiator $sql = "SELECT nh.*, u.name FROM {nf_handshake} nh LEFT JOIN {users} u ON u.uid = nh.auid WHERE iuid = %d AND (hstatus = %d OR hstatus = %d OR (hstatus = %d AND duration > " .time(). "))ORDER BY name"; $iuid_accepted = db_query($sql, $user->uid, NFHANDSHAKE_ACCEPTED, NFHANDSHAKE_UPGRADE_REQUESTED, NFHANDSHAKE_EXTENSION_REQUESTED); while ($next_accepted = db_fetch_object($iuid_accepted)) { $form['handshakes_i'][$next_accepted->name] = array( '#type' => 'value', '#value' => $next_accepted, ); } //next get instances where this user was the initiator $sql = "SELECT nh.*, u.name FROM {nf_handshake} nh LEFT JOIN {users} u ON u.uid = nh.iuid WHERE auid = %d AND (hstatus = %d OR hstatus = %d OR (hstatus = %d AND duration > " .time(). ")) ORDER BY name"; $auid_accepted = db_query($sql, $user->uid, NFHANDSHAKE_ACCEPTED, NFHANDSHAKE_UPGRADE_REQUESTED, NFHANDSHAKE_EXTENSION_REQUESTED); while ($next_accepted = db_fetch_object($auid_accepted)) { $form['handshakes_a'][$next_accepted->name] = array( '#type' => 'value', '#value' => $next_accepted, ); } return $form; } // function nf_handshake_view_contacts() /** * Display the handshakes in tabular format * * @param array $form The form to render. * @return string $output The html to display. */ function theme_nf_handshake_view_contacts($form) { global $user; $output = ''; $rows = array(); $header = array(array('data' => t('Username'), 'field' => 'name', 'sort' => 'asc'), array('data' => t('Created'), 'field' => 'name'), array('data' => t('Expires'), 'field' => 'name'), array('data' => t('Operations'), 'colspan' => '5'), ); foreach (element_children($form['handshakes_i']) as $num => $users) { $data = $form['handshakes_i'][$users]['#value']; $username = $data->name; $datestamp = $data->datestamp; $duration = $data->duration; $uid = $data->auid; $other_user = user_load(array('uid' => $uid)); //construct messaging link if (module_exists('privatemsg') && $other_user->privatemsg_allow == 1) { $msgto = 'privatemsg/msgto/' .$uid; $message_allowed = 1; } elseif (module_exists('contact') && $other_user->contact == 1) { $msgto = 'user/' .$uid. '/contact'; $message_allowed = 1; } if ($message_allowed) { $contact = l(t('Contact'), $msgto, array('title' => t("Contact this user via this site's messaging system."))); } //construct revokation link $revoke = l(t('Revoke'), 'user/nf_handshake/revoke_confirm/' .$user->uid. '/' .$uid, array('title' => t("Changes status of this handshake to Rejected as if you didn't accept it in the first place."))); //construct expiration extension link $extend = l(t('Request extension'), 'user/nf_handshake/request_extension/' .$user->uid. '/' .$uid, array('title' => t("You initiated this handshake, so you must request duration extension of the other user."))); //construct upgrade link $upgrade = l(t('Request upgrade'), 'user/nf_handshake/initiate/' .$user->uid. '/' .$uid. '/1', array('title' => t("You may ask the other user to expose more fields."))); //construct downgrade link $downgrade = l(t('Downgrade'), 'user/' .$user->uid. '/nf_handshake/view_hsr/' .$uid. '/1', array('title' => t("You may revoke specific fields from the handshake at any time."))); $rows[] = array(l($username, 'user/' .$uid), date('M j Y', $datestamp), date('M j Y', $duration), $contact, $revoke, $extend, $upgrade, $downgrade); } foreach (element_children($form['handshakes_a']) as $num => $users) { $data = $form['handshakes_a'][$users]['#value']; $username = $data->name; $datestamp = $data->datestamp; $duration = $data->duration; $uid = $data->iuid; $other_user = user_load(array('uid' => $uid)); //construct messaging link if (module_exists('privatemsg') && $other_user->privatemsg_allow == 1) { $msgto = 'privatemsg/msgto/' .$uid; $message_allowed = 1; } elseif (module_exists('contact') && $other_user->contact == 1) { $msgto = 'user/' .$uid. '/contact'; $message_allowed = 1; } if ($message_allowed) { $contact = l(t('Contact'), $msgto, array('title' => t("Contact this user via this site's messaging system."))); } //construct revokation link $revoke = l(t('Revoke'), 'user/nf_handshake/revoke_confirm/' .$user->uid. '/' .$uid, array('title' => t("Changes status of this handshake to Rejected as if you didn't accept it in the first place."))); //construct expiration extension link $extend = l(t('Extend expiration'), 'user/nf_handshake/extend_duration/' .$user->uid. '/' .$uid, array('title' => t("Because you did not initiate this handshake, you may extend the duration at any time."))); //construct upgrade link $upgrade = l(t('Request upgrade'), 'user/nf_handshake/initiate/' .$user->uid. '/' .$uid. '/1', array('title' => t("You may ask the other user to expose more fields."))); //construct downgrade link $downgrade = l(t('Downgrade'), 'user/' .$user->uid. '/nf_handshake/view_hsr/' .$uid. '/1', array('title' => t("You may revoke specific fields from the handshake at any time."))); $rows[] = array(l($username, 'user/' .$uid), date('M j Y', $datestamp), date('M j Y', $duration), $contact, $revoke, $extend, $upgrade, $downgrade); } $output .= theme('table', $header, $rows, array('width' => '100%')); $output .= drupal_render($form); return $output; } // function theme_nf_handshake_view_contacts() //-----------------------------------------Helper Functions----------------------------------------- //-----------------------------------------Helper Functions----------------------------------------- //-----------------------------------------Helper Functions----------------------------------------- /** * return an array that can be used in a drop down selector and which corresponds to the constants for the user flags. */ function nf_handshake_get_status_flags() { return array(0 => 'Rejected', 1 => 'Accepted', 2 => 'Pending', 3 => 'Reviewed by user', 4 => 'Flagged', 5 => 'Expired', 6 => 'Extension requested', 7 => 'Upgrade requested'); } // function nf_handshake_get_status_flags() /** * return an array that can be used in a drop down selector and which corresponds to the constants for the user flags. */ function nf_handshake_get_user_flags() { return array(0 => 'None', 1 => 'Age inappropriate', 2 => 'Spam', 3 => 'Harassment', 4 => 'Questionable purpose', 5 => 'Other'); } // function nf_handshake_get_user_flags() /** * return an array that can be used in a drop down selector and which corresponds to the constants for the admin flags. */ function nf_handshake_get_admin_flags() { return array(0 => 'None', 10 => 'Further admin review', 20 => 'T&S violation', 30 => 'First warning', 40 => 'Second warning', 50 => 'Suspend user', 60 => 'Alert parents', 70 => 'Send to IUID for comment', 80 => 'Send to AUID for comment'); } // function nf_handshake_get_admin_flags() /** * Fetch the number of unread handshake requests for display in various places. Cache it so we don't have to query the database so much. * * @param int $uid The user with the unread requests. * @return array $cache_pending Those handshake requests with the pending flag. */ function nf_handshake_get_new_handshake_requests($uid = 0) { global $user; static $cache_pending = array(); if ($uid == 0) { $uid = $user->uid; } if (!isset($cache_pending[$uid])) { $cache_pending[$uid] = (int)db_result(db_query('SELECT COUNT(*) FROM {nf_handshake} WHERE auid = %d AND hstatus = %d', $uid, NFHANDSHAKE_PENDING)); } return $cache_pending[$uid]; } // function nf_handshake_get_new_handshake_requests() /** * Fetch the number of read but unresponded handshake requests for display in various places. Cache it so we don't have to query the database so much. * * @param int $uid The user with the unread requests. * @return array $cache_pending Those handshake requests with the reviewed flag. */ function nf_handshake_get_read_handshake_requests($uid = 0) { global $user; static $cache_reviewed = array(); if ($uid == 0) { $uid = $user->uid; } if (!isset($cache_reviewed[$uid])) { $cache_reviewed[$uid] = (int)db_result(db_query('SELECT COUNT(*) FROM {nf_handshake} WHERE auid = %d AND hstatus = %d', $uid, NFHANDSHAKE_REVIEWED)); } return $cache_reviewed[$uid]; } // function nf_handshake_get_read_handshake_requests() /** * Fetch the number of flag response requests for display in various places. Cache it so we don't have to query the database so much. * * @param int $uid The user with the unread requests. * @return array $cache_pending Those handshake requests with the reviewed flag. */ function nf_handshake_get_read_handshake_flags_iuid($uid = 0) { global $user; static $cache_flags_i = array(); if ($uid == 0) { $uid = $user->uid; } if (!isset($cache_flags_i[$uid])) { $cache_flags_i[$uid] = (int)db_result(db_query('SELECT COUNT(*) FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE nh.iuid = %d AND nhm.adminflag = %d AND nh.hstatus = %d', $uid, NFHANDSHAKE_IUID_COMMENT, NFHANDSHAKE_FLAGGED)); } return $cache_flags_i[$uid]; } // function nf_handshake_get_read_handshake_flags_iuid() /** * Fetch the number of flag response requests for display in various places. Cache it so we don't have to query the database so much. * * @param int $uid The user with the unread requests. * @return array $cache_pending Those handshake requests with the reviewed flag. */ function nf_handshake_get_read_handshake_flags_auid($uid = 0) { global $user; static $cache_flags_a = array(); if ($uid == 0) { $uid = $user->uid; } if (!isset($cache_flags_a[$uid])) { $cache_flags_a[$uid] = (int)db_result(db_query('SELECT COUNT(*) FROM {nf_handshake} nh LEFT JOIN {nf_handshake_manage} nhm ON nh.auid = nhm.auid AND nh.iuid = nhm.iuid WHERE nh.auid = %d AND nhm.adminflag = %d AND nh.hstatus = %d', $uid, NFHANDSHAKE_AUID_COMMENT, NFHANDSHAKE_FLAGGED)); } return $cache_flags_a[$uid]; } // function nf_handshake_get_read_handshake_flags_auid() /** * Returns an array of groupnames, and the fieldnames they group. * Takes the form of array(group1 => array(contenttype1 => fieldname1, contenttype1 => fieldname2, ...), group2 => array(contenttype2 => fieldname3, contenttype5 => fieldname4, ...) */ function _nf_handshake_get_groupnames() { return variable_get('nf_handshake_groupnames', array()); } // function _nf_handshake_get_groupnames() /** * Returns an array of cck field names from which to draw profile data. * Takes the form array(Content_type1 => array(cck_field1 => cck_field1, cck_field2 => cck_field2), Content_type2 => array(cck_field3 => cck_field4...)) */ function _nf_handshake_get_cckfieldnames() { return variable_get('nf_handshake_cckfieldnames', array()); } // function _nf_handshake_get_cckfieldnames()