/*
 * Author       : hariharan
 * Generated on : 23-Nov-2009 03:59:09
 * Version      : 3.0
 */
application "Library Manager"
{
    type = public
    allow html = true
    date format = "dd-MMM-yyyy"
    time zone = "America/Los_Angeles"
    section About_Library_Manager
    {
        displayname = "About Library Manager"
        form  form_90084
        {
            displayname  =  ""
            
            PlainText
            (
                type  =  plaintext
                value = "<div style=\"text-align: center;\"><span style=\"font-weight: bold; text-decoration: underline;\">Welcome to our library manager<br><br></span></div> This library manager is created from scratch using click and drag functionality of zohocreator and enriched with a few lines of deluge script to give completeness.<br> If you are a college librarian and searching for a developer to design your customized library manager, just drop that idea , copy this application and customize it to your need.It is perfectly suitable for small to medium sized libraries such as in-house company library or college library. <br> <br> Do you ask, what is deluge? It is a domain specific scripting language for creating form based web application.We have taken care of all the underlying details and have exposed to user only a fine set of trivial tasks in deluge to make application building easier.<a href=\"../../../help/deluge/index.html\">Read More</a>.<br> <br style=\"color: rgb(0, 0, 0);\"><span style=\"font-weight: bold; color: rgb(0, 0, 0); text-decoration: underline;\"> About library manager</span><br> It has the following tabs. <br> <ul><li>Book Admin - Maintains the details of the books available with the library. <br>   </li><li>User Admin -  Maintains the details of users registered with the library.<br>   </li><li>Issue-Return Book - Takes care of the day to day transaction of the library.<br>   </li><li>Search - More useful to the library users than administrator. It helps to search for the books along with its availability status in library.<br>   </li><li>Old Transaction - This is just for the record purpose. It maintains the log of all the transaction done on the books.<br>   </li></ul> We have provided explanation on the implementation details, especially on the deluge scripting part in each tabs separately. You should have a look at the&nbsp; 'Issue-Return' tab that uses more scripting intelligence than any other tab.\n"
            )

            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 Book_Admin
    {
        displayname = "Book Admin"
        form  form_84930
        {
            displayname  =  ""
            
            PlainText
            (
                type  =  plaintext
                value = "<span style=\"font-weight: bold;\">Deluge questionnaire: <br></span>1 ).In the 'Add Book' form, how is the field 'Status' have the option 'Available' selected by default?<br>ans). Done in the '<a href=\"http://blogs.zoho.com/creator/zoho-creator-creating-ajax-forms/\">On Load</a>' action for the 'Add Book' form using the 'Set field = value' syntax.<br><br><span style=\"font-weight: bold;\"></span>\n"
            )

            Formula
            (
                displayname  =  "-"
                type  =  formula
                value  =  zoho.loginuser
            )

            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  Authors1
        {
            displayname = "Authors"
            show  all  rows  from  Author 
            (
                Name
                Country
                Gender
            )
            options
            (
                display rows = 100
            )
            permission
            (
                add = true
                edit = true
                delete = true
            )
        }

        list  Categories1
        {
            displayname = "Categories"
            show  all  rows  from  Category 
            (
                Name
            )
            options
            (
                display rows = 100
            )
            permission
            (
                add = true
                edit = true
                delete = true
            )
        }

        form  Book
        {
            displayname  =  "Add Book"
            
            unique  Name
            (
                type  =  text
            )

            Author
            (
                type  =  picklist
                values  =  Author.Name
            )

            must  have  Category
            (
                type  =  picklist
                values  =  Category.Name
            )

            must  have  Status
            (
                type  =  picklist
                values  =  {"Available",   "Issued"}
            )

            must  have  Language
            (
                type  =  picklist
                values  =  {"English",   "Tamil"}
            )

            AddedDate
            (
                type  =  date
            )

            Remarks
            (
                type  =  textarea
            )

            actions
            {
                on add
                {
                    on load
                    {
                        input.Language = "English";
                        input.Status = "Available";
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on success
                        {
                            sendmail
                            (
                                To       :  "hariharan@adventnet.com" 
                                From     :  zoho.adminuserid 
                                Subject  :  "hai" 
                                Message  :  "hai" + input.formdata 
                            )
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Author
        {
            displayname  =  "Add Author"
            
            must  have  Name
            (
                type  =  text
                width  =  53
            )

            Country
            (
                type  =  picklist
                values  =  {"US",   "India",   "Rest"}
            )

            Gender
            (
                type  =  radiobuttons
                values  =  {"male",   "female"}
            )

            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  Category
        {
            displayname  =  "Add Category"
            
            must  have  Name
            (
                type  =  text
            )

            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 User_Admin
    {
        displayname = "User Admin"
        form  form_84931
        {
            displayname  =  ""
            
            PlainText
            (
                type  =  plaintext
                value = "<span class=\"zoho-plaintext\" id=\"form_84930:PlainText__comp\" type=\"plaintext\"><span style=\"font-weight: bold;\">Deluge questionnaire:<br></span></span><span class=\"zoho-plaintext\" id=\"form_84930:PlainText__comp\" type=\"plaintext\">1 ).When I register my name here, how do i receive a welcome mail?<br>ans).It it due to the '<a href=\"http://www.zohocreator.com/help/deluge/index.html?url=sendmail.html\">Sendmail</a>' function written in the '<a href=\"http://www.zohocreator.com/help/deluge/index.html?url=form_success.html\">on success</a>' event of the 'Add User' form<br></span>\n"
            )

            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  User
        {
            displayname  =  "Add User"
            
            must  have  unique  Name
            (
                type  =  text
            )

            must  have  Passwrd
            (
                type  =  text
            )

            must  have  Mailid
            (
                type  =  email
            )

            Gender
            (
                type  =  picklist
                values  =  {"male",   "female"}
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on success
                        {
                            sendmail
                            (
                                To       :  input.Mailid 
                                From     :  zoho.adminuserid 
                                Subject  :  "Welcome" 
                                Message  :  "Hello " + input.Name + ",<br><br> Welcome to my library manager <br><br> Your usename: " + input.Name + "<br> Your password: " + input.Passwrd + "<br><br> You can access the library manager at http://www.zohocreator.com/hariharan/librarymanager<br><br> Best Regards,<br> Administrator<br> Library Manager" 
                            )
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Users1
        {
            displayname = "Users"
            show  all  rows  from  User 
            (
                Mailid
                Name
                Gender
                Passwrd
            )
            options
            (
                display rows = 100
            )
            permission
            (
                add = true
                edit = true
                delete = true
            )
        }

    }

    section Issue_Return_Book
    {
        displayname = "Issue - Return Book"
        form  form_84932
        {
            displayname  =  ""
            
            PlainText
            (
                type  =  plaintext
                value = "<span class=\"zoho-plaintext\" id=\"form_84931:PlainText__comp\" type=\"plaintext\"><span class=\"zoho-plaintext\" id=\"form_84930:PlainText__comp\" type=\"plaintext\"><span style=\"font-weight: bold;\">Deluge questionnaire:<br></span>1).In the 'Issue Book' form, the field 'issuedate' is not shown to the user for filling. How is the value set for this field?<br>ans).Done with the help of the <a href=\"http://www.zohocreator.com/help/deluge/index.html?url=updatefield.html\">deluge field modification</a> task in the '<a href=\"http://www.zohocreator.com/help/deluge/index.html?url=form_success.html\">on success</a>' event. <a href=\"http://blogs.zoho.com/creator/zoho-creator-modify-data-across-forms/\">Read related blog post</a>.<br><br>2).When the 'Issue Book' form is successfully submitted, how is the 'Status' field of the corresponding book modified from 'Available' to 'Issued'?<br>ans).Done with the help of the</span></span><span class=\"zoho-plaintext\" id=\"form_84931:PlainText__comp\" type=\"plaintext\"><span class=\"zoho-plaintext\" id=\"form_84930:PlainText__comp\" type=\"plaintext\"> <a href=\"../../../help/deluge/index.html?url=updatefield.html\">deluge field modification</a> task in the '<a href=\"../../../help/deluge/index.html?url=form_success.html\">on success</a>' event. <a href=\"http://blogs.zoho.com/creator/zoho-creator-modify-data-across-forms/\">Read related blog post</a>.</span></span>\n"
            )

            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  Issued
        {
            displayname  =  "Issue ssBook"
            
            must  have  book
            (
                displayname  =  "Name of the book"
                type  =  picklist
                values  =  Book[Status == "Available"].Name
            )

            must  have  user
            (
                displayname  =  "Issued to user"
                type  =  picklist
                values  =  User.Name
            )

            issuedate
            (
                displayname  =  "Issue date"
                type  =  datetime
            )

            Return_date
            (
                displayname  =  "Return date"
                type  =  datetime
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide issuedate;
                        hide Return_date;
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on validate
                        {
                            if (count(Issued[(book == input.book && (Return_date is null))])  >  0)
                            {
                                alert "This book is already issued";
                                cancel submit;
                            }
                            if (count(Issued[(user == input.user && (Return_date is null))])  >  2)
                            {
                                alert "User quota limit exceeded - A single user cannot book more than 3 books";
                                cancel submit;
                            }
                        }
                        on success
                        {
                            input.issuedate = zoho.currenttime;
                            myBook  =  Book  [Name == input.book];
                            myBook.Status = "Issued";
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Return_Book
        {
            displayname  =  "Return Book"
            
            Select_the_Book
            (
                displayname  =  "Select the book to return"
                type  =  picklist
                values  =  Book[Status == "Issued"].Name
                on user input
                {
                    iss  =  Issued  [(book == input.Select_the_Book && (Return_date is null))];
                    if (iss.book  !=  null)
                    {
                        input.viewdetails = "<h3>" + "Issued to : <i>" + iss.user + "</i> on <i>" + iss.issuedate + "</i></h3>";
                    }
                    else
                    {
                        input.viewdetails = "Select a valid book";
                    }
                }
            )

            viewdetails
            (
                type  =  plaintext
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on success
                        {
                            iss  =  Issued  [(book == input.Select_the_Book && (Return_date is null))];
                            iss.Return_date = zoho.currenttime;
                            mybook  =  Book  [Name == input.Select_the_Book];
                            mybook.Status = "Available";
                            info "This book issued to : " + iss.user + " returned successfully";
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

    }

    section Search
    {
        list  Available_Books
        {
            displayname = "Available Books"
            show  all  rows  from  Book [Status == "Available"]
            (
                Name
                Author
                Category
                Language
                AddedDate
                Remarks
                Added_Time as "Added Time"
            )
            options
            (
                display rows = 100
            )
            permission
            (
                add = true
                edit = true
                delete = true
            )
        }

        list  Books_Issued_Details
        {
            displayname = "Books Issued Details"
            show  all  rows  from  Issued [(Return_date is null)]
            (
                book as "Name of the book"
                user as "Issued to"
                issuedate as "Issue date"
                book.Author as "Written By"
                book.Category
                book.Language
                book.AddedDate as "Added On"
                book.Remarks
                Added_Time as "Added Time"
            )
            options
            (
                display rows = 100
            )
            permission
            (
                add = true
                edit = true
                delete = true
            )
        }

        list  Copy_of_Available_Books
        {
            displayname = "Copy of Available Books"
            show  all  rows  from  Book [Name.contains("City")]
            (
                Name
                Author
                Category
                Status
                Language
                AddedDate
                Remarks
            )
            filters 
            (
                Author
                Category
                Status
                Language
            )
            options
            (
                display rows = 100
            )
            permission
            (
                add = true
                duplicate = true
                edit = true
                bulk edit = true
                delete = true
            )
        }

    }

    section Old_Transaction
    {
        displayname = "Old Transaction"
        list  Transaction_History
        {
            displayname = "Transaction History"
            show  all  rows  from  Issued [(Return_date is not null)]
            (
                book as "Name of the book"
                user as "Issued to"
                issuedate as "Issue date"
                Return_date as "Return date"
            )
            options
            (
                display rows = 100
            )
            permission
            (
                add = true
                edit = true
                delete = true
            )
        }

        summary  TranHi1
        {
            displayname = "TranHi"
            show  all  rows  from  Book 
            (
                Name
                Author
                Category
                Status
                Language
                AddedDate
                Remarks
            )
            filters 
            (
                Author
                Category
                Status
                Language
                AddedDate
            )
            options
            (
                display rows = 100
            )
            permission
            (
                add = true
                edit = true
                delete = true
            )
        }

    }

    customize
    {
        layout = "tab"
        base theme = "gradient"
        color = "yellow"
    }
}
