You are here

function i18n_access_user in Translation Access 6

Implementation of hook_user().

File

./i18n_access.module, line 13
file_description

Code

function i18n_access_user($op, &$edit, &$account, $category = NULL) {
  if ($op == 'form' && $category == 'account' || $op == 'register') {
    $form['i18n_access'] = array(
      '#type' => 'fieldset',
      '#title' => t('Translation access'),
      '#tree' => 0,
      '#access' => user_access('administer users'),
    );
    $form['i18n_access']['i18n_access'] = array(
      '#type' => 'checkboxes',
      '#options' => array(
        I18N_ACCESS_LANGUAGE_NEUTRAL => t('Language neutral'),
      ) + locale_language_list('name'),
      '#default_value' => i18n_access_load_permissions($account),
      '#description' => t('Select the languages that this user should have permission to create and edit content for.'),
    );
    return $form;
  }
  elseif (($op == 'insert' || $op == 'submit') && $category == 'account') {

    // see user_admin_perm_submit()
    if (isset($edit['i18n_access'])) {
      db_query('DELETE FROM {i18n_access} WHERE uid = %d', $account->uid);
      $edit['i18n_access'] = array_filter($edit['i18n_access']);
      if (count($edit['i18n_access'])) {
        db_query("INSERT INTO {i18n_access} (uid, perm) VALUES (%d, '%s')", $account->uid, implode(', ', array_keys($edit['i18n_access'])));
      }
      unset($edit['i18n_access']);
    }
  }
}