Index: trunk/pstamp/web/request.php
===================================================================
--- trunk/pstamp/web/request.php	(revision 16960)
+++ trunk/pstamp/web/request.php	(revision 16977)
@@ -32,4 +32,5 @@
 $list_checked = "";
 $pstamp_checked = "";
+$get_checked = "";
 
 $command_line = "";
@@ -37,4 +38,5 @@
 $command_status = "";
 
+$outFileset = "";
 
 // Initialize the request variables that we depend upon
@@ -61,4 +63,5 @@
 
 $rvar_cmd_mode = "";
+$rvar_last_cmd_mode = "";
 $rvar_request_id = 0;
 $rvar_last_request_id = 0;
@@ -95,19 +98,19 @@
 
 // is the center is specified in Pixels or sky coordinates
-if ($rvar_center_type == "Pixels") {
+if ($rvar_center_type == "Sky") {
+    $sky_checked="checked";
+    $pix_checked="";
+} else {
     $sky_checked="";
     $pix_checked="checked";
-} else {
-    $sky_checked="checked";
-    $pix_checked="";
 }
 
 // is the range is specified in Pixels or sky coordinates
-if ($rvar_range_type == "Pixels") {
-    $rsky_checked="";
-    $rpix_checked="checked";
-} else {
+if ($rvar_range_type == "Sky") {
     $rsky_checked="checked";
     $rpix_checked="";
+} else {
+    $rpix_checked="checked";
+    $rsky_checked="";
 }
 
@@ -117,11 +120,21 @@
 $last_request_id = $rvar_last_request_id;
 
-
-// default to list mode, unless we are waiting for a request to finish
-if (($rvar_cmd_mode == "Make Stamps") || ($request_id != 0)) {
+// during request the page doesn't have cmd_mode set. So we remember the lat real value
+// and use that
+if (!$rvar_cmd_mode) {
+    $rvar_cmd_mode = "$rvar_last_cmd_mode";
+}
+
+if ($rvar_cmd_mode == "Make Stamps") {
     $pstamp_checked = "checked";
     $list_checked = "";
+    $get_checked = "";
+} else if ($rvar_cmd_mode == "Get Images") {
+    $get_checked = "checked";
+    $list_checked = "";
+    $pstamp_checked = "";
 } else {
     $list_checked = "checked";
+    $get_checked = "";
     $pstamp_checked = "";
 }
@@ -138,7 +151,8 @@
 if ($rvar_img_type) {
 
+    $jobFinished = 0;
     if ($request_id == 0) {
         try {
-            $command_line = build_command_line();
+            $command_line = build_request_cmd();
             $error_line = "";
             run_command($command_line);
@@ -155,4 +169,5 @@
                 $jobRunning = getRequestStatus();
                 if (!$jobRunning) {
+                    $jobFinished = 1;
                     $request_id = 0;
                 }
@@ -169,19 +184,25 @@
 
             if (!$jobRunning) {
+                $jobFinished = 1;
                 $request_id = 0;
             }
 
         } catch (Exception $e) {
+            echo "Got Exception $request_id $e\n";
             $error_line = $e->getMessage();
         }
     }
-    listJobs($last_request_id);
-}
-
-function build_command_line()
+    if ($last_request_id) {
+        // This doesn't work for get_image
+        listJobs($last_request_id, $jobFinished);
+    }
+}
+
+function build_request_cmd()
 {
     global $rvar_project, $rvar_user_tag;
     global $sky_checked, $rsky_checked;
     global $list_checked;
+    global $get_checked;
     global $rvar_RA, $rvar_DEC;
     global $rvar_dRA, $rvar_dDEC;
@@ -194,7 +215,13 @@
 
     $cmd = "pstamp_runcommand.sh pstamp_webrequest.pl";
+
+    $making_stamps = 1;
     
     if ($list_checked) {
         $cmd .= " -list";
+        $making_stamps = 0;
+    } else if ($get_checked) {
+        $making_stamps = 0;
+        $cmd .= " -get_image";
     }
 
@@ -203,37 +230,45 @@
     }
     $cmd .= " -project $rvar_project";
-    if (! $rvar_user_tag ) {
-        throw new Exception('Stamp Name must be specified.');
-    }
-    $cmd .= " -user_tag $rvar_user_tag";
-
-    // Set up the ROI parameters
-    if ($sky_checked) {
-        if (! $rvar_RA || ! $rvar_DEC) {
-            throw new Exception('RA and DEC must be specified.');
-        }
-        $cmd .= " -skycenter $rvar_RA $rvar_DEC";
-    } else {
-        if (! $rvar_X || ! $rvar_Y) {
-            throw new Exception('X and Y must be specified.');
-        }
-        $cmd .= " -pixcenter $rvar_X $rvar_Y";
-    }
-
-    if ($rsky_checked) {
-        if (! $rvar_dRA || ! $rvar_dDEC) {
-            throw new Exception('dRA and dDEC must be specified.');
-        }
-        $cmd .= " -arcrange $rvar_dRA $rvar_dDEC";
-    } else {
-        if (! $rvar_W || ! $rvar_H) {
-            throw new Exception('width and height must be specified.');
-        }
-        $cmd .= " -pixrange $rvar_W $rvar_H";
-    }
-
-
-    // Note: in the following block we assume that image type has been
-    // which is true since it comes from the menu
+
+    if ($making_stamps) {
+        if (!$rvar_user_tag) {
+            throw new Exception('Stamp Name must be specified.');
+        }
+        $cmd .= " -user_tag $rvar_user_tag";
+    }
+
+    if ($making_stamps || $coord_checked) {
+        // Set up the ROI parameters
+        if ($sky_checked) {
+            if (! $rvar_RA || ! $rvar_DEC) {
+                throw new Exception('RA and DEC must be specified.');
+            }
+            $cmd .= " -skycenter $rvar_RA $rvar_DEC";
+        } else {
+            if (! $rvar_X || ! $rvar_Y) {
+                throw new Exception('X and Y must be specified.');
+            }
+            $cmd .= " -pixcenter $rvar_X $rvar_Y";
+        }
+
+        if ($rsky_checked) {
+            if (! $rvar_dRA || ! $rvar_dDEC) {
+                throw new Exception('dRA and dDEC must be specified.');
+            }
+            $cmd .= " -arcrange $rvar_dRA $rvar_dDEC";
+        } else {
+            if (! $rvar_W || ! $rvar_H) {
+                throw new Exception('width and height must be specified.');
+            }
+            $cmd .= " -pixrange $rvar_W $rvar_H";
+        }
+    }
+
+
+    if (! $rvar_img_type) {
+        // this actually can't happen
+        throw new Exception('Must set image type.');
+    }
+
     if ($exp_checked) {
         if (! $rvar_id ) {
@@ -243,5 +278,5 @@
     } else if ($file_checked) {
         if (! $rvar_id ) {
-            throw new Exception('Must set ID specified.');
+            throw new Exception('Must set ID.');
         }
         $cmd .= " -byid $rvar_img_type $rvar_id";
@@ -270,4 +305,5 @@
     global $COMMAND_DIR;
 
+    // echo "running $command_line\n";
 
     exec ("$COMMAND_DIR/$command_line", $output_array, $command_status);
@@ -349,8 +385,24 @@
 }
 
-function listJobs($request_id)
+function listJobs($request_id, $jobFinished)
 {
+
     $command_line = "pstamp_runcommand.sh pstamp_listjobs.pl $request_id";
     run_command($command_line);
+    if ($jobFinished) {
+        global $outFileset;
+        $parse_error = "/var/www/html/ds/dsroot/$outFileset/parse_error";
+        #echo "reading $parse_error\n";
+        // readfile( $parse_error );
+        $fhandle = fopen($parse_error, "r");
+        if ($fhandle) {
+            $contents = fread($fhandle, 1024);
+            if ($contents) {
+                global $last_request_id;
+                global $error_line;
+                $error_line = "Request $last_request_id: $contents\n";
+            }
+        }
+    }
 }
 
@@ -360,4 +412,5 @@
     global $command_status;
     global $output_array;
+    global $outFileset;
 
     $command_line = "pstamp_runcommand.sh pstamptool -listreq -req_id $request_id -simple";
@@ -368,6 +421,7 @@
         for ($i = 0; $i < $size; $i++) {
             $elements = explode(" ", $output_array[$i]);
-            if (count($elements) >= 3) {
+            if (count($elements) >= 4) {
                 $state = $elements[2];
+                $outFileset = $elements[4];
                 if ($state != "stop") {
                     $runningReq++;
@@ -601,4 +655,5 @@
     <td><b>Mode:</b>&nbsp;&nbsp;
     <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 Images
     <input type=radio name="cmd_mode" value="List Images" <?php echo $list_checked; ?> >List Images
     </td>
@@ -686,4 +741,7 @@
     <input type="hidden" name="last_request_id" value=<?php echo $last_request_id ?> >
 </td>
+<td>
+    <input type="hidden" name="last_cmd_mode" value=<?php echo "\"$rvar_cmd_mode\"" ?> >
+</td>
 </tr>
 </table>
