home *** CD-ROM | disk | FTP | other *** search
/ Better Homes & Gardens: …oking for Today - Chicken / Image.iso / pc / planner.dxr / 00001_movie.ls next >
Encoding:
Text File  |  1995-11-20  |  24.4 KB  |  866 lines

  1. on startMovie
  2.   global gHiliteSprite, gPlanSprite, gCaloriesSprite, gFatSprite, gDayInsert, gMealInsert, gTheDays, gTheMonths, gMonthMax, gDayName, gDayNum, gMonth, gYear, gHelpSprite
  3.   set the textHeight of field "meals" to 14
  4.   set the textHeight of field "meals calories" to 14
  5.   set the textHeight of field "meals fat" to 14
  6.   set the textHeight of field "days" to 14
  7.   set the textHeight of field "days calories" to 14
  8.   set the textHeight of field "days fat" to 14
  9.   set the textHeight of field "dayNotes scroll" to 14
  10.   set the textHeight of field "weekNotes scroll" to 14
  11.   set the textStyle of field "weekNotes scroll" to "plain"
  12.   set the textStyle of field "dayNotes scroll" to "plain"
  13.   set the textStyle of field "meals fat" to "plain"
  14.   set the textStyle of field "meals calories" to "plain"
  15.   set the textStyle of field "days fat" to "plain"
  16.   set the textStyle of field "days calories" to "plain"
  17.   set the textSize of field "weekNotes scroll" to 12
  18.   set the textSize of field "dayNotes scroll" to 12
  19.   set the textSize of field "meals" to 12
  20.   set the textSize of field "meals fat" to 12
  21.   set the textSize of field "meals calories" to 12
  22.   set the textSize of field "days fat" to 12
  23.   set the textSize of field "days calories" to 12
  24.   set the textSize of field "days" to 12
  25.   if the machineType = 256 then
  26.     set the textFont of field "meals" to "arial"
  27.     set the textFont of field "dayNotes scroll" to "arial"
  28.     set the textFont of field "weekNotes scroll" to "arial"
  29.     set the textFont of field "days fat" to "arial"
  30.     set the textFont of field "days calories" to "arial"
  31.     set the textFont of field "meals fat" to "arial"
  32.     set the textFont of field "meals calories" to "arial"
  33.   else
  34.     set the textFont of field "meals" to "helvetica"
  35.     set the textFont of field "dayNotes scroll" to "helvetica"
  36.     set the textFont of field "weekNotes scroll" to "helvetica"
  37.     set the textFont of field "days fat" to "helvetica"
  38.     set the textFont of field "days calories" to "helvetica"
  39.     set the textFont of field "meals fat" to "helvetica"
  40.     set the textFont of field "meals calories" to "helvetica"
  41.   end if
  42.   set gHiliteSprite to 2
  43.   set gPlanSprite to 3
  44.   set gCaloriesSprite to 4
  45.   set gFatSprite to 5
  46.   set the backColor of cast 60 to 243
  47.   set the backColor of cast 50 to 243
  48.   set gDayInsert to 2
  49.   set gMealInsert to 2
  50.   set gTheDays to ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday "]
  51.   set gTheMonths to ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
  52.   set gMonthMax to [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  53.   set today to the long date
  54.   set name to word 1 of today
  55.   set name to char 1 to length(name) - 1 of name
  56.   set gDayName to getPos(gTheDays, name)
  57.   set day to word 3 of today
  58.   set gDayNum to integer(char 1 to length(day) - 1 of day)
  59.   put gDayNum into field "day"
  60.   set gMonth to integer(char 1 to offset("/", the short date) of the short date)
  61.   put getAt(gTheMonths, gMonth) into field "month"
  62.   set gYear to integer(word 4 of today)
  63.   put gYear into field "year"
  64.   put "Week of" into field "name"
  65.   set gHelpSprite to 42
  66.   helpOff()
  67.   updateRecipes()
  68.   changeDay(1 - gDayName)
  69.   go("weekly")
  70.   makeScrolls()
  71.   makeButtons()
  72.   loadPlanner()
  73. end
  74.  
  75. on stopMovie
  76.   savePlanner()
  77.   cleanLegos()
  78. end
  79.  
  80. on weekly
  81.   global gDayName
  82.   helpOff()
  83.   savePlanner()
  84.   cleanLegos()
  85.   changeDay(1 - gDayName)
  86.   put "Week of" into field "name"
  87.   go("weekly")
  88.   makeScrolls()
  89.   makeButtons()
  90.   loadPlanner()
  91. end
  92.  
  93. on daily
  94.   helpOff()
  95.   savePlanner()
  96.   cleanLegos()
  97.   put " " into field "name"
  98.   setDay()
  99.   go("daily")
  100.   makeScrolls()
  101.   makeButtons()
  102.   loadPlanner()
  103. end
  104.  
  105. on updateRecipes
  106.   global gPlannerRecipes
  107.   set sentList to EMPTY
  108.   set number to count(gPlannerRecipes)
  109.   if number = 0 then
  110.     set sentList to "(send recipes here from recipe screen)"
  111.   else
  112.     if number = 1 then
  113.       set sentList to getAt(gPlannerRecipes, 1) & RETURN
  114.     else
  115.       set sentList to getAt(gPlannerRecipes, 1) & RETURN
  116.       repeat with i = 2 to number
  117.         put getAt(gPlannerRecipes, i) & RETURN after sentList
  118.       end repeat
  119.     end if
  120.   end if
  121.   put sentList into field "recipes"
  122.   put sentList into field "sentScroll"
  123. end
  124.  
  125. on selectRecipe recipeTitle
  126.   global gPlannerRecipes, gPlannerCalories, gPlannerFat, gDayInsert, gMealInsert
  127.   if not stringp(recipeTitle) then
  128.     set aLine to the mouseLine
  129.     if aLine < 1 then
  130.       exit
  131.     end if
  132.     set recipeTitle to line aLine of field "sentScroll"
  133.     if recipeTitle = EMPTY then
  134.       exit
  135.     end if
  136.     if recipeTitle = "(send recipes here from recipe screen)" then
  137.       exit
  138.     end if
  139.   end if
  140.   DBPlanner(recipeTitle)
  141.   if the frame = label("weekly") then
  142.     if line gDayInsert of field "days" = EMPTY then
  143.       set newLine to RETURN
  144.     else
  145.       set newLine to EMPTY
  146.     end if
  147.     put "   " & recipeTitle & newLine into line gDayInsert of field "days"
  148.     put gPlannerCalories & newLine into line gDayInsert of field "days calories"
  149.     put gPlannerFat & newLine into line gDayInsert of field "days fat"
  150.     set gDayInsert to gDayInsert + 1
  151.     dayInsert()
  152.   else
  153.     if the frame = label("daily") then
  154.       if line gMealInsert of field "meals" = EMPTY then
  155.         set newLine to RETURN
  156.       else
  157.         set newLine to EMPTY
  158.       end if
  159.       put "   " & recipeTitle & newLine into line gMealInsert of field "meals"
  160.       put gPlannerCalories & newLine into line gMealInsert of field "meals calories"
  161.       put gPlannerFat & newLine into line gMealInsert of field "meals fat"
  162.       set gMealInsert to gMealInsert + 1
  163.       mealInsert()
  164.     end if
  165.   end if
  166.   totalNutrition()
  167. end
  168.  
  169. on deleteRecipe
  170.   global gDayInsert, gMealInsert
  171.   if the frame = label("weekly") then
  172.     if line gDayInsert of field "days" = EMPTY then
  173.       exit
  174.     end if
  175.     delete line gDayInsert of field "days"
  176.     delete line gDayInsert of field "days calories"
  177.     delete line gDayInsert of field "days fat"
  178.   else
  179.     if the frame = label("daily") then
  180.       if line gMealInsert of field "meals" = EMPTY then
  181.         exit
  182.       end if
  183.       delete line gMealInsert of field "meals"
  184.       delete line gMealInsert of field "meals calories"
  185.       delete line gMealInsert of field "meals fat"
  186.     end if
  187.   end if
  188.   totalNutrition()
  189. end
  190.  
  191. on totalNutrition
  192.   set totalCalories to 0
  193.   set totalFat to 0
  194.   if the frame = label("weekly") then
  195.     set allCalories to field "days calories"
  196.     set allFat to field "days fat"
  197.     set nutritionNum to the number of lines in allCalories
  198.     repeat with i = 1 to nutritionNum
  199.       set calories to integer(line i of allCalories)
  200.       if integerp(calories) then
  201.         set totalCalories to totalCalories + calories
  202.       end if
  203.       set fat to integer(line i of allFat)
  204.       if integerp(fat) then
  205.         set totalFat to totalFat + fat
  206.       end if
  207.     end repeat
  208.     put totalCalories into field "week total calories"
  209.     put totalFat into field "week total fat"
  210.   else
  211.     if the frame = label("daily") then
  212.       set allCalories to field "meals calories"
  213.       set allFat to field "meals fat"
  214.       set nutritionNum to the number of lines in allCalories
  215.       repeat with i = 1 to nutritionNum
  216.         set calories to integer(line i of allCalories)
  217.         if integerp(calories) then
  218.           set totalCalories to totalCalories + calories
  219.         end if
  220.         set fat to integer(line i of allFat)
  221.         if integerp(fat) then
  222.           set totalFat to totalFat + fat
  223.         end if
  224.       end repeat
  225.       put totalCalories into field "day total calories"
  226.       put totalFat into field "day total fat"
  227.     end if
  228.   end if
  229. end
  230.  
  231. on selectDayInsert
  232.   global gDayInsert, gTheDays
  233.   set aLine to the mouseLine
  234.   if aLine < 1 then
  235.     exit
  236.   end if
  237.   set inserted to 0
  238.   repeat with i in gTheDays
  239.     if line aLine of field "days" = i then
  240.       set gDayInsert to aLine + 1
  241.       set inserted to 1
  242.     end if
  243.   end repeat
  244.   if not inserted then
  245.     set gDayInsert to aLine
  246.   end if
  247.   dayInsert()
  248. end
  249.  
  250. on dayInsert
  251.   global gHiliteSprite, gPlanSprite, gDayInsert, gPlanScroll
  252.   if the machineType = 256 then
  253.     set loc to ((gDayInsert - 1) * 14) + the locV of sprite gPlanSprite
  254.   else
  255.     set loc to ((gDayInsert - 1) * 14) + the locV of sprite gPlanSprite
  256.   end if
  257.   set the locV of sprite gHiliteSprite to loc
  258.   if loc > 300 then
  259.     controlPosition(gPlanScroll, 1.0)
  260.   end if
  261. end
  262.  
  263. on selectMealInsert
  264.   global gMealInsert
  265.   set aLine to the mouseLine
  266.   if aLine < 1 then
  267.     exit
  268.   end if
  269.   set meals to ["breakfast", "lunch", "dinner "]
  270.   set inserted to 0
  271.   repeat with i in meals
  272.     if line aLine of field "meals" = i then
  273.       set gMealInsert to aLine + 1
  274.       set inserted to 1
  275.     end if
  276.   end repeat
  277.   if not inserted then
  278.     set gMealInsert to aLine
  279.   end if
  280.   mealInsert()
  281. end
  282.  
  283. on mealInsert
  284.   global gHiliteSprite, gPlanSprite, gMealInsert, gPlanScroll
  285.   if the machineType = 256 then
  286.     set loc to ((gMealInsert - 1) * 14) + the locV of sprite gPlanSprite
  287.   else
  288.     set loc to ((gMealInsert - 1) * 14) + the locV of sprite gPlanSprite
  289.   end if
  290.   set the locV of sprite gHiliteSprite to loc
  291.   if loc > 300 then
  292.     controlPosition(gPlanScroll, 1.0)
  293.   end if
  294. end
  295.  
  296. on dayButton direction
  297.   savePlanner()
  298.   set doOnce to 1
  299.   if field "name" = "Week of" then
  300.     set direction to direction * 7
  301.   end if
  302.   repeat while the mouseDown or doOnce
  303.     changeDay(direction)
  304.     waste()
  305.     set doOnce to 0
  306.   end repeat
  307.   loadPlanner()
  308. end
  309.  
  310. on setDay
  311.   global gDayName, gTheDays
  312.   if gDayName <= 0 then
  313.     set gDayName to gDayName + 7
  314.   else
  315.     if gDayName > 7 then
  316.       set gDayName to gDayName mod 7
  317.     end if
  318.   end if
  319.   if field "name" = "Week of" then
  320.     exit
  321.   end if
  322.   put getAt(gTheDays, gDayName) into field "name"
  323. end
  324.  
  325. on changeDay direction
  326.   global gDayName, gDayNum
  327.   set max to getMonth()
  328.   if (gDayNum + direction) > max then
  329.     setMonth(1)
  330.     set gDayNum to gDayNum - max + direction
  331.   else
  332.     if (gDayNum + direction) < 1 then
  333.       setMonth(-1)
  334.       set gDayNum to gDayNum + getMonth() + direction
  335.     else
  336.       set gDayNum to gDayNum + direction
  337.     end if
  338.   end if
  339.   put gDayNum into field "day"
  340.   set gDayName to gDayName + direction
  341.   setDay()
  342. end
  343.  
  344. on monthButton direction
  345.   savePlanner()
  346.   set doOnce to 1
  347.   repeat while the mouseDown or doOnce
  348.     changeMonth(direction)
  349.     waste()
  350.     set doOnce to 0
  351.   end repeat
  352.   loadPlanner()
  353. end
  354.  
  355. on getMonth
  356.   global gMonth, gMonthMax, gYear
  357.   set max to getAt(gMonthMax, gMonth)
  358.   if (gMonth = 2) and ((gYear mod 4) = 0) then
  359.     set max to max + 1
  360.   end if
  361.   return max
  362. end
  363.  
  364. on setMonth direction
  365.   global gMonth, gTheMonths, gYear
  366.   set gMonth to gMonth + direction
  367.   if gMonth > 12 then
  368.     set gMonth to 1
  369.     set gYear to gYear + 1
  370.     put gYear into field "year"
  371.   else
  372.     if gMonth < 1 then
  373.       set gMonth to 12
  374.       set gYear to gYear - 1
  375.       put gYear into field "year"
  376.     end if
  377.   end if
  378.   put getAt(gTheMonths, gMonth) into field "month"
  379. end
  380.  
  381. on changeMonth direction
  382.   global gDayName, gDayNum, gMonth, gMonthMax
  383.   if direction > 0 then
  384.     set max to getMonth()
  385.     set gDayName to gDayName + (max mod 7)
  386.   end if
  387.   set oldMax to getAt(gMonthMax, gMonth)
  388.   setMonth(direction)
  389.   set newMax to getAt(gMonthMax, gMonth)
  390.   if (oldMax > newMax) and (gDayNum > newMax) then
  391.     set gDayName to gDayName + (newMax - gDayNum)
  392.     set gDayNum to newMax
  393.     put gDayNum into field "day"
  394.   end if
  395.   if direction < 0 then
  396.     set max to getMonth()
  397.     set gDayName to gDayName - (max mod 7)
  398.   end if
  399.   if field "name" = "Week of" then
  400.     changeDay(1 - gDayName)
  401.   else
  402.     setDay()
  403.   end if
  404. end
  405.  
  406. on yearButton direction
  407.   savePlanner()
  408.   set doOnce to 1
  409.   repeat while the mouseDown or doOnce
  410.     changeYear(direction)
  411.     waste()
  412.     set doOnce to 0
  413.   end repeat
  414.   loadPlanner()
  415. end
  416.  
  417. on changeYear direction
  418.   global gDayName, gDayNum, gMonth, gYear
  419.   if (gMonth = 2) and (gDayNum = 29) then
  420.     set gYear to gYear + (direction * 4)
  421.     set gDayName to gDayName + (direction * 5)
  422.   else
  423.     if direction < 0 then
  424.       if ((gYear mod 4) = 0) and (gMonth > 2) then
  425.         set gDayName to gDayName - 2
  426.       else
  427.         if (((gYear - 1) mod 4) = 0) and (gMonth < 3) then
  428.           set gDayName to gDayName - 2
  429.         else
  430.           set gDayName to gDayName - 1
  431.         end if
  432.       end if
  433.     else
  434.       if direction > 0 then
  435.         if ((gYear mod 4) = 0) and (gMonth < 3) then
  436.           set gDayName to gDayName + 2
  437.         else
  438.           if (((gYear + 1) mod 4) = 0) and (gMonth > 2) then
  439.             set gDayName to gDayName + 2
  440.           else
  441.             set gDayName to gDayName + 1
  442.           end if
  443.         end if
  444.       end if
  445.     end if
  446.     set gYear to gYear + direction
  447.     put gYear into field "year"
  448.   end if
  449.   if field "name" = "Week of" then
  450.     changeDay(1 - gDayName)
  451.   else
  452.     setDay()
  453.   end if
  454. end
  455.  
  456. on waste
  457.   startTimer()
  458.   repeat while the timer < 10
  459.     nothing()
  460.   end repeat
  461. end
  462.  
  463. on makeScrolls
  464.   global gHiliteSprite, gPlanSprite, gCaloriesSprite, gFatSprite, gPlanScroll
  465.   set track to new("Button", [#spriteChan: 33])
  466.   set ball to new("Button", [#spriteChan: 34, #pressedCast: 75])
  467.   set up to new("Button", [#spriteChan: 35, #pressedCast: 77])
  468.   set down to new("Button", [#spriteChan: 36, #pressedCast: 79])
  469.   new("ScrollBar", [#scrollField: "recipes", #scrollFieldOut: 16, #minButton: up, #maxButton: down, #thumbButton: ball, #trackButton: track])
  470.   set spriteList to [gCaloriesSprite, gFatSprite]
  471.   set track to new("Button", [#spriteChan: 37])
  472.   set ball to new("Button", [#spriteChan: 38, #pressedCast: 75])
  473.   set up to new("Button", [#spriteChan: 39, #pressedCast: 77])
  474.   set down to new("Button", [#spriteChan: 40, #pressedCast: 79])
  475.   set gPlanScroll to new("ScrollBar", [#scrollSprite: gPlanSprite, #scrollLinks: spriteList, #handler: "shiftHilite", #minButton: up, #maxButton: down, #thumbButton: ball, #trackButton: track])
  476.   puppetSprite(gHiliteSprite, 1)
  477. end
  478.  
  479. on shiftHilite ratio
  480.   global gHiliteSprite, gPlanSprite, gDayInsert, gMealInsert
  481.   if the frame = label("weekly") then
  482.     if the machineType = 256 then
  483.       set loc to ((gDayInsert - 1) * 14) + the locV of sprite gPlanSprite
  484.     else
  485.       set loc to ((gDayInsert - 1) * 14) + the locV of sprite gPlanSprite
  486.     end if
  487.   else
  488.     if the machineType = 256 then
  489.       set loc to ((gMealInsert - 1) * 14) + the locV of sprite gPlanSprite
  490.     else
  491.       set loc to ((gMealInsert - 1) * 14) + the locV of sprite gPlanSprite
  492.     end if
  493.   end if
  494.   set the locV of sprite gHiliteSprite to loc
  495. end
  496.  
  497. on makeButtons
  498.   global gMainButton, gHelpButton, gBackButton, gNotesButton, gDeleteButton, gPrintButton
  499.   set gBackButton to birth(script "GACButton", 9)
  500.   set gHelpButton to birth(script "GACButton", 8)
  501.   set gMainButton to birth(script "GACButton", 10)
  502.   set gNotesButton to birth(script "GACButton", 12)
  503.   set gDeleteButton to birth(script "GACButton", 13)
  504.   set gPrintButton to birth(script "GACButton", 14)
  505. end
  506.  
  507. on notes
  508.   helpOff()
  509.   loadNotes()
  510.   if the frame = label("weekly") then
  511.     weekNotes()
  512.   else
  513.     if the frame = label("daily") then
  514.       dayNotes()
  515.     end if
  516.   end if
  517. end
  518.  
  519. on planner
  520.   cleanLegos()
  521.   if the frame = label("weeknotes") then
  522.     go("weekly")
  523.   else
  524.     if the frame = label("daynotes") then
  525.       go("daily")
  526.     end if
  527.   end if
  528.   saveNotes()
  529.   makeScrolls()
  530.   makeButtons()
  531. end
  532.  
  533. on dayNotes
  534.   cleanLegos()
  535.   put field "dayNotes" into field "dayNotes scroll"
  536.   go("dayNotes")
  537.   makeDayNotesScroll()
  538. end
  539.  
  540. on makeDayNotesScroll
  541.   global gDayNotesScroll, gNotesDoneButton
  542.   set track to new("Button", [#spriteChan: 4])
  543.   set ball to new("Button", [#spriteChan: 5, #pressedCast: 85])
  544.   set up to new("Button", [#spriteChan: 6, #pressedCast: 87])
  545.   set down to new("Button", [#spriteChan: 7, #pressedCast: 89])
  546.   set gDayNotesScroll to new("ScrollBar", [#scrollField: "dayNotes", #scrollFieldOut: 3, #minButton: up, #maxButton: down, #thumbButton: ball, #trackButton: track])
  547.   set gNotesDoneButton to birth(script "GACButton", 9)
  548. end
  549.  
  550. on weekNotes
  551.   cleanLegos()
  552.   put field "weekNotes" into field "weekNotes scroll"
  553.   go("weekNotes")
  554.   makeWeekNotesScroll()
  555. end
  556.  
  557. on makeWeekNotesScroll
  558.   global gWeekNotesScroll, gNotesDoneButton
  559.   set track to new("Button", [#spriteChan: 4])
  560.   set ball to new("Button", [#spriteChan: 5, #pressedCast: 85])
  561.   set up to new("Button", [#spriteChan: 6, #pressedCast: 87])
  562.   set down to new("Button", [#spriteChan: 7, #pressedCast: 89])
  563.   set gWeekNotesScroll to new("ScrollBar", [#scrollField: "weekNotes", #scrollFieldOut: 3, #minButton: up, #maxButton: down, #thumbButton: ball, #trackButton: track])
  564.   set gNotesDoneButton to birth(script "GACButton", 9)
  565. end
  566.  
  567. on savePlanner
  568.   global gDayNum, gMonth, gYear, gTheDays, gRecipeIDDB
  569.   cursor(4)
  570.   DBBeginSaveSession()
  571.   if gDayNum < 10 then
  572.     set day to "0" & gDayNum
  573.   else
  574.     set day to gDayNum
  575.   end if
  576.   if gMonth < 10 then
  577.     set month to "0" & gMonth
  578.   else
  579.     set month to gMonth
  580.   end if
  581.   set year to char 3 to 4 of string(gYear)
  582.   set lineNumbers to []
  583.   hiliteOff()
  584.   if the frame = label("weekly") then
  585.     set recipes to field "days"
  586.     set recipeNum to the number of lines in recipes
  587.     set oneDay to 7
  588.     set day to integer(day) + 6
  589.     if day < 10 then
  590.       put "0" before day
  591.     end if
  592.     set planID to month & day & year & 4
  593.     repeat with i = recipeNum down to 1
  594.       set aRecipe to line i of recipes
  595.       if (aRecipe <> EMPTY) and (aRecipe <> getAt(gTheDays, oneDay)) then
  596.         add(lineNumbers, i)
  597.         delete char 1 to 3 of aRecipe
  598.         set recipeID to getProp(gRecipeIDDB, aRecipe)
  599.         put "^" & recipeID after planID
  600.         next repeat
  601.       end if
  602.       if aRecipe = getAt(gTheDays, oneDay) then
  603.         if planID contains "^" then
  604.           DBSetRecord("meal plan", planID)
  605.         else
  606.           DBDeleteRecord("meal plan", planID)
  607.         end if
  608.         set oneDay to oneDay - 1
  609.         set day to integer(day) - 1
  610.         if day < 10 then
  611.           put "0" before day
  612.         end if
  613.         set planID to month & day & year & 4
  614.       end if
  615.     end repeat
  616.   else
  617.     if the frame = label("daily") then
  618.       set meals to ["breakfast", "lunch", "dinner "]
  619.       set recipes to field "meals"
  620.       set recipeNum to the number of lines in recipes
  621.       set oneMeal to 3
  622.       set planID to month & day & year & oneMeal
  623.       repeat with i = recipeNum down to 1
  624.         set aRecipe to line i of recipes
  625.         if (aRecipe <> EMPTY) and (aRecipe <> getAt(meals, oneMeal)) then
  626.           add(lineNumbers, i)
  627.           delete char 1 to 3 of aRecipe
  628.           set recipeID to getProp(gRecipeIDDB, aRecipe)
  629.           put "^" & recipeID after planID
  630.           next repeat
  631.         end if
  632.         if aRecipe = getAt(meals, oneMeal) then
  633.           if planID contains "^" then
  634.             DBSetRecord("meal plan", planID)
  635.           else
  636.             DBDeleteRecord("meal plan", planID)
  637.           end if
  638.           set oneMeal to oneMeal - 1
  639.           set planID to month & day & year & oneMeal
  640.         end if
  641.       end repeat
  642.     end if
  643.   end if
  644.   cleanPlan(lineNumbers)
  645.   DBEndSession()
  646.   cursor(-1)
  647. end
  648.  
  649. on saveNotes
  650.   global gDayNum, gMonth, gYear
  651.   cursor(4)
  652.   DBBeginSaveSession()
  653.   if gDayNum < 10 then
  654.     set day to "0" & gDayNum
  655.   else
  656.     set day to gDayNum
  657.   end if
  658.   if gMonth < 10 then
  659.     set month to "0" & gMonth
  660.   else
  661.     set month to gMonth
  662.   end if
  663.   set year to char 3 to 4 of string(gYear)
  664.   if the frame = label("weekly") then
  665.     set planID to month & day & year & 6
  666.     set note to removeCarrots(field "weekNotes")
  667.     if removeSpace(note) <> EMPTY then
  668.       put "^" & note after planID
  669.     end if
  670.     if planID contains "^" then
  671.       DBSetRecord(16000, planID)
  672.     else
  673.       DBDeleteRecord(16000, planID)
  674.     end if
  675.     put " " into field "weekNotes"
  676.     put " " into field "weekNotes scroll"
  677.   else
  678.     if the frame = label("daily") then
  679.       set planID to month & day & year & 5
  680.       set note to removeCarrots(field "dayNotes")
  681.       if removeSpace(note) <> EMPTY then
  682.         put "^" & note after planID
  683.       end if
  684.       if planID contains "^" then
  685.         DBSetRecord(16000, planID)
  686.       else
  687.         DBDeleteRecord(16000, planID)
  688.       end if
  689.       put " " into field "dayNotes"
  690.       put " " into field "dayNotes scroll"
  691.     end if
  692.   end if
  693.   DBEndSession()
  694.   cursor(-1)
  695. end
  696.  
  697. on loadPlanner
  698.   global gDayNum, gMonth, gYear, gTheDays, gRecipeIDDB, gDayInsert, gMealInsert, gDBResult
  699.   cursor(4)
  700.   DBBeginBothSession()
  701.   if gDayNum < 10 then
  702.     set day to "0" & gDayNum
  703.   else
  704.     set day to gDayNum
  705.   end if
  706.   if gMonth < 10 then
  707.     set month to "0" & gMonth
  708.   else
  709.     set month to gMonth
  710.   end if
  711.   set year to char 3 to 4 of string(gYear)
  712.   if the frame = label("weekly") then
  713.     set day to integer(day) + 7
  714.     repeat with i = 7 down to 1
  715.       set day to integer(day) - 1
  716.       if day < 10 then
  717.         put "0" before day
  718.       end if
  719.       set planID to month & day & year & 4
  720.       set gDayInsert to i * 2
  721.       DBGetSetRecord(planID, 15000)
  722.       if gDBResult = 0 then
  723.         set recipeID to DBGetSetField(15001)
  724.         set recipeTitle to getOne(gRecipeIDDB, integer(recipeID))
  725.         selectRecipe(recipeTitle)
  726.         repeat while 1
  727.           DBNextSetRecord(15000)
  728.           if gDBResult <> 0 then
  729.             exit repeat
  730.           end if
  731.           if integer(DBGetSetField(15000)) <> integer(planID) then
  732.             exit repeat
  733.           end if
  734.           set recipeID to DBGetSetField(15001)
  735.           set recipeTitle to getOne(gRecipeIDDB, integer(recipeID))
  736.           selectRecipe(recipeTitle)
  737.         end repeat
  738.       end if
  739.     end repeat
  740.   else
  741.     if the frame = label("daily") then
  742.       repeat with i = 3 down to 1
  743.         set planID to month & day & year & i
  744.         set gMealInsert to i * 2
  745.         DBGetSetRecord(planID, 15000)
  746.         if gDBResult = 0 then
  747.           set recipeID to DBGetSetField(15001)
  748.           set recipeTitle to getOne(gRecipeIDDB, integer(recipeID))
  749.           selectRecipe(recipeTitle)
  750.           repeat while 1
  751.             DBNextSetRecord(15000)
  752.             if gDBResult <> 0 then
  753.               exit repeat
  754.             end if
  755.             if integer(DBGetSetField(15000)) <> integer(planID) then
  756.               exit repeat
  757.             end if
  758.             set recipeID to DBGetSetField(15001)
  759.             set recipeTitle to getOne(gRecipeIDDB, integer(recipeID))
  760.             selectRecipe(recipeTitle)
  761.           end repeat
  762.         end if
  763.       end repeat
  764.     end if
  765.   end if
  766.   hiliteOn()
  767.   DBEndSession()
  768.   cursor(-1)
  769. end
  770.  
  771. on loadNotes
  772.   global gDBResult, gDayNum, gMonth, gYear
  773.   cursor(4)
  774.   DBBeginSaveSession()
  775.   if gDayNum < 10 then
  776.     set day to "0" & gDayNum
  777.   else
  778.     set day to gDayNum
  779.   end if
  780.   if gMonth < 10 then
  781.     set month to "0" & gMonth
  782.   else
  783.     set month to gMonth
  784.   end if
  785.   set year to char 3 to 4 of string(gYear)
  786.   if the frame = label("weekly") then
  787.     set planID to month & day & year & 6
  788.     DBGetSetRecord(planID, 16000)
  789.     if gDBResult = 0 then
  790.       set notes to DBGetSetField(20008)
  791.       put notes into field "weekNotes"
  792.       put notes into field "weekNotes scroll"
  793.     end if
  794.   else
  795.     if the frame = label("daily") then
  796.       set planID to month & day & year & 5
  797.       DBGetSetRecord(planID, 16000)
  798.       if gDBResult = 0 then
  799.         set notes to DBGetSetField(20008)
  800.         put notes into field "dayNotes"
  801.         put notes into field "dayNotes scroll"
  802.       end if
  803.     end if
  804.   end if
  805.   DBEndSession()
  806.   cursor(-1)
  807. end
  808.  
  809. on cleanPlan lineNumbers
  810.   if the frame = label("weekly") then
  811.     repeat with lineNum in lineNumbers
  812.       delete line lineNum of field "days"
  813.       delete line lineNum of field "days calories"
  814.       delete line lineNum of field "days fat"
  815.     end repeat
  816.     put 0 into field "week total calories"
  817.     put 0 into field "week total fat"
  818.   else
  819.     if the frame = label("daily") then
  820.       repeat with lineNum in lineNumbers
  821.         delete line lineNum of field "meals"
  822.         delete line lineNum of field "meals calories"
  823.         delete line lineNum of field "meals fat"
  824.       end repeat
  825.       put 0 into field "day total calories"
  826.       put 0 into field "day total fat"
  827.     end if
  828.   end if
  829. end
  830.  
  831. on hiliteOn
  832.   global gHiliteSprite, gDayInsert, gMealInsert, gPlanScroll
  833.   if the frame = label("weekly") then
  834.     set gDayInsert to 2
  835.     dayInsert()
  836.   else
  837.     if the frame = label("daily") then
  838.       set gMealInsert to 2
  839.       mealInsert()
  840.     end if
  841.   end if
  842.   controlPosition(gPlanScroll, 0.0)
  843.   set the visible of sprite gHiliteSprite to 1
  844. end
  845.  
  846. on hiliteOff
  847.   global gHiliteSprite, gPlanScroll
  848.   set the visible of sprite gHiliteSprite to 0
  849.   controlPosition(gPlanScroll, 0.0)
  850. end
  851.  
  852. on helpOn
  853.   global gLastHelp, gHelpLinks, gHelpActive, gHelpSprite
  854.   if gHelpActive then
  855.     helpOff()
  856.   else
  857.     set gHelpActive to 1
  858.     set gLastHelp to 0
  859.     set gHelpLinks to [3: 55, 8: 1, 9: 23, 10: 19, 11: 57, 12: 118, 13: 58, 14: 59, 16: 109, 17: 57]
  860.     repeat with i = 22 to 31
  861.       addProp(gHelpLinks, i, 56)
  862.     end repeat
  863.     puppetSprite(gHelpSprite, 1)
  864.   end if
  865. end
  866.