home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / bazy / dfa_birthdays / english / dfa / rexx / birthdays next >
Text File  |  1997-09-18  |  6KB  |  213 lines

  1. /*******************************************/
  2. /* Birthdays                               */
  3. /* Birthday-Checker for DFA                */
  4. /* by Ralf Keber (rkeber@sparkasse.net)    */
  5. /* 10.09.97 -  Version 1.1                 */
  6. /*******************************************/
  7.  
  8. if ~show('L',"rexxreqtools.library") then addlib('rexxreqtools.library',0,-30,0)
  9. fonttag="rt_font=courier.font/13"
  10.  
  11. if ~show(ports, DFA) then do
  12.     ADDRESS COMMAND 'RUN >NIL: DFA:DFA'
  13.     address command 'wait 2'
  14.     if ~show(ports, DFA) then do
  15.        address command 'wait 4'
  16.        if ~show(ports, DFA) then exit
  17.        end
  18.     end
  19.  
  20. options RESULTS
  21.  
  22. cr="0A"X
  23.  
  24. DaysComing = ""
  25. DaysPassed = ""
  26.  
  27. if open(Prefs,'ENV:DFA/Birthdays.env','R') then do
  28.    if ~EoF(Prefs) then do
  29.        text=ReadLn(Prefs)
  30.        PARSE VAR Text lastdate"*"DaysComing"*"DaysPassed
  31.        /* if coming from DFA, there's no date-filter*/
  32.        if (ADDRESS()~='DFA') & (lastdate=date('i')) then exit
  33.        if ABS(lastdate-date('i'))>365 then do
  34.       text="The system-date seems unreliable,"||cr||"please check it!"
  35.       call rtezrequest(text, "set date|forget about date|abort", ,,
  36.       fonttag "rt_reqpos = reqpos_centerscr" "rtez_defaultresponse = 1")
  37.       choice= rtresult
  38.       if choice == 0 then exit
  39.       if choice == 1 then Address command 'sys:prefs/time'
  40.       if choice == 2 then nop
  41.       end
  42.        end
  43.    close(Prefs)
  44.    end
  45.  
  46. IF DaysComing="" THEN DaysComing =15
  47. IF DaysPassed="" THEN DaysPassed = 5
  48.  
  49. if ADDRESS()~=DFA then ADDRESS 'DFA' CHANGEGROUPS ALL
  50.  
  51. again=1
  52. do until ~again
  53. again=calculate()
  54. end
  55.  
  56. if ~open(Prefs,'ENV:DFA/Birthdays.env','W') then exit
  57. text=date('i')||"*"||DaysComing||"*"||DaysPassed
  58. WriteCh(Prefs,text)
  59. close(Prefs)
  60. if ~open(Prefs,'ENVARC:DFA/Birthdays.env','W') then exit
  61. WriteCh(Prefs,text)
  62. close(Prefs)
  63.  
  64. exit
  65.  
  66. /*******************************************************************************************/
  67.  
  68. calculate:
  69.  
  70. /* disable listview refresh */
  71. address "DFA" gui output off input off
  72.  
  73. today = date('i')
  74. thisyear = substr(date(s), 1, 4)
  75. text="Birthdays, "||DaysPassed||" days passed until "||DaysComing||" days coming"||cr||,
  76.      "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"||cr
  77. address "DFA" first stem p.
  78.  
  79. InTheNextYear = (today+DaysComing > ConvDate("31.12", thisyear))
  80. if InTheNextYear then DayNextYear = today + DaysComing - 365
  81. InTheLastYear = (today-DaysPassed < ConvDate("01.01", thisyear))
  82. if InTheLastYear then DayLastYear = today - DaysPassed + 365
  83. i=0
  84. do while RC = 0
  85.     bday =  p.address.9
  86.     if bday ~= "" then
  87.     do
  88.     birthday = ConvDate(p.address.9, thisyear)
  89.     if InTheNextYear then
  90.        if birthday < DayNextYear then birthday = birthday + 365
  91.     if InTheLastYear then
  92.        if birthday > DayLastYear then birthday = birthday - 365
  93.     diff = birthday - today
  94.     if (birthday ~= 0) & (diff<=DaysComing) & (-diff<=DaysPassed) then
  95.     do
  96.        i=i+1
  97.        diff.i      = diff
  98.        birthday.i  = p.address.9
  99.        fname.i     = p.address.1
  100.        name.i      = p.address.2
  101.        sort.i      = i
  102.     end
  103.     end
  104.     address "DFA" next stem p.
  105. end
  106. max=i
  107. address "DFA" gui output on input on
  108.  
  109. /* order birthdays */
  110. dpassed=1
  111. dcoming=1
  112. do i=1 to max /* max-1 -> wrong dpassed, dcoming */
  113.    if diff.i<-9 then
  114.       if diff.i<-99 then dpassed=3
  115.             else if dpassed~=3 then dpassed=2
  116.    if diff.i>9 then
  117.       if diff.i>99 then dcoming=3
  118.            else if dcoming~=3 then dcoming=2
  119.    do l=i+1 to max
  120.       call compare(sort.i,sort.l)
  121.       end
  122.    end
  123.  
  124. do i=1 to max
  125.    call textout(sort.i)
  126.    end
  127.  
  128. call rtezrequest(text, "days passed|ok|days coming", ,,
  129.      fonttag "rt_reqpos = reqpos_centerscr" "rtez_defaultresponse = 2")
  130.  
  131. choice= rtresult
  132. if choice == 1 then do
  133.    rmax=365-DaysComing
  134.    number = rtgetlong(DaysPassed,, "days pased:", , fonttag,
  135.       "rtgl_min = 0 rtgl_max ="||rmax)
  136.    if rtresult == 0 then exit
  137.    else DaysPassed=number
  138.    neu=1
  139.    end
  140.  
  141. if choice == 2 then neu=0
  142.  
  143. if choice == 0 then do
  144.    rmax=365-DaysPassed
  145.    number = rtgetlong(DaysComing, , "days coming:", , fonttag,
  146.       "rtgl_min = 0 rtgl_max ="||rmax)
  147.    if rtresult == 0 then exit
  148.    else DaysComing=number
  149.    neu=1
  150.    end
  151. return neu
  152.  
  153. /*******************************************************************************************/
  154.  
  155. compare:
  156.    arg ii, ll
  157.  
  158.    if (diff.ll=0)|(diff.ii > diff.ll) then do
  159.       h=sort.i
  160.       sort.i=sort.l
  161.       sort.l=h
  162.       end
  163.    return
  164.  
  165. /*******************************************************************************************/
  166.  
  167. textout:
  168.    arg ii
  169.  
  170.    if right(birthday.ii, 1) = "." then
  171.    do
  172.      howold = ""
  173.      dot    = ""
  174.    end
  175.    else
  176.    do
  177.      howold = right(thisyear, 2) - right(birthday.ii, 2)
  178.      if howold < 0 then howold = howold + 100
  179.      dot = "."
  180.      howlast = right(howold, 1)
  181.    end
  182.  
  183.    if (diff.ii = 1) | (diff.ii = -1) then days = "day"
  184.    else days = "days"
  185.    GebTag=fname.ii name.ii||x2c(27)||"s "||howold||dot||"birthday."
  186.  
  187.    if (diff.ii > 0) then
  188.       text=text||"In "||Right(diff.ii,dcoming)||" "||days||" is "||GebTag||cr
  189.    if (diff.ii = 0) then
  190.        text=text||"*** Today is "||GebTag||" ***"||cr
  191.    if (diff.ii < 0) then
  192.        text=text||Right(diff.ii * (-1),dpassed)||" "||days||" ago was "||GebTag||cr
  193.    return 
  194.  
  195. /*******************************************************************************************/
  196.  
  197. ConvDate: procedure
  198.     arg bd,thisyear
  199.  
  200.     parse VAR bd day"."month"."year
  201.  
  202.     bdi=0
  203.     if (day>0) & (day<32) & (month>0) & (month<13) then
  204.        do
  205.      if length(day) < 2 then
  206.          day = 0||day
  207.      if length(month) < 2 then
  208.           month = 0||month
  209.      bdi=date(i, thisyear||month||day , s)
  210.        end
  211.     return bdi
  212.  
  213.