<?php

require_once "api/tripal_db.api.inc";
require_once "includes/tripal_db.admin.inc";

/**
 * @defgroup tripal_db DB Module
 * @ingroup tripal_modules
 */

/**
 *
 * @ingroup tripal_db
 */
function tripal_db_init() {

  // add the tripal_db JS and CSS
  drupal_add_css(drupal_get_path('module', 'tripal_db') . '/theme/css/tripal_db.css');
  drupal_add_js(drupal_get_path('module', 'tripal_db') . '/theme/js/tripal_db.js');
}
/**
 *
 * @ingroup tripal_db
 */
function tripal_db_menu() {
  $items = array();

  $items['admin/tripal/chado/tripal_db'] = array(
    'title' => 'Databases',
    'description' => 'References to External Database sites such as NCBI',
    'page callback' => 'tripal_db_admin_db_listing',
    'access arguments' => array('administer db cross-references'),
    'type' => MENU_NORMAL_ITEM,
  );

  $items['admin/tripal/chado/tripal_db/help'] = array(
    'title' => 'Help',
    'description' => "A description of the Tripal Database module including a short description of it's usage.",
    'page callback' => 'theme',
    'page arguments' => array('tripal_db_admin'),
    'access arguments' => array('administer db cross-references'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 10
  );

  $items['admin/tripal/chado/tripal_db/edit/%'] = array(
    'title' => 'Edit a Database Reference',
    'description' => 'Edit existing Database References.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_db_db_edit_form',5),
    'access callback' => 'user_access',
    'access arguments' => array('administer db cross-references'),
    'type' => MENU_CALLBACK,
  );

  $items['admin/tripal/chado/tripal_db/add'] = array(
    'title' => 'Create a Database Reference',
    'description' => 'Create a new reference to an External Database.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_db_db_add_form'),
    'access callback' => 'user_access',
    'access arguments' => array('administer db cross-references'),
    'type' => MENU_CALLBACK,
  );

  $items['admin/tripal/chado/tripal_db/views/dbs/enable'] = array(
    'title' => 'Enable Database Administrative View',
    'page callback' => 'tripal_views_admin_enable_view',
    'page arguments' => array('tripal_db_admin_dbs', 'admin/tripal/chado/tripal_db'),
    'access arguments' => array('administer controlled vocabularies'),
    'type' => MENU_CALLBACK,
  );
  $items['admin/tripal/chado/tripal_db/views/dbxrefs/enable'] = array(
    'title' => 'Enable Reference Administrative View',
    'page callback' => 'tripal_views_admin_enable_view',
    'page arguments' => array('tripal_db_admin_dbxrefs', 'admin/tripal/chado/tripal_db'),
    'access arguments' => array('administer controlled vocabularies'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Implements hook_help()
 * Purpose: Adds a help page to the module list
 */
function tripal_db_help ($path, $arg) {
  if ($path == 'admin/help#tripal_db') {
    return theme('tripal_db_help', array());
  }
}


/**
 *  Set the permission types that the chado module uses.  Essentially we
 *  want permissionis that protect creation, editing and deleting of chado
 *  data objects
 *
 * @ingroup tripal_db
 */
function tripal_db_permission() {
  return array(
    'administer db cross-references' => array(
      'title' => t('Administer the list of external databases used for data cross-references.'),
      'description' => t('Allows the user to add, edit or delete databases stored in the Chado database.'),
    ),
  );
}

/**
 * Implements hook_views_api()
 * Purpose: Essentially this hook tells drupal that there is views support for
 *  for this module which then includes tripal_db.views.inc where all the
 *  views integration code is
 *
 * @ingroup tripal_db
 */
function tripal_db_views_api() {
  return array('api' => 2.0);
}


/**
 *  We need to let drupal know about our theme functions and their arguments.
 *  We create theme functions to allow users of the module to customize the
 *  look and feel of the output generated in this module
 *
 * @ingroup tripal_db
 */
function tripal_db_theme() {
  $theme_path = drupal_get_path('module', 'tripal_db') . '/theme';
  $items = array(
    'tripal_db_admin' => array(
      'template' => 'tripal_db_admin',
      'arguments' =>  array(NULL),
      'path' => $theme_path,
    ),
  );
  return $items;
}