pub_form.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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_form($node, $form_state) {
  7. tripal_core_ahah_init_form();
  8. $form = array();
  9. $pub = $node->pub;
  10. $pub_id = $pub->pub_id;
  11. $d_title = $form_state['values']['title'] ? $form_state['values']['title'] : $node->title;
  12. $d_uniquename = $form_state['values']['uniquename'] ? $form_state['values']['uniquename'] : $pub->uniquename;
  13. $d_type_id = $form_state['values']['type_id'] ? $form_state['values']['type_id'] : $pub->type_id->cvterm_id;
  14. $d_volume = $form_state['values']['volume'] ? $form_state['values']['volume'] : $pub->volume;
  15. $d_volumetitle = $form_state['values']['volumetitle'] ? $form_state['values']['volumetitle'] : $pub->volumetitle;
  16. $d_series_name = $form_state['values']['series_name'] ? $form_state['values']['series_name'] : $pub->series_name;
  17. $d_issue = $form_state['values']['issue'] ? $form_state['values']['issue'] : $pub->issue;
  18. $d_pyear = $form_state['values']['pyear'] ? $form_state['values']['pyear'] : $pub->pyear;
  19. $d_pages = $form_state['values']['pages'] ? $form_state['values']['pages'] : $pub->pages;
  20. $d_miniref = $form_state['values']['miniref'] ? $form_state['values']['miniref'] : $pub->miniref;
  21. $d_publisher = $form_state['values']['publisher'] ? $form_state['values']['publisher'] : $pub->publisher;
  22. $d_pubplace = $form_state['values']['pubplace'] ? $form_state['values']['pubplace'] : $pub->pubplace;
  23. $d_is_obsolete = $form_state['values']['is_obsolete'] ? $form_state['values']['is_obsolete'] : $pub->is_obsolete;
  24. // if the obsolete value is set by the database then it is in the form of
  25. // 't' or 'f', we need to convert to 1 or 0
  26. $d_is_obsolete = $d_is_obsolete == 't' ? 1 : $d_is_obsolete;
  27. $d_is_obsolete = $d_is_obsolete == 'f' ? 0 : $d_is_obsolete;
  28. // on AHAH callbacks we want to keep a list of all the properties that have been removed
  29. // we'll store this info in a hidden field and retrieve it here
  30. $d_removed = $form_state['values']['removed'];
  31. // get the defaults first from the database and then from the form_state
  32. $default_type = $pub->type_id->cvterm_id;
  33. // get the number of new fields that have been aded via AHAH callbacks
  34. $num_new = $form_state['values']['num_new'] ? $form_state['values']['num_new'] : 0;
  35. // initialze default properties array. This is where we store the property defaults
  36. $d_properties = array();
  37. // get the list of publication types. In the Tripal publication
  38. // ontologies these are all grouped under the term 'Publication Type'
  39. // we want the default to be 'Journal Article'
  40. $sql = "
  41. SELECT CVTS.cvterm_id, CVTS.name
  42. FROM {cvtermpath} CVTP
  43. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  44. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  45. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  46. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Type' and
  47. NOT CVTS.is_obsolete = 1
  48. ORDER BY CVTS.name ASC
  49. ";
  50. $results = chado_query($sql);
  51. $pub_types = array();
  52. while ($pub_type = db_fetch_object($results)) {
  53. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  54. // if we don't have a default type then set the default to be 'Journal Article'
  55. if (strcmp($pub_type->name,"Journal Article") == 0 and !$d_type_id) {
  56. $d_type_id = $pub_type->cvterm_id;
  57. }
  58. }
  59. // get publication properties list
  60. $properties_select = array();
  61. $properties_select[] = 'Select a Property';
  62. $properties_list = array();
  63. $sql = "
  64. SELECT CVTS.cvterm_id, CVTS.name, CVTS.definition
  65. FROM {cvtermpath} CVTP
  66. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  67. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  68. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  69. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details' and
  70. NOT CVTS.is_obsolete = 1
  71. ORDER BY CVTS.name ASC
  72. ";
  73. $prop_types = chado_query($sql);
  74. while ($prop = db_fetch_object($prop_types)) {
  75. // the 'Citation' term is special because it serves
  76. // both as a property and as the uniquename for the publiation table
  77. // it is present by default in the initial fields of the form so
  78. // we don't want it again in the drop-down list
  79. // also remove other terms associated with the DBXref
  80. if ($prop->name != "Citation" and
  81. $prop->name != "Publication Accession" and
  82. $prop->name != "Publication Database") {
  83. $properties_select[$prop->cvterm_id] = $prop->name;
  84. }
  85. $properties_list[$prop->cvterm_id] = $prop;
  86. }
  87. $form['pub_id'] = array(
  88. '#type' => 'hidden',
  89. '#value' => $pub_id,
  90. );
  91. $form['title'] = array(
  92. '#type' => 'textarea',
  93. '#title' => t('Publication Title'),
  94. '#default_value' => $d_title,
  95. '#required' => TRUE,
  96. );
  97. $form['type_id'] = array(
  98. '#type' => 'select',
  99. '#title' => t('Publication Type'),
  100. '#options' => $pub_types,
  101. '#required' => TRUE,
  102. '#default_value' => $d_type_id,
  103. );
  104. $form['series_name'] = array(
  105. '#type' => 'textfield',
  106. '#title' => t('Series Name (e.g. Journal Name)'),
  107. '#description' => t('Full name of (journal) series.'),
  108. '#default_value' => $d_series_name,
  109. '#required' => TRUE,
  110. );
  111. $form['pyear'] = array(
  112. '#type' => 'textfield',
  113. '#title' => t('Publication Year'),
  114. '#default_value' => $d_pyear,
  115. '#required' => TRUE,
  116. '#size' => 5,
  117. );
  118. $form['uniquename'] = array(
  119. '#type' => 'textarea',
  120. '#title' => t('Citation'),
  121. '#default_value' => $d_uniquename,
  122. '#description' => t('All publications must have a unique citation. Please enter the full citation for this publication.
  123. For PubMed style citations list
  124. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  125. the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
  126. 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
  127. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52. PubMed PMID: 23462414</pre>'),
  128. '#required' => TRUE,
  129. );
  130. // add in the properties that are actually stored in the pub table fields.
  131. $num_properties = chado_pub_node_form_add_pub_table_props($form, $form_state, $properties_list,
  132. $d_properties, $d_removed, $d_volume, $d_volumetitle, $d_issue, $d_pages);
  133. // add in the properties from the pubprop table
  134. $num_properties += chado_pub_node_form_add_pubprop_table_props($form, $form_state, $pub_id, $d_properties, $d_removed);
  135. // add in any new properties that have been added by the user through an AHAH callback
  136. $num_properties += chado_pub_node_form_add_new_props($form, $form_state, $num_new, $d_properties, $d_removed);
  137. // add an empty row of field to allow for addition of a new property
  138. chado_pub_node_form_add_new_empty_props($form, $properties_select);
  139. $form['removed'] = array(
  140. '#type' => 'hidden',
  141. '#value' => $d_removed,
  142. );
  143. $form['num_new'] = array(
  144. '#type' => 'hidden',
  145. '#value' => $num_new,
  146. );
  147. $form['is_obsolete'] = array(
  148. '#type' => 'checkbox',
  149. '#title' => t('Is Obsolete? (Check for Yes)'),
  150. '#required' => TRUE,
  151. '#default_value' => $d_is_obsolete,
  152. );
  153. return $form;
  154. }
  155. /*
  156. *
  157. */
  158. function chado_pub_node_form_add_new_empty_props(&$form, $properties_select) {
  159. // add one more blank set of property fields
  160. $form['properties']['new']["new_id"] = array(
  161. '#type' => 'select',
  162. '#options' => $properties_select,
  163. '#ahah' => array(
  164. 'path' => "tripal_pub/properties/description",
  165. 'wrapper' => 'tripal-pub-new_value-desc',
  166. 'event' => 'change',
  167. 'method' => 'replace',
  168. ),
  169. );
  170. $form['properties']['new']["new_value"] = array(
  171. '#type' => 'textarea',
  172. '#default_value' => '',
  173. '#cols' => 5,
  174. '#rows' => $rows,
  175. '#description' => '<div id="tripal-pub-new_value-desc"></div>'
  176. );
  177. $form['properties']['new']["add"] = array(
  178. '#type' => 'image_button',
  179. '#value' => t('Add'),
  180. '#src' => drupal_get_path('theme', 'tripal') . '/images/add.png',
  181. '#ahah' => array(
  182. 'path' => "tripal_pub/properties/add",
  183. 'wrapper' => 'tripal-pub-edit-properties-table',
  184. 'event' => 'click',
  185. 'method' => 'replace',
  186. ),
  187. '#attributes' => array('onClick' => 'return false;'),
  188. );
  189. }
  190. /*
  191. *
  192. */
  193. function chado_pub_node_form_add_new_props(&$form, $form_state, $num_new, &$d_properties, &$d_removed) {
  194. // first, add in all of the new properties that were added through a previous AHAH callback
  195. $j = 0;
  196. $num_properties++;
  197. // we need to find the
  198. if ($form_state['values']) {
  199. foreach ($form_state['values'] as $element_name => $value) {
  200. if (preg_match('/new_value-(\d+)-(\d+)/', $element_name, $matches)) {
  201. $new_id = $matches[1];
  202. $rank = $matches[2];
  203. // skip any properties that the user requested to delete through a previous
  204. // AHAH callback or through the current AHAH callback
  205. if($d_removed["$new_id-$rank"]) {
  206. continue;
  207. }
  208. if($form_state['post']['remove-' . $new_id . '-' . $rank]) {
  209. $d_removed["$new_id-$rank"] = 1;
  210. continue;
  211. }
  212. // get this new_id information
  213. $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
  214. // add it to the $d_properties array
  215. $d_properties[$new_id][$rank]['name'] = $cvterm->name;
  216. $d_properties[$new_id][$rank]['id'] = $new_id;
  217. $d_properties[$new_id][$rank]['value'] = $value;
  218. $d_properties[$new_id][$rank]['definition'] = $cvterm->definition;
  219. $num_properties++;
  220. // determine how many rows we need in the textarea
  221. $rows = 1;
  222. if (preg_match('/Abstract/', $cvterm[0]->name)) {
  223. $rows = 10;
  224. }
  225. if ($cvterm[0]->name == 'Author List') {
  226. $rows = 2;
  227. }
  228. // add the new fields
  229. $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
  230. '#type' => 'item',
  231. '#value' => $cvterm[0]->name
  232. );
  233. $form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
  234. '#type' => 'textarea',
  235. '#default_value' => $value,
  236. '#cols' => 50,
  237. '#rows' => $rows,
  238. '#description' => $description,
  239. );
  240. $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
  241. '#type' => 'image_button',
  242. '#value' => t('Remove'),
  243. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  244. '#ahah' => array(
  245. 'path' => "tripal_pub/properties/minus/$new_id/$rank",
  246. 'wrapper' => 'tripal-pub-edit-properties-table',
  247. 'event' => 'click',
  248. 'method' => 'replace',
  249. ),
  250. '#attributes' => array('onClick' => 'return false;'),
  251. );
  252. }
  253. }
  254. }
  255. // second add in any new properties added during this callback
  256. if($form_state['post']['add']) {
  257. $new_id = $form_state['values']['new_id'];
  258. $new_value = $form_state['values']['new_value'];
  259. // get the rank by counting the number of entries
  260. $rank = count($d_properties[$new_id]);
  261. // get this new_id information
  262. $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
  263. // add it to the $d_properties array
  264. $d_properties[$new_id][$rank]['name'] = $cvterm->name;
  265. $d_properties[$new_id][$rank]['id'] = $new_id;
  266. $d_properties[$new_id][$rank]['value'] = $value;
  267. $d_properties[$new_id][$rank]['definition'] = $cvterm->definition;
  268. $num_properties++;
  269. // determine how many rows we need in the textarea
  270. $rows = 1;
  271. if (preg_match('/Abstract/', $cvterm[0]->name)) {
  272. $rows = 10;
  273. }
  274. if ($cvterm[0]->name == 'Author List') {
  275. $rows = 2;
  276. }
  277. // add the new fields
  278. $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
  279. '#type' => 'item',
  280. '#value' => $cvterm[0]->name
  281. );
  282. $form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
  283. '#type' => 'textarea',
  284. '#default_value' => $new_value,
  285. '#cols' => 50,
  286. '#rows' => $rows,
  287. '#description' => $description,
  288. );
  289. $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
  290. '#type' => 'image_button',
  291. '#value' => t('Remove'),
  292. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  293. '#ahah' => array(
  294. 'path' => "tripal_pub/properties/minus/$new_id/$rank",
  295. 'wrapper' => 'tripal-pub-edit-properties-table',
  296. 'event' => 'click',
  297. 'method' => 'replace',
  298. ),
  299. '#attributes' => array('onClick' => 'return false;'),
  300. );
  301. }
  302. return $num_properties;
  303. }
  304. /*
  305. *
  306. */
  307. function chado_pub_node_form_add_pubprop_table_props(&$form, $form_state, $pub_id, &$d_properties, &$d_removed) {
  308. // get the properties for this publication
  309. $num_properties = 0;
  310. if(!$pub_id) {
  311. return $num_properties;
  312. }
  313. $sql = "
  314. SELECT CVT.cvterm_id, CVT.name, CVT.definition, PP.value, PP.rank
  315. FROM {pubprop} PP
  316. INNER JOIN {cvterm} CVT on CVT.cvterm_id = PP.type_id
  317. WHERE PP.pub_id = %d
  318. ORDER BY CVT.name, PP.rank
  319. ";
  320. $pub_props = chado_query($sql, $pub_id);
  321. while ($prop = db_fetch_object($pub_props)) {
  322. $type_id = $prop->cvterm_id;
  323. $rank = count($d_properties[$type_id]);
  324. // skip properties that are found in the pub table
  325. if($prop->name == "Volume" or $prop->name == "Volume Title" or
  326. $prop->name == "Issue" or $prop->name == "Pages" or
  327. $prop->name == "Citation") {
  328. continue;
  329. }
  330. // skip any properties that the user requested to delete through a previous
  331. // AHAH callback or through the current AHAH callback
  332. if($d_removed["$type_id-$rank"]) {
  333. continue;
  334. }
  335. if($form_state['post']['remove-' . $type_id . '-' . $rank]) {
  336. $d_removed["$type_id-$rank"] = 1;
  337. continue;
  338. }
  339. $d_properties[$type_id][$rank]['name'] = $prop->name;
  340. $d_properties[$type_id][$rank]['id'] = $type_id;
  341. $d_properties[$type_id][$rank]['value'] = $prop->value;
  342. $d_properties[$type_id][$rank]['definition'] = $prop->definition;
  343. $num_properties++;
  344. // determine how many rows we need in the textarea
  345. $rows = 1;
  346. if (preg_match('/Abstract/', $prop->name)) {
  347. $rows = 10;
  348. }
  349. if ($prop->name == 'Author List') {
  350. $rows = 2;
  351. }
  352. $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
  353. '#type' => 'item',
  354. '#value' => $prop->name,
  355. );
  356. $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
  357. '#type' => 'textarea',
  358. '#default_value' => $prop->value,
  359. '#cols' => 50,
  360. '#rows' => $rows,
  361. '#description' => $description,
  362. );
  363. $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
  364. '#type' => 'image_button',
  365. '#value' => t('Remove'),
  366. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  367. '#ahah' => array(
  368. 'path' => "tripal_pub/properties/minus/$type_id/$rank",
  369. 'wrapper' => 'tripal-pub-edit-properties-table',
  370. 'event' => 'click',
  371. 'method' => 'replace',
  372. ),
  373. '#attributes' => array('onClick' => 'return false;'),
  374. );
  375. }
  376. return $num_properties;
  377. }
  378. /*
  379. *
  380. */
  381. function chado_pub_node_form_add_pub_table_props(&$form, $form_state, $properties_list,
  382. &$d_properties, &$d_removed, $d_volume, $d_volumetitle, $d_issue, $d_pages) {
  383. $num_properties = 0;
  384. $rank = 0;
  385. // add properties that are actually part of the pub table
  386. foreach($properties_list as $type_id => $prop) {
  387. // skip any properties that the user requested to delete through a previous
  388. // AHAH callback or through the current AHAH callback
  389. if($d_removed["$type_id-$rank"]) {
  390. continue;
  391. }
  392. if($form_state['post']["remove-$type_id-$rank"]) {
  393. $d_removed["$type_id-$rank"] = 1;
  394. continue;
  395. }
  396. // if any of the properties match the fields in the pub table then we want to include those
  397. // automatically
  398. if (($prop->name == 'Volume' and $d_volume) or
  399. ($prop->name == 'Issue' and $d_issue) or
  400. ($prop->name == 'Pages' and $d_pages) or
  401. ($prop->name == 'Volume Title' and $d_volumetitle)) {
  402. $d_properties[$type_id][$rank]['name'] = $prop->name;
  403. $d_properties[$type_id][$rank]['id'] = $type_id;
  404. $d_properties[$type_id][$rank]['definition'] = $prop->definition;
  405. $num_properties++;
  406. if ($prop->name == 'Volume') {
  407. $d_properties[$type_id][$rank]['value'] = $d_volume;
  408. }
  409. if ($prop->name == 'Issue') {
  410. $d_properties[$type_id][$rank]['value'] = $d_issue;
  411. }
  412. if ($prop->name == 'Pages') {
  413. $d_properties[$type_id][$rank]['value'] = $d_pages;
  414. }
  415. if ($prop->name == 'Volume Title') {
  416. $d_properties[$type_id][$rank]['value'] = $d_volumetitle;
  417. }
  418. // determine how many rows we need in the textarea
  419. $rows = 1;
  420. if (preg_match('/Abstract/', $prop->name)) {
  421. $rows = 10;
  422. }
  423. if ($prop->name == 'Author List') {
  424. $rows = 2;
  425. }
  426. // add in the fields
  427. $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
  428. '#type' => 'item',
  429. '#value' => $prop->name
  430. );
  431. $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
  432. '#type' => 'textarea',
  433. '#default_value' => $d_properties[$type_id][$rank]['value'],
  434. '#cols' => 50,
  435. '#rows' => $rows,
  436. '#description' => $description,
  437. );
  438. $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
  439. '#type' => 'image_button',
  440. '#value' => t('Remove'),
  441. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  442. '#ahah' => array(
  443. 'path' => "tripal_pub/properties/minus/$type_id/$rank",
  444. 'wrapper' => 'tripal-pub-edit-properties-table',
  445. 'event' => 'click',
  446. 'method' => 'replace',
  447. ),
  448. '#attributes' => array('onClick' => 'return false;'),
  449. );
  450. }
  451. }
  452. return $num_properties;
  453. }
  454. /*
  455. *
  456. */
  457. function theme_chado_pub_node_form($form) {
  458. $properties_table = tripal_pub_theme_node_form_properties($form);
  459. $markup = drupal_render($form['pub_id']);
  460. $markup .= drupal_render($form['title']);
  461. $markup .= drupal_render($form['type_id']);
  462. $markup .= drupal_render($form['series_name']);
  463. $markup .= drupal_render($form['pyear']);
  464. $markup .= drupal_render($form['uniquename']);
  465. $markup .= "<b>Include Additional Details</b><br>You may add additional properties to this publication by scrolling to the bottom of this table, selecting a property type from the dropdown and adding text. You may add as many properties as desired by clicking the plus button on the right. To remove a property, click the minus button";
  466. $markup .= $properties_table;
  467. $markup .= drupal_render($form['is_obsolete']);
  468. $form['properties'] = array(
  469. '#type' => 'markup',
  470. '#value' => $markup,
  471. );
  472. return drupal_render($form);
  473. }
  474. /*
  475. *
  476. */
  477. function tripal_pub_theme_node_form_properties($form) {
  478. $rows = array();
  479. if ($form['properties']) {
  480. // first add in the properties derived from the pub and pubprop tables
  481. // the array tree for these properties looks like this:
  482. // $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"]
  483. foreach ($form['properties'] as $type_id => $elements) {
  484. // there are other fields in the properties array so we only
  485. // want the numeric ones those are our type_id
  486. if (is_numeric($type_id)) {
  487. foreach ($elements as $rank => $element) {
  488. if (is_numeric($rank)) {
  489. $rows[] = array(
  490. drupal_render($element["prop_id-$type_id-$rank"]),
  491. drupal_render($element["prop_value-$type_id-$rank"]),
  492. drupal_render($element["remove-$type_id-$rank"]),
  493. );
  494. }
  495. }
  496. }
  497. }
  498. // second, add in any new properties added by the user through AHAH callbacks
  499. // the array tree for these properties looks like this:
  500. // $form['properties']['new'][$type_id][$rank]["new_id-$new_id-$rank"]
  501. foreach ($form['properties']['new'] as $type_id => $elements) {
  502. if (is_numeric($type_id)) {
  503. foreach ($elements as $rank => $element) {
  504. if (is_numeric($rank)) {
  505. $rows[] = array(
  506. drupal_render($element["new_id-$type_id-$rank"]),
  507. drupal_render($element["new_value-$type_id-$rank"]),
  508. drupal_render($element["remove-$type_id-$rank"]),
  509. );
  510. }
  511. }
  512. }
  513. }
  514. // finally add in a set of blank field for adding a new property
  515. $rows[] = array(
  516. drupal_render($form['properties']['new']['new_id']),
  517. drupal_render($form['properties']['new']['new_value']),
  518. drupal_render($form['properties']['new']['add']),
  519. );
  520. }
  521. $headers = array('Property Type','Value', '');
  522. return theme('table', $headers, $rows, array('id'=> "tripal-pub-edit-properties-table"));
  523. }
  524. /*
  525. *
  526. */
  527. function tripal_pub_property_add() {
  528. $status = TRUE;
  529. // prepare and render the form
  530. $form = tripal_core_ahah_prepare_form();
  531. // we only want to return the properties as that's all we'll replace with this AHAh callback
  532. $data = tripal_pub_theme_node_form_properties($form);
  533. // bind javascript events to the new objects that will be returned
  534. // so that AHAH enabled elements will work.
  535. $settings = tripal_core_ahah_bind_events();
  536. // return the updated JSON
  537. drupal_json(
  538. array(
  539. 'status' => $status,
  540. 'data' => $data,
  541. 'settings' => $settings,
  542. )
  543. );
  544. }
  545. /*
  546. *
  547. */
  548. function tripal_pub_property_delete() {
  549. $status = TRUE;
  550. // prepare and render the form
  551. $form = tripal_core_ahah_prepare_form();
  552. // we only want to return the properties as that's all we'll replace with this AHAh callback
  553. $data = tripal_pub_theme_node_form_properties($form);
  554. // bind javascript events to the new objects that will be returned
  555. // so that AHAH enabled elements will work.
  556. $settings = tripal_core_ahah_bind_events();
  557. // return the updated JSON
  558. drupal_json(
  559. array(
  560. 'status' => $status,
  561. 'data' => $data,
  562. 'settings' => $settings,
  563. )
  564. );
  565. }
  566. /*
  567. *
  568. */
  569. function tripal_pub_property_get_description() {
  570. $new_id = $_POST['new_id'];
  571. $values = array('cvterm_id' => $new_id);
  572. $cvterm = tripal_core_chado_select('cvterm', array('definition'), $values);
  573. $description = '&nbsp;';
  574. if ($cvterm[0]->definition) {
  575. $description = $cvterm[0]->definition;
  576. }
  577. drupal_json(
  578. array(
  579. 'status' => TRUE,
  580. 'data' => '<div id="tripal-pub-new_value-desc">' . $description . '</div>',
  581. )
  582. );
  583. }