You are here

function ad_permission_menu in Advertisement 5.2

@file Provide granular permissions for advertisements.

Copyright (c) 2008. Jeremy Andrews <jeremy@tag1consulting.com>.

File

permission/ad_permission.module, line 11
Provide granular permissions for advertisements.

Code

function ad_permission_menu($may_cache) {
  if (!$may_cache) {
    if (arg(0) == 'node' && is_numeric(arg(1)) && ad_permission(arg(1), 'manage owners')) {
      $node = node_load(arg(1));
      if ($node->adtype) {
        $items[] = array(
          'path' => "node/{$node->nid}/adowners",
          'access' => ad_permission($node->nid, 'manage owners'),
          'title' => t('Ad owners'),
          'callback' => 'ad_permission_owners_overview',
          'callback arguments' => array(
            $node,
          ),
          'type' => MENU_LOCAL_TASK,
          'weight' => 5,
        );
        $items[] = array(
          'path' => "node/{$node->nid}/adowners/list",
          'access' => ad_permission($node->nid, 'manage owners'),
          'title' => t('List'),
          'type' => MENU_DEFAULT_LOCAL_TASK,
          'weight' => 0,
        );
        if (is_numeric(arg(3))) {
          $uid = arg(3);
          $ad_user = user_load(array(
            'uid' => $uid,
          ));
          $items[] = array(
            'path' => "node/{$node->nid}/adowners/{$uid}/permissions",
            'title' => t('!owner\'s permissions', array(
              '!owner' => $ad_user->name,
            )),
            'access' => ad_permission($node->nid, 'manage owners'),
            'callback' => 'drupal_get_form',
            'callback arguments' => array(
              'ad_permission_owner',
              $node->nid,
              $uid,
            ),
            'type' => MENU_LOCAL_TASK,
            'weight' => 2,
          );
          $items[] = array(
            'path' => "node/{$node->nid}/adowners/{$uid}/remove",
            'callback' => 'drupal_get_form',
            'callback arguments' => array(
              'ad_permission_owner_remove',
              $node->nid,
              $uid,
            ),
            'type' => MENU_CALLBACK,
            'weight' => 6,
          );
        }
        else {
          $items[] = array(
            'path' => "node/{$node->nid}/adowners/add",
            'access' => ad_permission($node->nid, 'manage owners'),
            'title' => t('Add'),
            'callback' => 'drupal_get_form',
            'callback arguments' => array(
              'ad_permission_owner_add_form',
              $node,
            ),
            'type' => MENU_LOCAL_TASK,
            'weight' => 4,
          );
        }
      }
    }
  }
  return $items;
}