pub_form.inc 23 KB

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