#!/bin/sh
#
# sellermenu.sh - menu for salespersons
#

# these get set at install time

ISPUTIL="/var/lib/ISPutil"
BBSUTIL="/var/lib/BBSutil"
HOSTNAME=`hostname`
DNSDOMAINNAME=`dnsdomainname`
EDITOR="/usr/bin/pico -t"
VISUAL="$EDITOR"
QUOTA="/usr/bin/quota"
REPQUOTA="/usr/sbin/repquota"
CHAT="/usr/local/bin/vchat -s peak"
SUPER="/usr/bin/super"
PASSWD=/usr/bin/passwd
MODEMHOST="god"
AWK="/usr/bin/awk"

# defines not at left margin dont get set by the install script
 TITLE="$HOSTNAME.$DNSDOMAINNAME Sales Rep"

ureports()
{
RDONE=
while [ -z $RDONE ]; do
	reset
	dialog --title " $TITLE" \
		--menu "Reports and Lists" 13 40 7 \
	"BACK"   "Back out of menu" \
        "DISK"   "Disk quotas" \
        "FIRST"  "Users by firstname" \
	"IDNUM"  "Users by UID number" \
        "NEW"    "New (unvalidated) users" \
        "ONLINE" "Online users" \
        "UNAME"  "Users by username" \
        "X=EXIT" "Exit Menu" 2> /tmp/slmenu.tmp.$$
        if [ $? = 1 -o $? = 255 ]; then
                /bin/rm -f /tmp/slmenu.tmp.$$
                exit
        fi
        rchoice=`cat /tmp/slmenu.tmp.$$`
        /bin/rm -f /tmp/slmenu.tmp.$$

        if [ "$rchoice" = "BACK" ]; then
        RDONE=DONE
        fi
        if [ "$rchoice" = "DISK" ]; then
        /usr/sbin/repquota -a >/tmp/slmenu.tmp.$$
        dialog --title "User disk quotas" \
        --textbox /tmp/slmenu.tmp.$$ 18 76
        /bin/rm -f /tmp/slmenu.tmp.$$
        fi
        if [ "$rchoice" = "FIRST" ]; then
	cat /etc/passwd | sort -fdbit ":" +4 \
		| $AWK -f $ISPUTIL/util/rusrlist.awk > /tmp/slmenu.tmp.$$
	dialog --title "${HOSTNAME}'s Users" \
	--textbox /tmp/slmenu.tmp.$$ 20 72 
	/bin/rm -f /tmp/slmenu.tmp.$$  
        fi
        if [ "$rchoice" = "IDNUM" ]; then
	cat /etc/passwd | sort -rfndbit ":" +2 \
		| $AWK -f $ISPUTIL/util/rusrlist.awk > /tmp/slmenu.tmp.$$
	dialog --title "${HOSTNAME}'s Users" \
	--textbox /tmp/slmenu.tmp.$$ 20 72 
	/bin/rm -f /tmp/slmenu.tmp..$$     
        fi
        if [ "$rchoice" = "NEW" ]; then
	cat /etc/passwd | sort -fndbit ":" +2 \
		| $AWK -f $ISPUTIL/util/nusrlist.awk > /tmp/slmenu.tmp.$$
	dialog --title "${HOSTNAME}: Unvalidated Users" \
	--textbox /tmp/slmenu.tmp.$$ 20 72 
	/bin/rm -f /tmp/slmenu.tmp.$$
        fi
	if [ "$rchoice" = "ONLINE" ]; then
	/usr/bin/finger @$MODEMHOST > /tmp/slmenu.tmp.$$
        dialog --title "Users Online" \
        --textbox /tmp/slmenu.tmp.$$ 18 76
        /bin/rm -f /tmp/slmenu.tmp.$$
        fi
        if [ "$rchoice" = "UNAME" ]; then
	cat /etc/passwd | sort -fdbit ":" \
		| $AWK -f $ISPUTIL/util/rusrlist.awk > /tmp/slmenu.tmp.$$
	dialog --title "${HOSTNAME}'s Users" \
	--textbox /tmp/slmenu.tmp.$$ 20 72 
	/bin/rm -f /tmp/slmenu.tmp.$$      
        fi
        if [ "$rchoice" = "X=EXIT" ]; then
        RDONE=DONE
        fi
done
}


tsale()
{
TDONE=
while [ -z $TDONE ]; do
    reset
    dialog --title " $TITLE" \
    --menu "Online Hours Sale" 10 50 4 \
    "BACK"   "Back out of menu" \
    "1"      "1 block of 15 hours" \
    "2"    "2 blocks of 15 hours" \
    "3"    "3 blocks of 15 hours" \
    "X=EXIT" "Exit this menu" 2> /tmp/slmenu.tmp.$$
    if [ $? = 1 -o $? = 255 ]; then
            /bin/rm -f /tmp/slmenu.tmp.$$
            exit
    fi
    mchoice=`cat /tmp/slmenu.tmp.$$`
    /bin/rm -f /tmp/slmenu.tmp.$$

    if [ "$mchoice" = "BACK" ]; then
    TDONE=DONE
    fi
    if [ "$mchoice" = "1" ]; then
    $SUPER selltime.sh
    fi
    if [ "$mchoice" = "2" ]; then
    $SUPER selltime2.sh
    fi
    if [ "$mchoice" = "3" ]; then
    $SUPER selltime3.sh
    fi
    if [ "$mchoice" = "X=EXIT" ]; then
    TDONE=DONE
    fi
done
}


msale()
{
MSDONE=
while [ -z $MSDONE ]; do
    reset
    dialog --title " $TITLE" \
    --menu "Sell Months of Access" 10 55 4 \
    "BACK"   "Back out of menu" \
    "1"      "1 month internet access" \
    "2"    "2 months internet access" \
    "3"    "3 months internet access" \
    "X=EXIT" "Exit this menu" 2> /tmp/slmenu.tmp.$$
    if [ $? = 1 -o $? = 255 ]; then
            /bin/rm -f /tmp/slmenu.tmp.$$
            exit
    fi
    mchoice=`cat /tmp/slmenu.tmp.$$`
    /bin/rm -f /tmp/slmenu.tmp.$$

    if [ "$mchoice" = "BACK" ]; then
    MSDONE=DONE
    fi
    if [ "$mchoice" = "1" ]; then
    $SUPER sellmonth.sh
    fi
    if [ "$mchoice" = "2" ]; then
    $SUPER sellmonth2.sh
    fi
    if [ "$mchoice" = "3" ]; then
    $SUPER sellmonth3.sh
    fi
    if [ "$mchoice" = "X=EXIT" ]; then
    MSDONE=DONE
    fi
done
}


modify()
{
MDONE=
while [ -z $MDONE ]; do
    reset
    if [ "$DISPLAY" = "" ]; then
        dialog --title " $TITLE" \
        --menu "User Administration" 13 50 7 \
	"BACK"   "Back out of menu" \
	"HOURS"  "Hours sale" \
        "LISTS"  "Lists and Reports" \
	"MONTHS" "Months sale" \
        "NEW"    "New user account" \
	"PPP"    "PPP account" \
	"SLIP"   "SLIP account" \
        "X=EXIT" "Exit this menu" 2> /tmp/slmenu.tmp.$$
    else
        dialog --title " $TITLE" \
        --menu "User Administration" 14 50 8 \
	"BACK"   "Back out of menu" \
        "DB"     "Database" \
	"HOURS"  "Hours sale" \
        "LISTS"  "Lists and Reports" \
	"MONTHS" "Months sale" \
        "NEW"    "New user account" \
	"PPP"    "PPP account" \
	"SLIP"   "SLIP account" \
        "X=EXIT" "Exit this menu" 2> /tmp/slmenu.tmp.$$
    fi
    if [ $? = 1 -o $? = 255 ]; then
            /bin/rm -f /tmp/slmenu.tmp.$$
            exit
    fi
    mchoice=`cat /tmp/slmenu.tmp.$$`
    /bin/rm -f /tmp/slmenu.tmp.$$

    if [ "$mchoice" = "BACK" ]; then
    MDONE=DONE
    fi
    if [ "$DISPLAY" != "" ]; then
        if [ "$mchoice" = "DB" ]; then
        $SUPER launch clients
        fi
    fi
    if [ "$mchoice" = "HOURS" ]; then
    tsale
    fi
    if [ "$mchoice" = "LISTS" ]; then
    ureports
    fi
    if [ "$mchoice" = "MONTHS" ]; then
    msale
    fi
    if [ "$mchoice" = "NEW" ]; then
    $SUPER user_new
    fi
    if [ "$mchoice" = "PPP" ]; then
    $SUPER makeppp.sh
    fi
    if [ "$mchoice" = "SLIP" ]; then
    $SUPER makeslip.sh
    fi
    if [ "$mchoice" = "X=EXIT" ]; then
    MDONE=DONE
    fi
done
}


while [ "$DONE" = "" ]; do
	reset
	dialog --title " $TITLE " \
	--menu   "MAIN MENU" 14 40 8 \
	"BACK"   "Back out of menu" \
	"CHAT"	 "Online Chat" \
	"HELP"	 "Write for help" \
	"ONLINE" "See who is online" \
	"PPP"	 "Change account to PPP" \
	"SLIP"	 "Change account to SLIP" \
	"PASSWD" "Change login password" \
	"USERS"	 "User administration" \
	"X=EXIT" "Exit this menu" 2> /tmp/slmenu.tmp.$$
	if [ $? = 1 -o $? = 255 ]; then
		/bin/rm /tmp/slmenu.tmp.$$
		exit
	fi
	choice=`cat /tmp/slmenu.tmp.$$`
	/bin/rm -f /tmp/slmenu.tmp.$$

        if [ "$choice" = "BACK" ]; then
        DONE=DONE
        fi
        if [ "$choice" = "CHAT" ]; then
        $CHAT
        fi
        if [ "$choice" = "PPP" ]; then
        $SUPER ch2ppp.sh
        fi
        if [ "$choice" = "SLIP" ]; then
        $SUPER ch2slip.sh
        fi
        if [ "$choice" = "DISK" ]; then
        $QUOTA -v >/tmp/usradmin.tmp.$$
        dialog --title "Disk Quotas" \
        --textbox /tmp/usradmin.tmp.$$ 18 76
        /bin/rm -f /tmp/usradmin.tmp.$$
        fi
	if [ "$choice" = "ONLINE" ]; then
	/usr/bin/finger @dialup1 > /tmp/usradmin.tmp.$$
        dialog --title "Users Online" \
        --textbox /tmp/usradmin.tmp.$$ 18 76
        /bin/rm -f /tmp/usradmin.tmp.$$
        fi
        if [ "$choice" = "PASSWD" ]; then
        $PASSWD
        fi
        if [ "$choice" = "USERS" ]; then
        modify
        fi
        if [ "$choice" = "EXIT" ]; then
        DONE=DONE
        fi
done
