Source: site.view [edit]
Function name: mediaTimeChangeTime
Arguments: cmd,day,amount
Description: Zero's out hours for that day, or converts TV time to Computer time
Page type: webl
Render function:  
Module: global

Page source:

var html = "";
if cmd == "ZERO OUT HOURS FOR THIS DAY" then

   var info = (WubCall("global.mediaTimeData", []) ? [. currentMedia = "tv", currentState = "STOP" .]);
   html = "Time zero'd out for " + day;

   var timeLeft = [. tv = 0, computer = 0 .];
   info[day] := timeLeft;

   var funcinfo = Wub_GetFunctionInfo("global.mediaTimeData");
   funcinfo.exec := ToString(info);
   Wub_SaveFunctionInfo(funcinfo);

else

   amount = ToInt(amount);
   var info = (WubCall("global.mediaTimeData", []) ? [. currentMedia = "tv", currentState = "STOP" .]);
   var dat = Str_Split(Wub_GetDateTimeStr(), " ");
   var day = dat[0];
   var timeLeft = info[day] ? [. tv = 1000 * 60 * 120, computer = 1000 * 60 * 120 .];
   var now = Wub_GetDateTime();
   var lastClick = info.lastClick ? 0;

   var computerRemaining = timeLeft.computer;
   var tvRemaining = timeLeft.tv;

   if info.currentState == "START" then
      html = "Must stop clock before changing time"
   else
      if (tvRemaining) < 1000 * 60 * amount * 2 then 
         html = "Not enough TV time left to convert " + ToString(amount) + " minutes."
      else
         tvRemaining = tvRemaining - 1000 * 60 * amount * 2;
         computerRemaining = computerRemaining + 1000 * 60 * amount;
         timeLeft = [. tv = tvRemaining, computer = computerRemaining .];
         info[day] := timeLeft;
         html = "Converted " + ToString(amount) + " minutes.";

         var funcinfo = Wub_GetFunctionInfo("global.mediaTimeData");
         funcinfo.exec := ToString(info);
         Wub_SaveFunctionInfo(funcinfo);

      end
   end
end;

var m = Markup(WubCall("mediaTime", [html]));
m = Wub_ReplaceAll(m, `10"`, `4; URL=/webl/WubHub_DoIt?cmdline=global.mediaTime"`);

NewPage(m, "text/html");