Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2013 → Rev 2014

/trunk/papyrus/applications/admin_administrateur/bibliotheque/Registre.php
New file
0,0 → 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;
}
}
?>
/trunk/papyrus/applications/admin_administrateur/bibliotheque/Chronometre.php
New file
0,0 → 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 ----------------------------------------------------------------------------------------+
*/
?>
/trunk/papyrus/applications/admin_administrateur/bibliotheque/Modele.php
New file
0,0 → 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);
}
/**
* 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
New file
0,0 → 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 ;
}
 
}
?>
/trunk/papyrus/applications/admin_administrateur/bibliotheque/Controleur.php
New file
0,0 → 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;
}
}
?>
/trunk/papyrus/applications/admin_administrateur/bibliotheque/GestionnaireErreur.php
New file
0,0 → 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;
}
}
?>