Vejledende Løsning til Eksamen, forår 2001

for Database-baseret Web-publicering, forår 2001

af Niels Hallenberg


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

Opgave 1.1

  <form method=post action=nl_kontrol.tcl>
    Email: <input type=input name=email value=""><p>
    <input type=submit value="Kontrol">
  </form>

Opgave 1.2

  <form method=post action=nl_tilmeld.tcl>
    <table>
      <tr><td>Navn:</td><td><input type=input name=name value=""></td></tr>
      <tr><td>Tlf:</td><td><input type=input name=phone value=""></td></tr>
      <tr><td>Email:</td><td><input type=input name=email value=""></td></tr>
    </table><br>
    <blockquote>
      <input type=checkbox name=info value="4"> Buzz Talks<br>
      <input type=checkbox name=info value="3"> Forskning<br>
      <input type=checkbox name=info value="2"> Stillinger<br>
      <input type=checkbox name=info value="1"> Uddannelser<br>
    </blockquote>
    <input type=submit value="Tilmeld mig">
  </form>

Opgave 1.3

  proc nl_return_page { title body } {
    ns_return 200 text/html "
     <html>
       <head>
         <title>$title</title>
       </head>
       <body bgcolor=white>
         <table align=center width=100% bgcolor=red border=0 cellpadding=5 cellspacing=0>
	    <tr><th align=left><font color=white size=+2>$title</font></th>
                <th align=right><a href=\"www.it-c.dk\">www.it-c.dk</a></th></tr>
         </table>
         $body
         <hr>
         <center>
            Glentevej 67, 2400 København NV. Telefon: 38 16 88 88. 
            Email: <a href=\"mailto:info@it-c.dk\">info@it-c.dk</a>
         </center>
       </body>
     </html>"
  }

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

Opgave 2.1

     INFO_ID INFO_NAME
  ---------- -----------
           4 Buzz Talks
           3 Forskning
           2 Stillinger
           1 Uddannelser

Opgave 2.2

  create table nl_user (
    user_id integer primary key,
    name varchar(200) not null,
    phone varchar(50),
    email varchar(200) unique not null,
    create_date date not null);

  create table nl_user_info (
    user_id integer references nl_user,
    info_id integer references nl_info,
    unique(user_id, info_id)
  );

Opgave 2.3

  insert into nl_user (user_id, name, phone, email, create_date) 
    values (1, 'Anders And', '34 32 56 43', 'anders@andeby.dk', sysdate);

  insert into nl_user_info (user_id, info_id) values (1,4);

Opgave 2.4

  select nl_user.name, email, info_name, nl_user.user_id, nl_info.info_id
    from nl_user, nl_info, nl_user_info
   where nl_user.user_id = nl_user_info.user_id
     and nl_user_info.info_id = nl_info.info_id
     and nl_info.info_id = '1'
   order by email;

Opgave 2.5

  select count(*) as count, info_name 
    from nl_user_info, nl_info 
   where nl_info.info_id = nl_user_info.info_id
   group by nl_info.info_name
   order by nl_info.info_name;
Bemærk: Da as ikke har været gennemgået til forelæsning men kun til øvelser er den ikke nødvendig for at få fuld point.

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

Opgave 3.1

  <blockquote>
    <input type=checkbox name=info value="4"> Buzz Talks<br>
    <input type=checkbox name=info value="3"> Forskning<br>
    <input type=checkbox name=info value="2"> Stillinger<br>
    <input type=checkbox name=info value="1"> Uddannelser<br>
  </blockquote>

Opgave 3.2

  10.0

Opgave 3.3

  proc calc_pct { counts names } {
    set sum [calc_sum $counts]

    set infos "<ul>\n"
    for {set i 0} {$i < [llength $counts]} {incr i} {
      append infos "<li><b>[lindex $names $i]</b>: "
      append infos "[lindex $counts $i]([format "%.2f" 
                      [expr [lindex $counts $i] / $sum * 100.0]]%)\n"
    }
    append infos "</ul>\n"

    return $infos
  }

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

Opgave 4.1

Betragt det regulære udtryk
^[1-9][0-9]*$

Opgave 4.2

^([0-9][ -]*)*$

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

Opgave 5.1

  ##A##
    set user_id [database_to_tcl_string $db "
           select nl_user_seq.nextval as user_id from dual"]

  ##B##
    set insert_sql "insert into nl_user (user_id, name, phone, email, create_date) 
                    values ($user_id, '$QQname', '$QQphone', '$QQemail', sysdate)"

  ##C##
      set insert_sql "insert into nl_user_info(user_id, info_id) 
                      values ($user_id, $info_id)"

Opgave 5.2

  ##A##

    set selection [ns_db select $db $query]
    while {[ns_db getrow $db $selection]} {
      set_variables_after_query

      append body "<li>$name\n"
    }

Opgave 5.3

  ##A##
    if {[catch {set user_id [database_to_tcl_string $db $query]} errmsg]} {
      nl_return_page "Afmelding" "Den indtastede email er 
                                  ikke registreret i nyhedstjenesten."
    } else {
      set del_info_sql "delete from nl_user_info where user_id = '$user_id'"
      ns_db dml $db $del_info_sql
      set del_user_sql "delete from nl_user where user_id = '$user_id'"
      ns_db dml $db $del_user_sql

      nl_return_page "Afmelding" "Person med email <b>$email</b> er nu afmeldt nyhedslisten."
    }

Opgave 5.4

  ##A##
   set counts [list]; # list with counts
   set names [list];  # list with names
   while {[ns_db getrow $db $selection]} {
     set_variables_after_query
  
     lappend counts $count
     lappend names $info_name
  }

Opgave 5.5

  ##A##
    set db [ns_db gethandle]
    set selection [ns_db select $db $query]
    set body "Nyheden er sendt til følgende personer:
              <ul>\n"
    while {[ns_db getrow $db $selection]} {
      set_variables_after_query

      qmail $email $sender $subject "Kære $name

      $content"
      append body "<li>$name ($email)\n"
    }
    append body "</ul>\n"
    nl_return_page "Send Nyhed" $body

nh@it.edu