From: Jan T. <de...@us...> - 2003-05-01 10:39:52
|
Update of /cvsroot/net-script/netscript2/docs/netscript/examples/eventcalendar In directory sc8-pr-cvs1:/tmp/cvs-serv4281 Added Files: README.html classes.xml dbsettings.xml event.xml eventReply.xml reservation.xml reservationReply.xml wipeout.project Log Message: * examples --- NEW FILE: README.html --- <pre> /---------------------------------------------------------------------\ | $Id: README.html,v 1.1 2003/05/01 10:39:49 derkork Exp $ | NetScript and all related materials, such as documentation, | are protected under the terms and conditions of the Artistic License. | | (C) 2000-2002 by Jan Thomä, insOMnia (ko...@in...) \---------------------------------------------------------------------/ Event Calendar Example ------------------------ This example shows some of the things you will encounter when programming a web application, and how these things are done in NetScript. The example particulary covers: * HTML forms processing * database usage It is meant as a bigger introductory example, which shows you a somewhat bigger application, instead of just some code snippets. This example is not meant to be complete in terms of functionality. Instead you can add new features to the example to get used to NetScript. Have fun exploring! Preparations ------------- If you want to try out this example, you need to do the following: * modify dbsettings.xml to fit your configuration (reference to the source documentation of NetScript::Libraries::DatabaseLibrary for more information) * in your database, create the following tables: - events + id : varchar(100) + name: varchar(255) + date: varchar(30) + time: varchar(5) + place: varchar(255) + cost: float - reservations + id: varchar(100) + eId: varchar(100) + amount: int * launch index.xml </pre> --- NEW FILE: classes.xml --- <?xml version="1.0"?> <!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # NetScript 2.0 Event Calendar Demo Script - Classes # $Id: classes.xml,v 1.1 2003/05/01 10:39:49 derkork Exp $ # # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--> <ns:ignore xmlns:ns="http://netscript.insomnia-hq.de" xmlns:db="http://db.netscript.insomnia-hq.de"> <?netscript import $(url[dbsettings.xml])?> <ns:class name="Event"> <ns:member name="id"/> <ns:member name="name"/> <ns:member name="date"/> <ns:member name="time"/> <ns:member name="place"/> <ns:member name="cost"/> <!-- Constructor --> <ns:method name="INIT"> <!-- Initialising --> <ns:var var="this.id" val="0"/> <ns:var var="this.name" val=""/> <ns:var var="this.date" val="01.01.1970"/> <ns:var var="this.time" val="00:00"/> <ns:var var="this.place" val=""/> <ns:var var="this.cost" val="0"/> </ns:method> <!-- Load the entry with the given id from the database --> <ns:method name="load" byVal="id"> <db:exec name="dbResult" handle="myDB" query="SELECT * FROM events WHERE Id LIKE '$(id)'"/> <!-- Get the result line from the result set --> <ns:invoke var="dbResult" method="nextLine"/> <!-- Fill the member variables --> <ns:if test="$(dbResult.lineFetched)"> <ns:var var="this.id" val="$(dbResult.content:0)"/> <ns:var var="this.name" val="$(dbResult.content:1)"/> <ns:var var="this.date" val="$(dbResult.content:2)"/> <ns:var var="this.time" val="$(dbResult.content:3)"/> <ns:var var="this.place" val="$(dbResult.content:4)"/> <ns:var var="this.cost" val="$(dbResult.content:5)"/> </ns:if> <ns:else> <ns:fail message= "There is no event with the id $(id)"/> </ns:else> </ns:method> <!-- Saves the event represented by this instance to the database --> <ns:method name="store"> <db:exec handle="myDB" query="DELETE FROM events WHERE id LIKE '$(this.id)'"/> <db:exec handle="myDB" query="INSERT INTO events VALUES( $(this.id), '$(this.name)', '$(this.date)', '$(this.time)', '$(this.place)', $(this.cost) )"/> </ns:method> </ns:class> <ns:class name="Reservation"> <ns:member name="id"/> <ns:member name="eId"/> <ns:member name="count"/> <!-- Constructor --> <ns:method name="INIT"> <!-- Initialising --> <ns:var var="this.id" val="0"/> <ns:var var="this.eId" val="0"/> <ns:var var="this.count" val="0"/> </ns:method> <!-- Load the entry with the given id from the database --> <ns:method name="load" byVal="id"> <db:exec name="dbResult" handle="myDB" query="SELECT * FROM reservations WHERE Id LIKE '$(id)'"/> <!-- Get the result line from the result set --> <ns:invoke var="dbResult" method="nextLine"/> <!-- Fill the member variables --> <ns:if test="$(dbResult.lineFetched)"> <ns:var var="this.id" val="$(dbResult.content:0)"/> <ns:var var="this.eId" val="$(dbResult.content:1)"/> <ns:var var="this.count" val="$(dbResult.content:2)"/> </ns:if> <ns:else> <ns:fail message= "There is no reservation with the id $(id)"/> </ns:else> </ns:method> <!-- Saves the event represented by this instance to the database --> <ns:method name="store"> <db:exec handle="myDB" query="DELETE FROM reservations WHERE id LIKE '$(this.id)'"/> <db:exec handle="myDB" query="INSERT INTO reservations VALUES( $(this.id), '$(this.eId)', '$(this.count)' )"/> </ns:method> <!-- Calculats the sum of the prices of all reserved tickets. Result is returned in the variable "price" which is given by reference. --> <ns:method name="calculatePrice" byRef="price"> <db:exec handle="myDB" name="result" query="SELECT cost FROM events WHERE Id=$(this.eId)"/> <ns:invoke var="result" method="nextLine"/> <ns:if test="$(result.lineFetched)"> <ns:var var="price" val="$(eval[$(result.content:0)*$(this.count)])"/> </ns:if> <ns:else> <ns:fail message= "There are no matching events for this reservation"/> </ns:else> </ns:method> </ns:class> </ns:ignore> --- NEW FILE: dbsettings.xml --- <?xml version="1.0"?> <!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # NetScript 2.0 Event Calendar Demo Script - Database Settings # $Id: dbsettings.xml,v 1.1 2003/05/01 10:39:49 derkork Exp $ # # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--> <ns:ignore xmlns:ns="http://netscript.insomnia-hq.de" xmlns:db="http://db.netscript.insomnia-hq.de"> <?netscript use Database?> <db:settings handle="myDB" host="localhost" database="kork" type="Pg" username="kork" password=""/> </ns:ignore> --- NEW FILE: event.xml --- <?xml version="1.0"?> <!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # NetScript 2.0 Event Calendar Demo Script - Event editing form # $Id: event.xml,v 1.1 2003/05/01 10:39:49 derkork Exp $ # # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--> <html> <head><title>Add Event</title></head> <body> <h1>Create new event</h1> <form action="$(SYS.interpreterURL)" method="POST"> <input type="hidden" name="scriptURL" value="$(url[eventReply.xml])"/> <table> <tr><td>Name</td><td> <input name="eName"/></td></tr> <tr><td>Date</td><td><input name="eDate"/></td></tr> <tr><td>Time</td><td><input name="eTime"/></td></tr> <tr><td>Place</td><td><input name="ePlace"/></td></tr> <tr><td>Price</td><td><input name="eCost"/></td></tr> </table> <input type="submit"/> </form> </body> </html> --- NEW FILE: eventReply.xml --- <?xml version="1.0"?> <!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # NetScript 2.0 Event Calendar Demo Script - Event creating reply script # $Id: eventReply.xml,v 1.1 2003/05/01 10:39:49 derkork Exp $ # # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--> <html xmlns:ns="http://netscript.insomnia-hq.de"> <!-- Import the classes --> <?netscript import $(url[classes.xml])?> <head><title>Create an Event</title></head> <body> <h1>Event created</h1> <ns:new name="anEvent" class="Event"/> <ns:var var="anEvent.id" val="$(SYS.nextID)"/> <ns:var var="anEvent.name" val="$(P.eName)"/> <ns:var var="anEvent.date" val="$(P.eDate)"/> <ns:var var="anEvent.time" val="$(P.eTime)"/> <ns:var var="anEvent.place" val="$(P.ePlace)"/> <ns:var var="anEvent.cost" val="$(P.eCost)"/> <ns:invoke var="anEvent" method="store"/> The event $(anEvent.name) has been successfully created. <p> <a href="$(SYS.interpreterURL)?scriptURL=$(url[index.xml])">back</a> </p> </body> </html> --- NEW FILE: reservation.xml --- <?xml version="1.0"?> <!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # NetScript 2.0 Event Calendar Demo Script - Reservation dialog # $Id: reservation.xml,v 1.1 2003/05/01 10:39:49 derkork Exp $ # # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--> <html xmlns:ns="http://netscript.insomnia-hq.de" xmlns:db="http://db.netscript.insomnia-hq.de"> <head><title>Reserve tickets</title></head> <body> <h1>Make a reservation</h1> <!-- Load DB settings --> <?netscript import $(url[dbsettings.xml])?> <?netscript import $(url[classes.xml])?> <db:exec handle="myDB" name="dbResult" query="SELECT id FROM events"/> <ns:invoke var="dbResult" method="nextLine"/> <ns:new name="theEvent" class="Event"/> <ns:while test="$(dbResult.lineFetched)"> <ns:invoke var="theEvent" method="load" id="$(dbResult.content:0)"/> <form action="$(SYS.interpreterURL)" method="post"> <input type="hidden" name="scriptURL" value="$(url[reservationReply.xml])"/> <input type="hidden" name="eid" value="$(theEvent.id)"/> <table> <tr><td colspan="2">$(theEvent.name)</td></tr> <tr><td colspan="2">$(theEvent.place)</td></tr> <tr><td colspan="2">$(theEvent.date) at $(theEvent.time)</td></tr> <tr><td>Price: $(theEvent.cost)</td> <td><input name="amount"/> tickets <input type="submit" value="Reserve!"/> </td> </tr> </table> <hr/> </form> <ns:invoke var="dbResult" method="nextLine"/> </ns:while> </body> </html> --- NEW FILE: reservationReply.xml --- <?xml version="1.0"?> <!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # NetScript 2.0 Event Calendar Demo Script - Reservation dialog # $Id: reservationReply.xml,v 1.1 2003/05/01 10:39:49 derkork Exp $ # # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--> <html xmlns:ns="http://netscript.insomnia-hq.de"> <head><title>Reservation done</title></head> <body> <h1>Your reservation</h1> <?netscript import $(url[classes.xml])?> <ns:new name="aReservation" class="Reservation"/> <ns:var var="aReservation.id" val="$(SYS.nextID)"/> <ns:var var="aReservation.eId" val="$(P.eid)"/> <ns:var var="aReservation.count" val="$(P.amount)"/> <ns:invoke var="aReservation" method="store"/> <ns:new name="anEvent" class="Event"/> <ns:invoke var="anEvent" method="load" id="$(aReservation.eId)"/> <ns:var name="cost" val="0"/> <ns:invoke var="aReservation" method="calculatePrice" price="cost"/> Thank you for your reservation! <br/> <table border="0"> <tr> <td>Event:</td><td>$(anEvent.name)</td> </tr> <tr> <td>Date:</td><td>$(anEvent.date)</td> </tr> <tr> <td>Time:</td><td>$(anEvent.time) hours</td> </tr> <tr> <td>Number of reserved tickets:</td><td>$(aReservation.count)</td> </tr> <tr> <td>Price per ticket:</td><td>$(anEvent.cost)</td> </tr> <tr> <td>Total price:</td><td>$(cost)</td> </tr> </table> Your reservation number: $(aReservation.id). <p> <a href="$(SYS.interpreterURL)?scriptURL=$(url[index.xml])">back</a> </p> </body> </html> --- NEW FILE: wipeout.project --- b C DmDictionary 0 4989d 8 c 0 49a20 9 C Category 1 146a7 c 0 49a60 4 C DmString 2 49a67 2 e3 c 2 49a66 a defaultExe C DmSet 3 49a69 1 c 2 146b9 2 e3 L 146b9 c 2 49a68 b executables c 3 49a64 3 c 2 146af 3 *.C L 146af c 2 146b1 4 *.cc L 146b1 c 2 146b3 5 *.cpp L 146b3 c 2 49a63 a extensions c 2 49a62 a CPP_source c 2 49a61 4 name c 2 49a22 a CPP_source c 1 146bd c 0 49aa6 4 c 2 49aad 2 e3 c 2 49aac a defaultExe c 3 49aaf 1 c 2 146cb 2 e3 L 146cb c 2 49aae b executables c 3 49aaa 1 c 2 146c5 3 *.c L 146c5 c 2 49aa9 a extensions c 2 49aa8 8 C_source c 2 49aa7 4 name c 2 49a23 8 C_source c 1 146cf c 0 49ae0 4 c 2 49ae7 2 e3 c 2 49ae6 a defaultExe c 3 49ae9 1 c 2 146dd 2 e3 L 146dd c 2 49ae8 b executables c 3 49ae4 1 c 2 146d7 3 *.e L 146d7 c 2 49ae3 a extensions c 2 49ae2 6 Eiffel c 2 49ae1 4 name c 2 49a24 6 Eiffel c 1 146e1 c 0 49b1a 4 c 2 49b21 2 e3 c 2 49b20 a defaultExe c 3 49b23 1 c 2 146f5 2 e3 L 146f5 c 2 49b22 b executables c 3 49b1e 4 c 2 146e9 3 *.F L 146e9 c 2 146eb 3 *.f L 146eb c 2 146ed 5 *.for L 146ed c 2 146ef 5 *.fpp L 146ef c 2 49b1d a extensions c 2 49b1c 7 Fortran c 2 49b1b 4 name c 2 49a25 7 Fortran c 1 146f9 c 0 49b60 4 c 2 49b67 2 e3 c 2 49b66 a defaultExe c 3 49b69 1 c 2 14709 2 e3 L 14709 c 2 49b68 b executables c 3 49b64 2 c 2 14701 3 *.H L 14701 c 2 14703 3 *.h L 14703 c 2 49b63 a extensions c 2 49b62 6 Header c 2 49b61 4 name c 2 49a26 6 Header c 1 1470d c 0 49b9e 4 c 2 49ba5 9 surfboard c 2 49ba4 a defaultExe c 3 49ba7 2 c 2 1471d 2 e3 L 1471d c 2 1471f 9 surfboard L 1471f c 2 49ba6 b executables c 3 49ba2 2 c 2 14715 5 *.htm L 14715 c 2 14717 6 *.html L 14717 c 2 49ba1 a extensions c 2 49ba0 4 Html c 2 49b9f 4 name c 2 49a27 4 Html c 1 14723 c 0 49be0 4 c 2 49be7 2 e3 c 2 49be6 a defaultExe c 3 49be9 1 c 2 14731 2 e3 L 14731 c 2 49be8 b executables c 3 49be4 1 c 2 1472b 6 *.java L 1472b c 2 49be3 a extensions c 2 49be2 4 Java c 2 49be1 4 name c 2 49a28 4 Java c 1 14735 c 0 49c1a 4 c 2 49c21 2 e3 c 2 49c20 a defaultExe c 3 49c23 1 c 2 14743 2 e3 L 14743 c 2 49c22 b executables c 3 49c1e 1 c 2 1473d 5 *.tex L 1473d c 2 49c1d a extensions c 2 49c1c 5 Latex c 2 49c1b 4 name c 2 49a29 5 Latex c 1 14747 c 0 49c54 4 c 2 49c5b 2 e3 c 2 49c5a a defaultExe c 3 49c5d 1 c 2 14752 2 e3 L 14752 c 2 49c5c b executables c 3 49c58 0 c 2 49c57 a extensions c 2 49c56 5 Other c 2 49c55 4 name c 2 49a2a 5 Other c 2 49a1f a categories c 0 49a2c 1 C ProjectDir 4 1477f c 2 14780 31 netscript2/docs/netscript/examples/eventcalendar/ 11 81 c 2 14781 0 0 c 2 49a2e 31 netscript2/docs/netscript/examples/eventcalendar/ c 2 49a2b b directories C DmBag 5 498a9 7 c 2 498df dc b C DmDictionary 0 498ab 3 C DmString 1 498bd 38 b C DmSet 0 17de8 1 C DmString 1 17f6d 4 Html L 17f6d c 1 498bc a categories c 1 498ad b README.html c 1 498ac 4 name C DmInteger 2 498bf 1 c 1 498be 9 substMode c 2 49914 dd b C DmDictionary 0 498e0 3 C DmString 1 498f2 39 b C DmSet 0 1c4e1 1 C DmString 1 1c65b 5 Other L 1c65b c 1 498f1 a categories c 1 498e2 b classes.xml c 1 498e1 4 name C DmInteger 2 498f4 1 c 1 498f3 9 substMode c 2 49949 e0 b C DmDictionary 0 49915 3 C DmString 1 49927 39 b C DmSet 0 32f40 1 C DmString 1 330ba 5 Other L 330ba c 1 49926 a categories c 1 49917 e dbsettings.xml c 1 49916 4 name C DmInteger 2 49929 1 c 1 49928 9 substMode c 2 4997e db b C DmDictionary 0 4994a 3 C DmString 1 4995c 39 b C DmSet 0 424bb 1 C DmString 1 42635 5 Other L 42635 c 1 4995b a categories c 1 4994c 9 event.xml c 1 4994b 4 name C DmInteger 2 4995e 1 c 1 4995d 9 substMode c 2 499b3 e0 b C DmDictionary 0 4997f 3 C DmString 1 49991 39 b C DmSet 0 442bd 1 C DmString 1 44437 5 Other L 44437 c 1 49990 a categories c 1 49981 e eventReply.xml c 1 49980 4 name C DmInteger 2 49993 1 c 1 49992 9 substMode c 2 499e8 e1 b C DmDictionary 0 499b4 3 C DmString 1 499c6 39 b C DmSet 0 473e8 1 C DmString 1 47562 5 Other L 47562 c 1 499c5 a categories c 1 499b6 f reservation.xml c 1 499b5 4 name C DmInteger 2 499c8 1 c 1 499c7 9 substMode c 2 49a1d e7 b C DmDictionary 0 499e9 3 C DmString 1 499fb 39 b C DmSet 0 49718 1 C DmString 1 49892 5 Other L 49892 c 1 499fa a categories c 1 499eb 14 reservationReply.xml c 1 499ea 4 name C DmInteger 2 499fd 1 c 1 499fc 9 substMode c 2 49a1e 5 files c 2 498a5 94 xterm -ls -fn -*-lucidatypewriter-medium-r-normal-*-12-* -bg gray90 -T Program -geometry 80x10+0+0 -e "[set command with 'Project->Launch Command']" c 2 498a4 6 launch c 2 498a1 4 make c 2 498a0 4 make c 2 498a3 0 c 2 498a2 8 makeFile c 5 498a6 0 c 2 498a8 7 modules c 2 4989f d eventcalendar c 2 4989e 4 name |