uses dos,crt,records,genstr,STRL,io,init;

var urec:userrec;
    uf:file of userrec;
    key,KEY2,key3:char;
    user:integer;
    x,y:longint;

procedure printxy(x,y:byte;s:string);
var a:byte;
begin
textattr:=14;
gotoxy(x,y);
for a:=1 to 19 do write(' ');
gotoxy(x,y);
write(padstring( copy(S,1,19),19));
end;

PROCEDURE UPDATEUSER;
BEGIN
SEEK(UF,USER-1);
WRITE(UF,UREC);
END;

FUNCTION CHANGEINT(X,Y:BYTE;S:LONGINT;V,LIM:BYTE):LONGINT;
VAR F:STRING;
BEGIN
F:=STRLONG(S);
EDSTR(F,X,Y,V,7,1,LIM);
CHANGEINT:=STRTOINT(F);
UPDATEUSER;
END;

FUNCTION CHANGESTR(X,Y:BYTE;S:STRING;V,LIM:bYTE):STRING;
VAR F:STRING;
BEGIN
F:=S;
EDSTR(F,X,Y,V,7,1,LIM);
CHANGESTR:=F;
UPDATEUSER;
END;

FUNCTION CHANGEYN(S:BOOLEAN):BOOLEAN;
BEGIN
IF S=TRUE THEN CHANGEYN:=FALSE ELSE
IF S=FALSE THEN CHANGEYN:=TRUE;
UPDATEUSER;
END;

function yesno(s:boolean):string;
begin
if s=true then yesno:='Yes' else yesno:='No ';
end;


procedure getinfo(x:longint);
begin
seek(uf,x-1);
read(uf,urec);
end;

procedure displayinfo;
begin
gotoxy(15,23);
textcolor(6);
textbackground(3);
write('User # '+strr(user)+'    ');
printxy(21,4,urec.alias);
printxy(21,5,urec.realname);
printxy(21,6,urec.phone);
printxy(21,7,urec.password);
printxy(21,8,strr(urec.mainlev));
printxy(21,9,strr(urec.filelev));
printxy(21,10,urec.flags);
printxy(21,11,urec.usernote);
printxy(21,12,urec.sysopnote);
printxy(21,13,yesno(urec.allowpage));
printxy(21,14,yesno(urec.userlog));
printxy(21,15,yesno(urec.loguser));
printxy(21,16,yesno(urec.xpermode));
printxy(21,17,yesno(urec.fse));
printxy(21,18,yesno(urec.ansi));

printxy(59,4,strr(urec.pcr));
printxy(59,5,strr(urec.udratio));
printxy(59,6,strr(urec.credits));
printxy(59,7,strr(urec.uploads));
printxy(59,8,strr(urec.downloads));
printxy(59,9,strr(urec.bytesup));
printxy(59,10,strr(urec.bytesdown));
printxy(59,11,strr(urec.posts));
printxy(59,12,strr(urec.calls));
printxy(59,13,strr(urec.callsperday));
printxy(59,14,strr(urec.lastcall));
printxy(59,15,strr(urec.timeperday));
printxy(59,16,strr(urec.time));
end;

Procedure delete_user(num:integer);
var i,ii:integer;
    g:integer;
begin
g:=user;
if FILESIZE(UF)<1 then begin
write('Sorry That User Does Not Exist! ');
exit;
end;

if (num<1) or (num>FILESIZE(UF)) then exit;

seek(UF,num-1);
read(uf,urec);
 I:=NUM;
 for ii:=i to FILESIZE(UF)-1 do begin
    seek (uf,ii);
    read (uf,urec);
    seek (uf,ii-1);
    write (uf,urec);
  end;
  seek (uf,FILESIZE(UF)-1);
  truncate (uf);
user:=1;
getinfo(user);
end;

begin
 user:=1;
 textattr:=14;clrscr;
 read_in_config;
 Assign(UF,config.data_dir+'USER.DAT');
 {$I-} Reset(UF); {$I+}
 if ioresult<>0 then begin
                     rewrite(uf);
                     reset(uf);
                     Fillchar(Urec,sizeof(urec),#0);
                     urec.alias:='New User';
                     urec.password:='New';
                     end;

displayadf('USEREDIT.ADF');
getinfo(user);
repeat
displayinfo;
key:=readkey;
showcursor;
case upcase(key) of
#0:BEGIN
   KEY2:=READKEY;
   CASE KEY2 OF
   #83:BEGIN
       GOTOXY(1,25);
       WRITE('Delete User? y/n ');
       key3:=readkey;
       gotoxy(1,25);
       clreol;
       case upcase(key3) of
       'Y':DELETE_USER(USER);
       END;
   END;
   #82:BEGIN
       SEEK(UF,FILESIZE(UF));
       Fillchar(Urec,sizeof(urec),#0);
       urec.alias:='New User';
       urec.password:='New';
       WRITE(UF,UREC);
       USER:=FILESIZE(UF)-1;
       inc(user);
       getinfo(user);

       END;
   END;
   END;
'[':begin; dec(user); if user=0 then user:=(filesize(uf));getinfo(user); end;
']':begin; inc(user); if user=filesize(uf)+1 then user:=1;getinfo(user); end;
'A':UREC.ALIAS   :=CHANGESTR(21,4,UREC.ALIAS,19,30);
'B':UREC.REALNAME:=CHANGESTR(21,5,UREC.REALNAME,19,30);
'C':UREC.PHONE   :=CHANGESTR(21,6,UREC.PHONE,12,12);
'D':UREC.PASSWORD:=CHANGESTR(21,7,UREC.PASSWORD,19,30);
'E':UREC.MAINLEV:=CHANGEINT(21,8,UREC.MAINLEV,5,5);
'F':UREC.FILELEV:=CHANGEINT(21,9,UREC.FILELEV,5,5);
'G':UREC.FLAGS:=CHANGESTR(21,10,UREC.FLAGS,19,26);
'H':UREC.USERNOTE:=CHANGESTR(21,11,UREC.USERNOTE,19,50);
'I':UREC.SYSOPNOTE:=CHANGESTR(21,12,UREC.SYSOPNOTE,19,50);
'J':UREC.ALLOWPAGE:=CHANGEYN(UREC.ALLOWPAGE);
'K':UREC.USERLOG:=CHANGEYN(UREC.USERLOG);
'L':UREC.LOGUSER:=CHANGEYN(UREC.LOGUSER);
'M':UREC.XPERMODE:=CHANGEYN(UREC.XPERMODE);
'N':UREC.FSE:=CHANGEYN(UREC.FSE);
'O':UREC.ANSI:=CHANGEYN(UREC.ANSI);
'P':UREC.PCR:=CHANGEINT(59,4,UREC.PCR,3,3);
'Q':UREC.UDRATIO:=CHANGEINT(59,5,UREC.UDRATIO,3,3);
'R':UREC.CREDITS:=CHANGEINT(59,6,UREC.CREDITS,7,7);
'S':UREC.UPLOADS:=CHANGEINT(59,7,UREC.UPLOADS,5,5);
'T':UREC.DOWNLOADS:=CHANGEINT(59,8,UREC.DOWNLOADS,5,5);
'U':UREC.BYTESUP:=CHANGEINT(59,9,UREC.BYTESUP,7,7);
'V':UREC.BYTESDOWN:=CHANGEINT(59,10,UREC.BYTESDOWN,7,7);
'W':UREC.POSTS:=CHANGEINT(59,11,UREC.POSTS,5,5);
'X':UREC.CALLS:=CHANGEINT(59,12,UREC.CALLS,5,5);
'Y':UREC.CALLSPERDAY:=CHANGEINT(59,13,UREC.CALLSPERDAY,5,5);
'Z':UREC.LASTCALL:=CHANGEINT(59,14,UREC.LASTCALL,7,7);
'1':UREC.TIMEPERDAY:=CHANGEINT(59,15,UREC.TIMEPERDAY,5,5);
'2':UREC.TIME:=CHANGEINT(59,16,UREC.TIME,5,5);
end;
CASE UPCASE(KEY) OF
'A'..'Z':UPDATEUSER;
'1'..'2':UPDATEUSER;
END;
hidecursor;
until key=#27;
TEXTMODE(3);
showcursor;
end.