tripal_stock-secondary_tables.inc

@todo Add file header description

File

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