Complete Code Listings

In the next section, you will find the complete code listing for the User Directory application.

home.asp

Listing 16.1 User Directory Application—Home Page
/*******************************************
This page is the first page the user views.
It allows the user to select whether they want
to browse names by company, first name, or
last name.  After they select the top level
menu-item, they move on to other cards within
this page (the deck) in order to further narrow their
options.
*******************************************/
<% Response.ContentType = "text/vnd.wap.wml" %>
<!--- Defines XML Version and Document Data Type --->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>
  <card id="home" title="Choose an option">

   <p align="center">
     View:<br/>
     <a href="#company">By company</a><br/>
     <a href="stafflist.asp?type=fname">By first name</a>
     <a href="stafflist.asp?type=lname">By last name</a>
   </p>

  </card>

    <%
        ' Create the database connection
    set dbConn = Server.CreateObject("ADODB.Connection")
         dbConn.open("dsn=staffdir")
    company_sqlStr = "SELECT * from company"
    set company = dbConn.execute(company_sqlStr)
    %>

  <card id="company" title="View by Company">

     <do type="accept" label="Back">
       <go href="#home"/>
     </do>

    <p align="center">
    Select a company:<br/>

    <%
       While not company.eof
    %>

              <a href="staff.asp?company_id=<%=company ("company_id")%>"><%=company
("name")%></a>

    <%
          company.MoveNext
        Wend
    %>

    </p>

  </card>

</wml>

email.asp

Listing 16.2 User Directory Application—Email Handling
/*******************************************
This page allows the user to compose a new
email message to the specified person they selected
in the main menu (home.asp).  When the email is
complete, the page submits to email-action.asp
in order to instantaneously send an email.
*******************************************/

<% Response.ContentType = "text/vnd.wap.wml" %>
<!--- Defines XML Version and Document Data Type --->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<head>
<meta http-equiv="Cache-Control" content="max-age=0"/>
</head>
  <card id="email" title="E-mail">

    <%
    set dbConn = Server.CreateObject("ADODB.Connection")
         dbConn.open("dsn=staffdir")
    staff_sqlStr = "SELECT * from staff where staff _id = "&Request.QueryString("staff_id")
    set staff = dbConn.execute(staff_sqlStr)
    %>

        <do type="accept" label="Send">
           <go href="email-action.asp" method="post">
              <postfield name="email" value="<%=staff("email")%>"/>
              <postfield name="subject" value="$subject"/>
              <postfield name="message" value="$message"/>
           </go>
        </do>

    <p>
      E-mail <%=staff("fname")%>&nbsp;<%=staff("lname")%><br/>
      Subject: <input type="text" name="subject"/><br/>
      Message: <input type="text" name="message"/>
    </p>

  </card>

</wml>

call.asp

Listing 16.3 User Directory Application—Executing a Phone Call
/*******************************************
This page allows the user to actually call the
person that they selected from the main menu
(home.asp).  It calls a system command on the phone
to automatically call the number listed in the
database under the specified person's name.
*******************************************/

<% Response.ContentType = "text/vnd.wap.wml" %>
<!--- Defines XML Version and Document Data Type --->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card id="phone" title="Call">

    <%
    set dbConn = Server.CreateObject("ADODB.Connection")
         dbConn.open("dsn=staffdir")
    staff_sqlStr = "SELECT * from staff where staff _id = "&Request.QueryString("staff_id")
    set staff = dbConn.execute(staff_sqlStr)
    %>

    <do type="accept" label="Call">
       <go href="wtai://wp/mc;<%=staff("number")%>"/>
    </do>

    <do type="accept" label="Back">
       <go href="home.asp"/>
    </do>

    <p>
    Call <%=staff("fname")%>&nbsp;<%=staff("lname")%>?<br/>
    <%=staff("number")%>
    </p>

</card>

</wml>

stafflist.asp

Listing 16.4 User Directory Application—Search by Staff Name
/*******************************************
This deck is a search deck that either sorts
The user list by first name or last name.
From this deck a user can drill down into more
Detail for a particular employee.
*******************************************/
<% Response.ContentType = "text/vnd.wap.wml" %>
<!--- Defines XML Version and Document Data Type --->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

    <%
    set dbConn = Server.CreateObject("ADODB.Connection")
         dbConn.open("dsn=staffdir")
    staff_sqlStr = "SELECT * from staff order by "&Request.QueryString("type")&" asc"
    set staff = dbConn.execute(staff_sqlStr)
    %>


<wml>

     <card id="stafflist" title="Staff Directory">
        <do type="accept" label="Select">
          <go href="staff-detail.asp?staff_id=$employee"/>
        </do>

        <do type="accept" label="Back">
          <go href="home.asp"/>
        </do>

        <p>
       Staff:
          <select name="employee">
          <%
          While not staff.EOF
          %>
              <option value="<%=staff("staff_id")%>"><%=staff("fname")%>&nbsp;<%=staff
("lname")%></option>
          <%
              staff.MoveNext
          Wend
          %>
          </select>
        </p>
     </card>

</wml>

staff-detail.asp

Listing 16.5 User Directory Application—Display Staff Detail Record
/*******************************************
This deck displays information for a particular
Staff member.
*******************************************/

<% Response.ContentType = "text/vnd.wap.wml" %>
<!--- Defines XML Version and Document Data Type --->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

  <card id="options" title="Staff Directory">

   <do type="accept" label="Call">
       <go href="call.asp?staff_id=<%=Request.QueryString("staff_id")%>"/>
   </do>

   <do type="option" label="E-mail">
          <go href="email.asp?staff_id=<%=Request.QueryString("staff_id")%>"/>
   </do>

       <%
       set dbConn = Server.CreateObject("ADODB.Connection")
            dbConn.open("dsn=staffdir")
       staff_sqlStr = "SELECT * from staff where staff_id = "&Request.QueryString("staff_id")
       set staff = dbConn.execute(staff_sqlStr)
    %>
   <p>
   <%=staff("fname")%>&nbsp;<%=staff("lname")%><br/>
   E-mail: <i><%=staff("email")%></i><br/>
   Phone: <i><%=staff("number")%></i>
   </p>

  </card>

</wml>

staff.asp

Listing 16.6 User Directory Application—Select Staff Member Record
/*******************************************
This page lists staff members for a particular
Company and then allows a user to drill down
Into that specific user.
*******************************************/

<% Response.ContentType = "text/vnd.wap.wml" %>
<!--- Defines XML Version and Document Data Type --->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

  <card id="codetail" title="Staff Directory">
      <do type="accept" label="Select">
           <go href="staff-detail.asp?staff_id=$employee">
           </go>
      </do>

     <do type="accept" label="Back">
       <go href="home.asp"/>
     </do>

    <%
    set dbConn = Server.CreateObject("ADODB.Connection")
         dbConn.open("dsn=staffdir")
    staff_sqlStr = "SELECT company.name,staff.* from company INNER JOIN staff on company
.company_id = staff.company where staff.company = " & Request.QueryString("company_id")

    set staff = dbConn.execute(staff_sqlStr)
    %>
<onevent type="onpick">
        <go href="http://localhost/sams/ch16/staff-detail.asp?staff_id= <%=staff
("staff_id")%>"/>
        </onevent>

      <p align="center">
       <select name="employee">
           <%
           While not staff.EOF
           %>
           <option value="<%=staff("staff_id")%>"><%=staff("fname")%>&nbsp;<%=staff
("lname")%></option>
           <%
           staff.movenext
           Wend
           %>
     </select>
    </p>
  </card>

</wml>

email-action.asp

Listing 16.7 User Directory Application—Execute Email Action
/*******************************************
This page processes the data entered on email.asp
and automatically sends an email to the person
selected.  It then returns the user to the main
menu.
*******************************************/

<% Response.ContentType = "text/vnd.wap.wml" %>
<!--- Defines XML Version and Document Data Type --->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<head>
<meta http-equiv="Cache-Control" content="max-age=0"/>
</head>

<%

'Note: Persits Software's AspEmail Component is used to send this message...
'other components/programs, such as Microsoft's SMTP Server can be used to perform this task

Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "mail.mamail.com" 'Specify a valid SMTP server
Mail.From = "[email protected]" 'Specify sender's address
Mail.FromName = "My Wap Phone" 'Specify sender's name

Mail.AddAddress Request.Form("email")

Mail.Subject = Request.Form("subject")
Mail.Body = Request.Form("message")

Mail.Send

%>

<card>
  <do type="accept" label="Back">
    <go href="home.asp"/>
  </do>
  <p>The e-mail has been sent</p>
</card>

</wml>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.98.71