****************************************************************
** USER.PRG - menu of employee functions - mail, memos, etc.
** J Osako    29 Jan 1996	'This code is cursed'
** Copyright 1996 The Used Computer Store, All Rights Reserved
****************************************************************

*PROCEDURE main
	
	PUBLIC now_what
	now_what = 'Read Mail'	&& initialize properly
	DEFINE WINDOW UserOpt FROM 1,1 TO 7,20 NONE
	MOVE WINDOW UserOpt CENTER
	
	IF !USED('uopts')
		USE uopts IN 10
	ENDIF
	SELECT uopts
	COPY TO ARRAY olist
	SELECT Slaves			&& set to user database

	DO WHILE now_what != 'Quit'
		ACTIVATE WINDOW UserOpt
		@0,0 GET now_what FROM olist
		READ
		DEACTIVATE WINDOW UserOpt	
		DO CASE
			CASE now_what = 'Quit'
				&& get back to loop, its over
			CASE now_what = 'Read Mail'
				DO mailreader
			CASE now_what = 'Send Mail'
				DO maileditor
			CASE now_what = 'Change Password'
				DO newpass
			CASE now_what = 'Change Username'
				DO newname
			OTHERWISE
				DO oops WITH 'User Options corrupted'
		ENDCASE
	ENDDO
RETURN


PROCEDURE mailreader

	ACTIVATE WINDOW S_O_L
	@3,3 SAY 'This option is'
	@4,3 SAY 'not ready yet.'
	WAIT
	DEACTIVATE WINDOW S_O_L
RETURN


PROCEDURE maileditor

	ACTIVATE WINDOW S_O_L
	@3,3 SAY 'This option is'
	@4,3 SAY 'not ready yet.'
	WAIT
	DEACTIVATE WINDOW S_O_L
RETURN

PROCEDURE newpass
	STORE NULL TO tpin, npin

	SELECT Slaves
	IF .F. 				&& dummy code for project mangler
		DO pin IN ucsys
	ENDIF
	ACTIVATE WINDOW Login	&& may as well reuse it...
	@1,1 SAY 'Old pswd: '
	tpin = pin() 
	IF tpin = passwd		
		@2,1 SAY 'New pswd: '
		M.passwd = pin()
		@3,1 SAY 'Confirm : '
		IF M.passwd = pin()
			GATHER MEMVAR FIELD passwd
		ELSE
			@4,1 SAY 'Change cancelled'
			WAIT
		ENDIF
	ENDIF
	DEACTIVATE WINDOW Login
RETURN	

PROCEDURE newname
	ACTIVATE WINDOW Login
	@2,3 SAY 'New Name :' GET nname;
		DEFAULT NULL
	READ
	DEACTIVATE WINDOW Login
	IF nname = NULL
		@ROW()+2,3 SAY 'Cancelled'
		WAIT
	ELSE
		nname = UPPER(nname)
		SELECT Slaves
		SCATTER MEMVAR FIELD logname
		SET ORDER TO luser
		GOTO TOP
		DO WHILE SEEK(nname)
			ACTIVATE WINDOW Login
			@1,1 SAY 'The login name ' + nname 
			@2,1 SAY 'is already used. Please'
			@3,1 SAY 'enter another :' 
			@4,1 GET nname
			READ
			nname = UPPER(nname)
			DEACTIVATE WINDOW Login
		ENDDO
		SEEK M.logname
		M.logname = nname
		GATHER MEMVAR FIELD logname
	ENDIF
RETURN