Parcourir la source

Merge branch '6.x-1.x' of git.drupal.org:sandbox/spficklin/1337878 into 6.x-1.x

Stephen Ficklin il y a 11 ans
Parent
commit
ccb91a5da6

+ 1 - 0
tripal_eimage/api/tripal_eimage.api.inc

@@ -0,0 +1 @@
+<?php

+ 250 - 0
tripal_eimage/includes/tripal_eimage.admin.inc

@@ -0,0 +1,250 @@
+<?php
+/**
+ * @file
+ * @todo Add file header description
+ */
+
+function tripal_eimage_admin($form_state = NULL) {
+  $form = array();
+
+  // before proceeding check to see if we have any
+  // currently processing jobs. If so, we don't want
+  // to give the opportunity to sync libraries
+  $active_jobs = FALSE;
+  if (tripal_get_module_active_jobs('tripal_eimage')) {
+    $active_jobs = TRUE;
+  }
+
+  // add the field set for syncing libraries
+  if (!$active_jobs) {
+    get_tripal_eimage_admin_form_sync_set($form);
+    get_tripal_eimage_admin_form_cleanup_set($form);
+
+  }
+  else {
+    $form['notice'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Eimage Management Temporarily Unavailable')
+    );
+    $form['notice']['message'] = array(
+      '#value' => t('Currently, eimage management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete.  Please check back later once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.'),
+    );
+  }
+
+  return system_settings_form($form);
+}
+/**
+ *
+ *
+ * @ingroup tripal_eimage
+ */
+function get_tripal_eimage_admin_form_cleanup_set(&$form) {
+  $form['cleanup'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Clean Up')
+  );
+  $form['cleanup']['description'] = array(
+    '#type' => 'item',
+    '#value' => t("With Drupal and chado residing in different databases ".
+    "it is possible that nodes in Drupal and eimages in Chado become ".
+    "\"orphaned\".  This can occur if an eimage node in Drupal is ".
+    "deleted but the corresponding chado eimage is not and/or vice ".
+    "versa. Click the button below to resolve these discrepancies."),
+    '#weight' => 1,
+  );
+  $form['cleanup']['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Clean up orphaned eimages'),
+    '#weight' => 2,
+  );
+}
+/**
+ *
+ * @ingroup tripal_eimage
+ */
+function get_tripal_eimage_admin_form_sync_set(&$form) {
+  // define the fieldsets
+  $form['sync'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Sync Eimages')
+  );
+
+  // before proceeding check to see if we have any
+  // currently processing jobs. If so, we don't want
+  // to give the opportunity to sync libraries
+  $active_jobs = FALSE;
+  if (tripal_get_module_active_jobs('tripal_eimage')) {
+    $active_jobs = TRUE;
+  }
+
+  if (!$active_jobs) {
+
+    $eimage_boxes = array();
+
+    // get the list of eimages
+    $sql = "SELECT E.* FROM {eimage} E LEFT JOIN chado_eimage CE ON E.eimage_id = CE.eimage_id WHERE CE.eimage_id IS NULL LIMIT 100";
+    $org_rset = chado_query($sql);
+
+    // if we've added any eimages to the list that can be synced
+    // then we want to build the form components to allow the user
+    // to select one or all of them.  Otherwise, just present
+    // a message stating that all eimages are currently synced.
+
+    $added = 0;
+    $eimage_boxes = array();
+    while ($eimage = db_fetch_object($org_rset)) {
+        $eimage_boxes[$eimage->eimage_id] = "[" . $eimage->eimage_type . "] " . $eimage->image_uri;
+        $added++;
+    }
+    
+    // if we have eimages we need to add to the checkbox then
+    // build that form element
+    if ($added > 0) {
+      $eimage_boxes['all'] = "All Eimages";
+
+      $form['sync']['eimages'] = array(
+        '#title'       => t('Available Eimages (First 100 eimages listed if there are too many)'),
+        '#type'        => t('checkboxes'),
+        '#description' => t("Check the eimages you want to sync.  Drupal content will be created for each of the eimages listed above.  Select 'All Eimages' to sync all of them."),
+        '#required'    => FALSE,
+        '#prefix'      => '<div id="org_boxes">',
+        '#suffix'      => '</div>',
+        '#options'     => $eimage_boxes,
+      );
+      $form['sync']['button'] = array(
+        '#type' => 'submit',
+        '#value' => t('Submit Sync Job')
+      );
+    }
+    // we don't have any eimages to select from
+    else {
+    $form['sync']['value'] = array(
+        '#value' => t('All eimages in Chado are currently synced with Drupal.')
+    );
+    }
+  }
+  // we don't want to present a form since we have an active job running
+  else {
+    $form['sync']['value'] = array(
+        '#value' => t('Currently, jobs exist related to chado eimages. Please check back later for eimages that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
+    );
+  }
+}
+/**
+ *
+ * @ingroup tripal_eimage
+ */
+function tripal_eimage_admin_validate($form, &$form_state) {
+  global $user;  // we need access to the user info
+  $job_args = array();
+
+  if ($form_state['values']['op'] == t('Submit Sync Job')) {
+
+    // check to see if the user wants to sync chado and drupal.  If
+    // so then we need to register a job to do so with tripal
+    $eimages = $form_state['values']['eimages'];
+    $do_all = FALSE;
+    $to_sync = array();
+
+    foreach ($eimages as $eimage_id) {
+      if (preg_match("/^all$/i" , $eimage_id)) {
+        $do_all = TRUE;
+      }
+      if ($eimage_id and preg_match("/^\d+$/i" , $eimage_id)) {
+        // get the list of eimages
+        $sql = "SELECT * FROM {Eimage} WHERE eimage_id = %d";
+        $eimage = db_fetch_object(chado_query($sql, $eimage_id));
+        $to_sync[$eimage_id] = "[" . $eimage->eimage_type . "] $eimage->image_uri";
+      }
+    }
+
+    // submit the job the tripal job manager
+    if ($do_all) {
+      tripal_add_job('Sync all eimages' , 'tripal_eimage',
+      'tripal_eimage_sync_eimages' , $job_args , $user->uid);
+    }
+    else{
+      foreach ($to_sync as $eimage_id => $name) {
+        $job_args[0] = $eimage_id;
+        tripal_add_job("Sync eimage: $name" , 'tripal_eimage',
+          'tripal_eimage_sync_eimages' , $job_args , $user->uid);
+      }
+    }
+  }
+
+  // -------------------------------------
+  // Submit the Cleanup Job if selected
+  if ($form_state['values']['op'] == t('Clean up orphaned eimages')) {
+    tripal_add_job('Cleanup orphaned eimages', 'tripal_eimage',
+      'tripal_eimage_cleanup', $job_args, $user->uid);
+  }
+}
+/**
+ * Synchronize eimages from chado to drupal
+ *
+ * @ingroup tripal_eimage
+ */
+function tripal_eimage_sync_eimages($eimage_id = NULL, $job_id = NULL) {
+  global $user;
+  $page_content = '';
+
+  if (!$eimage_id) {
+    $sql = "SELECT * FROM {eimage} P";
+    $results = chado_query($sql);
+  }
+  else {
+    $sql = "SELECT * FROM {eimage} P WHERE eimage_id = %d";
+    $results = chado_query($sql, $eimage_id);
+  }
+
+  // We'll use the following SQL statement for checking if the eimage
+  // already exists as a drupal node.
+  $sql = "SELECT * FROM {chado_eimage} ".
+         "WHERE eimage_id = %d";
+
+  while ($eimage = db_fetch_object($results)) {
+
+    // check if this eimage already exists in the drupal database. if it
+    // does then skip this eimage and go to the next one.
+    if (!db_fetch_object(db_query($sql, $eimage->eimage_id))) {
+
+      $new_node = new stdClass();
+      $new_node->type = 'chado_eimage';
+      $new_node->uid = $user->uid;
+      $new_node->title = "$eimage->image_uri";
+      $new_node->eimage_id = $eimage->eimage_id;
+      $new_node->eimage_type = $eimage->eimage_type;
+      $new_node->eimage_data = $eimage->eimage_data;
+      node_validate($new_node);
+      if (!form_get_errors()) {
+        $node = node_submit($new_node);
+        node_save($node);
+        if ($node->nid) {
+          print "Added [" . $eimage->eimage_type . "] $eimage->image_uri\n";
+        }
+      }
+      else {
+        print "Failed to insert eimage [" . $eimage->eimage_type . "] $eimage->image_uri\n";
+      }
+    }
+    else {
+      print "Skipped [" . $eimage->eimage_type . "] $eimage->image_uri\n";
+    }
+  }
+  return $page_content;
+}
+
+/**
+ * Remove orphaned drupal nodes
+ *
+ * @param $dummy
+ *   Not Used -kept for backwards compatibility
+ * @param $job_id
+ *   The id of the tripal job executing this function
+ *
+ * @ingroup tripal_eimage
+ */
+function tripal_eimage_cleanup($dummy = NULL, $job_id = NULL) {
+
+  return tripal_core_clean_orphaned_nodes('eimage', $job_id);
+}

+ 26 - 0
tripal_eimage/theme/tripal_eimage_admin.tpl.php

@@ -0,0 +1,26 @@
+<h3>Tripal Eimage Administrative Tools Quick Links:</h3>
+<ul>
+ <li><a href="<?php print url("admin/tripal/tripal_eimage/configuration") ?>">Eimage Configuration</a></li>
+</ul>
+<h3>Module Description:</h3>
+<p>The Tripal Eimage module provides support for visualization of "eimage" pages, editing and updating.</p>
+
+<h3>Setup Instructions:</h3>
+<ol>
+   <li><p><b>Set Permissions</b>: By default only the site administrator account has access to create, edit, delete
+   or administer features. Navigate to the <?php print l('permissions page', 'admin/user/permissions')?> and set the
+   permissions under the 'tripal_eimage' section as appropriate for your site. For a simple setup, allow anonymous 
+   users access to view content and create a special role for creating, editing and other administrative tasks.</p></li>
+
+<li><p><b>Sync any Existing Eimages</b>: Near the top of the <?php print l('Eimage Configuration page', 'admin/tripal/tripal_eimage/configuration') ?> there is
+  a Sync Eimages section which provides list of eimages currently in chado which can be sync\'d.
+  Simply select the eimages you would like to create Drupal/Tripal pages for and click Sync Eimages.</p></li>
+</ol>
+
+
+<h3>Features of this Module:</h3>
+<ul>
+  <li><b>Add/Edit/Delete Eimages</b>: Eimages can be created <?php print l('here', 'node/add/chado-eimage') ?>. 
+  After creation, eimages (regardless of the method used to create them) can be
+  edited or deleted by clicking the Edit tab at the top of the Eimage Page.</li>
+</ul>

+ 7 - 0
tripal_eimage/tripal_eimage.info

@@ -0,0 +1,7 @@
+name = Tripal Eimage
+description = A module for interfacing the GMOD chado database with Drupal, providing viewing of eimages
+core = 6.x
+eimage = tripal_eimage
+package = Tripal
+version = 6.x-1.1
+dependencies[] = tripal_core

+ 69 - 0
tripal_eimage/tripal_eimage.install

@@ -0,0 +1,69 @@
+<?php
+
+/**
+ * @file
+ * This file contains all the functions which describe and implement drupal database tables
+ * needed by this module.
+ *
+ * The eimage manamgenet module allows you to sync data in a chado/Tripal instance with
+ * multiple eimages as well as manage and create such eimages
+ */
+
+/**
+ * Implementation of hook_install().
+ */
+function tripal_eimage_install() {
+  drupal_install_schema('tripal_eimage');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function tripal_eimage_uninstall() {
+  drupal_uninstall_schema('tripal_eimage');
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function tripal_eimage_schema() {
+  $schema['chado_eimage'] = array(
+    'fields' => array(
+      'nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'vid' => array(
+          'type' => 'int',
+          'not null' => TRUE,
+      ),
+      'eimage_id' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+    ),
+    'primary key' => array('nid', 'vid', 'eimage_id'),
+  );
+  return $schema;
+}
+
+/**
+ * Implementation of hook_requirements(). 
+ *
+ */
+function tripal_eimage_requirements($phase) {
+  $requirements = array();
+  if ($phase == 'install') {
+    // make sure chado is installed
+    if (!tripal_core_is_chado_installed()) {
+      $requirements ['tripal_eimage'] = array(
+            'title' => "tripal_eimage",
+            'value' => "ERROR: Chado most be installed before this module can be enabled",
+            'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
+}

+ 364 - 0
tripal_eimage/tripal_eimage.module

@@ -0,0 +1,364 @@
+<?php
+
+require('includes/tripal_eimage.admin.inc');
+require('api/tripal_eimage.api.inc');
+
+/**
+ *  @file
+ * This file contains the basic functions needed for this drupal module.
+ * The drupal tripal_eimage module maps directly to the chado general module.
+ *
+ * For documentation regarding the Chado General module:
+ * @see http://gmod.org/wiki/Chado_General_Module
+ *
+ * @defgroup tripal_eimage Eimage Module
+ * @ingroup tripal_modules
+ */
+
+/**
+ * Implements hook_menu
+ *
+ * @ingroup tripal_eimage
+ */
+function tripal_eimage_menu() {
+  $items[ 'admin/tripal/tripal_eimage' ]= array(
+    'title' => 'Eimages',
+    'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of eimages'),
+    'page callback' => 'theme',
+    'page arguments' => array('tripal_eimage_admin'),
+    'access arguments' => array('adminster tripal eimages'),
+    'type' => MENU_NORMAL_ITEM
+  );
+
+  $items[ 'admin/tripal/tripal_eimage/configuration' ]= array(
+    'title' => 'Configuration',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_eimage_admin'),
+    'access arguments' => array('adminster tripal eimages'),
+    'type' => MENU_NORMAL_ITEM
+  );
+
+  return $items;
+}
+
+/**
+ * Implements hook_perm()
+ *
+ *  This function sets the permission for the user to access the information in the database.
+ *  This includes creating, inserting, deleting and updating of information in the database
+ *
+ *
+ * @ingroup tripal_eimage
+ */
+function tripal_eimage_perm() {
+  return array(
+    'access chado_eimages content',
+    'create chado_eimages content',
+    'delete chado_eimages content',
+    'edit chado_eimages content',
+    'adminster tripal eimages',
+  );
+}
+
+/**
+ * Implement hook_access().
+ *
+ * This hook allows node modules to limit access to the node types they define.
+ *
+ *  @param $op
+ *  The operation to be performed
+ *
+ *  @param $node
+ *  The node on which the operation is to be performed, or, if it does not yet exist, the
+ *  type of node to be created
+ *
+ *  @param $account
+ *  A user object representing the user for whom the operation is to be performed
+ *
+ *  @return
+ *  If the permission for the specified operation is not set then return FALSE. If the
+ *  permission is set then return NULL as this allows other modules to disable
+ *  access.  The only exception is when the $op == 'create'.  We will always 
+ *  return TRUE if the permission is set.
+ *  
+ * @ingroup tripal_eimage
+ */
+function chado_eimage_access($op, $node, $account) {
+
+  if ($op == 'create') {
+    if (!user_access('create chado_eimages content', $account)) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+  if ($op == 'update') {
+    if (!user_access('edit chado_eimages content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'delete') {
+    if (!user_access('delete chado_eimages content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'view') {
+    if (!user_access('access chado_eimages content', $account)) {
+      return FALSE;
+    }
+  }
+  return NULL;
+}
+
+/**
+ * Implementation of hook_node_info().
+ *
+ * This node_info, is a simple node that describes the functionallity of the module. It specifies
+ * that the title(Eimage Name) and body(Description) set to true so that they information can be
+ * entered
+ *
+ *
+ * @ingroup tripal_eimage
+ */
+function tripal_eimage_node_info() {
+  return array(
+    'chado_eimage' => array(
+      'name' => t('Eimage'),
+      'module' => 'chado_eimage',
+      'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of eimages'),
+      'has_title' => TRUE,
+      'title_label' => t('Eimage'),
+      'had_body' => FALSE
+    )
+  );
+}
+/**
+ *  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_eimage
+ */
+function tripal_eimage_theme() {
+  return array(
+    'tripal_eimage_base' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_eimage_base',
+    ),
+    'tripal_eimage_admin' => array(
+      'template' => 'tripal_eimage_admin',
+      'arguments' =>  array(NULL),
+      'path' => drupal_get_path('module', 'tripal_eimage') . '/theme'
+    ),
+  );
+}
+/**
+ * Implementation of hook_form().
+ *
+ *  This form takes the Eimage Title information and description from the user.
+ *
+ *  @parm $node
+ *    The initialized node
+ *
+ *  @parm $form_state
+ *    The state of the form, that has the user entered information that is neccessary for adding
+ *    information to the eimage
+ *
+ *  @return $form
+ *    An array as described by the Drupal Form API
+ *
+ *
+ * @ingroup tripal_eimage
+ */
+function chado_eimage_form(&$node, $form_state) {
+  $form = array();
+
+  $eimage = $node->eimage;
+
+  // keep track of the eimage id if we have.  If we do have one then
+  // this is an update as opposed to an insert.
+  $form['eimage_id'] = array(
+    '#type' => 'value',
+    '#value' => $eimage->eimage_id,
+  );
+
+  $form['title']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('Eimage URI'),
+    '#description'   => t('Please enter the URI for this eimage. This appears at the top of the eimage page.'),
+    '#required'      => TRUE,
+    '#default_value' => $node->title,
+    '#weight'        => 1
+  );
+  $form['eimage_type']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('Eimage Type'),
+      '#description'   => t('Type of the eimage'),
+      '#required'      => FALSE,
+      '#default_value' => $eimage_type,
+      '#weight'        => 2
+  );
+  $form['eimage_data']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Eimage Data'),
+    '#description'   => t('Data of the eimage'),
+    '#required'      => FALSE,
+    '#default_value' => $eimage_data,
+    '#weight'        => 3
+  );
+
+  return $form;
+
+}
+
+/**
+ *  validates submission of form when adding or updating a eimage node
+ *
+ * @ingroup tripal_eimage
+ */
+function chado_eimage_validate($node) {
+  
+}
+
+/**
+ * Implementation of hook_insert().
+ *
+ *  @parm $node
+ *    Then node that has the information stored within, accessed given the nid
+ *
+ *
+ * @ingroup tripal_eimage
+ */
+function chado_eimage_insert($node) {
+
+  if ($node->eimage_id) {
+    $eimage['eimage_id'] = $node->eimage_id;
+  }
+  else {
+    $image_uri = trim($node->title);
+    $eimage_type = trim($node->eimage_type);
+    $eimage_data = trim($node->eimage_data);
+    $values = array(
+      'image_uri' => $image_uri,
+      'eimage_type' => $eimage_type ? $eimage_type : '',
+      'eimage_data' => $eimage_data ? $eimage_data : NULL,
+    );
+    $eimage = tripal_core_chado_insert('eimage', $values);
+  }
+
+  if ($eimage) {
+    // make sure the entry for this feature doesn't already exist in the chado_eimage table
+    // if it doesn't exist then we want to add it.
+    $eimage_id = chado_get_id_for_node('eimage', $node) ;
+    if (!$eimage_id) {
+       // next add the item to the drupal table
+      $sql = "INSERT INTO {chado_eimage} (nid, vid, eimage_id) ".
+             "VALUES (%d, %d, %d)";
+      db_query($sql, $node->nid, $node->vid, $eimage['eimage_id']);
+    }
+  }
+  else {
+    drupal_set_message(t('Unable to add eimage.', 'warning'));
+    watchdog('tripal_eimage', 'Insert eimage: Unable to create eimage where values: %values',
+      array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
+  }
+}
+
+/**
+ *
+ * Implementation of hook_delete().
+ *
+ * @param $node
+ * The node which is to be deleted, only chado eimage and chado_eimage need to be dealt with
+ * since the drupal node is deleted automagically
+ *
+ *
+ * @ingroup tripal_eimage
+ */
+function chado_eimage_delete($node) {
+
+  $eimage_id = chado_get_id_for_node('eimage', $node);
+
+  // if we don't have a eimage id for this node then this isn't a node of
+  // type chado_eimage or the entry in the chado_eimage table was lost.
+  if (!$eimage_id) {
+    return;
+  }
+
+  // Remove data from {chado_eimage}, {node} and {node_revisions} tables of
+  // drupal database
+  $sql_del = "DELETE FROM {chado_eimage} ".
+             "WHERE nid = %d ".
+             "AND vid = %d";
+  db_query($sql_del, $node->nid, $node->vid);
+  $sql_del = "DELETE FROM {node_revisions} ".
+             "WHERE nid = %d ".
+             "AND vid = %d";
+  db_query($sql_del, $node->nid, $node->vid);
+  $sql_del = "DELETE FROM {node} ".
+             "WHERE nid = %d ".
+             "AND vid = %d";
+  db_query($sql_del, $node->nid, $node->vid);
+
+
+  // Remove data from eimage table of chado database as well
+  chado_query("DELETE FROM {eimage} WHERE eimage_id = %d", $eimage_id);
+}
+
+/**
+ * Implements hook_update().
+ *
+ * @param $node
+ *  The node which is to have its containing information updated when the user modifies information
+ *  pertaining to the specific eimage
+ *
+ *
+ * @ingroup tripal_eimage
+ */
+function chado_eimage_update($node) {
+ if ($node->revision) {
+    // there is no way to handle revisions in Chado but leave
+    // this here just to make not we've addressed it.
+  }
+
+  // update the eimage and the description
+  $eimage_id = chado_get_id_for_node('eimage', $node) ;
+  $match = array(
+     'eimage_id' => $eimage_id,
+  );
+  $image_uri = trim($node->title);
+  $eimage_type = trim($node->eimage_type);
+  $eimage_data = trim($node->eimage_data);
+  $values = array(
+      'image_uri' => $image_uri,
+      'eimage_type' => $eimage_type ? $eimage_type : '',
+      'eimage_data' => $eimage_data ? $eimage_data : NULL,
+  );
+  $status = tripal_core_chado_update('eimage', $match, $values);
+  
+}
+
+/**
+ * Implementation of node_load().
+ *
+ * @param $node
+ *   The node that is to have its containing information loaded
+ *
+ * @return $node
+ *   The node, containing the loaded eimage with the current nid
+ *
+ *
+ * @ingroup tripal_eimage
+ */
+function chado_eimage_load($node) {
+
+  // get the feature details from chado
+  $eimage_id = chado_get_id_for_node('eimage', $node);
+
+  $values = array('eimage_id' => $eimage_id);
+  $eimage = tripal_core_generate_chado_var('eimage', $values);
+
+  $additions = new stdClass();
+  $additions->eimage = $eimage;
+  return $additions;
+
+}

+ 254 - 0
tripal_natural_diversity/includes/tripal_natural_diversity.admin.inc

@@ -0,0 +1,254 @@
+<?php
+/**
+ * @file
+ * @todo Add file header description
+ */
+
+function tripal_natural_diversity_admin($form_state = NULL) {
+  $form = array();
+
+  // before proceeding check to see if we have any
+  // currently processing jobs. If so, we don't want
+  // to give the opportunity to sync nd_geolocation
+  $active_jobs = FALSE;
+  if (tripal_get_module_active_jobs('tripal_nd_geolocation')) {
+    $active_jobs = TRUE;
+  }
+
+  // add the field set for syncing libraries
+  if (!$active_jobs) {
+    get_tripal_natural_diversity_admin_form_sync_set($form);
+    get_tripal_natural_diversity_admin_form_cleanup_set($form);
+  }
+  else {
+    $form['notice'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Natural Diversity Management Temporarily Unavailable')
+    );
+    $form['notice']['message'] = array(
+      '#value' => t('Currently, natural_diversity management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete.  Please check back later once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.'),
+    );
+  }
+
+  return system_settings_form($form);
+}
+/**
+ *
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function get_tripal_natural_diversity_admin_form_cleanup_set(&$form) {
+  $form['cleanup'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Clean Up')
+  );
+  $form['cleanup']['description'] = array(
+    '#type' => 'item',
+    '#value' => t("With Drupal and chado residing in different databases ".
+    "it is possible that nodes in Drupal and nd_geolocation in Chado become ".
+    "\"orphaned\".  This can occur if a nd_geolocation node in Drupal is ".
+    "deleted but the corresponding chado natural_diversity is not and/or vice ".
+    "versa. Click the button below to resolve these discrepancies."),
+    '#weight' => 1,
+  );
+  $form['cleanup']['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Clean up orphaned nd_geolocation'),
+    '#weight' => 2,
+  );
+}
+/**
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function get_tripal_natural_diversity_admin_form_sync_set(&$form) {
+  // define the fieldsets
+  $form['sync'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Sync ND Geolocation')
+  );
+
+  // before proceeding check to see if we have any
+  // currently processing jobs. If so, we don't want
+  // to give the opportunity to sync libraries
+  $active_jobs = FALSE;
+  if (tripal_get_module_active_jobs('tripal_nd_geolocation')) {
+    $active_jobs = TRUE;
+  }
+
+  if (!$active_jobs) {
+
+    // get the list of nd_geolocation
+    $sql = "SELECT * FROM {nd_geolocation} ORDER BY description";
+    $org_rset = chado_query($sql);
+
+    // if we've added any nd_geolocation to the list that can be synced
+    // then we want to build the form components to allow the user
+    // to select one or all of them.  Otherwise, just present
+    // a message stating that all nd_geolocation are currently synced.
+    $nd_geo_boxes = array();
+    $added = 0;
+    while ($nd_geolocation = db_fetch_object($org_rset)) {
+      // check to see if the nd_geolocation is already present as a node in drupal.
+      // if so, then skip it.
+      $sql = "SELECT * FROM {chado_nd_geolocation} WHERE nd_geolocation_id = %d";
+      if (!db_fetch_object(db_query($sql, $nd_geolocation->nd_geolocation_id))) {
+        $nd_geo_boxes[$nd_geolocation->nd_geolocation_id] = $nd_geolocation->description;
+        $added++;
+      }
+    }
+
+    // if we have nd_geolocation we need to add to the checkbox then
+    // build that form element
+    if ($added > 0) {
+      $nd_geo_boxes['all'] = "All ND Geolocation";
+
+      $form['sync']['nd_geolocation'] = array(
+        '#title'       => t('Available ND Geolocation'),
+        '#type'        => t('checkboxes'),
+        '#description' => t("Check the nd_geolocation you want to sync.  Drupal content will be created for each of the nd_geolocation listed above.  Select 'All Natural Diversity' to sync all of them."),
+        '#required'    => FALSE,
+        '#prefix'      => '<div id="org_boxes">',
+        '#suffix'      => '</div>',
+        '#options'     => $nd_geo_boxes,
+      );
+      $form['sync']['button'] = array(
+        '#type' => 'submit',
+        '#value' => t('Submit Sync Job')
+      );
+    }
+    // we don't have any nd_geolocation to select from
+    else {
+    $form['sync']['value'] = array(
+        '#value' => t('All nd_geolocation in Chado are currently synced with Drupal.')
+    );
+    }
+  }
+  // we don't want to present a form since we have an active job running
+  else {
+    $form['sync']['value'] = array(
+        '#value' => t('Currently, jobs exist related to chado nd_geolocation. Please check back later for nd_geolocation that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
+    );
+  }
+}
+/**
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_admin_validate($form, &$form_state) {
+  global $user;  // we need access to the user info
+  $job_args = array();
+
+  if ($form_state['values']['op'] == t('Submit Sync Job')) {
+
+    // check to see if the user wants to sync chado and drupal.  If
+    // so then we need to register a job to do so with tripal
+    $nd_geolocation = $form_state['values']['nd_geolocation'];
+    $do_all = FALSE;
+    $to_sync = array();
+
+    foreach ($nd_geolocation as $nd_geolocation_id) {
+      if (preg_match("/^all$/i" , $nd_geolocation_id)) {
+        $do_all = TRUE;
+      }
+      if ($nd_geolocation_id and preg_match("/^\d+$/i" , $nd_geolocation_id)) {
+        // get the list of nd_geolocation
+        $sql = "SELECT * FROM {nd_geolocation} WHERE nd_geolocation_id = %d";
+        $nd_geolocation = db_fetch_object(chado_query($sql, $nd_geolocation_id));
+        $to_sync[$nd_geolocation_id] = "$nd_geolocation->description";
+      }
+    }
+
+    // submit the job the tripal job manager
+    if ($do_all) {
+      tripal_add_job('Sync all nd_geolocation' , 'tripal_natural_diversity',
+      'tripal_natural_diversity_sync_nd_geolocation' , $job_args , $user->uid);
+    }
+    else{
+      foreach ($to_sync as $nd_geolocation_id => $name) {
+        $job_args[0] = $nd_geolocation_id;
+        tripal_add_job("Sync nd_geolocation: $name" , 'tripal_natural_diversity',
+          'tripal_natural_diversity_sync_nd_geolocation' , $job_args , $user->uid);
+      }
+    }
+  }
+
+  // -------------------------------------
+  // Submit the Cleanup Job if selected
+  if ($form_state['values']['op'] == t('Clean up orphaned nd_geolocation')) {
+    tripal_add_job('Cleanup orphaned nd_geolocation', 'tripal_natural_diversity',
+      'tripal_natural_diversity_cleanup', $job_args, $user->uid);
+  }
+}
+/**
+ * Synchronize natural_diversity from chado to drupal
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_sync_nd_geolocation($nd_geolocation_id = NULL, $job_id = NULL) {
+  global $user;
+  $page_content = '';
+
+  if (!$nd_geolocation_id) {
+    $sql = "SELECT * FROM {nd_geolocation} P";
+    $results = chado_query($sql);
+  }
+  else {
+    $sql = "SELECT * FROM {nd_geolocation} P WHERE nd_geolocation_id = %d";
+    $results = chado_query($sql, $nd_geolocation_id);
+  }
+
+  // We'll use the following SQL statement for checking if the nd_geolocation
+  // already exists as a drupal node.
+  $sql = "SELECT * FROM {chado_nd_geolocation} ".
+         "WHERE nd_geolocation_id = %d";
+
+  while ($nd_geolocation = db_fetch_object($results)) {
+
+    // check if this nd_geolocation already exists in the drupal database. if it
+    // does then skip this nd_geolocation and go to the next one.
+    if (!db_fetch_object(db_query($sql, $nd_geolocation->nd_geolocation_id))) {
+
+      $new_node = new stdClass();
+      $new_node->type = 'chado_nd_geolocation';
+      $new_node->uid = $user->uid;
+      $new_node->nd_geolocation_id = $nd_geolocation->nd_geolocation_id;
+      $new_node->title = $nd_geolocation->description;
+      $new_node->latitude = $nd_geolocation->latitude;
+      $new_node->longitude = $nd_geolocation->longitude;
+      $new_node->altitude = $nd_geolocation->altitude;
+      $new_node->geodetic_datum = $nd_geolocation->geodetic_datum;
+      node_validate($new_node);
+      if (!form_get_errors()) {
+        $node = node_submit($new_node);
+        node_save($node);
+        db_query("UPDATE node SET title = '%s' WHERE nid = %d", $nd_geolocation->description, $node->nid); // Use description as node title
+        if ($node->nid) {
+          print "Added $nd_geolocation->description\n";
+        }
+      }
+      else {
+        print "Failed to insert nd_geolocation $nd_geolocation->description\n";
+      }
+    }
+    else {
+      print "Skipped $nd_geolocation->description\n";
+    }
+  }
+  return $page_content;
+}
+
+/**
+ * Remove orphaned drupal nodes
+ *
+ * @param $dummy
+ *   Not Used -kept for backwards compatibility
+ * @param $job_id
+ *   The id of the tripal job executing this function
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_cleanup($dummy = NULL, $job_id = NULL) {
+
+  return tripal_core_clean_orphaned_nodes('nd_geolocation', $job_id);
+}

+ 255 - 0
tripal_natural_diversity/includes/tripal_natural_diversity.nd_geolocation.inc

@@ -0,0 +1,255 @@
+<?php
+/**
+ * Implementation of hook_form().
+ *
+ *  This form takes the ND Geolocation Title information and description from the user.
+ *
+ *  @parm $node
+ *    The initialized node
+ *
+ *  @parm $form_state
+ *    The state of the form, that has the user entered information that is neccessary for adding
+ *    information to the nd_geolocation
+ *
+ *  @return $form
+ *    An array as described by the Drupal Form API
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_form(&$node, $form_state) {
+  $form = array();
+  $nd_geolocation = $node->nd_geolocation;
+  $nd_geolocation_latitude = $nd_geolocation->latitude;
+  $nd_geolocation_longitude = $nd_geolocation->longitude;
+  $nd_geolocation_altitude = $nd_geolocation->altitude;
+  $nd_geolocation_geodetic_datum = $nd_geolocation->geodetic_datum;
+
+  // keep track of the nd_geolocation id if we have.  If we do have one then
+  // this is an update as opposed to an insert.
+  $form['nd_geolocation_id'] = array(
+      '#type' => 'value',
+      '#value' => $nd_geolocation->nd_geolocation_id,
+  );
+  
+  // use nd_geolocation.description as the node title
+  $form['title']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('ND Geolocation Description'),
+    '#description'   => t('A brief description of the nd_geolocation.'),
+    '#required'      => TRUE,
+    '#default_value' => $node->title,
+    '#weight'        => 1
+  );
+
+  $form['nd_geolocation_latitude']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('ND Geolocation Latitude'),
+      '#description'   => t('Latitude of the nd_geolocation'),
+      '#required'      => FALSE,
+      '#default_value' => $nd_geolocation_latitude,
+      '#weight'        => 2
+  );
+  
+  $form['nd_geolocation_longitude']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('ND Geolocation Longitude'),
+      '#description'   => t('Longitude of the nd_geolocation'),
+      '#required'      => FALSE,
+      '#default_value' => $nd_geolocation_longitude,
+      '#weight'        => 3
+  );
+  
+  $form['nd_geolocation_altitude']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('ND Geolocation Altitude'),
+      '#description'   => t('Altitude of the nd_geolocation'),
+      '#required'      => FALSE,
+      '#default_value' => $nd_geolocation_altitude,
+      '#weight'        => 4
+  );
+  
+  $form['nd_geolocation_geodetic_datum']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('ND Geolocation Geodetic Datum'),
+      '#description'   => t('Geodetic_datum of the nd_geolocation'),
+      '#required'      => FALSE,
+      '#default_value' => $nd_geolocation_geodetic_datum,
+      '#weight'        => 5
+  );
+  return $form;
+
+}
+
+/**
+ *  validates submission of form when adding or updating a nd_geolocation node
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_validate($node) {
+  // check to make sure latitude, longitude, and altitude are numbers or null
+  $latitude = trim($node->nd_geolocation_latitude);
+  $longitude = trim($node->nd_geolocation_longitude);
+  $altitude = trim($node->nd_geolocation_altitude);
+  if ($latitude && !is_numeric($latitude)) {
+    form_set_error('nd_geolocation_latitude', t('Latitude shoulbe a number'));
+  } 
+  if ($longitude && !is_numeric($longitude)) {
+    form_set_error('nd_geolocation_longitude', t('Longitude shoulbe a number'));
+  }
+  if ($altitude && !is_numeric($altitude)) {
+    form_set_error('nd_geolocation_altitude', t('Altitude shoulbe a number'));
+  }
+
+}
+/**
+ * Implementation of hook_insert().
+ *
+ *  @parm $node
+ *    Then node that has the information stored within, accessed given the nid
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_insert($node) {
+  if ($node->nd_geolocation_id) {
+    $nd_geolocation['nd_geolocation_id'] = $node->nd_geolocation_id;
+  }
+  else {
+    $description = trim($node->title);
+    $latitude = trim($node->nd_geolocation_latitude);
+    $longitude = trim($node->nd_geolocation_longitude);
+    $altitude = trim($node->nd_geolocation_altitude);
+    $geodetic_datum = trim($node->nd_geolocation_geodetic_datum);
+    $values = array(
+        'description' => $description,
+        'latitude' => $latitude ? $latitude : 'NULL',
+        'longitude' => $longitude ? $longitude : 'NULL',
+        'altitude' => $altitude ? $altitude : 'NULL',
+        'geodetic_datum' => $geodetic_datum ? $geodetic_datum : '',
+    );
+    $nd_geolocation = tripal_core_chado_insert('nd_geolocation', $values);
+  }
+
+  if ($nd_geolocation) {
+    // make sure the entry for this feature doesn't already exist in the chado_nd_geolocation table
+    // if it doesn't exist then we want to add it.
+    $nd_geolocation_id = chado_get_id_for_node('nd_geolocation', $node) ;
+    if (!$nd_geolocation_id) {
+      // next add the item to the drupal table
+      $sql = "INSERT INTO {chado_nd_geolocation} (nid, vid, nd_geolocation_id) ".
+          "VALUES (%d, %d, %d)";
+      db_query($sql, $node->nid, $node->vid, $nd_geolocation['nd_geolocation_id']);
+    }
+  }
+  else {
+    drupal_set_message(t('Unable to add nd_geolocation.', 'warning'));
+    watchdog('tripal_nd_geolocation', 'Insert nd_geolocation: Unable to create nd_geolocation where values: %values',
+    array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
+  }
+}
+
+/**
+ *
+ * Implementation of hook_delete().
+ *
+ * @param $node
+ * The node which is to be deleted, only chado nd_geolocation and chado_nd_geolocation need to be dealt with
+ * since the drupal node is deleted automagically
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_delete($node) {
+
+  $nd_geolocation_id = chado_get_id_for_node('nd_geolocation', $node);
+
+  // if we don't have a nd_geolocation id for this node then this isn't a node of
+  // type chado_nd_geolocation or the entry in the chado_nd_geolocation table was lost.
+  if (!$nd_geolocation_id) {
+    return;
+  }
+
+  // Remove data from {chado_nd_geolocation}, {node} and {node_revisions} tables of
+  // drupal database
+  $sql_del = "DELETE FROM {chado_nd_geolocation} ".
+      "WHERE nid = %d ".
+      "AND vid = %d";
+  db_query($sql_del, $node->nid, $node->vid);
+  $sql_del = "DELETE FROM {node_revisions} ".
+      "WHERE nid = %d ".
+      "AND vid = %d";
+  db_query($sql_del, $node->nid, $node->vid);
+  $sql_del = "DELETE FROM {node} ".
+      "WHERE nid = %d ".
+      "AND vid = %d";
+  db_query($sql_del, $node->nid, $node->vid);
+
+
+  // Remove data from nd_geolocation and nd_geolocationprop tables of chado database as well
+  chado_query("DELETE FROM {nd_geolocationprop} WHERE nd_geolocation_id = %d", $eimage_id);
+  chado_query("DELETE FROM {nd_geolocation} WHERE nd_geolocation_id = %d", $nd_geolocation_id);
+}
+
+/**
+ * Implements hook_update().
+ *
+ * @param $node
+ *  The node which is to have its containing information updated when the user modifies information
+ *  pertaining to the specific nd_geolocation
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_update($node) {
+  if ($node->revision) {
+    // there is no way to handle revisions in Chado but leave
+    // this here just to make not we've addressed it.
+  }
+
+  // update the nd_geolocation and the description
+  $nd_geolocation_id = chado_get_id_for_node('nd_geolocation', $node) ;
+  $match = array(
+      'nd_geolocation_id' => $nd_geolocation_id,
+  );
+  $description = trim($node->title);
+  $latitude = trim($node->nd_geolocation_latitude);
+  $longitude = trim($node->nd_geolocation_longitude);
+  $altitude = trim($node->nd_geolocation_altitude);
+  $geodetic_datum = trim($node->nd_geolocation_geodetic_datum);
+  $values = array(
+      'description' => $description,
+      'latitude' => $latitude ? $latitude : 'NULL',
+      'longitude' => $longitude ? $longitude : 'NULL',
+      'altitude' => $altitude ? $altitude : 'NULL',
+      'geodetic_datum' => $geodetic_datum ? $geodetic_datum : '',
+  );
+  $status = tripal_core_chado_update('nd_geolocation', $match, $values);
+
+}
+
+/**
+ * Implementation of node_load().
+ *
+ * @param $node
+ *   The node that is to have its containing information loaded
+ *
+ * @return $node
+ *   The node, containing the loaded nd_geolocation with the current nid
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_load($node) {
+
+  // get the feature details from chado
+  $nd_geolocation_id = chado_get_id_for_node('nd_geolocation', $node);
+
+  $values = array('nd_geolocation_id' => $nd_geolocation_id);
+  $nd_geolocation = tripal_core_generate_chado_var('nd_geolocation', $values);
+
+  $additions = new stdClass();
+  $additions->nd_geolocation = $nd_geolocation;
+  return $additions;
+
+}

+ 31 - 0
tripal_natural_diversity/theme/tripal_natural_diversity_admin.tpl.php

@@ -0,0 +1,31 @@
+<h3>Tripal Natural Diversity Administrative Tools Quick Links:</h3>
+<ul>
+ <li><a href="<?php print url("admin/tripal/tripal_natural_diversity/configuration") ?>">Natural Diversity Configuration</a></li>
+</ul>
+<h3>Module Description:</h3>
+<p>The Tripal Natural Diversity module provides support for visualization of "natural_diversity" pages, editing and updating.</p>
+
+<h3>Setup Instructions:</h3>
+<ol>
+   <li><p><b>Set Permissions</b>: By default only the site administrator account has access to create, edit, delete
+   or administer features. Navigate to the <?php print l('permissions page', 'admin/user/permissions')?> and set the
+   permissions under the 'tripal_natural_diversity' section as appropriate for your site. For a simple setup, allow anonymous 
+   users access to view content and create a special role for creating, editing and other administrative tasks.</p></li>
+
+<li><p><b>Sync any Existing Natural Diversity Geolocations</b>: Near the top of the <?php print l('Natural Diversity Configuration page', 'admin/tripal/tripal_natural_diversity/configuration') ?> there is
+  a Sync Natural Diversity Geolocation section which provides list of nd_geolocation currently in chado which can be sync\'d.
+  Simply select the nd_geolocation you would like to create Drupal/Tripal pages for and click Submit Sync Job.</p></li>
+</ol>
+
+
+<h3>Features of this Module:</h3>
+<ul>
+  <li><b>Add/Edit/Delete Natural Diversity Geolocation</b>: Natural Diversity Geolocation can be created <?php print l('here', 'node/add/chado-nd-geolocation') ?>. 
+  After creation, nd_geolocation (regardless of the method used to create them) can be
+  edited or deleted by clicking the Edit tab at the top of the Natural Diversity Geolocation Page.</li>
+    <li><p><b>Simple Search Tool</b>: A <?php print l('simple search tool','chado/nd_geolocation') ?> is provided for 
+    finding nd_geolocation. This tool relies on Drupal Views.  <a href="http://drupal.org/natural_diversity/views">Drupal Views</a>
+    which must be installed to see the search tool.  Look for it in the navigation menu under the item 
+    "Search Biological Data". </p></li>
+
+</ul>

+ 47 - 0
tripal_natural_diversity/tripal_natural_diversity.install

@@ -15,6 +15,10 @@ function tripal_natural_diversity_install() {
   // add cvterms
   tripal_natural_diversity_add_cvterms();
   
+  // add chado_nd_geolocation table
+  if (!db_table_exists('chado_nd_geolocation')) {
+    drupal_install_schema('tripal_natural_diversity_nd_geolocation');
+  }
 }
 
 /**
@@ -72,4 +76,47 @@ function tripal_natural_diversity_requirements($phase) {
     }
   }
   return $requirements;
+}
+
+/**
+ *  Update for Drupal 6.x, Tripal 1.1, Natural Diversity Module 1.1
+ *  This update adds new chado_nd_geolocation table
+ *
+ */
+function tripal_natural_diversity_update_6101() {
+   
+  // add chado_nd_geolocation table
+  drupal_install_schema('tripal_natural_diversity_nd_geolocation');
+
+  $ret = array(
+      '#finished' => 1,
+  );
+
+  return $ret;
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function tripal_natural_diversity_nd_geolocation_schema() {
+  $schema['chado_nd_geolocation'] = array(
+      'fields' => array(
+          'nid' => array(
+              'type' => 'int',
+              'unsigned' => TRUE,
+              'not null' => TRUE,
+          ),
+          'vid' => array(
+              'type' => 'int',
+              'not null' => TRUE,
+          ),
+          'nd_geolocation_id' => array(
+              'type' => 'int',
+              'unsigned' => TRUE,
+              'not null' => TRUE,
+          ),
+      ),
+      'primary key' => array('nid', 'vid', 'nd_geolocation_id'),
+  );
+  return $schema;
 }

+ 134 - 1
tripal_natural_diversity/tripal_natural_diversity.module

@@ -2,6 +2,8 @@
 
 require_once('api/tripal_natural_diversity.api.inc');
 require_once('includes/tripal_natural_diversity.schema.inc');
+require_once('includes/tripal_natural_diversity.nd_geolocation.inc');
+require_once('includes/tripal_natural_diversity.admin.inc');
 
 /**
  *  @file
@@ -48,6 +50,19 @@ function tripal_natural_diversity_theme() {
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_nd_phenotypes',
     ),
+    'tripal_nd_geolocation_base' => array(
+        'arguments' => array('node' => NULL),
+        'template' => 'tripal_nd_geolocation_base',
+    ),
+    'tripal_nd_geolocation_properties' => array(
+        'arguments' => array('node' => NULL),
+        'template' => 'tripal_nd_geolocation_properties',
+    ),
+    'tripal_natural_diversity_admin' => array(
+        'template' => 'tripal_natural_diversity_admin',
+        'arguments' =>  array(NULL),
+        'path' => drupal_get_path('module', 'tripal_natural_diversity') . '/theme'
+    ),
   );
 }
 
@@ -62,7 +77,7 @@ function tripal_natural_diversity_nodeapi(&$node, $op, $teaser, $page){
       if ($node->type == 'chado_feature') {
         // the tripal_genetic module provides a tripal_feature_genotype
         // template.  The only difference between them is the addition of
-        // project information by this module's template.  Therefore,
+        // natural_diversity information by this module's template.  Therefore,
         // if the tripal_genetic content is present get rid of as this
         // module superceeds it.
         if (array_key_exists('tripal_feature_genotypes', $node->content)) {
@@ -92,3 +107,121 @@ function tripal_natural_diversity_nodeapi(&$node, $op, $teaser, $page){
 function tripal_natural_diversity_preprocess_tripal_stock_nd_genotypes(&$variables){
 
 }
+
+/**
+ * Implements hook_menu
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_menu() {
+  $items[ 'admin/tripal/tripal_natural_diversity' ]= array(
+    'title' => 'Natural Diversity',
+    'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of natural_diversity data'),
+    'page callback' => 'theme',
+    'page arguments' => array('tripal_natural_diversity_admin'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM
+  );
+
+  $items[ 'admin/tripal/tripal_natural_diversity/configuration' ]= array(
+    'title' => 'Configuration',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_natural_diversity_admin'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM
+  );
+
+  return $items;
+}
+
+/**
+ * Implements hook_perm()
+ *
+ *  This function sets the permission for the user to access the information in the database.
+ *  This includes creating, inserting, deleting and updating of information in the database
+ *
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_perm() {
+  return array(
+      'access chado_nd_geolocation content',
+      'create chado_nd_geolocation content',
+      'delete chado_nd_geolocation content',
+      'edit chado_nd_geolocation content',
+      'adminster tripal natural_diversity',
+  );
+}
+
+/**
+ * Implement hook_access().
+ *
+ * This hook allows node modules to limit access to the node types they define.
+ *
+ *  @param $op
+ *  The operation to be performed
+ *
+ *  @param $node
+ *  The node on which the operation is to be performed, or, if it does not yet exist, the
+ *  type of node to be created
+ *
+ *  @param $account
+ *  A user object representing the user for whom the operation is to be performed
+ *
+ *  @return
+ *  If the permission for the specified operation is not set then return FALSE. If the
+ *  permission is set then return NULL as this allows other modules to disable
+ *  access.  The only exception is when the $op == 'create'.  We will always
+ *  return TRUE if the permission is set.
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function chado_natural_diversity_access($op, $node, $account) {
+
+  if ($op == 'create') {
+    if (!user_access('create chado_nd_geolocation content', $account)) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+  if ($op == 'update') {
+    if (!user_access('edit chado_nd_geolocation content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'delete') {
+    if (!user_access('delete chado_nd_geolocation content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'view') {
+    if (!user_access('access chado_nd_geolocation content', $account)) {
+      return FALSE;
+    }
+  }
+  return NULL;
+}
+
+/**
+ * Implementation of hook_node_info().
+ *
+ * This node_info, is a simple node that describes the functionallity of the module. It specifies
+ * that the title(Project Name) and body(Description) set to true so that they information can be
+ * entered
+ *
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_node_info() {
+  return array(
+      'chado_nd_geolocation' => array(
+          'name' => t('ND Geolocation'),
+          'module' => 'chado_nd_geolocation',
+          'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of nd_geolocation'),
+          'has_title' => TRUE,
+          'title_label' => t('ND Geolocation'),
+          'had_body' => FALSE,
+          'body_label' => t('Full Description'),
+      )
+  );
+}

+ 1 - 1
tripal_project/includes/tripal_project.admin.inc

@@ -250,7 +250,7 @@ function tripal_project_sync_projects($project_id = NULL, $job_id = NULL) {
       $new_node->uid = $user->uid;
       $new_node->title = "$project->name";
       $new_node->project_id = $project->project_id;
-      $new_node->name = $project->name;
+      //$new_node->name = $project->name;
       $new_node->description = $project->description;
       node_validate($new_node);
       if (!form_get_errors()) {