Vejledende Løsning til Eksamen, efterår 2000

for Database-baseret Web-publicering, efterår 2000

af Martin Elsman


Vejledende Løsning til Opgave 1 (20 procent) - HTML

Opgave 1.1

  <form action=order.tcl>
    <input type=hidden name=store_id value=1>
    <b>Bestilling:</b> 
       <select name=dish_id>
 	 <option value=1>Nr 9: Pepperoni. Kr. 38,-
	 <option value=2>Nr 24: Hawaii. Kr. 38,-
	 <option value=3>Nr 36: Didim Bøf. Kr. 40,-
       </select><p>
    <b>Dit tlf. nr.:</b> <input type=text size=8 name=phone><p>
    <input type=submit value=\"Afsend Bestilling\">
  </form>

Opgave 1.2

  <html><body bgcolor=white>
    <table width=100% bgcolor=red border=0 cellpadding=5 cellspacing=0>
      <tr><th align=left>
            <font color=white size=+2>Didim Pizza Pasta og Grill</font>
          </th>
          <th align=right>RestaurantOnline.dk</th>
      </tr>
    </table> <p>
    <img align=right src=http://didim.dk/didim.jpg>
      *FORM*
    Se <a href=statistics.tcl?store_id=1>bestillingsbarometeret</a> 
    før du bestiller!
    <hr>
    <center>
    Vibevej 35, 2400 Kbh. NV. Tlf. 38100571 - Så har vi det klar når De kommer
    </center>
  </body></html>

Vejledende Løsning til Opgave 2 (20 procent) - Tcl

Opgave 2.1

  <table width=100%>
    <tr><td width=50%>Pizza nr. 9</td>
        <td width=50%>5: *****</td>
    </tr><tr><td width=50%>Pizza nr. 5</td>
             <td width=50%>2: **</td>
    </tr>
  </table>

Opgave 2.2

  proc max_count { l } {
      set m 0
      foreach e $l {
	  set c [lindex $e 1]
	  if { $c > $m } { 
	      set m $c 
	  }
      }
      return $m
  }

Opgave 2.3

  proc star_graph2 { l } {
      set res "<table width=100%>"
      set max [max_count $l]
      if { $max <= 0 } {
	return "No elements"
      }
      foreach e $l {
	  set name [lindex $e 0]
	  set count [lindex $e 1]
	  set n [expr $count * 10 / $max]
	  set bar ""
	  while { $n > 0 } {
	      append bar "*"
	      incr n -1
	  }
	  append res "<tr><td width=50%>$name</td> 
			  <td width=50%>$count: $bar</td>
		      </tr>"
      }
      return "$res</table>"
  }

Vejledende Løsning til Opgave 3 (10 procent) - Regulære udtryk

Opgave 3.1

  [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]

Opgave 3.2

  proc pz_check_phone { phone } {
      if ![regexp {^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+$} $phone] {
	  ns_return 200 text/html "
            <html><body>
              <h2>Form variable violation</h2>
	      I expected a phone number, but received something 
              else - use the back button in your browser to go back
              and correct your input.
            </body></html>"
	  exit
      }
  }

Vejledende Løsning til Opgave 4 (20 procent) - SQL

Opgave 4.1

  id | name
  ---+----------------------------
   1 | Nr 9: Pepperoni. Kr. 38,-
   2 | Nr 24: Hawaii. Kr. 38,-
   3 | Nr 36: Didim Bøf. Kr. 40,-

Opgave 4.2

  create table dish_order (
    id integer primary key,
    dish_id references dish,
    order_date date not null,
    phone char(8) not null,
    deleted_p char(1) default 'f' check (deleted_p in ('t','f'))
  );

Opgave 4.3

  insert into dish_order (id, dish_id, order_date, phone)
  values (1, 1, '2001-01-05', '26122212');

  insert into dish_order (id, dish_id, order_date, phone)
  values (2, 3, '2001-01-06', '21332223');

Opgave 4.4

  select to_char(order_date, 'DD/MM-YYYY HH24:MI:SS') as order_date, 
         dish_id, name, phone, dish_order.id as order_id
  from dish, dish_order
  where store_id = 1
    and dish_id = dish.id
    and deleted_p = 'f'
  order by order_date

Opgave 4.5

  select name, count(*) as count
  from dish, dish_order
  where store_id = 1
    and dish.id = dish_id 
  group by name

Vejledende Løsning til Opgave 5 (30 procent) - Web-service

Opgave 5.1

  set query "select name, address 
             from store
             where id = $store_id" 

Opgave 5.2

  # set the form variable store_id, dish_id, phone
  set_form_variables

  # check form variables
  pz_check_id $store_id
  pz_check_id $dish_id
  pz_check_phone $phone

  set db [ns_db gethandle]

  set insert_sql "insert into dish_order (id, dish_id, order_date, phone)
		  values (order_id_seq.nextval, '$dish_id', sysdate, '$phone')"

  ns_db dml $db $insert_sql

  pz_return_page $db $store_id "
     <h2>Tak for din bestilling!</h2> Du kan enten
     <a href=index.tcl?store_id=$store_id>bestille mere</a> eller hente din
     bestilling om 10 minutter."

Opgave 5.3

##A##
  lappend dishes [list $name $count]
##B##
  pz_return_page $db $store_id "
   <h2>Besillingsbarometer</h2>
   <a href=index.tcl?store_id=$store_id>Hovedsiden</a> :: Barometer<hr>
   $graph"

Opgave 5.4

##A##
  set body "<table width=100%>"
##B##
  append body "<tr>
     <th width=30%>$order_date</th>
     <th width=40%>$name</th>
     <th width=10%>$phone</th>
     <th width=10%><a href=delete.tcl?order_id=$order_id&store_id=$store_id>delete</a></th>
   </tr>"
##C##
  append body "</table>"

Opgave 5.5

  # set the form variable order_id
  set_form_variables

  # check form variables
  pz_check_id $store_id
  pz_check_id $order_id

  set db [ns_db gethandle]

  ns_db dml $db "update dish_order set deleted_p = 't' 
		 where id = $order_id" 

  ns_returnredirect "admin.tcl?store_id=$store_id"

mael@it.edu