/trunk/papyrus/applications/admin_administrateur/autoload.inc.php |
---|
1,33 → 1,28 |
<?php |
/** |
* Fichier autoload contenant la fonction de chargement automatique des classes |
* et l'appel au fichier de configuration de base. |
* Ce fichier doit être inclut en premier dans toute application |
*/ |
if(!defined('CHEMIN_APPLI')) { |
define('CHEMIN_APPLI',dirname(__FILE__).DIRECTORY_SEPARATOR) ; |
} |
require_once('configuration/config.inc.php'); |
require_once('configuration/config_chemin.inc.php'); |
/** |
* La fonction __autoload() charge dynamiquement les classes trouvées dans le code. |
* |
* Cette fonction est appelée par php5 quand il trouve une instanciation de classe dans le code. |
* |
*@param string le nom de la classe appelée. |
*@return void le fichier contenant la classe doit être inclu par la fonction. |
*/ |
function __autoload($classe) |
{ |
$dossiers_classes = array(CHEMIN_BIBLIO.DIRECTORY_SEPARATOR,DOSSIER_CONTROLEURS.DIRECTORY_SEPARATOR,DOSSIER_MODELES.DIRECTORY_SEPARATOR) ; |
foreach ($dossiers_classes as $chemin) { |
if (file_exists($fichier_a_tester = $chemin.$classe.'.php')) { |
require_once $fichier_a_tester; |
return null; |
} |
} |
} |
<?php |
if(!defined('CHEMIN_APPLI')) { |
define('CHEMIN_APPLI',dirname(__FILE__).DIRECTORY_SEPARATOR) ; |
} |
require_once('configuration/config.inc.php'); |
require_once('configuration/config_chemin.inc.php'); |
/** |
* La fonction __autoload() charge dynamiquement les classes trouvées dans le code. |
* |
* Cette fonction est appelée par php5 quand il trouve une instanciation de classe dans le code. |
* |
*@param string le nom de la classe appelée. |
*@return void le fichier contenant la classe doit être inclu par la fonction. |
*/ |
function __autoload($classe) |
{ |
$dossiers_classes = array(CHEMIN_BIBLIO.DIRECTORY_SEPARATOR,DOSSIER_CONTROLEURS.DIRECTORY_SEPARATOR,DOSSIER_MODELES.DIRECTORY_SEPARATOR) ; |
foreach ($dossiers_classes as $chemin) { |
if (file_exists($fichier_a_tester = $chemin.$classe.'.php')) { |
require_once $fichier_a_tester; |
return null; |
} |
} |
} |
?> |
/trunk/papyrus/applications/admin_administrateur/configuration/config_chemin.inc.php |
---|
1,10 → 1,10 |
<?php |
// Définition des chemins de fichiers. |
define('CHEMIN_BIBLIO',CHEMIN_APPLI.'bibliotheque'); |
/** Constante stockant le chemin vers le dossier modèles.*/ |
define('DOSSIER_CONTROLEURS', CHEMIN_APPLI.'controleurs'); |
define('DOSSIER_MODELES', CHEMIN_APPLI.'modeles'); |
define('DOSSIER_SQUELETTES', CHEMIN_APPLI.'squelettes'); |
<?php |
// Définition des chemins de fichiers. |
define('CHEMIN_BIBLIO',CHEMIN_APPLI.'bibliotheque'); |
/** Constante stockant le chemin vers le dossier modèles.*/ |
define('DOSSIER_CONTROLEURS', CHEMIN_APPLI.'controleurs'); |
define('DOSSIER_MODELES', CHEMIN_APPLI.'modeles'); |
define('DOSSIER_SQUELETTES', CHEMIN_APPLI.'squelettes'); |
?> |
/trunk/papyrus/applications/admin_administrateur/modeles/ListeAdmin.php |
---|
1,250 → 1,250 |
<?php |
/** |
* Modèle d'accès à la base de données des administrateurs |
* de papyrus |
*/ |
class listeAdmin extends Modele { |
var $config = array() ; |
/** |
* Charge la liste complète des administrateurs |
* return array un tableau contenant des objets d'informations sur les administrateurs |
* @return array un tableau d'objets contenant la liste des administrateurs |
*/ |
function chargerAdmin() { |
$query = 'SELECT * FROM gen_annuaire ORDER BY ga_id_administrateur' ; |
$res = $this->requete($query) ; |
$admin = array() ; |
foreach ($res->fetchAll() as $ligne) |
{ |
if($ligne['ga_id_administrateur'] != 0) { |
$admin[] = $ligne ; |
} |
} |
return $admin ; |
} |
/** |
* Charge les informations liées à un administrateur |
* grâce à son id |
* @param int l'identifiant de l'administrateur. |
* @return object un object contenant les informations de l'administrateur demandé |
*/ |
function loadDetailsAdmin($id) { |
$query = 'SELECT * FROM gen_annuaire where ga_id_administrateur="'.$id.'"' ; |
$res = $this->requete($query) ; |
$admin = array() ; |
foreach ($res->fetchAll() as $ligne) { |
$admin = $ligne ; |
} |
return $admin ; |
} |
/** |
* Modifie les informations liées à un administrateur dans la base de données |
* Si le mot de passe n'est pas renseigné, il n'est pas changé |
* @param int identifiant de l'admiistrateur |
* @param string nom |
* @param string prenom |
* @param string le mail |
* @param string le code de langue |
* @param string le mot de passe (optionnel) |
* @param string la confirmation du mot de passe (optionnel) |
* @return array un tableau contenant les erreurs s'il y en a, vide sinon |
*/ |
function modifDetailsAdmin($id,$nom,$prenom,$mail,$lang,$pass='',$pass_conf='') { |
$res = array() ; |
$nb_admin = 0 ; |
if(!$this->validerMail($mail)) { |
$res['mail'] = 'Adresse mail invalide' ; |
} |
$query_verif_mail = 'SELECT COUNT(*) AS nb_admin FROM gen_annuaire WHERE ga_mail = '.$this->proteger($mail).' AND ga_id_administrateur !='.$id ; |
if($res_nb = $this->requete($query_verif_mail)) { |
$ligne = $res_nb->fetch(); |
$nb_admin = $ligne['nb_admin'] ; |
} else { |
$res['bdd'] = 'Erreur dans la base de données' ; |
return $res ; |
} |
if($nb_admin != 0) { |
$res['mail'] = 'Cet email est déjà utilisé par un autre utilisateur' ; |
} |
$query = 'UPDATE gen_annuaire SET ga_ce_i18n='.$this->proteger($lang).', ga_nom='.$this->proteger($nom).',ga_prenom='. |
$this->proteger($prenom).',ga_mail='.$this->proteger($mail) ; |
// si on a entré quelque chose dans les deux champs de mot de passe |
if($pass != '' || $pass_conf != '') { |
// on vérifie si les deux concordent |
if($pass == $pass_conf) { |
// si oui, on les modifie |
$query .= ',ga_mot_de_passe='.$this->proteger(md5($pass)) ; |
} else { |
// si non, on notifiera l'utilisateur |
$res['pass'] = 'mot de passe invalide' ; |
} |
} |
$query .= ' WHERE ga_id_administrateur='.$id ; |
if(count($res) != 0) { |
return $res ; |
} |
if($req_maj = $this->requete($query)) { |
} else { |
$res['bdd'] = 'Erreur de la requête dans la base de données' ; |
} |
return $res ; |
} |
/** |
* Supprime un administrateur ayant un id donnée |
* @param int l'identifiant de l'administrateur |
* @return array un tableau contenant les erreurs s'il y en a, vide sinon |
*/ |
function suppAdmin($id) { |
$nb_admin = 0 ; |
$res = '' ; |
$query_verif = 'SELECT COUNT(*) AS nb_admin FROM gen_annuaire' ; |
if($res_nb = $this->requete($query_verif)) { |
$ligne = $res_nb->fetch(); |
$nb_admin = $ligne['nb_admin'] ; |
} else { |
$res = 'Erreur dans la base de données' ; |
return $res ; |
} |
if($nb_admin == 2) { |
$res = 'Impossible de supprimer le dernier administrateur' ; |
return $res ; |
} |
$query = 'DELETE FROM gen_annuaire WHERE ga_id_administrateur='.$id ; |
if($res_supp = $this->requete($query)) { |
return $res ; |
} else { |
$res = 'Erreur dans la base de données' ; |
return $res ; |
} |
} |
/** |
* Ajoute un administrateur dans la base de données |
* @param string nom |
* @param string prenom |
* @param string le mail |
* @param string le code de langue |
* @param string le mot de passe |
* @param string la confirmation du mot de passe |
* @return array un tableau contenant les erreurs s'il y en a, vide sinon |
*/ |
function ajoutAdmin($nom,$prenom,$mail,$lang,$pass,$pass_conf) { |
$nouvel_id = 0 ; |
$nb_admin = 0 ; |
$res = array() ; |
if(!$this->validerMail($mail)) { |
$res['mail'] = 'adresse mail invalide' ; |
} |
$query_verif_mail = 'SELECT COUNT(*) AS nb_admin FROM gen_annuaire WHERE ga_mail = '.$this->proteger($mail) ; |
if($res_nb = $this->requete($query_verif_mail)) { |
$ligne = $res_nb->fetch() ; |
$nb_admin = $ligne['nb_admin'] ; |
} else { |
$res['bdd'] = 'Erreur dans la base de données' ; |
return $res ; |
} |
if($nb_admin != 0) { |
$res['mail'] = 'Cet email est déjà utilisé par un autre utilisateur' ; |
} |
if($pass != '' || $pass_conf != '') { |
// on vérifie si les deux concordent |
if($pass == $pass_conf) { |
} else { |
// si non, on notifiera l'utilisateur |
$res['pass'] = 'mot de passe invalide' ; |
} |
} |
$query = 'SELECT MAX(ga_id_administrateur) as nouvel_id FROM gen_annuaire' ; |
if($res_requete_id = $this->requete($query)) { |
$ligne = $res_requete_id->fetch() ; |
$nouvel_id = $ligne['nouvel_id'] + 1 ; |
} else { |
return $res ; |
} |
$query = 'INSERT INTO gen_annuaire VALUES ('.$nouvel_id.','.$this->proteger($lang).','. |
$this->proteger($nom).','.$this->proteger($prenom).','.$this->proteger(md5($pass)).','. |
$this->proteger($mail).')' ; |
if(count($res) != 0) { |
return $res ; |
} |
if($res_ajout = $this->requete($query)) { |
} else { |
$res['bdd'] = 'Erreur de la requête dans la base de données' ; |
} |
return $res ; |
} |
/** |
* Fonction qui prend une chaine en paramètre et renvoie vrai |
* si elle constitue un email syntaxiquement valide, faux sinon. |
* @param string le mail à valider |
* @return bool true si le mail est valide, false sinon |
*/ |
function validerMail($mail) { |
$atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; // caractères autorisés avant l'arobase |
$domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // caractères autorisés après l'arobase (nom de domaine) |
$regex = '/^' . $atom . '+' . // Une ou plusieurs fois les caractères autorisés avant l'arobase |
'(\.' . $atom . '+)*' . // Suivis par zéro point ou plus |
// séparés par des caractères autorisés avant l'arobase |
'@' . // Suivis d'un arobase |
'(' . $domain . '{1,63}\.)+' . // Suivis par 1 à 63 caractères autorisés pour le nom de domaine |
// séparés par des points |
$domain . '{2,63}$/i'; // Suivi de 2 à 63 caractères autorisés pour le nom de domaine |
// test de l'adresse e-mail |
if (preg_match($regex, $mail)) { |
return true ; |
} else { |
return false ; |
} |
} |
} |
<?php |
/** |
* Modèle d'accès à la base de données des administrateurs |
* de papyrus |
*/ |
class listeAdmin extends Modele { |
var $config = array() ; |
/** |
* Charge la liste complète des administrateurs |
* return array un tableau contenant des objets d'informations sur les administrateurs |
* @return array un tableau d'objets contenant la liste des administrateurs |
*/ |
function chargerAdmin() { |
$query = 'SELECT * FROM gen_annuaire ORDER BY ga_id_administrateur' ; |
$res = $this->requete($query) ; |
$admin = array() ; |
foreach ($res->fetchAll() as $ligne) |
{ |
if($ligne['ga_id_administrateur'] != 0) { |
$admin[] = $ligne ; |
} |
} |
return $admin ; |
} |
/** |
* Charge les informations liées à un administrateur |
* grâce à son id |
* @param int l'identifiant de l'administrateur. |
* @return object un object contenant les informations de l'administrateur demandé |
*/ |
function loadDetailsAdmin($id) { |
$query = 'SELECT * FROM gen_annuaire where ga_id_administrateur="'.$id.'"' ; |
$res = $this->requete($query) ; |
$admin = array() ; |
foreach ($res->fetchAll() as $ligne) { |
$admin = $ligne ; |
} |
return $admin ; |
} |
/** |
* Modifie les informations liées à un administrateur dans la base de données |
* Si le mot de passe n'est pas renseigné, il n'est pas changé |
* @param int identifiant de l'admiistrateur |
* @param string nom |
* @param string prenom |
* @param string le mail |
* @param string le code de langue |
* @param string le mot de passe (optionnel) |
* @param string la confirmation du mot de passe (optionnel) |
* @return array un tableau contenant les erreurs s'il y en a, vide sinon |
*/ |
function modifDetailsAdmin($id,$nom,$prenom,$mail,$lang,$pass='',$pass_conf='') { |
$res = array() ; |
$nb_admin = 0 ; |
if(!$this->validerMail($mail)) { |
$res['mail'] = 'Adresse mail invalide' ; |
} |
$query_verif_mail = 'SELECT COUNT(*) AS nb_admin FROM gen_annuaire WHERE ga_mail = '.$this->proteger($mail).' AND ga_id_administrateur !='.$id ; |
if($res_nb = $this->requete($query_verif_mail)) { |
$ligne = $res_nb->fetch(); |
$nb_admin = $ligne['nb_admin'] ; |
} else { |
$res['bdd'] = 'Erreur dans la base de données' ; |
return $res ; |
} |
if($nb_admin != 0) { |
$res['mail'] = 'Cet email est déjà utilisé par un autre utilisateur' ; |
} |
$query = 'UPDATE gen_annuaire SET ga_ce_i18n='.$this->proteger($lang).', ga_nom='.$this->proteger($nom).',ga_prenom='. |
$this->proteger($prenom).',ga_mail='.$this->proteger($mail) ; |
// si on a entré quelque chose dans les deux champs de mot de passe |
if($pass != '' || $pass_conf != '') { |
// on vérifie si les deux concordent |
if($pass == $pass_conf) { |
// si oui, on les modifie |
$query .= ',ga_mot_de_passe='.$this->proteger(md5($pass)) ; |
} else { |
// si non, on notifiera l'utilisateur |
$res['pass'] = 'mot de passe invalide' ; |
} |
} |
$query .= ' WHERE ga_id_administrateur='.$id ; |
if(count($res) != 0) { |
return $res ; |
} |
if($req_maj = $this->requete($query)) { |
} else { |
$res['bdd'] = 'Erreur de la requête dans la base de données' ; |
} |
return $res ; |
} |
/** |
* Supprime un administrateur ayant un id donnée |
* @param int l'identifiant de l'administrateur |
* @return array un tableau contenant les erreurs s'il y en a, vide sinon |
*/ |
function suppAdmin($id) { |
$nb_admin = 0 ; |
$res = '' ; |
$query_verif = 'SELECT COUNT(*) AS nb_admin FROM gen_annuaire' ; |
if($res_nb = $this->requete($query_verif)) { |
$ligne = $res_nb->fetch(); |
$nb_admin = $ligne['nb_admin'] ; |
} else { |
$res = 'Erreur dans la base de données' ; |
return $res ; |
} |
if($nb_admin == 2) { |
$res = 'Impossible de supprimer le dernier administrateur' ; |
return $res ; |
} |
$query = 'DELETE FROM gen_annuaire WHERE ga_id_administrateur='.$id ; |
if($res_supp = $this->requete($query)) { |
return $res ; |
} else { |
$res = 'Erreur dans la base de données' ; |
return $res ; |
} |
} |
/** |
* Ajoute un administrateur dans la base de données |
* @param string nom |
* @param string prenom |
* @param string le mail |
* @param string le code de langue |
* @param string le mot de passe |
* @param string la confirmation du mot de passe |
* @return array un tableau contenant les erreurs s'il y en a, vide sinon |
*/ |
function ajoutAdmin($nom,$prenom,$mail,$lang,$pass,$pass_conf) { |
$nouvel_id = 0 ; |
$nb_admin = 0 ; |
$res = array() ; |
if(!$this->validerMail($mail)) { |
$res['mail'] = 'adresse mail invalide' ; |
} |
$query_verif_mail = 'SELECT COUNT(*) AS nb_admin FROM gen_annuaire WHERE ga_mail = '.$this->proteger($mail) ; |
if($res_nb = $this->requete($query_verif_mail)) { |
$ligne = $res_nb->fetch() ; |
$nb_admin = $ligne['nb_admin'] ; |
} else { |
$res['bdd'] = 'Erreur dans la base de données' ; |
return $res ; |
} |
if($nb_admin != 0) { |
$res['mail'] = 'Cet email est déjà utilisé par un autre utilisateur' ; |
} |
if($pass != '' || $pass_conf != '') { |
// on vérifie si les deux concordent |
if($pass == $pass_conf) { |
} else { |
// si non, on notifiera l'utilisateur |
$res['pass'] = 'mot de passe invalide' ; |
} |
} |
$query = 'SELECT MAX(ga_id_administrateur) as nouvel_id FROM gen_annuaire' ; |
if($res_requete_id = $this->requete($query)) { |
$ligne = $res_requete_id->fetch() ; |
$nouvel_id = $ligne['nouvel_id'] + 1 ; |
} else { |
return $res ; |
} |
$query = 'INSERT INTO gen_annuaire VALUES ('.$nouvel_id.','.$this->proteger($lang).','. |
$this->proteger($nom).','.$this->proteger($prenom).','.$this->proteger(md5($pass)).','. |
$this->proteger($mail).')' ; |
if(count($res) != 0) { |
return $res ; |
} |
if($res_ajout = $this->requete($query)) { |
} else { |
$res['bdd'] = 'Erreur de la requête dans la base de données' ; |
} |
return $res ; |
} |
/** |
* Fonction qui prend une chaine en paramètre et renvoie vrai |
* si elle constitue un email syntaxiquement valide, faux sinon. |
* @param string le mail à valider |
* @return bool true si le mail est valide, false sinon |
*/ |
function validerMail($mail) { |
$atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; // caractères autorisés avant l'arobase |
$domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // caractères autorisés après l'arobase (nom de domaine) |
$regex = '/^' . $atom . '+' . // Une ou plusieurs fois les caractères autorisés avant l'arobase |
'(\.' . $atom . '+)*' . // Suivis par zéro point ou plus |
// séparés par des caractères autorisés avant l'arobase |
'@' . // Suivis d'un arobase |
'(' . $domain . '{1,63}\.)+' . // Suivis par 1 à 63 caractères autorisés pour le nom de domaine |
// séparés par des points |
$domain . '{2,63}$/i'; // Suivi de 2 à 63 caractères autorisés pour le nom de domaine |
// test de l'adresse e-mail |
if (preg_match($regex, $mail)) { |
return true ; |
} else { |
return false ; |
} |
} |
} |
?> |
/trunk/papyrus/applications/admin_administrateur/admin_administrateur.php |
---|
1,94 → 1,94 |
<?php |
// On inclut l'autoload avant toute chose |
require_once('autoload.inc.php'); |
/** |
* Fonction d'affichage de Papyrus, pour le corps de page |
*/ |
function afficherContenuCorps() { |
// si l'utilisateur est authentifié |
if(VAR_IDENT) { |
// on renvoie la vue principale de l'application |
$methode = '' ; |
if(isset($_GET['m'])) { |
$methode = $_GET['m'] ; |
} |
$controlleur = new AdminAdministrateur(); |
switch($methode) { |
case 'ajout_admin': |
return $controlleur->ajoutAdmin(); |
break; |
case 'ajout_admin_va': |
$nom = $_POST['admin_nom'] ; |
$prenom = $_POST['admin_prenom'] ; |
$mail = $_POST['admin_mail'] ; |
$lang = $_POST['admin_lang'] ; |
$pass = $_POST['admin_pass'] ; |
$pass_conf = $_POST['admin_pass_confirm'] ; |
return $controlleur->ajoutAdminVa($nom,$prenom,$mail,$lang,$pass,$pass_conf); |
break; |
case 'modif_admin': |
$id = $_GET['id_admin']; |
return $controlleur->modifAdmin($id); |
break; |
case 'modif_admin_va': |
$id = $_GET['id_admin']; |
$nom = $_POST['admin_nom']; |
$prenom = $_POST['admin_prenom']; |
$mail = $_POST['admin_mail']; |
$lang = $_POST['admin_lang']; |
$pass = $_POST['admin_pass']; |
$pass_conf = $_POST['admin_pass_confirm']; |
return $controlleur->modifAdminVa($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf); |
break; |
case 'suppr_admin': |
$id = $_GET['id_admin']; |
return $controlleur->supprAdmin($id); |
break; |
default: |
return $controlleur->chargerAdmin(); |
break; |
} |
} else { |
// sinon on lui demande de s'identifier |
$controlleur = new AdminAdministrateur() ; |
return $controlleur->demanderIdent() ; |
} |
} |
function afficherContenuTete() { |
$controlleur = new AdminAdministrateur(); |
return $controlleur->adminTete(); |
} |
function afficherContenuPied() { |
$controlleur = new AdminAdministrateur(); |
return $controlleur->adminPied(); |
} |
if(!defined('PAP_VERSION')) { |
echo afficherContenuTete(); |
echo afficherContenuCorps(); |
echo afficherContenuPied(); |
} |
/* |
* afficherContenuTete() |
* afficherContenuNavigation() |
* afficherContenuMenu() |
* afficherContenuPied() |
* |
*/ |
<?php |
require_once('autoload.inc.php'); |
/** |
* Fonction d'affichage de Papyrus, pour le corps de page |
*/ |
function afficherContenuCorps() { |
// si l'utilisateur est authentifié |
if(VAR_IDENT) { |
// on renvoie la vue principale de l'application |
$methode = '' ; |
if(isset($_GET['m'])) { |
$methode = $_GET['m'] ; |
} |
$controlleur = new AdminAdministrateur(); |
switch($methode) { |
case 'ajout_admin': |
return $controlleur->ajoutAdmin(); |
break; |
case 'ajout_admin_va': |
$nom = $_POST['admin_nom'] ; |
$prenom = $_POST['admin_prenom'] ; |
$mail = $_POST['admin_mail'] ; |
$lang = $_POST['admin_lang'] ; |
$pass = $_POST['admin_pass'] ; |
$pass_conf = $_POST['admin_pass_confirm'] ; |
return $controlleur->ajoutAdminVa($nom,$prenom,$mail,$lang,$pass,$pass_conf); |
break; |
case 'modif_admin': |
$id = $_GET['id_admin']; |
return $controlleur->modifAdmin($id); |
break; |
case 'modif_admin_va': |
$id = $_GET['id_admin']; |
$nom = $_POST['admin_nom']; |
$prenom = $_POST['admin_prenom']; |
$mail = $_POST['admin_mail']; |
$lang = $_POST['admin_lang']; |
$pass = $_POST['admin_pass']; |
$pass_conf = $_POST['admin_pass_confirm']; |
return $controlleur->modifAdminVa($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf); |
break; |
case 'suppr_admin': |
$id = $_GET['id_admin']; |
return $controlleur->supprAdmin($id); |
break; |
default: |
return $controlleur->chargerAdmin(); |
break; |
} |
} else { |
// sinon on lui demande de s'identifier |
$controlleur = new AdminAdministrateur() ; |
return $controlleur->demanderIdent() ; |
} |
} |
function afficherContenuTete() { |
$controlleur = new AdminAdministrateur(); |
return $controlleur->adminTete(); |
} |
function afficherContenuPied() { |
$controlleur = new AdminAdministrateur(); |
return $controlleur->adminPied(); |
} |
if(!defined('PAP_VERSION')) { |
echo afficherContenuTete(); |
echo afficherContenuCorps(); |
echo afficherContenuPied(); |
} |
/* |
* afficherContenuTete() |
* afficherContenuNavigation() |
* afficherContenuMenu() |
* afficherContenuPied() |
* |
*/ |
?> |
/trunk/papyrus/applications/admin_administrateur/bibliotheque/Controleur.php |
---|
1,97 → 1,97 |
<?php |
/** |
* Classe controlleur, coeur d'une application, c'est normalement la seule classe d'une application |
* qui devrait être appelée de l'extérieur. |
*/ |
abstract class Controleur { |
private $registre; |
private $gestionnaire_erreur; |
/** |
* Constructeur par défaut |
*/ |
final public function __construct() { |
$this->registre = Registre::getInstance() ; |
$this->registre->set('chemin_config',CHEMIN_APPLI.'configuration'.DIRECTORY_SEPARATOR); |
$this->registre->set('base_chemin_modele',DOSSIER_MODELES.DIRECTORY_SEPARATOR); |
$this->registre->set('base_chemin_squelette',DOSSIER_SQUELETTES.DIRECTORY_SEPARATOR); |
$this->registre->set('base_chemin_controleur',DOSSIER_CONTROLEURS.DIRECTORY_SEPARATOR); |
$this->registre->set('bdd_type',BDD_PROTOCOLE) ; |
$this->registre->set('bdd_hote',BDD_SERVEUR) ; |
$this->registre->set('bdd_nom',BDD_NOM_PRINCIPALE) ; |
$this->registre->set('bdd_utilisateur',BDD_UTILISATEUR) ; |
$this->registre->set('bdd_pass',BDD_MOT_DE_PASSE) ; |
$this->gestionnaire_erreur = GestionnaireErreur::getInstance(); |
} |
/** |
* Charge un modele donné et le rend disponible sous la forme $this->nom_modele |
* @param $nom_modele le nom du modèle à charger |
*/ |
final protected function chargerModele($nom_modele) { |
$chemin_modele = ($this->registre->get('base_chemin_modele')).$nom_modele.'.php'; |
if(!file_exists($chemin_modele)) { |
return false ; |
} |
include_once($chemin_modele) ; |
if(!class_exists($nom_modele)) { |
return false ; |
} |
$this->$nom_modele = new $nom_modele ; |
} |
/** |
* Fonction prenant en paramètre le nom d'un squelette et un tableau associatif de données, en extrait les variables, charge le squelette |
* et cree une variable de classe contenant les deux combinés. |
* @param String le nom du squelette |
* @param Array un tableau associatif contenant les variables a injecter dans la vue |
* |
*/ |
final protected function chargerVue($nom_squelette,$donnees) { |
$chemin_squelette = ($this->registre->get('base_chemin_squelette')).$nom_squelette.'.tpl.html'; |
if(!file_exists($chemin_squelette)) { |
return false ; |
} |
$donnees['base_url'] = $this->registre->get('base_url_application') ; |
// on extrait les variables du tableau de données |
extract($donnees); |
// et on enclenche la bufferisation de sortie |
ob_start(); |
// si les tags courts sont désactivés |
if ((bool) @ini_get('short_open_tag') === FALSE) |
{ |
// on remplace les tags par la syntaxe classique avec echo |
echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($chemin_squelette)))); |
} else { |
// sinon, on se contente d'inclure le squelette |
include($chemin_squelette); |
} |
// on récupère le buffer et on le vide |
$buffer = ob_get_contents(); |
@ob_end_clean(); |
// enfin on renvoie le contenu |
$this->$nom_squelette = $buffer; |
return $nom_squelette; |
} |
} |
<?php |
/** |
* Classe controlleur, coeur d'une application, c'est normalement la seule classe d'une application |
* qui devrait être appelée de l'extérieur. |
*/ |
abstract class Controleur { |
private $registre; |
private $gestionnaire_erreur; |
/** |
* Constructeur par défaut |
*/ |
final public function __construct() { |
$this->registre = Registre::getInstance() ; |
$this->registre->set('chemin_config',CHEMIN_APPLI.'configuration'.DIRECTORY_SEPARATOR); |
$this->registre->set('base_chemin_modele',DOSSIER_MODELES.DIRECTORY_SEPARATOR); |
$this->registre->set('base_chemin_squelette',DOSSIER_SQUELETTES.DIRECTORY_SEPARATOR); |
$this->registre->set('base_chemin_controleur',DOSSIER_CONTROLEURS.DIRECTORY_SEPARATOR); |
$this->registre->set('bdd_type',BDD_PROTOCOLE) ; |
$this->registre->set('bdd_hote',BDD_SERVEUR) ; |
$this->registre->set('bdd_nom',BDD_NOM_PRINCIPALE) ; |
$this->registre->set('bdd_utilisateur',BDD_UTILISATEUR) ; |
$this->registre->set('bdd_pass',BDD_MOT_DE_PASSE) ; |
$this->gestionnaire_erreur = GestionnaireErreur::getInstance(); |
} |
/** |
* Charge un modele donné et le rend disponible sous la forme $this->nom_modele |
* @param $nom_modele le nom du modèle à charger |
*/ |
final protected function chargerModele($nom_modele) { |
$chemin_modele = ($this->registre->get('base_chemin_modele')).$nom_modele.'.php'; |
if(!file_exists($chemin_modele)) { |
return false ; |
} |
include_once($chemin_modele) ; |
if(!class_exists($nom_modele)) { |
return false ; |
} |
$this->$nom_modele = new $nom_modele ; |
} |
/** |
* Fonction prenant en paramètre le nom d'un squelette et un tableau associatif de données, en extrait les variables, charge le squelette |
* et cree une variable de classe contenant les deux combinés. |
* @param String le nom du squelette |
* @param Array un tableau associatif contenant les variables a injecter dans la vue |
* |
*/ |
final protected function chargerVue($nom_squelette,$donnees) { |
$chemin_squelette = ($this->registre->get('base_chemin_squelette')).$nom_squelette.'.tpl.html'; |
if(!file_exists($chemin_squelette)) { |
return false ; |
} |
$donnees['base_url'] = $this->registre->get('base_url_application') ; |
// on extrait les variables du tableau de données |
extract($donnees); |
// et on enclenche la bufferisation de sortie |
ob_start(); |
// si les tags courts sont désactivés |
if ((bool) @ini_get('short_open_tag') === FALSE) |
{ |
// on remplace les tags par la syntaxe classique avec echo |
echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($chemin_squelette)))); |
} else { |
// sinon, on se contente d'inclure le squelette |
include($chemin_squelette); |
} |
// on récupère le buffer et on le vide |
$buffer = ob_get_contents(); |
@ob_end_clean(); |
// enfin on renvoie le contenu |
$this->$nom_squelette = $buffer; |
return $nom_squelette; |
} |
} |
?> |
/trunk/papyrus/applications/admin_administrateur/bibliotheque/GestionnaireErreur.php |
---|
1,369 → 1,369 |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 5.0.4 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This file is part of eFlore-Debogage. | |
// | | |
// | Foobar is free software; you can redistribute it and/or modify | |
// | it under the terms of the GNU General Public License as published by | |
// | the Free Software Foundation; either version 2 of the License, or | |
// | (at your option) any later version. | |
// | | |
// | Foobar is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// | GNU General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU General Public License | |
// | along with Foobar; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: GestionnaireErreur.class.php,v 1.6 2007-07-09 18:54:43 jp_milcent Exp $ |
/** |
* Classe de gestion des erreurs. |
* |
* |
* |
*@package eFlore |
*@subpackage Debogage |
//Auteur original : |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
//Autres auteurs : |
*@author aucun |
*@copyright Tela-Botanica 2000-2005 |
*@version $Revision: 1.6 $ $Date: 2007-07-09 18:54:43 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
// +------------------------------------------------------------------------------------------------------+ |
// | ENTETE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
// +------------------------------------------------------------------------------------------------------+ |
// | CORPS du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
/** |
* Classe GestionnaireErreur |
* |
* Gérer les erreurs PHP et SQL. |
*/ |
class GestionnaireErreur |
{ |
/*** Attributes: ***/ |
/** |
* Permet de savoir si on utilise PHP en ligne de commande dans une console (PHP-CLI) ou en mode module de serveur. |
* @access private |
*/ |
private $mode; |
/** |
* Contient la liste des erreurs. |
* @access private |
*/ |
private $erreurs; |
/** |
* Permet de savoir si on veut faire apparaître ou pas le contexte de l'erreur, |
* c'est à dire le contenu des variables. |
* @access private |
*/ |
private $contexte; |
/** |
* Contient le niveau d'erreur courant. Celui que l'on donne à la fonction |
* error_reporting(). |
* @access private |
*/ |
private $niveau_erreur_courant; |
/** |
* Le gestionnaire d'erreur est un singleton |
*/ |
private static $gestionnaire_erreurs; |
/*** Constructeur: ***/ |
/** |
* Construit le gestionnaire d'erreur. |
* |
* @return void |
* @access public |
*/ |
private function __construct( $contexte = false ) |
{ |
$this->mode = php_sapi_name(); |
$this->erreurs = array(); |
$this->setContexte($contexte); |
$this->niveau_erreur_courant = 2048 ; |
set_error_handler(array(&$this, 'gererErreur')); |
} |
/** |
* Fonction d'accès au singleton |
* @return GestionnaireErreur le gestionnaire d'erreurs courant |
*/ |
public static function getInstance() |
{ |
if (self::$gestionnaire_erreurs instanceof GestionnaireErreur) { |
return self::$gestionnaire_erreurs; |
} |
self::$gestionnaire_erreurs = new GestionnaireErreur ; |
return self::$gestionnaire_erreurs; |
} |
/*** Accesseurs: ***/ |
/** |
* Récupère le tableau des erreurs. |
* |
* @return array |
* @access public |
*/ |
public function getErreur( ) { |
return $this->erreurs; |
} |
/** |
* Ajoute une erreur à la liste. |
* |
* @param array une_erreur |
* @return void |
* @access public |
*/ |
public function setErreur( $une_erreur ) { |
$this->erreurs[] = $une_erreur; |
} |
/** |
* Récupère la valeur du contexte. |
* |
* @return boolean |
* @access public |
*/ |
public function getContexte( ) { |
return $this->contexte; |
} |
/** |
* Définit si oui ou non le contexte sera affiché. |
* |
* @param boolean un_contexte |
* @return void |
* @access public |
*/ |
public function setContexte( $un_contexte ) { |
$this->contexte = $un_contexte; |
} |
/** |
* Récupère le niveau d'erreur courrant. |
* |
* @return int le niveau d'erreur courrant. |
* @access public |
*/ |
public function getNiveauErreurCourant( ) { |
return (int)$this->niveau_erreur_courant; |
} |
/** |
* Définit le niveau d'erreur courrant. |
* |
* @param int un niveau d'erreur. |
* @return void |
* @access public |
*/ |
public function setNiveauErreurCourant( $niveau = 2048 ) { |
$this->niveau_erreur_courant = $niveau; |
} |
/** |
* Définit le niveau d'erreur courrant (synonyme fonction precedente) |
* |
* @param int un niveau d'erreur. |
* @return void |
* @access public |
*/ |
public function setActive ($niveau) { |
$this->niveau_erreur_courant = $niveau; |
} |
/*** Méthodes : ***/ |
/** |
* |
* @param int niveau |
* @param string message |
* @param string fichier |
* @param int ligne |
* @param boolean contexte |
* @return void |
* @access public |
*/ |
public function gererErreur($niveau, $message, $fichier, $ligne, $contexte) |
{ |
$aso_erreur = array(); |
// Nous vérifions si nous affichons ou pas l'erreur en fonction du niveau demandé |
if ( $niveau <= $this->getNiveauErreurCourant() ) { |
$aso_erreur['niveau'] = $niveau; |
switch ($niveau) { |
case E_USER_NOTICE : |
if (is_array($message) || is_object($message)) { |
$aso_erreur['message'] = print_r($message, true); |
} else { |
$aso_erreur['message'] = $message; |
} |
break; |
default: |
$aso_erreur['message'] = $message; |
} |
$aso_erreur['fichier'] = $fichier; |
$aso_erreur['ligne'] = $ligne; |
if ($this->getContexte()) { |
$aso_erreur['contexte'] = $contexte; |
} |
$this->setErreur($aso_erreur); |
} |
// Si nous avons à faire à une erreur et non à un warning ou une notice, nous arrêtons l'exécution du script |
switch ($niveau) { |
case E_ERROR : |
case E_USER_ERROR : |
die($this->retournerErreur()); |
break; |
} |
} |
/** |
* Retourne l'erreur PHP formatée en XHTML. |
* |
* @return string |
* @access public |
*/ |
public function retournerErreur() |
{ |
$retour = ''; |
foreach($this->getErreur() as $aso_erreur) { |
if ('<!-- BEGIN sql -->' == substr($aso_erreur['message'], 0, 18)) { |
$retour .= $aso_erreur['message']; |
continue; |
} |
switch ($this->mode) { |
case 'cli' : |
if ($aso_erreur['niveau'] == E_USER_NOTICE) { |
$retour .= $aso_erreur['message']."\n"; |
$retour .= 'Fichier : '.$aso_erreur['fichier']."\n"; |
$retour .= 'Ligne : '.$aso_erreur['ligne']."\n"; |
} else if ($aso_erreur['niveau'] <= 512) { |
$retour .= 'INFO : Niveau '.$aso_erreur['niveau']."\n"; |
} else { |
$retour .= 'ERREUR : Niveau '.$aso_erreur['niveau']."\n"; |
} |
$retour .= 'Niveau : '.$aso_erreur['niveau']."\n"; |
$retour .= 'Message : '.$aso_erreur['message']."\n"; |
$retour .= 'Fichier : '.$aso_erreur['fichier']."\n"; |
$retour .= 'Ligne : '.$aso_erreur['ligne']."\n"; |
if ($this->getContexte()) { |
$retour .= 'Contexte : '."\n".print_r($aso_erreur['contexte'], true)."\n"; |
} |
break; |
default: |
if ($aso_erreur['niveau'] == E_USER_NOTICE) { |
$retour .= '<pre class="debogage">'."\n"; |
$retour .= htmlentities($aso_erreur['message'])."\n"; |
$retour .= '<span class="debogage_fichier">'.'Fichier : '.$aso_erreur['fichier'].'</span>'."\n"; |
$retour .= '<span class="debogage_ligne">'.'Ligne : '.$aso_erreur['ligne'].'</span>'."\n"; |
$retour .= '</pre>'."\n"; |
continue; |
} else if ($aso_erreur['niveau'] <= 512) { |
$retour .= '<p class="information">'."\n"; |
$retour .= '<strong>INFO : Niveau '.$aso_erreur['niveau'].'</strong><br />'."\n"; |
} else { |
$retour .= '<p class="attention">'."\n"; |
$retour .= '<strong>ERREUR : Niveau '.$aso_erreur['niveau'].'</strong><br />'."\n"; |
} |
$retour .= '<strong>Niveau : </strong>'.$aso_erreur['niveau'].'<br />'."\n"; |
$retour .= '<strong>Message : </strong>'.$aso_erreur['message'].'<br />'."\n"; |
$retour .= '<strong>Fichier : </strong>'.$aso_erreur['fichier'].'<br />'."\n"; |
$retour .= '<strong>Ligne : </strong>'.$aso_erreur['ligne'].'<br />'."\n"; |
if ($this->getContexte()) { |
$retour .= '<pre>'."\n"; |
$retour .= '<stong>Contexte : </stong>'."\n".print_r($aso_erreur['contexte'], true)."\n"; |
$retour .= '</pre>'."\n"; |
} |
$retour .= '</p>'."\n"; |
} |
} |
return $retour; |
} |
/** |
* Retourne l'erreur SQL formatée en XHTML. |
* |
* @param string fichier |
* @param int ligne |
* @param string message |
* @param string requete |
* @param string autres |
* @return string |
* @static |
* @access public |
*/ |
public static function retournerErreurSql( $fichier, $methode, $message, $requete = null, $autres = null ) |
{ |
$retour = ''; |
switch (php_sapi_name()) { |
case 'cli' : |
$retour .= 'ERREUR SQL '."\n"; |
$retour .= 'Fichier : '.$fichier."\n"; |
$retour .= 'Méthode : '.$methode."\n"; |
$retour .= 'Message : '.$message."\n"; |
if (!is_null($requete)) { |
$retour .= 'Requete : '."\n"; |
$retour .= $requete."\n"; |
} |
if (!is_null($autres)) { |
$retour .= 'Autres infos : '."\n"; |
$retour .= $autres."\n"; |
} |
break; |
default: |
$retour .= '<!-- BEGIN sql -->'; |
$retour .= '<div id="zone_erreur">'."\n"; |
$retour .= '<h1 > ERREUR SQL </h1><br />'."\n"; |
$retour .= '<dl>'."\n"; |
$retour .= '<dt> Fichier : </dt> '; |
$retour .= '<dd> '.$fichier.'</dd>'."\n"; |
$retour .= '<dt> Méthode : </dt> '; |
$retour .= '<dd> '.$methode.'</dd>'."\n"; |
$retour .= '<dt> Message erreur : </dt> '; |
$retour .= '<dd> '.$message.'</dd>'."\n"; |
if (!is_null($requete)) { |
$retour .= '<dt> Requete : </dt> '; |
$retour .= '<dd> '.$requete.' </dd>'."\n"; |
} |
if (!is_null($autres)) { |
$retour .= '<dt> Autres infos : </dt> '; |
$retour .= '<dd> '.$autres.' </dd>'."\n"; |
} |
$retour .= '</dl>'."\n"; |
$retour .= '</div>'."\n"; |
$retour .= '<!-- END sql -->'."\n"; |
} |
return $retour; |
} |
} |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 5.0.4 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This file is part of eFlore-Debogage. | |
// | | |
// | Foobar is free software; you can redistribute it and/or modify | |
// | it under the terms of the GNU General Public License as published by | |
// | the Free Software Foundation; either version 2 of the License, or | |
// | (at your option) any later version. | |
// | | |
// | Foobar is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// | GNU General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU General Public License | |
// | along with Foobar; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: GestionnaireErreur.class.php,v 1.6 2007-07-09 18:54:43 jp_milcent Exp $ |
/** |
* Classe de gestion des erreurs. |
* |
* |
* |
*@package eFlore |
*@subpackage Debogage |
//Auteur original : |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
//Autres auteurs : |
*@author aucun |
*@copyright Tela-Botanica 2000-2005 |
*@version $Revision: 1.6 $ $Date: 2007-07-09 18:54:43 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
// +------------------------------------------------------------------------------------------------------+ |
// | ENTETE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
// +------------------------------------------------------------------------------------------------------+ |
// | CORPS du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
/** |
* Classe GestionnaireErreur |
* |
* Gérer les erreurs PHP et SQL. |
*/ |
class GestionnaireErreur |
{ |
/*** Attributes: ***/ |
/** |
* Permet de savoir si on utilise PHP en ligne de commande dans une console (PHP-CLI) ou en mode module de serveur. |
* @access private |
*/ |
private $mode; |
/** |
* Contient la liste des erreurs. |
* @access private |
*/ |
private $erreurs; |
/** |
* Permet de savoir si on veut faire apparaître ou pas le contexte de l'erreur, |
* c'est à dire le contenu des variables. |
* @access private |
*/ |
private $contexte; |
/** |
* Contient le niveau d'erreur courant. Celui que l'on donne à la fonction |
* error_reporting(). |
* @access private |
*/ |
private $niveau_erreur_courant; |
/** |
* Le gestionnaire d'erreur est un singleton |
*/ |
private static $gestionnaire_erreurs; |
/*** Constructeur: ***/ |
/** |
* Construit le gestionnaire d'erreur. |
* |
* @return void |
* @access public |
*/ |
private function __construct( $contexte = false ) |
{ |
$this->mode = php_sapi_name(); |
$this->erreurs = array(); |
$this->setContexte($contexte); |
$this->niveau_erreur_courant = 2048 ; |
set_error_handler(array(&$this, 'gererErreur')); |
} |
/** |
* Fonction d'accès au singleton |
* @return GestionnaireErreur le gestionnaire d'erreurs courant |
*/ |
public static function getInstance() |
{ |
if (self::$gestionnaire_erreurs instanceof GestionnaireErreur) { |
return self::$gestionnaire_erreurs; |
} |
self::$gestionnaire_erreurs = new GestionnaireErreur ; |
return self::$gestionnaire_erreurs; |
} |
/*** Accesseurs: ***/ |
/** |
* Récupère le tableau des erreurs. |
* |
* @return array |
* @access public |
*/ |
public function getErreur( ) { |
return $this->erreurs; |
} |
/** |
* Ajoute une erreur à la liste. |
* |
* @param array une_erreur |
* @return void |
* @access public |
*/ |
public function setErreur( $une_erreur ) { |
$this->erreurs[] = $une_erreur; |
} |
/** |
* Récupère la valeur du contexte. |
* |
* @return boolean |
* @access public |
*/ |
public function getContexte( ) { |
return $this->contexte; |
} |
/** |
* Définit si oui ou non le contexte sera affiché. |
* |
* @param boolean un_contexte |
* @return void |
* @access public |
*/ |
public function setContexte( $un_contexte ) { |
$this->contexte = $un_contexte; |
} |
/** |
* Récupère le niveau d'erreur courrant. |
* |
* @return int le niveau d'erreur courrant. |
* @access public |
*/ |
public function getNiveauErreurCourant( ) { |
return (int)$this->niveau_erreur_courant; |
} |
/** |
* Définit le niveau d'erreur courrant. |
* |
* @param int un niveau d'erreur. |
* @return void |
* @access public |
*/ |
public function setNiveauErreurCourant( $niveau = 2048 ) { |
$this->niveau_erreur_courant = $niveau; |
} |
/** |
* Définit le niveau d'erreur courrant (synonyme fonction precedente) |
* |
* @param int un niveau d'erreur. |
* @return void |
* @access public |
*/ |
public function setActive ($niveau) { |
$this->niveau_erreur_courant = $niveau; |
} |
/*** Méthodes : ***/ |
/** |
* |
* @param int niveau |
* @param string message |
* @param string fichier |
* @param int ligne |
* @param boolean contexte |
* @return void |
* @access public |
*/ |
public function gererErreur($niveau, $message, $fichier, $ligne, $contexte) |
{ |
$aso_erreur = array(); |
// Nous vérifions si nous affichons ou pas l'erreur en fonction du niveau demandé |
if ( $niveau <= $this->getNiveauErreurCourant() ) { |
$aso_erreur['niveau'] = $niveau; |
switch ($niveau) { |
case E_USER_NOTICE : |
if (is_array($message) || is_object($message)) { |
$aso_erreur['message'] = print_r($message, true); |
} else { |
$aso_erreur['message'] = $message; |
} |
break; |
default: |
$aso_erreur['message'] = $message; |
} |
$aso_erreur['fichier'] = $fichier; |
$aso_erreur['ligne'] = $ligne; |
if ($this->getContexte()) { |
$aso_erreur['contexte'] = $contexte; |
} |
$this->setErreur($aso_erreur); |
} |
// Si nous avons à faire à une erreur et non à un warning ou une notice, nous arrêtons l'exécution du script |
switch ($niveau) { |
case E_ERROR : |
case E_USER_ERROR : |
die($this->retournerErreur()); |
break; |
} |
} |
/** |
* Retourne l'erreur PHP formatée en XHTML. |
* |
* @return string |
* @access public |
*/ |
public function retournerErreur() |
{ |
$retour = ''; |
foreach($this->getErreur() as $aso_erreur) { |
if ('<!-- BEGIN sql -->' == substr($aso_erreur['message'], 0, 18)) { |
$retour .= $aso_erreur['message']; |
continue; |
} |
switch ($this->mode) { |
case 'cli' : |
if ($aso_erreur['niveau'] == E_USER_NOTICE) { |
$retour .= $aso_erreur['message']."\n"; |
$retour .= 'Fichier : '.$aso_erreur['fichier']."\n"; |
$retour .= 'Ligne : '.$aso_erreur['ligne']."\n"; |
} else if ($aso_erreur['niveau'] <= 512) { |
$retour .= 'INFO : Niveau '.$aso_erreur['niveau']."\n"; |
} else { |
$retour .= 'ERREUR : Niveau '.$aso_erreur['niveau']."\n"; |
} |
$retour .= 'Niveau : '.$aso_erreur['niveau']."\n"; |
$retour .= 'Message : '.$aso_erreur['message']."\n"; |
$retour .= 'Fichier : '.$aso_erreur['fichier']."\n"; |
$retour .= 'Ligne : '.$aso_erreur['ligne']."\n"; |
if ($this->getContexte()) { |
$retour .= 'Contexte : '."\n".print_r($aso_erreur['contexte'], true)."\n"; |
} |
break; |
default: |
if ($aso_erreur['niveau'] == E_USER_NOTICE) { |
$retour .= '<pre class="debogage">'."\n"; |
$retour .= htmlentities($aso_erreur['message'])."\n"; |
$retour .= '<span class="debogage_fichier">'.'Fichier : '.$aso_erreur['fichier'].'</span>'."\n"; |
$retour .= '<span class="debogage_ligne">'.'Ligne : '.$aso_erreur['ligne'].'</span>'."\n"; |
$retour .= '</pre>'."\n"; |
continue; |
} else if ($aso_erreur['niveau'] <= 512) { |
$retour .= '<p class="information">'."\n"; |
$retour .= '<strong>INFO : Niveau '.$aso_erreur['niveau'].'</strong><br />'."\n"; |
} else { |
$retour .= '<p class="attention">'."\n"; |
$retour .= '<strong>ERREUR : Niveau '.$aso_erreur['niveau'].'</strong><br />'."\n"; |
} |
$retour .= '<strong>Niveau : </strong>'.$aso_erreur['niveau'].'<br />'."\n"; |
$retour .= '<strong>Message : </strong>'.$aso_erreur['message'].'<br />'."\n"; |
$retour .= '<strong>Fichier : </strong>'.$aso_erreur['fichier'].'<br />'."\n"; |
$retour .= '<strong>Ligne : </strong>'.$aso_erreur['ligne'].'<br />'."\n"; |
if ($this->getContexte()) { |
$retour .= '<pre>'."\n"; |
$retour .= '<stong>Contexte : </stong>'."\n".print_r($aso_erreur['contexte'], true)."\n"; |
$retour .= '</pre>'."\n"; |
} |
$retour .= '</p>'."\n"; |
} |
} |
return $retour; |
} |
/** |
* Retourne l'erreur SQL formatée en XHTML. |
* |
* @param string fichier |
* @param int ligne |
* @param string message |
* @param string requete |
* @param string autres |
* @return string |
* @static |
* @access public |
*/ |
public static function retournerErreurSql( $fichier, $methode, $message, $requete = null, $autres = null ) |
{ |
$retour = ''; |
switch (php_sapi_name()) { |
case 'cli' : |
$retour .= 'ERREUR SQL '."\n"; |
$retour .= 'Fichier : '.$fichier."\n"; |
$retour .= 'Méthode : '.$methode."\n"; |
$retour .= 'Message : '.$message."\n"; |
if (!is_null($requete)) { |
$retour .= 'Requete : '."\n"; |
$retour .= $requete."\n"; |
} |
if (!is_null($autres)) { |
$retour .= 'Autres infos : '."\n"; |
$retour .= $autres."\n"; |
} |
break; |
default: |
$retour .= '<!-- BEGIN sql -->'; |
$retour .= '<div id="zone_erreur">'."\n"; |
$retour .= '<h1 > ERREUR SQL </h1><br />'."\n"; |
$retour .= '<dl>'."\n"; |
$retour .= '<dt> Fichier : </dt> '; |
$retour .= '<dd> '.$fichier.'</dd>'."\n"; |
$retour .= '<dt> Méthode : </dt> '; |
$retour .= '<dd> '.$methode.'</dd>'."\n"; |
$retour .= '<dt> Message erreur : </dt> '; |
$retour .= '<dd> '.$message.'</dd>'."\n"; |
if (!is_null($requete)) { |
$retour .= '<dt> Requete : </dt> '; |
$retour .= '<dd> '.$requete.' </dd>'."\n"; |
} |
if (!is_null($autres)) { |
$retour .= '<dt> Autres infos : </dt> '; |
$retour .= '<dd> '.$autres.' </dd>'."\n"; |
} |
$retour .= '</dl>'."\n"; |
$retour .= '</div>'."\n"; |
$retour .= '<!-- END sql -->'."\n"; |
} |
return $retour; |
} |
} |
?> |
/trunk/papyrus/applications/admin_administrateur/bibliotheque/Registre.php |
---|
1,56 → 1,56 |
<?php |
class Registre { |
private $aso_stock = array(); |
private static $registre; |
public function __construct() |
{ |
} |
public static function getInstance() |
{ |
if (self::$registre instanceof Registre) { |
return self::$registre; |
} |
self::$registre = new Registre; |
return self::$registre; |
} |
function set($intitule, $objet) |
{ |
if (is_array($objet) && isset($this->aso_stock[$intitule])) { |
$this->aso_stock[$intitule] = array_merge((array)$this->aso_stock[$intitule], (array)$objet); |
$message = "Le tableau $intitule présent dans le registre a été fusionné avec un nouveau tableau de même intitulé !"; |
trigger_error($message, E_USER_WARNING); |
} else { |
$this->aso_stock[$intitule] = $objet; |
} |
} |
function get($intitule) |
{ |
if (isset($this->aso_stock[$intitule])) { |
return $this->aso_stock[$intitule]; |
} |
return null; |
} |
function detruire($intitule) |
{ |
if (isset($this->aso_stock[$intitule])) { |
unset($this->aso_stock[$intitule]); |
} |
} |
public function etrePresent($intitule) |
{ |
if(isset($this->aso_stock[$intitule])){ |
return true; |
} |
return false; |
} |
} |
<?php |
class Registre { |
private $aso_stock = array(); |
private static $registre; |
public function __construct() |
{ |
} |
public static function getInstance() |
{ |
if (self::$registre instanceof Registre) { |
return self::$registre; |
} |
self::$registre = new Registre; |
return self::$registre; |
} |
function set($intitule, $objet) |
{ |
if (is_array($objet) && isset($this->aso_stock[$intitule])) { |
$this->aso_stock[$intitule] = array_merge((array)$this->aso_stock[$intitule], (array)$objet); |
$message = "Le tableau $intitule présent dans le registre a été fusionné avec un nouveau tableau de même intitulé !"; |
trigger_error($message, E_USER_WARNING); |
} else { |
$this->aso_stock[$intitule] = $objet; |
} |
} |
function get($intitule) |
{ |
if (isset($this->aso_stock[$intitule])) { |
return $this->aso_stock[$intitule]; |
} |
return null; |
} |
function detruire($intitule) |
{ |
if (isset($this->aso_stock[$intitule])) { |
unset($this->aso_stock[$intitule]); |
} |
} |
public function etrePresent($intitule) |
{ |
if(isset($this->aso_stock[$intitule])){ |
return true; |
} |
return false; |
} |
} |
?> |
/trunk/papyrus/applications/admin_administrateur/bibliotheque/Chronometre.php |
---|
1,185 → 1,185 |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 5.0.4 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This file is part of eFlore-Debogage. | |
// | | |
// | Foobar is free software; you can redistribute it and/or modify | |
// | it under the terms of the GNU General Public License as published by | |
// | the Free Software Foundation; either version 2 of the License, or | |
// | (at your option) any later version. | |
// | | |
// | Foobar is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// | GNU General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU General Public License | |
// | along with Foobar; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: Chronometre.class.php,v 1.1 2007-01-12 13:16:09 jp_milcent Exp $ |
/** |
* Classe permettant de mesurer le temps d'execution d'un script. |
* |
* Contient des méthodes permettant d'évaluer la vitesse d'exécution d'un script. |
* |
*@package eFlore |
*@subpackage Debogage |
//Auteur original : |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
//Autres auteurs : |
*@author aucun |
*@copyright Tela-Botanica 2000-2005 |
*@version $Revision: 1.1 $ $Date: 2007-01-12 13:16:09 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
// +------------------------------------------------------------------------------------------------------+ |
// | ENTETE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
// +------------------------------------------------------------------------------------------------------+ |
// | CORPS du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
/**Classe Chronometre() - Permet de stocker et d'afficher les temps d'éxécution de script. |
* |
* Cette classe permet de réaliser un ensemble de mesure de temps prises à |
* différents endroits d'un script. Ces mesures peuvent ensuite être affichées au |
* sein d'un tableau XHTML. |
* |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
*/ |
class Chronometre |
{ |
/*** Attributs : ***/ |
private $temps = array(); |
/*** Constructeur : ***/ |
public function __construct() { |
$this->setTemps(array('depart' => microtime())); |
} |
/*** Accesseurs : ***/ |
public function getTemps($cle = NULL) { |
if (!is_null($cle)) { |
return $this->temps[$cle]; |
} else { |
return $this->temps; |
} |
} |
public function setTemps($moment = array()) { |
array_push($this->temps, $moment); |
} |
/*** Méthodes : ***/ |
/**Méthode afficherChrono() - Permet d'afficher les temps d'éxécution de différentes parties d'un script. |
* |
* Cette fonction permet d'afficher un ensemble de mesure de temps prises à différents endroits d'un script. |
* Ces mesures sont affichées au sein d'un tableau XHTML dont on peut controler l'indentation des balises. |
* Pour un site en production, il suffit d'ajouter un style #chrono {display:none;} dans la css. De cette façon, |
* le tableau ne s'affichera pas. Le webmaster lui pourra rajouter sa propre feuille de style affichant le tableau. |
* Le développeur initial de cette fonction est Loic d'Anterroches. Elle a été modifiée par Jean-Pascal Milcent. |
* Elle utilise une variable gobale : $_CHRONO_ |
* |
* @author Loic d'Anterroches |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @param int l'indentation de base pour le code html du tableau. |
* @param int le pas d'indentation pour le code html du tableau. |
* @return string la chaine XHTML de mesure des temps. |
*/ |
function afficherChrono($indentation_origine = 8, $indentation = 4) { |
// Création du chrono de fin |
$GLOBALS['_SCRIPT_']['chrono']->setTemps(array('fin' => microtime())); |
// Début création de l'affichage |
$sortie = str_repeat(' ', $indentation_origine). |
'<table id="chrono" lang="fr" summary="Résultat du chronométrage du programme affichant la page actuelle.">'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'<caption>Chronométrage</caption>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'<thead>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))). |
'<tr><th>Action</th><th>Temps écoulé (en s.)</th><th>Cumul du temps écoulé (en s.)</th></tr>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'</thead>'."\n"; |
$tbody = str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'<tbody>'."\n"; |
$total_tps_ecoule = 0; |
// Récupération de la première mesure |
$tab_depart =& $this->getTemps(0); |
list($usec, $sec) = explode(' ', $tab_depart['depart']); |
// Ce temps correspond à tps_fin |
$tps_debut = ((float)$usec + (float)$sec); |
foreach ($this->getTemps() as $tab_temps) { |
foreach ($tab_temps as $cle => $valeur) { |
list($usec, $sec) = explode(' ', $valeur); |
$tps_fin = ((float)$usec + (float)$sec); |
$tps_ecoule = abs($tps_fin - $tps_debut); |
$total_tps_ecoule += $tps_ecoule; |
$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 2))). |
'<tr>'. |
'<th>'.$cle.'</th>'. |
'<td>'.number_format($tps_ecoule, 3, ',', ' ').'</td>'. |
'<td>'.number_format($total_tps_ecoule, 3, ',', ' ').'</td>'. |
'</tr>'."\n"; |
$tps_debut = $tps_fin; |
} |
} |
$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'</tbody>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'<tfoot>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))). |
'<tr>'. |
'<th>'.'Total du temps écoulé (en s.)'.'</th>'. |
'<td colspan="2">'.number_format($total_tps_ecoule,3, ',', ' ').'</td>'. |
'</tr>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'</tfoot>'."\n"; |
$sortie .= $tbody; |
$sortie .= str_repeat(' ', $indentation_origine). |
'</table>'."\n"; |
return $sortie; |
} |
} |
/* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log: Chronometre.class.php,v $ |
* Revision 1.1 2007-01-12 13:16:09 jp_milcent |
* Déplacement des classes de débogage et d'optimisation dans le dossier noyau. |
* |
* Revision 1.1 2005/08/04 15:51:45 jp_milcent |
* Implémentation de la gestion via DAO. |
* Fin page d'accueil. |
* Fin formulaire recherche taxonomique. |
* |
* Revision 1.2 2005/08/03 15:52:31 jp_milcent |
* Fin gestion des résultats recherche nomenclaturale. |
* Début gestion formulaire taxonomique. |
* |
* Revision 1.1 2005/08/02 16:19:33 jp_milcent |
* Amélioration des requetes de recherche de noms. |
* |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 5.0.4 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This file is part of eFlore-Debogage. | |
// | | |
// | Foobar is free software; you can redistribute it and/or modify | |
// | it under the terms of the GNU General Public License as published by | |
// | the Free Software Foundation; either version 2 of the License, or | |
// | (at your option) any later version. | |
// | | |
// | Foobar is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// | GNU General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU General Public License | |
// | along with Foobar; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: Chronometre.class.php,v 1.1 2007-01-12 13:16:09 jp_milcent Exp $ |
/** |
* Classe permettant de mesurer le temps d'execution d'un script. |
* |
* Contient des méthodes permettant d'évaluer la vitesse d'exécution d'un script. |
* |
*@package eFlore |
*@subpackage Debogage |
//Auteur original : |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
//Autres auteurs : |
*@author aucun |
*@copyright Tela-Botanica 2000-2005 |
*@version $Revision: 1.1 $ $Date: 2007-01-12 13:16:09 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
// +------------------------------------------------------------------------------------------------------+ |
// | ENTETE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
// +------------------------------------------------------------------------------------------------------+ |
// | CORPS du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
/**Classe Chronometre() - Permet de stocker et d'afficher les temps d'éxécution de script. |
* |
* Cette classe permet de réaliser un ensemble de mesure de temps prises à |
* différents endroits d'un script. Ces mesures peuvent ensuite être affichées au |
* sein d'un tableau XHTML. |
* |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
*/ |
class Chronometre |
{ |
/*** Attributs : ***/ |
private $temps = array(); |
/*** Constructeur : ***/ |
public function __construct() { |
$this->setTemps(array('depart' => microtime())); |
} |
/*** Accesseurs : ***/ |
public function getTemps($cle = NULL) { |
if (!is_null($cle)) { |
return $this->temps[$cle]; |
} else { |
return $this->temps; |
} |
} |
public function setTemps($moment = array()) { |
array_push($this->temps, $moment); |
} |
/*** Méthodes : ***/ |
/**Méthode afficherChrono() - Permet d'afficher les temps d'éxécution de différentes parties d'un script. |
* |
* Cette fonction permet d'afficher un ensemble de mesure de temps prises à différents endroits d'un script. |
* Ces mesures sont affichées au sein d'un tableau XHTML dont on peut controler l'indentation des balises. |
* Pour un site en production, il suffit d'ajouter un style #chrono {display:none;} dans la css. De cette façon, |
* le tableau ne s'affichera pas. Le webmaster lui pourra rajouter sa propre feuille de style affichant le tableau. |
* Le développeur initial de cette fonction est Loic d'Anterroches. Elle a été modifiée par Jean-Pascal Milcent. |
* Elle utilise une variable gobale : $_CHRONO_ |
* |
* @author Loic d'Anterroches |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @param int l'indentation de base pour le code html du tableau. |
* @param int le pas d'indentation pour le code html du tableau. |
* @return string la chaine XHTML de mesure des temps. |
*/ |
function afficherChrono($indentation_origine = 8, $indentation = 4) { |
// Création du chrono de fin |
$GLOBALS['_SCRIPT_']['chrono']->setTemps(array('fin' => microtime())); |
// Début création de l'affichage |
$sortie = str_repeat(' ', $indentation_origine). |
'<table id="chrono" lang="fr" summary="Résultat du chronométrage du programme affichant la page actuelle.">'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'<caption>Chronométrage</caption>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'<thead>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))). |
'<tr><th>Action</th><th>Temps écoulé (en s.)</th><th>Cumul du temps écoulé (en s.)</th></tr>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'</thead>'."\n"; |
$tbody = str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'<tbody>'."\n"; |
$total_tps_ecoule = 0; |
// Récupération de la première mesure |
$tab_depart =& $this->getTemps(0); |
list($usec, $sec) = explode(' ', $tab_depart['depart']); |
// Ce temps correspond à tps_fin |
$tps_debut = ((float)$usec + (float)$sec); |
foreach ($this->getTemps() as $tab_temps) { |
foreach ($tab_temps as $cle => $valeur) { |
list($usec, $sec) = explode(' ', $valeur); |
$tps_fin = ((float)$usec + (float)$sec); |
$tps_ecoule = abs($tps_fin - $tps_debut); |
$total_tps_ecoule += $tps_ecoule; |
$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 2))). |
'<tr>'. |
'<th>'.$cle.'</th>'. |
'<td>'.number_format($tps_ecoule, 3, ',', ' ').'</td>'. |
'<td>'.number_format($total_tps_ecoule, 3, ',', ' ').'</td>'. |
'</tr>'."\n"; |
$tps_debut = $tps_fin; |
} |
} |
$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'</tbody>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'<tfoot>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))). |
'<tr>'. |
'<th>'.'Total du temps écoulé (en s.)'.'</th>'. |
'<td colspan="2">'.number_format($total_tps_ecoule,3, ',', ' ').'</td>'. |
'</tr>'."\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))). |
'</tfoot>'."\n"; |
$sortie .= $tbody; |
$sortie .= str_repeat(' ', $indentation_origine). |
'</table>'."\n"; |
return $sortie; |
} |
} |
/* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log: Chronometre.class.php,v $ |
* Revision 1.1 2007-01-12 13:16:09 jp_milcent |
* Déplacement des classes de débogage et d'optimisation dans le dossier noyau. |
* |
* Revision 1.1 2005/08/04 15:51:45 jp_milcent |
* Implémentation de la gestion via DAO. |
* Fin page d'accueil. |
* Fin formulaire recherche taxonomique. |
* |
* Revision 1.2 2005/08/03 15:52:31 jp_milcent |
* Fin gestion des résultats recherche nomenclaturale. |
* Début gestion formulaire taxonomique. |
* |
* Revision 1.1 2005/08/02 16:19:33 jp_milcent |
* Amélioration des requetes de recherche de noms. |
* |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |
?> |
/trunk/papyrus/applications/admin_administrateur/bibliotheque/Modele.php |
---|
1,78 → 1,81 |
<?php |
abstract class Modele { |
private $registre; |
private $gestionnaire_erreur; |
private $dsn; |
private $type; |
private $hote; |
private $bdd_nom; |
private $utilisateur; |
private $pass ; |
private $connexion = null; |
/** |
* Constructeur par défaut, appelé à l'initialisation |
*/ |
final public function __construct() { |
$this->registre = Registre::getInstance() ; |
$this->gestionnaire_erreur = GestionnaireErreur::getInstance() ; |
$this->type = $this->registre->get('bdd_type'); |
$this->hote = $this->registre->get('bdd_hote'); |
$this->bdd_nom = $this->registre->get('bdd_nom'); |
$this->utilisateur = $this->registre->get('bdd_utilisateur'); |
$this->pass = $this->registre->get('bdd_pass'); |
$this->dsn = $this->type.':dbname='.$this->bdd_nom.';host='.$this->hote; |
} |
/** |
* Fonction qui appelle la bonne fonction de requete suivant le type de bdd. |
* |
* @param string la requete à effectuer |
* @return PDOStatement un objet contenant le résultat de la requête |
*/ |
final protected function requete($requete) { |
// on ne se connecte que lors du premier appel à une requete |
if($this->connexion == null) { |
$this->connecter(); |
} |
return $this->connexion->query($requete); |
} |
/** |
* Connection à la base de données en utilisant les informations fournies par |
* le fichier de configuration. |
* private et final car n'a pas vocation a être appelée par l'utilisateur. |
* |
* @throws PDOException une exception dans le cas ou là connexion échoue |
*/ |
final private function connecter() { |
try { |
$this->connexion = new PDO($this->dsn,$this->utilisateur,$this->pass); |
} catch (PDOException $e) { |
} |
} |
final protected function proteger($chaine) { |
// Connection lors du premier appel à une requete |
if($this->connexion == null) { |
$this->connecter(); |
} |
return $this->connexion->quote($chaine); |
} |
/** |
* Destructeur de classe, se contente de fermer explicitement la connexion |
*/ |
final public function __destruct() { |
if($this->connexion != null) { |
$this->connexion = null ; |
} |
} |
} |
<?php |
abstract class Modele { |
private $registre; |
private $gestionnaire_erreur; |
private $dsn; |
private $type; |
private $hote; |
private $bdd_nom; |
private $utilisateur; |
private $pass ; |
private $connexion = null; |
/** |
* Constructeur par défaut, appelé à l'initialisation |
*/ |
final public function __construct() { |
$this->registre = Registre::getInstance() ; |
$this->gestionnaire_erreur = GestionnaireErreur::getInstance() ; |
$this->type = $this->registre->get('bdd_type'); |
$this->hote = $this->registre->get('bdd_hote'); |
$this->bdd_nom = $this->registre->get('bdd_nom'); |
$this->utilisateur = $this->registre->get('bdd_utilisateur'); |
$this->pass = $this->registre->get('bdd_pass'); |
$this->dsn = $this->type.':dbname='.$this->bdd_nom.';host='.$this->hote; |
} |
/** |
* Fonction qui appelle la bonne fonction de requete suivant le type de bdd |
* @param string la requete à effectuer |
* @return PDOStatement un objet contenant le résultat de la requête |
*/ |
final protected function requete($requete) { |
// on ne se connecte que lors du premier appel à une requete |
if($this->connexion == null) { |
$this->connecter(); |
} |
return $this->connexion->query($requete); |
} |
/** |
* Connecte à la base de données en utilisant les informations fournies par |
* le fichier de configuration, private et final car n'a pas vocation a être appelée |
* par l'utilisateur |
* @throws PDOException une exception dans le cas ou là connexion échoue |
*/ |
final private function connecter() { |
try { |
$this->connexion = new PDO($this->dsn,$this->utilisateur,$this->pass); |
} catch (PDOException $e) { |
} |
} |
final protected function proteger($chaine) { |
// on ne se connecte que lors du premier appel à une requete |
if($this->connexion == null) { |
$this->connecter(); |
} |
return $this->connexion->quote($chaine); |
} |
/** |
* Destructeur de classe, se contente de fermer explicitement la connexion |
*/ |
final public function __destruct() { |
if($this->connexion != null) { |
$this->connexion = null ; |
} |
} |
} |
?> |
/trunk/papyrus/applications/admin_administrateur/bibliotheque/Net_URL.php |
---|
1,490 → 1,490 |
<?php |
// +-----------------------------------------------------------------------+ |
// | Copyright (c) 2002-2004, Richard Heyes | |
// | All rights reserved. | |
// | | |
// | Redistribution and use in source and binary forms, with or without | |
// | modification, are permitted provided that the following conditions | |
// | are met: | |
// | | |
// | o Redistributions of source code must retain the above copyright | |
// | notice, this list of conditions and the following disclaimer. | |
// | o Redistributions in binary form must reproduce the above copyright | |
// | notice, this list of conditions and the following disclaimer in the | |
// | documentation and/or other materials provided with the distribution.| |
// | o The names of the authors may not be used to endorse or promote | |
// | products derived from this software without specific prior written | |
// | permission. | |
// | | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
// | | |
// +-----------------------------------------------------------------------+ |
// | Author: Richard Heyes <richard at php net> | |
// +-----------------------------------------------------------------------+ |
// |
// $Id: URL.php,v 1.3 2007-11-19 14:06:54 alexandre_tb Exp $ |
// |
// Net_URL Class |
class Net_URL |
{ |
var $options = array('encode_query_keys' => false); |
/** |
* Full url |
* @var string |
*/ |
var $url; |
/** |
* Protocol |
* @var string |
*/ |
var $protocol; |
/** |
* Username |
* @var string |
*/ |
var $username; |
/** |
* Password |
* @var string |
*/ |
var $password; |
/** |
* Host |
* @var string |
*/ |
var $host; |
/** |
* Port |
* @var integer |
*/ |
var $port; |
/** |
* Path |
* @var string |
*/ |
var $path; |
/** |
* Query string |
* @var array |
*/ |
var $querystring; |
/** |
* Anchor |
* @var string |
*/ |
var $anchor; |
/** |
* Whether to use [] |
* @var bool |
*/ |
var $useBrackets; |
/** |
* PHP4 Constructor |
* |
* @see __construct() |
*/ |
function Net_URL($url = null, $useBrackets = true) |
{ |
$this->__construct($url, $useBrackets); |
} |
/** |
* PHP5 Constructor |
* |
* Parses the given url and stores the various parts |
* Defaults are used in certain cases |
* |
* @param string $url Optional URL |
* @param bool $useBrackets Whether to use square brackets when |
* multiple querystrings with the same name |
* exist |
*/ |
function __construct($url = null, $useBrackets = true) |
{ |
$this->url = $url; |
$this->useBrackets = $useBrackets; |
$this->initialize(); |
} |
function initialize() |
{ |
$HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; |
$this->user = ''; |
$this->pass = ''; |
$this->host = ''; |
$this->port = 80; |
$this->path = ''; |
$this->querystring = array(); |
$this->anchor = ''; |
// Only use defaults if not an absolute URL given |
if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) { |
$this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'); |
/** |
* Figure out host/port |
*/ |
if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) && |
preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) |
{ |
$host = $matches[1]; |
if (!empty($matches[3])) { |
$port = $matches[3]; |
} else { |
$port = $this->getStandardPort($this->protocol); |
} |
} |
$this->user = ''; |
$this->pass = ''; |
$this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost'); |
$this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol)); |
$this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/'; |
$this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null; |
$this->anchor = ''; |
} |
// Parse the url and store the various parts |
if (!empty($this->url)) { |
$urlinfo = parse_url($this->url); |
// Default querystring |
$this->querystring = array(); |
foreach ($urlinfo as $key => $value) { |
switch ($key) { |
case 'scheme': |
$this->protocol = $value; |
$this->port = $this->getStandardPort($value); |
break; |
case 'user': |
case 'pass': |
case 'host': |
case 'port': |
$this->$key = $value; |
break; |
case 'path': |
if ($value{0} == '/') { |
$this->path = $value; |
} else { |
$path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path); |
$this->path = sprintf('%s/%s', $path, $value); |
} |
break; |
case 'query': |
$this->querystring = $this->_parseRawQueryString($value); |
break; |
case 'fragment': |
$this->anchor = $value; |
break; |
} |
} |
} |
} |
/** |
* Returns full url |
* |
* @return string Full url |
* @access public |
*/ |
function getURL() |
{ |
$querystring = $this->getQueryString(); |
$this->url = $this->protocol . '://' |
. $this->user . (!empty($this->pass) ? ':' : '') |
. $this->pass . (!empty($this->user) ? '@' : '') |
. $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port) |
. $this->path |
. (!empty($querystring) ? '?' . $querystring : '') |
. (!empty($this->anchor) ? '#' . $this->anchor : ''); |
return $this->url; |
} |
/** |
* Adds or updates a querystring item (URL parameter). |
* Automatically encodes parameters with rawurlencode() if $preencoded |
* is false. |
* You can pass an array to $value, it gets mapped via [] in the URL if |
* $this->useBrackets is activated. |
* |
* @param string $name Name of item |
* @param string $value Value of item |
* @param bool $preencoded Whether value is urlencoded or not, default = not |
* @access public |
*/ |
function addQueryString($name, $value, $preencoded = false) |
{ |
if ($this->getOption('encode_query_keys')) { |
$name = rawurlencode($name); |
} |
if ($preencoded) { |
$this->querystring[$name] = $value; |
} else { |
$this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value); |
} |
} |
/** |
* Removes a querystring item |
* |
* @param string $name Name of item |
* @access public |
*/ |
function removeQueryString($name) |
{ |
if ($this->getOption('encode_query_keys')) { |
$name = rawurlencode($name); |
} |
if (isset($this->querystring[$name])) { |
unset($this->querystring[$name]); |
} |
} |
/** |
* Sets the querystring to literally what you supply |
* |
* @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc |
* @access public |
*/ |
function addRawQueryString($querystring) |
{ |
$this->querystring = $this->_parseRawQueryString($querystring); |
} |
/** |
* Returns flat querystring |
* |
* @return string Querystring |
* @access public |
*/ |
function getQueryString() |
{ |
if (!empty($this->querystring)) { |
foreach ($this->querystring as $name => $value) { |
// Encode var name |
$name = rawurlencode($name); |
if (is_array($value)) { |
foreach ($value as $k => $v) { |
$querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v); |
} |
} elseif (!is_null($value)) { |
$querystring[] = $name . '=' . $value; |
} else { |
$querystring[] = $name; |
} |
} |
$querystring = implode(ini_get('arg_separator.output'), $querystring); |
} else { |
$querystring = ''; |
} |
return $querystring; |
} |
/** |
* Parses raw querystring and returns an array of it |
* |
* @param string $querystring The querystring to parse |
* @return array An array of the querystring data |
* @access private |
*/ |
function _parseRawQuerystring($querystring) |
{ |
$parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY); |
$return = array(); |
foreach ($parts as $part) { |
if (strpos($part, '=') !== false) { |
$value = substr($part, strpos($part, '=') + 1); |
$key = substr($part, 0, strpos($part, '=')); |
} else { |
$value = null; |
$key = $part; |
} |
if (!$this->getOption('encode_query_keys')) { |
$key = rawurldecode($key); |
} |
if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { |
$key = $matches[1]; |
$idx = $matches[2]; |
// Ensure is an array |
if (empty($return[$key]) || !is_array($return[$key])) { |
$return[$key] = array(); |
} |
// Add data |
if ($idx === '') { |
$return[$key][] = $value; |
} else { |
$return[$key][$idx] = $value; |
} |
} elseif (!$this->useBrackets AND !empty($return[$key])) { |
$return[$key] = (array)$return[$key]; |
$return[$key][] = $value; |
} else { |
$return[$key] = $value; |
} |
} |
return $return; |
} |
/** |
* Resolves //, ../ and ./ from a path and returns |
* the result. Eg: |
* |
* /foo/bar/../boo.php => /foo/boo.php |
* /foo/bar/../../boo.php => /boo.php |
* /foo/bar/.././/boo.php => /foo/boo.php |
* |
* This method can also be called statically. |
* |
* @param string $path URL path to resolve |
* @return string The result |
*/ |
function resolvePath($path) |
{ |
$path = explode('/', str_replace('//', '/', $path)); |
for ($i=0; $i<count($path); $i++) { |
if ($path[$i] == '.') { |
unset($path[$i]); |
$path = array_values($path); |
$i--; |
} elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) { |
unset($path[$i]); |
unset($path[$i-1]); |
$path = array_values($path); |
$i -= 2; |
} elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') { |
unset($path[$i]); |
$path = array_values($path); |
$i--; |
} else { |
continue; |
} |
} |
return implode('/', $path); |
} |
/** |
* Returns the standard port number for a protocol |
* |
* @param string $scheme The protocol to lookup |
* @return integer Port number or NULL if no scheme matches |
* |
* @author Philippe Jausions <Philippe.Jausions@11abacus.com> |
*/ |
function getStandardPort($scheme) |
{ |
switch (strtolower($scheme)) { |
case 'http': return 80; |
case 'https': return 443; |
case 'ftp': return 21; |
case 'imap': return 143; |
case 'imaps': return 993; |
case 'pop3': return 110; |
case 'pop3s': return 995; |
default: return null; |
} |
} |
/** |
* Forces the URL to a particular protocol |
* |
* @param string $protocol Protocol to force the URL to |
* @param integer $port Optional port (standard port is used by default) |
*/ |
function setProtocol($protocol, $port = null) |
{ |
$this->protocol = $protocol; |
$this->port = is_null($port) ? $this->getStandardPort($protocol) : $port; |
} |
/** |
* Set an option |
* |
* This function set an option |
* to be used thorough the script. |
* |
* @access public |
* @param string $optionName The optionname to set |
* @param string $value The value of this option. |
*/ |
function setOption($optionName, $value) |
{ |
if (!array_key_exists($optionName, $this->options)) { |
return false; |
} |
$this->options[$optionName] = $value; |
$this->initialize(); |
} |
/** |
* Get an option |
* |
* This function gets an option |
* from the $this->options array |
* and return it's value. |
* |
* @access public |
* @param string $opionName The name of the option to retrieve |
* @see $this->options |
*/ |
function getOption($optionName) |
{ |
if (!isset($this->options[$optionName])) { |
return false; |
} |
return $this->options[$optionName]; |
} |
function __toString() { |
return $this->url ; |
} |
} |
?> |
<?php |
// +-----------------------------------------------------------------------+ |
// | Copyright (c) 2002-2004, Richard Heyes | |
// | All rights reserved. | |
// | | |
// | Redistribution and use in source and binary forms, with or without | |
// | modification, are permitted provided that the following conditions | |
// | are met: | |
// | | |
// | o Redistributions of source code must retain the above copyright | |
// | notice, this list of conditions and the following disclaimer. | |
// | o Redistributions in binary form must reproduce the above copyright | |
// | notice, this list of conditions and the following disclaimer in the | |
// | documentation and/or other materials provided with the distribution.| |
// | o The names of the authors may not be used to endorse or promote | |
// | products derived from this software without specific prior written | |
// | permission. | |
// | | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
// | | |
// +-----------------------------------------------------------------------+ |
// | Author: Richard Heyes <richard at php net> | |
// +-----------------------------------------------------------------------+ |
// |
// $Id: URL.php,v 1.3 2007-11-19 14:06:54 alexandre_tb Exp $ |
// |
// Net_URL Class |
class Net_URL |
{ |
var $options = array('encode_query_keys' => false); |
/** |
* Full url |
* @var string |
*/ |
var $url; |
/** |
* Protocol |
* @var string |
*/ |
var $protocol; |
/** |
* Username |
* @var string |
*/ |
var $username; |
/** |
* Password |
* @var string |
*/ |
var $password; |
/** |
* Host |
* @var string |
*/ |
var $host; |
/** |
* Port |
* @var integer |
*/ |
var $port; |
/** |
* Path |
* @var string |
*/ |
var $path; |
/** |
* Query string |
* @var array |
*/ |
var $querystring; |
/** |
* Anchor |
* @var string |
*/ |
var $anchor; |
/** |
* Whether to use [] |
* @var bool |
*/ |
var $useBrackets; |
/** |
* PHP4 Constructor |
* |
* @see __construct() |
*/ |
function Net_URL($url = null, $useBrackets = true) |
{ |
$this->__construct($url, $useBrackets); |
} |
/** |
* PHP5 Constructor |
* |
* Parses the given url and stores the various parts |
* Defaults are used in certain cases |
* |
* @param string $url Optional URL |
* @param bool $useBrackets Whether to use square brackets when |
* multiple querystrings with the same name |
* exist |
*/ |
function __construct($url = null, $useBrackets = true) |
{ |
$this->url = $url; |
$this->useBrackets = $useBrackets; |
$this->initialize(); |
} |
function initialize() |
{ |
$HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; |
$this->user = ''; |
$this->pass = ''; |
$this->host = ''; |
$this->port = 80; |
$this->path = ''; |
$this->querystring = array(); |
$this->anchor = ''; |
// Only use defaults if not an absolute URL given |
if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) { |
$this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'); |
/** |
* Figure out host/port |
*/ |
if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) && |
preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) |
{ |
$host = $matches[1]; |
if (!empty($matches[3])) { |
$port = $matches[3]; |
} else { |
$port = $this->getStandardPort($this->protocol); |
} |
} |
$this->user = ''; |
$this->pass = ''; |
$this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost'); |
$this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol)); |
$this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/'; |
$this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null; |
$this->anchor = ''; |
} |
// Parse the url and store the various parts |
if (!empty($this->url)) { |
$urlinfo = parse_url($this->url); |
// Default querystring |
$this->querystring = array(); |
foreach ($urlinfo as $key => $value) { |
switch ($key) { |
case 'scheme': |
$this->protocol = $value; |
$this->port = $this->getStandardPort($value); |
break; |
case 'user': |
case 'pass': |
case 'host': |
case 'port': |
$this->$key = $value; |
break; |
case 'path': |
if ($value{0} == '/') { |
$this->path = $value; |
} else { |
$path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path); |
$this->path = sprintf('%s/%s', $path, $value); |
} |
break; |
case 'query': |
$this->querystring = $this->_parseRawQueryString($value); |
break; |
case 'fragment': |
$this->anchor = $value; |
break; |
} |
} |
} |
} |
/** |
* Returns full url |
* |
* @return string Full url |
* @access public |
*/ |
function getURL() |
{ |
$querystring = $this->getQueryString(); |
$this->url = $this->protocol . '://' |
. $this->user . (!empty($this->pass) ? ':' : '') |
. $this->pass . (!empty($this->user) ? '@' : '') |
. $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port) |
. $this->path |
. (!empty($querystring) ? '?' . $querystring : '') |
. (!empty($this->anchor) ? '#' . $this->anchor : ''); |
return $this->url; |
} |
/** |
* Adds or updates a querystring item (URL parameter). |
* Automatically encodes parameters with rawurlencode() if $preencoded |
* is false. |
* You can pass an array to $value, it gets mapped via [] in the URL if |
* $this->useBrackets is activated. |
* |
* @param string $name Name of item |
* @param string $value Value of item |
* @param bool $preencoded Whether value is urlencoded or not, default = not |
* @access public |
*/ |
function addQueryString($name, $value, $preencoded = false) |
{ |
if ($this->getOption('encode_query_keys')) { |
$name = rawurlencode($name); |
} |
if ($preencoded) { |
$this->querystring[$name] = $value; |
} else { |
$this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value); |
} |
} |
/** |
* Removes a querystring item |
* |
* @param string $name Name of item |
* @access public |
*/ |
function removeQueryString($name) |
{ |
if ($this->getOption('encode_query_keys')) { |
$name = rawurlencode($name); |
} |
if (isset($this->querystring[$name])) { |
unset($this->querystring[$name]); |
} |
} |
/** |
* Sets the querystring to literally what you supply |
* |
* @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc |
* @access public |
*/ |
function addRawQueryString($querystring) |
{ |
$this->querystring = $this->_parseRawQueryString($querystring); |
} |
/** |
* Returns flat querystring |
* |
* @return string Querystring |
* @access public |
*/ |
function getQueryString() |
{ |
if (!empty($this->querystring)) { |
foreach ($this->querystring as $name => $value) { |
// Encode var name |
$name = rawurlencode($name); |
if (is_array($value)) { |
foreach ($value as $k => $v) { |
$querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v); |
} |
} elseif (!is_null($value)) { |
$querystring[] = $name . '=' . $value; |
} else { |
$querystring[] = $name; |
} |
} |
$querystring = implode(ini_get('arg_separator.output'), $querystring); |
} else { |
$querystring = ''; |
} |
return $querystring; |
} |
/** |
* Parses raw querystring and returns an array of it |
* |
* @param string $querystring The querystring to parse |
* @return array An array of the querystring data |
* @access private |
*/ |
function _parseRawQuerystring($querystring) |
{ |
$parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY); |
$return = array(); |
foreach ($parts as $part) { |
if (strpos($part, '=') !== false) { |
$value = substr($part, strpos($part, '=') + 1); |
$key = substr($part, 0, strpos($part, '=')); |
} else { |
$value = null; |
$key = $part; |
} |
if (!$this->getOption('encode_query_keys')) { |
$key = rawurldecode($key); |
} |
if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { |
$key = $matches[1]; |
$idx = $matches[2]; |
// Ensure is an array |
if (empty($return[$key]) || !is_array($return[$key])) { |
$return[$key] = array(); |
} |
// Add data |
if ($idx === '') { |
$return[$key][] = $value; |
} else { |
$return[$key][$idx] = $value; |
} |
} elseif (!$this->useBrackets AND !empty($return[$key])) { |
$return[$key] = (array)$return[$key]; |
$return[$key][] = $value; |
} else { |
$return[$key] = $value; |
} |
} |
return $return; |
} |
/** |
* Resolves //, ../ and ./ from a path and returns |
* the result. Eg: |
* |
* /foo/bar/../boo.php => /foo/boo.php |
* /foo/bar/../../boo.php => /boo.php |
* /foo/bar/.././/boo.php => /foo/boo.php |
* |
* This method can also be called statically. |
* |
* @param string $path URL path to resolve |
* @return string The result |
*/ |
function resolvePath($path) |
{ |
$path = explode('/', str_replace('//', '/', $path)); |
for ($i=0; $i<count($path); $i++) { |
if ($path[$i] == '.') { |
unset($path[$i]); |
$path = array_values($path); |
$i--; |
} elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) { |
unset($path[$i]); |
unset($path[$i-1]); |
$path = array_values($path); |
$i -= 2; |
} elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') { |
unset($path[$i]); |
$path = array_values($path); |
$i--; |
} else { |
continue; |
} |
} |
return implode('/', $path); |
} |
/** |
* Returns the standard port number for a protocol |
* |
* @param string $scheme The protocol to lookup |
* @return integer Port number or NULL if no scheme matches |
* |
* @author Philippe Jausions <Philippe.Jausions@11abacus.com> |
*/ |
function getStandardPort($scheme) |
{ |
switch (strtolower($scheme)) { |
case 'http': return 80; |
case 'https': return 443; |
case 'ftp': return 21; |
case 'imap': return 143; |
case 'imaps': return 993; |
case 'pop3': return 110; |
case 'pop3s': return 995; |
default: return null; |
} |
} |
/** |
* Forces the URL to a particular protocol |
* |
* @param string $protocol Protocol to force the URL to |
* @param integer $port Optional port (standard port is used by default) |
*/ |
function setProtocol($protocol, $port = null) |
{ |
$this->protocol = $protocol; |
$this->port = is_null($port) ? $this->getStandardPort($protocol) : $port; |
} |
/** |
* Set an option |
* |
* This function set an option |
* to be used thorough the script. |
* |
* @access public |
* @param string $optionName The optionname to set |
* @param string $value The value of this option. |
*/ |
function setOption($optionName, $value) |
{ |
if (!array_key_exists($optionName, $this->options)) { |
return false; |
} |
$this->options[$optionName] = $value; |
$this->initialize(); |
} |
/** |
* Get an option |
* |
* This function gets an option |
* from the $this->options array |
* and return it's value. |
* |
* @access public |
* @param string $opionName The name of the option to retrieve |
* @see $this->options |
*/ |
function getOption($optionName) |
{ |
if (!isset($this->options[$optionName])) { |
return false; |
} |
return $this->options[$optionName]; |
} |
function __toString() { |
return $this->url ; |
} |
} |
?> |
/trunk/papyrus/applications/admin_administrateur/index.php |
---|
1,9 → 1,9 |
<?php |
/* |
* Created on 19 mars 2009 |
* |
* To change the template for this generated file go to |
* Window - Preferences - PHPeclipse - PHP - Code Templates |
*/ |
header('Location: admin_administrateur.php'); |
?> |
<?php |
/* |
* Created on 19 mars 2009 |
* |
* To change the template for this generated file go to |
* Window - Preferences - PHPeclipse - PHP - Code Templates |
*/ |
header('Location: admin_administrateur.php'); |
?> |
/trunk/papyrus/applications/admin_administrateur/squelettes/modif_admin.tpl.html |
---|
1,28 → 1,28 |
<h2> Modification d'un administrateur</h2> |
<form id="modif_admin" action="<?=$base_url.'?m=modif_admin_va&id_admin='.$admin['ga_id_administrateur'] ?>" method="post"> |
<fieldset> |
<label for="admin_nom">Nom : </label> |
<input type="text" id="admin_nom" name="admin_nom" maxlength="80" tabindex="1" value="<?=$admin['ga_nom'] ?>" /> |
<label for="admin_prenom">Prénom : </label> |
<input type="text" id="admin_prenom" name="admin_prenom" maxlength="80" tabindex="2" value="<?=$admin['ga_prenom'] ?>" /> |
<label for="admin_mail">Mail : </label> |
<input type="text" id="admin_mail" name="admin_mail" maxlength="120" tabindex="3" value="<?=$admin['ga_mail'] ?>" /> |
<?php if (isset($erreurs['mail'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['mail'] ?> </span> |
<?php endif; ?> |
<label for="admin_lang">Langue : </label> |
<select id="admin_lang" name="admin_lang" tabindex="4"> |
<option <?=($admin['ga_ce_i18n'] == "fr-FR") ? 'selected="selected"' : '';?> value="fr-FR"> Français </option> |
<option <?=($admin['ga_ce_i18n'] == "en-EN") ? 'selected="selected"' : '';?> value="en-EN"> Anglais </option> |
</select> |
<label for="password">Mot de passe : </label> |
<input type="password" id="admin_pass" name="admin_pass" maxlength="80" tabindex="5" value="<?='' ?>" /> |
<label for="password_confirm">Confirmez le mot de passe : </label> |
<input type="password" id="admin_pass_confirm" name="admin_pass_confirm" maxlength="80" tabindex="6" value="<?='' ?>" /> |
<?php if (isset($erreurs['pass'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['pass'] ?> </span> |
<?php endif; ?> |
</fieldset> |
<input type="submit" id="valider_modif_admin" name="valider_modif_admin" tabindex="7" value="Modifier" /> |
<a href="<?=$base_url.'?m=liste_admin' ?>"> annuler </a> |
<h2> Modification d'un administrateur</h2> |
<form id="modif_admin" action="<?=$base_url.'?m=modif_admin_va&id_admin='.$admin['ga_id_administrateur'] ?>" method="post"> |
<fieldset> |
<label for="admin_nom">Nom : </label> |
<input type="text" id="admin_nom" name="admin_nom" maxlength="80" tabindex="1" value="<?=$admin['ga_nom'] ?>" /> <br /> |
<label for="admin_prenom">Prénom : </label> |
<input type="text" id="admin_prenom" name="admin_prenom" maxlength="80" tabindex="2" value="<?=$admin['ga_prenom'] ?>" /> <br /> |
<label for="admin_mail">Mail : </label> |
<input type="text" id="admin_mail" name="admin_mail" maxlength="120" tabindex="3" value="<?=$admin['ga_mail'] ?>" /> |
<?php if (isset($erreurs['mail'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['mail'] ?> </span> |
<?php endif; ?> <br /> |
<label for="admin_lang">Langue : </label> |
<select id="admin_lang" name="admin_lang" tabindex="4"> |
<option <?=($admin['ga_ce_i18n'] == "fr-FR") ? 'selected="selected"' : '';?> value="fr-FR"> Français </option> |
<option <?=($admin['ga_ce_i18n'] == "en-EN") ? 'selected="selected"' : '';?> value="en-EN"> Anglais </option> |
</select> <br /> |
<label for="password">Mot de passe : </label> |
<input type="password" id="admin_pass" name="admin_pass" maxlength="80" tabindex="5" value="<?='' ?>" /> <br /> |
<label for="password_confirm">Confirmez le mot de passe : </label> |
<input type="password" id="admin_pass_confirm" name="admin_pass_confirm" maxlength="80" tabindex="6" value="<?='' ?>" /> <br /> |
<?php if (isset($erreurs['pass'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['pass'] ?> </span> |
<?php endif; ?> |
</fieldset> |
<input type="submit" id="valider_modif_admin" name="valider_modif_admin" tabindex="7" value="Modifier" /> |
<a href="<?=$base_url.'?m=liste_admin' ?>"> annuler </a> |
</form> |
/trunk/papyrus/applications/admin_administrateur/squelettes/liste_admin.tpl.html |
---|
1,14 → 1,14 |
<h2> Liste des administrateurs</h2> |
<table class="liste_admin"> |
<th> Identifiant d'admin </th> <th> Nom </th> <th> Prénom </th> <th> Langue </th> <th> </th> <th> </th> |
<?php foreach ($admin as $element) : ?> |
<tr><td><?=$element['ga_id_administrateur'] ?></td><td><?=$element['ga_nom'] ?></td><td><?=$element['ga_prenom'] ?></td><td><?=$element['ga_ce_i18n'] ?></td><td><a href=<?=$base_url.'?m=modif_admin&id_admin='.$element['ga_id_administrateur'] ?>>Modifier</a></td><td><a href=<?=$base_url.'?m=suppr_admin&id_admin='.$element['ga_id_administrateur'] ?>>Supprimer</a></td></tr> |
<?php endforeach; ?> |
</table> |
<?php if (isset($erreurs['supp'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['supp'] ?> </span> |
<?php endif; ?> |
<p> |
<a href="<?=$base_url.'?&m=ajout_admin' ?>"> Ajouter un administrateur </a> |
<h2> Liste des administrateurs</h2> |
<table class="table_cadre"> |
<th> Identifiant d'admin </th> <th> Nom </th> <th> Prénom </th> <th> Langue </th> <th> </th> <th> </th> |
<?php foreach ($admin as $element) : ?> |
<tr><td><?=$element['ga_id_administrateur'] ?></td><td><?=$element['ga_nom'] ?></td><td><?=$element['ga_prenom'] ?></td><td><?=$element['ga_ce_i18n'] ?></td><td><a href=<?=$base_url.'?m=modif_admin&id_admin='.$element['ga_id_administrateur'] ?>>Modifier</a></td><td><a href=<?=$base_url.'?m=suppr_admin&id_admin='.$element['ga_id_administrateur'] ?>>Supprimer</a></td></tr> |
<?php endforeach; ?> |
</table> |
<?php if (isset($erreurs['supp'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['supp'] ?> </span> |
<?php endif; ?> |
<p> |
<a href="<?=$base_url.'?&m=ajout_admin' ?>"> Ajouter un administrateur </a> |
</p> |
/trunk/papyrus/applications/admin_administrateur/squelettes/ajout_admin.tpl.html |
---|
1,31 → 1,31 |
<h2> Ajout d'un administrateur</h2> |
<form id="modif_admin" action="<?=$base_url.'?&m=ajout_admin_va'?>" method="post"> |
<fieldset> |
<?php if (isset($erreurs['champs'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['champs'] ?> </span> |
<?php endif; ?> |
<label for="admin_nom">Nom : </label> |
<input type="text" id="admin_nom" name="admin_nom" maxlength="80" tabindex="1" value="<?=$admin['ga_nom'] ?>" /> |
<label for="admin_prenom">Prénom : </label> |
<input type="text" id="admin_prenom" name="admin_prenom" maxlength="80" tabindex="2" value="<?=$admin['ga_prenom'] ?>" /> |
<label for="admin_mail">Mail : </label> |
<input type="text" id="admin_mail" name="admin_mail" maxlength="120" tabindex="3" value="<?=$admin['ga_mail'] ?>" /> |
<?php if (isset($erreurs['mail'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['mail'] ?> </span> |
<?php endif; ?> |
<label for="admin_lang">Langue : </label> |
<select id="admin_lang" name="admin_lang" tabindex="4"> |
<option <?=($admin['ga_ce_i18n'] == "fr-FR") ? 'selected="selected"' : '';?> value="fr-FR"> Français </option> |
<option <?=($admin['ga_ce_i18n'] == "en-EN") ? 'selected="selected"' : '';?> value="en-EN"> Anglais </option> |
</select> |
<label for="password">Mot de passe : </label> |
<input type="password" id="admin_pass" name="admin_pass" maxlength="80" tabindex="5" value="<?='' ?>" /> |
<label for="password_confirm">Confirmez le mot de passe : </label> |
<input type="password" id="admin_pass_confirm" name="admin_pass_confirm" maxlength="80" tabindex="6" value="<?='' ?>" /> |
<?php if (isset($erreurs['pass'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['pass'] ?> </span> |
<?php endif; ?> |
</fieldset> |
<input type="submit" id="valider_ajout_admin" name="valider_ajout_admin" tabindex="7" value="Ajouter" /> |
<a href="<?= $base_url.'?m=liste_admin' ?>"> annuler </a> |
<h2> Ajout d'un administrateur</h2> |
<form id="modif_admin" action="<?=$base_url.'?&m=ajout_admin_va'?>" method="post"> |
<fieldset> |
<?php if (isset($erreurs['champs'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['champs'] ?> </span> |
<?php endif; ?> <br /> |
<label for="admin_nom">Nom : </label> |
<input type="text" id="admin_nom" name="admin_nom" maxlength="80" tabindex="1" value="<?=$admin['ga_nom'] ?>" /> <br /> |
<label for="admin_prenom">Prénom : </label> |
<input type="text" id="admin_prenom" name="admin_prenom" maxlength="80" tabindex="2" value="<?=$admin['ga_prenom'] ?>" /> <br /> |
<label for="admin_mail">Mail : </label> |
<input type="text" id="admin_mail" name="admin_mail" maxlength="120" tabindex="3" value="<?=$admin['ga_mail'] ?>" /> |
<?php if (isset($erreurs['mail'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['mail'] ?> </span> |
<?php endif; ?> <br /> |
<label for="admin_lang">Langue : </label> |
<select id="admin_lang" name="admin_lang" tabindex="4"> |
<option <?=($admin['ga_ce_i18n'] == "fr-FR") ? 'selected="selected"' : '';?> value="fr-FR"> Français </option> |
<option <?=($admin['ga_ce_i18n'] == "en-EN") ? 'selected="selected"' : '';?> value="en-EN"> Anglais </option> |
</select> <br /> |
<label for="password">Mot de passe : </label> |
<input type="password" id="admin_pass" name="admin_pass" maxlength="80" tabindex="5" value="<?='' ?>" /> <br /> |
<label for="password_confirm">Confirmez le mot de passe : </label> |
<input type="password" id="admin_pass_confirm" name="admin_pass_confirm" maxlength="80" tabindex="6" value="<?='' ?>" /> |
<?php if (isset($erreurs['pass'])): ?> |
<span class="symbole_obligatoire"> <?=$erreurs['pass'] ?> </span> |
<?php endif; ?> <br /> |
</fieldset> |
<input type="submit" id="valider_ajout_admin" name="valider_ajout_admin" tabindex="7" value="Ajouter" /> |
<a href="<?= $base_url.'?m=liste_admin' ?>"> annuler </a> |
</form> |
/trunk/papyrus/applications/admin_administrateur/squelettes/ident_admin.tpl.html |
---|
1,11 → 1,11 |
<p class="zone_alert">Identifiez-vous</p> |
<form id="form_connexion" style="clear:both;" class="form_identification" action="<?=$base_url ?>" method="post"> |
<fieldset> |
<legend>Identifiez vous</legend> |
<label for="username">Courriel : </label> |
<input type="text" id="username" name="username" maxlength="80" tabindex="1" value="courriel" /> |
<label for="password">Mot de passe : </label> |
<input type="password" id="password" name="password" maxlength="80" tabindex="2" value="mot de passe" /> |
<input type="submit" id="connexion" name="connexion" tabindex="3" value="ok" /> |
</fieldset> |
<p class="zone_alert">Identifiez-vous</p> |
<form id="form_connexion" style="clear:both;" class="form_identification" action="<?=$base_url ?>" method="post"> |
<fieldset> |
<legend>Identifiez vous</legend> |
<label for="username">Courriel : </label> |
<input type="text" id="username" name="username" maxlength="80" tabindex="1" value="courriel" /> |
<label for="password">Mot de passe : </label> |
<input type="password" id="password" name="password" maxlength="80" tabindex="2" value="mot de passe" /> |
<input type="submit" id="connexion" name="connexion" tabindex="3" value="ok" /> |
</fieldset> |
</form> |
/trunk/papyrus/applications/admin_administrateur/controleurs/AdminAdministrateur.php |
---|
1,177 → 1,177 |
<?php |
/** |
* Classe controleur pour l'application administration des administrateurs |
*/ |
class AdminAdministrateur extends Controleur { |
/** |
* Fonction d'affichage par défaut, elle appelle la liste des administrateurs |
*/ |
function index() { |
$this->charger_admin() ; |
} |
/** |
* Charge la liste des administrateurs et l'envoie à la vue |
* @param array un tableau contenant les erreurs à afficher s'il y en a |
*/ |
function chargerAdmin($erreurs = array()) { |
$this->chargerModele('ListeAdmin'); |
$data['erreurs'] = $erreurs; |
$data['admin'] = $this->ListeAdmin->chargerAdmin(); |
$this->chargerVue('liste_admin',$data); |
return $this->liste_admin; |
} |
/** |
* Charge les détails d'un administrateur demandé et l'envoi à la |
* vue qui permet de les modifier |
*/ |
function modifAdmin($id) { |
$this->chargerModele('ListeAdmin'); |
$data['admin'] = $this->ListeAdmin->loadDetailsAdmin($id); |
$this->chargerVue('modif_admin',$data); |
return $this->modif_admin; |
} |
/** |
* Fonction appelée lors de la validation du formulaire de modification |
* des détails d'un administrateurs. Elle modifie les détails dans la base |
* de données. S'il y a une erreur et rappelle la formulaire et notifie l'erreur, |
* sinon elle charge la liste des administrateurs |
*/ |
function modifAdminVa($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf) { |
$this->chargerModele('ListeAdmin') ; |
$res = $this->ListeAdmin->modifDetailsAdmin($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf) ; |
if(count($res) == 0) { |
return $this->chargerAdmin() ; |
} else { |
$admin['ga_id_administrateur'] = $id ; |
$admin['ga_nom'] = $nom ; |
$admin['ga_prenom'] = $prenom ; |
$admin['ga_mail'] = $mail ; |
$admin['ga_ce_i18n'] = $lang ; |
$data['admin'] = $admin ; |
$data['erreurs'] = $res ; |
$this->chargerVue('modif_admin',$data); |
return $this->modif_admin; |
} |
} |
/** |
* Supprime un administrateur dans la base de données, |
* renvoie la liste des administrateurs, en affichant des erreurs |
* s'il y en a. |
* |
*/ |
function supprAdmin() { |
$id = $_GET['id_admin'] ; |
$this->chargerModele('ListeAdmin') ; |
$res = $this->ListeAdmin->suppAdmin($id) ; |
if($res == '') { |
return $this->chargerAdmin() ; |
} else { |
$erreurs['supp'] = $res ; |
return $this->chargerAdmin($erreurs) ; |
} |
} |
/** |
* Appelle la vue contenant le formulaire d'ajout d'un administrateur |
*/ |
function ajoutAdmin() { |
$admin['ga_id_administrateur'] = ''; |
$admin['ga_nom'] = ''; |
$admin['ga_prenom'] = ''; |
$admin['ga_mail'] = ''; |
$admin['ga_ce_i18n'] = ''; |
$data['admin'] = $admin; |
$this->chargerVue('ajout_admin',$data); |
return $this->ajout_admin; |
} |
/** |
* Fonction appelée lors de la validation du formulaire d'ajout d'un administrateur. |
* Elle ajoute celui-ci les dans la base de données |
* S'il y a une erreur et rappelle la formulaire et notifie l'erreur, |
* sinon elle charge la liste des administrateurs |
*/ |
function ajoutAdminVa($nom,$prenom,$mail,$lang,$pass,$pass_conf) { |
if(empty($nom) || empty($prenom) || empty($mail) || empty($pass) || empty($pass_conf)) { |
$res = array('champs' => 'Tous les champs sont obligatoires') ; |
$data['erreurs'] = $res ; |
$admin['ga_nom'] = $nom ; |
$admin['ga_prenom'] = $prenom ; |
$admin['ga_mail'] = $mail ; |
$admin['ga_ce_i18n'] = $lang ; |
$data['admin'] = $admin ; |
$this->chargerVue('ajout_admin',$data); |
return $this->ajout_admin; |
} |
$this->chargerModele('ListeAdmin') ; |
$res = $this->ListeAdmin->ajoutAdmin($nom,$prenom,$mail,$lang,$pass,$pass_conf) ; |
if(count($res) == 0) { |
return $this->chargerAdmin() ; |
} else { |
$admin['ga_nom'] = $nom ; |
$admin['ga_prenom'] = $prenom ; |
$admin['ga_mail'] = $mail ; |
$admin['ga_ce_i18n'] = $lang ; |
$data['admin'] = $admin ; |
$data['erreurs'] = $res ; |
$this->chargerVue('ajout_admin',$data); |
return $this->ajout_admin; |
} |
} |
/** Apelle le formulaire d'identification (dans le cas où l'utilisateur n'est pas identifié) |
*/ |
function demanderIdent() { |
$this->chargerVue('ident_admin',null) ; |
return $this->ident_admin; |
} |
/** |
* Renvoie la tête de page de l'application |
*/ |
function adminTete() { |
$tete = '<h1>Gestion des administrateurs de Papyrus</h1>'; |
return $tete; |
} |
/** |
* Renvoie le pied de page de l'application |
*/ |
function adminPied() { |
$pied = ''; |
return $pied ; |
} |
} |
?> |
<?php |
/** |
* Classe controleur pour l'application administration des administrateurs |
*/ |
class AdminAdministrateur extends Controleur { |
/** |
* Fonction d'affichage par défaut, elle appelle la liste des administrateurs |
*/ |
function index() { |
$this->charger_admin() ; |
} |
/** |
* Charge la liste des administrateurs et l'envoie à la vue |
* @param array un tableau contenant les erreurs à afficher s'il y en a |
*/ |
function chargerAdmin($erreurs = array()) { |
$this->chargerModele('ListeAdmin'); |
$data['erreurs'] = $erreurs; |
$data['admin'] = $this->ListeAdmin->chargerAdmin(); |
$this->chargerVue('liste_admin',$data); |
return $this->liste_admin; |
} |
/** |
* Charge les détails d'un administrateur demandé et l'envoi à la |
* vue qui permet de les modifier |
*/ |
function modifAdmin($id) { |
$this->chargerModele('ListeAdmin'); |
$data['admin'] = $this->ListeAdmin->loadDetailsAdmin($id); |
$this->chargerVue('modif_admin',$data); |
return $this->modif_admin; |
} |
/** |
* Fonction appelée lors de la validation du formulaire de modification |
* des détails d'un administrateurs. Elle modifie les détails dans la base |
* de données. S'il y a une erreur et rappelle la formulaire et notifie l'erreur, |
* sinon elle charge la liste des administrateurs |
*/ |
function modifAdminVa($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf) { |
$this->chargerModele('ListeAdmin') ; |
$res = $this->ListeAdmin->modifDetailsAdmin($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf) ; |
if(count($res) == 0) { |
return $this->chargerAdmin() ; |
} else { |
$admin['ga_id_administrateur'] = $id ; |
$admin['ga_nom'] = $nom ; |
$admin['ga_prenom'] = $prenom ; |
$admin['ga_mail'] = $mail ; |
$admin['ga_ce_i18n'] = $lang ; |
$data['admin'] = $admin ; |
$data['erreurs'] = $res ; |
$this->chargerVue('modif_admin',$data); |
return $this->modif_admin; |
} |
} |
/** |
* Supprime un administrateur dans la base de données, |
* renvoie la liste des administrateurs, en affichant des erreurs |
* s'il y en a. |
* |
*/ |
function supprAdmin() { |
$id = $_GET['id_admin'] ; |
$this->chargerModele('ListeAdmin') ; |
$res = $this->ListeAdmin->suppAdmin($id) ; |
if($res == '') { |
return $this->chargerAdmin() ; |
} else { |
$erreurs['supp'] = $res ; |
return $this->chargerAdmin($erreurs) ; |
} |
} |
/** |
* Appelle la vue contenant le formulaire d'ajout d'un administrateur |
*/ |
function ajoutAdmin() { |
$admin['ga_id_administrateur'] = ''; |
$admin['ga_nom'] = ''; |
$admin['ga_prenom'] = ''; |
$admin['ga_mail'] = ''; |
$admin['ga_ce_i18n'] = ''; |
$data['admin'] = $admin; |
$this->chargerVue('ajout_admin',$data); |
return $this->ajout_admin; |
} |
/** |
* Fonction appelée lors de la validation du formulaire d'ajout d'un administrateur. |
* Elle ajoute celui-ci les dans la base de données |
* S'il y a une erreur et rappelle la formulaire et notifie l'erreur, |
* sinon elle charge la liste des administrateurs |
*/ |
function ajoutAdminVa($nom,$prenom,$mail,$lang,$pass,$pass_conf) { |
if(empty($nom) || empty($prenom) || empty($mail) || empty($pass) || empty($pass_conf)) { |
$res = array('champs' => 'Tous les champs sont obligatoires') ; |
$data['erreurs'] = $res ; |
$admin['ga_nom'] = $nom ; |
$admin['ga_prenom'] = $prenom ; |
$admin['ga_mail'] = $mail ; |
$admin['ga_ce_i18n'] = $lang ; |
$data['admin'] = $admin ; |
$this->chargerVue('ajout_admin',$data); |
return $this->ajout_admin; |
} |
$this->chargerModele('ListeAdmin') ; |
$res = $this->ListeAdmin->ajoutAdmin($nom,$prenom,$mail,$lang,$pass,$pass_conf) ; |
if(count($res) == 0) { |
return $this->chargerAdmin() ; |
} else { |
$admin['ga_nom'] = $nom ; |
$admin['ga_prenom'] = $prenom ; |
$admin['ga_mail'] = $mail ; |
$admin['ga_ce_i18n'] = $lang ; |
$data['admin'] = $admin ; |
$data['erreurs'] = $res ; |
$this->chargerVue('ajout_admin',$data); |
return $this->ajout_admin; |
} |
} |
/** Apelle le formulaire d'identification (dans le cas où l'utilisateur n'est pas identifié) |
*/ |
function demanderIdent() { |
$this->chargerVue('ident_admin',null) ; |
return $this->ident_admin; |
} |
/** |
* Renvoie la tête de page de l'application |
*/ |
function adminTete() { |
$tete = '<h1>Gestion des administrateurs de Papyrus</h1>'; |
return $tete; |
} |
/** |
* Renvoie le pied de page de l'application |
*/ |
function adminPied() { |
$pied = ''; |
return $pied ; |
} |
} |
?> |