Plands.com Logo  Business Internet Services 
Main Menu
Home
Planetary CRM
  Benefits
  Features
  Demo
E-Mail Services
  E-mail Hosting
  Newsletters
  Discussion Lists
Web Hosting
Server Co-location
and Administration
Web Applications
Technical Support
Contact Us
DXP Samples
 
DxpHome  ||   Samples  ||   Details  ||   Docs  ||   Trees  ||   xml-xsl  ||   Links

Sample .dxp Page with comments
(Overview -*- Front Page -*- (more coming))

Comments precede the page sections to which the refer.

This page serves 2 functions. It is an intro page that offers various options to search the database and it also adds new entries to the database. This means that someone posting a new entry arives back at the main page.

Page header

<?xml version="1.0"?>
<dxp:DxpPage xmlns:dxp="dxp.plands.com" contentType="text/html" buffsize="2048" debug="false">

By convention I put authorization and all database transactions at the top of the page. The folowing auth tag require the user to have PUT privileges to the .time.hint resource a realm specified at runtime (the parameter rname). If the request lacks the rname parameter (or a valid username/password) the user will not be allowed to access the page.


<dxp:AuthUser type="PW" lifespan="30" store="user">
   <dxp:Resource priv="PUT" name=".time.hint" param="rname" />
</dxp:AuthUser>

A text insert that provides the HTML headers, the logo, and header links.


<dxp:Replace token="$" value="user.realm">
   <dxp:ReadText name="target" filename="log/header.txt"/>
</dxp:Replace>

If someone is adding a new entry I first check to see if they're using one of the existing categories (subject heading) or whether they are adding a new one. If so the first DbStmt tag adds the new subject to the database. Note that 'choice' and 'subject2' are both parameters that can be passed with the request while 'user.realm' is a parameter that is stored by the AuthUser tag above.


<dxp:If test="choice == 'new'">
   <dxp:If test="subject2 != null">
      <dxp:DbStmt action="update" dbcon="datauser" store="cnt">
         <dxp:SqlStmt>
            <dxp:Cp name="sql">insert into log.hint_subject(subject,realm) values('?','?')</dxp:Cp>
            <dxp:SqlParam name="subject2" type="CHAR"/>
            <dxp:SqlParam name="user.realm" require="true" type="CHAR"/> 
         </dxp:SqlStmt>
      </dxp:DbStmt>
   </dxp:If>

The following tag stored the posted entry (hint) in an html friendly form. See dxp:RpToHtml for details on the conversion.


   <dxp:RpToHtml name="hint" store="hint_html"/>

The following tag takes a possible array of subject values (posted with html checkboxes) and creates a comma delimited list


   <dxp:Tokens action="concat" delim=", " store="subject_list">
      <dxp:Ap name="subject"/>
      <dxp:Rp name="subject2"/>
   </dxp:Tokens>

The tag that actually enters a new 'hint' into the database. Notice that this stores both the original text that the user posted and the html friendly version. The intention is that the html version is used for display and the text version is used as the basis for any edits. There is a slight amount of redundancy, but it's simpler to do the text to html conversion once than have to do it everytime the record is viewed.

When the parameters are loaded into the database statement it looks like insert into log.hints(name,posted,title,subject,hint,hint_html,realm) values('[user.username]',now(),'[title]','[subject_list]','[hint]','[hint_html]','[user.realm]')

Notice that the first If statement (If choice == 'new') is finally closed after this database statement.


   <dxp:DbStmt action="update" dbcon="datauser" store="cnt">
      <dxp:SqlStmt>
         <dxp:Cp name="sql">
	        insert into log.hints(name,posted,title,subject,hint,hint_html,realm) values('?',now(),'?','?','?','?','?')
	     </dxp:Cp>
         <dxp:SqlParam name="user.username" require="true" type="CHAR"/> 
         <dxp:SqlParam name="title" type="CHAR"/>
         <dxp:SqlParam name="subject_list" type="DIRECT"/>
         <dxp:SqlParam name="hint" require="true" type="CHAR"/>
         <dxp:SqlParam name="hint_html" type="CHAR"/>
         <dxp:SqlParam name="user.realm" require="true" type="CHAR"/> 
      </dxp:SqlStmt>
   </dxp:DbStmt>
</dxp:If>

A simple query that returns a list of subject headings. This will populate a list for the user to search by subject. Note that all of the queries have a clause "where realm='?'". The database that this uses is designed to have multiple organizations using it simultaneously. The realm column is used to define which organization owns a record.


<dxp:DbStmt action="query" dbcon="datauser" store="subject">
   <dxp:SqlStmt>
      <dxp:Cp name="sql">Select subject from log.hint_subject where realm='?' order by id</dxp:Cp>
      <dxp:SqlParam name="user.realm" require="true" type="CHAR"/> 
   </dxp:SqlStmt>
</dxp:DbStmt>

Another query that will populate a select list on the search form


<dxp:DbStmt action="query" dbcon="datauser" store="users">
   <dxp:SqlStmt>
      <dxp:Cp name="sql">Select distinct name from log.hints where realm='?'</dxp:Cp>
      <dxp:SqlParam name="user.realm" require="true" type="CHAR"/> 
   </dxp:SqlStmt>
</dxp:DbStmt>

The begining of the html form. In the database I call the entries 'hints' in the form they're refered to as 'facts' it would probably be better to keep the terminology the same, but I changed the form after setting up the database and didn't think it worthwhile to change the database to match.


 <h2><font face="Arial, Helvetica, sans-serif">Search </font></h2>

<table width="580" cellspacing="0" cellpadding="0" bordercolor="#333333" border="1" bgcolor="#FFFFEF">

Displays a message if nothing's been entered yet, otherwise it displays the search form.


<dxp:If test="users == null">
   <tr>
      <th colspan="4" bgcolor="#F0F0FF"><br /><br />No facts entered<br /><br /> </th>
   </tr>
</dxp:If>
<dxp:Else>
   <tr>
     <th colspan="4">Select one or more of the following search criteria</th>
   </tr>
   <form method="post" action="hint-list.dxp">

This passes the realm to the next page as rname.


   <![CDATA[<input type="hidden" name="rname" value="]]><dxp:Rp name="user.realm" /><![CDATA[" />]]>

The form is generally in the form of a search category followed by a select list. The select statement are filled with by the LoopSet tag which takes the results from the database queries at the top of the page and prints a line for every record in the query.


   <tr>
     <td align="right">User:   </td>
     <td>   
       <select name="user">
   	<option value="">All</option>
   	<dxp:LoopSet matrix="users">
   	<![CDATA[<option>]]><dxp:Index value="0" /><![CDATA[</opion>]]>
   	</dxp:LoopSet>
   	</select>
     </td>   
     <td align="right">Subject:   </td>
     <td>
       <select name="subject">
   	<option value="">Any</option>
   	<dxp:LoopSet matrix="subject">
   	<![CDATA[<option>]]><dxp:Index value="0" /><![CDATA[</opion>]]>
   	</dxp:LoopSet>
   	</select>
     </td>
   </tr>
   <tr>
     <td align="right">Entered After:   </td>
     <td>   <input type="text" name="date1" size="8" maxlength="10" />   (mm/dd/yy)</td>
     <td align="right">Entered Before:   </td>
     <td>   <input type="text" name="date2" size="8" maxlength="10" />   (mm/dd/yy)</td>
   </tr>
   <tr>
     <td align="right">Keyword:   </td>
     <td>   <input type="text" name="key" size="15" maxlength="15" /></td>
     <td colspan="2" align="center"><input type="submit" value="Go!" /></td>
   </tr>
   
   
   </form>
</dxp:Else>
</table>

The user may also go to the form to enter a new record.


<p><![CDATA[<a href="hint-new.dxp?rname=]]><dxp:Rp name="user.realm" /><![CDATA[">]]>Enter Hint<![CDATA[</a>]]></p>

Insert a text file containing footer links and closing html tags


<dxp:Replace token="$" value="user.realm">
    <dxp:ReadText name="target" filename="log/footer.txt"/>
</dxp:Replace>

</dxp:DxpPage>