ONO::Lib::UI::MSG

package ONO::Lib::UI::MSG;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# 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.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################

#: Basic ONO UI system messages, the saving() function is used extensively
#: by most ONO modules and software.

use strict;

sub saving {

#: Display a green "saving" message box that will automatically fade
#: and disappear, no input required, language is optional

&system("","saving","f",$_[3],$_[1]);

}

sub success {

#: Display a green "success" message, text required.

&_message($_[1],"green", "actions/agt_action_success", $_[2], $_[3]);
}

sub system {

#: Display a green "system" message, text required, can be "saving",
#: "moving", or "deleting"

&_message($_[1],"green", "auto", $_[2], $_[3]);
}

sub info {

#: Display a yellow "info" message.

&_message($_[1],"yellow", "ono/help", $_[2], $_[3]);
}

sub warning {

#: Display a red "warning" message.

&_message($_[1],"red", "ono/delete", $_[2], $_[3]);

}

sub error {

#: Display a red "error" message.

&_message($_[1],"red", "ono/delete", $_[2], $_[3]);

}


sub _message {

#: Internal function used by some other message functions.

my $text = $_[0];
my $bgcolor = $_[1];
my $icon = $_[2];
my $switches = $_[3];
my $lang = $_[4];

if ($icon eq "auto") {
if ($text eq "saving") {
$icon = "actions/filesave";
$text = "Saving...";
if ($lang eq "de") {
$text = "Speichere...";
}
if ($lang eq "fr") {
$text = "Enrégistrer...";
}
if ($lang eq "lu") {
$text = "Späicheren...";
}
}
if ($text eq "moving") {
$bgcolor = "yellow";
$icon = "ono/help";
$text = "Moving...";
if ($lang eq "de") {
$text = "Bewege...";
}
if ($lang eq "fr") {
$text = "Bouger...";
}
if ($lang eq "lu") {
$text = "Bewegen...";
}
}
if ($text eq "deleting") {
$bgcolor = "red";
$icon = "ono/delete";
$text = "Deleting...";
if ($lang eq "de") {
$text = "Lösche...";
}
if ($lang eq "fr") {
$text = "Effacer...";
}
if ($lang eq "lu") {
$text = "Läschen...";
}
}
}

$text =~ s/\n/<\/b>/g;
my $valign;
if ($text =~ /<br>/i || $text =~ /button_/) {
$valign = qq~ class="vtop"~;
}

my $rand = int(rand(999999));
my $opts = "mb20";
my ($onload,$style);

if ($switches =~ /f/) {
$opts = "abs w33";
$onload = qq~<script>onojs_gui_fx_disappear('box_$rand','200');</script>~;
$style = qq~ style="z-index:999"~;
}

return qq~<div id="box_$rand" class="box_$bgcolor p2 $opts"$style>
<table class="wide_table">
<tr$valign>
<td class="p5">
<img class="block24" src="/ono/osr/images/icons/crystal/32x32/$icon.png" alt="">
</td>
<td class="p5 w100">$text</td>
</tr>
</table>
</div>
$onload
~;
}

###############################################################################
# end of script
###############################################################################

1;

__END__