You are here

function userprotect_menu in User protect 5

Same name and namespace in other branches
  1. 6 userprotect.module \userprotect_menu()
  2. 7 userprotect.module \userprotect_menu()

Implementation of hook_menu().

File

./userprotect.module, line 316

Code

function userprotect_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $admin = user_access('administer userprotect');

    // Admin page link.
    $items[] = array(
      'path' => 'admin/user/userprotect',
      'title' => t('User Protect'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'userprotect_protected_users',
      ),
      'description' => t('Protect inidividual users and/or roles from editing operations.'),
      'access' => $admin,
    );

    // Default tab.
    $items[] = array(
      'path' => 'admin/user/userprotect/protected_users',
      'title' => t('Protected users'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'access' => $admin,
      'weight' => 1,
    );

    // Protected roles tab.
    $items[] = array(
      'path' => 'admin/user/userprotect/protected_roles',
      'title' => t('Protected roles'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'userprotect_protected_roles',
      ),
      'type' => MENU_LOCAL_TASK,
      'access' => $admin,
      'weight' => 2,
    );

    // Administrator ypass tab.
    $items[] = array(
      'path' => 'admin/user/userprotect/administrator_bypass',
      'title' => t('Administrator bypass'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'userprotect_administrator_bypass',
      ),
      'type' => MENU_LOCAL_TASK,
      'access' => $admin,
      'weight' => 3,
    );

    // Default settings.
    $items[] = array(
      'path' => 'admin/user/userprotect/protection_defaults',
      'title' => t('Protection defaults'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'userprotect_protection_defaults',
      ),
      'type' => MENU_LOCAL_TASK,
      'access' => $admin,
      'weight' => 4,
    );

    // Remove a user from being protected.
    $items[] = array(
      'path' => 'userprotect/delete',
      'title' => t('Delete protected user'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'userprotect_protected_users_delete_form',
      ),
      'type' => MENU_CALLBACK,
      'access' => user_access('administer userprotect'),
    );
  }
  else {
    $uid = arg(1);
    if (arg(0) == 'user' && is_numeric($uid)) {
      $account = user_load(array(
        'uid' => $uid,
      ));
      switch (arg(2)) {
        case 'edit':

          // Check to see if the user's roles are protecting edits, or the user
          // themselves is protected
          if (!userprotect_check_bypass('up_edit') && userprotect_get_user_protection($account, 'up_edit')) {

            // If so, set a message and kick 'em out.
            drupal_set_message(t('%user is currently being protected from any edits.', array(
              '%user' => $account->name,
            )), 'error');
            drupal_goto("user/{$uid}");
          }
          break;

        // Check to see if the user's roles are protecting deletion, or the user
        // themselves is protected
        case 'delete':
          if (!userprotect_check_bypass('up_delete') && userprotect_get_user_protection($account, 'up_delete')) {

            // If so, set a message and kick 'em out.
            drupal_set_message(t('%user is currently being protected from deletion.', array(
              '%user' => $account->name,
            )), 'error');
            drupal_goto("user/{$uid}");
          }
          break;
      }
    }
  }
  return $items;
}