/*
 * Author       : zohocreator
 * Generated on : 23-Nov-2009 08:52:50
 * Version      : 3.0
 */
application "Student Management"
{
    type = public
    allow html = true
    date format = "dd-MMM-yyyy"
    time zone = "America/Los_Angeles"
    section Students
    {
        list  Student_View
        {
            displayname = "Student View"
            show  all  rows  from  Student 
            (
                Name
                Country
                Detailed_View_Link
            )
            options
            (
                display rows = 100
            )
        }

        form  Student
        {
            
            Name
            (
                type  =  text
                width  =  25
                tooltip  =  "Web application"
            )

            Country
            (
                type  =  text
                width  =  25
                tooltip  =  "Web application"
            )

            Detailed_View_Link
            (
                type  =  formula
                value  =  "<a href='#View:Detailed_Student_View?student_id=" + ID + "'>Detailed View</a>"
            )

            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"
                    )
                }
            }
        }

    }

    section Courses
    {
        list  Course_View
        {
            displayname = "Course View"
            show  all  rows  from  Course 
            (
                Name
                Description
                Detailed_View_Link
            )
            options
            (
                display rows = 100
            )
        }

        form  Course
        {
            
            Name
            (
                type  =  text
                width  =  25
                tooltip  =  "Web application"
            )

            Description
            (
                type  =  textarea
            )

            Detailed_View_Link
            (
                type  =  formula
                value  =  "<a href='#View:Detailed_Course_View?course_id=" + ID + "'>Detailed View</a>"
            )

            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"
                    )
                }
            }
        }

    }

    section Student_Courses
    {
        displayname = "Student Courses"
        list  Student_Course_View
        {
            displayname = "Student Course View"
            show  all  rows  from  Student_Course 
            (
                Student
                Course
                Year
                Grade
            )
            filters 
            (
                Course
                Student
            )
            options
            (
                display rows = 100
            )
            permission
            (
                edit = true
            )
        }

        form  Student_Course
        {
            displayname  =  "Student Course"
            
            Year
            (
                type  =  number
                width  =  20
                maxchar  =  99
                tooltip  =  "Web application"
            )

            Grade
            (
                type  =  picklist
                values  =  {"A",   "B",   "C"}
                tooltip  =  "Web application"
            )

            Course
            (
                type  =  picklist
                values  =  Course.Name
            )

            Student
            (
                type  =  picklist
                values  =  Student.Name
            )

            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"
                    )
                }
            }
        }

        list  CombinedView
        {
            show  all  rows  from  Student_Course 
            (
                Year
                Grade
                Course
                Student
                Course.Description as "Course Description"
                Student.Country as "Student Country"
            )
            filters 
            (
                Grade
                Course
                Student
            )
            options
            (
                display rows = 100
            )
        }

    }

    section Hidden_Section
    {
        displayname = "Hidden Section"
        hide = true
        htmlpage Detailed_Student_View(student_id)
displayname = "Detailed Student View"
content
        <%{%>
<%students  =  Student  [ID == input.student_id.toLong()];%>
<table cellpadding=3 cellspacing=3 width="100%" height="100%">
<tr><td>    
<table width="100%" height="100%">
<tr><td width="50%" align="left">
<b><u><a  href="#View:Student_View"><< Back</a></u></b>
</table>    
</td></tr>
<tr><td align="center">
<span style="font-size:17;font-weight:bold"><u>Detailed Student View</u></span>
</td></tr>
<tr><td>    
<table width="100%"><tr><td>
<span style="font-size:17;font-weight:bold">Student Detail:</span>
</td></tr>
<tr><td>
<div elName='zc-component' viewLinkName='Embedded_Student_View' params='ID=<%=student_id%>&zc_Header=false&zc_Footer=false&zc_SecHeader=false&zc_AddRec=false&zc_EditRec=true&zc_DelRec=false&zc_DuplRec=false&zc_EditBulkRec=false&zc_Filter=false&zc_Search=false&zc_Paging=false&zc_RecLimit=false&zc_SumRow=false&zc_Summary=false&zc_RecSelect=false&zc_AltRowClr=false&zc_SaveRec=false'>Loading View...</div>    
</td></tr>
</table>

</td></tr>
<tr><td>    
<table width="100%" height="100%"><tr><td>
<span style="font-size:17;font-weight:bold">Courses Subscribed:</span>   <b><u><a  href="#Form:Student_Course?Student=<%=students.Name%>&zc_NextUrl=#View:Detailed_Student_View?student_id=<%=student_id%>">Add</a></u></b>
</td>
</tr>
<tr>
<td>
<div elName='zc-component' viewLinkName='Student_Course_View' params='zc_Header=false&zc_AddRec=false&zc_DuplRec=false&zc_Filter=false&Student=<%=students.Name%>&hideColumns=Student;'>Loading View...</div>    
</td></tr></table>

</td></tr>
</table>        <%}%>

        list  Embedded_Student_View
        {
            displayname = "Embedded Student View"
            show  all  rows  from  Student 
            (
                Name
                Country
                ID
            )
            options
            (
                display rows = 100
            )
            permission
            (
                edit = true
            )
        }

        list  Embedded_Course_View
        {
            displayname = "Embedded Course View"
            show  all  rows  from  Course 
            (
                Name
                Description
                ID
            )
            options
            (
                display rows = 100
            )
            permission
            (
                edit = true
            )
        }

        htmlpage Detailed_Course_View(course_id)
displayname = "Detailed Course View"
content
        <%{%>
<%coursevar  =  Course  [ID == input.course_id.toLong()];%>
<table cellpadding=3 cellspacing=3 width="100%" height="100%">
<tr><td>    
<table width="100%" height="100%">
<tr><td width="50%" align="left">
<b><u><a  href="#View:Student_View"><< Back</a></u></b>
</table>    
</td></tr>
<tr><td align="center">
<span style="font-size:17;font-weight:bold"><u>Detailed Course View</u></span>
</td></tr>
<tr><td>    
<table width="100%"><tr><td>
<span style="font-size:17;font-weight:bold">Course Detail:</span>
</td></tr>
<tr><td>
<div elName='zc-component' viewLinkName='Embedded_Course_View' params='ID=<%=course_id%>&zc_Header=false&zc_Footer=false&zc_SecHeader=false&zc_AddRec=false&zc_EditRec=true&zc_DelRec=false&zc_DuplRec=false&zc_EditBulkRec=false&zc_Filter=false&zc_Search=false&zc_Paging=false&zc_RecLimit=false&zc_SumRow=false&zc_Summary=false&zc_RecSelect=false&zc_AltRowClr=false&zc_SaveRec=false'>Loading View...</div>    
</td></tr>
</table>

</td></tr>
<tr><td>    
<table width="100%" height="100%"><tr><td>
<span style="font-size:17;font-weight:bold">Students Subscribed:</span>   <b><u><a  href="#Form:Student_Course?Course=<%=coursevar.Name%>&zc_NextUrl=#View:Detailed_Course_View?course_id=<%=course_id%>">Add</a></u></b>
</td>
</tr>
<tr>
<td>
<div elName='zc-component' viewLinkName='Student_Course_View' params='zc_Header=false&zc_AddRec=false&zc_DuplRec=false&zc_Filter=false&Course=<%=coursevar.Name%>&Course=&hideColumns=Course;'>Loading View...</div>    
</td></tr></table>

</td></tr>
</table>        <%}%>

        form  Select_Country
        {
            displayname  =  "Select Country"
            store data in zc = false
            
            must  have  Country
            (
                type  =  picklist
                values  =  Student.Country
            )

            actions
            {
                on load
                {
                    countryList = List();
                    for each x in Student  [ID > 0]
                    {
                        if (!countryList.contains(x.Country))
                        {
                            countryList.add(x.Country);
                        }
                    }
                    for each elem in countryList
                    {
                        Country:ui.add(elem);
                    }
                }
                Apply
                (
                    type  =  submit
                    displayname  =  "Apply"
                    on click
                    {
                        openUrl(("#View:CountryChart?country=") + input.Country, "same window");
                    }
                )
            }
        }

    }

    section Reports
    {
        list  Grouped_By_Course
        {
            displayname = "Grouped By Course"
            show  all  rows  from  Student_Course 
            (
                Course
                Student
                Year
                Grade
                Student.Country
                Student.Detailed_View_Link as "Student summary"
            )
            filters 
            (
                Grade
                Course
                Student
            )
            group by
            (
                Course   ascending
            )
            options
            (
                display rows = 100
            )
            custom actions
            (
                "send mail"
                (
                    function = sendnotification(Added_User)
                    show action in view header = true
                    show action for each record = false
                )
            )
        }

        list  Grouped_By_Student
        {
            displayname = "Grouped By Student"
            show  all  rows  from  Student_Course 
            (
                Year
                Grade
                Course
                Student
                Course.Description as "Course Description"
                Course.Detailed_View_Link as "Course Summary"
            )
            filters 
            (
                Grade
                Course
                Student
            )
            group by
            (
                Student   ascending
            )
            options
            (
                display rows = 100
            )
        }

        list  Grouped_By_Country
        {
            displayname = "Grouped By Country"
            show  all  rows  from  Student_Course 
            (
                Course
                Student
                Year
                Grade
                Student.Country
            )
            filters 
            (
                Grade
                Course
                Student
            )
            group by
            (
                Student.Country   ascending
                Course   ascending
            )
            options
            (
                display rows = 100
            )
        }

    }

    section Charts
    {
        htmlpage CountryChart(country)
        <%{%>
<table width="100%">
<tr><td align="left">
<div elName='zc-component' formLinkName='Select_Country' params='zc_Header=true&zc_SuccMsg=Country Selected&zc_SubmitVal=Submit&zc_ResetVal=Reset'>Loading Form...</div>
</td></tr><%if (input.country  !=  null)
            {
                if (input.country  !=  "")
                {
                    enrolmentChart = thisapp.getChartUrl(input.country);%>
<tr><td>
<table cellpadding=0 cellspacing=0 width="100%"><tr><td width="100%"><img src='<%=enrolmentChart%>'/></td></tr></table>
</td></tr>                <%}
            }%>
</table>        <%}%>

    }

    functions
    {
        string getChartUrl(string country)
        {
            courseRecs  =  Course  [ID > 0];
            courseList = courseRecs.Name.getall();
            graphType = "BAR3D";
            width = "300";
            height = "300";
            data = "Courses" + "," + "Students Enrolled";
            for each key in courseList
            {
                cc = count(Student_Course[(Student.Country == input.country && Course == key)]);
                data = data + "%0A" + key + "," + cc;
            }
            url = (("http://sheet.zoho.com/zohochart.do?xlabel=Courses&ylabel=Students&title=Students Enrolled in Different Courses in " + input.country) + "&charttype=") + graphType;
            url = url + "&width=" + width + "&height=" + height;
            url = url + "&chartdata=" + data;
            return url;
        }

        void sendnotification(string toaddress)
        {
            sendmail
            (
                To       :  input.toaddress 
                From     :  zoho.adminuserid 
                Subject  :  "Hai, There" 
                Message  :  "This is a notification mail generated from zohocreator" 
            )
        }

    }

    customize
    {
        layout = "tab"
        base theme = "professional"
        color = "blue"
    }
}
