// 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(); } ''') # html header lunchlib.write_head_uname(uname) # input form: lunchlib.write_form(''' <p>Start Month (yyyy-mm): <input type="text" name="start_month"> <p>End Month (yyyy-mm): <input type="text" name="end_month"> <i>(if left blank, defaults to start month)</i><br/> <p><input type="button" value="Submit" onClick="goToDetailedReport(this.form)"> <p><input type="button" value="Cancel" onClick="cancel(this.form)"> <p><input type="hidden" name="uname" value="''' + uname + '''"> ''') # html footer lunchlib.write_tail()
# 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 lunchlib.write_form( ''' <p><input type="button" value="Back to Menu" onClick="goToMainMenu(this.form)"> <p><input type="hidden" name="uname" value="''' + uname + """"> """ ) # both reports will be part of a larger overall table: print "<table><tr>" print "<td>" # Only run summary report if there is data in the detailed report. if write_detailed_report(uname, start_month, end_month, db): print '</td><td width="60"></td><td>' write_summary_report(uname, start_month, end_month, db) print "</td></tr></table>"
# 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 + '''"> ''') # html footer lunchlib.write_tail() # close db connection db.close() except pg.InternalError: lunchlib.write_fail("Could not connect to database")
# 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: lunchlib.write_fail("Could not connect to 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(); } ''') # write html header: lunchlib.write_head_uname(uname) print "<h3>Enter a lunch expense for a day</h3>" lunchlib.write_form(''' <p>Date (yyyy-mm-dd): <input type="text" name="ldate"><br/> <p>Amount Spent: <input type="text" name="amount"><br/> (format: dollars[.cents], do not type "$", max.: 9999.99) <p><input type="button" value="Submit" onClick="insertLunch(this.form)"> <p><input type="button" value="Cancel" onClick="cancel(this.form)"> <p><input type="hidden" name="uname" value="''' + uname + '''"> ''') # html footer lunchlib.write_tail()
} 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(''' <p><input type="button" value="Add to lunch expenditures" onClick="enterLunchExp(this.form)"> <p><input type="button" value="List of monthly lunch expenditures" onClick="detailedReport(this.form)"> <p><input type="button" value="Logout" onClick="logout(this.form)"> <p><input type="hidden" name="uname" value="''' + uname + '''"> ''') lunchlib.write_tail()