2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
24 * Gestion des erreurs pour LdapSaisie
26 * Cette classe gère les retours d'erreurs.
28 * @author Benjamin Renard <brenard@easter-eggs.com>
32 private static $_errorCodes = array(
33 '0' => array('msg' => "%{msg}")
39 * @author Benjamin Renard <brenard@easter-eggs.com>
41 * @param[in] $code numeric Le code de l'erreur
42 * @param[in] $msg LSformat Le format paramètrable du message de l'erreur
46 public static function defineError($code=-1,$msg='') {
47 self :: $_errorCodes[$code] = array(
55 * @author Benjamin Renard <brenard@easter-eggs.com>
57 * @param[in] $code numeric Le code de l'erreur
58 * @param[in] $msg mixed Un tableau ou une chaine pour la construction du message d'erreur
59 * Tableau : '[clef]' => 'valeur'
60 * La clef sera utilisé dans le format de message d'erreur
61 * dans le fichier 'error_code.php'.
65 public static function addErrorCode($code=-1,$msg='') {
66 $_SESSION['LSerror'][] = array($code,$msg);
72 * @author Benjamin Renard <brenard@easter-eggs.com>
74 * @param[in] $return boolean True pour que le texte d'erreurs soit retourné
78 public static function display($return=False) {
79 $errors = self::getErrors();
84 $GLOBALS['Smarty'] -> assign('LSerrors',$errors);
89 * Print errors and stop LdapSaisie
91 * @author Benjamin Renard <brenard@easter-eggs.com>
93 * @param[in] $code Error code (Goto : addErrorCode())
94 * @param[in] $msg Error msg (Goto : addErrorCode())
98 public static function stop($code=-1,$msg='') {
99 if(!empty($_SESSION['LSerror'])) {
100 print "<h1>"._('Errors')."</h1>\n";
101 print self::display(true);
103 print "<h1>"._('Stop')."</h1>\n";
104 exit (self::getError(array($code,$msg)));
108 * Retourne le texte des erreurs
110 * @author Benjamin Renard <brenard@easter-eggs.com>
112 * @retvat string Le texte des erreurs
114 public static function getErrors() {
115 if(!empty($_SESSION['LSerror'])) {
116 foreach ($_SESSION['LSerror'] as $error) {
117 $txt.=self::getError($error);
126 * Retourne le texte d'une erreur
128 * @author Benjamin Renard <brenard@easter-eggs.com>
130 * @retvat string Le texte des erreurs
132 private static function getError($error) {
133 return "(Code ".$error[0].") ".getFData(self :: $_errorCodes[$error[0]]['msg'],$error[1])."<br />\n";
137 * Définir si il y a des erreurs
139 * @author Benjamin Renard <brenard@easter-eggs.com>
143 public static function errorsDefined() {
144 return !empty($_SESSION['LSerror']);
148 * Efface les erreurs sotckés
150 * @author Benjamin Renard <brenard@easter-eggs.com>
154 private static function resetError() {
155 unset ($_SESSION['LSerror']);
159 * Check if is Net_LDAP2 error and display possible error message
161 * @param[in] $data mixed Data
163 * @retval boolean True if it's an error or False
165 public function isLdapError($data) {
166 if (Net_LDAP2::isError($data)) {
167 LSerror :: addErrorCode(0,$data -> getMessage());
177 LSerror :: defineError(-1,_("Unknown error!"));