You are here

function support_admin_client_validate in Support Ticketing System 6

File

./support.admin.inc, line 219
support.admin.inc

Code

function support_admin_client_validate($form, &$form_state) {
  if (preg_match('/[&*(),<>?\\[\\]]/', $form_state['values']['name'])) {
    form_set_error('name', t('You have entered an unsupported character.  The following characters can not be used in the client name: &*(),<>?[]'));
  }
  if (!empty($form_state['values']['autosubscribe'])) {
    $subscribe = array();
    $autosubscribe = explode(',', $form_state['values']['autosubscribe']);
    foreach ($autosubscribe as $name) {
      $account = user_load(array(
        'name' => trim($name),
      ));
      if (!is_object($account) || !$account->uid) {
        form_set_error('autosubscribe', t('User %username does not exist.', array(
          '%username' => $name,
        )));
      }
      else {
        if (!user_access('access ' . $form_state['values']['name'] . ' tickets', $account) && !user_access('administer support')) {
          form_set_error('autosubscribe', t('User %username does not have permission to access %client tickets.', array(
            '%username' => $name,
            '%client' => $form_state['values']['name'],
          )));
        }
      }
    }
  }
  if (!empty($form_state['values']['autoassign'])) {
    $autoassign = $form_state['values']['autoassign'];
    switch ($autoassign) {
      case '<nobody>':
      case '<creator>':
        break;
      default:
        $account = user_load(array(
          'name' => trim($form_state['values']['autoassign']),
        ));
        $client = $form_state['values']['name'];
        if (empty($account)) {
          form_set_error('autoassign', t('Invalid %field user, %username does not exist.', array(
            '%field' => t('auto-assign'),
            '%username' => trim($form_state['values']['autoassign']),
          )));
        }
        else {
          if (!user_access('administer support', $account) && !user_access("access {$client} tickets", $account)) {
            form_set_error('autoassign', t('Invalid %field  user, %username does not have permission to access %client tickets.', array(
              '%field' => t('auto-assign'),
              '%username' => trim($form_state['values']['autoassign']),
              '%client' => $client,
            )));
          }
        }
        break;
    }
  }
  if (!empty($form_state['values']['domains'])) {
    _support_validate_domains('domains', explode(',', $form_state['values']['domains']));
  }
  if ($form_state['values']['integrate_email'] && !function_exists('imap_open')) {
    form_set_error('integrate_email', t('PHP must be !compiled in order to enable inbound email integration.  The IMAP functions are required to support the IMAP, POP3, and local mailbox access methods.', array(
      '!compiled' => l(t('compiled with the IMAP extension'), 'http://php.net/imap'),
    )));
  }
}