Alternc  latest
Alternc logiel libre pour l'hébergement
m_messages Class Reference

Handle messages (error, warning, info, ok) appearing in API calls. More...

Public Member Functions

 __construct ()
 
 raise ($level="ERROR", $clsid, $msg, $param="")
 Record a message, insert it into the logfile. More...
 
 init_msgs ()
 Reset the stored messages array. More...
 
 has_msgs ($level="")
 Tell if there are stored messages for a specific level or for all levels (if level is empty) More...
 
 msg_str ($level="ERROR", $all=true)
 Return a string of concateneted messages of all recorded messages or only the last message. More...
 
 msg_html ($level="ERROR", $all=true)
 Return a message in HTML form with associated CSS. More...
 
 msg_html_all ($all=true, $init=false)
 Return all the messages of all levels in HTML form with associated CSS. More...
 
 logAlternC ($level="ERROR", $arrMsg)
 Log a message into /var/log/alternc/bureau.log. More...
 
 log ($clsid, $function, $param="")
 Log an API function call into /var/log/alternc/bureau.log. More...
 
 debug ($clsid, $function, $param="")
 Log an API function call into /var/log/alternc/bureau.log. More...
 

Public Attributes

 $arrMessages = array()
 Contains the messages and their ID. More...
 
 $logfile = "/var/log/alternc/bureau.log"
 
 $ARRLEVEL = array("ERROR", "ALERT", "INFO")
 List of possible message level. More...
 
 $ARRCSS
 CSS classes for each level. More...
 

Detailed Description

Handle messages (error, warning, info, ok) appearing in API calls.

This class handles messages appearing while calling API functions of AlternC Those messages are stored as a number (class-id) and a message localized messages are available

This class also handle inserting those messages into the logging system in /var/log/alternc/bureau.log

Definition at line 33 of file m_messages.php.

Constructor & Destructor Documentation

◆ __construct()

m_messages::__construct ( )

Definition at line 51 of file m_messages.php.

51  {
52  $this->init_msgs();
53  }
init_msgs()
Reset the stored messages array.
Definition: m_messages.php:91

References init_msgs().

Member Function Documentation

◆ debug()

m_messages::debug (   $clsid,
  $function,
  $param = "" 
)

Log an API function call into /var/log/alternc/bureau.log.

This function logs in /var/log/alternc an API function call of AlternC

Parameters
integer$clsidNumber of the class doing the call
string$functionName of the called function
string$paramnon-mandatory parameters of the API call
Returns
boolean TRUE if the log where successfull, FALSE if not

Definition at line 278 of file m_messages.php.

278  {
279  global $mem;
280  if (variable_get("debug_panel", "0", "Set it to 1 to enable panel debug in /var/log/alternc/bureau.log")) {
281  return @file_put_contents(
282  $this->logfile,
283  date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - DEBUG - " . $mem->user["login"] . " - $clsid - $function - $param\n",
284  FILE_APPEND
285  );
286  }
287  }
$mem
Definition: bootstrap.php:71
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:85
get_remote_ip()
Return the remote IP.
Definition: functions.php:134

References $mem, get_remote_ip(), and variable_get().

◆ has_msgs()

m_messages::has_msgs (   $level = "")

Tell if there are stored messages for a specific level or for all levels (if level is empty)

Parameters
string$levelThe level of the msg array to work with (if empty or not set, use all levels)
Returns
boolean TRUE if there is/are msg recorded.

Definition at line 107 of file m_messages.php.

107  {
108  $level = strtoupper($level);
109  if (in_array($level, $this->ARRLEVEL)) {
110  return (count($this->arrMessages[$level]) > 0);
111  } else {
112  foreach ($this->arrMessages as $v) {
113  if (count($v) > 0)
114  return true;
115  }
116  return false;
117  }
118  }

Referenced by msg_str().

◆ init_msgs()

m_messages::init_msgs ( )

Reset the stored messages array.

Definition at line 91 of file m_messages.php.

91  {
92  // $me=debug_backtrace(); $this->log("messages", "init_msgs from ".$me[1]["class"].".".$me[1]["function"]);
93  foreach ($this->ARRLEVEL as $v) {
94  $this->arrMessages[$v] = array();
95  }
96  }

Referenced by __construct(), and msg_html_all().

◆ log()

m_messages::log (   $clsid,
  $function,
  $param = "" 
)

Log an API function call into /var/log/alternc/bureau.log.

This function logs in /var/log/alternc an API function call of AlternC

Parameters
integer$clsidNumber of the class doing the call
string$functionName of the called function
string$paramnon-mandatory parameters of the API call
Returns
boolean TRUE if the log where successfull, FALSE if not

Definition at line 258 of file m_messages.php.

258  {
259  global $mem;
260  return @file_put_contents(
261  $this->logfile,
262  date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - CALL - " . $mem->user["login"] . " - $clsid - $function - $param\n",
263  FILE_APPEND
264  );
265  }

References $mem, and get_remote_ip().

◆ logAlternC()

m_messages::logAlternC (   $level = "ERROR",
  $arrMsg 
)

Log a message into /var/log/alternc/bureau.log.

This function logs the last message in the /var/log/alternc folder allowing sysadmins to know what's happened. automatically called by raise()

Parameters
string$levelthe error level
array$arrMsgthe array containing message info. @access private

Definition at line 228 of file m_messages.php.

228  {
229  global $mem;
230 
231  $args = $arrMsg['param'];
232 
233  if (is_array($args) && count($args) > 0) {
234  array_unshift($args, $arrMsg['msg']);
235  $str = call_user_func_array("sprintf", $args);
236  } else
237  $str = $arrMsg['msg'];
238 
239  @file_put_contents(
240  $this->logfile,
241  date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - $level - " . $mem->user["login"] . " - " . $str . "\n",
242  FILE_APPEND
243  );
244  }

References $mem, and get_remote_ip().

Referenced by raise().

◆ msg_html()

m_messages::msg_html (   $level = "ERROR",
  $all = true 
)

Return a message in HTML form with associated CSS.

Parameters
string$levelThe level of the msg array to work with
string$sepThe separator used to concatenate msgs
boolean$allshow all the messages or only the last one
Returns
string HTML message

Definition at line 180 of file m_messages.php.

180  {
181  $level = strtoupper($level);
182  if (! in_array($level, $this->ARRLEVEL)) {
183  throw new Exception('Missing or unknown level in a raise() call');
184  }
185 
186  if (count($this->arrMessages[$level]) == 0)
187  return "";
188 
189  $str = $this->msg_str($level, $all);
190  $str = "<div class='alert " . $this->ARRCSS[$level] . "'>" . nl2br($str) . "</div>";
191 
192  return $str;
193  }
msg_str($level="ERROR", $all=true)
Return a string of concateneted messages of all recorded messages or only the last message.
Definition: m_messages.php:132

References msg_str().

Referenced by msg_html_all().

◆ msg_html_all()

m_messages::msg_html_all (   $all = true,
  $init = false 
)

Return all the messages of all levels in HTML form with associated CSS.

Parameters
string$sepThe separator used to concatenate msgs
boolean$allshow all the messages or only the last one
Returns
string HTML message

Definition at line 204 of file m_messages.php.

204  {
205  $msg="";
206 
207  $msg.=$this->msg_html("ERROR", $all);
208  $msg.=$this->msg_html("INFO", $all);
209  $msg.=$this->msg_html("ALERT", $all);
210 
211  if ($init)
212  $this->init_msgs();
213 
214  return $msg;
215  }
$msg
Definition: bootstrap.php:75
msg_html($level="ERROR", $all=true)
Return a message in HTML form with associated CSS.
Definition: m_messages.php:180

References $msg, init_msgs(), and msg_html().

◆ msg_str()

m_messages::msg_str (   $level = "ERROR",
  $all = true 
)

Return a string of concateneted messages of all recorded messages or only the last message.

Parameters
string$levelThe level of the msg array to work with
boolean$allshow all the messages or only the last one

@access private

Returns
string Message.

Definition at line 132 of file m_messages.php.

132  {
133  $str = "";
134 
135  $level = strtoupper($level);
136  if (! in_array($level, $this->ARRLEVEL)) {
137  throw new Exception('Missing or unknown level in a raise() call');
138  }
139 
140  if (! $this->has_msgs($level))
141  return "";
142 
143  if ($all) {
144  foreach ($this->arrMessages[$level] as $k => $arrMsg) {
145  $args = $arrMsg['param'];
146 
147  if (is_array($args) && count($args) > 0) {
148  array_unshift($args, $arrMsg['msg']);
149  $str .= call_user_func_array("sprintf", $args) . "\n";
150  } else
151  $str .= $arrMsg['msg'] . "\n";
152  }
153 
154  } else {
155  $i = count($this->arrMessages[$level]) - 1;
156  if ($i > 0) {
157  $arr_msg=$this->arrMessages[$level][$i];
158  $args = $arr_msg['param'];
159  if (is_array($args) && count($args) > 0) {
160  array_unshift($args, $arr_msg['msg']);
161  $str = call_user_func_array("sprintf", $args);
162  } else
163  $str = $arr_msg['msgId'];
164  }
165  }
166 
167  return $str;
168  }
has_msgs($level="")
Tell if there are stored messages for a specific level or for all levels (if level is empty)
Definition: m_messages.php:107
$i

References $i, and has_msgs().

Referenced by msg_html().

◆ raise()

m_messages::raise (   $level = "ERROR",
  $clsid,
  $msg,
  $param = "" 
)

Record a message, insert it into the logfile.

This function records a message, add it to the logfile, and make it available for the web panel to print it later.

Parameters
string$catThe category of the msg array to work with
integer$clsidWhich class raises this message
mixed$msgThe message
array$paramNon-mandatory array of string parameter for this message
Returns
boolean TRUE if the message got recorded, FALSE if not.

Definition at line 69 of file m_messages.php.

69  {
70  $arrInfos = array();
71 
72  $level = strtoupper($level);
73  if (! in_array($level, $this->ARRLEVEL)) {
74  throw new Exception('Missing or unknown level in a raise() call');
75  }
76 
77  $arrInfos['clsid'] = $clsid;
78  $arrInfos['msg'] = $msg;
79  $arrInfos['param'] = is_array($param)?$param:(empty($param)?"":array($param));
80 
81  $this->arrMessages[$level][] = $arrInfos;
82 
83  $this->logAlternC($level,$arrInfos);
84  return true;
85  }
logAlternC($level="ERROR", $arrMsg)
Log a message into /var/log/alternc/bureau.log.
Definition: m_messages.php:228

References $msg, and logAlternC().

Member Data Documentation

◆ $ARRCSS

m_messages::$ARRCSS
Initial value:
= array(
"ERROR" => "alert-danger",
"ALERT" => "alert-warning",
"INFO" => "alert-success",
)

CSS classes for each level.

Definition at line 44 of file m_messages.php.

◆ $ARRLEVEL

m_messages::$ARRLEVEL = array("ERROR", "ALERT", "INFO")

List of possible message level.

Definition at line 41 of file m_messages.php.

◆ $arrMessages

m_messages::$arrMessages = array()

Contains the messages and their ID.

Definition at line 36 of file m_messages.php.

◆ $logfile

m_messages::$logfile = "/var/log/alternc/bureau.log"

Definition at line 38 of file m_messages.php.


The documentation for this class was generated from the following file: