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.

94 lines
3.0 KiB

<?php
require 'Module.php';
class AccueilModules {
const CONFIG_FILE = 'db/config.xml';
private $modules = array();
/**
* Constructeur
* Initialise le XML de conf g�n�rale
* Active les modules
* Construit le menu
*/
function __construct(){
if($config = simplexml_load_file(self::CONFIG_FILE)){
$config_xml = $config->item;
foreach($config_xml as $item){
$this->modules["$item[id]"] = $item;
}
$this->getModules();
$this->buildConfigMenu();
}else{
echo 'Impossible de trouver le fichier de configuration.';
}
}
/**
*
* Initialise les modules activ�s uniquement
*/
function getModules(){
foreach($this->modules as $module=>$moduleConf){
if(file_exists('modules/'.$module.'/'.ucfirst($module).'.php') && $moduleConf->visibility == "true"){
$params = array();
foreach($moduleConf as $confParam){
$params[$confParam->getName()] = "$confParam";
}
require 'modules/'.$module.'/'.ucfirst($module).'.php';
call_user_func(array($module, "start"), $params);
}
}
}
/**
*
* Construit et ins�re le menu de changement de config
*/
function buildConfigMenu(){
echo '<a href="#config" id="config-menu"><img src="images/interface/config.png" /></a>
<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&nbsp;&nbsp;<input type="radio" name="'.$module.'_group" value="false"';
if ($moduleConf->visibility == "false") echo " checked";
echo '/>false<br/><br/>';
}
echo '<span id="config-submit" class="green-button">Enregistrer</span>
</form>
</div>
</div>';
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 = {';
$temp = '';
foreach($this->modules as $module=>$moduleConf){
$temp .= '\''.$module.'\' : $(\'input[type=radio][name='.$module.'_group]:checked\').attr(\'value\'),';
}
echo substr($temp, 0, -1);
echo '};
$.post(\'ajax/post-config.php\',data3,function(msg3){
location.reload();
});
e.preventDefault();
});
});
</script>';
}
/**
*
* @property Chaque module poss�de la fonction updateModule en static qui permet de changer un ou plusieurs de ses attributs
* @param $module String Nom du module � modifier
* @param $things2change Array du ou des attributs � 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 '../modules/'.$module.'/'.ucfirst($module).'.php';
return call_user_func(array($module, "updateConfig"), $things2change);
}
}