You are here

function ad_owners_add_form_validate in Advertisement 6.3

Same name and namespace in other branches
  1. 5 ad.module \ad_owners_add_form_validate()
  2. 6 owners/ad_owners.module \ad_owners_add_form_validate()
  3. 6.2 owners/ad_owners.module \ad_owners_add_form_validate()
  4. 7 owners/ad_owners.module \ad_owners_add_form_validate()

File

owners/ad_owners.module, line 330
Enhances the ad module to support ad owners.

Code

function ad_owners_add_form_validate($form, &$form_state) {
  $owner = user_load(array(
    'name' => $form_state['values']['username'],
  ));
  if (!is_object($owner)) {
    form_set_error('username', t('The specified username %username does not exist.', array(
      '%username' => $form_state['values']['username'],
    )));
  }
  else {
    if (db_result(db_query('SELECT oid FROM {ad_owners} WHERE uid = %d AND aid = %d', $owner->uid, $form_state['values']['aid']))) {
      form_set_error('username', t('The specified user %username is already an owner of this ad.', array(
        '%username' => $form_state['values']['username'],
      )));
    }
    else {
      if (!user_access('edit own advertisements', $owner) && !user_access('administer advertisements', $owner)) {
        form_set_error('username', t('The specified user %username does not have <em>edit own advertisements</em> nor <em>administer advertisements</em> permissions.  The user must be !assigned to a !role with these privileges before you can add them as an ad owner.', array(
          '%username' => $form_state['values']['username'],
          '!assigned' => l(t('assigned'), "user/{$owner->uid}/edit"),
          '!role' => l(t('role'), 'admin/user/permissions'),
        )));
      }
    }
  }
  module_invoke_all('adowners', 'validate', $owner, $form_state['values']['aid']);
}