Subroutine O4W_REVSHOW(CTLENTID, EVENT, REQUEST) * * Build an O4W Stored Procedure to make Penn & Teller reservations * * Demonstrated at Revelation Software User Conference 04/2010 * NOTE: for this to work you will need (in addition to the standard O4W files): * 1. The "template" named tickets.html, and * 2. The "youtubin" plugin * * * Insert our required equates * $Insert O4WCOMMON $Insert O4WEQUATES * * Respond to the various events that our O4W form generates * Begin Case * Every form is called with the "create" event when it starts up Case EVENT _EQC "CREATE" * Specify the location of the "template" we want to use for this form O4WForm("C:\TEMP\tickets.html") * Add in the "js" (javascript) and "css" (style sheets) for any of our plugins O4WScript("../plugins/Zebra_DatePicker/zebra_datepicker.js") O4WStyleSheet("../plugins/Zebra_DatePicker/metallic.css") O4WScript("../plugins/youtube/jquery.youtubin-1.js") * What do we want to show at the top of our browser page? O4WTitle("Penn & Teller Reservations") * Convert our sections into tabs O4WTabs("orderTabs", "showing":@VM:"reserve", "Select A Show":@VM:"Reservation Details") O4WSectionStart("showing", O4WMarkedStyle('','0')) * Put up a button to hide or show our on-line help O4WButton("Show/Hide Instructions...", "BTN_HELP") * Build the on-line help into a special section O4WSectionStart("helpSection") O4WText("You should put some help text here. It would make everyone's life much easier!") O4WSectionEnd("helpSection") * When the form starts up, make sure the help section is hidden O4WQualifyEvent("", "hide", "helpSection") * Enable the pure client-side "toggling" of the help section when the help button is clicked O4WQualifyEvent("BTN_HELP", "toggle", "helpSection", "1") * Output a newline so things look nice O4WBreak() * Lay out our show information as a table so it looks nice as well O4WTableStart("showInfo") O4WSetCell(1,1) O4WText("Show date:") O4WSetCell(1,2) * Build a textbox with the current date as the default value * The textbox will be 10 characters wide, it will be named "DATE", and * it will have a unique ID of "txtDATE" O4WTextbox(Oconv(DATE(), "D4/"), 10, "", "DATE", "txtDATE") O4WSetCell(2,1) O4WText("Number of tickets:") O4WSetCell(2,2) * Build a textbox with "0" as the default value * The textbox will be 5 characters wide, and will accept no more than 5 characters * It will be named "NUMTICKETS" and have the unique ID of "txtNUMBER" * When the form is submitted, or validated, the textbox will be checked to make sure only numeric data * is present - and that something is, indeed, present O4WTextbox("0", "5", "5", "NUMTICKETS", "txtNUMBER", O4WValidateStyle('', O4W_VALIDATE_NUM$, "1")) O4WSetCell(3,1) O4WText("Total Cost":@VM:"($49.99/seat):") O4WSetCell(3,2) O4WText("$0.00", "lblCost") O4WSetCell(3,3) * We'll put up a button labeled "Update"... O4WButton("Update", "BTN_UPDATE") * ...that will generate a "click" event when pressed O4WQualifyEvent("BTN_UPDATE", "CLICK") O4WTableEnd("showInfo") O4WSectionEnd("showing") * In the next section let's collect the "demographic" data for the buyer O4WSectionStart("reserve", O4WMarkedStyle('','0')) O4WTableStart("demoInfo") O4WSetCell(1,1) O4WText("Name:") O4WSetCell(1,2) O4wTextbox("", "", "", "NAME") O4WSetCell(2,1) O4WText("Address 1:") O4WSetCell(2,2) O4WTextbox("", "", "", "ADD1") O4WSetCell(3,1) O4WText("Address 2:") O4WSetCell(3,2) O4WTextbox("", "", "", "ADD2") O4WSetCell(4,1) O4WText("City:") O4WSetCell(4,2) O4WTextbox("", "", "", "CITY") O4WSetCell(4,3) O4WText("State:") O4WSetCell(4,4) * Build a listbox with the state information: first, read the state names and codes... states = Xlate("O4WCODES", "CODES_STATES", "", "X") * ...and then pass them into a listbox named "ST" O4WListbox(states<1>, states<2>, "ST") O4WSetCell(5,3) O4WText("ZIP:") O4WSetCell(5,4) O4WTextbox("", "", "", "ZIP") O4WTableEnd("demoInfo") O4WSectionEnd("reserve") O4WSectionEnd("orderTabs") O4WBreak() * Outside of the tabs, display a "Make Your Reservation" button and a link to YouTube o4wTableStart("displayTable", O4WMarkedStyle('','0')) O4WButton("Make Your Reservation!", "BTN_RESERVE") O4WSetCell(1,2) url = "http://www.youtube.com/watch?v=_qQX-jayixQ&NR=1" O4WLink("Watch a clip!", O4W_LINKTYPE_NORMAL$, url, "", "lnkPT") O4WTableEnd("displayTable") * When the "BTN_RESERVE" is clicked, it will generate a "SUBMIT" event * (which is like a CLICK event, but it also performs any validation) O4WQualifyEvent("BTN_RESERVE", "SUBMIT") * Turn our textbox (with the ID "txtDATE") into a "date picker" field by using * the "Zebra DatePicker" plugin O4WPlugin("testDATE","Zebra_DatePicker", "{format: 'M d, Y'}") * Turn our Penn & Teller link (with the ID "lnkPT") into an embedded video by * using the "youtubin" plugin O4WPlugin("lnkPT", "youtubin") * The CLICK event was generated by the BTN_UPDATE Case EVENT _EQC "CLICK" * Let O4W know we're building a response (and not a full page) O4WResponse() * Pull in the value of the NUMTICKETS field numTickets = O4WGetValue("NUMTICKETS") If Num(numTickets) And numTickets <> "" then * Had a valid number; calculate the cost and update the lblCost control * Note the use of the O4WResponseStyle to tell the control we're only * updating its text portion O4WUpdate("lblCost", Oconv(numTickets * 4999, "MD2,$"), O4WResponseStyle('','1')) End Else * Didn't have a valid number - show an error message O4WError("You must enter a valid number to continue") End * The SUBMIT event was generated by the BTN_RESERVE Case EVENT _EQC "SUBMIT" * After a SUBMIT, we do have to build a new page - so we'll call O4WForm with * our template again O4WForm("C:\TEMP\tickets.html") * Load in the data from the form numTickets = O4WGetValue("NUMTICKETS") NAME = O4WGetValue("NAME") amt = Oconv(numTickets * 4999, "MD2,$") * Imagine that we get all the rest of the info from the form too... * ...and write it out somewhere in the database * Now generate a thank you message O4WText("Thanks, ":NAME:"! Please be sure to complete your purchase using PayPal and your tickets will be waiting for you at the 'All Call' box") * And call the PayPal site (with the O4WPayPal api) to do a "buy it now" transaction O4WPaypal("BUY", "", "xxx@revelation.com", "Penn and Teller tickets", "pttickets", NUMTICKETS, "$49.99", "$0.00", "$0.00") End Case * Return 0