/****************************************************/
/* ModRule.spot                                     */
/* $VER: ModRule.spot 1.2 (27.10.94) ŠPer Jonsson   */
/*                                                  */
/*            Moderator/Rule Manager                */
/* This script adds the possibility to add/show the */
/* moderator/rules for a specific area.  The script */
/* is  easy to use and mostly self-explanatory.  To */
/* install  the script add it to the arexx menu and */
/* use one of the following options:                */
/*                                                  */
/*                                                  */
/* SAVEMOD  Add the writer of the current           */
/*          message as the moderator of this        */
/*          area.                                   */
/* MODREP   Makes a matrix reply to the moderator   */
/*          for the area.                           */
/* SHOWMOD  Shows the name and address of the       */
/*          moderator.                              */
/* SAVERULE Saves the current message as the rules  */
/*          for the area.                           */
/* SHOWRULE Shows the rules for an area.            */
/* HELP     This text.                              */
/*                                                  */
/* i.e.   in  the  string  gadget  asking  for  the */
/* filename write "<path>ModRule.spot SHOWRULE"     */
/*                                                  */
/* Or  you  can  just  skip the options and get the */
/* interactiver version.                            */
/*                                                  */
/* Sorry for my BAD english =)                      */
/*                                                  */
/* If you have any suggestions or bugreports please */
/* send it to me at the above address.              */
/****************************************************/

/****************************************************/
/* There are some variables that have to be changed */
/* to fit your system                               */
/****************************************************/
/* path -> The  path  to  the  directory  where the */
/*         datafiles  created by the script will be */
/*         stored (if the directory doesn't exsist  */
/*         it will be created).                     */
/****************************************************/

path='dh0:spot/rules'

/****************************************************/
/* viewer -> The path and the name to your favorite */
/*           text viewer                            */
/****************************************************/

viewer='c:lg'

/****************************************************/
/* pubscreenopt  -> The option your textviewer need */
/*                  to be opened on a public screen */
/*                  (don't forget to add the screen */
/*                  name).If your text viewer can't */
/*                  be  opened  on  a public screen */
/*                  tuff luck.                      */
/****************************************************/

pubscreenopt='PubScreen SPOT'

/*****************************************************/

parse arg opt


address SPOT
options results


CR='0d'x

if ~exists(path) then do
	address command 'makedir '||path
end
opt=upper(opt)
/* say opt */

mupp=0
ver='1.2'
select
	when opt="SAVEMOD" then CALL SAVEMOD
	when opt="MODREP" then CALL MODREP
	when opt="SAVERULE" then CALL SAVERULE
	when opt="SHOWRULE" then CALL SHOWRULE
	when opt="SHOWMOD" then CALL SHOWMOD
	when opt="HELP" then CALL HELP
	otherwise CALL WIN
end

EXIT

WIN:

	'requestresponse TITLE "Moderator/Rule Manager (ModRule v'||ver||')" PROMPT "Which module do you want to use?" GADGETS "_Moderator Manager|_Rule Manager|_Help|_Cancel" CENTER'
	select
		when RC=0 then exit
		when RC=1 then CALL MODMANAGER
		when RC=2 then CALL RULEMANAGER
		when RC=3 then CALL HELP
		otherwise 
	end
return


MODMANAGER:

	mupp=1
	'isarealist'
	if RC=0 then do
		'requestnotify TITLE "Module Manager v'||ver||'" PROMPT "When you are in the Area list'||CR||'you can only show the moderator'||CR||'for an area." CENTER'
		CALL SHOWMOD
	end
	else do
		'getfrom'
		name=RESULT
		txt='              What do you wanna do'||CR
		txt=txt||'Save  = Save '||name||' as the moderator for this area.'||CR
		txt=txt||'Reply = Make a matrix replay to the moderator for this area.'||CR
		txt=txt||'Show  = Show the name of the moderator for this area.'
		'requestresponse TITLE "Moderator Manager v'||ver||'" PROMPT "'||txt||'" GADGETS "_Save|_Reply|S_how|_Cancel"'
		select
			when RC=0 then EXIT
			when RC=1 then CALL SAVEMOD
			when RC=2 then CALL MODREP
			when RC=3 then CALL SHOWMOD
			otherwise
		end
	end
return

RULEMANAGER:

	'isarealist'
	if RC=0 then do
		'requestnotify TITLE "Rule Manager v'||ver||'" PROMPT "When you are in the Area list'||CR||'you can only show the rules'||CR||'for an area." CENTER'
		CALL SHOWRULE
	end
	else do
		txt='               What do you wanna do?'||CR
		txt=txt||'Save = Save the current message as the rules for this area.'||CR
		txt=txt||'Show = Show the rules for this area.'
		'requestresponse TITLE "Rule Manager v'||ver||'" PROMPT "'||txt||'" GADGETS "_Save|S_how|_Cancel"'
		select
			when RC=0 then EXIT
			when RC=1 then CALL SAVERULE
			when RC=2 then CALL SHOWRULE
			otherwise
		end
	end
return

SAVEMOD:

	'isarealist'
	if RC=0 then CALL NOTMESS
	'getareaname'
	area=RESULT
	CALL FIXLEN
	'getfrom'
	name=RESULT
	'getfromaddress'
	adr=RESULT

	'requestresponse TITLE "Save as moderator" PROMPT "Do you want to save '||name||' ('||adr||') as'||CR||'the moderator of this area('||areatot||')?" CENTER'
	if RC=5 then exit


	fname=path||'/'||area||'.moderator'
	if ~open(fil, fname, w) then do
		'requestnotify PROMPT "ERROR:'||CR||'Can`t create file." CENTER'
		exit
	end
	i=writeln(fil,name)
	i=writeln(fil,adr)

return



MODREP:

	'isarealist'
	if RC=0 then CALL NOTMESS

	'getareaname'
	area=RESULT
	CALL FIXLEN

	fname=path||'/'||area||'.moderator'
	if ~open(fi, fname, r) then CALL NOMOD
	else do
		name=readln(fi)
		adr=readln(fi)
	end
	RC=0

	'matrixreply TO "'name'" TOADDR "'adr'"'

return

SAVERULE:

	'isarealist'
	if RC=0 then CALL NOTMESS

	'getareaname'
	area=RESULT
	CALL FIXLEN

	fname=path||'/'||area||'.rule'
	'requestresponse TITLE "Save as rule" PROMPT "Do you want to save this message as'||CR||'rules for this area'||CR||'('||areatot||')?" CENTER'
	if RC=5 then exit

	'saveascii TO "'||fname||'" OVERWRITE NOHEADER NOTEARLINE NOORIGIN NOKLUDGES'

return

SHOWRULE:

	'isarealist'
	if RC=0 then CALL GETAREA
	else do
		'getareaname'
		area=RESULT
		CALL FIXLEN
	end

	fname=path||'/'||area||'.rule'
	if ~exists(fname) then CALL NORULE
	else do
		temp=viewer||' '||fname||' '||pubscreenopt
		address command temp
	end

return


SHOWMOD:

	'isarealist'
	if RC=0 then CALL GETAREA /* INMSGL */
	else do
		'getareaname'
		area=RESULT
		CALL FIXLEN
	end

	fname=path||'/'||area||'.moderator'
	if ~open(fi, fname, r) then CALL NOMODER
	name=readln(fi)
	adr=readln(fi)

	'requestnotify PROMPT "Moderator for this area is: '||name||CR||'                            '||adr||'"'

return

HELP:

Temp='Moderator/Rule Manager v'||ver||' ŠPer Jonsson 1994'||CR
temp=temp||'                            2:203/602.8@fidonet'||CR
temp=temp||'                            per@flerp.ct.se'||CR
temp=temp||'Usage:'||CR
temp=temp||'ShowMod.spot <option>'||CR
temp=temp||'             <option>=SAVEMOD  Add the writer of the current'||CR
temp=temp||'                               message as the moderator of this'||CR
temp=temp||'                               area.'||CR
temp=temp||'                      MODREP   Makes a matrix reply to the moderator'||CR
temp=temp||'                               of the area.'||CR
temp=temp||'                      SHOWMOD  Shows the name and address of the moderator'||CR
temp=temp||'                      SAVERULE Saves the current message as the rules'||CR
temp=temp||'                               for the area.'||CR
temp=temp||'                      SHOWRULE Shows the rules for an area.'||CR
temp=temp||'                      HELP     This text'||CR||CR
temp=temp||'Or if you skip the option then you get some requesters that guide you'||CR
temp=temp||'through the program.'

'requestnotify PROMPT "'||temp||'"'


return

FIXLEN:

	areatot=area
	if length(area)>19 then area=substr(area,length(area)-19)

return


GETAREA:

	'requestarea TITLE "Choose a message area"'
	if RC=5 then exti
	area=RESULT
	CALL FIXLEN
return




NOTMESS:

'requestnotify PROMPT "You must be in a message area'||CR||'or in a message list." CENTER'
exit
return

NOMODER:

'requestnotify PROMPT "I can`t find any moderator'||CR||'for this area ('||area||')" CENTER'
exit
return


NOMOD:

	'requestresponse TITLE "Problem" PROMPT "I can`t find any moderator for'||cr||'this area ('||areatot||')'||cr||cr||'Do you want to create one?" CENTER'
	if RC=5 then exit

	'requeststring TITLE "Moderator name" PROMPT "Write the name of the moderator of this area." CENTER'
	if RC=5 then exit
	Name=RESULT
	'requeststring TITLE "Moderator address" PROMPT "Write the address to the moderator." CENTER'
	if RC=5 then exit
	adr=RESULT

	if ~open(fil, fname, w) then do
		'requestnotify PROMPT "ERROR:'||CR||'Can`t create file." CENTER'
		exit
	end
	i=writeln(fil,name)
	i=writeln(fil,adr)

return

NORULE:

	'requestnotify PROMPT "I can`t find any rules for'||cr||'this area ('||areatot||')" CENTER'
	exit
return
