tripal_core.module 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. require_once "jobs.php";
  3. require_once "mviews.php";
  4. require_once "cvterms.php";
  5. require_once "chado_install.php";
  6. require_once "gff_loader.php";
  7. /*************************************************************************
  8. *
  9. */
  10. function tripal_core_init(){
  11. }
  12. /*************************************************************************
  13. *
  14. */
  15. function tripal_create_moddir($module_name){
  16. // make the data directory for this module
  17. $data_dir = file_directory_path() . "/tripal/$module_name";
  18. if(!file_check_directory($data_dir,FILE_CREATE_DIRECTORY|FILE_MODIFY_PERMISSIONS)){
  19. $message = "Cannot create directory $data_dir. This module may not ".
  20. "behave correctly without this directory. Please create ".
  21. "the directory manually or fix the problem and reinstall.";
  22. drupal_set_message($message,'error');
  23. watchdog('tripal_core',$message,array(),WATCHDOG_ERROR);
  24. }
  25. }
  26. /*************************************************************************
  27. *
  28. */
  29. function tripal_get_moddir($module_name){
  30. $data_dir = file_directory_path() . "/tripal/$module_name";
  31. return $data_dir;
  32. }
  33. /*************************************************************************
  34. *
  35. */
  36. function tripal_core_menu() {
  37. $items = array();
  38. // Triapl setting groups
  39. $items['admin/tripal'] = array(
  40. 'title' => 'Tripal Management',
  41. 'description' => "Manage the behavior or Tripal and its various modules.",
  42. 'position' => 'right',
  43. 'weight' => -5,
  44. 'page callback' => 'system_admin_menu_block_page',
  45. 'access arguments' => array('administer site configuration'),
  46. 'file' => 'system.admin.inc',
  47. 'file path' => drupal_get_path('module', 'system'),
  48. );
  49. // the administative settings menu
  50. /* $items['admin/tripal/tripal_core'] = array(
  51. 'title' => 'Tripal core settings',
  52. 'description' => 'Tripal Settings',
  53. 'page callback' => 'drupal_get_form',
  54. 'page arguments' => array('tripal_core_admin'),
  55. 'access arguments' => array('access administration pages'),
  56. 'type' => MENU_NORMAL_ITEM,
  57. );
  58. */
  59. $items['admin/tripal/tripal_jobs'] = array(
  60. 'title' => 'Jobs',
  61. 'description' => 'Jobs managed by Tripal',
  62. 'page callback' => 'tripal_jobs_report',
  63. 'access arguments' => array('access administration pages'),
  64. 'type' => MENU_NORMAL_ITEM,
  65. );
  66. $items['admin/tripal/tripal_mview/%'] = array(
  67. 'title' => 'Materialized View',
  68. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  69. 'page callback' => 'tripal_mview_report',
  70. 'page arguments' => array(3),
  71. 'access arguments' => array('access administration pages'),
  72. 'type' => MENU_NORMAL_ITEM,
  73. );
  74. $items['admin/tripal/tripal_mviews'] = array(
  75. 'title' => 'Materialized Views',
  76. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  77. 'page callback' => 'tripal_mviews_report',
  78. 'access arguments' => array('access administration pages'),
  79. 'type' => MENU_NORMAL_ITEM,
  80. );
  81. $items['admin/tripal/tripal_mviews/new'] = array(
  82. 'title' => 'Create View',
  83. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  84. 'page callback' => 'drupal_get_form',
  85. 'page arguments' => array('tripal_mviews_form'),
  86. 'access arguments' => array('access administration pages'),
  87. 'type' => MENU_NORMAL_ITEM,
  88. );
  89. $items['admin/tripal/tripal_mviews/edit/%'] = array(
  90. 'title' => 'Edit View',
  91. 'page callback' => 'drupal_get_form',
  92. 'page arguments' => array('tripal_mviews_form',4),
  93. 'access arguments' => array('access administration pages'),
  94. 'type' => MENU_NORMAL_ITEM,
  95. );
  96. $items['admin/tripal/tripal_mviews/action/%/%'] = array(
  97. 'title' => 'Create View',
  98. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  99. 'page callback' => 'tripal_mviews_action',
  100. 'page arguments' => array(4,5),
  101. 'access arguments' => array('access administration pages'),
  102. 'type' => MENU_CALLBACK,
  103. );
  104. $items['tripal_toggle_box_menu/%/%/%'] = array(
  105. 'title' => t('Libraries'),
  106. 'page callback' => 'tripal_toggle_box_menu',
  107. 'page arguments' => array(1,2,3),
  108. 'access arguments' => array('access administration pages'),
  109. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  110. );
  111. $items['admin/tripal/chado_install'] = array(
  112. 'title' => 'Install Chado v1.11',
  113. 'description' => 'Installs Chado version 1.11 inside the current Drupal database',
  114. 'page callback' => 'tripal_core_install_job',
  115. 'access arguments' => array('access administration pages'),
  116. 'type' => MENU_NORMAL_ITEM,
  117. );
  118. $items['admin/tripal/gff3_load'] = array(
  119. 'title' => 'Load a GFF3 file',
  120. 'description' => 'Loads a GFF3 file into Chado',
  121. 'page callback' => 'tripal_core_load_gff3',
  122. 'access arguments' => array('access administration pages'),
  123. 'type' => MENU_NORMAL_ITEM,
  124. );
  125. return $items;
  126. }
  127. /************************************************************************
  128. * The typical display for information on feature, organism, library, etc
  129. * pages is to use the Tripal expandable boxes. However, some sites may
  130. * prefer to use a menu system to keep the pages less cluttered. This
  131. * function provides a common interface for setting a Drupal variable
  132. * that indicates whether or not the content is displayed in a box or as
  133. * a menu item. This function just reverses the setting each time it is
  134. * called
  135. */
  136. function tripal_toggle_box_menu($module,$box_name,$nid){
  137. // if the content is not in a menu then we wnat to turn on the
  138. // menu. If the content is in a menu item then we want to turn
  139. // on the box.
  140. if(strcmp(variable_get("$module-box-$box_name","menu_off"),"menu_off")==0){
  141. variable_set("$module-box-$box_name","menu_on");
  142. } else {
  143. variable_set("$module-box-$box_name","menu_off");
  144. }
  145. drupal_goto("node/$nid");
  146. }
  147. /************************************************************************
  148. *
  149. */
  150. function tripal_core_admin () {
  151. $form['chado_feature_data_url'] = array (
  152. '#title' => t('URL for data files'),
  153. '#type' => t('textfield'),
  154. '#description' => t("This is the base URL location (without a leading forward slash) for where files (e.g. blast .xml files) related to each feature are stored. All files available for download or parsing that a feature needs for display should be located in this base directory."),
  155. '#required' => TRUE,
  156. '#default_value' => variable_get('chado_feature_data_url','sites/default/files/data'),
  157. );
  158. return system_settings_form($form);
  159. }
  160. /************************************************************************
  161. * The tripal_db_set_active function is used to prevent namespace collisions
  162. * when chado and drupal are installed in the same database but in different
  163. * schemas. It is also used for backwards compatibility with older versions
  164. * of tripal or in cases where chado is located outside of the Drupal database.
  165. */
  166. function tripal_db_set_active($dbname){
  167. global $db_url, $db_type;
  168. // only postgres can support search paths. So if this is MysQL then
  169. // just run the normal tripal_db_set_active function.
  170. if(strcmp($db_type,'pgsql')==0){
  171. // if the 'chado' database is in the $db_url variable then chado is
  172. // not in the same Drupal database
  173. if(is_array($db_url)){
  174. if(isset($db_url[$dbname])){
  175. return tripal_db_set_active($dbname);
  176. }
  177. }
  178. // here we make the assumption that the default database schema is
  179. // 'public'. This will most likely always be the case but if not,
  180. // then this code will break
  181. if(strcmp($dbname,'chado')==0){
  182. db_query("set search_path to %s",'chado,public');
  183. return 'public';
  184. }
  185. else {
  186. db_query("set search_path to %s",'public,chado');
  187. return 'chado';
  188. }
  189. }
  190. else return tripal_db_set_active($dbname);
  191. }