tripal_views_setup.admin.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. function tripal_views_setup_admin_form(){
  3. $form = array();
  4. $form['#theme'] = 'tripal';
  5. $query_results = db_query('SELECT * FROM public.tripal_views_setup;');
  6. $header = array('Setup ID', 'Name', 'Materialized View ID', 'Base Table Name', 'Description');
  7. $rows = array();
  8. $results = array();
  9. while($result = db_fetch_object($query_results)){
  10. $rows[] = array($result->setup_id, $result->name, $result->mview_id, $result->base_table_name, $result->description,);
  11. $results[] = $result;
  12. }
  13. $options = array();
  14. foreach ($results as $key => $value) {
  15. if(!empty($value))
  16. $options[] = $value->setup_id;// . ' | ' . $value->name . ' | ' . $value->mview_id . ' | ' . $value->base_table_name;
  17. }
  18. $form['existing_rows'] = array(
  19. '#type' => 'select',
  20. '#options' => $options,
  21. '#description' => '<strong>Select a View Setup to delete from the database.</strong>',
  22. '#prefix' => theme('table', $header, $rows),
  23. );
  24. $form['submit'] = array(
  25. '#type' => 'submit',
  26. '#value' => t('Remove'),
  27. );
  28. $form['cancel'] = array(
  29. '#type' => 'markup',
  30. '#value' => l(t('Cancel '), 'admin/tripal/'),
  31. );
  32. $form['new'] = array(
  33. '#type' => 'markup',
  34. '#value' => l(t(' New'), 'admin/tripal/tripal_views_setup_new'),
  35. );
  36. return $form;
  37. }
  38. function tripal_views_setup_admin_form_submit($form, &$form_state){
  39. $value = $form['existing_rows']['#options'][$form_state['values']['existing_rows']];
  40. db_query("DELETE FROM public.tripal_views_setup WHERE setup_id = $value;");
  41. db_query("DELETE FROM public.tripal_views_handlers WHERE setup_id = $value;");
  42. db_query("DELETE FROM public.tripal_mviews_join WHERE setup_id = $value;");
  43. }
  44. function tripal_views_setup_new_search_form($form_state){
  45. $form = array();
  46. $form['#cache'] = TRUE;
  47. $form['row_name'] = array(
  48. '#title' => t('Name'),
  49. '#type' => 'textfield',
  50. '#size' => 60,
  51. '#maxlength' => 128,
  52. '#description' => 'Name of the Views Setup',
  53. '#required' => TRUE,
  54. );
  55. $form['row_description'] = array(
  56. '#title' => t('Description'),
  57. '#type' => 'textfield',
  58. '#size' => 60,
  59. '#maxlength' => 255,
  60. '#description' => 'Briefly describe in which view this will be used',
  61. '#required' => TRUE,
  62. );
  63. $mview_query = db_query("SELECT name FROM {tripal_mviews} ORDER BY name;");
  64. $mview_options = array();
  65. while ($mview_option = db_fetch_array($mview_query)){
  66. $mview_options[] = $mview_option['name'];
  67. }
  68. $form['row_mview'] = array(
  69. '#title' => t('Materialized View'),
  70. '#type' => 'select',
  71. '#options' => $mview_options,
  72. '#description' => 'Which materialized view to use.',
  73. '#required' => TRUE,
  74. // '#ahah' => array(
  75. // 'path' => 'rowmview/ahah',
  76. // 'wrapper' => 'rowmview-ahah',
  77. // 'effect' => 'fade',
  78. // 'event' => 'change',
  79. // 'method' => 'replace',
  80. // ),
  81. );
  82. $form['row_base_table_name'] = array(
  83. '#title' => t('Base Table Name'),
  84. '#type' => 'select',
  85. // '#options' => array('stub'),
  86. '#options' => tripal_core_get_chado_tables(),
  87. '#description' => 'Select which chado table to use for this view.',
  88. '#required' => TRUE,
  89. );
  90. //--tripal_mviews_join
  91. $form['row_view_column'] = array(
  92. '#title' => t('View Column'),
  93. '#type' => 'select',
  94. '#options' => array('stub'),
  95. '#description' => 'Which materialized view column to use.',
  96. '#required' => TRUE,
  97. );
  98. $form['row_chado_column'] = array(
  99. '#title' => t('Chado Column'),
  100. '#type' => 'select',
  101. '#options' => array('stub'),
  102. '#description' => 'Which Chado table column to use.',
  103. '#required' => TRUE,
  104. );
  105. $form['submit'] = array(
  106. '#type' => 'submit',
  107. '#value' => 'Create',
  108. );
  109. return $form;
  110. }
  111. // function rowmview_ahah(){
  112. // $query = "SELECT mv_specs FROM tripal_mviews;";
  113. // $row_options = db_fetch_array(db_query($query));
  114. //
  115. //
  116. // }
  117. // function tripal_views_setup_ajax_db_mview_columns(){
  118. // $mview = $_POST['row_mview'];
  119. // $form = drupal_get_form('tripal_views_setup_mview_column_form', $mview);
  120. // drupal_json(array('status' => TRUE, 'data' => $form));
  121. // }
  122. // function tripal_views_setup_mview_column_form(&$form_state = NULL, $mview = NULL){
  123. // if ($mview){
  124. // $mview_query = db_fetch_array(db_query("SELECT mv_specs FROM tripal_mviews WHERE name = $mview;"));
  125. //
  126. // $form['row_mview']
  127. // }
  128. //
  129. // }
  130. // function tripal_views_setup_ajax_db_chado_tables(){
  131. // }
  132. function tripal_views_setup_new_search_form_submit($form, &$form_state){
  133. }