tripal_bulk_loader.admin.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /*******************************************************************************
  3. * tripal_bulk_loader_admin_template
  4. */
  5. function tripal_bulk_loader_admin_template () {
  6. $add_url = url("admin/tripal/tripal_bulk_loader_template/add");
  7. $output = "<a href=\"$add_url\">Create a new bulk loader template</a><br>";
  8. $del_url = url("admin/tripal/tripal_bulk_loader_template/delete");
  9. $output .= "<a href=\"$del_url\">Delete a bulk loader template</a>";
  10. return $output;
  11. }
  12. /*******************************************************************************
  13. * tripal_bulk_loader_admin_template_add
  14. */
  15. function tripal_bulk_loader_admin_template_add () {
  16. return drupal_get_form('tripal_bulk_loader_admin_template_form');
  17. }
  18. function tripal_bulk_loader_admin_template_form (&$form_state = NULL) {
  19. $form = array();
  20. $form['template_name'] = array(
  21. '#type' => 'textfield',
  22. '#title' => t('Template Name'),
  23. '#weight' => 0,
  24. '#attributes' => array('id' => 'tripal-bulk-loader-template-name'),
  25. '#required' => TRUE
  26. );
  27. $form['datafile'] = array(
  28. '#type' => 'fieldset',
  29. '#title' => t("From"),
  30. '#weight' => 1,
  31. '#attributes' => array('id' => 'tripal-bulk-loader-template-from-field'),
  32. );
  33. $form['template'] = array(
  34. '#type' => 'fieldset',
  35. '#title' => t("To"),
  36. '#weight' => 1,
  37. '#attributes' => array('id' => 'tripal-bulk-loader-template-to-field'),
  38. );
  39. $form['submit'] = array (
  40. '#type' => 'submit',
  41. '#value' => t('Create'),
  42. '#weight' => 2,
  43. '#executes_submit_callback' => TRUE,
  44. );
  45. return $form;
  46. }
  47. /************************************************************************
  48. * tripal_bulk_loader_admin_template_form_submit
  49. */
  50. function tripal_bulk_loader_admin_template_form_submit($form, &$form_state){
  51. $name = $form_state['values']['template_name'];
  52. $template_array = "array('DUMMY' => 'TEMPLATE ARRAY')";
  53. $sql = "INSERT INTO {tripal_bulk_loader_template} (name, template_array) VALUES ('%s', '%s')";
  54. if (db_query($sql, $name, $template_array)) {
  55. drupal_set_message("Bulk loader template '$name' added.");
  56. }
  57. }
  58. /************************************************************************
  59. * tripal_bulk_loader_admin_template_delete
  60. */
  61. function tripal_bulk_loader_admin_template_delete () {
  62. return drupal_get_form('tripal_bulk_loader_admin_template_del_form');
  63. }
  64. /************************************************************************
  65. * tripal_bulk_loader_admin_template_del_from
  66. */
  67. function tripal_bulk_loader_admin_template_del_form (&$form_state = NULL) {
  68. $form = array();
  69. $sql = "SELECT * FROM {tripal_bulk_loader_template}";
  70. $results = db_query($sql);
  71. $templates = array();
  72. while ($template = db_fetch_object($results)) {
  73. $templates [$template->template_id] = $template->name;
  74. }
  75. if ($templates) {
  76. $form['label'] = array(
  77. '#type' => 'item',
  78. '#title' => t('Select a template to delete'),
  79. '#weight' => 0,
  80. );
  81. $form['template_name'] = array(
  82. '#type' => 'select',
  83. '#title' => t('Template Name'),
  84. '#options' => $templates,
  85. '#weight' => 1,
  86. '#required' => TRUE
  87. );
  88. $form['submit'] = array (
  89. '#type' => 'submit',
  90. '#value' => t('Delete'),
  91. '#weight' => 2,
  92. '#executes_submit_callback' => TRUE,
  93. );
  94. } else {
  95. $form['label'] = array(
  96. '#type' => 'item',
  97. '#description' => t('No template available'),
  98. '#weight' => 0,
  99. );
  100. }
  101. return $form;
  102. }
  103. /************************************************************************
  104. * function tripal_bulk_loader_admin_template_del_form_submit
  105. */
  106. function tripal_bulk_loader_admin_template_del_form_submit($form, &$form_state){
  107. $template = $form_state['values']['template_name'];
  108. $name = db_result(db_query("SELECT name FROM {tripal_bulk_loader_template} WHERE template_id = $template"));
  109. $sql = "DELETE FROM {tripal_bulk_loader_template} WHERE template_id = %d";
  110. if (db_query($sql, $template)) {
  111. drupal_set_message("Bulk loader template '$name' deleted.");
  112. }
  113. }