Пример #1
0
    lunchlib.write_js('''
        function goToDetailedReport(form) {
            // check to see if the start month is written correctly:
            if (/^\d{4}-\d{2}$/.test(form.start_month.value)) {
                // if the format is correct, split up the string:
                bits = form.start_month.value.split('-');

                // use the parts to construct a new date object to compare to
                // the current date. Note that the constructor assumes that
                // January is the 0th month, so subtract 1.
                // Also give the "day" paramater a value of the 1st
                // of the month
                var testDate = new Date(bits[0], bits[1]-1, 1);

                // supplied month should not be in the future.
                // note that we don't care how far in the past it is.
                if (testDate > new Date()) {
                    alert("month is in the future.");
                    return;
                }
            }
            else {
                // return if the format is incorrect:
                alert("invalid start month format.");
                return;
            }

            // check to see if "end month" parameter is present.
            // If so, check its format as well. Note we don't care
            // if it is in the future.
            if (/^\s*$/.test(form.end_month.value) == false &&
                /^\d{4}-\d{2}$/.test(form.end_month.value) == false) {
                alert("invalid end month format.");
                return;
            }

            // if all is ok then call the report generation script:
            form.setAttribute("action", "detailedReport.py");
            form.submit();
        }

        // do not run the report and go back to the main menu:
        function cancel(form) {
            form.setAttribute("action", "menu.py")
            form.submit();
        }
    ''')
Пример #2
0
                'lunch_date': ldate,
                'amount': amount
            }

            if db.insert("lunch_expenses", updValues) == None:
                status_message = status_message + \
                                 "Problem inserting row to database"
            else:
                status_message = status_message + "New entry for " + \
                                 ldate + " inserted successfully!"

            # write out the html page:
            lunchlib.write_js('''
                function goToMainMenu(form) {
                    // go back to main menu:
                    form.setAttribute("action", "menu.py");
                    form.submit();
                }
            ''')

            # html header
            lunchlib.write_head_uname(uname)

            # information message
            print status_message

            # form to go back to main menu
            lunchlib.write_form('''
                <p><input type="button" value="OK" onClick="goToMainMenu(this.form)">
                <p><input type="hidden" name="uname" value="''' + uname + '''">
            ''')
Пример #3
0
else:
    uname = arguments["uname"].value
    start_month = arguments["start_month"].value

    # grab the end month if it has been supplied,
    # otherwise default to the same as the start month:
    if "end_month" not in arguments:
        end_month = start_month
    else:
        end_month = arguments["end_month"].value

    # write javascript for going back to main menu:
    lunchlib.write_js(
        """
        function goToMainMenu(form) {
            form.setAttribute("action", "menu.py");
            form.submit();
        }
    """
    )

    # write html header
    lunchlib.write_head_uname(uname)

    try:
        # connect to the database
        db = pg.DB(dbname=lunchlib.dbname, host=lunchlib.dbhost, user=lunchlib.dbuser, passwd=lunchlib.dbpasswd)

        # report header
        print "Report for user: <b>" + uname + "</b> for period: <b>" + start_month + " to " + end_month + "</b><br/><br/>"

        # form to go back to main menu
Пример #4
0
            lunchlib.write_fail("No such user")
        else:
            # password should be in the first and only field of the
            # first and only row:
            retrievedpw = rows[0][0]

            # verify that supplied password is the same as the retrieved one:
            if not hashpw(passwd, retrievedpw) == retrievedpw:
                # if not, write out some html informing of a mismatch:
                lunchlib.write_fail("Incorrect password")
            else:
                # otherwise write out some html informing of a success
                lunchlib.write_js('''
                    function goToMainMenu(form) {
                            // proceed to main menu when button is pressed:
                            form.setAttribute("action", "menu.py");
                            form.submit();
                    }
                ''')
                lunchlib.write_head_uname(uname)

                lunchlib.write_form('''
                    <p><input type="button" value="OK" onClick="goToMainMenu(this.form)">
                    <p><input type="hidden" name="uname" value="''' + uname + '''">
                ''')

                lunchlib.write_tail()

        # close database connection:
        db.close()
    except pg.InternalError:
Пример #5
0
            lunchlib.write_fail("No such user")
        else:
            # password should be in the first and only field of the
            # first and only row:
            retrievedpw = rows[0][0]

            # verify that supplied password is the same as the retrieved one:
            if not hashpw(passwd, retrievedpw) == retrievedpw:
                # if not, write out some html informing of a mismatch:
                lunchlib.write_fail("Incorrect password")
            else:
                # otherwise write out some html informing of a success
                lunchlib.write_js('''
                    function goToMainMenu(form) {
                            // proceed to main menu when button is pressed:
                            form.setAttribute("action", "menu.py");
                            form.submit();
                    }
                ''')
                lunchlib.write_head_uname(uname)

                lunchlib.write_form('''
                    <p><input type="button" value="OK" onClick="goToMainMenu(this.form)">
                    <p><input type="hidden" name="uname" value="''' + uname +
                                    '''">
                ''')

                lunchlib.write_tail()

        # close database connection:
        db.close()
Пример #6
0
            # now insert the new entry to the database:
            updValues = {'emp_id':emp_id, 'lunch_date':ldate, 'amount':amount}

            if db.insert("lunch_expenses", updValues) == None:
                status_message = status_message + \
                                 "Problem inserting row to database"
            else:
                status_message = status_message + "New entry for " + \
                                 ldate + " inserted successfully!"

            # write out the html page:
            lunchlib.write_js('''
                function goToMainMenu(form) {
                    // go back to main menu:
                    form.setAttribute("action", "menu.py");
                    form.submit();
                }
            ''')

            # html header
            lunchlib.write_head_uname(uname);

            # information message
            print status_message

            # form to go back to main menu
            lunchlib.write_form('''
                <p><input type="button" value="OK" onClick="goToMainMenu(this.form)">
                <p><input type="hidden" name="uname" value="''' + uname + '''">
            ''');
Пример #7
0
    lunchlib.write_js('''
        function insertLunch(form) {
            // check first to see if date is in desired format:
            dateRegexp = /^\d{4}-\d{2}-\d{2}$/.test(form.ldate.value)
            if (!dateRegexp) {
               alert("bad date format.");
               return;
            }

            // extract parts of the date
            bits = form.ldate.value.split('-');
            var year = bits[0];
            var month = bits[1];
            var day = bits[2];

            // create a new date object. note that the Date constructor
            // assumes January is the 0th month, so we must subtract 1
            // from our month value before calling the constructor:
            var testDate = new Date(year, month - 1, day);

            // make sure that the supplied date is not in the future:
            if (testDate > new Date()) {
                alert("date in the future.");
                return;
            }
  
            // if date is in the right format, make sure it is valid:
            if (year < 1 || month > 12 || month < 1 || day < 1) {
               alert("invalid date.");
               return;
            }
            else if (month == 1 || month == 3 || month == 5 ||
                month == 7 || month == 8 || month == 10 ||
                month == 12) {
                // some months have 31 days:
                if (day > 31) {
                   alert("invalid date.");
                   return;
                }
            }
            else if (month == 4 || month == 6 || month == 9 ||
                     month == 11) {
                // some months have 30 days:
                if (day > 30) {
                   alert("invalid date.");
                   return;
                }
            }
            else if (month == 2) {
                // February may have 28 or 29 days depending on the year:
                if ((year % 4) == 0 &&
                    ((year % 100) != 0 || (year % 400) == 0)) {
                   if (day > 29) {
                       alert("invalid date.");
                       return;
                   }
                }
                else {
                   if (day > 28) {
                       alert("invalid date.");
                       return;
                   }
                }
            }

            // now validate the amount. No one is allowed to spend more
            // than 9999.99 dollars on lunch!
            // note also that you can't input more than two decimal places
            if (/^\d{1,4}(\.\d{0,2}){0,1}$/.test(form.amount.value)
                == false) {
                alert("invalid amount.");
                return;
            }

            // if we get to here then we can call the code to insert the
            // lunch expense in the database:
            form.setAttribute("action", "insertLunch.py");
            form.submit();

        }

        // do not enter a lunch expense and go back to the main menu:
        function cancel(form) {
            form.setAttribute("action", "menu.py")
            form.submit();
        }
    ''')
Пример #8
0
if "uname" not in arguments:
    lunchlib.write_fail("Username not received in POST.")
else:
    uname = arguments["uname"].value

    # write out the menu options in html:
    lunchlib.write_js('''
        function enterLunchExp(form) {
            // go to lunch expense entry form:
            form.setAttribute("action", "lunchForm.py");
            form.submit();
        }

        function detailedReport(form) {
            // go to lunch expense reporting form:
            form.setAttribute("action", "detailedReportForm.py");
            form.submit();
        }

        function logout(form) {
            // go back to the login page.
            // do not pass any form data since the user has logged out.
            location="../login.html"
        }
    ''')

    lunchlib.write_head_uname(uname)

    print "<h3>Main Menu</h3>"

    lunchlib.write_form('''