/*
 * Author       : sharetactics
 * Generated on : 22-Nov-2009 19:20:59
 * Version      : 3.0
 */
application "Airport Weather"
{
    type = public
    allow html = true
    date format = "dd-MMM-yyyy"
    time zone = "America/Los_Angeles"
    section NWS_Query
    {
        displayname = "NWS Query"
        form  UI
        {
            displayname  =  "Send Weather Request"
            success message  =  "Weather Report Requested"
            
            blogLink
            (
                type  =  plaintext
                value = "<br>\n"
            )

            page_intro
            (
                type  =  plaintext
                value = "<span style=\"font-family: arial,helvetica,sans-serif; font-weight: bold;\"></span><font size=\"2\"><span style=\"font-family: arial,helvetica,sans-serif;\">This page will send your request for the latest available weather conditions to<br>the United States' <span style=\"font-weight: bold;\">National Weather Service</span> for processing.&nbsp;&nbsp; The response <br>will </span></font><font size=\"2\"><span style=\"font-family: arial,helvetica,sans-serif;\">appear in  <span style=\"font-weight: bold;\">NWS Reports</span> but may take </span></font><font size=\"2\"><span style=\"font-family: arial,helvetica,sans-serif;\">several minutes or longer to appear.<br></span></font><br>\n"
            )

            plain
            (
                type  =  plaintext
                value = "Select a country:<br>\n"
            )

            Country
            (
                type  =  picklist
                values  =  Just_Countries.SingleLine1
                on user input
                {
                    //You can drag and drop tasks from the immediate left pane
                    //Below is the SAMPLE script for dynamic, condition based field manipulation
                    input.airportMessage = "Select an airport in " + input.Country;
                    show airportMessage;
                    show Airport;
                    for each c in Weather_Form  [Countries == input.Country]
                    {
                        Airport:ui.add(c.Airports);
                    }
                }
            )

            airportMessage
            (
                type  =  plaintext
                value = "<br>\n"
            )

            Airport
            (
                type  =  picklist
                values  =  Weather_Form.Airports
                on user input
                {
                    airports  =  Weather_Form  [Airports == input.Airport];
                    input.Commands = (("reply sharetactics-947@forms.zohocreator.com\nopen\ncd data\ncd observations\ncd metar\ncd decoded\nget ") + airports.ICAO_Codes) + ".TXT\nquit";
                    input.submitMessage = "Click Submit to request the latest weather information available for " + input.Airport + " airport in " + input.Country + ".";
                    show submitMessage;
                }
            )

            submitMessage
            (
                type  =  plaintext
            )

            FTPMail
            (
                type  =  text
                defaultvalue  =  "ftpmail@weather.noaa.gov"
            )

            Commands
            (
                type  =  textarea
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide airportMessage;
                        hide Airport;
                        hide Commands;
                        hide FTPMail;
                        hide submitMessage;
                        input.blogLink = "<a href='http://sharetactics.wordpress.com/2007/07/11/talking-to-zoho-creator-with-email/'>Talking to Zoho Creator with Email</a>";
                        if (zoho.loginuser  !=  zoho.adminuser)
                        {
                            app = "Airport Weather";
                            // REPLACE value with name of this application.
                            frm = "Send Weather Report";
                            // 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"
                        on success
                        {
                            //You can drag and drop tasks from the immediate left pane
                            //Below is the SAMPLE email notification
                            sendmail
                            (
                                To       :  input.FTPMail 
                                From     :  zoho.adminuserid 
                                Subject  :  "Weather Request" 
                                Message  :  input.Commands 
                            )
                            success message "Weather Report Requested.";
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

    }

    section NWS_Reports
    {
        displayname = "NWS Reports"
        summary  Requested_Weather_Reports
        {
            displayname = "Requested Weather Reports"
            show  all  rows  from  Weather_Database 
            (
                created as "Date Received"
                Country
                Airport
                Temperature
                Wind
                Skyconditions as "Sky conditions"
                DewPoint as "Dew Point"
                Visibility
                RelativeHumidity as "Relative Humidity"
                Pressurealtimeter as "Pressure (altimeter)"
            )
            options
            (
                display rows = 100
            )
        }

    }

    section Data
    {
        displayname = "___Data"
        hide = true
        form  Just_Countries
        {
            displayname  =  "___Countries"
            captcha = true
            
            SingleLine1
            (
                displayname  =  "Countries"
                type  =  text
                private  =  true
            )

            Dropdown_1
            (
                displayname  =  "Dropdown 1"
                type  =  picklist
                values  =  {"Option 1",   "Option 2",   "Option 3"}
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Weather_Form
        {
            displayname  =  "___Locations"
            captcha = true
            
            ICAO_Codes
            (
                displayname  =  "ICAO Codes"
                type  =  text
                private  =  true
                width  =  25
                tooltip  =  "Web application"
            )

            Countries
            (
                type  =  text
                private  =  true
                width  =  25
                tooltip  =  "Web application"
            )

            Airports
            (
                type  =  text
                private  =  true
                width  =  25
                tooltip  =  "Web application"
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Weather_Database
        {
            displayname  =  "___Weather Reports"
            
            column
            {
                Country
                (
                    type  =  text
                )

                Airport
                (
                    type  =  text
                )

                UTCTime
                (
                    type  =  formula
                    value  =  (((ob.getSuffix(" ")).getPrefix(" ")).removeLastOccurence("Z")) + " UTC"
                )

                Temperature
                (
                    type  =  text
                )

                Wind
                (
                    type  =  text
                )

                DewPoint
                (
                    displayname  =  "Dew Point"
                    type  =  text
                )

                cycle
                (
                    type  =  text
                )

            }
            column
            {
                Skyconditions
                (
                    displayname  =  "Sky conditions"
                    type  =  text
                )

                Visibility
                (
                    type  =  text
                )

                RelativeHumidity
                (
                    displayname  =  "Relative Humidity"
                    type  =  text
                )

                Pressurealtimeter
                (
                    displayname  =  "Pressure (altimeter)"
                    type  =  text
                )

                must  have  ob
                (
                    type  =  text
                )

                created
                (
                    type  =  formula
                    value  =  zoho.currenttime
                )

                timestamp
                (
                    type  =  formula
                    value  =  zoho.currenttime.toLong()
                )

            }
            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on success
                        {
                            lookup  =  Weather_Form  [ICAO_Codes == input.ob.getPrefix(" ")];
                            empty_countries  =  Weather_Database  [((Country is null) && (Airport is null))];
                            empty_countries.Country = lookup.Countries;
                            empty_countries.Airport = lookup.Airports;
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

    }

}
