/* mdb.trans (c) '94 by Georg 'Gio' Magschok                                 */
/*                                                                           */
/* $VER: mdb.trans 1.0ger (4.6.94)
                                                                             */
/* an ARexx-script for TransAmiga BBS V 1.10 and later to access             */
/* MovieMUI V3.0 and later written by Andre 'ABernie' Bernhardt              */

options results

/* get information from TransAmiga */

USERINFO 1 ; xpert=upper(RESULT)
USERINFO a ; uname=RESULT
SYSTEMINFO 8 ; bbsline=RESULT

menuname ='mdbmenu'             /* the name of the main menu                 */
selmenu  ='mdbselmenu'          /* the name of the selection menu            */
mmui ='run MovieMUI errorfile errorlevel=0 debuglevel=0 quiet'    /* how to start MovieMUI               */
autoquit =0                               /* specify 1 to QUIT MovieMUI after use,0 to */
                                          /* hold MovieMUI running in the background   */
tempfile ='t:mdbtratemp.'||bbsline        /* temporary file for viewing                */

/* look if MovieMUI is around, and launch it if necessary                    */

if (~show('p','MOVIEMUI')) then do
 transmit 'MovieMUI wird gestartet...'
 address command mmui
 address command 'waitforport MOVIEMUI'
end
transmit '0c'x

/* say uname||'hat mdb.trans probiert um'||time() */

do until cmd='+'
 if xpert='NOVICE' then sendmenu menuname
 systeminfo m ; time=result
 getcmd '[Time: '||time||'] [MDB - Commands: M A S I ? + ] ' ; cmd=upper(result)
 if cmd='###PANIC' then call stopit
 select
  when (cmd='?' | cmd='') then sendmenu menuname
  when cmd='+' then transmit
  when cmd=''  then transmit
  when cmd='RESULT' then transmit
  when cmd='M' then call moviesearch
  when cmd='A' then call personsearch
  when cmd='S' then call selectivesearch
  when cmd='I' then call infor
  otherwise do
    transmit
    transmit "Dieser Befehl ist hier unbekannt, versuch's mal mit "||'"?"!'
    transmit
    if xpert='NOVICE' THEN CONTINUE
  end
 end
end

stopit:
if autoquit=1 then address 'MOVIEMUI' 'QUIT'
shutdown
exit

moviesearch:
 transmit
 query 'Nach welchem Film suchen? ' ; movie=result
 if movie~='RESULT' & movie~='' & movie~='###PANIC' then do
  transmit "MovieDataBase wird nach '"||movie||"' durchsucht..."
  address 'MOVIEMUI' 'GET "'||movie||'" FROM MOVIE' ; mytext=result
  if mytext='RESULT' | RC~=0 then do
   transmit "Der Film wurde nicht gefunden! Probier' es mal mit"
   transmit "selektiver Suche!"
  end
  else
   call gibsaus
 end
return

personsearch:
 transmit
 query 'Nach welcher Person suchen (Nachname, Vorname)?' ; person=result
 if person~='RESULT' & person~='' & person~='###PANIC' then do
  transmit "MovieDataBase wird nach '"||person||"' durchsucht..."
  address 'MOVIEMUI' 'GET "'||person||'" FROM ANY' ; mytext=result
  if mytext='RESULT' | RC~=0 then do
   transmit "Die Person wurde nicht gefunden! Probier' es mal mit"
   transmit "selektiver Suche!"
  end
  else
   call gibsaus
 end
return

selectivesearch:
send '0c'x
address 'MOVIEMUI' 'UNSELECT KEY=0' ; skey=result
numentries='alle'
do until cmd='+'
 if xpert='NOVICE' then sendmenu selsearch
 systeminfo m ; time=result
 transmit
 transmit 'Es sind '||numentries||' Datensaetze selektiert!'
 getcmd '[Time: '||time||'] [Select - Commands: 0-9 U N G F ? + ] ' ; cmd=upper(result)
 if CARRIER=0 then call stopit
 einschr=0
 select
  when (cmd='?' | cmd='') then sendmenu selmenu
  when cmd='+' then transmit
  when cmd=''  then transmit
  when cmd='RESULT' then transmit
  when cmd='0' then do
   sts='MOVIE' ; stl='Filmtitel' ; einschr=1 ; end
  when cmd='1' then do
   sts='ACR' ; stl='Schauspieler' ; einschr=1 ; end
  when cmd='2' then do
   sts='ACS' ; stl='Schauspielerin' ; einschr=1 ; end
  when cmd='3' then do
   sts='COMP' ; stl='Komponist' ; einschr=1 ; end
  when cmd='4' then do
   sts='COST' ; stl='Kostuem Designer' ; einschr=1 ; end
  when cmd='5' then do
   sts='DIR' ; stl='Regisseur' ; einschr=1 ; end
  when cmd='6' then do
   sts='ED' ; stl='Editor' ; einschr=1 ; end
  when cmd='7' then do
   sts='PRDE' ; stl='Production Designer' ; einschr=1 ; end
  when cmd='8' then do
   sts='PROD' ; stl='Produzent' ; einschr=1 ; end
  when cmd='9' then do
   sts='WRITE' ; stl='Autor' ; einschr=1 ; end
  when cmd='U' then do
    address 'MOVIEMUI' 'UNDOSELECT KEY='||skey ; numentries=result
   end
  when cmd='N' then do
    transmit
    numentries='alle'
    address 'MOVIEMUI' 'ENDSELECTION KEY='||skey
    address 'MOVIEMUI' 'UNSELECT KEY=0' ; skey=result
   end
  when cmd='G' then call getsel
  when cmd='F' then call getfromsel
  otherwise do
   transmit
   transmit "Dieser Befehl ist hier unbekannt, versuch's mal mit "||'"?"!'
  end
 end
 if einschr=1 then do
  transmit
  transmit 'Einschraenkungspattern (nach AmigaOS-Konventionen!)'
  query 'fuer '||stl||': ' ; mypat=result
  if mypat~='RESULT' & mypat~='' then do
   do while pos('*',mypat)>0
    sternpos=pos('*',mypat)
    mypat=left(mypat,sternpos-1)||'#?'||right(mypat,length(mypat)-sternpos)
   end
/*   transmit 'SELECT KEY='||skey||' "'||mypat||'" FROM '||sts */
   transmit "MovieDataBase wird nach "||stl||"='"||mypat||"' durchsucht..."
   address 'MOVIEMUI' 'SELECT KEY='||skey||' "'||mypat||'" FROM '||sts ; numentries=result
   if RC~=0 then do
    transmit 'Fehler beim Selektieren, mache Selektierung rueckgaengig...'
    address 'MOVIEMUI' 'UNDOSELECT KEY='||skey ; numentries=result
   end
  end
 end
end
address 'MOVIEMUI' 'ENDSELECTION KEY='||skey
cmd=''
return

getsel:
 transmit
 if numentries=0 then
  transmit 'Es sind keine Daten selektiert!'
 else
  if numentries > 100 | numentries='alle' then do
   transmit 'Es sind mehr als 100 Datensaetze selektiert!'
   transmit 'Bitte weiter einschraenken!'
  end
  else do
   address 'MOVIEMUI' 'GETSELECTION KEY='||skey ; mytext=result
   if mytext='RESULT' | RC~=0 then
    transmit "Tja, nix gefunden, sorry!"
   else
    call gibsaus
  end
return

getfromsel:
 transmit
 if numentries=0 then
  transmit 'Es sind keine Daten selektiert!'
 else do
  query 'Welchen '||stl||' (Nummer 1..'||numentries||') zeigen? ' ; frose=result
  if frose~='RESULT' & frose~='' & datatype(frose)='NUM' then
   if frose>0 & frose<numentries+1 then do
    address 'MOVIEMUI' 'GETFROMSELECTION KEY='||skey||' NUMBER='||frose ; mytext=result
    if mytext='RESULT' | RC~=0 then
     transmit "Tja, nix gefunden, sorry!"
    else
     call gibsaus
   end
 end
return

infor:
 transmit '0c'x
 transmit "mdb.trans V1.0ger (C)'94 by Georg 'Gio' Magschok"
 address 'MOVIEMUI' 'INFO "title"' ; transmit result
/* address 'MOVIEMUI' 'INFO "author"' ; transmit 'by '||result */
 address 'MOVIEMUI' 'INFO "copyright"' ; transmit '(C) '||result
 address 'MOVIEMUI' 'INFO "description"' ; transmit result
 address 'MOVIEMUI' 'INFO "version"' ; transmit result
 address 'MOVIEMUI' 'GETSTATISTIC' ; mytext=result
 call gibsaus
return

gibsaus:
 fina=tempfile||bbsline||time(s)
 if open('fit',fina,'W') then do
  call writeln('fit',mytext)
  call close('fit')
  sendfile fina
  address command 'delete '||fina||' quiet'
  continue
 end
 else
  transmit "Unable to open redirection file! Contact SysOp!"
return
