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

#
# List user's permissions
#
# Parameters (form or url): none
#
# History
#   2002/05/21 : pda/jean : design
#   2002/07/09 : pda      : add nologin
#   2003/05/13 : pda/jean : use auth base
#   2005/04/06 : pda      : add dhcp profiles
#   2010/12/10 : pda      : i18n
#   2010/12/25 : pda      : use cgi-dispatch
#

#
# Template pages used by this script
#

set conf(page)		profile.html

#
# Netmagis general library
#

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

# ::webapp::cgidebug ; exit

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

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

    #
    # Only admin users can show other logins
    #

    if {$tabuid(p_admin) && $login ne ""} then {
	set n [read-user $dbfd $login tablogin msg]
	if {$n != 1} then {
	    d error [mc "Login '%s' does not exist" $login]
	}
    } else {
	array set tablogin [array get tabuid]
    }

    #
    # Display user informations.
    #

    set user	[display-user tablogin]

    #
    # Display last logins
    #

    set lastlogin [display-last-connections $dbfd $tablogin(idcor)]

    #
    # Display group informations.
    #

    lassign [display-group $dbfd $tablogin(idgrp)] \
	tabperm \
	tabuser \
	tabnetworks \
	tabcidralone \
	tabviews \
	tabdomains \
	tabdhcpprofile \
	tabpermeq \
	tabl2only

    if {$tabcidralone eq ""} then {
	set titlecidralone ""
    } else {
	set titlecidralone [mc "Permissions not associated with any network"]
    }

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

    d result $conf(page) [list \
			    [list %CORRESP% $user] \
			    [list %LASTLOGIN% $lastlogin] \
			    [list %TABNETWORKS% $tabnetworks] \
			    [list %TITLECIDRALONE% $titlecidralone] \
			    [list %TABCIDRALONE% $tabcidralone] \
			    [list %TABDOMAINS% $tabdomains] \
			    [list %TABVIEWS% $tabviews] \
			    [list %TABDHCPPROFILE% $tabdhcpprofile] \
			    [list %TABPERMEQ% $tabpermeq] \
			    [list %TABL2ONLY% $tabl2only] \
			    ]
}

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

d cgi-dispatch "dns" ""
