Changeset 29086
- Timestamp:
- Aug 31, 2010, 2:53:39 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/web/request.php (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/web/request.php
r25322 r29086 16 16 // XXX This is just a prototype for testing purposes. 17 17 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 18 require "pstamp.php"; 19 require "submitted.php"; 33 20 34 21 # this script sets up the environment to run IPP commands with current directory … … 55 42 $diff_checked = ""; 56 43 $list_checked = ""; 44 $getstatus_checked = ""; 57 45 $pstamp_checked = ""; 58 46 $get_checked = ""; … … 102 90 if ($rvar_project == "gpc1") { 103 91 $gpc1_selected = "selected"; 104 $require_class_id = 1;92 // $require_class_id = 1; 105 93 } else if ($rvar_project == "megacam-mops") { 106 94 $mops_selected = "selected"; … … 122 110 $diff_checked = "CHECKED"; 123 111 } else { 124 // nothing checked default to By Exposure125 $ exp_checked = "CHECKED";112 // nothing checked default to By ID 113 $file_checked = "CHECKED"; 126 114 } 127 115 … … 140 128 141 129 // is the center is specified in Pixels or sky coordinates 142 if ($rvar_center_type == "Sky") { 130 if ($rvar_center_type == "Pixels") { 131 $sky_checked=""; 132 $pix_checked="checked"; 133 } else { 143 134 $sky_checked="checked"; 144 135 $pix_checked=""; 145 } else {146 $sky_checked="";147 $pix_checked="checked";148 136 } 149 137 … … 168 156 } 169 157 158 $getstatus_checked = ""; 159 $pstamp_checked = ""; 160 $list_checked = ""; 161 $get_checked = ""; 170 162 if ($rvar_cmd_mode == "Make Stamps") { 171 163 $pstamp_checked = "checked"; 172 $list_checked = "";173 $get_checked = "";174 164 } else if ($rvar_cmd_mode == "Get Images") { 175 165 $get_checked = "checked"; 176 $list_checked = ""; 177 $ pstamp_checked = "";166 } else if ($rvar_cmd_mode == "Get Status") { 167 $getstatus_checked = "checked"; 178 168 } else { 179 $list_checked = "checked"; 180 $get_checked = ""; 181 $pstamp_checked = ""; 169 // default 170 $pstamp_checked = "checked"; 182 171 } 183 172 … … 188 177 189 178 // 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 that179 // Well, the first time rvar_img_type is not set. So we key off of that. 191 180 // TODO: find a better way to decide whether or not to run commands 192 181 193 182 if ($rvar_img_type) { 194 195 183 $jobFinished = 0; 196 if ( $request_id == 0) {184 if (! $getstatus_checked) { 197 185 try { 198 186 $command_line = build_request_cmd(); … … 201 189 if (! $list_checked) { 202 190 // The only output from a successful run is the request_id 191 $request_name = trim(Array_pop($output_array)); 203 192 $request_id = Array_pop($output_array); 204 193 $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 } 209 205 } 210 211 $jobRunning = getRequestStatus();212 if (!$jobRunning) {213 // echo "1 getRequestStatus reuturned 0\n";214 $jobFinished = 1;215 $request_id = 0;216 }217 218 206 } else { 219 207 $last_request_id = 0; … … 222 210 $error_line = $e->getMessage(); 223 211 } 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 246 216 247 217 function build_request_cmd() … … 296 266 throw new Exception('RA and DEC must be specified.'); 297 267 } 298 $cmd .= " - skycenter $rvar_RA$rvar_DEC";268 $cmd .= " --ra $rvar_RA --dec $rvar_DEC"; 299 269 } else { 300 270 if (! $rvar_X || ! $rvar_Y) { 301 271 throw new Exception('X and Y must be specified.'); 302 272 } 303 $cmd .= " -pixcenter $rvar_X$rvar_Y";273 $cmd .= " -pixcenter --x $rvar_X --y $rvar_Y"; 304 274 } 305 275 … … 308 278 throw new Exception('dRA and dDEC must be specified.'); 309 279 } 310 $cmd .= " - arcrange $rvar_dRA$rvar_dDEC";280 $cmd .= " --arcseconds --width $rvar_dRA --height $rvar_dDEC"; 311 281 } else { 312 282 if (! $rvar_W || ! $rvar_H) { 313 283 throw new Exception('width and height must be specified.'); 314 284 } 315 $cmd .= " - pixrange $rvar_W$rvar_H";285 $cmd .= " --width $rvar_W --height $rvar_H"; 316 286 } 317 287 } … … 324 294 325 295 if ($exp_checked) { 296 if ($rvar_img_type == "stack") { 297 throw new Exception('Lookup by exposure name not supported for stack images.'); 298 } 326 299 if (! $rvar_id ) { 327 300 throw new Exception('Must set ID to the Exposure ID.'); 328 301 } 329 $cmd .= " - byexp $rvar_img_type$rvar_id";302 $cmd .= " --req_type byexp --stage $rvar_img_type --id $rvar_id"; 330 303 } else if ($file_checked) { 331 304 if (! $rvar_id ) { 332 305 throw new Exception('Must set ID to the exposure name.'); 333 306 } 334 $cmd .= " - byid $rvar_img_type$rvar_id";307 $cmd .= " --req_type byid --stage $rvar_img_type --id $rvar_id"; 335 308 } 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."); 340 312 } else if ($diff_checked) { 341 313 if (! $rvar_id ) { 342 314 throw new Exception('Must set ID to Diff Image ID.'); 343 315 } 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 // } 357 329 358 330 return escapeshellcmd($cmd); … … 390 362 } 391 363 364 // This is no longer used 392 365 function printURL($line) 393 366 { … … 442 415 echo "</td></tr>"; 443 416 } 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 536 417 ?> 537 418 538 <!-- Beginning of the HTML --------------------------------------------- --> 419 <!----------------------Beginning of the HTML --------------------------------------------- --> 420 539 421 <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> 430 Postage Stamp Request Form 431 </h1> 432 433 <?php 434 welcomeHeader($auth_user, "pstamp_links.php", "Postage Stamp Home"); 435 ?> 436 551 437 <form method="post"> 552 553 <body>554 555 <H1 align=center>556 Postage Stamp Request557 </h1>558 559 438 <!-- Whole page is a single column table --> 560 439 … … 586 465 <td> 587 466 <b>Select Images By:</b> 467 <input type=radio name="select_by" value="db_id" <?php echo $file_checked; ?> >Database ID 468 588 469 <input type=radio name="select_by" value="exposure_id" <?php echo $exp_checked; ?> >Exposure Name 589 470 590 <input type=radio name="select_by" value="db_id" <?php echo $file_checked; ?> >Database ID 591 471 592 472 <input type=radio name="select_by" value="coord" <?php echo $coord_checked; ?> >Coordinates 593 473 … … 625 505 echo "Chip ID:"; 626 506 } else { 627 echo "C lass ID:";507 echo "Component:"; 628 508 } 629 509 ?> … … 685 565 686 566 <input type="text" name="dRA" size=10 value= <?php echo $rvar_dRA; ?> > 567 " 687 568 </td> 688 569 <td> … … 691 572 692 573 <input type="text" name="dDEC" size=10 value="<?php echo $rvar_dDEC;?>" > 574 " 693 575 </td> 694 576 </tr> … … 742 624 <tr> 743 625 744 <?php745 if ($request_id == 0): ?>746 626 <td><input type=submit value="Submit"></td> 747 627 <td><b>Mode:</b> 628 <input type=radio name="cmd_mode" value="Get Status"<?php echo $getstatus_checked; ?> >Get Status 748 629 <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 <!-- 750 632 <input type=radio name="cmd_mode" value="List Images" <?php echo $list_checked; ?> >List Images 633 --> 751 634 </td> 752 <?php753 else: ?>754 <td><input type=submit value="Check Status"></td>755 <!--- <td><input type=submit value="Cancel"></td> --->756 635 <?php 757 echo "<td><b>Request Id: $request_id";758 endif;?>636 // echo "<td><b>Request Id: $request_id"; 637 ?> 759 638 760 639 </tr> … … 766 645 767 646 <tr> 647 <!--- Don't show the command 768 648 <td> 769 649 <b>Command:</b> <?php echo "$command_line\n";?> 650 </td> 651 ---> 652 653 </tr> 654 <tr> 655 <td> 656 <b>Last Command</b> 770 657 </td> 771 658 </tr> … … 794 681 <td> 795 682 <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> 798 684 799 685 <?php 686 if (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 800 690 $size = sizeof($output_array); 801 691 // echo "<pre>size of output array is $size\n</pre>"; … … 818 708 } 819 709 } 710 } // end if if(0) 820 711 ?> 821 712 </table> … … 845 736 </table> 846 737 738 <?php 739 listRequests("http://datastore.ipp.ifa.hawaii.edu/pstampresults", "pstamp_results_fileset"); 740 ?> 741 847 742 <!-- The end --> 848 743 … … 861 756 ?> 862 757 758 </form> 863 759 </body> 864 </form>865 866 760 </html>
Note:
See TracChangeset
for help on using the changeset viewer.
