You are here

total_control.module in Total Control Admin Dashboard 7.2

File

total_control.module
View source
<?php

/**
 * @file
 *
 * This module enables an administrative dashboard.
 */
include_once 'includes/total_control.inc';
include_once 'includes/total_control.views_default.inc';
define('TOTAL_CONTROL_REQUIRED_PANELS_API', '3');
define('TOTAL_CONTROL_REQUIRED_VIEWS_API', '2');

// This is the name of the dashboard as the page manager module sees it via the page task.
define('TOTAL_CONTROL_DASHBOARD_PANEL_NAME', 'dashboard');
define('TOTAL_CONTROL_MINIMUM_VERSION', 2);
define('TOTAL_CONTROL_VERSION', 2);

/** 
 * Implements hook_perm().
 *
 * Adds permissions for access to the total control dashboard
 */
function total_control_permission() {
  return array(
    'have total control' => array(
      'title' => t('Have total control'),
      'description' => t('See the Total Control administrative dashboard.'),
    ),
    'administer total control' => array(
      'title' => t('Administer total control'),
      'description' => t('Adjust the settings for the Total Control administrative dashboard.'),
    ),
  );
}

/** 
 * Implements hook_menu().
 *
 * Adds the total control dashboard
 */
function total_control_menu() {
  $items = array();
  $items['admin/config/administration/control'] = array(
    'title' => 'Total Control Dashboard',
    'description' => 'Adjust dashboard settings.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'total_control_admin_settings',
    ),
    'access arguments' => array(
      'administer total control',
    ),
    'file' => 'total_control.admin.inc',
  );

  // Add a tab for the dashboard.
  $items['admin/dashboard/overview'] = array(
    'title' => 'Dashboard',
    'description' => 'Total Control admin dashboard',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -100,
  );
  return $items;
}

/**
* Implements hook_menu_local_tasks_alter().
*/
function total_control_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  if ($router_item['page_callback'] == 'views_page' && $router_item['page_arguments'][0] == 'control_content') {
    if ($router_item['page_arguments'][1]) {
      $pattern = '/^page_tc_([\\S]*)/';
      if (preg_match($pattern, $router_item['page_arguments'][1], $matches)) {
        $content_type = node_type_get_type($matches[1]);
        if (user_access('create ' . $content_type->type . ' content')) {
          $type_url_str = str_replace('_', '-', $content_type->type);
          $item = menu_get_item('node/add/' . $type_url_str);
          $item['title'] = t('Add %type', array(
            '%type' => $content_type->name,
          ));
          if ($item['access']) {
            $data['actions']['output'][] = array(
              '#theme' => 'menu_local_action',
              '#link' => $item,
            );
          }
        }
      }
    }
  }
}

/**
 * Implements hook_form_alter().
 *
 * Adds views adjustment handling when content types are added or removed
 */
function total_control_form_alter(&$form, $form_state, $form_id) {
  if ('node_type_form' == $form_id) {
    $form['#submit'][] = 'total_control_add_type_submit';
  }
  if ('node_type_delete_confirm' == $form_id) {
    $form['#submit'][] = 'total_control_remove_type_submit';
  }
}

/**
 * Implements hook_user_login().
 * Redirects to the dashboard if configured.
 */
function total_control_user_login(&$edit, $account) {

  // Don't redirect for password reset.
  if (!(arg(0) == 'user' && arg(1) == 'reset')) {

    // Check for permission to use total control.
    if (user_access('have total control', $account)) {

      // Check for redirect to dashboard setting.
      if (variable_get('total_control_login_redirect', 0) == 1) {

        // TODO Make sure destination is not already set.

        //if (!isset($_GET['destination'])) {

        // TODO worry about overlay module.
        $_GET['destination'] = 'admin/dashboard';

        //}
      }
    }
  }
}

/**
 * Implements hook_ctools_plugin_dierctory().
 */
function total_control_ctools_plugin_directory($module, $plugin) {
  if ($module == 'ctools' && !empty($plugin)) {
    return "plugins/{$plugin}";
  }
}

/**
 * Implements hook_ctools_plugin_api().
 */
function total_control_ctools_plugin_api($module, $api) {
  if ($module == 'panels_mini' && $api == 'panels_default') {
    return array(
      'version' => 1,
    );
  }
  if ($module == 'page_manager' && $api == 'pages_default') {
    return array(
      'version' => 1,
    );
  }
}

/**
 * Implements hook_views_api().
 *
 * Register View API information. This is required for your module to have
 * its include files loaded; for example, when implementing
 * hook_views_default_views().
 *
 * @return
 *   An array with the following possible keys:
 *   - api:  (required) The version of the Views API the module implements.
 *   - path: (optional) If includes are stored somewhere other than within
 *       the root module directory or a subdirectory called includes, specify
 *       its path here.
 */
function total_control_views_api() {
  return array(
    'api' => 2,
  );
}

/**
 * Implements hook_theme().
 *
 * Adds theme functions for the output of content panes.
 */
function total_control_theme() {
  return array(
    'total_control_create' => array(
      'variables' => array(
        'create' => array(),
      ),
      'file' => 'total_control.theme.inc',
    ),
    'total_control_overview' => array(
      'variables' => array(
        'content' => array(),
        'users' => array(),
      ),
      'file' => 'total_control.theme.inc',
    ),
    'total_control_overview_content' => array(
      'variables' => array(
        'overview' => array(),
      ),
      'file' => 'total_control.theme.inc',
    ),
    'total_control_overview_user' => array(
      'variables' => array(
        'overview' => array(),
      ),
      'file' => 'total_control.theme.inc',
    ),
    'total_control_admin_table' => array(
      'variables' => array(
        'header' => array(),
        'rows' => array(),
        'link' => FALSE,
      ),
      'file' => 'total_control.theme.inc',
    ),
  );
}