PageRenderTime 38ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/core/limsadmin.modules.php

https://bitbucket.org/unixcrab/colab-lims
PHP | 202 lines | 146 code | 45 blank | 11 comment | 31 complexity | 893fce57457bf5550fc80d5caf058819 MD5 | raw file
  1. <?php
  2. if( $_SESSION['lims']['auth_level'] < PERM_ADMIN ) return;
  3. include_once "functions.modules.php";
  4. $mods = getModulesAll();
  5. $mod_id_arr = array();
  6. foreach( $mods as $m ) {
  7. $mod_id_arr[$m->file] = $m->module_id;
  8. }
  9. //print "<pre>";
  10. // var_dump($mod_id_arr);
  11. //print "</pre>";
  12. ?>
  13. <h4><?php print $_SESSION['lims']['langdata']['limsadmin_modules']; ?></h4>
  14. <hr>
  15. <div id="user_feedback" class="alert alert-info" style="display:none;"></div>
  16. <div class="accordion" id="accordion2">
  17. <?php
  18. $tmp_mod_id = 1;
  19. if ($handle = opendir($modules_dir)) {
  20. while (false !== ($entry = readdir($handle))) {
  21. if ($entry != "." && $entry != "..") {
  22. $ext = substr(strrchr($entry, '.'), 1);
  23. if( $ext != "xml" ) continue;
  24. $modXML = simplexml_load_file($modules_dir."/".$entry);
  25. //print "<pre>";
  26. //var_dump($modXML->db->table[0]['type']);
  27. //foreach($modXML->db->table[0]->field as $field) var_dump($field);
  28. //print "</pre>";
  29. $accord_name = str_replace(".","_",$entry);
  30. $mod_enabled = true;
  31. $chkString = "checked";
  32. //if( isset($mod_id_arr[$entry]) && ( $mods[$mod_id_arr[$entry]]->active==1 ) ) {
  33. if( isset($mod_id_arr[$entry]) ) {
  34. $mod_id = $mod_id_arr[$entry];
  35. $mod_menus = getModuleMenus($mod_id,MODULE_COMPONENT_APP_CONFIG);
  36. if($mods[$mod_id_arr[$entry]]->active==0) {
  37. $chkString = "";
  38. $mod_enabled = false;
  39. }
  40. }
  41. else {
  42. $mod_id = $tmp_mod_id;
  43. $mod_enabled = false;
  44. $chkString = "";
  45. }
  46. $descrLang = $modXML->descr->gb;
  47. if( $modXML->descr->$_SESSION['lims']['lang'] != "" ) $descrLang = $modXML->descr->$_SESSION['lims']['lang'];
  48. $menu_chkString = "";
  49. ?>
  50. <div class="accordion-group">
  51. <div class="accordion-heading">
  52. <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapse-<?php print $accord_name; ?>">
  53. <?php print "<strong>".myhtmlentities($modXML->name)."</strong> (".myhtmlentities($descrLang).")"; ?>
  54. </a>
  55. </div>
  56. <div id="collapse-<?php print $accord_name; ?>" class="accordion-body collapse ">
  57. <div class="accordion-inner">
  58. <!-- MODULE CONFIG -->
  59. <label class="checkbox">
  60. <input type="checkbox" id='module_enable_chkbox--<?php print $entry; ?>' <?php print $chkString; ?> value='<?php print $chkString; ?>'>
  61. <?php print $_SESSION['lims']['langdata']['enable']; ?>
  62. </label>
  63. <form>
  64. <fieldset>
  65. <legend><?php print $_SESSION['lims']['langdata']['menus']; ?></legend>
  66. <?php if( isset($mod_menus[MENU_ADMIN]) ) $menu_chkString="checked"; else $menu_chkString=""; ?>
  67. <label class="checkbox"><input type="checkbox" id="moduleMenu--<?php print $entry; ?>--admin--<?php print MENU_ADMIN; ?>" <?php print $menu_chkString; ?>> <?php print $_SESSION['lims']['langdata']['topmenu_admin']; ?></label>
  68. <?php if( isset($mod_menus[MENU_USER_PROFILE]) ) $menu_chkString="checked"; else $menu_chkString=""; ?>
  69. <label class="checkbox"><input type="checkbox" id="moduleMenu--<?php print $entry; ?>--profile--<?php print MENU_USER_PROFILE; ?>" <?php print $menu_chkString; ?>> <?php print $_SESSION['lims']['langdata']['account_admin']; ?></label>
  70. <?php
  71. $menu_section = 0;
  72. if( isset($mod_menus[MENU_INVENTORY]) ) {
  73. $menu_chkString="checked";
  74. $menu_section = $mod_menus[MENU_INVENTORY]->section_id;
  75. }
  76. else $menu_chkString="";
  77. ?>
  78. <label class="checkbox">
  79. <input type="checkbox" id="moduleMenu--<?php print $entry; ?>--inv--<?php print MENU_INVENTORY; ?>" <?php print $menu_chkString; ?>> <?php print $_SESSION['lims']['langdata']['limsadmin_inventory']; ?>
  80. </label>
  81. <select id="moduleMenu--<?php print $entry; ?>--invSection">
  82. <option value=0><?php print $_SESSION['lims']['langdata']['section']; ?></option>
  83. <option value=<?php print MENU_SECTION_CARTONS; ?> <?php if($menu_section==MENU_SECTION_CARTONS) print "selected"; ?>>
  84. <?php print $_SESSION['lims']['langdata']['cartons']; ?>
  85. </option>
  86. <option value=<?php print MENU_SECTION_SAMPLES; ?> <?php if($menu_section==MENU_SECTION_SAMPLES) print "selected"; ?>>
  87. <?php print $_SESSION['lims']['langdata']['samples']; ?>
  88. </option>
  89. <option value=<?php print MENU_SECTION_LAB; ?> <?php if($menu_section==MENU_SECTION_LAB) print "selected"; ?>>
  90. <?php print $_SESSION['lims']['langdata']['laboratory']; ?>
  91. </option>
  92. </select>
  93. </fieldset>
  94. <button class="btn btn-primary" id="saveButton--<?php print $entry; ?>"><?php print $button_save; ?></button>
  95. </form>
  96. </div>
  97. </div>
  98. <?php
  99. $tmp_mod_id++;
  100. ?>
  101. </div>
  102. <?php
  103. //if(!$mod_enabled) print "<script>$(function() { $('[id^=moduleMenu--reserve_instrument\\\.xml--]').attr('disabled','disabled'); });</script>";
  104. if(!$mod_enabled) print "<script>$(function() { $('[id^=moduleMenu--".str_replace(".","\\\.",$entry)."--]').attr('disabled','disabled'); });</script>";
  105. }
  106. }
  107. closedir($handle);
  108. }
  109. ?>
  110. </div>
  111. <script type="text/javascript" src="<?print $site_root.'/core/js/json/jquery.json.min.js';?>"></script>
  112. <script>
  113. $(function() {
  114. $("[id^=saveButton--]").click(function () {
  115. var saveMenus = true;
  116. var fname = this.id.split("--")[1];
  117. var fname_esc = fname.replace(".","\\.");
  118. //console.log("id="+this.id+" fname="+fname);
  119. var enMod = $("#module_enable_chkbox--"+fname_esc).val();
  120. var menuArray = {}; //new Array(); // key=menu id, value=section id
  121. $("[id*=moduleMenu--"+fname_esc+"--]").each(function(){
  122. if(this.checked) {
  123. var mid = this.id.split("--")[3];
  124. menuArray[mid] = 0;
  125. if(mid==<?php print MENU_INVENTORY;?>) {
  126. // get the section id
  127. var sid = parseInt($("#moduleMenu--"+fname_esc+"--invSection").val());
  128. menuArray[mid] = sid;
  129. console.log("sid="+sid);
  130. if((sid==0)&&(enMod=="checked")) {
  131. saveMenus = false;
  132. userFeedbackL("alert-error", "module_choose_section");
  133. }
  134. }
  135. console.log(mid+" checked");
  136. }
  137. });
  138. var numMenus = Object.keys(menuArray).length;
  139. console.log("menuArray length "+numMenus);
  140. if(numMenus==0) {
  141. saveMenus = false;
  142. userFeedbackL("alert-error", "module_choose_menu");
  143. }
  144. if(saveMenus) {
  145. var menuArrayJSON = $.toJSON(menuArray);
  146. console.log(menuArrayJSON);
  147. if(enMod=="checked") {
  148. ajaxUpdateModule(fname, 1, menuArrayJSON);
  149. }
  150. else {
  151. ajaxUpdateModule(fname, 0, menuArrayJSON);
  152. }
  153. }
  154. return false;
  155. });
  156. });
  157. </script>