123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737 |
- <?php
- 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
- );
-
- $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;
- }
- function tripal_pub_theme() {
- return array(
- 'tripal_pub_author_table' => array(
- 'arguments' => array('form' => NULL),
- ),
- 'publication_author' => array(
- 'arguments' => array('element' => NULL)
- ),
- );
- }
- function tripal_pub_perm() {
- return array('edit own tripal_pub', 'edit tripal_pub', 'create tripal_pub');
- }
- 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 publication module supports the Drupal user permissions interface for
- controlling access to publlication content and functions. These permissions include viewing,
- creating, editing or administering of
- publication 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 publication content and
- allow the site administrator all other permissions.</p></li>';
- $text .= '<li><p><b>Set Publication Type Controlled Vocabulary</b>: The select list for setting the publication '
- . 'type is controlled be a controlled vocabulary (cv). '
- . '<ul><li>Before you can add any publications you need '
- . 'to create/load this cv. There is a limited cv included in this module. To use it, you need to '
- . 'load it using the <a href="' . url('admin/tripal/tripal_cv/obo_loader') . '">OBO Loader included with Tripal</a>.</li>'
- . '<li>After the controlled vocabulary is loaded you need to set it to be used for the publication '
- . 'module. To do this, go to <a href="' . url('admin/tripal/tripal_pub/configuration') . '">Publication->Configuration</a>, select it in the controlled vocabulary '
- . 'select list and click save configuration.</p></li></ul>';
- $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;
- }
- function chado_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;
- }
- }
-
- }
- 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,
- ),
- );
- }
- function chado_pub_form(&$node, $form_state) {
- $type = node_get_types('type', $node);
-
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => check_plain($type->title_label),
- '#default_value' => $node->title,
- '#required' => TRUE,
- '#weight' => 0,
- );
-
- $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),
- );
-
- $result = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), $values);
- foreach ($result as $value) {
- $newArray[$value->cvterm_id]=$value->name;
- }
- $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>',
- );
-
- $author_count = empty($node->authors) ? 0 : count($node->authors);
-
- 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++;
- }
-
- $remove_delta = -1;
- if (!empty($form_state['remove_delta'])) {
- $remove_delta = $form_state['remove_delta'] - 1;
- unset($node->authors[$remove_delta]);
-
- $node->authors = array_values($node->authors);
- $author_count--;
- }
-
- $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'];
- }
- }
-
- 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'])) {
-
- $form['author_wrapper']['edit_author'] = array(
- '#type' => 'fieldset',
- '#title' => t('Current Publication Authors'),
- '#tree' => FALSE,
- );
-
- $form['author_wrapper']['edit_author']['edit_author'] = array(
- '#tree' => TRUE,
-
-
- );
- $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,
- );
-
-
- $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{
-
- $form['author_wrapper']['add_author'] = array(
- '#type' => 'fieldset',
- '#title' => t('Publication Authors'),
- '#tree' => FALSE,
- );
-
- $form['author_wrapper']['add_author']['new_author'] = array(
- '#tree' => TRUE,
-
- '#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,
- );
-
-
- $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;
- }
- 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
- );
-
- $result = tripal_core_chado_insert('pub', $values);
- if (isset($result)) {
-
- db_query("INSERT INTO {chado_pub} (nid, vid, pub_id) VALUES (%d, %d, %d)",
- $node->nid,
- $node->vid,
- $result['pub_id']
- );
-
- $abstract_info = tripal_core_chado_select('cvterm', array('cvterm_id'),
- array('name' => 'abstract', 'cv_id' => array('name' => 'tripal')
- )
- );
-
- $type_id = $abstract_info[0]->cvterm_id;
-
- $abstract = array(
- 'pub_id' => $result['pub_id'],
- 'type_id' => $type_id,
- 'value' => $node->abstract,
- 'rank' => 1
- );
-
- tripal_core_chado_insert('pubprop', $abstract);
-
- 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'],
- );
-
- 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'],
- );
-
- tripal_core_chado_insert('pubauthor', $authors);
- }
- }
- else{
- druapl_set_message('Pub_id was not set, No information has been set.');
- }
- }
- function chado_pub_delete(&$node) {
-
- $values = array(
- 'pub_id' => $node->pub_id->pub_id,
- );
-
- tripal_core_chado_delete('pub', $values);
-
- db_query('DELETE FROM {chado_pub} WHERE nid = %d', $node->nid);
- }
- 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));
-
- $match = array( 'pub_id' => $result->pub_id );
-
- $update_result = tripal_core_chado_update('pub', $match, $values);
-
- $abstract_info = tripal_core_chado_select('cvterm', array('cvterm_id'),
- array('name' => 'abstract', 'cv_id' => array('name' => 'tripal')
- )
- );
-
- $type_id = $abstract_info[0]->cvterm_id;
-
- $abstract = array(
- 'pub_id' => $result->pub_id,
- 'type_id' => $type_id,
- 'value' => $node->abstract,
- 'rank' => 1
- );
-
- tripal_core_chado_update('pubprop', array('pub_id' => $result->pub_id, 'type_id' => $type_id, 'rank' => 1), $abstract);
-
- for ($i=0; $i<=sizeof($node->authors); $i++) {
- if (isset($node->authors[$i]['author_name'] )) {
-
- 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'],
- );
-
- tripal_core_chado_insert('pubauthor', $authors);
- }
- else{
-
-
- tripal_core_chado_update('pubauthor', array('pub_id' => $match['pub_id'], 'rank' => $node->authors[$i]['author_name']['rank']), $node->authors[$i]['author_name']);
- }
- }
- }
- }
- 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("Unable to find publication", 'error');
- }
- else{
- $node->pub = tripal_core_generate_chado_var('pub', $values);
-
- $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;
- }
- function tripal_pub_add_author_submit($form, &$form_state) {
- $form_state['remove_delta'] = 0;
-
- node_form_submit_build_node($form, $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;
- }
- }
- function tripal_pub_edit_author_submit($form, &$form_state) {
-
- $delta = $form_state['values']['edit_author']['delta'];
-
- $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;
-
- unset($form_state['values']['edit_author']);
-
- node_form_submit_build_node($form, $form_state);
- }
- function tripal_pub_set_edit_author_submit($form, &$form_state) {
- $form_state['remove_delta'] = 0;
-
- $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;
- }
-
- node_form_submit_build_node($form, $form_state);
- }
- 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']
- );
-
- tripal_core_chado_delete('pubauthor', $values);
-
- node_form_submit_build_node($form, $form_state);
- }
- function tripal_pub_js($delta = 0) {
- $form = tripal_pub_ajax_form_handler($delta);
-
- $author_form = $form['author_wrapper'];
-
- unset($author_form['#prefix'], $author_form['#suffix']);
- $output = theme('status_messages') . drupal_render($author_form);
-
-
-
- $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>';
- }
-
- drupal_json(array('status' => TRUE, 'data' => $output));
- }
- function tripal_pub_ajax_form_handler($delta=0 ) {
-
- include_once 'modules/node/node.pages.inc';
- $form_state = array('storage' => NULL, 'submitted' => FALSE);
- $form_build_id = $_POST['form_build_id'];
-
- $form = form_get_cache($form_build_id, $form_state);
- $args = $form['#parameters'];
- $form_id = array_shift($args);
-
- $form_state['post'] = $form['#post'] = $_POST;
- $form['#programmed'] = $form['#redirect'] = FALSE;
-
- $form_state['remove_delta'] = $delta;
-
- drupal_process_form($form_id, $form, $form_state);
-
- if (form_get_errors()) {
- form_execute_handlers('submit', $form, $form_state);
- }
-
-
- $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'),
- '',
- );
- foreach (element_children($form) as $key) {
-
- 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']
- );
-
- $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'),
- ),
- );
-
- if (isset($form[$key]['#attributes'])) {
- $row = array_merge($row, $form[$key]['#attributes']);
- }
- $rows[] = $row;
- }
-
- $output .= drupal_render($form);
- return $output;
- }
- function tripal_pub_author_display_form($delta, $author) {
- $form = array(
- '#tree' => TRUE,
- );
-
- $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'],
- );
-
- $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',
- ),
- );
-
- $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;
- }
- function tripal_pub_configuration_form() {
- $cv_options = tripal_cv_get_cv_options();
-
- $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.'
- );
-
- $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)
- );
-
-
- $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;
- }
- function tripal_pub_configuration_form_submit($form, $form_state) {
- global $user;
- 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'] );
- }
-
- 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);
- }
- }
- function tripal_pub_search_load_pubmed_publications($search_term_array) {
- $key_terms = preg_split('/\s+/', $search_term_array);
- $search_terms= implode("+", $key_terms);
-
- $path = drupal_get_path('module', 'tripal_pub');
- $i_path = realpath(".");
- $absolute_path = $i_path . '/' . $path;
-
- $command = 'perl ' . $absolute_path . '/e_utilities.pl' . ' ' . $search_terms . ' ' . 'uilist';
- print "\nAccessing PubMed ID's\n";
- exec($command, $output);
-
- for ($i=0; $i < sizeof($output); $i++) {
- $pmid = $output[$i];
-
- $pubmed_id = tripal_core_chado_select( 'pub', array('pub_id'), array( 'uniquename' => $pmid) );
-
- if (!isset($pubmed_id[0]->pub_id)) {
- print "\nRetrieving PubMed ID:" . $pmid . "\n";
- $command = '';
- $xml_report = '';
- $newline_separated = '';
- $xml = '';
-
-
- $command = 'perl ' . $absolute_path . '/e_utilities.pl' . ' ' . $pmid . '[uid] ' . 'xml';
- exec($command, $xml_report);
-
- $newline_separated = implode("\n", $xml_report);
-
- $xml = simplexml_load_string($newline_separated);
-
- if (isset($xml->PubmedArticle->MedlineCitation->Article->ArticleTitle)) {
- $form_id ='chado_pub_node_form';
- $form_state = array();
- module_load_include('inc', 'node', 'node.pages');
- $node = array('type' => 'chado_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 (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 ( $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";
- }
- }
- }
- 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,
-
-
- '#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,
-
-
- '#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,
-
-
- '#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.'));
- }
- }
- }
|