#!/usr/local/bin/tclsh8.6

#
# Display general Netmagis starting page
#
# Parameters (form or url): none
#
# History
#   2002/06/03 : pda      : design
#   2002/07/09 : pda      : add nologin
#   2003/05/13 : pda/jean : use auth base
#   2010/12/06 : pda      : i18n
#   2010/12/25 : pda      : use cgi-dispatch
#   2015/04/01 : pda/jean : rename index to start
#

#
# Template pages used by this script
#

set conf(page)		start.html

#
# Netmagis general library
#

source /usr/local/lib/netmagis/libnetmagis.tcl

# ::webapp::cgidebug ; exit

##############################################################################
# Display start page
##############################################################################

d cgi-register {} {
    {lastlogin	0 1}
} {
    global conf

    #
    # Display lastlogin information?
    #
    
    if {$lastlogin eq ""} then {
	set llmsg ""
    } else {
	set llmsg [mc "Last login: no information"]
	set sql "SELECT start, ip FROM global.wtmp
	    		WHERE idcor = $tabuid(idcor)
			ORDER BY start DESC
			LIMIT 1"
	pg_select $dbfd $sql tab {
	    set llmsg [mc {Last login: %1$s from %2$s} $tab(start) $tab(ip)]
	}
    }

    #
    # URL and substitution list building
    #

    foreach script {net add mod del profile mail web dhcp search} {
	set up [string toupper $script]
	d urlset "%URL$up%" "$script" {}
    }
    d urlset "%URLWHERE%" "search" [list [list "q" "_"]]

    #
    # End of script: output page and close database
    #

    d result $conf(page) [list \
    				[list %LASTLOGIN% $llmsg] \
			    ]
}

##############################################################################
# Main procedure
##############################################################################

d cgi-dispatch "dns" ""
