Texis Web Script source code for: /texis/site/demos/bookstore.vs
Note: Click on links to view the documentation for HTML tags which are special to the Vortex compiler.
<script language=vortex>

<!-- 

The intent of this demo is to show functionality, it is not
a production quality application. Specifically, it needs
more field validation and input verification.

Notes: Vortex is just HTML extended with programmatic tags and Texis SQL .
       
       Vortex functions are defined with <a name=X> and closed by </a> .
       
       Functions are called by using their name as a tag ie: <X> 
       
       The code is auto-compiled at the server into a Java-esque P-code.
       
       A function is invoked by http://texis/script_name/function.html 
      
-->

<!-- Schema for tables:
bookorder:  Cid counter, Bookid counter, Copies int
books:      id counter, Title varchar, Image varchar, Author varchar,
            Publisher varchar, Category varchar, ISBN varchar, Pubdate date, 
            Spubdate varchar, Price float, Pages int, Description varchar
-->

<export $custid>  <!-- Persistent CGI variables for this app -->
<export $Coverid url>
<export $id url>
<uses demonav=demonav><!--simple look and feel module-->
<entryfunc=init>              <!-- init function for every invocation -->

<!-- --------------------------------------------------------------------- -->
<a name=init private>
  <sum "%s" $SERVER_ROOT "/texis"><db = $ret>  <!-- set the database -->
</a>

<!-- ---------------------------------------------------------------------- -->

<a name=hdr PUBLIC>
<if "" eq $custid>
  <if "" eq $BOOKCID>
     <$newcust=1>
     <sql max =1 "insert into bookorder values (counter,'000000000000',0)">
          <$custid=$Cid>
          <$qauthor=brains>
     </sql>
  <else>
     <$repeatcust=1>
     <$custid=$BOOKCID>
  </if>
</if>
<META HTTP-EQUIV=Set-Cookie CONTENT="BOOKCID=$custid; path=/; expires=Friday, 31-Dec-2010 23:59:59 GMT">
<demolook title="Texis Book Store Example Code">
</a>

<a name=ftr PUBLIC>
<H6 ALIGN=right>Copyright © 1996 <A HREF=/>Thunderstone - EPI, Inc.</A></H6>
</demolook>
</a>

<A NAME=bye PUBLIC>
  <ftr>
  <EXIT>
</A>

<!-- ---------------------------------------------------------------------- -->

<a name=buttons PUBLIC>
<input type=submit name=cmd value="Add to my order">
<input type=submit name=cmd value="View my order">
<input type=submit name=cmd value="Check out">
<input type=submit name=cmd value="New search">
</a>

<!-- ---------------------------------------------------------------------- -->

<a name=getorder PUBLIC>

   <if "" eq $custid>
     <bye> 
   </if>
   <$Bookid = >
   <sql "select books.id Bookid,Author,Title,Price,sum(Copies) Qty,Price*sum(Copies) Subtot 
         from bookorder,books
         where  bookorder.Cid = $custid
         and  books.id=bookorder.Bookid
         group by Author,Title,Price"/>
   <$LineItems=$#Bookid>
   <$gotorder = 1>

</a>


<!-- ---------------------------------------------------------------------- -->

<a name=view PUBLIC>
<form method=post action="$url/">
<getorder>
<if $loop ne 0>
   <center>
   <table border=1>
   <tr><th align=center colspan=4>Your Order</th></tr>
   <tr><th>Quantity</th><th><b>Title</b></th><th>Author</th><th align=right>Unit Price</th></tr>
   <loop $Author $Title $Price $Qty $Bookid>
     <if $Qty ne 0>
         <tr><td><small><input type=hidden name=Book value="$Bookid"><input size=4 name=oqty value="$Qty"></small></td><td><b>$Title</b></td><td>$Author</td><td align=right><fmt "%.2f" $Price> </td></tr>
     </if>
   </loop>
   <tr>
     <th colspan=3 align=right> Total $$</th> 
     <th align=right><sum "%.2f" $Subtot>$ret</th>
   </tr>
  </table>   
  <input type=submit name=cmd value="Check out">
  <input type=submit name=cmd value="Change order">
  <input type=submit name=cmd value="New search">
  </center>
<else>
You have nothing in your order.
</if>

</form>
</a>

<a name="View my order" PUBLIC>
<hdr>
<view>
<ftr>
</a>

<!-- ---------------------------------------------------------------------- -->

<a name="Change order" PUBLIC>
<hdr>
<sql "delete from bookorder where Cid=$custid"/>
<loop $Book $oqty>
  <sql "insert into bookorder values($custid,$Book,$oqty)"/>
</loop>
<view>
<ftr>
</a>

<!-- ---------------------------------------------------------------------- -->

<a name="Add to my order" PUBLIC>
<hdr>
<loop $Buy>
     <sql max=1 "insert into bookorder values ($custid,$Buy,1)">
     </sql>
</loop>
<view>
<ftr>
</a>

<!-- ---------------------------------------------------------------------- -->

<a name="New search" PUBLIC>
<search>
</a>

<!-- ---------------------------------------------------------------------- -->
<a name=ordertxt PUBLIC>
Posted from: $REMOTE_ADDR $REMOTE_HOST
<verb>
                        Thunderstone Bookstore Example Code
</verb>

SEND TO:
$Custname
$Address
$City, $State $Zip

Email: $Email


<fmt "%-5s " "Qty"><fmt "%-35s " "Title"><fmt "%-25s " "Author">Unit Price
---------------------------------------------------------------------------------------------
<loop $Author $Title $Price $Qty>
   <if $Qty ne 0>
     <fmt "%5d " $Qty><fmt "%-35.34s " $Title> <fmt "%-25s " $Author> <fmt "%8.2f" $Price>

   </if>
</loop>
---------------------------------------------------------------------------------------------
<fmt "%58s" ""><sum "%1.2f" $Subtot><fmt "Total  $$%10.2f" $ret>

</a>


<!-- ---------------------------------------------------------------------- -->

<a name=clearorder>
<if "" eq $custid>
  <bye>
</if>
<sql "delete from bookorder where Cid=$custid"/>
</a>


<a name=mailit PUBLIC>
<getorder>
<$errors = >
<if $LineItems eq 0>
 <$errors = $errors "You have no books in your order">
</if>

<rex "\alpha+[^\alpha]+\alpha+" $Custname /> 
<if $ret eq "">
  <$errors = $errors "Name Field Incorrect">
</if>
<rex "\alpha+" $City />
<if $ret eq "">
  <$errors = $errors "City Field Incorrect">
</if>
<rex "\alpha{2}" $State />
<if $ret eq "">
  <$errors = $errors "State Field Incorrect">
</if>
<rex "\digit{5}" $Zip />
<if $ret eq "">
  <$errors = $errors "Zip Field Incorrect">
</if>

<if $errors neq "">
<hdr>
  <loop $errors>
    <h4>$errors</h4>
  </loop>
  Please Hit The Back Button and correct the information.
<ftr>
<else>
   <clearorder>
   <hdr>
   <pre>
   <ordertxt>
   </pre>
   <ftr>
   <flush>
   <exec BKGND /usr/lib/sendmail  -fnobody@nowhere.com $Email>
      From: $Email ($Custname)
      To: $Email 
      Subject: Texis Bookstore Example Code
   
      <ordertxt>
      .
   </exec>
</if>
</a>

<!-- ---------------------------------------------------------------------- -->

<a name="Check out" PUBLIC>
<rex "\.\P=[\alnum\-]+>>\.[cen][ode][mut]" $REMOTE_HOST />
<$Email=$ret>
<hdr>
<center>
<h4>Confirmation of this order will be emailed to you. </h4>
<form method=post action=$url/mailit.html>
<table>
<tr><td align=right>Name:</td><td colspan=8><input size=40 name=Custname></td></tr>
<tr><td align=right>Street Address</td><td colspan=8><input size=40 name=Address ></td></tr>
<tr><td align=right>City:</td><td><input size=20 name=City ></td>
    <td align=right>State:</td><td><input size=2 name=State ></td>
    <td align=right>Zip:</td><td><input size=5 name=Zip ></td></tr>
<tr><td align=right>Email Address:</td><td colspan=8><input size=40 name=Email value="@$Email"></td></tr>
</table>
<input type=submit value="Submit Your Order">
</form>
<br>
<view>
</center>
<ftr>
</a>

<!-- ---------------------------------------------------------------------- -->
<a name=cover PUBLIC>
<sql max=1 "select Cover from covers where Coverid = $Coverid">
$Cover
</sql>
</a>

<!-- ---------------------------------------------------------------------- -->

<a name=cover_href PUBLIC>
<!--
Notes: This function is really screwey because the people who created the 
original data didn't realize ISBN's were 10 characters long and DOS filenames
are only 8 plus an extention. The result is that we have a truncated name
in the Covers Table. Otherwise this function would have been a simple lookup.
-->
<sandr ">>\digit{8}\digit+\.gif" "\1" $Image>
<sql max=1 "select Coverid from covers where Coverid = $ret">
<image src=$url/cover.gif>
</sql>
</a>

<!-- ---------------------------------------------------------------------- -->

<a name=showbook PUBLIC>
<hdr>
<sql max=1 "select
     id,Title,Image,Author,Publisher,Category,ISBN,Pubdate,Spubdate,Price,Pages,Description
     from books where id=$id">
</sql>
<sandr "[\n\r]+" "<p>" $Description>
<$Description = $ret>
<form method=post action="$url/">
<table width=100%>
<tr><td colspan=4 align=center><small><buttons></small><input type=hidden name=Buy value=$id></td></tr>
<tr><td colspan=4 align=center valign=top>
<big><b>$Title</b></big><br><small>Author:</small><big> <b>$Author</b></big>
</td></tr>
<tr><td valign=top>
<cover_href>
</td><td valign=top>
<send $Description>
</td><td valign=top>
<center>
<table >
<tr><td align=right>Price:</td>      <td><b>$$<fmt "%.2f" $Price></b></td></tr>
<tr><td align=right>Category:</td>   <td>$Category</td></tr>
<tr><td align=right>ISBN:</td>       <td>$ISBN</td></tr>
<tr><td align=right>Pubdate:</td>    <td><fmt "%b, %Y" $Pubdate></td></tr>
<tr><td align=right>Pages:</td>      <td>$Pages</td><tr>
<tr><td align=right>Publisher:</td>  <td>$Publisher</td></tr>
</table>
</td></tr>
</table>
</form>
</center>
<ftr>
</a>

<!-- ---------------------------------------------------------------------- -->

<a name=listbooks PUBLIC>
<hdr>
<local nullVals>
<$nullVals = "" "-all-">
<center>
<form method=post action=$url>
<buttons>
<table width="90%">
<tr><th align=left>order?</th><th>Author</th><th><b>Title</b></th><th>Published</th><th align=right>Price</th></tr>
                          <!-- the books table is pre-ordered by Title,Author,Pubdate -->
<sql null=$nullVals max=20 "select
     id,Title,Author,Pubdate,Price
     from books 
     where Author like $qAuthor
     and   Title  like $qTitle
     and   Category = $qCategory
     and   Title\Category\Description likep $qSubject">
<if $Author eq "">
  <$Author="anonymous">
</if>
<tr><td><small><input name=Buy type=checkbox value=$id></small></td><td>$Author</td><td><b><a href=$url/showbook.html>$Title</a></b></td><td><fmt "%h/%y" $Pubdate></td><td align=right>$$<fmt "%.2f" $Price></td></tr>
</sql>
</table>
</form>
</center>
<ftr>
</a>

<!-- ---------------------------------------------------------------------- -->

<a name=searchform>
<$catlist= "-all-" "Anthropology" "Art" "Autobiography" "Biography" "Business" 
           "Child Care" "Computers" "Cook Book" "Current" "Education" 
           "Espionage" "Fantasy" "Fiction" "Film" "Games Sports" "Health" 
           "Historical" "History" "Home Improvement" "Horror" 
           "House of Collectibles" "Humor" "Inspirational" "Literature" 
           "Movie Tie-in" "Music" "Mystery" "Native Americans" "Nature" 
           "Nonfiction" "Ortho" "Parapsychology" "Pet" "Philosophy" "Poetry" 
           "Politics" "Psychology" "Puzzles" "Recovery" "Reference" 
           "Religion" "Romance" "Science" "Science Fiction" 
           "Self Help" "Sociology" "Sports" "Suspense" "To Come" "Travel" 
           "True Crime" "True Medicine" "Vietnam" "Western" "Women's Studies" 
           "World War" "Young Adults">

<form method=post action=$url/listbooks.html>
<table>
<tr><td align=right>Author:<td></td>  <td><input size=40 name=qAuthor  value=$qAuthor></td><tr>
<tr><td align=right>Title:<td></td>   <td><input size=40 name=qTitle   value=$qTitle></td><tr>
<tr><td align=right>Subject:<td></td> <td><input size=40 name=qSubject value=$qSubject></td><tr>
<tr><td align=right>Category:<td></td><td><select name=qCategory><options $catlist $qCategory $catlist></select><input type=submit></td><tr>
</table>
</form>
</a>

<!-- ---------------------------------------------------------------------- -->
<a name=search PUBLIC>
<hdr>
<searchform>
<i>Hint:</i> Enter a Name or Keywords into one of the fields, or just
select a category.
<ftr>
</a>

<!-- ---------------------------------------------------------------------- -->

<a name=main PUBLIC>
<hdr>
<getorder>
<if $repeatcust neq "">
  <h2> Welcome back </h2>
</if>
<if $LineItems gt 0>
  <h2> You still have a pending order </h2>
  <view>
<else>
    This example shows a light-weight framework for a Web store.
    <p>
    It also shows how to <i>remember</i> things between sessions with "Client Cookies".
    <p>
    The database only has 2500 books so don't exepect to find every Author
    and Title in the world.<br> 
    About 300 of the books have cover art available.<br>
    If you want to see a cover type "Brains" in the title field. 
    <h3 align=middle><a href=$url/search.html>Enter The Store</a></h3>
</if>
<ftr>
</a>

</script>

Back to the Code Example List

The Source Viewer is also a Code Example.
Click Here to see its source.
Copyright © 1992-1999 Thunderstone Software
Copyright © 2024 Thunderstone Software LLC. All rights reserved.