176 lines
5.6 KiB
PHP
176 lines
5.6 KiB
PHP
<?php
|
|
function __autoload($class)
|
|
{
|
|
$BASE_DIR = $_SERVER['DOCUMENT_ROOT'].'/test/trunk3/'; // à modifier selon la configuration souhaitée
|
|
set_include_path($BASE_DIR);
|
|
$path = 'modules/'.$class;
|
|
if(file_exists($path . DIRECTORY_SEPARATOR . ucfirst($class) . '.php') || file_exists($BASE_DIR . $path . DIRECTORY_SEPARATOR . ucfirst($class) . '.php')){
|
|
require_once($path . DIRECTORY_SEPARATOR . ucfirst($class) . '.php');
|
|
}else{
|
|
require_once('class/' . $class . '.php');
|
|
}
|
|
}
|
|
class AccueilModules {
|
|
|
|
const CONFIG_FILE = 'db/config.xml';
|
|
private $modules = array();
|
|
|
|
/**
|
|
* Constructeur
|
|
* Initialise le XML de conf générale
|
|
*/
|
|
function __construct(){
|
|
if($config = simplexml_load_file(self::CONFIG_FILE)){
|
|
$config_xml = $config->item;
|
|
foreach($config_xml as $item){
|
|
$this->modules["$item[id]"] = $item;
|
|
}
|
|
}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";
|
|
}
|
|
$module = new $module($params);
|
|
if(is_subclass_of($module,'Module'))
|
|
$module->build();
|
|
// require 'modules/'.$module.'/'.ucfirst($module).'.php';
|
|
// call_user_func(array($module, "start"), $module, $params);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return le module donné avec ses paramètres actuellement présent en conf
|
|
*/
|
|
public static function getModule($module){
|
|
if($config = simplexml_load_file('../'.self::CONFIG_FILE)){
|
|
$config_xml = $config->item;
|
|
foreach($config_xml as $item){
|
|
if($item["id"] == $module){
|
|
$params = array();
|
|
foreach($item as $confParam){
|
|
$params[$confParam->getName()] = "$confParam";
|
|
}
|
|
//require '../modules/'.$module.'/'.ucfirst($module).'.php';
|
|
return new $module($params);
|
|
}
|
|
}
|
|
echo "object not found";
|
|
return;
|
|
}else{
|
|
echo "bad persistance";
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* 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 '/>activé <input type="radio" name="'.$module.'_group" value="false"';
|
|
if ($moduleConf->visibility == "false") echo " checked";
|
|
echo '/>desactivé<br/><br/>';
|
|
}
|
|
echo '<span id="config-submit" class="green-button">Enregistrer</span>
|
|
</form><br/><br/>
|
|
<h3>Ajout d\'un module</h3>
|
|
<form action="includes/addModule.php" method="POST" enctype="multipart/form-data">
|
|
<input type="file" name="newModuleFile" id="newModuleFile"/>
|
|
<input type="submit" value="Envoyer"/>
|
|
</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>';
|
|
}
|
|
|
|
public static function retrieveModuleParams($module){
|
|
$temp = new $module;
|
|
return $temp->getParamsList();
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Fonction d'ajout de module dans le fichier de config
|
|
*/
|
|
public static function addModule($file, $name)
|
|
{
|
|
if($config = simplexml_load_file('../'.self::CONFIG_FILE)){
|
|
foreach($config->item as $item){
|
|
if($item['id'] == $name)
|
|
exit ('module déjà présent !');
|
|
}
|
|
}
|
|
if(class_exists('ZipArchive')){
|
|
$zip = new ZipArchive;
|
|
$res = $zip->open($file);
|
|
if ($res === TRUE) {
|
|
$zip->extractTo('../modules/');
|
|
$zip->close();
|
|
if(!file_exists('../modules/'.$name.'/'.ucfirst($name).'.php'))
|
|
exit ('L\'extraction n\'a pas fonctionné...');
|
|
else{
|
|
unlink ($file);
|
|
require '../modules/'.$name.'/'.ucfirst($name).'.php';
|
|
if($config = simplexml_load_file('../'.self::CONFIG_FILE)){
|
|
$newItem = $config->addChild('item');
|
|
$newItem->addAttribute('id', $name);
|
|
//$params = call_user_func(array($name, 'getParamList'));
|
|
$params = self::retrieveModuleParams($name);
|
|
foreach($params as $param){
|
|
if($param == 'visibility')
|
|
$newItem->AddChild($param, 'true');
|
|
else
|
|
$newItem->AddChild($param, '0');
|
|
}
|
|
$config->asXML('../'.self::CONFIG_FILE);
|
|
echo 'Module enregistré. Vous pouvez revenir à la page d\'accueil';
|
|
}else{
|
|
exit ('L\'enregistrement dans le menu a échoué...');
|
|
}
|
|
}
|
|
} else {
|
|
exit ('failed, code:' . $res);
|
|
}
|
|
}else{
|
|
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');
|
|
}
|
|
}
|
|
} |