ONO::Apps::Admin::Menu

package ONO::Apps::Admin::Menu;
################################################################################
# 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 ... #
################################################################################


use strict;

use ONO::ToolBox::Screen;

###############################################################################
# ONO
###############################################################################

use lib "../../ono/sys";

#: This module generates the front end application main menu and submenu.

sub menu {

my (
$self,
$lang,
$BLK_ref,
$vars_ref,
) = @_;

my %BLK = %$BLK_ref;
my %vars = %$vars_ref;

my ($MENU,$SUB,$SUB_PHONE);

my $SIZE = 90;

my @items = &menu_items("",$BLK_ref);

foreach my $item (@items) {
my @ip = split(/\:/,$item);
if (!$BLK{$ip[2]}) {
$BLK{$ip[2]} = $ip[2];
}

my $class = "col3";
my $sel;
if (($vars{'mode'} && $ip[0] && $vars{'mode'} =~ /^$ip[0]/) || ((!$vars{'mode'} || $vars{'mode'} eq "info" || $vars{'mode'} =~ /^info_/) && !$ip[0])) {
$class = "cole";
$sel .= qq~;background:#444444~;
}

my $LINK = qq~/ono/admin/~;
if ($ip[0]) {
$LINK = qq~/ono/admin/?/$ip[0]/~;
}

$MENU .= ONO::ToolBox::Screen->menu($LINK,$ip[1],$BLK{$ip[2]},$class,$sel);

}

my @items = &menu_subs("","info",$BLK_ref);

if ($vars{'mode'} eq "web" || $vars{'mode'} =~ /^web_/) {
@items = &menu_subs("","web",$BLK_ref);
}

if ($vars{'mode'} eq "users" || $vars{'mode'} =~ /^users_/) {
@items = &menu_subs("","users",$BLK_ref);
}

if ($vars{'mode'} eq "db" || $vars{'mode'} =~ /^db_/) {
@items = &menu_subs("","db",$BLK_ref);
if ($vars{'mode'} !~ /^db_(sql)/ && $vars{'base'}) {
@items = &menu_subs("","db_base",$BLK_ref);;
}
}

if ($vars{'mode'} eq "network" || $vars{'mode'} =~ /^network_/) {
@items = &menu_subs("","network",$BLK_ref);
}

if ($vars{'mode'} eq "tools" || $vars{'mode'} =~ /^tools_/) {
@items = &menu_subs("","tools",$BLK_ref);
}

if ($vars{'mode'} eq "setup" || $vars{'mode'} =~ /^setup_/) {
@items = &menu_subs("","setup",$BLK_ref);
}

foreach my $item (@items) {

my @ip = split(/\:/,$item);

if (!$BLK{$ip[1]}) {
$BLK{$ip[1]} = $ip[1];
}

my $section = "info";
if ($vars{'mode'}) {
$section = $vars{'mode'};
$section =~ s~_(.*)$~~;
}

my ($sel,$sel2);
my $col = "cole";
if (($vars{'mode'} && ($vars{'mode'} eq "$section\_$ip[0]" || $vars{'mode'} =~ /^$section\_$ip[0]\_/)) || (!$ip[0] && $vars{'mode'} eq $section) || (!$vars{'mode'} && !$ip[0])) {
$sel = ";background-color:#ffffff";
$sel2 = " bg_paper";
$col = "col6";
}

my $LINK = qq~/ono/admin/?/$section/~;
if ($ip[0]) {
$LINK = qq~/ono/admin/?/$section\_$ip[0]/~;
}

if ($ENV{'HTTP_USER_AGENT'} !~ /phone/i || $sel) {

$SUB .= ONO::ToolBox::Screen->submenu($LINK,"",$BLK{$ip[1]},$col,$sel);

}

$SUB_PHONE .= qq~<div class="p10 bb bl br $col$sel2" style="padding:13px 00px 14px 30px" onclick="window.location='$LINK';">$BLK{$ip[1]}</div>~;

}

return ONO::ToolBox::Screen->menu_pack($MENU,$SUB,$SUB_PHONE,$SIZE);

}

sub menu_items {

my $BLK_ref = $_[1];
my %BLK = %$BLK_ref;

my @items = (
':filesystems/folder_home:Dashboard',
'web:filesystems/network:Web',
'users:kdm/group:Users',
'db:filesystems/database:Databases',
"network:devices/fileshare:$BLK{'Network'} & $BLK{'Servers'}",
'tools:apps/kgoldrunner:Tools',
'setup:actions/configure:Setup',
);

return @items;

}

sub menu_subs {

my $type = $_[1];
my $BLK_ref = $_[2];
my %BLK = %$BLK_ref;

my @items = (
':Info',
'system:System',
'statistics:Usage & Statistics',
'security:Security & Firewall',
'logfiles:Logfiles & Monitoring',
);

if ($type eq "web") {
@items = (
":Overview",
"platforms:Platforms",
);
}

if ($type eq "users") {
@items = (
":$BLK{'Users'} & $BLK{'Profiles'}",
'mail:E-Mail',
);
}

if ($type eq "db" || $type eq "db_base") {
@items = (
':Databases',
);

# db_base means that a database has been selected

if ($type eq "db" || $type eq "db_base") {
@items = (
':Databases',
);
}
}

if ($type eq "network") {
@items = (
':Overview',
"cloud:Cloud",
"fileserver:File Server",
"mediaserver:Media Server",
"network:$BLK{'Network'}",
"devices:Devices",
"servers:$BLK{'Servers'} & Disks",
"monitor:Monitoring",
);
}

if ($type eq "tools") {
@items = (
':Overview',
'automation:Automation',
'keymanager:Key Manager',
'server:Server Management',
);
}

if ($type eq "setup") {
@items = (
':Overview',
'sql:SQL Connection',
"features:$BLK{'Enable'} / $BLK{'Disable'} Screens & Features",
'security:Security',
);
}

return @items;

}

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

1;

__END__