12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736 |
- <?php
- // $Id$
- //require_once('cron.php');
- /**
- * @file
- * This file contains all the functions which provide functionality to this module.
- * This module was developed by Chad N.A. Krilow and Lacey-Anne Sanderson,
- * The University of Saskatchewan.
- *
- *
- * 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.
- */
- //-----------------------------------------------------------------------------
- // SECTION: Main Outline Menu for Tripal Publication
- //-----------------------------------------------------------------------------
- /**
- * 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' => t('Publications'),
- 'description' => ('A module for interfacing the GMOD chado database with Drupal,
- providing viewing of publications'),
- 'page callback' => 'administration_description_page',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items['admin/tripal/tripal_pub/configuration'] = array(
- 'title' => t('Configuration'),
- 'description' => t('Configuration for this module'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_pub_configuration_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- // 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)
- ),
- );
- }
- /**
- * Implement hook_perm().
- */
- function tripal_pub_perm(){
- return array('edit own tripal_pub', 'edit tripal_pub', 'create tripal_pub');
- }
- /**
- * This section uses HTML to output the descriptions of the module, through the Tripal Management
- * Administation window.Any installation instructions are given as well as included features
- * as well as a overview of the purpose Module.
- *
- * @return
- * Returns '$text'The HTML description of the Module, its instructions, features, and any other
- * important aspects. This is returned when the Administration page is selected.
- */
- function administration_description_page(){
- $text = '';
-
- $text = '<br><h3>Tripal Publication Administrative Tools Quick Links</h3>';
- $text .= '<ul>';
- $text .= '<li>'.l('Configuration', 'admin/tripal/tripal_pub/configuration').'</li>';
- $text .= '<li>'.l('Create A Publication', 'node/add/publication').'</li>';
- $text .= '</ul>';
-
- $text .= '<h3>Module Description:</h3>';
- //================================================================================
- $text .= '<p>The Tripal Publication Module provides the functionality for adding, editing, deleting and
- accessing academic publications, entered by the user.This module also allows a time limited search,
- specified by the user, which searches the PubMed extracts and saves acedemic puplications.
- </p>';
-
- $text .= '<h3>Setup Instructions:</h3>';
- //================================================================================
- $text .= '<ol>';
- $text .= '<ol type="i">';
- $text .= '</ol>';
-
- $text .= '<li><p><b>Set Permissions</b>: The stock module supports the Drupal user permissions interface for
- controlling access to stock content and functions. These permissions include viewing,
- creating, editing or administering of
- stock content. The default is that only the original site administrator has these
- permissions. You can <a href="'.url('admin/user/roles').'">add roles</a> for classifying users,
- <a href="'.url('admin/user/user').'">assign users to roles</a> and
- <a href="'.url('admin/user/permissions').'">assign permissions</a> for the publication content to
- those roles. For a simple setup, allow anonymous users access to view organism content and
- allow the site administrator all other permissions.</p></li>';
-
- $text .= '</ol>';
- $text .= '<h3>Features of this Module:</h3>';
- //================================================================================
- $text .= '<ul>';
-
-
-
-
- $text .= '<li><p><b>Configuration (Search For Academic Publications):</b> The search capability implemented in
- this module allows a user to search, by remote connection , the PubMEd database for articles
- that relate to key search words, chosen by the user.The "search keys" are used to search through
- Publication titles and when one of the key words is matched in a title, the recognized article will
- be saved to the database.
-
- <ul>
-
- <li><b>Choose a Controlled Vocabulary:</b>The controlled vocabulary list is a set of terms
-
- <li><b>Set Search Key Words:</b>The search keywords, are the user entered key terms, in which
- the publications in the PubMed database can be recognized by. The user may enter any number
- of search terms, as by adding more search terms, the search will limit the results to those
- in which all of the search terms appear in the publication title.
-
- <li><b>Set a time search interval:</b>The search term interval represents a pre-set ammount
- of time for the search. The time search interval must be entered in minutes. This allows
- the module to automatically search the PubMed database in a predetermined time interval.
- </ul>
-
-
-
-
-
- </p></li>';
-
- $text .= '<li><b>Creating a Publication:</b>';
-
- $text .= '<p>To <b>Create,update/delete a given property of a publication</b>:When Creating a Publication
- it is neccessary to enter the requried fields in the form. These are marked with an astrix and
- if they are not entered upon completion a warning will be issued and the user is forced to fill
- in these entries. The author field, requires a given/surname/suffix to be entered. To add the
- author to the publication, the add author button is to be pushed. The user is able to add as
- many authors to the publication as needed.
- </p>';
-
-
-
-
- return $text;
- }
- //-----------------------------------------------------------------------------
- // SECTION: Node Capability
- //-----------------------------------------------------------------------------
- /**
- * 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 tripal_pub_access($op, $node, $account ){
-
- global $user;
-
- if (empty($account)) {
- $account = $user;
- }
- if ($op != 'create') {
- $node = (object)$node;
- }
-
- if ($op == 'create') {
-
- if (user_access('create tripal_pub')) {
-
- return TRUE;
-
- }
-
- }
- elseif ($op == 'update' || $op == 'delete') {
-
- if (user_access('edit tripal_pub')) {
-
- return TRUE;
- }
- elseif (user_access('edit own tripal_pub') && $account->uid == $node->uid) {
-
- return TRUE;
- }
-
- }
-
- /////////////////The following is taken from the tripal_pub module insert later////////////////////
- /*
- if ($op == 'create') {
- // Only users with permission to do so may create this node type.
- <<<<<<< .mine
- return user_access('create tripal_pub', $account);
- =======
- if(!user_access('create tripal_pub', $account)){
- return FALSE;
- }
- >>>>>>> .r25216
- }
- // Users who create a node may edit or delete it later, assuming they have the
- // necessary permissions.
- if ($op == 'update' || $op == 'delete') {
- if (user_access('edit own tripal_pub',$account) && ($account->uid == $node->uid)) {
- return TRUE;
- }
- }*/
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- }
- /**
- * Implement hook_view().
- */
- function tripal_pub_view($node, $teaser = FALSE, $page = FALSE){
-
- $node = node_prepare($node, $teaser);
-
- $content = $node->content['body']['#value'];
- return $node;
- }
- /**
- * 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(
- 'publication' => array(
- 'name' => t('Publication'),
- 'module' => 'tripal_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,
- ),
- );
- }
- /**
- * 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 tripal_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);
-
- }
-
- /////////////////////Edit authors//////////////////////////////////////////////////////////////////
-
- 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 tripal_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 tripal_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 tripal_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 tripal_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("Unable to find publication", 'error');
-
- }else{
-
- $node->pub_id = 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_id->pub_id));
-
- $size= sizeof($authors);
-
- for($i=0;$i<$size;$i++){
-
- $node->authors[$i]['author_name'] = (array) $authors[$i];
-
- }
-
- }
-
- return $node;
- }
- //-----------------------------------------------------------------------------
- // SECTION: Drupal AHAH Implementation & Edit Publication Section
- //-----------------------------------------------------------------------------
- /**
- * 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 = $_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: Configuration form
- //-----------------------------------------------------------------------------
- /**
- * Implementation of tripal_pub_form().
- *
- * This form takes the following information:A Publication Title,Volume title,Volume,Series Name,
- * Issue,Publication Year,Pages where the Article is located, Miniref,Type-Id, if the article is Obsolete,
- * Publishing company,Pubplication Place and a Uniquename for the the instance. It then puts the
- * infromation into the Chado_project database table based on its 'pub_id'.
- *
- *
- * @return $form
- * An array of menu items '$form'
- *
- */
- function tripal_pub_configuration_form(){
-
- $cv_options = tripal_cv_get_cv_options();
-
- //Creating Fieldset for multiple fields in form
- $form['node_form'] = array(
- '#type' => 'fieldset',
- '#title' => t('Create/Edit Publication Settings'),
- );
-
- $form['node_form']['tripal_pub_types_cv'] = array(
- '#type' => 'select',
- '#title' => t('Controlled Vocabularies'),
- '#options' => $cv_options,
- '#default_value' => variable_get('tripal_pub_types_cv', 0),
- '#description' => 'Set the controlled vocabulary to pull publication type options from. Terms in this vocabulary will be available is the Publication Type select box on both the create and edit pages.',
- );
-
- $form['pubmed'] = array(
- '#type' => 'fieldset',
- '#title' => t('Create Nodes via PubMed Search'),
- );
- $form['pubmed']['description'] = array(
- '#type' => 'item',
- '#value' => 'Publication nodes are created based on the results of a PubMed publication search using '
- .'the keywords entered below. No content is created until the sync is clicked below and the registered tripal job is '
- .'run. This script attempts to only load new publications (ones which don\'t already have nodes from a previous search) '
- .'by comparing the pub_id thus if a publication is added manually which also appears in the pubmed search it will likely '
- .'get added twice.'
- );
-
- //define form elements for the node's title and body.
- $form['pubmed']['unique_name'] = array(
- '#type' => 'textfield',
- '#title' => t('Search Keywords'),
- '#description' => t('Specific search terms. Must be seperated by a single space.'),
- '#required' => FALSE,
- '#default_value' => variable_get('unique_name', NULL)
- );
-
- //define form elements for the node's title and body.
- /**
- $form['set']['time_interval'] = array(
- '#type' => 'textfield',
- '#title' => t('Time Search Interval (Minutes)'),
- '#description'=>t(' The “Search Interval” set here determines when a drupal cron job should
- schedule a tripal job. As such, in reality the time until publications are sync’d is “Search Interval”
- + time remaining until drupal cron is run + time between drupal cron run and next tripal jobs run'),
- '#required' => FALSE,
- '#default_value' => variable_get('time_interval', NULL)
- );
- */
-
- $form['pubmed']['sync_info'] = array(
- '#type' => 'submit',
- '#title' => t('Sync Publications Jobs'),
- '#value' => t('Sync'),
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#weight' => 10,
- '#value' => t('Save Configuration')
- );
-
- return $form;
- }
- /*
- * Pub Configuration-Form
- * This form submit uses variable_set to set the vocabularies that are used, as well as the
- * unique_name and time interval that was entered by the user. If the user selects the option
- * to Sync Publicatin Jobs, the 'tripal_add_job' function is called, and a tripal job
- * will be added.
- *
- * @param $form
- * -The submitted form containing the user entered infromation
- * @param $form_state
- * -Is the state of the form: i.e what button was pressed, what infromation was entered,etc.
- * The key is the 'values'
- */
- function tripal_pub_configuration_form_submit($form, $form_state){
-
- global $user; //needed to make the current users details available so access of user id is available
- if($form_state['values']['op'] == t('Save Configuration')) {
-
- variable_set('tripal_pub_types_cv', $form_state['values']['tripal_pub_types_cv']);
- variable_set('unique_name',$form_state['values']['unique_name'] );
-
- }
-
- //adding a tripal job if the user selects to Sync the Publications
- if($form_state['values']['op']== t('Sync')){
- variable_set('unique_name',$form_state['values']['unique_name'] );
- $job_args = array($form_state['values']['unique_name']);
- $job_id = tripal_add_job('Search & Load PubMed Publications', 'tripal_pub', 'tripal_pub_search_load_pubmed_publications', $job_args, $user->uid);
- }
- }
- /**
- * Tripal Pub Search Load Pubmed Publications
- *
- * This function takes a search term array and uses it as the parameters for the perl script
- * e_utiliies.pl, which needs to be included and installed in any system that wants full
- * functionality of this module, with respects to searching PubMed for relative articles.
- * When the function ends, and all of the form_state values are set, the drupal_execute()
- * function is called and retrieves a form using a form_id, populates it with $form_values,
- * processes it, and returns any validation errors that came up.
- *
- *
- *
- * @TODO: The loading of this function still needs to be fixed. When running the configuration, there
- * are still errors coming up, UFT8 warnings still come up, in random places. My guess, it is when
- * a article is found that is not in english
- *
- *
- *
- * @param $search_term_array
- * -This arrary contains the search terms that were entered
- *
- *
- */
- function tripal_pub_search_load_pubmed_publications($search_term_array){
-
- $key_terms = preg_split('/\s+/', $search_term_array);
-
- $search_terms= implode("+",$key_terms);
-
- //Retrieving absolute path of current directory
- $path = drupal_get_path('module', 'tripal_pub');
-
- $i_path = realpath(".");
-
- $absolute_path = $i_path .'/' .$path;
-
- //perl file required for operating the NCBI PubMed database search, uses users working directory
- $command = 'perl ' . $absolute_path .'/e_utilities.pl' .' ' .$search_terms .' ' .'uilist';
-
- print "\nAccessing PubMed ID's\n";
-
- exec($command, $output);
-
-
- //for loop going through all the pub_med_id, creating a node for each one
- for($i=0; $i < sizeof($output); $i++){
-
- $pmid = $output[$i];
-
- //aquiring the pubmed id from the pub table based on the uniquename
- $pubmed_id = tripal_core_chado_select ( 'pub', array('pub_id'), array( 'uniquename' => $pmid) );
-
- //Checking that the pub-med id is not set & thus not in the database
- if(!isset($pubmed_id[0]->pub_id)){
-
- print "\nRetrieving PubMed ID:".$pmid."\n";
-
- $command = '';
-
- $xml_report = '';
-
- $newline_separated = '';
-
- $xml = '';
-
- //Uncomment below line to see any syntax errors within the perl script
- //$command = 'perl ' ."-cs" .' ' . $absolute_path .'/e_utilities.pl' .' ' .$pmid.'[uid] ' .'xml';
-
- $command = 'perl ' . $absolute_path .'/e_utilities.pl' .' ' .$pmid.'[uid] ' .'xml';
-
- exec($command, $xml_report);
-
- //adding the xml report once the new line characters have been removed
- $newline_separated = implode("\n", $xml_report);
-
- //relaying the xml output so it can be put in a string variable
- $xml = simplexml_load_string($newline_separated);
-
- //checking the Article Title exists, if so, procede with setting values
- if(isset($xml->PubmedArticle->MedlineCitation->Article->ArticleTitle)){
-
- $form_id ='tripal_pub_node_form';
-
- $form_state = array();
-
- module_load_include('inc', 'node', 'node.pages');
-
- $node = array('type' => 'tripal_pub');
-
- $form_state = array();
-
- $form_state['values']['title'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle->MedlineCitation->Article->ArticleTitle),
- "UTF-8",
- (string)$xml->PubmedArticle->MedlineCitation->Article->ArticleTitle);
-
- $form_state['values']['abstract'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle),
- "UTF-8",
- (string)$xml->PubmedArticle);
-
- $form_state['values']['authors'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle),
- "UTF-8",
- (string)$xml->PubmedArticle);
-
- $form_state['values']['volumetitle'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle->MedlineCitation->Article->Journal->Title),
- "UTF-8",
- (string)$xml->PubmedArticle->MedlineCitation->Article->Journal->Title);
-
- $form_state['values']['series_name'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle->MedlineCitation->Article->Journal->Title),
- "UTF-8",
- (string)$xml->PubmedArticle->MedlineCitation->Article->Journal->Title);
-
- $form_state['values']['volume'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle->MedlineCitation->Article->Journal->JournalIssue->Volume),
- "UTF-8",
- (string)$xml->PubmedArticle->MedlineCitation->Article->Journal->JournalIssue->Volume);
-
- $form_state['values']['issue'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle->MedlineCitation->Article->Journal->JournalIssue->Issue),
- "UTF-8",
- (string)$xml->PubmedArticle->MedlineCitation->Article->Journal->JournalIssue->Issue);
-
- $form_state['values']['pyear'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle->MedlineCitation->Article->Journal->JournalIssue->PubDate->Year),
- "UTF-8",
- (string)$xml->PubmedArticle->MedlineCitation->Article->Journal->JournalIssue->PubDate->Year);
-
- $form_state['values']['pages'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle->MedlineCitation->Article->Pagination->MedlinePgn),
- "UTF-8",
- (string)$xml->PubmedArticle->MedlineCitation->Article->Pagination->MedlinePgn);
-
- $form_state['values']['uniquename'] =
- iconv(iconv_get_encoding ((string)$xml->PubmedArticle->MedlineCitation->PMID),
- "UTF-8",
- (string)$xml->PubmedArticle->MedlineCitation->PMID);
-
- $type_id = tripal_core_chado_select ( 'cvterm', array('cvterm_id'), array( 'name' => 'Article') );
-
- $form_state['values']['type_id'] = $type_id[0]->cvterm_id;
-
- $form_state['values']['is_obsolete']='f';
-
- $form_state['values']['op'] = t('Save');
-
- form_set_error(NULL, '', TRUE);
- //If the required values & fields are not set, the drupal_execute function is not called and node is not added
- if(isset($form_state['values']['volumetitle']) || isset($form_state['values']['series_name'])||
- isset($form_state['values']['pages'])||isset($form_state['values']['uniquename'])){
-
- drupal_execute('tripal_pub_node_form', $form_state, (object)$node);
-
- }
-
- $errors = form_get_errors();
-
- //if(isset($errors)){
-
-
- if( $errors !=
- 'Warning: pg_query(): Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xfc
- HINT: This error can also happen if the byte sequence does not match the encoding expected
- by the server, which is controlled by "client_encoding".'){
-
- print "\nErrors:".print_r($errors,TRUE)."\n";
-
- }else{
-
- print "\nErrors:".print_r($errors,TRUE)."\n";
-
-
- }
-
- }
-
- }elseif($i==sizeof($output)){
-
- print "\n Search Completed Successfully \n";
-
- print "\n Total Nodes Created:".$i."\n";
-
- }else{
-
- print "\nERROR: The following PubMed ID:" .' ' .$pubmed_id[0]->pub_id. " Exists in database,skipped.\n";
- }
- }
-
- }
- //-----------------------------------------------------------------------------
- // 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.'));
- }
- }
-
- }
- //-----------------------------------------------------------------------------
- // End of Software
- //-----------------------------------------------------------------------------
|