pub_form.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. /**
  3. * This is the chado_pub node form callback. The arguments
  4. * are out of order from a typical form because it's a defined callback
  5. */
  6. function chado_pub_node_form($form_state, $node) {
  7. tripal_core_ahah_init_form();
  8. $form = array();
  9. dpm($form_state);
  10. $type = node_get_types('type', $node);
  11. $pub = $node->pub;
  12. $pub_id = $pub->pub_id;
  13. $d_title = $form_state['values']['title'] ? $form_state['values']['title'] : $pub->title;
  14. $d_uniquename = $form_state['values']['uniquename'] ? $form_state['values']['uniquename'] : $pub->uniquename;
  15. $d_type_id = $form_state['values']['type_id'] ? $form_state['values']['type_id'] : $pub->type_id->cvterm_id;
  16. $d_volume = $form_state['values']['volume'] ? $form_state['values']['volume'] : $pub->volume;
  17. $d_volumetitle = $form_state['values']['volumetitle'] ? $form_state['values']['volumetitle'] : $pub->volumetitle;
  18. $d_series_name = $form_state['values']['series_name'] ? $form_state['values']['series_name'] : $pub->series_name;
  19. $d_issue = $form_state['values']['issue'] ? $form_state['values']['issue'] : $pub->issue;
  20. $d_pyear = $form_state['values']['pyear'] ? $form_state['values']['pyear'] : $pub->pyear;
  21. $d_pages = $form_state['values']['pages'] ? $form_state['values']['pages'] : $pub->pages;
  22. $d_miniref = $form_state['values']['miniref'] ? $form_state['values']['miniref'] : $pub->miniref;
  23. $d_publisher = $form_state['values']['publisher'] ? $form_state['values']['publisher'] : $pub->publisher;
  24. $d_pubplace = $form_state['values']['pubplace'] ? $form_state['values']['pubplace'] : $pub->pubplace;
  25. $d_is_obsolete = $form_state['values']['is_obsolete'] ? $form_state['values']['is_obsolete'] : $pub->is_obsolete;
  26. // get the defaults first from the database and then from the form_state
  27. $default_type = $pub->type_id->cvterm_id;
  28. $form['pub_id'] = array(
  29. '#type' => 'hidden',
  30. '#value' => (isset($node->pub_id)) ? $node->pub_id->pub_id : NULL ,
  31. );
  32. // get the list of publication types. In the Tripal publication
  33. // ontologies these are all grouped under the term 'Publication Type'
  34. // we want the default to be 'Journal Article'
  35. $sql = "
  36. SELECT CVTS.cvterm_id, CVTS.name
  37. FROM {cvtermpath} CVTP
  38. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  39. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  40. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  41. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Type'
  42. ORDER BY CVTS.name ASC
  43. ";
  44. $results = chado_query($sql);
  45. $pub_types = array();
  46. while ($pub_type = db_fetch_object($results)) {
  47. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  48. // if we don't have a default type then set the default to be 'Journal Article'
  49. if (strcmp($pub_type->name,"Journal Article") == 0 and !$d_type_id) {
  50. $d_type_id = $pub_type->cvterm_id;
  51. }
  52. }
  53. $form['type_id'] = array(
  54. '#type' => 'select',
  55. '#title' => t('Publication Type'),
  56. '#options' => $pub_types,
  57. '#required' => TRUE,
  58. '#default_value' => $d_type_id,
  59. );
  60. // Article Title.
  61. $form['title'] = array(
  62. '#type' => 'textfield',
  63. '#title' => check_plain($type->title_label),
  64. '#default_value' => $d_title,
  65. '#required' => TRUE,
  66. );
  67. $form['series_name'] = array(
  68. '#type' => 'textfield',
  69. '#title' => t('Series Name (e.g. Journal Name)'),
  70. '#description' => t('Full name of (journal) series.'),
  71. '#default_value' => $d_series_name,
  72. '#required' => TRUE,
  73. );
  74. $form['pyear'] = array(
  75. '#type' => 'textfield',
  76. '#title' => t('Publication Year'),
  77. '#default_value' => $d_pyear,
  78. '#required' => TRUE,
  79. );
  80. $form['uniquename'] = array(
  81. '#type' => 'textarea',
  82. '#title' => t('Citation'),
  83. '#default_value' => $d_uniquename,
  84. '#description' => t('All publications must have a unique citation. Please enter the full citation for this publication.
  85. For PubMed style citations list
  86. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  87. the title, followed by the series title (e.g. journal name), publication date (3 character Month, day, 4
  88. digit year), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
  89. Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
  90. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52. PubMed PMID: 23462414</pre>'),
  91. '#required' => TRUE,
  92. );
  93. // get publication properties list and create the array that will be used for selecting a property type
  94. $sql = "
  95. SELECT CVTS.cvterm_id, CVTS.name
  96. FROM {cvtermpath} CVTP
  97. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  98. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  99. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  100. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details'
  101. ORDER BY CVTS.name ASC
  102. ";
  103. $prop_types = chado_query($sql);
  104. $num_properties = 0;
  105. $d_properties = array();
  106. $properties = array();
  107. while ($prop = db_fetch_object($prop_types)) {
  108. $properties[$prop->cvterm_id] = $prop->name;
  109. // if any of the properties match the fields in the pub table then we want to include those
  110. // automatically
  111. if($prop->name == 'Volume' and $d_volume) {
  112. $d_properties[$prop->cvterm_id][0]['name'] = $prop->name;
  113. $d_properties[$prop->cvterm_id][0]['id'] = $prop->cvterm_id;
  114. $d_properties[$prop->cvterm_id][0]['value'] = $d_volume;
  115. $num_properties++;
  116. }
  117. if($prop->name == 'Volume Title' and $d_volumetitle) {
  118. $d_properties[$prop->cvterm_id][0]['name'] = $prop->name;
  119. $d_properties[$prop->cvterm_id][0]['id'] = $prop->cvterm_id;
  120. $d_properties[$prop->cvterm_id][0]['value'] = $d_volumetitle;
  121. $num_properties++;
  122. }
  123. if($prop->name == 'Issue' and $d_issue) {
  124. $d_properties[$prop->cvterm_id][0]['name'] = $prop->name;
  125. $d_properties[$prop->cvterm_id][0]['id'] = $prop->cvterm_id;
  126. $d_properties[$prop->cvterm_id][0]['value'] = $d_issue;
  127. $num_properties++;
  128. }
  129. if($prop->name == 'Pages' and $d_pages) {
  130. $d_properties[$prop->cvterm_id][0]['name'] = $prop->name;
  131. $d_properties[$prop->cvterm_id][0]['id'] = $prop->cvterm_id;
  132. $d_properties[$prop->cvterm_id][0]['value'] = $d_pages;
  133. $num_properties++;
  134. }
  135. }
  136. // get the properties for this publication
  137. if($pub_id) {
  138. $sql = "
  139. SELECT CVT.cvterm_id, CVT.name, PP.value, PP.rank
  140. FROM {pubprop} PP
  141. INNER JOIN {cvterm} CVT on CVT.cvterm_id = PP.type_id
  142. WHERE PP.pub_id = %d
  143. ORDER BY CVT.name, PP.rank
  144. ";
  145. $pub_props = chado_query($sql, $pub_id);
  146. while ($prop = db_fetch_object($pub_props)) {
  147. // skip properties that were handled above
  148. if($prop->name == "Volume" or $prop->name == "Volume Title" or
  149. $prop->name == "Issue" or $prop->name == "Pages" or
  150. $prop->name == "Citation") {
  151. continue;
  152. }
  153. // add new properties that weren't handled yet
  154. if(array_key_exists($prop->cvterm_id, $properties)) {
  155. $d_properties[$prop->cvterm_id][$prop->rank]['name'] = $prop->name;
  156. $d_properties[$prop->cvterm_id][$prop->rank]['id'] = $prop->cvterm_id;
  157. $d_properties[$prop->cvterm_id][$prop->rank]['value'] = $prop->value;
  158. $num_properties++;
  159. }
  160. }
  161. }
  162. // build the fields for the properties
  163. $i = 0;
  164. foreach ($d_properties as $type_id => $ranks) {
  165. foreach ($ranks as $rank => $d_property) {
  166. $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
  167. '#type' => 'select',
  168. '#options' => $properties,
  169. '#default_value' => $d_property['id']
  170. );
  171. $rows = 2;
  172. if (preg_match('/Abstract/', $d_property['name'])) {
  173. $rows = 10;
  174. }
  175. $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
  176. '#type' => 'textarea',
  177. '#options' => $properties,
  178. '#default_value' => $d_property['value'],
  179. '#cols' => 20,
  180. '#rows' => $rows
  181. );
  182. $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
  183. '#type' => 'image_button',
  184. '#value' => t('Remove'),
  185. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  186. '#ahah' => array(
  187. 'path' => "tripal_pub/properties/minus/$type_id/$rank",
  188. 'wrapper' => 'chado-pub-details',
  189. 'event' => 'click',
  190. 'method' => 'replace',
  191. ),
  192. '#attributes' => array('onClick' => 'return false;'),
  193. );
  194. if($i == $num_properties - 1) {
  195. $form['properties'][$type_id][$rank]["add-$type_id-$rank"] = array(
  196. '#type' => 'image_button',
  197. '#value' => t('Add'),
  198. '#src' => drupal_get_path('theme', 'tripal') . '/images/add.png',
  199. '#ahah' => array(
  200. 'path' => "tripal_pub/properties/add/$type_id",
  201. 'wrapper' => 'chado-pub-details',
  202. 'event' => 'click',
  203. 'method' => 'replace',
  204. ),
  205. '#attributes' => array('onClick' => 'return false;'),
  206. );
  207. }
  208. $i++;
  209. }
  210. }
  211. /*
  212. $form['volume'] = array(
  213. '#type' => 'textfield',
  214. '#title' => t('Volume'),
  215. '#default_value' => $d_volume
  216. );
  217. $form['issue'] = array(
  218. '#type' => 'textfield',
  219. '#title' => t('Issue'),
  220. '#default_value' => $d_issue
  221. );
  222. $form['pages'] = array(
  223. '#type' => 'textfield',
  224. '#title' => t('Pages'),
  225. '#description' => t('Page number range[s], e.g. 457--459, viii + 664pp, lv--lvii.'),
  226. '#default_value' => $d_pages
  227. );
  228. $form['volumetitle'] = array(
  229. '#type' => 'textfield',
  230. '#title' => t('Volume Title'),
  231. '#description' => t('Title of part if one of a series.'),
  232. '#default_value' => $d_volumetitle
  233. );
  234. $form['miniref'] = array(
  235. '#type' => 'textfield',
  236. '#title' => t('Mini-Ref'),
  237. '#required' => FALSE,
  238. '#default_value' => $d_miniref
  239. );
  240. $form['publisher'] = array(
  241. '#type' => 'textfield',
  242. '#title' => t('Publisher Name'),
  243. '#required' => FALSE,
  244. '#default_value' => $d_publisher
  245. );
  246. $form['pubplace'] = array(
  247. '#type' => 'textfield',
  248. '#title' => t('Place of Publication'),
  249. '#required' => FALSE,
  250. '#default_value' => $d_pubplace
  251. );
  252. */
  253. $form['is_obsolete'] = array(
  254. '#type' => 'checkbox',
  255. '#title' => t('Is Obsolete? (Check for Yes)'),
  256. '#required' => TRUE,
  257. '#default_value' => $d_isobsolete
  258. );
  259. return $form;
  260. }
  261. /*
  262. *
  263. */
  264. function theme_chado_pub_node_form($form) {
  265. $rows = array();
  266. if ($form['properties']) {
  267. foreach ($form['properties'] as $i => $ranks) {
  268. if (is_numeric($i)) {
  269. foreach ($ranks as $rank => $elements) {
  270. if (is_numeric($rank)) {
  271. $rows[] = array(
  272. array('data' => drupal_render($elements["prop_id-$i-$rank"]), 'width' => '20%'),
  273. drupal_render($elements["prop_value-$i-$rank"]),
  274. array('data' => drupal_render($elements["add-$i-$rank"]) . drupal_render($elements["remove-$i-$rank"]), 'width' => '5%'),
  275. );
  276. }
  277. }
  278. }
  279. }
  280. }
  281. $headers = array('Property Type','Value', '');
  282. $markup = '<div id="chado-pub-details">';
  283. $markup .= drupal_render($form['pub_id']);
  284. $markup .= drupal_render($form['title']);
  285. $markup .= drupal_render($form['type_id']);
  286. $markup .= drupal_render($form['series_name']);
  287. $markup .= drupal_render($form['pyear']);
  288. $markup .= drupal_render($form['uniquename']);
  289. $markup .= "<b>Include Additional Details</b>";
  290. $markup .= theme('table', $headers, $rows);
  291. $markup .= "</div>";
  292. $form['properties'] = array(
  293. '#type' => 'markup',
  294. '#value' => $markup,
  295. );
  296. return drupal_render($form);
  297. }
  298. /*
  299. *
  300. */
  301. function tripal_pub_property_add() {
  302. $status = TRUE;
  303. // prepare and render the form
  304. $form = tripal_core_ahah_prepare_form();
  305. $data = theme('node_form', $form);
  306. // bind javascript events to the new objects that will be returned
  307. // so that AHAH enabled elements will work.
  308. $settings = tripal_core_ahah_bind_events();
  309. // return the updated JSON
  310. drupal_json(
  311. array(
  312. 'status' => $status,
  313. 'data' => $data,
  314. 'settings' => $settings,
  315. )
  316. );
  317. }
  318. /*
  319. *
  320. */
  321. function tripal_pub_property_delete() {
  322. $status = TRUE;
  323. // prepare and render the form
  324. $form = tripal_core_ahah_prepare_form();
  325. $data = theme('chado_pub_node_form', $form);
  326. // bind javascript events to the new objects that will be returned
  327. // so that AHAH enabled elements will work.
  328. $settings = tripal_core_ahah_bind_events();
  329. // return the updated JSON
  330. drupal_json(
  331. array(
  332. 'status' => $status,
  333. 'data' => $data,
  334. 'settings' => $settings,
  335. )
  336. );
  337. }