tripal_core.module 8.9 KB

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