tripal_feature-secondary_tables.inc 5.7 KB

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