You are here

function user_relationships_request_validate in User Relationships 5

Same name and namespace in other branches
  1. 5.2 user_relationships_actions.inc \user_relationships_request_validate()

Validate relationship request.

File

./user_relationships_actions.inc, line 109

Code

function user_relationships_request_validate($form_id, &$form_values) {
  $requester = $form_values['requester'];
  $requestee = $form_values['requestee'];
  if (user_access('can have relationship', $requestee)) {
    $current_relationships = _user_relationships_current_relationships($requester, $requestee);
    if (!db_result(db_query("SELECT COUNT(*) FROM {user_relationship_types}" . ($current_relationships ? " WHERE rtid NOT IN (%s) ORDER BY name" : ''), implode(',', array_keys($current_relationships))))) {
      drupal_set_message(user_relationships_get_message('too_many_relationships'));
      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_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_get_message('not_accepting_requests'));
    drupal_goto();
  }
}