/*
 * Author       : landofzc
 * Generated on : 22-Nov-2009 19:42:32
 * Version      : 3.0
 */
application "The Strings of Time"
{
    type = public
    allow html = true
    date format = "dd-MMM-yyyy"
    time zone = "America/Los_Angeles"
    section Home
    {
        form  Stamp_Selector
        {
            displayname  =  "Stamp Selector"
            
            instructions
            (
                type  =  plaintext
            )

            must  have  timestamp_type
            (
                displayname  =  "Stamp Type"
                type  =  picklist
                values  =  {"PT Stamp",   "UTC Stamp",   "PT",   "UTC",   "PT Date",   "UTC Date",   "Epoch"}
                on user input
                {
                    // These next 3 variables are just used to print out Deluge script in the UI for 
                    // tutorial purposes.
                    utc_days_deluge_script = (("// see http://answers.google.com/answers/threadview?id=560486<br/>" + ("epoch_seconds = (((zoho.currenttime.toLong()) / 1000).toLong());<br/>")) + "days = (epoch_seconds / 86400);<br/>") + "days_int = (( days.toString()).getPrefix(&quot;.&quot;)).toLong();<br/>";
                    utc_date_deluge_script = (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((("// see: http://www.jsifaq.com/SF/Tips/Tip.aspx?id=7323<br/>" + ("a = (days_int + 2472632);<br/>") + "b = (4 * a + 3);<br/>" + "b = (b / 146097).toLong();<br/>") + "c = ((0 - b) * 146097).toLong();<br/>") + "c = (c / 4).toLong();<br/>") + "c = (c + a);<br/>") + "d = (4 * c + 3);<br/>") + "d = (d / 1461).toLong();<br/>") + "e = ((0 - 1461) * d);<br/>") + "e = (e / 4).toLong();<br/>") + "e = (e + c);<br/>") + "m = (5 * e + 2);<br/>") + "m = (m / 153).toLong();<br/>") + "dd = (153 * m + 2);<br/>") + "dd = (dd / 5).toLong();<br/>") + "day = (0 - dd + e + 1);<br/>") + "mm = ((0 - m) / 10).toLong();<br/>") + "mm = (mm * 12);<br/>") + "month = (mm + m + 3);<br/>") + "year = (b * 100 + d - 4800 + m / 10).toLong();<br/>") + "month_str = &quot;&quot;;<br/>") + "if (month == 1)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Jan&quot;;<br/>") + "}<br/>") + "else if (month == 2)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Feb&quot;;<br/>") + "}<br/>") + "else if (month == 3)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Mar&quot;;<br/>") + "}<br/>") + "else if (month == 4)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Apr&quot;;<br/>") + "}<br/>") + "else if (month == 5)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;May&quot;;<br/>") + "}<br/>") + "else if (month == 6)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Jun&quot;;<br/>") + "}<br/>") + "else if (month == 7)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Jul&quot;;<br/>") + "}<br/>") + "else if (month == 8)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Aug&quot;;<br/>") + "}<br/>") + "else if (month == 9)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Sep&quot;;<br/>") + "}<br/>") + "else if (month == 10)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Oct&quot;;<br/>") + "}<br/>") + "else if (month == 11)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Nov&quot;;<br/>") + "}<br/>") + "else if (month == 12)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;month_str = &quot;Dec&quot;;<br/>") + "}<br/>";
                    utc_time_deluge_script = (((((((((((((((((((((((((("day_fraction = (days - days_int);<br/>" + "secs_left_over = (day_fraction * 86400);<br/>" + "hrs = (secs_left_over / 3600);<br/>" + "hrs_int = (((hrs.toString()).getPrefix(&quot;.&quot;)).toLong());<br/>") + "hrs_fraction = (hrs - hrs_int);<br/>") + "hours = hrs_int;<br/>") + "secs_left_over = (hrs_fraction * 3600).toLong();<br/>") + "mins = (secs_left_over / 60);<br/>") + "mins_int = (((mins.toString()).getPrefix(&quot;.&quot;)).toLong());<br/>") + "mins_fraction = (mins - mins_int);<br/>") + "minutes = &quot;&quot;;<br/>") + "if (((mins_int.toString()).length()) < 2)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;minutes = &quot;0&quot; + mins_int;<br/>") + "}<br/>") + "else<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;minutes = mins_int.toString();<br/>") + "}<br/>") + "secs_left_over = (mins_fraction * 60).toLong();<br/>") + "secs_int = secs_left_over.toLong();<br/>") + "seconds = &quot;&quot;;<br/>") + "if (((secs_int.toString()).length()) < 2)<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;seconds = &quot;0&quot; + secs_int;<br/>") + "}<br/>") + "else<br/>") + "{<br/>") + "&nbsp;&nbsp;&nbsp;&nbsp;seconds = secs_int.toString();<br/>") + "}<br/>";
                    if (input.timestamp_type  ==  "PT Stamp")
                    {
                        grab_time = zoho.currenttime;
                        input.ts = grab_time.toString();
                        input.example = "<strong>Example:</strong> " + grab_time;
                        input.deluge_script = ("<strong>Deluge Script:</strong> zoho.currenttime.toString()");
                    }
                    else if (input.timestamp_type  ==  "UTC Stamp")
                    {
                        input.deluge_script = "<strong>Deluge Script:</strong><br/>" + utc_days_deluge_script + utc_time_deluge_script + utc_date_deluge_script + "utc_stamp = day + &quot;-&quot; + month_str + &quot;-&quot; + year + &quot; &quot; + hours + &quot;:&quot; + minutes + &quot;:&quot; + seconds;<br/>";
                        grab_time = zoho.currenttime;
                        // see http://answers.google.com/answers/threadview?id=560486
                        epoch_seconds = ((grab_time.toLong()  /  1000)).toLong();
                        days = (epoch_seconds  /  86400);
                        days_int = (days.getPrefix(".")).toLong();
                        day_fraction = (days  -  days_int);
                        secs_left_over = (day_fraction  *  86400);
                        hrs = (secs_left_over  /  3600);
                        hrs_int = (hrs.getPrefix(".")).toLong();
                        hrs_fraction = (hrs  -  hrs_int);
                        hours = hrs_int;
                        secs_left_over = ((hrs_fraction  *  3600)).toLong();
                        mins = (secs_left_over  /  60);
                        mins_int = (((mins)).getPrefix(".")).toLong();
                        mins_fraction = (mins  -  mins_int);
                        minutes = "";
                        if ((((mins_int).toString())).length()  <  2)
                        {
                            minutes = "0" + (mins_int);
                        }
                        else
                        {
                            minutes = (mins_int).toString();
                        }
                        secs_left_over = ((mins_fraction  *  60)).toLong();
                        secs_int = secs_left_over.toLong();
                        seconds = "";
                        if (((secs_int.toString())).length()  <  2)
                        {
                            seconds = "0" + secs_int;
                        }
                        else
                        {
                            seconds = secs_int.toString();
                        }
                        // see: http://www.jsifaq.com/SF/Tips/Tip.aspx?id=7323
                        a = (days_int  +  2472632);
                        b = (4  *  a  +  3);
                        b = ((b  /  146097)).toLong();
                        c = (((0  -  b)  *  146097)).toLong();
                        c = ((c  /  4)).toLong();
                        c = (c  +  a);
                        d = (4  *  c  +  3);
                        d = ((d  /  1461)).toLong();
                        e = ((0  -  1461)  *  d);
                        e = ((e  /  4)).toLong();
                        e = (e  +  c);
                        m = (5  *  e  +  2);
                        m = ((m  /  153)).toLong();
                        dd = (153  *  m  +  2);
                        dd = ((dd  /  5)).toLong();
                        day = (0  -  dd  +  e  +  1);
                        mm = (((0  -  m)  /  10)).toLong();
                        mm = (mm  *  12);
                        month = (mm  +  m  +  3);
                        year = ((b  *  100  +  d  -  4800  +  m  /  10)).toLong();
                        month_str = "";
                        if (month  ==  1)
                        {
                            month_str = "Jan";
                        }
                        else if (month  ==  2)
                        {
                            month_str = "Feb";
                        }
                        else if (month  ==  3)
                        {
                            month_str = "Mar";
                        }
                        else if (month  ==  4)
                        {
                            month_str = "Apr";
                        }
                        else if (month  ==  5)
                        {
                            month_str = "May";
                        }
                        else if (month  ==  6)
                        {
                            month_str = "Jun";
                        }
                        else if (month  ==  7)
                        {
                            month_str = "Jul";
                        }
                        else if (month  ==  8)
                        {
                            month_str = "Aug";
                        }
                        else if (month  ==  9)
                        {
                            month_str = "Sep";
                        }
                        else if (month  ==  10)
                        {
                            month_str = "Oct";
                        }
                        else if (month  ==  11)
                        {
                            month_str = "Nov";
                        }
                        else if (month  ==  12)
                        {
                            month_str = "Dec";
                        }
                        input.example = (("<strong>Example:</strong> " + day + "-" + month_str + "-" + year + " " + hours + ":" + minutes) + ":") + seconds;
                        input.ts = ((day + "-" + month_str + "-" + year + " " + hours + ":" + minutes) + ":") + seconds;
                    }
                    else if (input.timestamp_type  ==  "PT")
                    {
                        input.deluge_script = ("<strong>Deluge Script:</strong> zoho.currenttime.toString().getSuffix(&quot; &quot;)");
                        grab_time = zoho.currenttime;
                        pt = grab_time.getSuffix(" ");
                        input.example = "<strong>Example:</strong> " + pt;
                        input.ts = pt;
                    }
                    else if (input.timestamp_type  ==  "UTC")
                    {
                        input.deluge_script = "<strong>Deluge Script:</strong><br/>" + utc_days_deluge_script + utc_time_deluge_script + utc_time_deluge_script + "<br/>" + "utc_time = hours + &quot;:&quot; + minutes + &quot;:&quot; + seconds;<br/>";
                        grab_time = zoho.currenttime;
                        // see http://answers.google.com/answers/threadview?id=560486
                        epoch_seconds = ((grab_time.toLong()  /  1000)).toLong();
                        days = (epoch_seconds  /  86400);
                        days_int = (days.getPrefix(".")).toLong();
                        day_fraction = (days  -  days_int);
                        secs_left_over = (day_fraction  *  86400);
                        hrs = (secs_left_over  /  3600);
                        hrs_int = (hrs.getPrefix(".")).toLong();
                        hrs_fraction = (hrs  -  hrs_int);
                        hours = hrs_int;
                        secs_left_over = ((hrs_fraction  *  3600)).toLong();
                        mins = (secs_left_over  /  60);
                        mins_int = (((mins)).getPrefix(".")).toLong();
                        mins_fraction = (mins  -  mins_int);
                        minutes = "";
                        if ((((mins_int).toString())).length()  <  2)
                        {
                            minutes = "0" + (mins_int);
                        }
                        else
                        {
                            minutes = (mins_int).toString();
                        }
                        secs_left_over = ((mins_fraction  *  60)).toLong();
                        secs_int = secs_left_over.toLong();
                        seconds = "";
                        if (((secs_int.toString())).length()  <  2)
                        {
                            seconds = "0" + secs_int;
                        }
                        else
                        {
                            seconds = secs_int.toString();
                        }
                        input.example = (("<strong>Example:</strong> " + hours + ":" + minutes) + ":") + seconds;
                        input.ts = ((hours + ":" + minutes) + ":") + seconds;
                    }
                    else if (input.timestamp_type  ==  "PT Date")
                    {
                        input.deluge_script = ("<strong>Deluge Script:</strong> zoho.currenttime.toString().getPrefix(&quot; &quot;)");
                        grab_time = zoho.currenttime;
                        pt_date = grab_time.getPrefix(" ");
                        input.example = "<strong>Example:</strong> " + pt_date;
                        input.ts = pt_date;
                    }
                    else if (input.timestamp_type  ==  "UTC Date")
                    {
                        input.deluge_script = "<strong>Deluge Script:</strong><br/>" + utc_days_deluge_script + utc_date_deluge_script + "utc_date = day + &quot;-&quot; + month_str + &quot;-&quot; + year;";
                        grab_time = zoho.currenttime;
                        // see http://answers.google.com/answers/threadview?id=560486
                        epoch_seconds = ((grab_time.toLong()  /  1000)).toLong();
                        days = (epoch_seconds  /  86400);
                        days_int = (days.getPrefix(".")).toLong();
                        day_fraction = (days  -  days_int);
                        secs_left_over = (day_fraction  *  86400);
                        hrs = (secs_left_over  /  3600);
                        hrs_int = (hrs.getPrefix(".")).toLong();
                        hrs_fraction = (hrs  -  hrs_int);
                        hours = hrs_int;
                        secs_left_over = ((hrs_fraction  *  3600)).toLong();
                        mins = (secs_left_over  /  60);
                        mins_int = (((mins)).getPrefix(".")).toLong();
                        mins_fraction = (mins  -  mins_int);
                        minutes = "";
                        if ((((mins_int).toString())).length()  <  2)
                        {
                            minutes = "0" + (mins_int);
                        }
                        else
                        {
                            minutes = (mins_int).toString();
                        }
                        secs_left_over = ((mins_fraction  *  60)).toLong();
                        secs_int = secs_left_over.toLong();
                        seconds = "";
                        if (((secs_int.toString())).length()  <  2)
                        {
                            seconds = "0" + secs_int;
                        }
                        else
                        {
                            seconds = secs_int.toString();
                        }
                        // see: http://www.jsifaq.com/SF/Tips/Tip.aspx?id=7323
                        a = (days_int  +  2472632);
                        b = (4  *  a  +  3);
                        b = ((b  /  146097)).toLong();
                        c = (((0  -  b)  *  146097)).toLong();
                        c = ((c  /  4)).toLong();
                        c = (c  +  a);
                        d = (4  *  c  +  3);
                        d = ((d  /  1461)).toLong();
                        e = ((0  -  1461)  *  d);
                        e = ((e  /  4)).toLong();
                        e = (e  +  c);
                        m = (5  *  e  +  2);
                        m = ((m  /  153)).toLong();
                        dd = (153  *  m  +  2);
                        dd = ((dd  /  5)).toLong();
                        day = (0  -  dd  +  e  +  1);
                        mm = (((0  -  m)  /  10)).toLong();
                        mm = (mm  *  12);
                        month = (mm  +  m  +  3);
                        year = ((b  *  100  +  d  -  4800  +  m  /  10)).toLong();
                        month_str = "";
                        if (month  ==  1)
                        {
                            month_str = "Jan";
                        }
                        else if (month  ==  2)
                        {
                            month_str = "Feb";
                        }
                        else if (month  ==  3)
                        {
                            month_str = "Mar";
                        }
                        else if (month  ==  4)
                        {
                            month_str = "Apr";
                        }
                        else if (month  ==  5)
                        {
                            month_str = "May";
                        }
                        else if (month  ==  6)
                        {
                            month_str = "Jun";
                        }
                        else if (month  ==  7)
                        {
                            month_str = "Jul";
                        }
                        else if (month  ==  8)
                        {
                            month_str = "Aug";
                        }
                        else if (month  ==  9)
                        {
                            month_str = "Sep";
                        }
                        else if (month  ==  10)
                        {
                            month_str = "Oct";
                        }
                        else if (month  ==  11)
                        {
                            month_str = "Nov";
                        }
                        else if (month  ==  12)
                        {
                            month_str = "Dec";
                        }
                        input.example = "<strong>Example:</strong> " + day + "-" + month_str + "-" + year;
                        input.ts = day + "-" + month_str + "-" + year;
                    }
                    else if (input.timestamp_type  ==  "Epoch")
                    {
                        input.deluge_script = ("<strong>Deluge Script:</strong> ((((zoho.currenttime.toLong ()) / 1000)).toLong())");
                        grab_time = zoho.currenttime;
                        epoch_seconds = ((grab_time.toLong()  /  1000)).toLong();
                        input.example = "<strong>Example:</strong> " + epoch_seconds;
                        input.ts = epoch_seconds.toString();
                    }
                    show example;
                    show deluge_script;
                }
            )

            must  have  ts
            (
                displayname  =  "Stamp"
                type  =  text
                width  =  1
                maxchar  =  50
            )

            example
            (
                type  =  plaintext
            )

            deluge_script
            (
                type  =  plaintext
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide ts;
                        hide example;
                        hide deluge_script;
                        input.instructions = "<ol><li>Select a datestamp or timestamp to view.</li>" + "<li>An example and the Deluge script that created it will be displayed.</li>" + "<li>Submitting your selection will store it in <strong>Stamp Examples" + "</strong>.</li></ol><br/>" + "<p><a href='http://landofzc.wordpress.com'>Back to LoZC</a></p>";
                        if (zoho.loginuser  !=  zoho.adminuser)
                        {
                            app = "The Strings of Time";
                            // REPLACE value with name of this application.
                            frm = "Stamp Selector";
                            // REPLACE value with the name of this form.
                            usr = zoho.loginuser;
                            // The username of the current ZC user.
                            tst = zoho.currenttime.toLong();
                            // A timestamp of the current time.
                            log_entry = "Entry String : " + "App" + "|" + app + "*" + "Form" + "|" + frm + "*" + "User" + "|" + usr + "*" + "Time" + "|" + tst;
                            sendmail
                            (
                                To       :  "landofzc-73@forms.zohocreator.com" 
                                From     :  zoho.adminuserid 
                                Subject  :  "Log Entry" 
                                Message  :  log_entry 
                            )
                        }
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Stamp_Examples
        {
            displayname = "Stamp Examples"
            show  all  rows  from  Stamp_Selector 
            (
                timestamp_type as "Type"
                ts as "Stamp"
            )
            options
            (
                display rows = 100
            )
        }

    }

}
