Index: /trunk/pstamp/web/request.php
===================================================================
--- /trunk/pstamp/web/request.php	(revision 16279)
+++ /trunk/pstamp/web/request.php	(revision 16279)
@@ -0,0 +1,534 @@
+<html>
+ <head>
+  <title>Postage Stamp Request Form</title>
+ </head>
+<form method="post">
+
+<body>
+
+<H1 align=center>
+Postage Stamp Request Form
+</h1>
+
+<!--- for dumping output from the following code for debug TODO: remove this--->
+<pre>
+<?php 
+
+// Initialize variables
+$output_array = array();
+
+$raw_selected = "";
+$chip_selected = "";
+$warp_selected = "";
+$stack_selected = "";
+$diff_selected = "";
+
+$exp_checked = "";
+$file_checked = "";
+$coord_checked = "";
+$list_checked = "";
+$pstamp_checked = "";
+
+$command_line = "";
+$error_line = "";
+$command_status = "";
+
+
+// Initialize the request variables that we depend upon
+$rvar_project="gpc1";
+
+$rvar_user_tag="";
+$rvar_select_by = "";
+$rvar_img_type = "";
+$rvar_id = "";
+$rvar_class_id = "";
+$rvar_cell_id = "";
+
+$rvar_center_type = "";
+$rvar_range_type  = "";
+
+$rvar_RA = "";
+$rvar_DEC = "";
+$rvar_dRA = "";
+$rvar_dDEC = "";
+$rvar_X = "";
+$rvar_Y = "";
+$rvar_W = "";
+$rvar_H = "";
+
+$rvar_cmd_mode = "";
+
+// now get the values from this post
+
+import_request_variables("gp", "rvar_");
+
+// figure out which select_by is set and save it's checked value 
+
+if ($rvar_select_by == "exposure_id") {
+    $exp_checked = "CHECKED";
+} else if ($rvar_select_by == "db_id") {
+    $file_checked = "CHECKED";
+} else if ($rvar_select_by == "coord") {
+    $coord_checked = "CHECKED";
+} else {
+    // nothing checked default to By Exposure
+    $exp_checked = "CHECKED";
+}
+
+// get the Image type
+if ($rvar_img_type == "raw") {
+    $raw_selected = "selected";
+} else if ($rvar_img_type == "chip") {
+    $chip_selected = "selected";
+} else if ($rvar_img_type == "warp") {
+    $warp_selected = "selected";
+} else if ($rvar_img_type == "stack") {
+    $stack_selected = "selected";
+} else if ($rvar_img_type == "diff") {
+    $diff_selected = "selected";
+}
+
+// is the center is specified in Pixels or sky coordinates
+if ($rvar_center_type == "Pixels") {
+    $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 {
+    $rsky_checked="checked";
+    $rpix_checked="";
+}
+
+if ($rvar_cmd_mode == "Make Stamps") {
+    $pstamp_checked = "checked";
+    $list_checked = "";
+} else {
+    $list_checked = "checked";
+    $pstamp_checked = "";
+}
+
+echo "\n\n\n";
+
+// If the data is from a Post run the command
+// How do we know? Well if it's the initial get of the web page, rvar_img_type is not set
+// TODO: find a better way to decide whether to proceed
+if ($rvar_img_type) {
+
+    try {
+        $command_line = build_command_line();
+        $error_line = "";
+        run_command();
+    } catch (Exception $e) {
+        $error_line = $e->getMessage();
+    }
+}
+
+?>
+</pre>
+<!-- end of preformatted area for debug printing TODO: remove this -->
+
+
+<!-- Whole page is a single column table -->
+
+<table width=90% align=center>
+
+
+<!-- first row in the main table is the image selector UI which consists of a 2 x 3 table -->
+<tr>
+<td>
+
+<table width=100% align=center>
+
+<!-- first row of image selector is "Project" pulldown menu "Select Image By" radio boxes -->
+<tr>
+<td width=20% >
+  <table>
+    <tr><td><b>Project:</b>&nbsp;&nbsp;&nbsp;</td>
+        <td><select name="project">
+            <option>gpc1
+        </td>
+    </tr>
+  </table>
+
+<td>
+&nbsp;<b>Select Images By:</b>&nbsp;&nbsp;&nbsp;
+<input type=radio name="select_by" value="exposure_id" <?php echo $exp_checked; ?> >Exposure ID
+&nbsp;
+<input type=radio name="select_by" value="db_id" <?php echo $file_checked; ?> >Database ID
+&nbsp;
+<!--
+<input type=radio name="select_by" value="coord" <?php echo $coord_checked; ?> >Coordinates
+-->
+</td>
+</tr>
+
+
+<!-- the second row of the image selector table contains 
+    "Image Type" pulldown menu   "ID:" text input "Class ID" text input
+-->
+
+<tr>
+<td width=20%>
+<table>
+    <td><b>Image Type:</b>&nbsp;</td>
+    <td>
+        <select name="img_type">" >
+            <option <?php echo $raw_selected;?>   >raw
+            <option <?php echo $chip_selected;?>  >chip
+            <option <?php echo $warp_selected ;?> >warp
+            <option <?php echo $stack_selected;?> >stack   
+            <option <?php echo $diff_selected;?>  >diff
+        </select>
+    </td>
+</table>
+</td>
+
+<td>
+&nbsp;<b>ID:</b>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+<input type="text" name="id" value= <?php echo $rvar_id; ?> >
+&nbsp;&nbsp;&nbsp;&nbsp;
+<b>
+<?php if ($rvar_project == "gpc1") {
+        echo "Chip ID:";
+      } else {
+        echo "Class ID:";
+      }
+?>
+</b>
+&nbsp;<input type="text" name="class_id" size=10 value="<?php echo $rvar_class_id;?>" >
+
+&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;?>" >
+
+-->
+
+</td>
+
+</tr>
+
+<!-- third row of table just contains a blank column followed by the user tag input -->
+<tr>
+<!-- blank label -->
+<td width=20% > </td>
+<!-- user tag input text -->
+<td>&nbsp;<b>Stamp Name:</b>&nbsp;<input type="text" name="user_tag" size=60 value=<?php echo $rvar_user_tag; ?> ></td>
+</tr>
+
+</table> <!-- end of Image selector table -->
+
+<!-- a blank row for space-->
+<tr height=20><td></td></tr>
+
+<!-- next row of main table contains the ROI input UI -->
+<tr align=center width=100%>
+    <td>
+    <!-- 2 row by 6 column table -->
+    <table width=100%>
+    <thead>
+    <tr>
+    <!-- <td></td><td></td><td><b>Center</b></td><td></td><td></td><td><b>Range</b></td> -->
+    <td><td><td><b>Center</b><td><td><td><b>Range</b>
+    </tr>
+    </thead>
+    <tr>
+        <td>
+            <input type=radio name="center_type" value="Sky" <?php echo $sky_checked; ?> >Sky
+        </td>
+        <td>
+            &nbsp;
+            RA:
+            &nbsp;
+            &nbsp;
+            <input type="text" name="RA" size=15  value= <?php echo $rvar_RA; ?> >
+        </td>
+        <td>
+            &nbsp;
+            DEC:
+            &nbsp;
+            <input type="text" name="DEC" size=15 value="<?php echo $rvar_DEC;?>" >
+        </td>
+        <td>
+            <input type=radio name="range_type" value="Sky" <?php echo $rsky_checked; ?> >Sky
+        </td>
+        <td>
+            &nbsp;
+            dRA:
+            &nbsp;
+            &nbsp;
+            &nbsp;
+            <input type="text" name="dRA" size=15  value= <?php echo $rvar_dRA; ?> >
+        </td>
+        <td>
+            &nbsp;
+            dDEC:
+            &nbsp;
+            <input type="text" name="dDEC" size=15 value="<?php echo $rvar_dDEC;?>" >
+        </td>
+    </tr>
+    <tr>
+        <td>
+            <input type=radio name="center_type" value="Pixels" <?php echo $pix_checked; ?> >Pixels
+        </td>
+        <td>
+            &nbsp;
+            X:
+            &nbsp;
+            &nbsp;
+            &nbsp;
+            <input type="text" name="X" size=15  value= <?php echo $rvar_X; ?> >
+        </td>
+        <td>
+            &nbsp;
+            Y:
+            &nbsp;
+            &nbsp;
+            &nbsp;
+            <input type="text" name="Y" size=15 value="<?php echo $rvar_Y;?>" >
+        </td>
+        <td>
+            <input type=radio name="range_type" value="Pixels" <?php echo $rpix_checked; ?> >Pixels
+        </td>
+        <td>
+            &nbsp;
+            width:
+            &nbsp;
+            &nbsp;
+            <input type="text" name="W" size=15  value= <?php echo $rvar_W; ?> >
+        </td>
+        <td>
+            &nbsp;
+            height:
+            &nbsp;
+            <input type="text" name="H" size=15 value="<?php echo $rvar_H;?>" >
+        </td>
+    </tr>
+    </table>
+    </td>
+</tr>
+
+
+<!-- next row of the main table just contains the Submit button -->
+
+<tr align=center width=100% height=50>
+  <td>
+  <table width=40%>
+  <tr>
+    <td><input type=submit value="Submit"></td>
+    <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="List Images" <?php echo $list_checked; ?> >List Images
+    </td>
+  </tr>
+  </table>
+  </td>
+</tr>
+
+<!--- next row in the main table is the Results of the previous request --->
+
+<tr>
+    <td>
+    <b>Command:</b>&nbsp;&nbsp; <?php echo "$command_line\n";?>
+    </td>
+</tr>
+<tr>
+    <td>
+    <b>Status:</b>&nbsp;&nbsp;&nbsp; <?php echo "$command_status\n";?>
+    </td>
+</tr>
+<tr>
+    <td>
+    <b>Error:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
+        <?php 
+            if ($error_line) {
+                echo "<pre>";
+                echo "$error_line\n";
+                echo "<pre>\n";
+            }
+        ?>
+    </td>
+</tr>
+<!-- a blank row for space-->
+<tr height=20><td></td></tr>
+
+<tr>
+<td>
+<table align=center width=100% rules=none>
+<caption height=10 valign=center><b>Results</b></caption>
+
+
+<?php 
+    $size = sizeof($output_array);
+    if ($command_status == 0) {
+        if ($list_checked) {
+            for ($i = 0; $i < $size; $i++)  {
+                echo "<tr><td>$output_array[$i]</td></tr>";
+            }
+        } else {
+            for ($i = 0; $i < $size; $i++)  {
+                printURL($output_array[$i]);
+            }
+        }
+    }
+?>
+</table>
+</td>
+</tr>
+</table>
+
+<!-- The end -->
+
+<p>
+<pre>
+
+<!--- rvar_select_by = <?php echo $rvar_select_by; ?>
+--->
+
+<?php 
+// dump parameters 
+
+   // phpinfo(32);
+
+?>
+
+<?php
+
+function build_command_line()
+{
+    global $rvar_project, $rvar_user_tag;
+    global $sky_checked, $rsky_checked;
+    global $list_checked;
+    global $rvar_RA, $rvar_DEC;
+    global $rvar_dRA, $rvar_dDEC;
+    global $rvar_X, $rvar_Y;
+    global $rvar_W, $rvar_H;
+    global $exp_checked, $file_checked, $coord_checked;
+    global $rvar_img_type;
+    global $rvar_id, $rvar_class_id;
+    global $command_line;
+
+    $cmd = "pstampwebrequest.sh";
+    
+    if ($list_checked) {
+        $cmd .= " -list";
+    }
+
+    if (! $rvar_project ) {
+        throw new Exception('project must be specified.');
+    }
+    $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 ($exp_checked) {
+        if (! $rvar_id ) {
+            throw new Exception('Must set Exposure ID.');
+        }
+        $cmd .= " -byexp $rvar_img_type $rvar_id";
+    } else if ($file_checked) {
+        if (! $rvar_id ) {
+            throw new Exception('Must set ID specified.');
+        }
+        $cmd .= " -byid $rvar_img_type $rvar_id";
+    } else if ($coord_checked) {
+        // $cmd .= " -bycoord $rvar_img_type";
+        $coord_checked = "";
+        $exp_checked = "checked";
+        throw new Exception("Image selection by coordinate not implemented yet.");
+    }
+
+    if (($rvar_img_type == "raw") || ($rvar_img_type == "chip")) {
+        if (! $rvar_class_id ) {
+            throw new Exception("must specify Class ID with Image Type $rvar_img_type.");
+        }
+        $cmd .= " $rvar_class_id";
+    }
+
+    return escapeshellcmd($cmd);
+}
+
+function run_command()
+{
+    global $command_line;
+    global $output_array;
+    global $error_line;
+    global $command_status;
+
+    $HOME = "/export/data1/bills/pstamp";
+    $cmd_dir  = "$HOME/bin";
+    $work_dir = "$HOME/work";
+
+
+    exec ("$cmd_dir/$command_line", $output_array, $command_status);
+
+    $size = sizeof($output_array);
+    // echo "output_array  contains $size lines\n";
+    if ($command_status == 0) {
+        // echo "Output: $size lines\n";
+        for ($i = 0; $i < $size; $i++) {
+          //  echo "$output_array[$i]\n";
+        }
+    } else {
+        // copy the output to the error_line
+        $error_line = "";
+        for ($i = 0; $i < $size; $i++) {
+             $error_line .= "$output_array[$i]\n";
+        }
+    }
+
+}
+
+function printURL($path)
+{
+    $fileName = basename($path);
+    echo "<tr><td>";
+    echo "<a href=\"http:$path\" target=\"_blank\" type=\"image/fits\">";
+    echo $fileName;
+    echo "</a>";
+    echo "</td></tr>";
+}
+
+?>
+
+</body>
+</form>
+</html>
