Complete Code Listings

The next section presents the entire code listing for the User Directory application. Here you can reference all of the code mentioned earlier in the chapter.

main.wml

Listing 17.1 Scheduling Application Home Page
<?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="options" title="Scheduler">
    <do type="accept" label="Select">
        <go href="$option"/>
    </do>

   <p align="center">
   Scheduler
   </p>

   <p>
     <a href="#appttype">Your schedule</a><br/>
     <a href="#add">Schedule appt</a>
   </p>

</card>

<card id="appttype" title="Your Schedule">

<p>
<b>Select an option:</b><br/>
<a href="schedule.cfm?type=future">Future Appts</a><br/>
<a href="schedule.cfm?type=now">Today's Appts</a><br/>
<a href="schedule.cfm?type=past">Past Appts</a><br/>
</p>

</card>

<card id="add" title="Add an appointment">

 <do type="accept" label="Add">
     <go href="add.cfm">
       <postfield name="date_start" value="$date_start"/>
       <postfield name="date_end" value="$date_end"/>
       <postfield name="time_start" value="$time_start"/>
       <postfield name="time_end" value="$time_end"/>
       <postfield name="description" value="$description"/>
        </go>
 </do>

  <p>
    Add appointment:<br/>
    Start Date: <input type="text" name="date_start"/>
    End Date: <input type="text" name="date_end" />
    Start Time: <input type="text" name="time_start"/>
    End Time: <input type="text" name="time_end"/>
    Description: <input type="text" name="description" maxlength="50"/>
  </p>
</card>

</wml
							
							
							
							>

add.cfm

Listing 17.2 Writing Appointment Data to the Database
<CFCONTENT type="text/vnd.wap.wml">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">




<!---show error and abort if the values entered are not date/time values--->
<cfif ( not isDate(Replace(date_start,".","/","ALL")) or not isDate(Replace(date_end,".","
/","ALL")) ) or ( not isDate(Replace(time_start,".","/","ALL")) or not isDate(Replace
(time_end,".","/")) )>

<wml>

<card>

<do type="accept" label="Back">
    <go href="main.wml#add"/>
</do>

<p>
<b>Error:</b> <br/>
Invalid date/time value detected.<br/>
<cfoutput>#Replace(date_start,".","/","ALL")#</cfoutput>
</p>

</card>

</wml>
<CFABORT>

</cfif>
<!---if the dates are valid, put them into the
database and show confirmation message--->
    <CFQUERY datasource="schedule">
        INSERT into schedule(date_start,date _end,time_start,time_end,description)
values(#CreateODBCDate(Replace(date_start,".","/","ALL"))# ,#CreateODBCDate(Replace
(date_end,".","/","ALL"))#,#CreateODBCTime (time_start)#,#CreateODBCTime(time_end)#
,'#description#')
    </CFQUERY>



<wml>

<card>

<do type="accept" label="Back">
    <go href="main.wml#options"/>
</do>

<p>
Your appointment was added succesfully.
</p>
</card>

</wml
							
							
							
							
							>

schedule.cfm

Listing 17.3 Displaying Appointment Data
<CFCONTENT type="text/vnd.wap.wml">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<!---make sure this page is not cached in any way--->
<cfheader name="Expires" value="#Now()#">
<cfheader name="Pragma" value="No-Cache">
<cfheader name="cache-control" value="No-Cache, no-store, must-revalidate">

<!---if the id was passed (from clicking on 'next appointment')
, get that specific record, otherwise get the first record
 in the time range (past, present, or future) that the user selected from  main.wml.--->
<cfif type is "future">
  <cfquery name="getSchedule" datasource="schedule">
            SELECT * FROM schedule WHERE
          <cfif parameterexists(id)>
          id = #id#
          <cfelse>
          (date_start = #CreateODBCDate(Now())#
           AND
           time_start >= #CreateODBCTime(Now())#)

           OR

           (date_start > #CreateODBCDate(Now())#)
          </cfif>
         ORDER BY date_start ASC
      </cfquery>
  <cfelseif type is "past">
        <cfquery name="getSchedule" datasource="schedule">
            SELECT * FROM schedule WHERE
          <cfif parameterexists(id)>
          id = #id#
          <cfelse>
           date_start < #CreateODBCDate(Now())#
          </cfif>
         ORDER BY date_start ASC
      </cfquery>
   <cfelseif type is "now">
      <cfquery name="getSchedule" datasource="schedule">
               SELECT * FROM schedule WHERE
             <cfif parameterexists(id)>
             id = #id#
             <cfelse>
             (date_start = #CreateODBCDate(Now())#
              AND
              time_start >= #CreateODBCTime(Now())#)
             </cfif>
            ORDER BY time_start ASC
      </cfquery>
   </cfif>

<wml
							
							
							
							
							>

<head>
<meta http-equiv="Cache-Control" content="max-age=0"/>
</head>
<card id="display" title="Your schedule">

<!---if they have at least one appointment, display it--->
<cfif getSchedule.recordcount gt 0>

    <do type="accept" label="Back">
        <go href="main.wml#options"/>
    </do>

    <!---get the next appointment in the selected time group--->
<cfif type is "future">
        <cfquery name="getNext" datasource="schedule">
            SELECT id FROM schedule
            where (id <> #getSchedule.id# and date_start >= #CreateODBCDate(Now())# and
 date_start >=  #CreateODBCDate(getSchedule.date_start)#)
            order by date_start asc
        </cfquery>
    <cfelseif type is "past">
        <cfquery name="getNext" datasource="schedule">
            SELECT id FROM schedule
            where (id <> #getSchedule.id# and date_start < #CreateODBCDate(Now())# and
 date_start >= #CreateODBCDate(getSchedule.date_start)#)
            order by date_start asc
        </cfquery>
    <cfelseif type is "now">
        <cfquery name="getNext" datasource="schedule">
            SELECT id FROM schedule
            where (id <> #getSchedule.id# and date_start  = #CreateODBCDate(Now())# and
 date_start  >= #CreateODBCDate(getSchedule.date_start)#)
            order by date_start asc
        </cfquery>
    </cfif>


    <do type="accept" label="Next">
      <!---if there is at least one more appointment, provide a link to it--->
  <cfif getNext.recordcount gt 0>
        <go href="schedule.cfm?id=<cfoutput> #getNext.id#&amp;type=#type#</cfoutput>"/>
      <cfelse>
          <go href="schedule.cfm?type=<cfoutput>#type#</cfoutput>"/>
      </cfif>
    </do>

    <cfoutput
							
							
							
							
							>
    <p>
    <table columns="2">
    <tr>
    <td><b>Start Date:</b></td><td>#DateFormat (getSchedule.date_start,"mm/dd/yy")#</td>
    </tr>
    <tr>
    <td><b>Start Time:</b></td><td>#TimeFormat (getSchedule.time_start,"hh:mmt")#</td>
    </tr>
    <tr>
    <td><b>End Date:</b></td><td>#DateFormat (getSchedule.date_end,"mm/dd/yy")#</td>
    </tr>
    <tr>
    <td><b>End Time:</b></td><td>#TimeFormat (getSchedule.time_end,"hh:mmt")#</td>
    </tr>
    </table>
    <br/><b>Description:</b><br/>
    #getSchedule.description#
    </p>
    </cfoutput>

<cfelse>
<!---if there are no appointments in the selected time
 group, display this message to the user--->
<do type="accept" label="Back">
    <go href="main.wml#options"/>
</do>

<p>
No appointments have been scheduled.
</p>

</cfif>
</card>
</wml
							
							
							
							
							>

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

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