1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276 |
- <?php
- //require_once('cron.php');
- require_once "includes/tripal_pub.admin.inc";
- require_once "includes/pubmed.inc";
- require_once "includes/remote_search.inc";
- /**
- * @file
- *
- * The Tripal Publication module allows you to search the PubMed databse for academic articles,
- * that relate to user specified tpoic\s. As well, it allows management of publications so that
- * a user can enter specified details regarding a desired publication. This allows all of the important
- * information that is unique to a Academic Publication to be stored for access.
- */
- /**
- *
- * @ingroup tripal_pub
- */
- function tripal_pub_init() {
- drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_pub.js');
- }
- /**
- * Implementation of hook_tripal_pub_node_info().
- *
- * This node_info, is a simple node that describes the functionallity of the module.
- *
- */
- function tripal_pub_node_info() {
- return array(
- 'chado_pub' => array(
- 'name' => t('Publication'),
- 'module' => 'chado_pub',
- 'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of publications'),
- 'title_label' => t('Article Title'),
- 'body_label' => t('Abstract'),
- 'has_title' => TRUE,
- 'has_body' => FALSE,
- ),
- );
- }
- /**
- * Tripal-Publication-Menu
- *
- * Implemets hook_menu(): Adds menu items for the tripal_pub module menu. This section
- * gives the outline for the main menu of the Tripal-Publication module
- *
- * @return
- * An array of menu items that is visible within the Drupal Menu, returned as soon
- * as the program is ran
- */
- function tripal_pub_menu() {
- $items = array();
- $items[ 'admin/tripal/tripal_pub' ]= array(
- 'title' => 'Publications',
- 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of publications'),
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_pub_admin'),
- 'access arguments' => array('administer tripal pubs'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_pub/configuration'] = array(
- 'title' => 'Configuration',
- 'description' => 'Configuration for this module',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_pub_configuration_form'),
- 'access arguments' => array('administer tripal pubs'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items['admin/tripal/tripal_pub/import_setup'] = array(
- 'title' => t('Pub Loader Setup'),
- 'description' => t('Finds publications using remote publication databases (e.g. PubMed).'),
- 'page callback' => 'tripal_pub_remote_search_page',
- 'access arguments' => array('administer tripal pubs'),
- 'type ' => MENU_CALLBACK,
- );
-
- $items['admin/tripal/tripal_pub/import_setup/criteria/%/%'] = array(
- 'page callback' => 'tripal_pub_remote_search_page_update_criteria',
- 'page arguments' => array(5, 6),
- 'access arguments' => array('administer tripal pubs'),
- 'type ' => MENU_CALLBACK,
- );
-
- // Automatically generate checkboxes.
- $items['node/add/tripal_pub/ahah_authors'] = array(
- 'title' => 'Add Additional Authors',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('author_addition_fields_ahah_callback'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- 'weight' => 2,
- );
- $items['tripal_pub/js/%'] = array(
- 'page callback' => 'tripal_pub_js',
- 'page arguments' => array(2),
- 'access arguments' => array('access content'),
- 'type ' => MENU_CALLBACK,
- );
- return $items;
- }
- /**
- * Implements hook_theme(): Register themeing functions for this module
- *
- *
- * @return
- * An array of themeing functions to register
- *
- */
- function tripal_pub_theme() {
- return array(
- 'tripal_pub_author_table' => array(
- 'arguments' => array('form' => NULL),
- ),
- 'publication_author' => array(
- 'arguments' => array('element' => NULL)
- ),
- 'publication_author' => array(
- 'arguments' => array('element' => NULL)
- ),
- 'tripal_pub_remote_search_form' => array(
- 'arguments' => array('form'),
- ),
- 'tripal_pub_admin' => array(
- 'template' => 'tripal_pub_admin',
- 'arguments' => array(NULL),
- 'path' => drupal_get_path('module', 'tripal_pub') . '/theme'
- ),
- );
- }
- /**
- * Implement hook_perm().
- */
- function tripal_pub_perm() {
- return array(
- 'access chado_pub content',
- 'create chado_pub content',
- 'delete chado_pub content',
- 'edit chado_pub content',
- 'administer tripal pubs',
- );
- }
- /**
- * 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
- * TRUE
- *
- */
- function chado_pub_access($op, $node, $account ) {
- if ($op == 'create') {
- if (!user_access('create chado_pub content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'update') {
- if (!user_access('edit chado_pub content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_pub content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_pub content', $account)) {
- return FALSE;
- }
- }
- return NULL;
- }
- /**
- * Implementation of tripal_pub_form().
- *
- *
- *
- * @parm &$node
- * The node that is created when the database is initialized
- *
- * @parm $form_state
- * The state of the form, that has the user entered information that is neccessary for, setting
- * up the database tables for the publication
- *
- * @return $form
- * The information that was enterd allong with
- *
- */
- function chado_pub_form(&$node, $form_state) {
- $type = node_get_types('type', $node);
- // Article Title.
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => check_plain($type->title_label),
- '#default_value' => $node->title,
- '#required' => TRUE,
- '#weight' => 0,
- );
- // Abstract
- $form['abstract'] = array(
- '#title' => 'Abstract',
- '#type' => 'textarea',
- '#default_value' => isset($node->abstract) ? $node->abstract : ''
- );
- $form['pub_id'] = array(
- '#type' => 'hidden',
- '#value' => (isset($node->pub_id)) ? $node->pub_id->pub_id : NULL ,
- );
- $form['uniquename'] = array(
- '#type' => 'textfield',
- '#title' => t('Unique Name'),
- '#required' => TRUE,
- '#description' => 'A unique name/identifier for this publication. If this article exists in pubmed, entering the pubmed ID here will ensure duplicate publication pages are not created.',
- '#default_value' => isset($node->pub_id->uniquename) ? $node->pub_id->uniquename : ''
- );
- $values= array(
- 'cv_id' => variable_get('tripal_pub_types_cv', NULL),
- );
- //population select list with 'cvterm' names
- $result = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), $values);
- foreach ($result as $value) {
- $newArray[$value->cvterm_id]=$value->name; //options for the select list
- }
- $form['type_id'] = array(
- '#type' => 'select',
- '#title' => t('Publication Type'),
- '#options' => $newArray,
- '#required' => TRUE,
- '#default_value' => isset($node->pub_id->type_id) ? $node->pub_id->type_id : ''
- );
- $form['author_wrapper'] = array(
- '#tree' => FALSE,
- '#prefix' => '<div class="clear-block" id="author-wrapper">',
- '#suffix' => '</div>',
- );
- // Get number of authors
- $author_count = empty($node->authors) ? 0 : count($node->authors);
- // If a new author added, add to list and update the author count.
- if (isset($form_state['new_author'])) {
- if (!isset($node->authors)) {
- $node->authors = array();
- }
- $node->authors = array_merge($node->authors, array($form_state['new_author']));
- $author_count++;
- }
- // If a author removed, remove from list and update the author count.
- $remove_delta = -1;
- if (!empty($form_state['remove_delta'])) {
- $remove_delta = $form_state['remove_delta'] - 1;
- unset($node->authors[$remove_delta]);
- // Re-number the values.
- $node->authors = array_values($node->authors);
- $author_count--;
- }
- // Container to display existing authors.
- $form['author_wrapper']['authors'] = array(
- '#prefix' => '<div id="publication-authors">',
- '#suffix' => '</div>',
- '#theme' => 'tripal_pub_author_table',
- );
- if (!isset($node->authors)) {
- if (isset($node->new_author['new_author_name'])) {
- $node->authors = array();
- $node->authors[]['author_name'] = $node->new_author['new_author_name'];
- }
- }
- //Add the existing authors to the form.
- for ($delta = 0; $delta < $author_count; $delta++) {
- $author = isset($node->authors[$delta]['author_name']) ? $node->authors[$delta] : array();
- $form['author_wrapper']['authors'][$delta] = tripal_pub_author_display_form($delta, $author);
- }
- if (isset($form_state['values']['edit_author'])) {
- // Add new authors
- $form['author_wrapper']['edit_author'] = array(
- '#type' => 'fieldset',
- '#title' => t('Current Publication Authors'),
- '#tree' => FALSE,
- );
- // Define the form fields for the new author
- $form['author_wrapper']['edit_author']['edit_author'] = array(
- '#tree' => TRUE,
- //'#default_value'=> '',
- //'#theme' => 'author_add_author_form',
- );
- $form['author_wrapper']['edit_author']['edit_author']['delta'] = array(
- '#type' => 'hidden',
- '#value' => $form_state['values']['edit_author']['delta']
- );
- $form['author_wrapper']['edit_author']['edit_author']['edit_author_name'] = array(
- '#type' => 'publication_author',
- '#title' => t('Contributing Authors'),
- '#default_value' => array(
- 'givennames' => $form_state['values']['edit_author']['author_name']['givennames'],
- 'surname' => $form_state['values']['edit_author']['author_name']['surname'],
- 'suffix' => $form_state['values']['edit_author']['author_name']['suffix'],
- ),
- '#weight' => 1,
- );
- // We name our button 'author_more' to avoid conflicts with other modules using
- // AHAH-enabled buttons with the id 'more'.
- $form['author_wrapper']['edit_author']['author_save'] = array(
- '#type' => 'submit',
- '#value' => t('Save Author'),
- '#weight' => 0,
- '#submit' => array('tripal_pub_edit_author_submit'),
- '#ahah' => array(
- 'path' => 'tripal_pub/js/0',
- 'wrapper' => 'author-wrapper',
- 'method' => 'replace',
- 'effect' => 'fade',
- ),
- );
- }
- else{
- // Add new authors
- $form['author_wrapper']['add_author'] = array(
- '#type' => 'fieldset',
- '#title' => t('Publication Authors'),
- '#tree' => FALSE,
- );
- // Define the form fields for the new author
- $form['author_wrapper']['add_author']['new_author'] = array(
- '#tree' => TRUE,
- //'#default_value'=> '',
- '#theme' => 'author_add_author_form',
- );
- $form['author_wrapper']['add_author']['new_author']['new_author_name'] = array(
- '#type' => 'publication_author',
- '#title' => t('Contributing Authors'),
- '#default_value' => '',
- '#weight' => 1,
- );
- // We name our button 'author_more' to avoid conflicts with other modules using
- // AHAH-enabled buttons with the id 'more'.
- $form['author_wrapper']['add_author']['author_more'] = array(
- '#type' => 'submit',
- '#value' => t('Add Author'),
- '#weight' => 0,
- '#submit' => array('tripal_pub_add_author_submit'),
- '#ahah' => array(
- 'path' => 'tripal_pub/js/0',
- 'wrapper' => 'author-wrapper',
- 'method' => 'replace',
- 'effect' => 'fade',
- ),
- );
- }
- $form['volumetitle'] = array(
- '#type' => 'textfield',
- '#title' => t('Volume Title'),
- '#description' => t('Title of part if one of a series.'),
- '#default_value' => isset($node->pub_id->volumetitle) ? $node->pub_id->volumetitle : ''
- );
- $form['volume'] = array(
- '#type' => 'textfield',
- '#title' => t('Volume'),
- '#default_value' => isset($node->pub_id->volume) ? $node->pub_id->volume : ''
- );
- $form['series_name'] = array(
- '#type' => 'textfield',
- '#title' => t('Series Name'),
- '#default_value' => isset($node->pub_id->series_name) ? $node->pub_id->series_name : ''
- );
- $form['issue'] = array(
- '#type' => 'textfield',
- '#title' => t('Issue'),
- '#default_value' => isset($node->pub_id->issue) ? $node->pub_id->issue : ''
- );
- $form['pyear'] = array(
- '#type' => 'textfield',
- '#title' => t('Publication Year'),
- '#default_value' => isset($node->pub_id->pyear) ? $node->pub_id->pyear : ''
- );
- $form['pages'] = array(
- '#type' => 'textfield',
- '#title' => t('Pages'),
- '#description' => t('Page number range[s], e.g. 457--459, viii + 664pp, lv--lvii.'),
- '#default_value' => isset($node->pub_id->pages) ? $node->pub_id->pages : ''
- );
- $form['miniref'] = array(
- '#type' => 'textfield',
- '#title' => t('Mini-Ref'),
- '#required' => FALSE,
- '#default_value' => isset($node->pub_id->miniref) ? $node->pub_id->miniref : ''
- );
- $form['is_obsolete'] = array(
- '#type' => 'checkbox',
- '#title' => t('Is Obsolete?(Check for Yes)'),
- '#required' => TRUE,
- '#default_value' => isset($node->pub_id->is_obsolete) ? $node->pub_id->is_obsolete : FALSE
- );
- $form['publisher'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher Name'),
- '#required' => FALSE,
- '#default_value' => isset($node->pub_id->publisher) ? $node->pub_id->publisher : ''
- );
- $form['pubplace'] = array(
- '#type' => 'textfield',
- '#title' => t('Place of Publication'),
- '#required' => FALSE,
- '#default_value' => isset($node->pub_id->pubplace) ? $node->pub_id->pubplace : ''
- );
- return $form;
- }
- /**
- * Implementation of tripal_pub_insert().
- *
- * This function inserts user entered information pertaining to the Publication instance into the
- * 'pubauthor', 'pubprop', 'chado_pub', 'pub' talble of the database.
- *
- * @parm $node
- * Then node which contains the information stored within the node-ID
- *
- *
- */
- function chado_pub_insert($node) {
- $values = array(
- 'title' => $node->title,
- 'volumetitle' => $node->volumetitle,
- 'volume' => $node->volume,
- 'series_name' => $node->series_name,
- 'issue' => $node->issue,
- 'pyear' => $node->pyear,
- 'pages' => $node->pages,
- 'miniref' => $node->miniref,
- 'type_id' => $node->type_id,
- 'is_obsolete' => $node->is_obsolete,
- 'publisher' => $node->publisher,
- 'pubplace' => $node->pubplace,
- 'uniquename' => $node->uniquename,
- 'type_id' => $node->type_id
- );
- //inserts info into chado table
- $result = tripal_core_chado_insert('pub', $values);
- if (isset($result)) {
- //inserts the row of vid,nid,project_id into the chado_pub table
- db_query("INSERT INTO {chado_pub} (nid, vid, pub_id) VALUES (%d, %d, %d)",
- $node->nid,
- $node->vid,
- $result['pub_id']
- );
- //Aquiring information for the abstract
- $abstract_info = tripal_core_chado_select('cvterm', array('cvterm_id'),
- array('name' => 'abstract', 'cv_id' => array('name' => 'tripal')
- )
- );
- //Extracting the type_id
- $type_id = $abstract_info[0]->cvterm_id;
- //setting the abstract values
- $abstract = array(
- 'pub_id' => $result['pub_id'],
- 'type_id' => $type_id,
- 'value' => $node->abstract,
- 'rank' => 1
- );
- //inserts info into chado pubpro table for abstract
- tripal_core_chado_insert('pubprop', $abstract);
- //counter for loop
- for ($i=0; $i<=sizeof($node->authors); $i++) {
- if (isset($node->authors[$i]['author_name'] )) {
- $authors = array(
- 'pub_id' => $result['pub_id'],
- 'rank' => $i,
- 'surname' => $node->authors[$i]['author_name']['surname'],
- 'givennames' => $node->authors[$i]['author_name']['givennames'],
- 'suffix' => $node->authors[$i]['author_name']['suffix'],
- );
- //inserts info into chado pubpro table for abstract
- tripal_core_chado_insert('pubauthor', $authors);
- }
- }
- if (!empty($node->new_author['new_author_name']['surname'])) {
- $authors = array(
- 'pub_id' => $result['pub_id'],
- 'rank' => $i+1,
- 'surname' => $node->new_author['new_author_name']['surname'],
- 'givennames' => $node->new_author['new_author_name']['givennames'],
- 'suffix' => $node->new_author['new_author_name']['suffix'],
- );
- //inserts info into chado pubpro table for abstract
- tripal_core_chado_insert('pubauthor', $authors);
- }
- }
- else{
- druapl_set_message('Pub_id was not set, No information has been set.');
- }
- }
- /**
- * Implementation of tripal_pub_delete().
- *
- * This function takes a node and if the delete button has been chosen by the user, the publication
- * and it's details will be removed.Following,given the node-ID, the instance will be deleted from
- * the 'chado_pub' table.
- *
- * @parm $node
- * Then node which contains the information stored within the node-ID
- *
- */
- function chado_pub_delete(&$node) {
- // Matching all revision, by using the node's pub_id.
- $values = array(
- 'pub_id' => $node->pub_id->pub_id,
- );
- //deleting row in chado table
- tripal_core_chado_delete('pub', $values);
- //deleteing in drupal chado_project table
- db_query('DELETE FROM {chado_pub} WHERE nid = %d', $node->nid);
- }
- /*
- *
- * Implements hook_update
- *
- * The purpose of the function is to allow the module to take action when an edited node is being
- * updated. It updates any name changes to the database tables that werec reated upon registering a Publication.
- * As well, the database will be changed, so the user changed information will be saved to the database.
- *
- * @param $node
- * The node being updated
- *
- */
- function chado_pub_update($node) {
- $values = array(
- 'title' => $node->title,
- 'volumetitle' => $node->volumetitle,
- 'volume' => $node->volume,
- 'series_name' => $node->series_name,
- 'issue' => $node->issue,
- 'pyear' => $node->pyear,
- 'pages' => $node->pages,
- 'miniref' => $node->miniref,
- 'uniquename' => $node->uniquename,
- 'type_id' => $node->type_id,
- 'is_obsolete' => $node->is_obsolete,
- 'publisher' => $node->publisher,
- 'pubplace' => $node->pubplace,
- 'type_id' => $node->type_id
- );
- $result = db_fetch_object(db_query('SELECT pub_id FROM {chado_pub} WHERE nid=%d AND vid=%d ', $node->nid, $node->vid));
- //extract pub_id from the chado table for update function
- $match = array( 'pub_id' => $result->pub_id );
- //$table to be updated, $match is the 'pub_id', $value are the values that are to be updated
- $update_result = tripal_core_chado_update('pub', $match, $values);
- //Aquiring information for the abstract
- $abstract_info = tripal_core_chado_select('cvterm', array('cvterm_id'),
- array('name' => 'abstract', 'cv_id' => array('name' => 'tripal')
- )
- );
- //Grabbing the type id of the old abstract
- $type_id = $abstract_info[0]->cvterm_id;
- //Aquiring information for the abstract
- $abstract = array(
- 'pub_id' => $result->pub_id,
- 'type_id' => $type_id,
- 'value' => $node->abstract,
- 'rank' => 1
- );
- //$table to be updated, $match is the 'pub_id', $value are the values that are to be updated
- tripal_core_chado_update('pubprop', array('pub_id' => $result->pub_id, 'type_id' => $type_id, 'rank' => 1), $abstract);
- //counter for loop
- for ($i=0; $i<=sizeof($node->authors); $i++) {
- if (isset($node->authors[$i]['author_name'] )) {
- //if new insert
- if (isset($node->authors[$i]['is_new'])) {
- $authors = array(
- 'pub_id' => $match['pub_id'],
- 'rank' => $i+1,
- 'surname' => $node->authors[$i]['author_name']['surname'],
- 'givennames' => $node->authors[$i]['author_name']['givennames'],
- 'suffix' => $node->authors[$i]['author_name']['suffix'],
- );
- //inserts info into chado pubpro table for abstract
- tripal_core_chado_insert('pubauthor', $authors);
- }
- else{
- //update
- //$table=pubauthor to be updated, $match=author_match is the 'pub_id', $value=author are the values that are to be updated
- tripal_core_chado_update('pubauthor', array('pub_id' => $match['pub_id'], 'rank' => $node->authors[$i]['author_name']['rank']), $node->authors[$i]['author_name']);
- }
- }
- }
- }
- /**
- * Implementation of tripal_pub_load().
- *
- *
- * @param $node
- * The node that is to be accessed from the database
- *
- * @return $node
- * The node with the information to be loaded into the database
- *
- */
- function chado_pub_load($node) {
- $result = db_fetch_object(db_query('SELECT * FROM {chado_pub} WHERE nid=%d AND vid=%d ', $node->nid, $node->vid));
- $values = array(
- 'pub_id' => $result->pub_id,
- );
- if (empty($result->pub_id)) {
- drupal_set_message(t("Unable to find publication"), 'error');
- }
- else{
- $node->pub = tripal_core_generate_chado_var('pub', $values);
- // add in authors
- $authors = tripal_core_chado_select(
- 'pubauthor',
- array('rank', 'surname', 'givennames', 'suffix'),
- array('pub_id' => $node->pub->pub_id)
- );
- foreach ($authors as $author) {
- $node->pub->authors[$author->rank] = $author;
- }
- ksort($node->pub->authors);
- }
- return $node;
- }
- /**
- * Submit handler for 'Add Author' button on node form.
- */
- function tripal_pub_add_author_submit($form, &$form_state) {
- $form_state['remove_delta'] = 0;
- // Set the form to rebuild and run submit handlers.
- node_form_submit_build_node($form, $form_state);
- // Make the changes we want to the form state.
- if ($form_state['values']['author_more']) {
- $new_author = array();
- $new_author['author_name'] = $form_state['values']['new_author']['new_author_name'];
- $new_author['is_new'] = TRUE;
- $form_state['new_author'] = $new_author;
- }
- }
- /**
- * Submit handler for 'Edit' button on node form.
- */
- function tripal_pub_edit_author_submit($form, &$form_state) {
- // remember which author we're editing
- $delta = $form_state['values']['edit_author']['delta'];
- //add changes author details back
- $rank = $form_state['values']['authors'][$delta]['author_name']['rank'];
- $form_state['values']['authors'][$delta]['author_name'] = $form_state['values']['edit_author']['edit_author_name'];
- $form_state['values']['authors'][$delta]['author_name']['rank'] = $rank;
- //ensures that after they save their changes the edit fieldstate goes away
- unset($form_state['values']['edit_author']);
- // Set the form to rebuild and run submit handlers.
- node_form_submit_build_node($form, $form_state);
- }
- /**
- * Submit handler for 'Edit' button on node form.
- */
- function tripal_pub_set_edit_author_submit($form, &$form_state) {
- $form_state['remove_delta'] = 0;
- // Make the changes we want to the form state
- $edit_author = array();
- if (preg_match('/edit_author_(\d+)/', $form_state['clicked_button']['#name'], $matches)) {
- $delta = $matches[1];
- $form_state['values']['edit_author'] = $form_state['values']['authors'][$delta];
- $form_state['values']['edit_author']['delta'] = $delta;
- }
- // Set the form to rebuild and run submit handlers.
- node_form_submit_build_node($form, $form_state);
- }
- /**
- * Submit handler for 'Remove' button on node form.
- */
- function tripal_pub_remove_row_submit($form, &$form_state) {
- if (preg_match('/remove_author_(\d+)/', $form_state['clicked_button']['#name'], $matches)) {
- $delta = $matches[1];
- $form_state['values']['remove_author'] = $form_state['values']['authors'][$delta];
- $form_state['values']['remove_author']['delta'] = $delta;
- }
- $values = array(
- 'pub_id' => $form_state['values']['pub_id'],
- 'rank' => $form_state['values']['authors'][$delta]['author_name']['rank']
- );
- //deleting row in chado table
- tripal_core_chado_delete('pubauthor', $values);
- // Set the form to rebuild and run submit handlers.
- node_form_submit_build_node($form, $form_state);
- }
- /*
- *
- *
- *
- */
- function tripal_pub_js($delta = 0) {
- $form = tripal_pub_ajax_form_handler($delta);
- // Render the new output.
- $author_form = $form['author_wrapper']; //was ['author']
- // Prevent duplicate wrappers.
- unset($author_form['#prefix'], $author_form['#suffix']);
- $output = theme('status_messages') . drupal_render($author_form);
- // AHAH does not know about the "Remove" button.
- // This causes it not to attach AHAH behaviours to it after modifying the form.
- // So we need to tell it first.
- $javascript = drupal_add_js(NULL, NULL);
- if (isset($javascript['setting'])) {
- $output .= '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>';
- }
- // Final rendering callback.
- drupal_json(array('status' => TRUE, 'data' => $output));
- }
- /**
- * AJAX form handler.
- */
- function tripal_pub_ajax_form_handler($delta=0 ) {
- // The form is generated in an include file which we need to include manually.
- include_once 'modules/node/node.pages.inc';
- $form_state = array('storage' => NULL, 'submitted' => FALSE);
- $form_build_id = filter_xss($_POST['form_build_id']);
- // Get the form from the cache.
- $form = form_get_cache($form_build_id, $form_state);
- $args = $form['#parameters'];
- $form_id = array_shift($args);
- // We need to process the form, prepare for that by setting a few internals.
- $form_state['post'] = $form['#post'] = $_POST;
- $form['#programmed'] = $form['#redirect'] = FALSE;
- // Set up our form state variable, needed for removing authors.
- $form_state['remove_delta'] = $delta;
- // Build, validate and if possible, submit the form.
- drupal_process_form($form_id, $form, $form_state);
- // If validation fails, force form submission.
- if (form_get_errors()) {
- form_execute_handlers('submit', $form, $form_state);
- }
- // This call recreates the form relying solely on the form_state that the
- // drupal_process_form set up.
- $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
- return $form;
- }
- /*
- *
- *
- */
- function theme_tripal_pub_author_table($form) {
- $rows = array();
- $headers = array(
- t('Givennames'),
- t('Surname'),
- t('Suffix'),
- '', // Blank header title for the remove link.
- );
- foreach (element_children($form) as $key) {
- // No need to print the field title every time.
- unset(
- $form[$key]['author_name_text']['#title'],
- $form[$key]['author_name_text-2']['#title'],
- $form[$key]['author_name_text-3']['#title'],
- $form[$key]['remove_author']['#title']
- );
- // Build the table row.
- $row = array(
- 'data' => array(
- array('data' => drupal_render($form[$key]['author_name']) . drupal_render($form[$key]['author_name_text']), 'class' => 'author-name'),
- array('data' => drupal_render($form[$key]['author_name']) . drupal_render($form[$key]['author_name_text-2']), 'class' => 'author-name'),
- array('data' => drupal_render($form[$key]['author_name']) . drupal_render($form[$key]['author_name_text-3']), 'class' => 'author-name'),
- array('data' => drupal_render($form[$key]['edit_author']) . drupal_render($form[$key]['remove_author']), 'class' => 'remove-author'),
- ),
- );
- // Add additional attributes to the row, such as a class for this row.
- if (isset($form[$key]['#attributes'])) {
- $row = array_merge($row, $form[$key]['#attributes']);
- }
- $rows[] = $row;
- }
- //$output = theme('table', $headers, $rows);
- $output .= drupal_render($form);
- return $output;
- }
- /**
- *
- * Helper function to define populated form field elements for publication node form.
- *
- */
- function tripal_pub_author_display_form($delta, $author) {
- $form = array(
- '#tree' => TRUE,
- );
- // Author Name
- $form['author_name'] = array(
- '#type' => 'hidden',
- '#value' => $author,
- '#parents' => array('authors', $delta),
- );
- $form['author_name_text'] = array(
- '#type' => 'item',
- '#title' => t('Givennames'),
- '#parents' => array('authors', $delta),
- '#value' => $author['author_name']['givennames'],
- );
- $form['author_name_text-2'] = array(
- '#type' => 'item',
- '#title' => t('Surname'),
- '#parents' => array('authors', $delta),
- '#value' => $author['author_name']['surname'],
- );
- $form['author_name_text-3'] = array(
- '#type' => 'item',
- '#title' => t('Suffix'),
- '#parents' => array('authors', $delta),
- '#value' => $author['author_name']['suffix'],
- );
- // Remove button.
- $form['remove_author'] = array(
- '#type' => 'submit',
- '#name' => 'remove_author_' . $delta,
- '#value' => t('Remove'),
- '#submit' => array('tripal_pub_remove_row_submit'),
- '#parents' => array('authors', $delta, 'remove_author'),
- '#ahah' => array(
- 'path' => 'tripal_pub/js/0',
- 'wrapper' => 'author-wrapper',
- 'method' => 'replace',
- 'effect' => 'fade',
- ),
- );
- // Edit Author button
- $form['edit_author'] = array(
- '#type' => 'submit',
- '#name' => 'edit_author_' . $delta,
- '#value' => t('Edit'),
- '#submit' => array('tripal_pub_set_edit_author_submit'),
- '#parents' => array('authors', $delta, 'edit_author'),
- '#ahah' => array(
- 'path' => 'tripal_pub/js/0',
- 'wrapper' => 'author-wrapper',
- 'method' => 'replace',
- 'effect' => 'fade',
- ),
- );
- return $form;
- }
- /*
- * This function executes commands periodically. This is called whenever a cron run occurs. This
- * function uses the time interval that the user has entered. This Publication module, requires
- * that the program is ran in pre-determined intervals, as desired by the user. By using a time stamp
- * and comparing the current time and the time that the last time a cron was ran, this program will
- * be ran.
- *
- *
- * @TODO: The cron function is not working correctly, not sure why the cron is not working properly.
- *
- *
- *
- */
- /**
- function tripal_pub_cron(){
- global $user; //needed to make the current users details available so access of user id is available
- //Aquiring the current time
- $current_time = time();
- //Aquiring the user entered time interval
- $user_interval = variable_get('time_interval',NULL);
- //converting the user entered interval into seconds for use with unix time stamp
- $converted_interval = ($user_interval*60);
- //Accessing database for time stamp from watchdog
- $cron = db_result(db_query('select timestamp from {watchdog} where type="cron" order by timestamp desc limit 1'));
- //debugging print statement
- //print($cron);
- //taking variable value & assigning for use
- $cron_last = variable_get('cron', time());
- $updated_interval = $cron_last - $converted_interval;
- if($current_time >= $updated_interval ){
- tripal_add_job('Search & Load PubMed Publications', 'tripal_pub', 'tripal_pub_search_load_pubmed_publications', $job_args, $user->uid);
- }
- }
- */
- //-----------------------------------------------------------------------------
- // SECTION: Custom form Elements
- //-----------------------------------------------------------------------------
- /*
- * This fucnction tells the FAPI(Form-API) that this is a element that will carry a value, contains
- * arrays of callback function names. Will declare an element will create a reuseable element type.
- *
- * @return
- * An associative array with the name of each element type as a key and an
- * array of attributes describingthe type as a value
- */
- function tripal_pub_elements() {
- return array(
- 'publication_author' => array(
- '#input' => TRUE,
- '#process' => array('expand_publication_author'),
- '#element_validate' => array('publication_author_validate'),
- ),
- );
- }
- /*
- *
- *
- *
- */
- function expand_publication_author($element) {
- if (empty($element['#value'])) {
- $element['#value'] = array(
- 'givennames' => '',
- 'suffix' => '',
- 'surname' => '',
- );
- }
- $element['#tree'] = TRUE;
- $parents = $element['#parents'];
- $parents[] = 'givennames';
- $element['givennames'] = array(
- '#type' => 'textfield',
- '#size' => 10,
- //'#maxlength' => TRUE,
- //'#default_value'=> $element['#value']['#given'],
- '#prefix' => 'Given Name',
- );
- if ($element['#default_value']) {
- $element['givennames']['#default_value'] = $element['#default_value']['givennames'];
- }
- $parents = $element['#parents'];
- $parents[]= 'surname';
- $element['surname'] = array(
- '#type' => 'textfield',
- '#size' => 10,
- //'#maxlength' => TRUE,
- //'#default_value'=> $element['#value']['#surname'],
- '#prefix' => 'Surname',
- );
- if ($element['#default_value']) {
- $element['surname']['#default_value'] = $element['#default_value']['surname'];
- }
- $parents = $element['#parents'];
- $parents[]= 'suffix';
- $element['suffix'] = array(
- '#type' => 'textfield',
- '#size' => 5,
- //'#maxlength' => TRUE,
- //'#default_value'=> $element['#value']['#suffix'],
- '#prefix' => 'suffix',
- );
- if ($element['#default_value']) {
- $element['suffix']['#default_value'] = $element['#default_value']['suffix'];
- }
- return $element;
- }
- /*
- *
- *
- *
- */
- function theme_publication_author($element) {
- return theme('form_element', $element, '<div class="container-inline">' . $element['#children'] . '</div>');
- }
- /*
- *
- *
- *
- */
- function publication_author_validate($element) {
- if ($element['#required']) {
- if (trim($element['#value']['givennames']) == '' || trim($element['#value']['suffix']) == '' || trim($element['#value']['surname']) == '' ||
- !is_string($element['#value']['givennames']) || !is_string($element['#value']['givennames']) || !is_string($element['#value']['surname'])) {
- form_error($element, t('The Author name is required.'));
- }
- }
- }
- /*
- *
- */
- function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
- if ($form_id == "tripal_pub_remote_search_form") {
- // updating the form through the ahah callback sets the action of
- // the form to the ahah callback URL. We need to set it back
- // to the normal form URL
- $form['#action'] = url("admin/tripal/tripal_pub/import_setup");
- }
- }
|