Debian Codegraph @

lib/status.inc

raw
1 <?php
2 /*
3
4 This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
5 Copyright (C) 2003 - 2006 Michael Duergner
6 2011 - 2026 Roland Gruber
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 /**
24 * LDAP Account Manager status messages.
25 *
26 * @author Michael Duergner
27 * @package lib
28 */
29
30 /**
31 * This function prints a short status message. It can be used to print INFO,
32 * WARN and ERROR messages.
33 *
34 * @param string $MessageTyp The type of the message to be printed. It must be one of
35 * the following types: 'INFO', 'WARN' or 'ERROR'.
36 * <br> Every other type will lead to an error message indicating an invalid message type.
37 * @param string $MessageHeadline The headline of the status message.
38 * <br> It may be formatted with special color/link/bold tags.
39 * @param string $MessageText The text of the status message.
40 * <br> It may be formatted with special color/link/bold tags. This parameter is optional.
41 * @param string[]|string|null $MessageVariables The variables that are used to replace the spacers (%s) in the
42 * submitted text. This parameter is optional.
43 * @param bool $returnOutput if set to true this function will return the generated HTML code instead of printing it directly (default: false)
44 * @return string HTML code if $returnOutput is set to true, otherwise null
45 */
46 function StatusMessage($MessageTyp, $MessageHeadline, $MessageText = '', array|string|null $MessageVariables = [], bool $returnOutput = false): string {
47 /* Setting CSS-StyleSheet class depending on the $MessageTyp and rewriting $MessageTyp with a readable string. */
48 if ($MessageTyp == "INFO") {
49 $class = "class=\"statusInfo lam-status-message\"";
50 }
51 elseif ($MessageTyp == "WARN") {
52 $class = "class=\"statusWarn lam-status-message\"";
53 }
54 elseif ($MessageTyp == "ERROR") {
55 $class = "class=\"statusError lam-status-message\"";
56 }
57 /* Set output-message, when none or false $MessageTyp is submitted. */
58 else {
59 $class = "class=\"statusError lam-status-message\"";
60 $MessageHeadline = "Invalid/Missing Message type";
61 $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.";
62 }
63
64 $MessageHeadline = "<div class=\"statusTitle\">" . $MessageHeadline . "</div>"; // Format $MessageHeadline
65 if ($MessageText != '') {
66 $MessageText = "<p class=\"statusText\">" . $MessageText . "</p>"; // Format $MessageText
67 }
68 $format = "<div " . $class . ">\n<table>\n<tr>\n<td>" . $MessageHeadline . $MessageText . "</td>\n</tr>\n</table>\n</div>\n";
69 if (is_array($MessageVariables)) {
70 if ($MessageVariables !== []) {
71 array_unshift($MessageVariables, $format);
72 $output = call_user_func_array(sprintf(...), $MessageVariables);
73 }
74 else {
75 $output = $format;
76 }
77 }
78 elseif ($MessageVariables !== null) {
79 $output = sprintf($format, $MessageVariables);
80 }
81 else {
82 $output = $format;
83 }
84 if ($returnOutput) {
85 return $output;
86 }
87 else {
88 echo $output;
89 }
90 return '';
91 }