Spring Semester 2006


Thu May 18
Here are the slides from The Krishna Kumar Presentation.

Thu-Fri May 4-6
Please keep your servers up until Sunday morning.

Mon-Wed May 1-3
Date: Wed, 3 May 2006 18:40:38 -0400 (EDT)
From: Adrian German <dgerman@cs.indiana.edu>
To: undisclosed-recipients:  ;
Subject: A348/A548 Final Exam tomorrow (LH102 @2:45-4:45pm).

Dear A348/A548 Friends,

The Final Exam is in class (LH102) between 2:45pm and 4:45pm tomorrow.

The exam is closed book. The best review is your homework and lab work.

Short questions will be asked about the material covered in class. The
questions posted for your review are meant to give you an idea about the
format not the content. Questions will be about things discussed in class
and the work that you have put in your assignments.

The class notes page has been changed. It now contains a brief review,
with a link at the top to a complet set of notes very similar to the one
we have used this semester. Also, don't forget to review the What's New?
page, it contains code we developed in class and information posted on an
almost daily basis. So that is I think a very close summary in a nutshell
of what we have been through (as far as A348 material is concerned) this
semester. Good luck tomorrow and please let me know if you have questions
or need any help.

... Adrian
Script for appointments is still here.

Fri-Sun Apr 28-30
The Javascript shopping cart default project shown in class on Fri.

Here is a list of questions to think about when preparing for the final.

Thu Apr 27
Today in class I can show three default projects from the past:

Sat-Wed Apr 18-26
Here's an example of a program that might help with Homework Seven.

Fri-Mon Apr 15-17
Tue we'll have the first project presentation: by Jun Yin.

Individual appointments for the next two weeks can be scheduled through this script.

Thu Apr 14
Code developed by Sarah Rieke in class on Thu:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Three extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    HttpSession session = request.getSession(); 
    String message = (String)session.getAttribute("message"),
           compScore = (String)session.getAttribute("compScore"),
           userScore = (String)session.getAttribute("userScore"),
           secret = (String)session.getAttribute("secret"),
           attempts = (String)session.getAttribute("attempts"), // state ends here
           answer = request.getParameter("answer"); // input
    String me = request.getContextPath() + request.getServletPath();
    if (message != null) {
      int a = Integer.parseInt(answer),
          s = Integer.parseInt(secret),
          n = Integer.parseInt(attempts);
      if (a == s) { // they won
        message = "Good.";
        userScore = Integer.parseInt(userScore) + 1 + "";
        attempts = "0";
        secret = Math.round(Math.random() * 100) + "";
      } else {
        n += 1;
        if (n == 10) { // they lost
          message = "Bad.";
          compScore = Integer.parseInt(compScore) + 1 + "";
          attempts = "0";
          secret = Math.round(Math.random() * 100) + "";
        } else {
          if (a < s) {
            message = "Try higher.";
          } else {
            message = "Try lower.";
          }
          attempts = n + "";
        }
      }
    } else {
      message = "The game has started.";
      session.setAttribute("message", message);
      secret = Math.round(Math.random() * 100) + "";
      session.setAttribute("secret", secret);
      attempts = "0";
      session.setAttribute("attempts", attempts);
      compScore = "0";
      session.setAttribute("compScore", compScore);
      userScore = "0";
      session.setAttribute("userScore", userScore);
    }

    session.setAttribute("message", message);
    session.setAttribute("secret", secret);
    session.setAttribute("attempts", attempts);
    session.setAttribute("compScore", compScore);
    session.setAttribute("userScore", userScore);

    out.println(

"<form action=\"" + me + "\">" +
"  " + message + "<p>" +
" secret: " + secret + "<p>" +
" attempts: " + attempts + "<p>" +
"  (" + compScore + " - " + userScore + ") <p>" +
"  Type your answer here: <input type=\"text\" name=\"answer\"> <p> " +
"  Push <input type=\"submit\" value=\"Proceed\"> when ready. " +
"</form>"

    );

  }
}

The part in blue is the last step in the development. 

Do you know what name this part has in our template?

Thu Apr 13
Notes to be used today in class:

  • an old lab eleven (for good, simple templates)
  • an old set of lecture notes (lecture notes twenty, for more information)
Once this is done we can look at an older project:

Sat-Wed Apr 9-12
Servlet developed in class on Tuesday:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Four extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String message = request.getParameter("message"),
           compScore = request.getParameter("compScore"),
           userScore = request.getParameter("userScore"),
           secret = request.getParameter("secret"),
           attempts = request.getParameter("attempts"), // state ends here
           answer = request.getParameter("answer"); // input
    String me = request.getContextPath() + request.getServletPath();
    if (message != null) {
      int a = Integer.parseInt(answer),
          s = Integer.parseInt(secret),
          n = Integer.parseInt(attempts);
      if (a == s) { // they won
        message = "Good.";
        userScore = Integer.parseInt(userScore) + 1 + "";
        attempts = "0";
        secret = Math.round(Math.random() * 100) + "";
      } else {
        n += 1;
        if (n == 10) { // they lost
          message = "Bad.";
          compScore = Integer.parseInt(compScore) + 1 + "";
          attempts = "0";
          secret = Math.round(Math.random() * 100) + "";
        } else {
          if (a < s) {
            message = "Try higher.";
          } else {
            message = "Try lower.";
          }
          attempts = n + "";
        }
      }
    } else {
      message = "The game has started.";
      secret = Math.round(Math.random() * 100) + "";
      attempts = "0";
      compScore = "0";
      userScore = "0";
    }

    out.println(

"<form action=\"" + me + "\">" +
"  " + message + "<p>" +
" secret: " + secret + "<p>" +
" attempts: " + attempts + "<p>" +
"  (" + compScore + " - " + userScore + ") <p>" +
"  Type your answer here: <input type=\"text\" name=\"answer\"> <p> " +
"  Push <input type=\"submit\" value=\"Proceed\"> when ready. " +
"  <input type=\"hidden\" name=\"message\" value=\"" + message + "\">" +
"  <input type=\"hidden\" name=\"compScore\" value=\"" + compScore + "\">" +
"  <input type=\"hidden\" name=\"userScore\" value=\"" + userScore + "\">" +
"  <input type=\"hidden\" name=\"attempts\" value=\"" + attempts + "\">" +
"  <input type=\"hidden\" name=\"secret\" value=\"" + secret + "\">" +
"</form>"

    );

  }
}

Mon-Fri Apr 2-7
Relevant for the lab this week:

  • make sure your Tomcat is installed
  • create a new context and make it reloadable
  • add a servlet to the classes folder
  • add a description in the associated web.xml for the servlet
  • compile and access the servlet, change and recompile the servlet until done

After lab this week we can get started with Homework Five (and Six follows right away).

Thu-Sun Mar 30-Apr 2
Code developed in class on Thursday:
#!/usr/bin/perl

use DBI;
use MD5;
use CGI;

$EXPIRE    = 60 * 60 * 24 * 30;     # allow 30 days before expiration
$DB        = "DBI:mysql:a348";      # data source name (database)
$username  = "a348";                # username
$password  = "a348AG";              # password
$DBAUTH    = "$username:$password";
$SECRET    = " ***( something secret, whatever )*** ";
$MAX_TRIES = 10;

$DB_TABLE  = "ckotil_firstta"; 

$ID_LENGTH = 8;                     # length of the session ID

$q = new CGI;

# Open the database -------------------------------------------------------- 

$DBH = DBI->connect($DB, $username, $password, {PrintError => 0}) || die "Couldn't open database: ", $DBI::errstr;

# get the current session ID, or make one ----------------------------------
my ($session_id, $note) = &get_session_id();

print $q->header,
      $q->start_html(-title => 'Database Sessions with URL Rewriting',
                     -bgcolor => 'white');

# retrieve the state -------------------------------------------------------
my $state = &get_state($session_id) unless $q->param('clear');

$message = $state->{message};  
$comp = $state->{comp};
$user = $state->{user};

$guess = $q->param('guess'); 

if ($message) {
  $user += $guess;
  if ($user >= 100) { 
    print "You WIN!";
    $user=0;
  } else {
    $comp = 1 + int(rand(10)); # this is the number
    $user=$user + $comp;
  };

  if ($user>=100) { 
    print "I WIN!";
    $user=0;
  } 
} else {
  $message = "Welcome"; 
  $user = 0;
  $comp = -1; 
}

$state->{message} = $message;
$state->{comp} = $comp;
$state->{user} = $user; 

# save the modified state --------------------------------------------------
&save_state($state, $session_id);

print qq{<form>
  I have chosen $comp . <br> 
  The total is currently $user , remember first to 100 wins. <p> 
  How much will you enter? (0-10) <input type="text" name="guess"/> <p> 
  Press <input name="submit" type="submit" value="Submit"/> when ready to submit. 
  
</form>};


print $q->end_html;
$DBH->disconnect;

# retrieve the session ID from the path info. if it's -----get_session_id---
# not already there, add it to the path info (more or less) with a redirect
sub get_session_id {

  my (@result);
  &expire_old_sessions();
  my ($id) = $q->path_info() =~ m:^/([a-h0-9]{$ID_LENGTH}):o;
  return @result if $id and @result = &check_id($id);
  
  # if we get here, there's not already an ID in the path info
  my $session_id = &generate_id();
  die "Couldn't make a new session id" unless $session_id;
  print $q->redirect($q->script_name() . "/$session_id");
  exit 0;
}

# find a new unique ID and insert it into the database -------generate_id---
sub generate_id {
  # create a new session id
  my $tries = 0;
  my $id = &hash($SECRET . rand());

  while ($tries++ < $MAX_TRIES) {
    last if $DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')");
    $id = &hash($id);
  }

  return undef if $tries >= $MAX_TRIES; # we failed
  return $id;
}

# check to see that an old ID is valid --------------------------check_id---
sub check_id {
  my $id = shift;
  return ($id, '')
    if $DBH->do("SELECT 1 FROM $DB_TABLE WHERE session_id = '$id'") > 0;
  return ($id, 'The record of your game may have expired. Restarting.')
    if $DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')");
  return ();
}

# generate a hash value ---------------------------------------------hash---
sub hash {
  my $value = shift;
  return substr(MD5->hexhash($value), 0, $ID_LENGTH);
}

sub expire_old_sessions { # --------------------------expire_old_sessions---
  $DBH->do(<<END);
DELETE FROM $DB_TABLE
  WHERE (unix_timestamp() - unix_timestamp(modified)) > $EXPIRE
END
}

# get the state from the database ------------------------------get_state---
sub get_state {
  my $id = shift;  
  my $query =
      "SELECT * FROM $DB_TABLE WHERE session_id = '$id'";
  my $sth = $DBH->prepare($query) || die "Prepare: ", $DBH->errstr;
  $sth->execute || die "Execute: ", $sth->errstr;
  my $state = $sth->fetchrow_hashref;
  $sth->finish;
  return $state;
}


# save the state in the database ------------------------------save_state---
sub save_state {
  my ($state, $id) = @_;
  my $sth = $DBH->prepare(<<END) || die "prepare: ", $DBH->errstr;
UPDATE $DB_TABLE
  SET message=?,comp=?,user=?
  WHERE session_id='$id'
END
  $sth->execute(@{$state}{qw(message comp user)})
    || die "execute: ", $DBH->errstr;
  $sth->finish;
} 
This was developed based on Chad Kotil's code, there was one based on Nathan Adams' code too.

Wed Mar 29
Class Notes to be posted under a different format from now on.

Please review the notes posted for Thu and Fri, labs will focus exclusively on Homework Four.

That is: keeping state with CGI using custom sessions and DBI for database access.

Tue Mar 28
Guest lecture today is canceled, since Aaron can't come any longer.

We start on server-side Java, JDBC and discuss the remaining hoemwork assignments.

Please check your grades in A348-0205, they have been updated Monday morning to include the exams.

Mon Mar 27
In lab this week you need to bring design documents describing your project.

The next few homework assignments are:

Homework Four The exam problem implemented with CGI/DBI and server side state
Homework Five The exam problem implemented with servlets (hidden fields and session based)
Homework Six The exam problem implemented using Java Server Pages (hidden fields and sessions)
Homework Seven The exam problem implemented using Javascript and DHTML

Due dates will be posted soon. Labs will be dedicated to helping with homework.

We also need to pay attention to the project, and your design documents are due this coming week, in lab.

More details on what is needed will be posted here and sent by e-mail to you Sun morning:

Date: Sun, 26 Mar 2006 09:28:51 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A348/A548 Spr. 2006 Distr. List <dgerman@indiana.edu>
Subject: project design documents due in lab this coming week (03/30-31)

As discussed in lab last week design documents for your projects are due
in lab this coming Thu and Fri 03/30-31. You need to describe the screens
and basic functionality of your project as if it's finished, and you want
to pitch it for sale or funding to someone else (me, Craig and Minh).

We will collect these documents and I will give you feedback by the Tue
that follows (04/04). I will tell you how much is enough for A348/A548 and
how I think you "implemented" it. It will be up to you to use the feedback
in any way you want, and the most convenient implementation method for you
but we would then have two more stages in which you would have to show us
the project on the computer, as it's being developed.

Tue we go back to Tomcat, Java servlets and Java Server Pages. The lecture
on PHP/ColdFusion is canceled and we will instead discuss server-side Java,
JDBC and Perl CGI/DBI. This will take care of the next 3 hw assignments (4,
5 and 6) after which we can approach the last assignment (7) which will be
implementing the midterm exam problem using Javascript and DHTML.

Grades up to Lab 10 and Homework 3 and the Midterm Exam are being posted.

If you have any questions or need any help please let me know.

... Adrian

Sat-Sun Mar 25-26
Grades for labs 1-10 and homework assignments 1-3, plus the midterm exam, are being posted.

Next an announcement will be made regarding this coming lab and the remaining homework assignments.

Fri Mar 24
Basic settings for your ~/.bash_profile before installation of Tomcat:
EDITOR=pico
export EDITOR

PATH=/usr/local/gnu/bin:$PATH:/home/user1/mysql/bin
export PATH

JAVA_HOME=/l/jdk1.5
export JAVA_HOME
CATALINA_HOME=/u/dgerman/tomcat/jakarta-tomcat-5.5.9
export CATALINA_HOME
CLASSPATH=.:$CATALINA_HOME/common/lib/servlet-api.jar
export CLASSPATH
You should be using your own username, of course.

Wed-Thu Mar 22-23
We'll try to post Krishna's slides here soon.

Tue Mar 21
In lab this week we install Tomcat.

Deploying servlets requires a web.xml very much like this:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <servlet>
        <servlet-name>One</servlet-name>

        <servlet-class>One</servlet-class>

    </servlet>

    <servlet-mapping>
        <servlet-name>One</servlet-name>

        <url-pattern>/servlet/One</url-pattern>

    </servlet-mapping>

    <servlet>
        <servlet-name>Fv2_3</servlet-name>

        <servlet-class>Two</servlet-class>

    </servlet>

    <servlet-mapping>
        <servlet-name>Fv2_3</servlet-name>

        <url-pattern>/servlet/Fancy</url-pattern>

    </servlet-mapping>


</web-app>

Here's how you tell Tomcat to reload your servlets after you recompile them:
<Server port="15477" shutdown="SHUTDOWN">

  <GlobalNamingResources>
    <!-- Used by Manager webapp -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
       description="User database that can be updated and saved"
           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">
    <Connector port="15476" />

    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase" />

      <Host name="localhost" appBase="webapps">

        <Context path="/nov09" docBase="nov09" debug="0" reloadable="true" />

      </Host>

    </Engine>

  </Service>
</Server>

Sat-Mon Mar 11-20
Have a good Spring Break!

Thu-Fri Mar 9-10
Here's the code we need for Lab Nine:

<?
   function get_book_cats($isbn) {

       $conn = db_connect(); 

       $query = "select dgerman_php_catboo.catid, catname 
                 from dgerman_php_categories, dgerman_php_catboo 
                 where '$isbn' = dgerman_php_catboo.isbn and
                       dgerman_php_categories.catid = dgerman_php_catboo.catid"; 

       $result = @mysql_query($query); 


       if (! $result) return false;



       $num_cats = @mysql_num_rows($result); 
       if ($num_cats == 0) return false; 



              $cat_array = array(); 

              for (
                   $count = 0; 
                   $row = @mysql_fetch_array($result); 
                   $count++
                  ) 
                $cat_array[$count] = $row; 

       if (! is_array($cat_array)) {
                     echo "No categories currently available. <br>"; 
              }



              foreach ($cat_array as $row) {

                     $url = "show_cat.php?catid=".($row["catid"]); 
                     $title = $row["catname"]; 



                     do_html_url($url, $title); 

              }


   } 
 ?>

Wed Mar 8
It looks like after the break we will have two guest lectures:

  • Thu Mar 23 Krishna Kumar (Microsoft, Introducing ASP.NET)

  • Tue Mar 28 Aaron Bond (UITS, Using PHP to emulate ColdFusion)

I will post more details as we get closer to those dates.

Krishna will also buy pizza and soft drinks for everybody for his lecture.

Tue Mar 7
Seven stages to getting started with a registration system in PHP:

  1. stage one
  2. stage two
  3. stage three
  4. stage four
  5. stage five
  6. stage six
  7. stage seven

As far as tables are concerned you can see how we got started here.

Here's the lab for this week:

Fri-Mon Mar 3-6
Congratulations to Jun Yin for her nifty midterm implementation.

Thu Mar 2
Exam in class today, posted. Please finish it in lab.

Wed Mar 1
Exam announcement sent to the class distribution list.

Mon-Tue Feb 27-28
I am in Washington, DC, attending a workshop and returning Tue night.

Sun Feb 26
There will be a review and help session in anticipation of the exam on Tue, in class.
Craig Shue will be teaching Tuesday's class and will be answering all your questions.

Sat Feb 25
Things that you should have completed by the Midterm Exam next week.

Homework One (Apache, HTML) Lab Assignment One (Unix, archiving)
Homework Two
  • Flag Quiz (CGI/h)
Lab Assignment Two (Basic CGI/CGI.pm)
  • helloFive (source code)
  • circular lindley portfolio (next/previous)
Homework Three:
  • Flag Quiz (PHP/h)
  • Flag Quiz (PHP/s)
Lab Assignment Three:
  • password protection
  • PHP installation
Lab Assignment Four
  • basic HTTP
  • GET vs. POST
Lab Assignment Five:
  • First to 100 (CGI/h)
  • First to 100 (PHP/h)
  • First to 100 (PHP/s)
Lab Assignment Six:
  • Guess the Number (CGI/h)
  • Guess the Number (PHP/h)
  • Guess the Number (PHP/s)
Lab Assignment Seven:
  • Addition Quiz (CGI/h)
  • Addition Quiz (PHP/h)
  • Addition Quiz (PHP/s)

Fri Feb 24
Programs developed in class yesterday:

  1. program one (source code)
  2. program two (source code)

Thu Feb 23
Here's what we do in labs today and tomorrow.

Wed Feb 22
Minh's office hours today will be at 5:30pm in 201I (instead of the normal time).

Tue Feb 21
Programs written in class today (pay attention to the differences).

Sun-Mon Feb 19-20
Programs developed with Greg Bailey on Friday, during office hours:

Sat Feb 18
Program developed by Adam Licht in class on Thu:
<? session_start();
   if (
$message){

   }else{
     
session_register("secret");
     
session_register("attempts");
     
session_register("message");
     
$secret = rand(1,100);
     
$attempts = 0;
     
$message = "Welcome to the game";
   }


?>


<form>
The secret number is <?=$secret?><p>
You've tried <?=$attempts?> tries<p>
<?=$message?><p>
Please enter your guess here: <input type="text" name="guess"><p>
Please push <input type="submit" name="action" value="Submit"><p>

</form>

Thu-Fri Feb 15-16
Here's our new password for your protected folder
dgerman:xAzOFxiQYqKxE

Wed Feb 15
Here's the plan for this week's labs.

Tue Feb 14
Thanks to Matt Myjak here's the code developed in class today:

You must be able to start seeing how close these programs are to each other!

They're almost, almost identical.

Mon Feb 13
This week bring to lab three versions of the first-to-100 program:

  1. a version written in CGI/Perl using hidden fields to keep state
  2. a version written in PHP using session variables to keep state, and
  3. a version written in PHP using hidden fields to keep state.

In class we will discuss server-side management of state (in general).

We will then develop tools to implement that using CGI/Perl and MySQL.

Sun Feb 12
Some outstanding work, thus far:

Jun Yin

Jun Yin's Spiffy Lab Five Program
Keira Johnson

Keira Johnson's Homework Two
Jonathan Warren

Jonathan Warren's Homework Two

This list is not exhaustive by any means.

But I hope it is a source of inspiration to all of us.

Sat Feb 11
Another note from Ben Klopfer, now with Epic Systems.

Fri Feb 10
Programs developed yesterday in class: one, two.

Thu Feb 9
Plans for the labs this week described in e-mail sent last night to Craig and Minh.

A note from a former student.

Wed Feb 8
Mock-up for the "First-to-100-Wins" problem.

Sun-Tue Feb 5-7
Here are the two PHP programs developed in class on Tue: one, two.

Their prototype is the minute paper for Tue: this program developed with CGI.pm.

Sat Feb 4
Here's Lab Assignment Two developed with Tim Devlin in lab on Friday:
#!/usr/bin/perl

%images = (
  "One"     =>    "http://www.cs.indiana.edu/dept/img/lh01.gif", 
  "Seven"   =>    "http://www.cs.indiana.edu/dept/img/lh07.gif", 
  "Eight"   =>    "http://www.cs.indiana.edu/dept/img/lh08.gif", 
  "Nine"    =>    "http://www.cs.indiana.edu/dept/img/lh09.gif"
); 

@keys = ("One", "Seven", "Eight", "Nine"); 

use CGI; 
$q = new CGI; 

print $q->header, $q->start_html;

$index = $q->param('index'); # read the value for the parameter named index in the input 

$action = $q->param('action'); 

if ($action eq "previous") { 
  $index = $index -1 ; 
  if ($index < 0) { $index = 3; } 
} elsif ($action eq "next pic") { 
  $index = $index + 1; 
  if ($index >= 4) { $index = 0; } 
} else { 
  $index = 0; 
} 

$key = $keys[$index]; 
$picture = $images{$key}; 

print qq{
  <form>
  <table>
  <tr> <td> <input type="submit" name="action" value="previous">
       <td align=right> <input type="submit" name="action" value="next pic">
  <tr> <td colspan=2> You are looking at picture $key 
  <tr> <td colspan=2> <img src="$picture">

  </table>
  <input type="hidden" name="index" value="$index">
  </form>
}; 

print $q->end_html; 

Fri Feb 3
Don't forget this setting in php.ini after installation:
register_globals = On
You should also create a phpsessions to keep session information in it.

Thu Feb 2
In labs this week please install PHP like we did on Thu.

Here's the PHP code we developed at the end of Thu's class:

<?
   $balance
+= $amount;

?>

<form>
The current balance is: <? echo $balance; ?> <p>

Please enter the amount here: <input type="text" name="amount"> <p>

Chooose an action: <select name="what">
  <option value="none"> Click me!
  <option value="deposit"> Deposit
  <option value="withdraw"> Withdraw
</select>

<input type="hidden" name="balance" value="<? echo $balance; ?>">

<p> Please press <input type="submit" value="Proceed"> when ready.

</form>

Wed Feb 1
Here's the code we developed in class on Tuesday:
#!/usr/bin/perl

@answers = ("zero", "one", "two", "three", "four", "five", "six", "seven"); 

use CGI;

$q = new CGI; 

print $q->header, $q->start_html; 

$times = $q->param('times'); 
$times += 0; 
$action = $q->param('action'); 
$userInput = $q->param('userInput'); 

if ($answers[$times] eq $userInput) { # skip it first time around 
  $message = "Very good, that was the answer."; 
} else { 
  $message = "Too bad, better be more careful next time."; 
} 

if ($action =~ /next/) { $times += 1; } 
elsif ($action =~ /previous/) { $times -= 1; } 
else { } 
#--------------------(no printing above on  purpose)-------
print qq{
  <form>
    <table>
    <tr> <td> <input type="submit" name="action" value="previous"> 
         <td> <input type="submit" name="action" value="next"> 
    <tr> <td colspan=2> $message         
    <tr> <td colspan=2> You are looking at picture: $times <p> 
    <input type="hidden" name="times" value="$times"> 
    <tr> <td colspan=2> Please type here the number you see: 
                        <input type="text" name="userInput"> 
    </table>
  </form> 
};

print $q->end_html; 

Tue Jan 31
This week in lab we will install PHP and discuss the HTTP lab tutorial.

In class we will discuss keeping state on the server side (tutorial 12 and the associated example).

Fri-Mon Jan 27-30
Please review Tutorial 9 for information on CGI.pm which will come in handy shortly.

Thu Jan 26
Things you might need:

Don't forget that Homework Two is just like the Lab Assignment Two program.

Except we also collect the answers, which we grade, and tally.

Wed Jan 25
The first program developed in class yesterday:
#!/usr/bin/perl

print qq{Content-type: text/html\n\n<html><head><title>CGI Processor</title><head><body bgcolor="white">};

&readParse; 

foreach $k (keys %in) {
  print $k, " --> ", $in{$k}, "<br>"; 
}

$input = $ENV{"QUERY_STRING"}; 

print qq{
  ($input) <hr> 

  <form>
    <table border cellpadding=3>
      <tr> <td> Field one: <td> <input type="text" name="one"> 
      <tr> <td> Field two: <td> <input type="text" name="two"> 
    </table> <p> 
    Please press <input type="submit" value="Proceed"> 
  </form>
};

print qq{</body></html>}; 

sub readParse {
  $user = $ENV{"QUERY_STRING"}; 
  @pairs = split(/&/, $user); 
  foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair, 2); 
    $value =~ s/%(..)/chr(hex($1))/ge; 
    $in{$name} = $value; 
  } 
}
The second program that starts us on the sequential portfolio:
#!/usr/bin/perl

print qq{Content-type: text/html\n\n<html><head><title>CGI Processor</title><head><body bgcolor="white">};

&readParse; 

%images = (
  "One"     =>    "http://www.cs.indiana.edu/dept/img/lh01.gif", 
  "Seven"   =>    "http://www.cs.indiana.edu/dept/img/lh07.gif", 
  "Eight"   =>    "http://www.cs.indiana.edu/dept/img/lh08.gif", 
  "Nine"    =>    "http://www.cs.indiana.edu/dept/img/lh09.gif"
); 

$pic = "lh01.gif"; 

$pic = $in{"pic"} if ($images{$in{"pic"}}); 

if ($in{"Next"}) {
   
} elsif ($in{"Previous"}) {
  
} else {

}

print qq{
  <form>
    <table>
    <tr>
    <td> <input type="submit" name="previous" value="Previous">
    <td> <input type="submit" name="next" value="Next">
    <tr><td colspan=2> <img src="http://www.cs.indiana.edu/dept/img/$pic">
    </table> 
    <input type="hidden" name="pic" value="$pic"> 
  </form> 

};

print qq{</body></html>}; 

sub readParse {
  $user = $ENV{"QUERY_STRING"}; 
  @pairs = split(/&/, $user); 
  foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair, 2); 
    $value =~ s/%(..)/chr(hex($1))/ge; 
    $in{$name} = $value; 
  } 
}

Tue Jan 24
Attention will be given this week to Lab Assignment Two and Homework Two.

Here's a framework we need to start understanding.

Mon Jan 23
Lecture Notes for the week to be posted during the day.

(They're mostly in the right places, they just need to be cleaned up a bit).

Sun Jan 22
Attendance/grades updated: choose section A348-0205.

Click here to see if your archive is accessible.

Sat Jan 21
Minh Tang joins A348/A548, labs to be taught as follows:

Thursday lab
3:35pm-5:30pm
Lindley Hall 115
Craig Shue (assisted by Minh Tang)
Friday first lab
10:10am-12:05pm
Lindley Hall 025
Adrian German (assisted by Craig Shue)
Friday second lab
12:20pm- 2:15pm
Lindley Hall 025
Minh Tang (assisted by Adrian German)

Fri Jan 20
Don't forget that the permissions for Lab One are:
chmod 711 ~
chmod 755 ~/public
chmod 644 ~/public/whoa.tar.gz

Thu Jan 19
Here's how you change the default editor:
  1. create a ~/.bash-profile file with two lines
  2. first line reads EDITOR=pico
  3. second line reads export EDITOR

From here on every time you login pico is your default editor.

Type crontab -e to use it to change your crontab entries.

Wed Jan 18
The Thu lab is now in Lindley 115 (at the same time, 3:35-5:30pm).

Tue Jan 17
Attendance (minute papers) updated: choose section A348-0205.

Mon Jan 16
Lecture and lab notes for this week and the next sketched.

Lab notes for this week will be finalized Tuesday night.

Sat-Sun Jan 14-15
Lecture Notes for the week, Homework One posted.

Fri Jan 13
Attendance (minute papers) updated: choose section A348-0205.

Thu Jan 12
Lecture Notes Three have been posted.

Attendance (minute papers) is collected here: A348-0205.
(PostEm will soon appear listed as a tool in OnCourse.)

Wed Jan 11
After two days of confusing announcements STCSITE tells us that
CSCI-A 348/A548 (14754/14764)  R  3:35PM - 5:30PM
has been moved to ED2015.

Please make a note of it (location is close to the original venue).

Tue Jan 10
Class information from the Office of the Registrar.

Mon Jan 9
Class starts tomorrow, here's the schedule for this semester:
LEC 1:00pm-2:15pm TR LH102 German
LAB 3:35pm-5:30pm R ED2025
LAB 10:10am-12:05pm F LH025
LAB 12:20pm-2:15pm F LH025


Updated by Adrian German for A348/A548