You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AccueilModules.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. function __autoload($class)
  3. {
  4. $BASE_DIR = $_SERVER['DOCUMENT_ROOT'] . '/accueil/'; // à modifier selon la configuration souhaitée
  5. set_include_path($BASE_DIR);
  6. $path = 'modules/' . $class;
  7. if (file_exists($path . DIRECTORY_SEPARATOR . ucfirst($class) . '.php') || file_exists($BASE_DIR . $path . DIRECTORY_SEPARATOR . ucfirst($class) . '.php')) {
  8. require_once($path . DIRECTORY_SEPARATOR . ucfirst($class) . '.php');
  9. } else {
  10. require_once('class/' . $class . '.php');
  11. }
  12. }
  13. class AccueilModules
  14. {
  15. const CONFIG_FILE = 'db/config.xml';
  16. private $modules = array();
  17. /**
  18. * Constructeur
  19. * Initialise le XML de conf générale
  20. */
  21. function __construct()
  22. {
  23. if ($config = simplexml_load_file(self::CONFIG_FILE)) {
  24. $config_xml = $config->item;
  25. foreach ($config_xml as $item) {
  26. $this->modules["$item[id]"] = $item;
  27. }
  28. } else {
  29. echo 'Impossible de trouver le fichier de configuration.';
  30. }
  31. }
  32. /**
  33. *
  34. * Initialise les modules activés uniquement
  35. */
  36. function getModules()
  37. {
  38. foreach ($this->modules as $module => $moduleConf) {
  39. if (file_exists('modules/' . $module . '/' . ucfirst($module) . '.php') && $moduleConf->visibility == "true") {
  40. $params = array();
  41. foreach ($moduleConf as $confParam) {
  42. $params[$confParam->getName()] = "$confParam";
  43. }
  44. $module = new $module($params);
  45. if (is_subclass_of($module, 'Module')) {
  46. $module->build();
  47. }
  48. // require 'modules/'.$module.'/'.ucfirst($module).'.php';
  49. // call_user_func(array($module, "start"), $module, $params);
  50. }
  51. }
  52. }
  53. /**
  54. *
  55. * @return le module donné avec ses paramètres actuellement présent en conf
  56. */
  57. public static function getModule($module)
  58. {
  59. if ($config = simplexml_load_file('../' . self::CONFIG_FILE)) {
  60. $config_xml = $config->item;
  61. foreach ($config_xml as $item) {
  62. if ($item["id"] == $module) {
  63. $params = array();
  64. foreach ($item as $confParam) {
  65. $params[$confParam->getName()] = "$confParam";
  66. }
  67. //require '../modules/'.$module.'/'.ucfirst($module).'.php';
  68. return new $module($params);
  69. }
  70. }
  71. echo "object not found";
  72. return;
  73. } else {
  74. echo "bad persistance";
  75. return;
  76. }
  77. }
  78. /**
  79. *
  80. * Construit et insère le menu de changement de config
  81. */
  82. function buildConfigMenu()
  83. {
  84. echo '<a href="#config" id="config-menu"><img src="images/interface/config.png" /></a>
  85. <div style="display:none;">
  86. <div id="config">
  87. <form id="config_form" action="" method="post">
  88. <h3>Modules configuration</h3><br/>';
  89. foreach ($this->modules as $module => $moduleConf) {
  90. echo $module . ' module : <input type="radio" name="' . $module . '_group" value="true"';
  91. if ($moduleConf->visibility == "true") echo " checked";
  92. echo '/>activé&nbsp;&nbsp;<input type="radio" name="' . $module . '_group" value="false"';
  93. if ($moduleConf->visibility == "false") echo " checked";
  94. echo '/>desactivé<br/><br/>';
  95. }
  96. echo '<span id="config-submit" class="green-button">Enregistrer</span>
  97. </form><br/><br/>
  98. <h3>Ajout d\'un module</h3>
  99. <form action="includes/addModule.php" method="POST" enctype="multipart/form-data">
  100. <input type="file" name="newModuleFile" id="newModuleFile"/>
  101. <input type="submit" value="Envoyer"/>
  102. </form>
  103. </div>
  104. </div>';
  105. echo '<script>$(document).ready(function(){
  106. $(\'#config-submit\').live(\'click\',function(e){
  107. $(this).replaceWith(\'<img src="images/interface/ajax_load.gif" style="margin:30px auto;display:block" />\');
  108. var data3 = {';
  109. $temp = '';
  110. foreach ($this->modules as $module => $moduleConf) {
  111. $temp .= '\'' . $module . '\' : $(\'input[type=radio][name=' . $module . '_group]:checked\').attr(\'value\'),';
  112. }
  113. echo substr($temp, 0, -1);
  114. echo '};
  115. $.post(\'ajax/post-config.php\',data3,function(msg3){
  116. location.reload();
  117. });
  118. e.preventDefault();
  119. });
  120. });
  121. </script>';
  122. }
  123. public static function retrieveModuleParams($module)
  124. {
  125. $temp = new $module;
  126. return $temp->getParamsList();
  127. }
  128. /**
  129. *
  130. * Fonction d'ajout de module dans le fichier de config
  131. */
  132. public static function addModule($file, $name)
  133. {
  134. if ($config = simplexml_load_file('../' . self::CONFIG_FILE)) {
  135. foreach ($config->item as $item) {
  136. if ($item['id'] == $name)
  137. exit ('module déjà présent !');
  138. }
  139. }
  140. if (class_exists('ZipArchive')) {
  141. $zip = new ZipArchive;
  142. $res = $zip->open($file);
  143. if ($res === TRUE) {
  144. $zip->extractTo('../modules/');
  145. $zip->close();
  146. if (!file_exists('../modules/' . $name . '/' . ucfirst($name) . '.php'))
  147. exit ('L\'extraction n\'a pas fonctionné...');
  148. else {
  149. unlink($file);
  150. require '../modules/' . $name . '/' . ucfirst($name) . '.php';
  151. if ($config = simplexml_load_file('../' . self::CONFIG_FILE)) {
  152. $newItem = $config->addChild('item');
  153. $newItem->addAttribute('id', $name);
  154. //$params = call_user_func(array($name, 'getParamList'));
  155. $params = self::retrieveModuleParams($name);
  156. foreach ($params as $param) {
  157. if ($param == 'visibility')
  158. $newItem->AddChild($param, 'true');
  159. else
  160. $newItem->AddChild($param, '0');
  161. }
  162. $config->asXML('../' . self::CONFIG_FILE);
  163. echo 'Module enregistré. Vous pouvez revenir à la page d\'accueil';
  164. } else {
  165. exit ('L\'enregistrement dans le menu a échoué...');
  166. }
  167. }
  168. } else {
  169. exit ('failed, code:' . $res);
  170. }
  171. } else {
  172. exit ('Votre serveur ne peut installer les modules automatiquement. Merci de passer par votre client FTP habituel ou d\'ajouter la classe ZipArchive à votre serveur PHP');
  173. }
  174. }
  175. }