LDAPAccountManager/lam/lib/status.inc

168 lines
6.4 KiB
PHP
Raw Permalink Normal View History

<?php
/*
$Id$
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
2006-03-03 17:30:35 +00:00
Copyright (C) 2003 - 2006 Michael Duergner
2013-04-28 18:45:35 +00:00
2011 - 2013 Roland Gruber
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.
2015-08-02 19:16:30 +00:00
*
2006-07-26 19:35:33 +00:00
* @author Michael Duergner
2004-10-30 16:46:06 +00:00
* @package lib
*/
/**
* This function prints a short status message. It can be used to print INFO,
* WARN and ERROR messages at the moment.
2005-07-20 10:04:07 +00:00
*
* The headline and text may be formated with special tags:
* <br>
* <br><b>{bold}, {endbold}:</b> All text between these tags is printed bold.
* <br><b>{color=#123456}, {endcolor}:</b> All text between these tags is printed in the given color.
* <br><b>{link=http://nodomain.org}, {endlink}:</b> A link with the given target is created. The link text is the text between the tags.
2015-08-02 19:16:30 +00:00
*
2005-07-20 10:04:07 +00:00
* @param string $MessageTyp The type of the message to be printed. It must be one of
* the following types: 'INFO', 'WARN' or 'ERROR'.
* <br> Every other type will lead to an error message indicating an invalid message type.
* @param string $MessageHeadline The headline of the status message.
2015-08-02 19:16:30 +00:00
* <br> It may be formatted with special color/link/bold tags.
2005-07-20 10:04:07 +00:00
* @param string $MessageText The text of the status message.
* <br> It may be formatted with special color/link/bold tags. This parameter is optional.
2005-07-20 10:04:07 +00:00
* @param array $MessageVariables The variables that are used to replace the spacers (%s) in the
2004-10-30 16:46:06 +00:00
* submitted text. This parameter is optional.
* @param boolean $returnOutput if set to true this function will return the generated HTML code instead of printing it directly (default: false)
* @return String HTML code if $returnOutput is set to true, otherwise null
2004-10-30 16:46:06 +00:00
*/
function StatusMessage($MessageTyp,$MessageHeadline,$MessageText='',$MessageVariables = array(), $returnOutput = false) {
/* 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") {
2010-10-16 12:39:56 +00:00
$class = "class=\"statusInfo ui-corner-all\"";
}
2003-10-18 11:26:49 +00:00
elseif($MessageTyp == "WARN") {
2010-10-16 12:39:56 +00:00
$class = "class=\"statusWarn ui-corner-all\"";
}
2003-10-18 11:26:49 +00:00
elseif($MessageTyp == "ERROR") {
2010-10-16 12:39:56 +00:00
$class = "class=\"statusError ui-corner-all\"";
}
/* Set output-message, when none or false $MessageTyp is submitted. */
2003-10-18 11:26:49 +00:00
else {
2010-10-16 12:39:56 +00:00
$class = "class=\"statusError ui-corner-all\"";
2006-01-07 11:07:45 +00:00
$MessageTyp = "ERROR";
2006-07-26 19:35:33 +00:00
$MessageHeadline = "Invalid/Missing Message type";
2009-08-10 16:13:27 +00:00
$MessageText = "Please report this error to the Bug-Tracker at {link=http://www.ldap-account-manager.org/}LDAP Account Manager Development Team{endlink}. Thank you.";
}
$MessageHeadline = parseMessageString($MessageHeadline);
$MessageText = parseMessageString($MessageText);
2003-11-12 20:33:06 +00:00
if (is_file("../graphics/error.png")) {
2015-08-02 19:16:30 +00:00
$MessageTyp = "<img class=\"margin5\" src=\"../graphics/" . strtolower($MessageTyp) . ".png\" alt=\"" . $MessageTyp . "\" width=\"24\" height=\"24\">";
2003-11-12 20:33:06 +00:00
}
else {
2015-08-02 19:16:30 +00:00
$MessageTyp = "<img class=\"margin5\" src=\"../../graphics/" . strtolower($MessageTyp) . ".png\" alt=\"" . $MessageTyp . "\" width=\"24\" height=\"24\">";
2003-11-12 20:33:06 +00:00
}
2013-04-28 18:45:35 +00:00
$MessageHeadline = "<div class=\"statusTitle\">" . $MessageHeadline . "</div>"; // Format $MessageHeadline
if ($MessageText != '') {
$MessageText = "<p class=\"statusText\">" . $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";
$output = '';
if (is_array($MessageVariables)) {
2005-05-06 13:15:27 +00:00
if (sizeof($MessageVariables) > 0) {
array_unshift($MessageVariables, $format);
$output = call_user_func_array('sprintf',$MessageVariables);
2005-05-06 13:15:27 +00:00
}
else {
$output = $format;
2005-05-06 13:15:27 +00:00
}
}
else {
$output = sprintf($format, $MessageVariables);
}
if ($returnOutput) {
return $output;
}
else {
echo $output;
}
return null;
}
2004-10-30 16:46:06 +00:00
/**
* Use the three replace functions on the submitted Text.
2015-08-02 19:16:30 +00:00
*
2004-10-30 16:46:06 +00:00
* @access private
2015-08-02 19:16:30 +00:00
*
2005-07-20 10:04:07 +00:00
* @param string $MessageString The text that is used to search for replaceable strings.
2015-08-02 19:16:30 +00:00
*
2004-10-30 16:46:06 +00:00
* @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)));
}
2004-10-30 16:46:06 +00:00
/**
* Replace {bold} and {endbold} with <b> and </b> HTML-Tags.
2015-08-02 19:16:30 +00:00
*
2004-10-30 16:46:06 +00:00
* @access private
2015-08-02 19:16:30 +00:00
*
2005-07-20 10:04:07 +00:00
* @param string $text The text that is used to search for {bold} and {endbold} tags.
2015-08-02 19:16:30 +00:00
*
2004-10-30 16:46:06 +00:00
* @return string The submitted text with {bold} and {endbold} replaced with
2015-08-02 19:16:30 +00:00
* the appropriate HTML tages <b> and </b>
2004-10-30 16:46:06 +00:00
*/
2003-10-18 11:26:49 +00:00
function boldText($text) {
2007-12-28 16:08:04 +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);
}
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.
2015-08-02 19:16:30 +00:00
*
2004-10-30 16:46:06 +00:00
* @access private
2015-08-02 19:16:30 +00:00
*
2005-07-20 10:04:07 +00:00
* @param string $text The text that is used to search for {color} and {endcolor} tags.
2015-08-02 19:16:30 +00:00
*
2005-07-20 10:04:07 +00:00
* @return string Input string with HTML-formatted color tags
2004-10-30 16:46:06 +00:00
*/
2003-10-18 11:26:49 +00:00
function colorText($text) {
2007-12-28 16:08:04 +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);
}
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.
2015-08-02 19:16:30 +00:00
*
2004-10-30 16:46:06 +00:00
* @access private
2015-08-02 19:16:30 +00:00
*
2005-07-20 10:04:07 +00:00
* @param string $text The text that is used to search for {link} and {endlink} tags.
2015-08-02 19:16:30 +00:00
*
2005-07-20 10:04:07 +00:00
* @return string Input string with HTML-formatted link tags
2004-10-30 16:46:06 +00:00
*/
2003-10-18 11:26:49 +00:00
function linkText($text) {
2007-12-28 16:08:04 +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-07 18:21:19 +00:00
?>