pub_form.inc 24 KB

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