env(); $data = $env->data(); $sgbd = $data->sgbd(); $host = isset($params["host"]) ? $params["host"] : ""; $base = isset($params["base"]) ? $params["base"] : ""; $user = isset($params["user"]) ? $params["user"] : ""; $password = isset($params["password"]) ? $params["password"] : ""; if(!$host || !$base) return "paramètres manquant pour la base XML"; $host .= substr($host, -1) == "/" ? "" : "/"; if(!is_dir($host)){ $parent_dir = dirname($host); if(is_dir($parent_dir)) @mkdir($host); if(!is_dir($host)) return "impossible de créer le répertoire des données XML"; } $base_dir = $host.$base; if(!is_dir($base_dir)) @mkdir($base_dir); if(!is_dir($base_dir)) return "impossible de créer le dossier de la base XML"; $base .= substr($base, -1) == "/" ? "" : "/"; if( !$sgbd->connect( $host, $base, $user, $password ) || !$sgbd->select_db($base) ){ return "impossible de se connecter à la base XML"; } if(!($version = $env->version("mtweb"))){ return "impossible de lire la version de mtweb"; } $ERROR = false; $EXISTS = false; if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("actions_roles"); $ERROR = !isset($EXISTS); if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("config"); $ERROR = !isset($EXISTS); if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("roles"); $ERROR = !isset($EXISTS); if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("users"); $ERROR = !isset($EXISTS); if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("users_roles"); $ERROR = !isset($EXISTS); if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("versions"); $ERROR = !isset($EXISTS); if($ERROR){ return "impossible de savoir si les tables existent deja"; } if($EXISTS){ return "des tables a installer existent deja en base. installation annulee"; } if(!$ERROR) if(!$sgbd->create_data("actions_roles")) $ERROR = true; if(!$ERROR) if(!$sgbd->create_data("config")) $ERROR = true; if(!$ERROR) if(!$sgbd->create_data("roles")) $ERROR = true; if(!$ERROR) if(!$sgbd->create_data("users")) $ERROR = true; if(!$ERROR) if(!$sgbd->create_data("users_roles")) $ERROR = true; if(!$ERROR) if(!$sgbd->create_data("versions")) $ERROR = true; if($ERROR){ return "imposible de creer les tables en base"; } // ------------------------------------ actions_roles if(!$ERROR) if( !$sgbd->add_data( "actions_roles", array( "action" => "admin", "id_role" => 1 ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "actions_roles", array( "action" => "users", "id_role" => 2 ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "actions_roles", array( "action" => "users/identification", "id_role" => 0 ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "actions_roles", array( "action" => "config", "id_role" => 3 ) ) ) $ERROR = true; // ------------------------------------ config if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "site_name", "value" => "mtweb" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "max_list", "value" => "10" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "description", "value" => "" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "out", "value" => "default" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "start_action", "value" => "" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "contact_form", "value" => "0" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "email", "value" => "" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "captcha", "value" => "0" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "start_action_params", "value" => "" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "out_navig_menu_top", "value" => "on" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "out_colonne", "value" => "on" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "config", array( "key" => "default_allow", "value" => "1" ) ) ) $ERROR = true; // ------------------------------------ roles if(!$ERROR){ $res = $sgbd->add_data( "roles", array( "nom" => "guest", "intitule" => "invité" ), 0 ); if(!isset($res)) $ERROR = true; } if(!$ERROR) if( !$sgbd->add_data( "roles", array( "nom" => "admin", "intitule" => "administrateur" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "roles", array( "nom" => "membre", "intitule" => "membre" ) ) ) $ERROR = true; if(!$ERROR) if( !$sgbd->add_data( "roles", array( "nom" => "webmaster", "intitule" => "webmaster" ) ) ) $ERROR = true; // ------------------------------------ versions if(!$ERROR){ $res = $sgbd->add_data( "versions", array( "application" => "mtweb", "version" => $version ), 0 ); if(!isset($res)) $ERROR = true; } if($ERROR){ return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut."; } return true; } } ?>