* // render a error directly * $oNotification = new Contenido_Notification(); * $oNotification->displayNotification( * Contenido_Notification::LEVEL_ERROR, 'Foobar does not exists' * ); * * // assign a notification to a variable * $oNotification = new Contenido_Notification(); * $sNotification = $oNotification->displayNotification( * Contenido_Notification::LEVEL_NOTIFICATION, 'Hey dude, you did it!' * ); * * * Requirements: * @con_php_req 5.0 * * * @package Contenido Backend classes * @version 1.1.0 * @author Timo A. Hummel * @copyright four for business AG * @license http://www.contenido.org/license/LIZENZ.txt * @link http://www.4fb.de * @link http://www.contenido.org * @since file available since contenido release <= 4.6 * * {@internal * created unknown * modified 2008-04-04, Timo Trautmann, added new colors and functions for direct output * modified 2008-06-30, Dominik Ziegler, add security fix * modified 2011-05-19, Murat Purc, adapted to PHP 5, formatted and documented code * * $Id$: * }} * */ if (!defined('CON_FRAMEWORK')) { die('Illegal call'); } class Contenido_Notification { /** * Error message level * @var string */ const LEVEL_ERROR = 'error'; /** * Warning message level * @var string */ const LEVEL_WARNING = 'warning'; /** * Info message level * @var string */ const LEVEL_INFO = 'info'; /** * Notification message level * @var string */ const LEVEL_NOTIFICATION = 'notification'; /** * Colors configuration * @var array */ protected $_aColors; /** * HTML path to images * @var string */ protected $_sPathImages; /** * Constructor */ public function __construct() { global $cfg; $this->_aColors = $cfg['color']; $this->_sPathImages = $cfg['path']['contenido_fullhtml'] . $cfg['path']['images']; } /** * Generates message box and returns it back. * * @param string $sLevel Message level, one of Contenido_Notification::LEVEL_* constants * @param string $sMessage The message to display * @param int $iStyle Flag tp use styles for display or not (feasible 1 or 0) * @return string */ public function messageBox($sLevel, $sMessage, $iStyle = 1) { switch ($sLevel) { case self::LEVEL_ERROR: $sHead = i18n('Error'); $sHeadClass = 'alertbox_error'; $frameColor = $this->_aColors['notify_error']; $sImgPath = $this->_sPathImages . 'icon_fatalerror.gif'; break; case self::LEVEL_WARNING: $sHead = i18n('Warning'); $sHeadClass = 'alertbox_warning'; $sBgColor = $this->_aColors['notify_warning']; $sImgPath = $this->_sPathImages . 'icon_warning.gif'; break; case self::LEVEL_INFO: $sHead = i18n('Info'); $sHeadClass = 'alertbox_info'; $sMessage = '' . $sMessage . ''; $sBgColor = $this->_aColors['notify_info']; $sImgPath = $this->_sPathImages . 'but_ok.gif'; break; default: $sHead = i18n('Notification'); $sHeadClass = 'alertbox_notification'; $sMessage = '' . $sMessage . ''; $sBgColor = $this->_aColors['notify']; $sImgPath = $this->_sPathImages . 'but_ok.gif'; break; } if ($iStyle == 1) { // Box on login page $sMessageBox = '
' . '

' . $sHead . '

' . '
' . $sMessage . '
' . '
'; } else { // Simple box $sMessageBox = '
' . '

' . $sHead . '

' . '
' . $sMessage . '
' . '
'; } return $sMessageBox; } /** * Generates message box and returns it back, uses markup with table. * * @param string $sLevel Message level, one of Contenido_Notification::LEVEL_* constants * @param string $sMessage The message to display * @return string */ public function returnNotification($sLevel, $sMessage) { switch ($sLevel) { case self::LEVEL_ERROR: $sBgColor = $this->_aColors['notify_error']; $sImgPath = $this->_sPathImages . 'icon_fatalerror.gif'; break; case self::LEVEL_WARNING: $sBgColor = $this->_aColors['notify_warning']; $sImgPath = $this->_sPathImages . 'icon_warning.gif'; break; case self::LEVEL_INFO: $sMessage = '' . $sMessage . ''; $sBgColor = $this->_aColors['notify_info']; $sImgPath = $this->_sPathImages . 'but_ok.gif'; break; default: $sMessage = ''.$sMessage.''; $sBgColor = $this->_aColors['notify']; $sImgPath = $this->_sPathImages . 'but_ok.gif'; break; } $oTable = new Table($sBgColor, 'solid', 0, 2, '#FFFFFF', '#FFFFFF', '#FFFFFF', true, false); $sNoti = '
'; $sNoti .= $oTable->start_table(); $sNoti .= $oTable->header_row(); $sNoti .= $oTable->borderless_cell(''); $sNoti .= $oTable->borderless_cell( '' . $sMessage . '', 'left', 'middle' ); $sNoti .= $oTable->end_row(); $sNoti .= $oTable->end_table(); $sNoti .= '
'; return $sNoti; } /** * Displays small message box directly. * * @param string $sLevel Message level, one of Contenido_Notification::LEVEL_* constants * @param string $sMessage The message to display * @return void */ public function displayNotification($sLevel, $sMessage) { echo $this->returnNotification($sLevel, $sMessage) . '
'; } /** * Displays large message box directly. * * @param string $sLevel Message level, one of Contenido_Notification::LEVEL_* constants * @param string $sMessage The message to display * @param int $iStyle Flag tp use styles for display or not (feasible 1 or 0) * @return void */ public function displayMessageBox($sLevel, $sMessage, $iStyle = 1) { echo $this->messageBox($sLevel, $sMessage, $iStyle) . '
'; } } ?>