Accueil/class/AccueilModules.php

94 lines
3.0 KiB
PHP
Raw Normal View History

<?php
2010-09-20 11:40:27 +02:00
require 'Module.php';
class AccueilModules {
2010-09-15 23:36:14 +02:00
const CONFIG_FILE = 'db/config.xml';
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
*/
function __construct(){
2010-09-15 23:36:14 +02:00
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...';
}
}
2010-09-15 23:36:14 +02:00
/**
*
* Initialise les modules activ<EFBFBD>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);
}
}
}
2010-09-15 23:36:14 +02:00
/**
*
* Construit et ins<EFBFBD>re le menu de changement de config
*/
function buildConfigMenu(){
2010-09-17 15:38:57 +02:00
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/>';
}
2010-09-17 15:38:57 +02:00
echo '<span id="config-submit" class="green-button">Enregistrer</span>
</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 = {';
$temp = '';
2010-09-17 15:38:57 +02:00
foreach($this->modules as $module=>$moduleConf){
$temp .= '\''.$module.'\' : $(\'input[type=radio][name='.$module.'_group]:checked\').attr(\'value\'),';
2010-09-17 15:38:57 +02:00
}
echo substr($temp, 0, -1);
2010-09-17 15:38:57 +02:00
echo '};
$.post(\'ajax/post-config.php\',data3,function(msg3){
location.reload();
2010-09-17 15:38:57 +02:00
});
e.preventDefault();
});
});
</script>';
}
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);
}
}