2003-05-04 09:00:14 +00:00
< ? php
/*
$Id $
This code is part of LDAP Account Manager ( http :// www . sourceforge . net / projects / lam )
Copyright ( C ) 2003 Michael Duergner
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
2004-10-30 16:46:06 +00:00
/**
* LDAP Account Manager status messages .
*
* @ author Michael D<EFBFBD> rgner
* @ version 0.5
* @ package lib
* @ copyright Copyright ( C ) 2003 - 2004 Michael D<EFBFBD> rgner
* @ license GPL
*/
/**
* This function prints a short status message . It can be used to print INFO ,
* WARN and ERROR messages at the moment .
*
* @ param string The type of the message to be printed . It must be one of
* the following types : 'INFO' , 'WARN' or 'ERROR' . Every other type will lead
* to an error message indicating an invalid message type .
* @ param string The headline of the status message .
* @ param string The text of the status message . It may be formatted with
* the syntax specified by the other functions in this file .
* @ param array The variables that are used to replace the spacers in the
* submitted text . This parameter is optional .
*/
2003-10-19 09:28:15 +00:00
function StatusMessage ( $MessageTyp , $MessageHeadline , $MessageText , $MessageVariables = array ()) {
2003-05-04 21:36:18 +00:00
/* Setting CSS-StyleSheet class depending on the $MessageTyp and rewriting $MessageTyp with a readable string. */
2003-10-18 11:26:49 +00:00
if ( $MessageTyp == " INFO " ) {
2003-08-16 17:30:20 +00:00
$class = " class= \" statusInfo \" " ;
2003-05-04 09:00:14 +00:00
}
2003-10-18 11:26:49 +00:00
elseif ( $MessageTyp == " WARN " ) {
2003-08-16 17:30:20 +00:00
$class = " class= \" statusWarn \" " ;
2003-05-04 09:00:14 +00:00
}
2003-10-18 11:26:49 +00:00
elseif ( $MessageTyp == " ERROR " ) {
2003-08-16 17:30:20 +00:00
$class = " class= \" statusError \" " ;
2003-05-04 09:00:14 +00:00
}
2003-05-04 21:36:18 +00:00
/* Set output-message, when none or false $MessageTyp is submitted. */
2003-10-18 11:26:49 +00:00
else {
2003-08-16 17:30:20 +00:00
$class = " class= \" statusError \" " ;
2003-10-29 19:19:00 +00:00
$MessageTyp = _ ( " LAM Internal Error " );
2003-08-16 17:30:20 +00:00
$MessageHeadline = _ ( " Invalid/Missing Message type " );
$MessageText = _ ( " Please report this error to the Bug-Tracker at { link=http://lam.sf.net}LDAP Account Manager Development Team { endlink}. The error number is { bold}0001:Invalid/Missing Message type. { endbold} Thank you. " );
2003-05-04 09:00:14 +00:00
}
2003-05-04 21:36:18 +00:00
$MessageHeadline = parseMessageString ( $MessageHeadline );
$MessageText = parseMessageString ( $MessageText );
2003-05-04 09:00:14 +00:00
2003-11-12 20:33:06 +00:00
if ( is_file ( " ../graphics/error.png " )) {
$MessageTyp = " <img src= \" ../graphics/ " . strtolower ( $MessageTyp ) . " .png \" alt= \" " . $MessageTyp . " \" width= \" 50 \" height= \" 50 \" > " ;
}
else {
$MessageTyp = " <img src= \" ../../graphics/ " . strtolower ( $MessageTyp ) . " .png \" alt= \" " . $MessageTyp . " \" width= \" 50 \" height= \" 50 \" > " ;
}
2003-10-18 11:26:49 +00:00
$MessageHeadline = " <h2 " . $class . " > " . $MessageHeadline . " </h2> " ; // Format $MessageHeadline
$MessageText = " <p " . $class . " > " . $MessageText . " </p> " ; // Format $MessageText
2004-09-08 14:39:47 +00:00
$format = " <div " . $class . " > \n <table> \n <tr> \n <td> " . $MessageTyp . " </td> \n <td> " . $MessageHeadline . $MessageText . " </td> \n </tr> \n </table> \n </div> \n " ;
2004-03-09 10:07:10 +00:00
if ( is_array ( $MessageVariables )) {
array_unshift ( $MessageVariables , $format );
call_user_func_array ( 'printf' , $MessageVariables );
}
else {
printf ( $format , $MessageVariables );
}
2003-05-04 09:00:14 +00:00
}
2004-10-30 16:46:06 +00:00
/**
* Use the three replace functions on the submitted Text .
*
* @ access private
*
* @ param string The text that is used to search for replaceable strings .
*
* @ return string The processed text .
*/
2003-10-18 11:26:49 +00:00
function parseMessageString ( $MessageString ) {
2003-05-07 18:21:19 +00:00
return linkText ( colorText ( boldText ( $MessageString )));
2003-05-04 09:00:14 +00:00
}
2004-10-30 16:46:06 +00:00
/**
* Replace { bold } and { endbold } with < b > and </ b > HTML - Tags .
*
* @ access private
*
* @ param string The text that is used to search for { bold } and { endbold } tags .
*
* @ return string The submitted text with { bold } and { endbold } replaced with
* the appropriate HTML tages < b > and </ b >
*/
2003-10-18 11:26:49 +00:00
function boldText ( $text ) {
2003-05-04 21:36:18 +00:00
$pattern = " / \ { bold \ }([^ { ]*) \ { endbold \ }/ " ; // Regular expression matching {bold}[Text]{endbold}
2003-10-18 11:26:49 +00:00
$replace = " <b class= \" status \" > \\ 1</b> " ; // Replace pattern
2003-05-07 18:21:19 +00:00
return preg_replace ( $pattern , $replace , $text );
2003-05-04 09:00:14 +00:00
}
2004-10-30 16:46:06 +00:00
/**
* Replace { color = #[HEX-Value]} or {color=[HEX-Value]} and {endcolor} with <font color="#[HEX-Value]"> and </font> HTML-Tags.
*
* @ access private
*
* @ param string
*
* @ return string
*/
2003-10-18 11:26:49 +00:00
function colorText ( $text ) {
2003-05-04 21:36:18 +00:00
$pattern = " / \ { color=#?([0-9,a-f,A-F] { 6}) \ }([^ { ]*) \ { endcolor \ }/ " ; // Regular expression matching {color=#[HEX-Value]}[Text]{endcolor} or {color=[HEX-Value]}[Text]{endcolor}
$replace = " <font color= \" # \\ 1 \" > \\ 2</font> " ; // Replace pattern
2003-05-07 18:21:19 +00:00
return preg_replace ( $pattern , $replace , $text );
2003-05-04 09:00:14 +00:00
}
2004-10-30 16:46:06 +00:00
/**
* Replace { link = [ Link - Target ]} and { endlink } with < a href = " [Link-Target] " target = " _blank " > and </ a > HTML - Tags .
*
* @ access private
*
* @ param string
*
* @ return string
*/
2003-10-18 11:26:49 +00:00
function linkText ( $text ) {
2003-05-04 21:36:18 +00:00
$pattern = " / \ { link=([^}]*) \ }([^ { ]*) \ { endlink \ }/ " ; // Regular expression matching {link=[Link-Target]}[Text]{endlink}
$replace = " <a href= \" \\ 1 \" target= \" _blank \" > \\ 2</a> " ; //Replace pattern
2003-05-07 18:21:19 +00:00
return preg_replace ( $pattern , $replace , $text );
2003-05-04 09:00:14 +00:00
}
2003-05-07 18:21:19 +00:00
?>