$info) { $arguments = array($element['#value']); if (isset($info['valid_options'])) { $arguments[] = $info['valid_options']; } if (!call_user_func_array($validation, $arguments)) { form_set_error($element['#name'], $info['msg']); } } } /** * Validate the submitted relationship type */ function user_relationships_ui_type_edit_form_validate($form_id, &$form_values) { $rtype = (object)$form_values; // find a relationship type with the name we're trying to save // if it's an update action check to see that the rtypes match // otherwise it's just invalid if ( ($found_rt = user_relationships_type_load(array('name' => $rtype->name))) && ($form_values['action'] == 'update' ? $found_rt->rtid != $rtype->rtid : TRUE) ) { form_set_error('name', t('%name has already been used.', array('%name' => $form_values['name']))); } if (!is_numeric($rtype->expires_val) || (int)$rtype->expires_val < 0) { form_set_error('expires_val', t('Expiration period must be an integer greater than or equal to 0.')); } } /** * Process the relationship edit page form submission. */ function user_relationships_ui_type_edit_form_submit($form_id, &$form_values) { $rtype = (object)$form_values; $action = $form_values['action'] == 'add' ? t('added') : t('updated'); if (user_relationships_type_save($rtype)) { drupal_set_message(t('Relationship %name has been @action.', array('%name' => $rtype->name, '@action' => $action))); watchdog( 'u_relationship', t('User Relationships form: relationship %name @action.', array('%name' => $rtype->name, '@action' => $action)), WATCHDOG_NOTICE, l(t('view'), 'admin/user/user_relationship/types') ); } else { drupal_set_message( t('Relationship %name has not been @action. There is a problem, please contact the site admin', array('%name' => $rtype->name, '@action' => $action)) ); } return 'admin/user/relationships'; } /** * Process relationship delete form submission. */ function user_relationships_ui_type_delete_form_submit($form_id, &$form_values) { $rtid = $form_values['rtid']; $rtype = user_relationships_type_load($rtid); user_relationships_type_delete($rtid); drupal_set_message(t('Relationship %name has been deleted.', array('%name' => $rtype->name))); watchdog('u_relationship', t('User Relationships form: relationship %name deleted.', array('%name' => $rtype->name)), WATCHDOG_NOTICE); return 'admin/user/relationships'; } /** * Validate relationship request. */ function user_relationships_ui_request_form_validate($form_id, &$form_values) { $requester = $form_values['requester']; $requestee = $form_values['requestee']; if (user_access('can have relationship', $requestee)) { $current_relationships = user_relationships_load(array('between' => array($requester->uid, $requestee->uid))); if (!db_result(db_query( "SELECT COUNT(*) FROM {user_relationship_types}" . ($current_relationships ? " WHERE rtid NOT IN (%s) GROUP BY name ORDER BY name" : ''), implode(',', array_keys($current_relationships)) ))) { drupal_set_message(user_relationships_ui_get_message('too_many_relationships'), 'error'); drupal_goto(); } else if ($current_relationships[$form_values['rtid']]) { $message_name = $current_relationships[$form_values['rtid']]->approved ? 'exisitng_relationship' : 'existing_request'; form_set_error('rtid', user_relationships_ui_get_message($message_name, array( '%requester' => $requester->name, '%requestee' => $requestee->name, '%relationship_name' => $$current_relationships[$form_values['rtid']]->name, '%relationship_plural_name' => $$current_relationships[$form_values['rtid']]->plural_name ))); } } else { drupal_set_message(user_relationships_ui_get_message('not_accepting_requests')); drupal_goto(); } } /** * Process relationship request. */ function user_relationships_ui_request_submit($form_id, &$form_values) { $requester = $form_values['requester']; $requestee = $form_values['requestee']; $relationship_type = user_relationships_type_load(array('rtid' => $form_values['rtid'])); $relationship = user_relationships_request_relationship($requester, $requestee, $relationship_type); if ($relationship === FALSE) { drupal_set_message(user_relationships_ui_get_message('unknown_error', $relationship)); } $relationship->requester = $requester; $relationship->requestee = $requestee; $relationship->type = $relationship_type; drupal_set_message(user_relationships_ui_get_message(($relationship->approved ? 'pre_approved' : 'submitted'), $relationship)); return 'user'; } /** * Approve, Disapprove, or Cancel a relationship request */ function user_relationships_ui_pending_requested_submit($form_id, &$form_values) { global $user; $relationship = user_relationships_load($form_values['rid'], array('include_user_info' => TRUE)); $requester = $relationship->requester; $requestee = $relationship->requestee; switch ($form_values['action']) { case 'approve': $relationship->approved = TRUE; user_relationships_save_relationship($relationship, $form_values['action']); drupal_set_message(user_relationships_ui_get_message('accepted', $relationship)); break; case 'cancel': case 'disapprove': user_relationships_delete_relationship($relationship, $user, $form_values['action']); drupal_set_message(user_relationships_ui_get_message($form_values['action'], $relationship)); break; default: drupal_set_message(user_relationships_ui_get_message('default')); } return "user/{$form_values['viewed_id']}/relationships/requests"; } /** * Remove a relationship */ function user_relationships_ui_remove_submit($form_id, &$form_values) { global $user; $relationship = user_relationships_load($form_values['rid'], array('include_user_info' => TRUE)); $requester = $relationship->requester; $requestee = $relationship->requestee; user_relationships_delete_relationship($relationship, $user); drupal_set_message(user_relationships_ui_get_message('removed', $relationship)); return "user/{$form_values['viewed_id']}/relationships"; }