tripal_stock-secondary_tables.inc 5.3 KB

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