tripal_stock-secondary_tables.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. // $Id$
  3. /**
  4. *
  5. *
  6. * @ingroup tripal_stock
  7. */
  8. function tripal_stock_back_to_stock_button($form_state, $nid) {
  9. $form = array();
  10. $form['nid'] = array(
  11. '#type' => 'hidden',
  12. '#value' => $nid
  13. );
  14. $form["submit-back"] = array(
  15. '#type' => 'submit',
  16. '#value' => t('Back to Stock')
  17. );
  18. return $form;
  19. }
  20. /**
  21. *
  22. *
  23. * @ingroup tripal_stock
  24. */
  25. function tripal_stock_back_to_stock_button_submit($form, $form_state) {
  26. drupal_goto('node/'.$form_state['values']['nid']);
  27. }
  28. /**
  29. *
  30. *
  31. * @ingroup tripal_stock
  32. */
  33. function tripal_stock_add_chado_properties_progress($current) {
  34. $value = '<div class="form_progress"><div class="form_progress-text">';
  35. if ($current == 'main') { $value .= '<span id="form-step-current">Create Basic Stock</span>'; }
  36. else { $value .= '<span id="form-step">Create Basic Stock</span>'; }
  37. $value .= '<span id="form-segway"> >> </span>';
  38. if ($current == 'properties') { $value .= '<span id="form-step-current">Add Synonyms & Properties</span>'; }
  39. else { $value .= '<span id="form-step">Add Synonyms & Properties</span>'; }
  40. $value .= '<span id="form-segway"> >> </span>';
  41. if ($current == 'db_references') { $value .= '<span id="form-step-current">Add Database References</span>'; }
  42. else { $value .= '<span id="form-step">Add Database References</span>'; }
  43. $value .= '<span id="form-segway"> >> </span>';
  44. if ($current == 'relationships') { $value .= '<span id="form-step-current">Add Relationships</span>'; }
  45. else { $value .= '<span id="form-step">Add Relationships</span>'; }
  46. $value .= '</div></div>';
  47. return $value;
  48. }
  49. /**
  50. *
  51. *
  52. * @ingroup tripal_stock
  53. */
  54. function tripal_stock_add_chado_properties_navigate($form_state, $step, $nid) {
  55. $form = array();
  56. $form['current_step'] = array(
  57. '#type' => 'hidden',
  58. '#value' => $step
  59. );
  60. // Use this field to set all the steps and the path to each form
  61. // where each step is of the form name;path and each step is separated by ::
  62. $steps =array(
  63. 'properties' => 'node/%node/properties',
  64. 'db_references' => 'node/%node/db_references',
  65. 'relationships' => 'node/%node/relationships'
  66. );
  67. $steps_value = array();
  68. foreach ($steps as $k => $v) { $steps_value[] = $k.';'.$v; }
  69. $form['steps'] = array(
  70. '#type' => 'hidden',
  71. '#value' => implode('::', $steps_value)
  72. );
  73. $form['first_step'] = array(
  74. '#type' => 'hidden',
  75. '#value' => 'properties'
  76. );
  77. $form['last_step'] = array(
  78. '#type' => 'hidden',
  79. '#value' => 'relationships'
  80. );
  81. $form['nid'] = array(
  82. '#type' => 'hidden',
  83. '#value' => $nid
  84. );
  85. if ($step != $form['first_step']['#value']) {
  86. $form['submit-prev'] = array(
  87. '#type' => 'submit',
  88. '#value' => t('Previous Step')
  89. );
  90. }
  91. if ($step != $form['last_step']['#value']) {
  92. $form['submit-next'] = array(
  93. '#type' => 'submit',
  94. '#value' => t('Next Step')
  95. );
  96. }
  97. if ($step == $form['last_step']['#value']) {
  98. $form['submit-finish'] = array(
  99. '#type' => 'submit',
  100. '#value' => t('Finish')
  101. );
  102. }
  103. return $form;
  104. }
  105. /**
  106. *
  107. *
  108. * @ingroup tripal_stock
  109. */
  110. function tripal_stock_add_chado_properties_navigate_submit($form, $form_state) {
  111. $raw_steps = preg_split('/::/', $form_state['values']['steps']);
  112. $steps = array();
  113. $current_index = 'EMPTY';
  114. $i=0;
  115. foreach ($raw_steps as $raw_step) {
  116. $step = preg_split('/;/', $raw_step);
  117. $steps[$i] = $step;
  118. if ($step[0] == $form_state['values']['current_step']) {
  119. $current_index = $i;
  120. }
  121. $i++;
  122. }
  123. $num_steps = $i;
  124. if (strcmp($current_index,'EMPTY') == 0) {
  125. // No Matching Step
  126. drupal_set_message('Could not determine next step -'.$form_state['values']['current_step'].', please contact the administrator', 'error');
  127. } elseif ($current_index == 0) {
  128. $next_goto = $steps[$current_index+1][1];
  129. } elseif ($current_index == ($num_steps-1)) {
  130. $prev_goto = $steps[$current_index-1][1];
  131. $next_goto = 'node/%node';
  132. } else {
  133. $prev_goto = $steps[$current_index-1][1];
  134. $next_goto = $steps[$current_index+1][1];
  135. }
  136. if ($form_state['clicked_button']['#value'] == t('Previous Step') ) {
  137. //replace %node
  138. $prev_goto = preg_replace('/%node/', $form_state['values']['nid'], $prev_goto);
  139. $_REQUEST['destination'] = $prev_goto;
  140. } elseif ($form_state['clicked_button']['#value'] == t('Next Step') ) {
  141. $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
  142. $_REQUEST['destination'] = $next_goto;
  143. } elseif ($form_state['clicked_button']['#value'] == t('Finish') ) {
  144. $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
  145. $_REQUEST['destination'] = $next_goto;
  146. }
  147. }
  148. /**
  149. *
  150. *
  151. * @ingroup tripal_stock
  152. */
  153. function tripal_stock_is_obsolete_form($node, $stock_id) {
  154. $form['make_obsolete'] = array(
  155. '#type' => 'submit',
  156. '#value' => t('Mark Stock as Obsolete')
  157. );
  158. $form['make_obsolete_stock_id'] = array(
  159. '#type' => 'value',
  160. '#value' => $stock_id,
  161. '#required' => TRUE
  162. );
  163. return $form;
  164. }
  165. /**
  166. *
  167. *
  168. * @ingroup tripal_stock
  169. */
  170. function tripal_stock_is_obsolete_form_submit($form, &$form_state) {
  171. $previous_db = tripal_db_set_active('chado');
  172. db_query(
  173. "UPDATE stock SET is_obsolete='t' WHERE stock_id=%d",
  174. $form_state['values']['make_obsolete_stock_id']
  175. );
  176. tripal_db_set_active($previous_db);
  177. }