[doc] switching comments to english for quenenni patches

This commit is contained in:
Benjamin Sonntag 2017-10-06 12:00:27 +02:00
parent b88b639b60
commit b777f982e5
1 changed files with 128 additions and 133 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
/* /*
$Id: m_messages.php,v 1.4 2004/05/19 14:23:06 benjamin Exp $
---------------------------------------------------------------------- ----------------------------------------------------------------------
LICENSE LICENSE
@ -17,111 +16,108 @@
To read the license please visit http://www.gnu.org/copyleft/gpl.html To read the license please visit http://www.gnu.org/copyleft/gpl.html
---------------------------------------------------------------------- ----------------------------------------------------------------------
Original Author of file: Benjamin Sonntag, Franck Missoum */
----------------------------------------------------------------------
*/
/** /**
* Classe de gestion des messages apparaissant lors d'appels API. * Handle messages (error, warning, info, ok) appearing in API calls.
* *
* <p>Cette classe gère les messages qui peuvent apparaitre lors d'appels * <p>This class handles messages appearing while calling API functions of AlternC
* à l'API d'AlternC. Ces msgs sont stockées sous la forme d'1 nombre * Those messages are stored as a number (class-id) and a message
* (Classe ID) ainsi que du msg en associé. * localized messages are available</p>
* Des messages localisés sont aussi disponibles.</p> * <p>This class also handle inserting those messages into the logging
* <p>Cette classe se charge aussi d'insérer les appels à l'API d'AlternC * system in /var/log/alternc/bureau.log
* dans les logs du système dans /var/log/alternc/bureau.log
* </p> * </p>
* Copyleft {@link http://alternc.net/ AlternC Team}
* *
* @copyright AlternC-Team 2002-11-01 http://alternc.net/ * @copyright AlternC-Team https://alternc.com/
*/ */
class m_messages { class m_messages {
/** Tableau qui va contenir les messages et leur id */ /** Contains the messages and their ID */
var $arrMessages = array(); var $arrMessages = array();
/** Emplacement du fichier de logs d'AlternC */
var $logfile = "/var/log/alternc/bureau.log"; var $logfile = "/var/log/alternc/bureau.log";
/** Liste of possible type */ /** List of possible message types */
var $ARRTYPES = array("ERROR", "ALERT", "INFO", "OK"); var $ARRTYPES = array("ERROR", "ALERT", "INFO", "OK");
/** Associate css classes */ /** CSS classes for each type */
var $ARRCSS = array( var $ARRCSS = array(
"ERROR" => "alert-danger", "ERROR" => "alert-danger",
"ALERT" => "alert-warning", "ALERT" => "alert-warning",
"INFO" => "alert-info", "INFO" => "alert-info",
"OK" => "alert-success" "OK" => "alert-success"
); );
public function __construct() { public function __construct() {
$this->init_msgs(); $this->init_msgs();
} }
/** /**
* Enregistre un message, signale celle-ci dans les logs * Record a message, insert it into the logfile.
* *
* Cette fonction enregistre un message, l'ajoute dans les logs d'AlternC, * This function records a message, add it to the logfile,
* et la met à disposition pour le bureau virtuel pour affichage ultérieur. * and make it available for the web panel to print it later.
* *
* @param string $cat The category of the msg array to work with * @param string $cat The category of the msg array to work with
* @param integer $clsid Classe qui lève le message * @param integer $clsid Which class raises this message
* @param mixed $msg Message * @param mixed $msg The message
* @param string $param Paramètre chaine associé au message (facultatif) * @param string $param Non-mandatory string parameter for this message
* @return boolean TRUE si le msg est enregistré, FALSE sinon. * @return boolean TRUE if the message got recorded, FALSE if not.
* *
*/ */
function raise($cat = "Error", $clsid, $msg, $param = "") { function raise($cat = "Error", $clsid, $msg, $param = "") {
$arrInfos = array(); $arrInfos = array();
$type = strtoupper($cat); $type = strtoupper($cat);
if (! in_array($type, $this->ARRTYPES)) { if (! in_array($type, $this->ARRTYPES)) {
return false; return false;
} }
$arrInfos['clsid'] = $clsid; $arrInfos['clsid'] = $clsid;
$arrInfos['msg'] = $msg; $arrInfos['msg'] = $msg;
$arrInfos['param'] = is_array($param)?$param:(empty($param)?"":array($param)); $arrInfos['param'] = is_array($param)?$param:(empty($param)?"":array($param));
$this->arrMessages[$type][] = $arrInfos; $this->arrMessages[$type][] = $arrInfos;
$this->logAlternC($cat); $this->logAlternC($cat);
return true; return true;
} }
/**
* Reset the stored messages array
*/
function init_msgs() { function init_msgs() {
// Initialisation du tableau des message foreach ($this->ARRTYPES as $v) {
foreach ($this->ARRTYPES as $v) { $this->arrMessages[$v] = array();
$this->arrMessages[$v] = array(); }
}
} }
/** /**
* Indique s'il y a ds msgs enregistrés pour une catégorie si le param $cat contient une catégorie * Tell if there are stored messages for a specific level
* ou pour toutesl es catégories si $cat est vide * or for all levels (if level is empty)
* *
* @param string $cat The category of the msg array to work with * @param string $cat The level of the msg array to work with
* @return boolean True if there is/are msg recorded. * @return boolean TRUE if there is/are msg recorded.
* *
*/ */
function has_msgs($cat) { function has_msgs($cat) {
$type = strtoupper($cat); $type = strtoupper($cat);
if (in_array($type, $this->ARRTYPES)) { if (in_array($type, $this->ARRTYPES)) {
return (count($this->arrMessages[$type]) > 0); return (count($this->arrMessages[$type]) > 0);
} else { } else {
foreach ($this->arrMessages as $v) { foreach ($this->arrMessages as $v) {
if (count($v) > 0) if (count($v) > 0)
return true; return true;
} }
return false; return false;
} }
} }
/** /**
* Retourne la chaine de message concaténés de l'ensemble des msgs enregistrés * Return a string of concateneted messages of all recorded messages
* ou du dernièr message rencontré * or only the last message
* *
* @param string $cat The category of the msg array to work with * @param string $cat The level of the msg array to work with
* @param string $sep The separator used to concatenate msgs * @param string $sep The separator used to concatenate msgs
* @param boolean $all show all the messages or only the last one * @param boolean $all show all the messages or only the last one
* *
@ -129,78 +125,78 @@ class m_messages {
* *
*/ */
function msg_str($cat = "Error", $sep = "<li>", $all = true) { function msg_str($cat = "Error", $sep = "<li>", $all = true) {
$str = ""; $str = "";
$type = strtoupper($cat); $type = strtoupper($cat);
if (! in_array($type, $this->ARRTYPES)) { if (! in_array($type, $this->ARRTYPES)) {
return false; return false;
} }
if (! $this->has_msgs($cat)) if (! $this->has_msgs($cat))
return ""; return "";
if ($all) { if ($all) {
foreach ($this->arrMessages[$type] as $k => $arrMsg) { foreach ($this->arrMessages[$type] as $k => $arrMsg) {
$args = $arrMsg['param']; $args = $arrMsg['param'];
if (is_array($args) && count($args) > 0) { if (is_array($args) && count($args) > 0) {
array_unshift($args, $arrMsg['msg']); array_unshift($args, $arrMsg['msg']);
if ($sep == "<li>") if ($sep == "<li>")
$str .= "<li>" . call_user_func_array("sprintf", $args) . "</li>"; $str .= "<li>" . call_user_func_array("sprintf", $args) . "</li>";
else else
$str .= call_user_func_array("sprintf", $args) . $sep; $str .= call_user_func_array("sprintf", $args) . $sep;
} else } else
if ($sep == "<li>") if ($sep == "<li>")
$str .= "<li>" . $arrMsg['msg'] . "</li>"; $str .= "<li>" . $arrMsg['msg'] . "</li>";
else else
$str .= $arrMsg['msg'] . $sep; $str .= $arrMsg['msg'] . $sep;
} }
if ($sep == "<li>") if ($sep == "<li>")
$str = "<ul>".$str."</ul>"; $str = "<ul>".$str."</ul>";
} else { } else {
$i = count($this->arrMessages[$type]) - 1; $i = count($this->arrMessages[$type]) - 1;
if ($i > 0) { if ($i > 0) {
$arr_msg=$this->arrMessages[$type][$i]; $arr_msg=$this->arrMessages[$type][$i];
$args = $arr_msg['param']; $args = $arr_msg['param'];
if (is_array($args) && count($args) > 0) { if (is_array($args) && count($args) > 0) {
array_unshift($args, $arr_msg['msg']); array_unshift($args, $arr_msg['msg']);
$str = call_user_func_array("sprintf", $args); $str = call_user_func_array("sprintf", $args);
} else } else
$str = $arr_msg['msgId']; $str = $arr_msg['msgId'];
} }
} }
return $str; return $str;
} }
/** /**
* Retourn le message au format Html avec la class Css associée * Return a message in HTML form with associated CSS
* *
* @param string $cat The category of the msg array to work with * @param string $cat The level of the msg array to work with
* @param string $sep The separator used to concatenate msgs * @param string $sep The separator used to concatenate msgs
* @param boolean $all show all the messages or only the last one * @param boolean $all show all the messages or only the last one
* *
* @return string HTML message * @return string HTML message
*/ */
function msg_html($cat = "Error", $sep = "<li>", $all = true) { function msg_html($cat = "Error", $sep = "<li>", $all = true) {
$type = strtoupper($cat); $type = strtoupper($cat);
if (! in_array($type, $this->ARRTYPES)) { if (! in_array($type, $this->ARRTYPES)) {
return false; return false;
} }
if (count($this->arrMessages[$type]) == 0) if (count($this->arrMessages[$type]) == 0)
return ""; return "";
$str = $this->msg_str($cat, $sep, $all); $str = $this->msg_str($cat, $sep, $all);
$str = "<div class='alert " . $this->ARRCSS[$type] . "'>" . $str . "</div>"; $str = "<div class='alert " . $this->ARRCSS[$type] . "'>" . $str . "</div>";
return $str; return $str;
} }
/** /**
* Retourn le message de toutes les catégories au format Html avec la class Css associée * Return all the messages of all levels in HTML form with associated CSS
* *
* @param string $sep The separator used to concatenate msgs * @param string $sep The separator used to concatenate msgs
* @param boolean $all show all the messages or only the last one * @param boolean $all show all the messages or only the last one
@ -208,48 +204,47 @@ class m_messages {
* @return string HTML message * @return string HTML message
*/ */
function msg_html_all($sep = "<li>", $all = true, $init = false) { function msg_html_all($sep = "<li>", $all = true, $init = false) {
$msg=""; $msg="";
$msg.=$this->msg_html("Error", $sep, $all); $msg.=$this->msg_html("Error", $sep, $all);
$msg.=$this->msg_html("Ok", $sep, $all); $msg.=$this->msg_html("Ok", $sep, $all);
$msg.=$this->msg_html("Info", $sep, $all); $msg.=$this->msg_html("Info", $sep, $all);
$msg.=$this->msg_html("Alert", $sep, $all); $msg.=$this->msg_html("Alert", $sep, $all);
if ($init) if ($init)
$this->init_msgs(); $this->init_msgs();
return $msg; return $msg;
} }
/** /**
* Envoi un log dans /var/log/alternc/bureau.log * Log a message into /var/log/alternc/bureau.log
* *
* Cette fonction Loggue le dernier msg dans /var/log sur la machine, * This function logs the last message in the /var/log/alternc folder
* permettant ainsi aux admins de savoir ce qu'il se passe... * allowing sysadmins to know what's happened.
* Elle est appelée automatiquement par error * automatically called by raise()
* @access private * @access private
*/ */
function logAlternC($cat = "Error") { function logAlternC($cat = "Error") {
global $mem; global $mem;
$type = strtoupper($cat); $type = strtoupper($cat);
if (! in_array($type, $this->ARRTYPES)) { if (! in_array($type, $this->ARRTYPES)) {
return false; return false;
} }
@file_put_contents($this->logfile, date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - $type - " . $mem->user["login"] . " - " . $this->msg_str($cat, "", false), FILE_APPEND); @file_put_contents($this->logfile, date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - $type - " . $mem->user["login"] . " - " . $this->msg_str($cat, "", false), FILE_APPEND);
} }
/** /**
* Envoi un log d'appel d'API dans /var/log/alternc/bureau.log * Log an API function call into /var/log/alternc/bureau.log
* *
* Cette fonction loggue dans /var/log l'appel à la fonction de l'API * This function logs in /var/log/alternc an API function call of AlternC
* d'AlternC.
* *
* @param integer $clsid Numéro de la classe dont on a appelé une fonction * @param integer $clsid Number of the class doing the call
* @param string $function Nom de la fonction appelée * @param string $function Name of the called function
* @param string $param Paramètre (facultatif) passés à la fonction de l'API. * @param string $param non-mandatory parameters of the API call
* @return boolean TRUE si le log a été ajouté, FALSE sinon * @return boolean TRUE if the log where successfull, FALSE if not
* *
*/ */
function log($clsid, $function, $param = "") { function log($clsid, $function, $param = "") {
@ -259,4 +254,4 @@ class m_messages {
} }
/* Classe m_messages */ /* Class m_messages */