Source for file message.class.php

Documentation is available at message.class.php

  1. <?php   /*
  2.    *@=@=@=@ START LICENSE @=@=@=@*
  3.    Copyright or © or Copr. Stéphane TRICHET and Nicolas SOTRON
  4.    
  5.    stephane.t@simpliciweb.net and nicolas.s@simpliciweb.net
  6.    
  7.    This software is a computer program whose purpose is to make a
  8.    web hosting platform
  9.    
  10.    This software is governed by the CeCILL  license under French law and
  11.    abiding by the rules of distribution of free software.  You can  use, 
  12.    modify and/ or redistribute the software under the terms of the CeCILL
  13.    license as circulated by CEA, CNRS and INRIA at the following URL
  14.    "http://www.cecill.info". 
  15.    
  16.    As a counterpart to the access to the source code and  rights to copy,
  17.    modify and redistribute granted by the license, users are provided only
  18.    with a limited warranty  and the software's author,  the holder of the
  19.    economic rights,  and the successive licensors  have only  limited
  20.    liability. 
  21.    
  22.    In this respect, the user's attention is drawn to the risks associated
  23.    with loading,  using,  modifying and/or developing or reproducing the
  24.    software by the user in light of its specific status of free software,
  25.    that may mean  that it is complicated to manipulate,  and  that  also
  26.    therefore means  that it is reserved for developers  and  experienced
  27.    professionals having in-depth computer knowledge. Users are therefore
  28.    encouraged to load and test the software's suitability as regards their
  29.    requirements in conditions enabling the security of their systems and/or 
  30.    data to be ensured and,  more generally, to use and operate it in the 
  31.    same conditions as regards security. 
  32.    
  33.    The fact that you are presently reading this means that you have had
  34.    knowledge of the CeCILL license and that you accept its terms.
  35.    *@=@=@=@ END   LICENSE @=@=@=@*
  36.  
  37. */?><?php  
  38. /**
  39.  * Message Class
  40.  * 
  41.  * 
  42.  * @author SimpliciWeb
  43.  * @version $Id: message.class.php 804 2008-01-08 17:05:37Z stephanet $
  44.  * @package Common
  45.  * @subpackage Start
  46.  */    
  47.  
  48. /**
  49.  * Type of error : SILENT
  50.  *
  51.  */
  52. define('NET_ERROR_SILENT',         'S');
  53. /**
  54.  * Type of error : HTML
  55.  *
  56.  */
  57. define('NET_ERROR_HTML',           'H');
  58. /**
  59.  * Type of error : Internal
  60.  *
  61.  */
  62. define('NET_ERROR_INTERNAL',       'I');
  63.  
  64.  
  65. /**
  66.  * Generate an error loged to the PLICI logs /log
  67.  *
  68.  * @param bool $p_as_got_an_error   TRUE = log the error, FALSE = do nothing
  69.  * @param string $p_error_id 
  70.  * @return bool $p_as_got_an_error
  71.  */
  72. function onErrorThrow($p_as_got_an_error$p_error_id)/*, $p_fonction_name , $file_name_or_design_id , 
  73.                         $error_type = NET_ERROR_HTML, $array_params_for_error = array()) */{
  74.     if (!$p_as_got_an_error)
  75.         return $p_as_got_an_error
  76.     
  77.         $current_message_error $p_error_id;
  78.     
  79.         // quoi qu'il arrive on met une version courte de l'erreur dans le log
  80.         $prefix_msg_error "";//"[".date("D M d G:i:s Y")."] "."PLICI[".$_SERVER['HTTP_HOST']."] : "; 
  81.         
  82.         $error_msg_to_log $prefix_msg_error.$p_error_id."\n";
  83.         foreach(debug_backtrace(as $value{
  84.             $file $value['file'];
  85.             $line "(line: ".$value['line'].")";
  86.             $function $value['function'];
  87.             if (isset($value['args']&& is_array($value['args'])) {
  88.                 $function .= '("';
  89.                 foreach($value['args'as $keyargs => $valueargs{
  90.                     if ($keyargs>0)
  91.                         $function .= ",";
  92.                         
  93.                     if (!is_object($valueargs))
  94.                         $function .= $valueargs;
  95.                     else
  96.                         $function .= get_class($valueargs);
  97.                     
  98.                 }
  99.                 $function .= '")';
  100.             else
  101.                 $function .= '(none)';
  102.                 
  103.             $error_msg_to_log .=  $prefix_msg_error."         ".$line."  ".$file."\n";
  104.             $error_msg_to_log .=  $prefix_msg_error."         Fct :".$function."\n";
  105.         }
  106.         
  107.         if (mysql_errno()>0)
  108.             $error_msg_to_log .=  mysql_error()."\n";
  109.         
  110.         trigger_error($error_msg_to_log);
  111.  
  112.  
  113.     
  114.         // Si on doit setter une erreur vers l'HTML on le fait ici
  115.         global $g_object_loader;
  116.         $g_object_message =$g_object_loader->getMessage();
  117.         //echo_net("error, $p_error_id, $current_message_error");
  118.         $g_object_message->addError("error"$p_error_id$p_error_id);
  119.         
  120.         
  121.     return $p_as_got_an_error
  122. }
  123.  
  124. /**
  125.  * Any class wich extend ObjectCached can use a function cache using xRemembered, etc.
  126.  *
  127.  * @author SimpliciWeb
  128.  * @version $Id: message.class.php 804 2008-01-08 17:05:37Z stephanet $
  129.  * @package Common
  130.  * @subpackage Start
  131.  */
  132.  
  133. class Message {
  134.  
  135.     /**
  136.      * Pushed errors
  137.      *
  138.      * @var array 
  139.      */
  140.     var $errors         = array();
  141.     /**
  142.      * SiteInformation Object
  143.      *
  144.      * @var siteInformation 
  145.      */
  146.     var $m_object_siteinformation = NULL;
  147.     /**
  148.      * There is an error
  149.      *
  150.      * @var bool 
  151.      */
  152.     var $there_is_an_error  = false;
  153.     
  154.     /**
  155.      * Stop the message system
  156.      *
  157.      * @var bool 
  158.      */
  159.     var $m_is_registering = false;
  160.     /**
  161.      * Error registered
  162.      *
  163.      * @var array 
  164.      */
  165.     var $m_array_error_registered = NULL;
  166.     /**
  167.      * Error registered by id
  168.      *
  169.      * @var array 
  170.      */
  171.  
  172.     /**
  173.      * Constructor, init the requests and objects
  174.      *
  175.      * @return Message 
  176.      */
  177.     function Message({
  178.  
  179.         global $g_object_loader;
  180.         $this->m_object_siteinformation =$g_object_loader->getSiteInformation();
  181.         
  182.         
  183.     }
  184.  
  185.  
  186.  
  187.     /**
  188.      * Get messages to assign
  189.      *
  190.      * @param string $message 
  191.      */
  192.     function getMessagesToAssign(&$message{
  193.     
  194.             $this->xMakeErrorMessage($message$this->errors);
  195.  
  196.     }
  197.  
  198.     /**
  199.      * Format the errors messages
  200.      *
  201.      * @access private
  202.      * @param string $r_message 
  203.      * @param array $array_erros 
  204.      */
  205.     function xMakeErrorMessage(&$r_message$array_erros {
  206.  
  207.  
  208.         $r_message "";
  209.         for ($i=0$i sizeof($array_erros);$i++{
  210.  
  211.             if ($i>0)
  212.             $r_message .="<BR>";
  213.  
  214.             $r_message .=$array_erros[$i];
  215.         }
  216.     }
  217.  
  218.  
  219.     /**
  220.      * Enable Error Message registering
  221.      *
  222.      * @return bool 
  223.      */
  224.     function startDisablingError({
  225.         $this->m_array_error_registered = array();
  226.         $this->m_array_error_registered_by_iderror = array();
  227.         $this->m_is_registering = true;
  228.         return false;
  229.     }
  230.  
  231.     /**
  232.      * Disable Error Message registering
  233.      *
  234.      * @return bool 
  235.      */
  236.     function endDisablingError({
  237.         $this->m_is_registering = false;
  238.         
  239.         return false;
  240.     }
  241.  
  242.     /**
  243.      * Get the messages during disabling
  244.      *
  245.      * Used in import/export to not show errors directly but to show it after
  246.      * 
  247.      * @return string 
  248.      */
  249.     function getMessagesDuringDisabling({
  250.         $r_error_message "";
  251.         $this->xMakeErrorMessage($r_error_message$this->m_array_error_registered);
  252.         return $r_error_message;        
  253.     }
  254.  
  255.  
  256.     /**
  257.      * Return if a message has been encountred
  258.      *
  259.      * @return bool 
  260.      */
  261.     function thereIsAnError({
  262.         if ($this->there_is_an_error{
  263.             $this->there_is_an_error = false;
  264.             return true;
  265.         
  266.         return false;
  267.     }
  268.  
  269.  
  270.     /**
  271.      * Add an error
  272.      *
  273.      * @param string $p_type 
  274.      * @param string $p_id 
  275.      * @param string $current_message_error 
  276.      * @return string 
  277.      */
  278.     function addError($p_type$p_id$current_message_error{
  279.         $this->there_is_an_error = true;
  280.  
  281.         
  282.  
  283.         if ($this->m_is_registering{
  284.             $this->m_array_error_registered[sizeof($this->m_array_error_registered)$current_message_error;
  285.             $this->m_array_error_registered_by_iderror[$p_id$current_message_error;
  286.         else {
  287.             if (!in_array($current_message_error,$this->errors)) {
  288.                 $this->errors[sizeof($this->errors)$current_message_error;
  289.             }
  290.         }
  291.         
  292.         return $current_message_error;
  293.  
  294.     }
  295.  
  296.  
  297.  
  298. }
  299.  
  300.  
  301.  
  302. ?>

Documentation generated on Tue, 25 Mar 2008 15:35:14 +0100 by phpDocumentor 1.3.2