2010-09-27 16:37:14 +02:00
< ? php
2010-10-05 17:30:04 +02:00
function __autoload ( $class )
{
$BASE_DIR = '/homez.9/shikiryu/www/test/trunk3/' ;
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' );
}
}
2010-09-15 16:55:54 +02:00
class AccueilModules {
2010-10-05 17:30:04 +02:00
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-10-05 17:30:04 +02:00
2010-09-15 23:36:14 +02:00
/**
* Constructeur
2010-09-27 16:37:14 +02:00
* Initialise le XML de conf générale
2010-09-15 23:36:14 +02:00
*/
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 ;
}
} else {
2010-09-27 12:48:53 +02:00
echo 'Impossible de trouver le fichier de configuration.' ;
2010-09-15 16:55:54 +02:00
}
}
2010-09-15 23:36:14 +02:00
/**
*
2010-09-27 16:37:14 +02:00
* Initialise les modules activés uniquement
2010-09-15 23:36:14 +02:00
*/
2010-09-15 16:55:54 +02:00
function getModules (){
foreach ( $this -> modules as $module => $moduleConf ){
2010-09-27 12:48:53 +02:00
if ( file_exists ( 'modules/' . $module . '/' . ucfirst ( $module ) . '.php' ) && $moduleConf -> visibility == " true " ){
2010-09-15 16:55:54 +02:00
$params = array ();
foreach ( $moduleConf as $confParam ){
$params [ $confParam -> getName ()] = " $confParam " ;
}
2010-10-05 17:30:04 +02:00
$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 );
}
2010-09-15 16:55:54 +02:00
}
2010-10-05 17:30:04 +02:00
echo " object not found " ;
return ;
} else {
echo " bad persistance " ;
return ;
2010-09-15 16:55:54 +02:00
}
2010-10-05 17:30:04 +02:00
2010-09-15 16:55:54 +02:00
}
2010-09-15 23:36:14 +02:00
/**
*
2010-09-27 16:37:14 +02:00
* Construit et insère le menu de changement de config
2010-09-15 23:36:14 +02:00
*/
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 " ;
2010-09-27 16:37:14 +02:00
echo '/>activé <input type="radio" name="' . $module . '_group" value="false"' ;
2010-09-15 16:55:54 +02:00
if ( $moduleConf -> visibility == " false " ) echo " checked " ;
2010-09-27 16:37:14 +02:00
echo '/>desactivé<br/><br/>' ;
2010-09-15 16:55:54 +02:00
}
2010-09-17 15:38:57 +02:00
echo ' < span id = " config-submit " class = " green-button " > Enregistrer </ span >
2010-09-27 16:37:14 +02:00
</ 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 " />
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 = { ' ;
2010-09-22 16:02:40 +02:00
$temp = '' ;
2010-09-17 15:38:57 +02:00
foreach ( $this -> modules as $module => $moduleConf ){
2010-09-22 16:02:40 +02:00
$temp .= '\'' . $module . '\' : $(\'input[type=radio][name=' . $module . '_group]:checked\').attr(\'value\'),' ;
2010-09-17 15:38:57 +02:00
}
2010-09-22 16:02:40 +02:00
echo substr ( $temp , 0 , - 1 );
2010-09-17 15:38:57 +02:00
echo ' };
$ . post ( \ ' ajax / post - config . php\ ' , data3 , function ( msg3 ){
2010-09-22 16:02:40 +02:00
location . reload ();
2010-09-17 15:38:57 +02:00
});
e . preventDefault ();
});
});
</ script > ' ;
2010-09-15 16:55:54 +02:00
}
2010-09-15 23:36:14 +02:00
/**
*
2010-09-27 16:37:14 +02:00
* @ 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
2010-09-15 23:36:14 +02:00
* @ return " ok " String si c 'est bon, ou le message d' erreur
*/
2010-10-05 17:30:04 +02:00
/* public static function updateModule ( $module , $things2change ){
//require 'Module.php';
//require '../modules/'.$module.'/'.ucfirst($module).'.php';
$module = new $module ();
2010-09-15 23:36:14 +02:00
return call_user_func ( array ( $module , " updateConfig " ), $things2change );
2010-10-05 17:30:04 +02:00
} */
2010-09-27 16:37:14 +02:00
/**
*
* 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' ));
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' );
}
}
2010-09-15 16:55:54 +02:00
}