IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29086


Ignore:
Timestamp:
Aug 31, 2010, 2:53:39 PM (16 years ago)
Author:
bills
Message:

updated web form

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/web/request.php

    r25322 r29086  
    1616// XXX This is just a prototype for testing purposes.
    1717
    18 
    19 // XXX: change to include pstampconfig.php
    20 
    21 // BEGIN Local configuration
    22 
    23 $WORKDIR = "/data/ipp049.0/pstamp/work";
    24 $dsroot = "/data/ipp049.0/datastore/dsroot";
    25 $dbname = "ippRequestServer";
    26 $dbserver = "ipp049";
    27 
    28 $PSCONFDIR = "/data/ipp053.0/home/bills/psconfig";
    29 $PSCONFIG  = "debug";
    30 $PSBINDIR  = "$PSCONFDIR/$PSCONFIG.lin64/bin";
    31 
    32 // END Local configuration
     18require "pstamp.php";
     19require "submitted.php";
    3320
    3421# this script sets up the environment to run IPP commands with current directory
     
    5542$diff_checked = "";
    5643$list_checked = "";
     44$getstatus_checked = "";
    5745$pstamp_checked = "";
    5846$get_checked = "";
     
    10290if ($rvar_project == "gpc1") {
    10391    $gpc1_selected = "selected";
    104     $require_class_id = 1;
     92//    $require_class_id = 1;
    10593} else if ($rvar_project == "megacam-mops") {
    10694    $mops_selected = "selected";
     
    122110    $diff_checked = "CHECKED";
    123111} else {
    124     // nothing checked default to By Exposure
    125     $exp_checked = "CHECKED";
     112    // nothing checked default to By ID
     113    $file_checked = "CHECKED";
    126114}
    127115
     
    140128
    141129// is the center is specified in Pixels or sky coordinates
    142 if ($rvar_center_type == "Sky") {
     130if ($rvar_center_type == "Pixels") {
     131    $sky_checked="";
     132    $pix_checked="checked";
     133} else {
    143134    $sky_checked="checked";
    144135    $pix_checked="";
    145 } else {
    146     $sky_checked="";
    147     $pix_checked="checked";
    148136}
    149137
     
    168156}
    169157
     158$getstatus_checked = "";
     159$pstamp_checked = "";
     160$list_checked = "";
     161$get_checked = "";
    170162if ($rvar_cmd_mode == "Make Stamps") {
    171163    $pstamp_checked = "checked";
    172     $list_checked = "";
    173     $get_checked = "";
    174164} else if ($rvar_cmd_mode == "Get Images") {
    175165    $get_checked = "checked";
    176     $list_checked = "";
    177     $pstamp_checked = "";
     166} else if ($rvar_cmd_mode == "Get Status") {
     167    $getstatus_checked = "checked";
    178168} else {
    179     $list_checked = "checked";
    180     $get_checked = "";
    181     $pstamp_checked = "";
     169    // default
     170    $pstamp_checked = "checked";
    182171}
    183172
     
    188177
    189178// How do we know whether or not this is the intial page load or not?
    190 // Well, in that case rvar_img_type is not set so key off of that
     179// Well, the first time rvar_img_type is not set. So we key off of that.
    191180// TODO: find a better way to decide whether or not to run commands
    192181
    193182if ($rvar_img_type) {
    194 
    195183    $jobFinished = 0;
    196     if ($request_id == 0) {
     184    if (! $getstatus_checked) {
    197185        try {
    198186            $command_line = build_request_cmd();
     
    201189            if (! $list_checked) {
    202190                // The only output from a successful run is the request_id
     191                $request_name = trim(Array_pop($output_array));
    203192                $request_id = Array_pop($output_array);
    204193                $last_request_id = $request_id;
    205                 setcookie("our_request_id", $request_id);
    206                 // echo "The request id is $request_id\n";
    207                 if (count($output_array) != 0) {
    208                     throw new Exception("unexpected output returned by pstampwebrequest.");
     194                if ($request_id && $request_name) {
     195                    addRequest($request_id, $request_name);
     196                    // setcookie("our_request_id", $request_id);
     197                    // echo "The request id is $request_id\n";
     198                    $getstatus_checked = "checked";
     199                    $pstamp_checked = "";
     200                } else {
     201                    // XXX: TODO print out the error
     202                    if (count($output_array) != 0) {
     203                        throw new Exception("unexpected output returned by pstampwebrequest.");
     204                    }
    209205                }
    210 
    211                 $jobRunning = getRequestStatus();
    212                 if (!$jobRunning) {
    213                   //   echo "1  getRequestStatus reuturned 0\n";
    214                     $jobFinished = 1;
    215                     $request_id = 0;
    216                 }
    217 
    218206            } else {
    219207                $last_request_id = 0;
     
    222210            $error_line = $e->getMessage();
    223211        }
    224     } else {
    225         try {
    226             // get the list of jobs for the request
    227             // echo "calling getRequestStatus\n";
    228             $jobRunning = getRequestStatus();
    229 
    230             if (!$jobRunning) {
    231                //  echo "2  getRequestStatus reuturned 0\n";
    232                 $jobFinished = 1;
    233                 $request_id = 0;
    234             }
    235 
    236         } catch (Exception $e) {
    237             echo "Got Exception $request_id $e\n";
    238             $error_line = $e->getMessage();
    239         }
    240     }
    241     if ($last_request_id) {
    242         // This doesn't work for get_image
    243         listJobs($last_request_id, $jobFinished);
    244     }
    245 }
     212    }
     213}
     214
     215// This is the end of the Logic
    246216
    247217function build_request_cmd()
     
    296266                throw new Exception('RA and DEC must be specified.');
    297267            }
    298             $cmd .= " -skycenter $rvar_RA $rvar_DEC";
     268            $cmd .= " --ra $rvar_RA --dec $rvar_DEC";
    299269        } else {
    300270            if (! $rvar_X || ! $rvar_Y) {
    301271                throw new Exception('X and Y must be specified.');
    302272            }
    303             $cmd .= " -pixcenter $rvar_X $rvar_Y";
     273            $cmd .= " -pixcenter --x $rvar_X --y $rvar_Y";
    304274        }
    305275
     
    308278                throw new Exception('dRA and dDEC must be specified.');
    309279            }
    310             $cmd .= " -arcrange $rvar_dRA $rvar_dDEC";
     280            $cmd .= " --arcseconds --width $rvar_dRA --height $rvar_dDEC";
    311281        } else {
    312282            if (! $rvar_W || ! $rvar_H) {
    313283                throw new Exception('width and height must be specified.');
    314284            }
    315             $cmd .= " -pixrange $rvar_W $rvar_H";
     285            $cmd .= " --width $rvar_W --height $rvar_H";
    316286        }
    317287    }
     
    324294
    325295    if ($exp_checked) {
     296        if ($rvar_img_type == "stack") {
     297            throw new Exception('Lookup by exposure name not supported for stack images.');
     298        }
    326299        if (! $rvar_id ) {
    327300            throw new Exception('Must set ID to the Exposure ID.');
    328301        }
    329         $cmd .= " -byexp $rvar_img_type $rvar_id";
     302        $cmd .= " --req_type byexp --stage $rvar_img_type --id $rvar_id";
    330303    } else if ($file_checked) {
    331304        if (! $rvar_id ) {
    332305            throw new Exception('Must set ID to the exposure name.');
    333306        }
    334         $cmd .= " -byid $rvar_img_type $rvar_id";
     307        $cmd .= " --req_type byid --stage $rvar_img_type --id $rvar_id";
    335308    } else if ($coord_checked) {
    336         // $cmd .= " -bycoord $rvar_img_type";
    337         $coord_checked = "";
    338         $exp_checked = "checked";
    339         throw new Exception("Image selection by coordinate not implemented yet.");
     309        $cmd .= " --req_type bycoord --stage $rvar_img_type";
     310        $coord_checked = "checked";
     311//        throw new Exception("Image selection by coordinate not implemented yet.");
    340312    } else if ($diff_checked) {
    341313        if (! $rvar_id ) {
    342314            throw new Exception('Must set ID to Diff Image ID.');
    343315        }
    344         $cmd .= " -bydiff $rvar_img_type $rvar_id";
    345     }
    346 
    347     if (($rvar_img_type == "raw") || ($rvar_img_type == "chip")) {
    348         if ($require_class_id && ! $rvar_class_id ) {
    349             throw new Exception("must specify Class ID with Image Type $rvar_img_type.");
    350         }
    351         if ((!$rvar_class_id) || ($rvar_class_id == "all")) {
    352             $cmd .= " null";
    353         } else {
    354             $cmd .= " $rvar_class_id";
    355         }
    356     }
     316        $cmd .= " --req_type bydiff --stage $rvar_img_type --id $rvar_id";
     317    }
     318
     319// XXX: don't need to require class_id anymore
     320//    if (($rvar_img_type == "raw") || ($rvar_img_type == "chip")) {
     321//        if (!$sky_checked && ($require_class_id && ! $rvar_class_id )) {
     322//            throw new Exception("must specify Class ID with Image Type $rvar_img_type.");
     323//        }
     324        // leave off compoennt if we're looking up by coordinates. It breaks it
     325        if (!$coord_checked && (($rvar_class_id) && ($rvar_class_id != "all"))) {
     326            $cmd .= " --component $rvar_class_id";
     327        }
     328//    }
    357329
    358330    return escapeshellcmd($cmd);
     
    390362}
    391363
     364// This is no longer used
    392365function printURL($line)
    393366{
     
    442415    echo "</td></tr>";
    443416}
    444 
    445 function countRunningJobs()
    446 {
    447     global $output_array;
    448 
    449     $runningJobs = 0;
    450     $size = sizeof($output_array);
    451     for ($i = 0; $i < $size; $i++) {
    452         $elements = explode(" ", $output_array[$i]);
    453         if (count($elements) == 3) {
    454             $state    = $elements[1];
    455             if ($state != "stop") {
    456                 $runningJobs++;
    457             }
    458         } else {
    459             throw new Exception ("incorrect data in job status: $output_array[$i]");
    460         }
    461     }
    462     return $runningJobs;
    463 }
    464 
    465 function listJobs($request_id, $jobFinished)
    466 {
    467     global $WORKDIR;
    468     global $SCRIPT;
    469 
    470     $command_line = "$SCRIPT pstamp_listjobs.pl $request_id";
    471     global $dbname;
    472     global $dbserver;
    473     if ($dbname) {
    474         $command_line .= " --dbname $dbname --dbserver $dbserver";
    475     }
    476 
    477     run_command($command_line);
    478     if ($jobFinished) {
    479         global $outFileset;
    480         global $dsroot;
    481         $parse_error = "$WORKDIR/$request_id/parse_error.txt";
    482         #echo "reading $parse_error\n";
    483         // readfile( $parse_error );
    484         if (file_exists($parse_error)) {
    485             $fhandle = fopen($parse_error, "r");
    486             if ($fhandle) {
    487                 $contents = fread($fhandle, 1024);
    488                 if ($contents) {
    489                     global $last_request_id;
    490                     global $error_line;
    491                     $error_line = "Request $last_request_id: $contents\n";
    492                 }
    493             }
    494         }
    495     }
    496 }
    497 
    498 function getRequestStatus()
    499 {
    500     global $request_id;
    501     global $command_status;
    502     global $output_array;
    503     global $outFileset;
    504     global $dbname;
    505     global $dbserver;
    506     global $SCRIPT;
    507 
    508     $command_line = "$SCRIPT pstamptool -listreq -req_id $request_id -simple";
    509     if ($dbname) {
    510         $command_line .= " -dbname $dbname -dbserver $dbserver";
    511     }
    512     // echo "Running $command_line\n";
    513 
    514     run_command($command_line);
    515     if ($command_status == 0) {
    516         $size = sizeof($output_array);
    517         $runningReq = 0;
    518         for ($i = 0; $i < $size; $i++) {
    519             $elements = explode(" ", $output_array[$i]);
    520             if (count($elements) >= 4) {
    521                 $state = $elements[2];
    522                 $outFileset = $elements[4];
    523                 if ($state != "stop") {
    524                     $runningReq++;
    525                 }
    526             } else {
    527                 throw new Exception ("incorrect data in job status: $output_array[$i]");
    528             }
    529         }
    530         return $runningReq;
    531     } else {
    532         return 0;
    533     }
    534 }
    535 
    536417?>
    537418
    538 <!-- Beginning of the HTML --------------------------------------------- -->
     419<!----------------------Beginning of the HTML --------------------------------------------- -->
     420
    539421<html>
    540  <head>
    541   <title>Postage Stamp Request Form</title>
    542     <?php
    543         if ($request_id != 0) {
    544             // This doesn't do what I want. It does a get not a post
    545 
    546             // echo '<META HTTP-EQUIV="refresh" CONTENT="5">';
    547 
    548         }
    549     ?>
    550  </head>
     422<head>
     423  <title>
     424    Postage Stamp Request Form (prototype)
     425  </title>
     426</head>
     427<body>
     428
     429<H1 align=center>
     430Postage Stamp Request Form
     431</h1>
     432
     433<?php
     434    welcomeHeader($auth_user, "pstamp_links.php", "Postage Stamp Home");
     435?>
     436
    551437<form method="post">
    552 
    553 <body>
    554 
    555 <H1 align=center>
    556 Postage Stamp Request
    557 </h1>
    558 
    559438<!-- Whole page is a single column table -->
    560439
     
    586465<td>
    587466&nbsp;<b>Select Images By:</b>&nbsp;&nbsp;&nbsp;
     467<input type=radio name="select_by" value="db_id" <?php echo $file_checked; ?> >Database ID
     468&nbsp;
    588469<input type=radio name="select_by" value="exposure_id" <?php echo $exp_checked; ?> >Exposure Name
    589470&nbsp;
    590 <input type=radio name="select_by" value="db_id" <?php echo $file_checked; ?> >Database ID
    591 &nbsp;
     471
    592472<input type=radio name="select_by" value="coord" <?php echo $coord_checked; ?> >Coordinates
    593473&nbsp;
     
    625505        echo "Chip ID:";
    626506      } else {
    627         echo "Class ID:";
     507        echo "Component:";
    628508      }
    629509?>
     
    685565            &nbsp;
    686566            <input type="text" name="dRA" size=10  value= <?php echo $rvar_dRA; ?> >
     567            &nbsp; "
    687568        </td>
    688569        <td>
     
    691572            &nbsp;
    692573            <input type="text" name="dDEC" size=10 value="<?php echo $rvar_dDEC;?>" >
     574            &nbsp; "
    693575        </td>
    694576    </tr>
     
    742624  <tr>
    743625
    744 <?php
    745   if ($request_id == 0): ?>
    746626    <td><input type=submit value="Submit"></td>
    747627    <td><b>Mode:</b>&nbsp;&nbsp;
     628    <input type=radio name="cmd_mode" value="Get Status"<?php echo $getstatus_checked; ?> >Get Status
    748629    <input type=radio name="cmd_mode" value="Make Stamps"<?php echo $pstamp_checked; ?> >Make Stamps
    749     <input type=radio name="cmd_mode" value="Get Images" <?php echo $get_checked; ?> >Get Images
     630    <input type=radio name="cmd_mode" value="Get Images" <?php echo $get_checked; ?> >Get Bundles
     631<!--
    750632    <input type=radio name="cmd_mode" value="List Images" <?php echo $list_checked; ?> >List Images
     633-->
    751634    </td>
    752 <?php
    753   else: ?>
    754     <td><input type=submit value="Check Status"></td>
    755 <!---    <td><input type=submit value="Cancel"></td> --->
    756635<?php
    757   echo "<td><b>Request Id: $request_id";
    758   endif; ?>
     636  // echo "<td><b>Request Id: $request_id";
     637?>
    759638
    760639  </tr>
     
    766645
    767646<tr>
     647<!--- Don't show the command
    768648    <td>
    769649    <b>Command:</b>&nbsp;&nbsp; <?php echo "$command_line\n";?>
     650    </td>
     651--->
     652
     653</tr>
     654<tr>
     655    <td>
     656    <b>Last Command</b>
    770657    </td>
    771658</tr>
     
    794681<td>
    795682<table align=center width=100% rules=none>
    796 <caption height=10 valign=center><b>Results</b></caption>
    797 
     683<caption height=10 valign=center><b>Request Results</b></caption>
    798684
    799685<?php
     686if (0) {
     687    // This is the old way of listing the status of the current request.
     688    // now we save the submitted requests in the session see listRequests() below
     689
    800690    $size = sizeof($output_array);
    801691    // echo "<pre>size of output array is $size\n</pre>";
     
    818708        }
    819709    }
     710} // end if if(0)
    820711?>
    821712</table>
     
    845736</table>
    846737
     738<?php
     739    listRequests("http://datastore.ipp.ifa.hawaii.edu/pstampresults", "pstamp_results_fileset");
     740?>
     741
    847742<!-- The end -->
    848743
     
    861756?>
    862757
     758</form>
    863759</body>
    864 </form>
    865 
    866760</html>
Note: See TracChangeset for help on using the changeset viewer.