'Databases',
'description' => 'Basic Description of Tripal DB Module Functionality',
'page callback' => 'tripal_db_module_description_page',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/tripal/tripal_db/edit_db'] = array(
'title' => 'Update/Delete Database References',
'description' => 'Manage Databases ',
'page callback' => 'tripal_db_admin_page',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/tripal/tripal_db/add_db'] = array(
'title' => 'Add a Database',
'page callback' => 'drupal_get_form',
'page arguments' => array('tripal_db_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/tripal/tripal_db/edit/js'] = array(
'title' => 'Edit Databases',
'page callback' => 'tripal_ajax_db_edit',
'access arguments' => array('access administration pages'),
'type' => MENU_CALLBACK,
);
return $items;
}
/*******************************************************************************
* Set the permission types that the chado module uses. Essentially we
* want permissionis that protect creation, editing and deleting of chado
* data objects
*/
function tripal_db_perm(){
return array(
'access chado_db content',
'create chado_db content',
'delete chado_db content',
'edit chado_db content',
);
}
/*************************************************************************
* 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
*/
function tripal_db_views_api() {
return array('api' => 2.0);
}
/*************************************************************************
* Purpose: Provide Guidance to new Tripal Admin
*
* @return HTML Formatted text
*/
function tripal_db_module_description_page() {
$text = '';
$text = '
Tripal External Database Administrative Tools Quick Links
';
$text .= '';
$text .= '- '.l('Add External DB', 'admin/tripal/tripal_db/add_db').'
';
$text .= '- '.l('Update/Delete External DBs', 'admin/tripal/tripal_db/edit_db').'
';
$text .= '- '.l('Database References Listing', 'admin/tripal/tripal_db/list_dbxrefs').'
';
$text .= '
';
$text .= 'Description:
';
$text .= 'The Tripal DB Module provides functionality for linking the data in your Tripal Website with other biological websites out there. Essentially you register an enternal database with your website and then associate any of your data (usually sequence features) with that external database by providing the accession for your data in the other database. If the other database is online and you provided a URL prefix when you registered the external database with your site then there will be a link on the details page for your data that takes the user to the same record in the external database.
';
$text .= 'Post Installation Instructions:
';
$text .= 'Simply register any external databases with data pertinent to your site. Then as you load in your data, create database references linking your data to the external database.
';
$text .= 'Features of this Module:
';
$text .= 'Add/Register External Databases';
$text .= 'By entering the name and any additional details into the add database form you register an external database with your website. This allows you to specify that a sequence feature or other data is also stored in an external database. This is escpecially useful if the external database may contain additional details not stored in yours. If the external database is online you can even provide a URL prefix which will automatically link any data in your website to theirs via a web link.
';
$text .= 'Update/Delete External Databases';
$text .= 'To edit the details of an external database record or to delete an already existing external database, go to the Update/Delete DBs form. This will allow you to change details or enter new details.
';
$text .= 'List all External Database References';
$text .= 'If you have views installed, there will be a link to a default listing of all database references currently in your database. This listing can be accessed here. It requires the Drupal Module Views version 2 to be installed (Drupal Views)
';
return $text;
}
/*************************************************************************
*
*/
function tripal_db_admin_page(){
$add_url = url("admin/tripal/tripal_db/add_db");
$output = "Add a new external database";
$output .= drupal_get_form('tripal_db_select_form');
$output .= 'Please select a database above to view or edit
';
return $output;
}
/*************************************************************************
*
*/
function tripal_db_select_form(){
$previous_db = tripal_db_set_active('chado'); // use chado database
// get a list of db from chado for user to choose
$sql = "SELECT * FROM {db} WHERE NOT name = 'tripal' ORDER BY name ";
$results = db_query ($sql);
tripal_db_set_active($previous_db); // use drupal database
$dbs = array();
$dbs[] = '';
while ($db = db_fetch_object($results)){
$dbs[$db->db_id] = $db->name;
}
$form['dbid'] = array(
'#title' => t('External Database Name'),
'#type' => 'select',
'#options' => $dbs,
'#ahah' => array(
'path' => 'admin/tripal/tripal_db/edit/js',
'wrapper' => 'db-edit-div',
'effect' => 'fade',
'event' => 'change',
'method' => 'replace',
),
);
return $form;
}
/*************************************************************************
*
*/
function tripal_ajax_db_edit (){
// get the database id, build the form and then return the JSON object
$dbid = $_POST['dbid'];
$form = drupal_get_form('tripal_db_form',$dbid);
drupal_json(array('status' => TRUE, 'data' => $form));
}
/*************************************************************************
*
*/
function tripal_db_form(&$form_state = NULL,$dbid = NULL){
// get this requested database
if($dbid){
$sql = "SELECT * FROM {db} WHERE db_id = $dbid ";
$previous_db = tripal_db_set_active('chado');
$db = db_fetch_object(db_query($sql));
tripal_db_set_active($previous_db);
# set the default values. If there is a value set in the
# form_state then let's use that, otherwise, we'll pull
# the values from the database
$default_db = $form_state['values']['name'];
$default_desc = $form_state['values']['description'];
$default_url = $form_state['values']['url'];
$default_urlprefix = $form_state['values']['urlprefix'];
if(!$default_db){
$default_db = $db->name;
}
if(!$default_desc){
$default_desc = $db->description;
}
if(!$default_url){
$default_url = $db->url;
}
if(!$default_urlprefix){
$default_urlprefix = $db->urlprefix;
}
$action = 'Update';
} else {
$action = 'Add';
}
$form['dbid'] = array(
'#type' => 'hidden',
'#value' => $dbid
);
$form['name']= array(
'#type' => 'textfield',
'#title' => t("Database Name"),
'#description' => t('Please enter the name for this external database.'),
'#required' => TRUE,
'#default_value' => $default_db,
'#weight' => 1
);
$form['description']= array(
'#type' => 'textarea',
'#title' => t('Description'),
'#description' => t('Please enter a description for this database'),
'#default_value' => $default_desc,
'#weight' => 2
);
$form['url']= array(
'#type' => 'textfield',
'#title' => t('URL'),
'#description' => t('Please enter the web address for this database.'),
'#default_value' => $default_url,
'#weight' => 3
);
$form['urlprefix']= array(
'#type' => 'textfield',
'#title' => t('URL prefix'),
'#description' => t('Tripal can provide links to external databases when accession numbers or unique identifiers are known. Typically, a database will provide a unique web address for each accession and the accession usually is the last component of the page address. Please enter the web address, minus the accession number for this database. When an accession number is present, Tripal will combine this web address with the accession and provide a link to the external site.'),
'#default_value' => $default_urlprefix,
'#weight' => 4
);
if(strcmp($action,'Update')==0){
$form['update'] = array (
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 5,
'#executes_submit_callback' => TRUE,
);
$form['delete'] = array (
'#type' => 'submit',
'#value' => t('Delete'),
'#weight' => 6,
'#executes_submit_callback' => TRUE,
);
} else {
$form['add'] = array (
'#type' => 'submit',
'#value' => t('Add'),
'#weight' => 5,
'#executes_submit_callback' => TRUE,
);
}
$form['#redirect'] = 'admin/tripal/tripal_db';
return $form;
}
/************************************************************************
*
*/
function tripal_db_form_submit($form, &$form_state){
$name = $form_state['values']['name'];
$desc = $form_state['values']['description'];
$url = $form_state['values']['url'];
$urlp = $form_state['values']['urlprefix'];
$dbid = $form_state['values']['dbid'];
$op = $form_state['values']['op'];
if($dbid){
if(strcmp($op,'Update')==0){
$sql = "
UPDATE {db} SET
name = '%s',
description = '%s',
url = '%s',
urlprefix = '%s'
WHERE db_id = %d
";
$previous_db = tripal_db_set_active('chado');
$db = db_query($sql,$name,$desc,$url,$urlp,$dbid);
tripal_db_set_active($previous_db);
if($db){
drupal_set_message("External database updated");
} else {
drupal_set_message("Failed to update external database.");
}
}
if(strcmp($op,'Delete')==0){
$sql = "
DELETE FROM {db}
WHERE db_id = %d
";
$previous_db = tripal_db_set_active('chado');
$db = db_query($sql,$dbid);
tripal_db_set_active($previous_db);
if($db){
drupal_set_message("External database deleted");
} else {
drupal_set_message("Failed to delete external database.");
}
}
}
else {
$sql = "
INSERT INTO {db}
(name,description,url,urlprefix)
VALUES
('%s','%s','%s','%s')
";
$previous_db = tripal_db_set_active('chado');
$db = db_query($sql,$name,$desc,$url,$urlp);
tripal_db_set_active($previous_db);
if($db){
drupal_set_message("External database added");
} else {
drupal_set_message("Failed to add external database.");
}
}
return '';
}