93 lines
2.9 KiB
PHP
93 lines
2.9 KiB
PHP
<?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 'baaaaad persistance...';
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Initialise les modules activés uniquement
|
|
*/
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* 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 <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 = {';
|
|
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>';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @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 ucfirst($module).'.php';
|
|
return call_user_func(array($module, "updateConfig"), $things2change);
|
|
}
|
|
} |