ONO::ToolBox::Init

package ONO::ToolBox::Init;
################################################################################
# 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::Lib::Lang::BLK;
use ONO::Lib::SQL::Quote;

use ONO::ToolBox::Auth;
use ONO::ToolBox::DomainLang;
use ONO::ToolBox::Input;

use ONO::Lib::Lang::LangKitEdu;

###############################################################################
# DEFAUT SCRIPT HEADER
###############################################################################

sub header {

#: This will set up all basic variables required for your own software
#: platforms, at the same time it handles basic user authentication,
#: including a sudo feature for admins.
#:
#: This requires a database connection as well as the name of the running
#: community / platform as input, with optional switches.
#:
#: To enable the sudo feature, a list with allowed sudoers must be
#: transmitted too.
#:
#: Available switches:
#:
#: -E use educational BLK langkit

my (
$self,
$db,
$community,
$switches,
$sudos,
) = @_;

my $lang = ONO::ToolBox::DomainLang->get;
my ($vars_ref,%vars) = ONO::ToolBox::Input->get("","",$lang);

my $BLK_ref;

if ($switches =~ /E/) {

($BLK_ref) = ONO::Lib::Lang::LangKitEdu->get($lang,$vars_ref);

} else {

($BLK_ref) = ONO::Lib::Lang::BLK->get($lang,$vars_ref);

}

if ($db && $community && $vars{'mode'} !~ /^(login|signup|enable|password|checkout_login|checkout_password)$/ && $vars{'store_action'} !~ /^(login|password)$/) {
$vars_ref = ONO::ToolBox::Auth->auth($db,$community,\%vars);
%vars = %$vars_ref;
if ($vars{'username'} && $sudos =~ /:$vars{'username'}:/) {
$vars_ref = ONO::ToolBox::Auth->sudo($community,\%vars);
%vars = %$vars_ref;
}
}

my $sql_ref = ONO::Lib::SQL::Quote->vars(\%vars);

return (\%vars,$sql_ref,$lang,$BLK_ref);

}

###############################################################################
# CREATE LOGIN PAGE
###############################################################################

sub exec {

# deprecated

}

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

1;

__END__