/*
 * Author       : zchelp
 * Generated on : 22-Nov-2009 20:38:51
 * Version      : 3.0
 */
application "Quiz"
{
    type = public
    date format = "dd-MMM-yyyy"
    time zone = "America/Los_Angeles"
    section Home
    {
        form  Form
        {
            
            Name
            (
                type  =  text
            )

            Qstn1
            (
                type  =  radiobuttons
                values  =  {"Ans1",   "Ans2",   "Ans3"}
                on user input
                {
                    dat = 0;
                    Correct = " ";
                    if (input.Qstn1  ==  "Ans1")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn1, ";
                    }
                    if (input.Qstn2  ==  "Ans2")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn2, ";
                    }
                    if (input.Qstn3  ==  "Ans3")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn3, ";
                    }
                    if (input.Qstn4  ==  "Ans1")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn4";
                    }
                    input.CorrectAnswers = Correct;
                    input.NoofCorrectAnswers = dat;
                }
            )

            Qstn2
            (
                type  =  radiobuttons
                values  =  {"Ans1",   "Ans2",   "Ans3"}
                on user input
                {
                    dat = 0;
                    Correct = " ";
                    if (input.Qstn1  ==  "Ans1")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn1, ";
                    }
                    if (input.Qstn2  ==  "Ans2")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn2, ";
                    }
                    if (input.Qstn3  ==  "Ans3")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn3, ";
                    }
                    if (input.Qstn4  ==  "Ans1")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn4";
                    }
                    input.CorrectAnswers = Correct;
                    input.NoofCorrectAnswers = dat;
                }
            )

            Qstn3
            (
                type  =  radiobuttons
                values  =  {"Ans1",   "Ans2",   "Ans3"}
                on user input
                {
                    dat = 0;
                    Correct = " ";
                    if (input.Qstn1  ==  "Ans1")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn1, ";
                    }
                    if (input.Qstn2  ==  "Ans2")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn2, ";
                    }
                    if (input.Qstn3  ==  "Ans3")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn3, ";
                    }
                    if (input.Qstn4  ==  "Ans1")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn4";
                    }
                    input.CorrectAnswers = Correct;
                    input.NoofCorrectAnswers = dat;
                }
            )

            Qstn4
            (
                type  =  radiobuttons
                values  =  {"Ans1",   "Ans2",   "Ans3"}
                on user input
                {
                    dat = 0;
                    Correct = " ";
                    if (input.Qstn1  ==  "Ans1")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn1, ";
                    }
                    if (input.Qstn2  ==  "Ans2")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn2, ";
                    }
                    if (input.Qstn3  ==  "Ans3")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn3, ";
                    }
                    if (input.Qstn4  ==  "Ans1")
                    {
                        dat = (dat  +  1);
                        Correct = Correct + "Qstn4";
                    }
                    input.CorrectAnswers = Correct;
                    input.NoofCorrectAnswers = dat;
                }
            )

            NoofCorrectAnswers
            (
                type  =  number
                width  =  20
            )

            CorrectAnswers
            (
                type  =  text
            )

            Grade
            (
                type  =  text
            )

            Performance
            (
                type  =  decimal
                width  =  20
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide CorrectAnswers;
                        hide NoofCorrectAnswers;
                        hide Grade;
                        hide Performance;
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on validate
                        {
                            //You can drag and drop tasks from the immediate left pane
                            //Below is the SAMPLE validation script
                            if (input.NoofCorrectAnswers  ==  4)
                            {
                                input.Grade = ("A+");
                            }
                            else if (input.NoofCorrectAnswers  ==  3)
                            {
                                input.Grade = "A";
                            }
                            else if (input.NoofCorrectAnswers  ==  2)
                            {
                                input.Grade = "B";
                            }
                            else if (input.NoofCorrectAnswers  ==  1)
                            {
                                input.Grade = "C";
                            }
                            else if (input.NoofCorrectAnswers  ==  0)
                            {
                                input.Grade = "Fail";
                            }
                            input.Performance = (input.NoofCorrectAnswers  /  4  *  100);
                        }
                        on success
                        {
                            sendmail
                            (
                                To       :  "harshavardhan@adventnet.com" 
                                From     :  zoho.adminuserid 
                                Subject  :  "Subject of the email" 
                                Message  :  input.Name + "<br />Number of Correct Answers : " + input.NoofCorrectAnswers + "<br />QuestionsAnsweredCorrectly  :" + input.CorrectAnswers 
                            )
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Form_View
        {
            displayname = "Form View"
            show  all  rows  from  Form 
            (
                Name
                NoofCorrectAnswers
                CorrectAnswers
                Qstn1
                Qstn2
                Qstn3
                Qstn4
                Grade
                Performance
            )
            filters 
            (
                Qstn1
                Qstn2
                Qstn3
                Qstn4
            )
            options
            (
                display rows = 100
            )
        }

    }

}
