2010-09-15 16:55:54 +02:00
|
|
|
|
<?php
|
2010-09-20 11:40:27 +02:00
|
|
|
|
require 'Module.php';
|
2010-09-15 16:55:54 +02:00
|
|
|
|
class AccueilModules {
|
2010-09-15 23:36:14 +02:00
|
|
|
|
const CONFIG_FILE = 'db/config.xml';
|
2010-09-15 16:55:54 +02:00
|
|
|
|
private $modules = array();
|
|
|
|
|
|
2010-09-15 23:36:14 +02:00
|
|
|
|
/**
|
|
|
|
|
* Constructeur
|
|
|
|
|
* Initialise le XML de conf g<EFBFBD>n<EFBFBD>rale
|
|
|
|
|
* Active les modules
|
|
|
|
|
* Construit le menu
|
|
|
|
|
*/
|
2010-09-15 16:55:54 +02:00
|
|
|
|
function __construct(){
|
2010-09-15 23:36:14 +02:00
|
|
|
|
if($config = simplexml_load_file(self::CONFIG_FILE)){
|
2010-09-15 16:55:54 +02:00
|
|
|
|
$config_xml = $config->item;
|
|
|
|
|
foreach($config_xml as $item){
|
|
|
|
|
$this->modules["$item[id]"] = $item;
|
|
|
|
|
}
|
|
|
|
|
$this->getModules();
|
|
|
|
|
$this->buildConfigMenu();
|
|
|
|
|
}else{
|
|
|
|
|
echo 'baaaaad persistance...';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-15 23:36:14 +02:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* Initialise les modules activ<EFBFBD>s uniquement
|
|
|
|
|
*/
|
2010-09-15 16:55:54 +02:00
|
|
|
|
function getModules(){
|
|
|
|
|
foreach($this->modules as $module=>$moduleConf){
|
|
|
|
|
if(file_exists('class/'.ucfirst($module).'.php') && $moduleConf->visibility == "true"){
|
|
|
|
|
$params = array();
|
|
|
|
|
foreach($moduleConf as $confParam){
|
|
|
|
|
$params[$confParam->getName()] = "$confParam";
|
|
|
|
|
}
|
|
|
|
|
require ucfirst($module).'.php';
|
|
|
|
|
call_user_func(array($module, "start"), $params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-15 23:36:14 +02:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* Construit et ins<EFBFBD>re le menu de changement de config
|
|
|
|
|
*/
|
2010-09-15 16:55:54 +02:00
|
|
|
|
function buildConfigMenu(){
|
2010-09-17 15:38:57 +02:00
|
|
|
|
echo '<a href="#config" id="config-menu"><img src="images/interface/config.png" /></a>
|
2010-09-15 16:55:54 +02:00
|
|
|
|
<div style="display:none;">
|
|
|
|
|
<div id="config">
|
|
|
|
|
<form id="config_form" action="" method="post">
|
|
|
|
|
<h3>Modules configuration</h3><br/>';
|
|
|
|
|
foreach($this->modules as $module=>$moduleConf){
|
|
|
|
|
echo $module.' module : <input type="radio" name="'.$module.'_group" value="true"';
|
|
|
|
|
if ($moduleConf->visibility == "true") echo " checked";
|
|
|
|
|
echo '/>true <input type="radio" name="'.$module.'_group" value="false"';
|
|
|
|
|
if ($moduleConf->visibility == "false") echo " checked";
|
|
|
|
|
echo '/>false<br/><br/>';
|
|
|
|
|
}
|
2010-09-17 15:38:57 +02:00
|
|
|
|
echo '<span id="config-submit" class="green-button">Enregistrer</span>
|
2010-09-15 16:55:54 +02:00
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>';
|
2010-09-17 15:38:57 +02:00
|
|
|
|
echo '<script>$(document).ready(function(){
|
|
|
|
|
$(\'#config-submit\').live(\'click\',function(e){
|
|
|
|
|
$(this).replaceWith(\'<img src="images/interface/ajax_load.gif" style="margin:30px auto;display:block" />\');
|
|
|
|
|
var data3 = {';
|
|
|
|
|
foreach($this->modules as $module=>$moduleConf){
|
|
|
|
|
echo '\''.$module.'\' : $(\'input[type=radio][name='.$module.'_group]:checked\').attr(\'value\'),';
|
|
|
|
|
}
|
|
|
|
|
echo '};
|
|
|
|
|
$.post(\'ajax/post-config.php\',data3,function(msg3){
|
|
|
|
|
if(msg3=="1"){
|
|
|
|
|
location.reload();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
</script>';
|
2010-09-15 16:55:54 +02:00
|
|
|
|
}
|
2010-09-15 23:36:14 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @property Chaque module poss<EFBFBD>de la fonction updateModule en static qui permet de changer un ou plusieurs de ses attributs
|
|
|
|
|
* @param $module String Nom du module <EFBFBD> modifier
|
|
|
|
|
* @param $things2change Array du ou des attributs <EFBFBD> modifier avec sa ou ses nouvelles valeurs
|
|
|
|
|
* @return "ok" String si c'est bon, ou le message d'erreur
|
|
|
|
|
*/
|
|
|
|
|
public static function updateModule($module, $things2change){
|
|
|
|
|
require ucfirst($module).'.php';
|
|
|
|
|
return call_user_func(array($module, "updateConfig"), $things2change);
|
|
|
|
|
}
|
2010-09-15 16:55:54 +02:00
|
|
|
|
}
|