Index: /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/authenticate.php
===================================================================
--- /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/authenticate.php	(revision 42993)
+++ /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/authenticate.php	(revision 42994)
@@ -3,9 +3,15 @@
 // function check_login()
 
+$lifetime=86400;
 session_start();
+setcookie(session_name(),session_id(),time()+$lifetime);
+ini_set('session.gc_maxlifetime', 86400);
 
 // XXX TODO use mysql
-$auth_user="setme";
-$auth_passwd="setmetoo";
+$auth_user="SET_ME";
+$auth_passwd="SET_ME";
+
+$alt_user="SET_ME";
+$alt_passwd="SET_ME";
 
 $user   = $_SERVER['PHP_AUTH_USER'];
@@ -13,12 +19,14 @@
 $did_login = isset($_SESSION['did_login']);
 
-if ($did_login && isset($user) && isset($passwd) &&
-    ($auth_user == $user) && ($auth_passwd == $passwd)) {
+# uncomment this to skipp authentication
+$skip_login = 0;
 
-    echo "Welcome:  " . $user;
-    echo "&nbsp;&nbsp;&nbsp; <a href=\"./logout.php\">Logout</a>";
-    echo "<br />";
-    echo "<br />";
-} else {
+$valid_pwd = 0;
+if ($did_login && isset($user) && isset($passwd)) {
+  $valid_pwd = $valid_pwd || (($auth_user == $user) && ($auth_passwd == $passwd));
+  $valid_pwd = $valid_pwd || (($alt_user  == $user) && ($alt_passwd  == $passwd));
+ }
+
+if (!$skip_login && !$valid_pwd) {
     $_SESSION['did_login'] = true;
     header('WWW-Authenticate: Basic realm="Restricted Section"');
@@ -31,3 +39,27 @@
 
 ?>
+<?php
+function welcomeHeader($user, $link, $text)
+{
+    echo "Welcome:  " . $user;  //  . "<br /><br />";
+    echo "&nbsp;&nbsp;&nbsp;";
+    echo "<a href=\"./logout.php\">Logout</a>";
+    echo "&nbsp;&nbsp;&nbsp;\n";
+    if ($link) {
+        echo "<a href=\"./$link\">$text</a>";
+    }
+    include "pstamp_links.php";
+    echo "<br /><br />";
 
+    // Top of the page is the contents of the "message of the day file"
+    // This can be empty but must exist or the user sees an error.
+    $motd_filename = "pstamp_motd.html";
+    $file = fopen($motd_filename, "r");
+    if ($file) {
+        fpassthru($file);
+    }
+
+//    echo "<br />";
+//    echo "<br />";
+}
+?>
Index: /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/dsroot.php
===================================================================
--- /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/dsroot.php	(revision 42994)
+++ /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/dsroot.php	(revision 42994)
@@ -0,0 +1,101 @@
+<?php // upload.php
+
+// get the locatl configuration variables
+require "pstamp.php";
+require "dblogin.php";
+
+
+$user = $_SERVER['PHP_AUTH_USER'];
+$passwd = $_SERVER['PHP_AUTH_PW'];
+?>
+
+<HTML>
+<head>
+    <title>
+        Links to the IPP data store
+    </title>
+    <script type='text/javascript'>
+    setTimeout('countdown()', 100);
+
+    function countdown() {
+    var s = document.getElementById('timer');
+    s.innerHTML = s.innerHTML - 1;
+    if (s.innerHTML == 0)
+  //    window.location = 'http://pstamp.ipp.ifa.hawaii.edu/dsroot.php';
+      location.reload();
+    else
+    setTimeout('countdown()', 1000*60);
+    }
+    </script>
+</head>
+<body>
+<H1 align=center>
+IPP DataStore
+</h1>
+
+<?php
+
+welcomeHeader($auth_user, "", "");
+
+echo "<body>\n";
+echo "The page will NOW refresh in <span id='timer'> 20</span> mins";
+$dbserver = dblogin();
+
+$query = "SELECT prod_name, last_fs, last_update, type, description FROM dsProduct ORDER BY type, prod_id";
+$result = mysqli_query($dbserver, $query);
+if (!$result) {
+    die("Database access failed: " . mysqli_error($dbserver));
+}
+
+echo "<table><tr><th>productID</th><th>Most recent </th><th>Time registered</th>";
+echo "<th>type     </th><th>Description</th></tr>\n";
+
+$rows = mysqli_num_rows($result);
+
+for ($i = 0; $i < $rows; $i++) {
+    $row = mysqli_fetch_row($result);
+    echo "<tr>";
+    $prod_name = $row[0];
+    echo "<td>";
+    // echo "<a href=\"http://datastore.ipp.ifa.hawaii.edu/$prod_name\">$prod_name</a>";
+    //$prod_link = "http://datastore.ipp.ifa.hawaii.edu/$prod_name";
+    $prod_link = "http://datastore.ipp.ifa.hawaii.edu/ds/$prod_name";
+
+    // $prod_link "<a href=\"http://datastore.ipp.ifa.hawaii.edu/$prod_name\">$prod_name</a>";
+    echo "<a href=\"$prod_link\">$prod_name</a>";
+    
+    echo "</td>";
+
+    $last_fs = $row[1];
+    echo "<td>";
+    if ($last_fs && ($last_fs != "none")) {
+        echo "<a href=\"$prod_link/$last_fs\">$last_fs</a>";
+    } else {
+        echo "none";
+    }
+    echo "</td>\n";
+
+    $time_reg = $row[2];
+    list($reg_date, $reg_time) = sscanf($time_reg, "%s %s");
+    echo "<td>" . $reg_date . "T" . $reg_time . "Z" . "</td>";
+
+    $type = $row[3];
+    echo "<td>$type</td>";
+    $description = $row[4];
+    echo "<td>$description</td>";
+    echo "</tr>\n";
+
+}
+echo "</table>\n";
+
+
+// BEGIN debugging area
+
+// print lots of information
+// phpinfo(-1);
+// print the most useful variables
+// phpinfo(32);
+
+echo "</body></html>";
+
+?>
Index: /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/logout.php
===================================================================
--- /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/logout.php	(revision 42993)
+++ /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/logout.php	(revision 42994)
@@ -7,12 +7,17 @@
 $_SESSION = array();
 if (isset($_COOKIE[session_name()])) {
-    setcookie(session_name(), '', time()-42000, '/');
+    setcookie(session_name(), '', time()+3600, '/');
 }
 session_destroy();
 
 echo "You are now logged out<br /><br />";
-echo "<a href=\"./upload.php\">Upload</a>";
 
-// phpinfo(32);
 ?>
+<a href="./pshome.php">Postage Stamp Home</a>
+<br />
+<br />
+<?php
 
+include "pstamp_links.php";
+
+?>
Index: /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/request.php
===================================================================
--- /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/request.php	(revision 42993)
+++ /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/request.php	(revision 42994)
@@ -14,5 +14,6 @@
 // The mode for the page is given by $request_id != 0
 
-// XXX This is just a prototype for testing purposes. 
+// XXX This was intended to just be a prototype for testing purposes but people have
+// become dependent on it so it lives on
 
 require "pstamp.php";
@@ -27,4 +28,7 @@
 // Initialize variables
 $output_array = array();
+
+// set to 1 to print command line and to change label to TEST
+$TESTING = 0;
 
 $request_id = 0;
@@ -35,4 +39,5 @@
 $warp_selected = "";
 $stack_selected = "";
+$stack_summary_selected = "";
 $diff_selected = "";
 
@@ -56,14 +61,19 @@
 
 $gpc1_selected="";
+$gpc2_selected="";
 $mops_selected="";
 $simtest_selected="";
 
-$require_class_id = 0;
-
+$require_component = 0;
+
+$rvar_email = "";
 $rvar_select_by = "";
 $rvar_img_type = "";
 $rvar_id = "";
-$rvar_class_id = "";
-$rvar_cell_id = "";
+$rvar_component = "";
+$rvar_survey = "bypass";
+$rvar_release = "";
+$rvar_data_group = "";
+$rvar_filter = "";
 
 $rvar_center_type = "";
@@ -79,4 +89,7 @@
 $rvar_H = "";
 
+$rvar_make_jpeg = "";
+$rvar_getall_roi = "";
+
 $rvar_cmd_mode = "";
 $rvar_last_cmd_mode = "";
@@ -90,11 +103,13 @@
 if ($rvar_project == "gpc1") {
     $gpc1_selected = "selected";
-//    $require_class_id = 1;
+//    $require_component = 1;
+} else if ($rvar_project == "gpc2") {
+    $gpc2_selected = "selected";
 } else if ($rvar_project == "megacam-mops") {
     $mops_selected = "selected";
-    $require_class_id = 0;
+    $require_component = 0;
 } else { //    if ($rvar_project == "simtest") {
     $simtest_selected = "selected";
-    $require_class_id = 0;
+    $require_component = 0;
 }
 
@@ -123,4 +138,6 @@
 } else if ($rvar_img_type == "stack") {
     $stack_selected = "selected";
+} else if ($rvar_img_type == "stack_summary") {
+    $stack_summary_selected = "selected";
 } else if ($rvar_img_type == "diff") {
     $diff_selected = "selected";
@@ -145,4 +162,16 @@
 }
 
+if ($rvar_make_jpeg) {
+    $make_jpeg_checked = "checked";
+} else {
+    $make_jpeg_checked = "";
+}
+
+if ($rvar_getall_roi) {
+    $getall_roi_checked = "checked";
+} else {
+    $getall_roi_checked = "";
+}
+
 // When request_id is non-zero we respond to posts by check the status of that request
 // request_id gets set to zero when the status of all jobs for the request is 'stop'
@@ -162,5 +191,5 @@
 if ($rvar_cmd_mode == "Make Stamps") {
     $pstamp_checked = "checked";
-} else if ($rvar_cmd_mode == "Get Images") {
+} else if ($rvar_cmd_mode == "Get Bundles") {
     $get_checked = "checked";
 } else if ($rvar_cmd_mode == "Get Status") {
@@ -185,19 +214,38 @@
         try {
             $command_line = build_request_cmd();
+            if ($TESTING) {
+                echo "$command_line\n";
+            }
             $error_line = "";
-            run_command($command_line);
+            $command_status = run_command($command_line);
+            // run_command($command_line);
             if (! $list_checked) {
-                // The only output from a successful run is the request_id
-                $request_name = trim(Array_pop($output_array));
-                $request_id = Array_pop($output_array);
-                $last_request_id = $request_id;
-                if ($request_id && $request_name) {
+                // The only output from a successful run is the request_id and the request name
+                $words = array();
+                $words = explode(" ", trim(Array_pop($output_array)));
+                $request_id = $words[0];
+                $request_name = $words[1];
+
+                // echo "<br>Submission Results: Request_name: $request_name Request_id $request_id status: $command_status\n<br>";
+                $whatthaheck =  $request_id && $request_name;
+                // $whatthaheck = !$command_status;
+                // echo "<br>Boolean: $whatthaheck\n<br>";
+
+                // XXX: for some reason this does not evaluate to true
+                // if (!$command_status && $request_id && $request_name) {
+                if (!$command_status) {
+                    $last_request_id = $request_id;
                     addRequest($request_id, $request_name);
                     // setcookie("our_request_id", $request_id);
                     // echo "The request id is $request_id\n";
+                    // switch page Mode to Get Status
                     $getstatus_checked = "checked";
                     $pstamp_checked = "";
+                    $get_checked = "";
                 } else {
+                    echo "got an error\n";
                     // XXX: TODO print out the error
+                    // This doesn't work
+                    // echo "$error_line\n";
                     if (count($output_array) != 0) {
                         throw new Exception("unexpected output returned by pstampwebrequest.");
@@ -211,4 +259,8 @@
         }
     }
+} else {
+    // default to stack
+    $rvar_img_type = "stack";
+    $stack_selected = "selected";
 }
 
@@ -218,4 +270,5 @@
 {
     global $rvar_project;
+    global $rvar_email;
     global $sky_checked, $rsky_checked;
     global $list_checked;
@@ -227,14 +280,26 @@
     global $exp_checked, $file_checked, $coord_checked, $diff_checked;
     global $rvar_img_type;
-    global $rvar_id, $rvar_class_id;
+    global $rvar_id, $rvar_component;
+    global $rvar_data_group, $rvar_filter;
+    global $rvar_survey, $rvar_release;
     global $command_line;
     global $dbname;
     global $dbserver;
-    global $require_class_id;
+    global $require_component;
     global $PSCONFDIR, $PSCONFIG, $WORKDIR;
     global $SCRIPT;
+    global $TESTING;
+    global $rvar_make_jpeg;
+    global $rvar_getall_roi;
 
     $making_stamps = 1;
     $cmd = "$SCRIPT pstamp_webrequest.pl";
+
+//    echo "list_checked: $list_checked\n";
+//    echo "get_checked: $get_checked\n<br>";
+
+    if ($TESTING) {
+        $cmd .= " --label TEST";
+    } 
 
     if ($list_checked) {
@@ -245,8 +310,17 @@
         $cmd .= " --job_type get_image";
     }
+//    echo "making_stamps: $making_stamps<br>\n";
+//    echo "$cmd<br>\n";
 
     if ($dbname) {
         $cmd .= " --dbname $dbname --dbserver $dbserver";
     }
+
+    if (! $rvar_email ) {
+        throw new Exception('Email address must be specified.');
+    }
+    // TODO: check for "valid" email address
+    $cmd .= " --username $rvar_email";  // This arg is used by pstamptool -addreq
+    $cmd .= " --email $rvar_email";     // This is used by psmkreq
 
     if (! $rvar_project ) {
@@ -258,28 +332,41 @@
         // TODO: put options on the GUI for these
 //        $cmd .= " -mask -weight";
-    }
-
-    if ($making_stamps || $coord_checked) {
+        if ($rvar_img_type == "stack_summary") {
+            $cmd .= " --option_mask 196673";
+        }
+    }
+
+    if ($making_stamps) { //  || $coord_checked) {
         // Set up the ROI parameters
+        $wholefile = 0;
         if ($sky_checked) {
-            if (! $rvar_RA || ! $rvar_DEC) {
-                throw new Exception('RA and DEC must be specified.');
+            if ($rvar_RA == NULL || $rvar_DEC == NULL) {
+                throw new Exception("RA and DEC must be specified. Got: ($rvar_RA, $rvar_DEC)");
             }
             $cmd .= " --ra $rvar_RA --dec $rvar_DEC";
         } else {
-            if (! $rvar_X || ! $rvar_Y) {
-                throw new Exception('X and Y must be specified.');
-            }
-            $cmd .= " -pixcenter --x $rvar_X --y $rvar_Y";
+            if ($rvar_X == NULL || $rvar_Y == NULL) {
+            }
+            if ($rvar_X == 0 && $rvar_Y == 0) {
+                // Pixel center with both coordinates == 0 is code for return the whole file
+                $wholefile = 1;
+            }
+            $cmd .= " --pixcenter --x $rvar_X --y $rvar_Y";
         }
 
         if ($rsky_checked) {
             if (! $rvar_dRA || ! $rvar_dDEC) {
-                throw new Exception('dRA and dDEC must be specified.');
+                throw new Exception('dRA and dDEC must be non zero.');
             }
             $cmd .= " --arcseconds --width $rvar_dRA --height $rvar_dDEC";
         } else {
             if (! $rvar_W || ! $rvar_H) {
-                throw new Exception('width and height must be specified.');
+                $wholefile = 1;
+            }
+            if ($wholefile) {
+                $rvar_W = 0;
+                $rvar_H = 0;
+            // } else if (! $rvar_W || ! $rvar_H) {
+            //     throw new Exception('width and height must be specified and non zero.');
             }
             $cmd .= " --width $rvar_W --height $rvar_H";
@@ -298,10 +385,15 @@
         }
         if (! $rvar_id ) {
-            throw new Exception('Must set ID to the Exposure ID.');
+            throw new Exception('Must set ID to the Exposure name.');
         }
         $cmd .= " --req_type byexp --stage $rvar_img_type --id $rvar_id";
     } else if ($file_checked) {
         if (! $rvar_id ) {
-            throw new Exception('Must set ID to the exposure name.');
+            throw new Exception("Must set ID to the ${rvar_img_type}_id.");
+        }
+        $id = $rvar_id + 0;
+//        echo "id is $id  rvar_id is $rvar_id\n";
+        if (!$id) {
+            throw new Exception("$rvar_id is not a valid ${rvar_img_type}_id.");
         }
         $cmd .= " --req_type byid --stage $rvar_img_type --id $rvar_id";
@@ -317,14 +409,40 @@
     }
 
-// XXX: don't need to require class_id anymore
+// XXX: don't need to require component anymore
 //    if (($rvar_img_type == "raw") || ($rvar_img_type == "chip")) {
-//        if (!$sky_checked && ($require_class_id && ! $rvar_class_id )) {
+//        if (!$sky_checked && ($require_component && ! $rvar_component )) {
 //            throw new Exception("must specify Class ID with Image Type $rvar_img_type.");
 //        }
-        // leave off compoennt if we're looking up by coordinates. It breaks it
-        if (!$coord_checked && (($rvar_class_id) && ($rvar_class_id != "all"))) {
-            $cmd .= " --component $rvar_class_id";
+        // leave off component if we're looking up by coordinates. The parser will figure it out
+        // IS THIS  a good idea? What if somebody only wants images from a particular skycell?
+        if (!$coord_checked && (($rvar_component) && ($rvar_component != "all"))) {
+            $cmd .= " --component $rvar_component";
         }
 //    }
+
+    if ($rvar_survey) {
+        $cmd .= " --survey $rvar_survey";
+    }
+    if ($rvar_release) {
+        $cmd .= " --release $rvar_release";
+    }
+    if ($rvar_data_group) {
+        $cmd .= " --data_group $rvar_data_group";
+    }
+    if ($rvar_filter) {
+        $cmd .= " --filter $rvar_filter";
+    }
+
+    if ($rvar_img_type == 'stack') {
+        $cmd .= " --unconvolved";
+    }
+
+    if ($rvar_make_jpeg) {
+        $cmd .= " --jpeg";
+    }
+
+    if ($rvar_getall_roi) {
+        $cmd .= " --allroi";
+    }
 
     return escapeshellcmd($cmd);
@@ -337,5 +455,5 @@
     global $command_status;
 
-    //    echo "running $command_line\n";
+    // echo "<br>running $command_line\n<br>";
 
     exec ("$command_line", $output_array, $command_status);
@@ -349,5 +467,5 @@
             echo "Output: $size lines\n";
             for ($i = 0; $i < $size; $i++) {
-                echo "$output_array[$i]\n";
+                echo "<br>$i: $output_array[$i]\n";
             }
         }
@@ -359,5 +477,5 @@
         }
     }
-
+    return $command_status;
 }
 
@@ -386,5 +504,7 @@
                 $dirName  = "$dsroot/$product/$req_name";
                 // XXX: TODO: make this a configuration parameter
-                $filesetURL = "http://datastore.ipp.ifa.hawaii.edu/$product/$req_name";
+                //$filesetURL = "http://datastore.ipp.ifa.hawaii.edu/$product/$req_name";
+                $filesetURL = "http://datastore.ipp.ifa.hawaii.edu/ds/$product/$req_name";
+
                 $fullpath = "$dirName/$fileName";
 // echo "<pre>fullpath: $fullpath filesetURL: $filesetURL\n</pre>";
@@ -422,21 +542,49 @@
 <head>
   <title>
-    Postage Stamp Request Form (prototype)
+    Prototype Postage Stamp Request Form : test
   </title>
+  <script type='text/javascript'>
+  setTimeout('countdown()', 100);
+  
+  function countdown() {
+  var s = document.getElementById('timer');
+  s.innerHTML = s.innerHTML - 1;
+  if (s.innerHTML == 0)
+//    window.location = 'http://pstamp.ipp.ifa.hawaii.edu/request.php';
+    location.reload();
+  else
+  setTimeout('countdown()', 1000*60);
+  }
+  </script>
 </head>
 <body>
 
 <H1 align=center>
-Postage Stamp Request Form
+Prototype Postage Stamp Request Form : test
 </h1>
 
 <?php
-    welcomeHeader($auth_user, "pstamp_links.php", "Postage Stamp Home");
+    welcomeHeader($auth_user, 0, 0);
+    echo "<br>\n";
 ?>
 
 <form method="post">
+
+<b>Notice: This request submission form is an obsolete prototype -- MODIFIED 20180501 </b>
+
+<br><br><b>Some time soon this form will no longer be available.
+<br> <br>Please migrate our requests to new more fully featured postage stamp
+interface located at </b>
+<a href=http://psps.ifa.hawaii.edu/PSI/postage_stamp.php>PSI Postage Stamp Request Form</a>.
+<br>
+<b>Or upload your own request tables using the upload link.</b>
+<br><br>
+<b>This page will refresh in <span id='timer'>20</span> mins</b>
+<! -- Add link to STSCI page as well -->
+<br><br><br>
+
+
+
 <!-- Whole page is a single column table -->
-
-
 <table width=90% align=center>
 
@@ -447,4 +595,15 @@
 
 <table width=100% align=center>
+
+<tr>
+<td>
+</td>
+<td align = left> 
+<b>Email Address:</b>&nbsp;&nbsp; 
+<input type="text" name="email" size=60 value= "<?php echo $rvar_email; ?>" >&nbsp; REQUIRED
+</td>
+<td>
+</td>
+</tr>
 
 <!-- first row of image selector is "Project" pulldown menu "Select Image By" radio boxes -->
@@ -455,4 +614,5 @@
         <td><select name="project">
            <option <?php echo $gpc1_selected;?> >gpc1
+           <option <?php echo $gpc2_selected;?> >gpc2
 <!--
            <option <?php echo $mops_selected;?> >megacam-mops
@@ -490,4 +650,5 @@
             <option <?php echo $warp_selected ;?> >warp
             <option <?php echo $stack_selected;?> >stack   
+            <option <?php echo $stack_summary_selected;?> >stack_summary   
             <option <?php echo $diff_selected;?>  >diff
             <option <?php echo $raw_selected;?>   >raw
@@ -499,23 +660,16 @@
 <td>
 &nbsp;<b>ID/Name:</b>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-<input type="text" name="id" value= <?php echo $rvar_id; ?> >
+<input type="text" name="id" size=14 value= <?php echo $rvar_id; ?> >
 &nbsp;&nbsp;&nbsp;&nbsp;
-<b>
-<?php if (0 && $rvar_project == "gpc1") {
-        echo "Chip ID:";
-      } else {
-        echo "Component:";
-      }
-?>
-</b>
-&nbsp;<input type="text" name="class_id" size=10 value="<?php echo $rvar_class_id;?>" >
-
+<b>Component:</b> &nbsp; <input type="text" name="component" size=14 value="<?php echo $rvar_component;?>" >
 &nbsp;&nbsp;&nbsp;&nbsp;
-<!-- add text input field for Cell ID, not used yet -->
-
-<!--
-<b>Cell ID:</b>&nbsp;<input type="text" name="cell_id" size=10 value="<?php echo $rvar_cell_id;?>" >
-
--->
+
+<b>Survey:<input type="text" name="survey" size=6 value="<?php echo $rvar_survey;?>" >
+&nbsp;&nbsp;&nbsp;&nbsp;
+<b>Release:<input type="text" name="release" size=6 value="<?php echo $rvar_release;?>" >
+&nbsp;&nbsp;&nbsp;&nbsp;
+<b>Data Group:<input type="text" name="data_group" size=14 value="<?php echo $rvar_data_group;?>" >
+<b>Filter:<input type="text" name="filter" size=3 value="<?php echo $rvar_filter;?>" >
+
 
 </td>
@@ -612,4 +766,17 @@
         </td>
     </tr>
+    <!-- a blank row for space-->
+    <tr height=20><td></td>
+    </tr>
+    <tr>
+        <td>
+            <input type=checkbox name ="make_jpeg" value="value" checked="<?php echo $make_jpeg_checked; ?>" >Produce a JPEG
+        <td>
+    </tr>
+    <tr>
+        <td>
+            <input type=checkbox name ="getall_roi" value="value" checked="<?php echo $getall_roi_checked; ?>" >Include all images in ROI (MOPS)
+        <td>
+    </tr>
     </table>
     </td>
@@ -628,5 +795,5 @@
     <input type=radio name="cmd_mode" value="Get Status"<?php echo $getstatus_checked; ?> >Get Status
     <input type=radio name="cmd_mode" value="Make Stamps"<?php echo $pstamp_checked; ?> >Make Stamps
-    <input type=radio name="cmd_mode" value="Get Images" <?php echo $get_checked; ?> >Get Bundles
+    <input type=radio name="cmd_mode" value="Get Bundles" <?php echo $get_checked; ?> >Get Bundles
 <!--
     <input type=radio name="cmd_mode" value="List Images" <?php echo $list_checked; ?> >List Images
@@ -683,31 +850,4 @@
 <caption height=10 valign=center><b>Request Results</b></caption>
 
-<?php 
-if (0) {
-    // This is the old way of listing the status of the current request.
-    // now we save the submitted requests in the session see listRequests() below
-
-    $size = sizeof($output_array);
-    // echo "<pre>size of output array is $size\n</pre>";
-    if ($command_status == 0) {
-        if ($list_checked) {
-            // in list mode the output is a list of image files, just list them
-            // later we might add links to cause a stamp to be made from a selected file
-            for ($i = 0; $i < $size; $i++)  {
-                // $uri = array_shift($output_array);
-                $uri = $output_array[$i];
-                echo "<tr><td>$uri</td></tr>";
-            }
-        } else {
-            // output the list of urls
-            for ($i = 0; $i < $size; $i++)  {
-                // $uri = array_shift($output_array);
-                $uri = $output_array[$i];
-                printURL($uri);
-            }
-        }
-    }
-} // end if if(0)
-?>
 </table>
 </td>
@@ -737,5 +877,7 @@
 
 <?php
-    listRequests("http://datastore.ipp.ifa.hawaii.edu/pstampresults", "pstamp_results_fileset");
+    // echo "calling listRequests\n";
+    //listRequests("http://datastore.ipp.ifa.hawaii.edu", "pstamp_results_fileset");
+    listRequests("http://datastore.ipp.ifa.hawaii.edu/ds", "pstamp_results_fileset");
 ?>
 
Index: /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/submitted.php
===================================================================
--- /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/submitted.php	(revision 42994)
+++ /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/submitted.php	(revision 42994)
@@ -0,0 +1,210 @@
+<?php
+
+require_once "dblogin.php";
+
+class Request
+{
+    public $id;
+    public $name;
+    function __construct($p1, $p2)
+    {
+        $this->id = $p1;
+        $this->name = $p2;
+        $this->state = "new";
+        $this->fault = 0;
+        $this->jobs = 0;
+    }
+    function __destruct()
+    {
+        // print "Destroying " . $this->name. "\n";
+    }
+}
+
+function initializeRequests()
+{
+    if (!isset($_SESSION['requests'])) {
+        // echo "<br />initializing requests<br />\n";
+        $_SESSION['requests'] = array();
+    }
+}
+
+function addRequest($req_id, $req_name)
+{
+    // echo "<br>AddRequest($req_id, $req_name)<br>\n";
+    initializeRequests();
+    $new_request = new Request($req_id, $req_name);
+
+    $num = count($_SESSION['requests']);
+
+    // echo "request array length: $num<br />";
+
+    // Our request object gets destroyed after this instance of our
+    // script runs.
+    // save it in serialized form so that we can regenerate it
+    // XXX: There must be as simpler way to do this
+    $_SESSION['requests'][$num] = serialize($new_request);
+
+    $num = count($_SESSION['requests']);
+
+    // echo "after request array length: $num<br />";
+}
+
+
+// old listRequests function. Assumes that callers know the name of the product
+function oldlistRequests($dataStoreProduct, $targetWindow)
+{
+    $debug_listing = 0;
+    $request_count = count($_SESSION['requests']);
+    // echo "request_count: $request_count<br />";
+
+    for ($i = $request_count-1; $i >= 0; $i--) {
+        // unserialize the object
+        $ser_req = $_SESSION['requests'][$i];
+        // print_r($ser_req);
+        $req = unserialize($ser_req);
+        echo "<br />";
+        // print_r($req);
+        // echo "<br />";
+
+        $name = $req->name;
+        $id = $req->id;
+
+        if ($id && ($req->state != "stop")) {
+            // Get the current state of this request from the database
+            if (!$dbserver) {
+                $dbserver = dblogin();
+            }
+
+            $query = "SELECT pstampRequest.state, COUNT(job_id) as num_jobs, pstampRequest.fault FROM pstampRequest LEFT JOIN pstampJob USING(req_id) WHERE req_id = $id";
+            // echo "<br />$query<br />";
+
+            $result  = mysqli_query($dbserver, $query);
+            if (!$result) {
+                die("Database access failed: " . mysqli_error($dbserver));
+            }
+
+            // save the state so that we don't have to look it up again
+
+	    // EAM : old PHP version
+            // EAM : $req->state = mysql_result($result, 0, 'state');
+            // EAM : $req->num_jobs = mysql_result($result, 0, 'num_jobs');
+            // EAM : $req->fault = mysql_result($result, 0, 'fault');
+
+	    // EAM : new PHP version (we only need row 0 to replicate the old behavior)
+	    mysqli_data_seek($result, 0);
+	    $row = mysqli_fetch_row($result);
+            $req->state    = $row['state'];
+            $req->num_jobs = $row['num_jobs'];
+            $req->fault    = $row['fault'];
+
+            $_SESSION['requests'][$i] =  serialize($req);
+        }
+
+        echo "request id: $id";
+        echo "&nbsp;&nbsp;";
+        echo " State: $req->state  Num Jobs: $req->num_jobs \n";
+        if ($req->state == "stop") {
+            // Job is done output fileset as link.
+            echo "<a href=\"" . $dataStoreProduct . "/$name\"";
+
+            if ($targetWindow) {
+                echo " TARGET=\"upload_results_fileset\"";
+            }
+
+            echo ">$name</a>\n";
+        } else {
+            // Job isn't done Just output the name
+            echo "$name in process\n";
+        }
+    }
+
+    if ($debug_listing) {
+        echo "<br /><br />session contains $request_count requests\n";
+    }
+}
+
+// new listRequests function. Gets root of data store from config. Products from DB query.
+
+function listRequests($dataStoreRoot, $targetWindow)
+{
+    $debug_listing = 0;
+    $request_count = count($_SESSION['requests']);
+    // echo "request_count: $request_count<br />";
+
+    for ($i = $request_count-1; $i >= 0; $i--) {
+        // unserialize the object
+        $ser_req = $_SESSION['requests'][$i];
+        // print_r($ser_req);
+        $req = unserialize($ser_req);
+        echo "<br />";
+        // print_r($req);
+        // echo "<br />";
+
+        $name = $req->name;
+        $id = $req->id;
+
+        if ($id && ($req->state != "stop")) {
+            // Request not done last time that we checked.
+            // Get its current state of this request from the database
+            if (!$dbserver) {
+                $dbserver = dblogin();
+            }
+            $query = "SELECT pstampRequest.state, COUNT(job_id) as num_jobs, pstampRequest.fault, pstampRequest.outProduct FROM pstampRequest LEFT JOIN pstampJob USING(req_id) WHERE req_id = $id";
+
+            // echo "<br />$query<br />";
+
+            $result  = mysqli_query($dbserver, $query);
+            if (!$result) {
+                die("Database access failed: " . mysqli_error($dbserver));
+            }
+
+            // cache the state in the session so that we don't have to look it up again
+
+	    // EAM : old PHP version
+            // EAM : $req->state = mysql_result($result, 0, 'state');
+            // EAM : $req->num_jobs = mysql_result($result, 0, 'num_jobs');
+            // EAM : $req->fault = mysql_result($result, 0, 'fault');
+            // EAM : $req->outProduct = mysql_result($result, 0, 'outProduct');
+
+	    // EAM : new PHP version (we only need row 0 to replicate the old behavior)
+	    mysqli_data_seek($result, 0);
+	    $row = mysqli_fetch_row($result);
+            $req->state      = $row['state'];
+            $req->num_jobs   = $row['num_jobs'];
+            $req->fault      = $row['fault'];
+            $req->outProduct = $row['outProduct'];
+
+            $_SESSION['requests'][$i] =  serialize($req);
+        }
+
+        echo "request id: $id";
+        echo "&nbsp;&nbsp;";
+        echo " State: $req->state  Num Jobs: $req->num_jobs \n";
+        if ($req->state == "stop") {
+            // Job is done output fileset as link.
+            $outProduct = $req->outProduct;
+            // XXX This is a transitory workaround which can be deleted
+            // before deployment.
+            if (!$outProduct) {
+                $outProduct = "pstampresults";
+            }
+            echo "<a href=\"" . $dataStoreRoot ."/" . "$outProduct" ."/$name\"";
+
+            if ($targetWindow) {
+                echo " TARGET=\"upload_results_fileset\"";
+            }
+
+            echo ">$name</a>\n";
+        } else {
+            // Job isn't done Just output the name of the request as a placeholder
+            echo "$name in process\n";
+        }
+    }
+
+    if ($debug_listing) {
+        echo "<br /><br />session contains $request_count requests\n";
+    }
+}
+
+
+?>
Index: /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/upload.php
===================================================================
--- /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/upload.php	(revision 42993)
+++ /branches/eam_branches/ipp-pstamp-20260421/pstamp/web/upload.php	(revision 42994)
@@ -2,17 +2,41 @@
 
 // get the locatl configuration variables
-include "pstamp.php";
+require "pstamp.php";
+require "submitted.php";
 
 
 $user = $_SERVER['PHP_AUTH_USER'];
 $passwd = $_SERVER['PHP_AUTH_PW'];
-echo "<HTML>
+?>
+
+<HTML>
 <head>
     <title>
         Upload Postage Stamp Request File
     </title>
+    <script type='text/javascript'>
+    setTimeout('countdown()', 100);
+    function countdown() {
+      var s = document.getElementById('timer');
+      s.innerHTML = s.innerHTML - 1;
+      if (s.innerHTML == 0)
+//        window.location = 'http://pstamp.ipp.ifa.hawaii.edu/upload.php';
+        location.reload();
+      else
+        setTimeout('countdown()', 1000*60);
+    }
+    </script>
+</head>
 <body>
-";
+<H1 align=center>
+Postage Stamp Request Upload Form
+</h1>
 
+<?php
+
+welcomeHeader($auth_user, 0, 0);
+// include "pstamp_links.php";
+echo "<br/><br/>";
+echo "The page will refresh in <span id='timer'>20</span> min<br><br>";
 // echo "Hello $user $passwd";
 
@@ -21,7 +45,8 @@
         <label>Postage Stamp Request File:
         <input type="file" name='filename' accept='image/x-fits' /></label>
+        Maximum Size 2 MB
     <br />
     <br />
-    <input type="submit" value="Upload" />
+    <input type="submit" value="Submit" />
     &nbsp; &nbsp; &nbsp;
     <input type="reset" name="cancel" value="Cancel"/>
@@ -31,33 +56,47 @@
 _END;
 
+$debug = 0;
+
 $command = "";
 if ($_FILES) {
+    $error = $_FILES['filename']['error'];
     $name = $_FILES['filename']['name'];
-    $tmp_name = $_FILES['filename']['tmp_name'];
-    $type = $_FILES['filename']['type'];
-    $size = $_FILES['filename']['size'];
 
-    if ($name && ($size > 0)) {
-  //      echo "Uploaded $size bytes for '$type' file '$name' as '$tmp_name'<br />";
-        $command = "$SCRIPT pstamp_insert_request.pl --tmp_req_file $tmp_name --dbname $dbname --dbserver $dbserver --workdir $WORKDIR";
+    if ($error == UPLOAD_ERR_OK) {
+        $tmp_name = $_FILES['filename']['tmp_name'];
+        $type = $_FILES['filename']['type'];
+        $size = $_FILES['filename']['size'];
+
+
+        if ($name) {
+           if ($size > 0) {
+      //      echo "Uploaded $size bytes for '$type' file '$name' as '$tmp_name'<br />";
+            $command = "$SCRIPT pstamp_insert_request.pl --tmp_req_file $tmp_name --dbname $dbname --dbserver $dbserver --workdir $WORKDIR";
+            } else {
+                echo "Error: Received 0 bytes for file '$name' <br />\n";
+            }
+        } else {
+            if ($debug) {
+                echo "Error: no name for file<br />\n";
+            }
+        }
+    } else {
+        if ($error == UPLOAD_ERR_INI_SIZE) {
+            echo "File <b>$name</b> is too large.<br />\n";
+        } else if ($error == UPLOAD_ERR_NO_FILE) {
+            if ($debug) {
+                echo "no file<br />\n";
+            }
+        } else {
+            echo "File upload error $error<br />\n";
+        }
+    }
+} else {
+    if ($debug)  {
+        echo "_FILES is null<br />\n";
     }
 }
 
-class Request
-{
-    public $id;
-    public $name;
-    function __construct($p1, $p2)
-    {
-        $this->id = $p1;
-        $this->name = $p2;
-    }
-}
-
-if (!isset($_SESSION['requests'])) {
-//    echo "initializing requests\n";
-//    echo "<br />";
-    $_SESSION['requests'] = array();
-}
+initializeRequests();
 
 // echo "<br />SCRIPT is <br />$SCRIPT";
@@ -67,5 +106,5 @@
 if ($command) {
     $command = escapeshellcmd($command);
-   // echo "<br />command:<br />$command";
+//    echo "<br />command:<br />$command";
     echo "<br />";
     exec($command, $output, $command_status);
@@ -75,34 +114,28 @@
         // get rid of any whitespace in req_name
         $req_name = trim($output[1]);
-        echo "Submitted Request ID:&nbsp; $req_id Request Name: &nbsp; $req_name<br \>";
-        $new_request = new Request($req_id, $req_name);
-        $num = count($_SESSION['requests']);
-//        echo "request array length: $num<br />";
-        $_SESSION['requests'][$num] = $new_request;
-        $num = count($_SESSION['requests']);
-//        echo "after request array length: $num<br />";
+        echo "Submitted Request ID:&nbsp; $req_id Request Name: &nbsp; $req_name<br />";
+
+        addRequest($req_id, $req_name);
     } else if ($command_status == 5) {
         // PS_EXIT_DATA_ERROR
-        echo "Error:&nbsp;&nbsp;&nbsp;";
+        echo "Error: 5 &nbsp;&nbsp;&nbsp;";
         for ($i=0; $i < count($output); $i++) {
             echo $output[$i];
+        }
+        if (count($output) == 0) {
+            echo "Insert command failed. Invalid request file?";
         }
         echo "<br />\n";
     } else {
         echo "Unexpected Error.<br /> insert command returned $command_status<br \>";
+        echo "<br \OUTPUT: $output>";
     }
 }
-echo "<br />";
+echo "<br />\n";
 
-foreach ($_SESSION['requests'] as $req) {
-    echo "<br />";
-    echo $req->id;
-    echo "&nbsp;&nbsp";
-    $name = $req->name;
-    echo "&nbsp;&nbsp";
-    // XXX: get this data store product location a configuation
-    echo "<a href=\"http://datastore.ipp.ifa.hawaii.edu/pstampresults/$name\" TARGET=\"upload_results_fileset\">$name</a>\n";
-}
-echo "<br />";
+// listRequests("http://datastore.ipp.ifa.hawaii.edu", "pstamp_results_fileset");
+listRequests("http://datastore.ipp.ifa.hawaii.edu/ds", "pstamp_results_fileset");
+
+echo "<br />\n";
 
 // print lots of information
@@ -111,5 +144,5 @@
 // phpinfo(32);
 
-echo "</body></html>";
+echo "</body>\n</html>";
 
 ?>
