Index: /trunk/htdocs/conesearch.php
===================================================================
--- /trunk/htdocs/conesearch.php	(revision 194)
+++ /trunk/htdocs/conesearch.php	(revision 195)
@@ -168,3 +168,4 @@
 echo"</RESOURCE>\n";
 echo"</VOTABLE>\n";
+
 ?>
Index: /trunk/htdocs/print_tables.php
===================================================================
--- /trunk/htdocs/print_tables.php	(revision 194)
+++ /trunk/htdocs/print_tables.php	(revision 195)
@@ -5,6 +5,21 @@
   // Function definitions for printing the results page
   // --------------------------------------------------
-  //&orderDir=asc&cals=cals&cals_within_mins=30
+  //
   ///////////////////////////////////////////////////////////////////////////////////////////////
+
+function printURL($state, $startRange, $endRange)
+{
+
+  // Collect the form values
+  global $params, $params_in, $params_URL,
+    $pulsar_name, $orderBy, $data_type, $orderDir, $bandname,
+    $rahour, $ramin, $rasec, $decdeg, $decmin, $decsec,
+    $radius, $from_day,	$from_month, $from_year,
+    $to_day, $to_month, $to_year, $state, $cals, $cals_within_mins;
+  		
+  echo "$PHP_SELF?startRange=$startRange&endRange=$endRange&$params_URL&cals=$cals&pulsar_name=$pulsar_name&orderBy=$orderBy&orderDir=$orderDir&cals=$cals&cals_within_mins=$cals_within_mins&data_type=$data_type&bandname=$bandname&rahour=$rahour&ramin=$ramin&rasec=$rasec&decdeg=$decdeg&decmin=$decmin&decsec=$decsec&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state";
+
+}
+
 
   // The page navigator
@@ -17,8 +32,4 @@
     $to_day, $to_month, $to_year, $state, $cals, $cals_within_mins;
 	
-  if (isset($params)) {
-    $params_str = array2urlstring("params", $params_in);
-  }
-		
   $num_pages = ceil($num_rows/MAX_DISPLAY_ROWS);
 	
@@ -31,5 +42,7 @@
     $prevStartRange = ($startPageRange - 1)*MAX_DISPLAY_ROWS + 1;
     $prevEndRange = $prevStartRange + MAX_DISPLAY_ROWS - 1;
-    echo "<a href=\"$PHP_SELF?startRange=$prevStartRange&endRange=$prevEndRange&$params_str&cals=$cals&pulsar_name=$pulsar_name&orderBy=$orderBy&orderDir=$orderDir&cals=$cals&cals_within_mins=$cals_within_mins&data_type=$data_type&rahour=$rahour&ramin=$ramin&rasec=$rasec&decdeg=$decdeg&decmin=$decmin&decsec=$decsec&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state\"><< Prev 10</a> &nbsp;\n";
+    echo "<a href=\"";
+    printURL($state, $prevStartRange, $prevEndRange);
+    echo "\"><< Prev10</a> &nbsp;\n";
   }
 
@@ -47,9 +60,13 @@
     // When the page index has reached the maximum range, print the next button
     else if ($i - $startPageRange == MAX_DISPLAY_PAGES ) {
-      echo " <a href=\"$PHP_SELF?startRange=$start&endRange=$end&$params_str&cals=$cals&pulsar_name=$pulsar_name&orderBy=$orderBy&orderDir=$orderDir&cals=$cals&cals_within_mins=$cals_within_mins&data_type=$data_type&rahour=$rahour&ramin=$ramin&rasec=$rasec&decdeg=$decdeg&decmin=$decmin&decsec=$decsec&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state\">Next 10 >></a> \n";
+      echo " <a href=\"";
+      printURL($state, $start, $end);
+      echo "\">Next 10 >></a> \n";
 		
     }
     else {
-      echo " <a href=\"$PHP_SELF?startRange=$start&endRange=$end&$params_str&cals=$cals&pulsar_name=$pulsar_name&orderBy=$orderBy&orderDir=$orderDir&cals=$cals&cals_within_mins=$cals_within_mins&data_type=$data_type&rahour=$rahour&ramin=$ramin&rasec=$rasec&decdeg=$decdeg&decmin=$decmin&decsec=$decsec&radius=$radius&from_day=$from_day&from_month=$from_month&from_year=$from_year&to_day=$to_day&to_month=$to_month&to_year=$to_year&state=$state\">".($i+1)."</a> &nbsp;\n";
+      echo " <a href=\"";
+      printURL($state, $start, $end);
+      echo "\">".($i+1)."</a> &nbsp;\n";
     }
   }
Index: /trunk/htdocs/query.php
===================================================================
--- /trunk/htdocs/query.php	(revision 194)
+++ /trunk/htdocs/query.php	(revision 195)
@@ -70,4 +70,6 @@
 $params_in           = get_param('params', $HTTP_GET_VARS);	
 	
+$params_URL       = array2urlstring("params", $params_in);	
+
 // The current state. E.g cart or results
 // Need to maintain this because other actions could be performed without changing state 
@@ -146,8 +148,8 @@
   $raj = ($rahour + $ramin/60. + $rasec/3600.) * 15.;
   $decj = abs($decdeg) + $decmin/60. + $decsec/3600.;
-  if($decdeg[0]=='-') $decj *= -1.;
- }
-
-if(is_numeric($radius)) $radius /= 60.; // put into degrees.
+  if($decdeg[0]=='-'){$decj *= -1.;}
+ }
+
+$radius /= 60.; // put into degrees.
 
 $params = array();
@@ -157,9 +159,8 @@
  }
 
-
 ///////
 // Do some basic error checking: SR>0, |dec|<90, ...
-echo "state=$state<br>\n";
-echo "actions=$actions<br>\n";
+//echo "state=$state<br>\n";
+//echo "actions=$actions<br>\n";
 if(!isset($actions)){
 
@@ -193,8 +194,4 @@
 // Precondition: The query has already been made, so the list of cals foreach observation
 // has already been determined ($_SESSION['obs_cals']).
-	
-if (!isset($cart_items)) {
-  $cart_items = array();
- }
 	
 if (isset($actions) && $actions != "") {
@@ -277,5 +274,4 @@
     break;
   }
-
  }
 	
@@ -294,4 +290,8 @@
  }
 	
+if (!isset($cart_items)) {
+  $cart_items = array();
+ }
+	
 $_SESSION['cart_items'] = $cart_items;
 $_SESSION['start_range'] = $startRange;
@@ -349,168 +349,161 @@
   }
 		
-  if(!$isError && !isset($actions))  {
-
-    ///////////////////////////////
-    // Set up the query string
-    //
-
-    $whereString = "";
-    $selectString = "SELECT ";
-
-    ///////////////////////////
-    // Constraint on pulsar name
-    //
-    //  In this case, query on pulsar name and on pulsar position 
-    //       -- obtain the latter from PSRCAT
-    //  if ($pulsar_name) {
-    if ($psrNameOK) {
-
-      // Check to see if the pulsar given is in the catalogue
-      $command = PSRCAT." -nohead -nonumber -o short -c \"\" $pulsar_name";
-      exec($command,$output);
-
-      if($output[0]=="") { // Pulsar is present
-
-	$commandPSR = PSRCAT." -nohead -nonumber -o short -c \"RAJD DECJD\" $pulsar_name";
-	exec($commandPSR, $outputPSR);
-	list($psr_rajd, $psr_decjd) = split("[ ]+", trim($outputPSR[0]));
+
+  ///////////////////////////////
+  // Set up the query string
+  //
+
+  $whereString = "";
+  $selectString = "SELECT ";
+
+  ///////////////////////////
+  // Constraint on pulsar name
+  //
+  //  In this case, query on pulsar name and on pulsar position 
+  //       -- obtain the latter from PSRCAT
+  //  if ($pulsar_name) {
+  if ($psrNameOK) {
+
+    // Check to see if the pulsar given is in the catalogue
+    $command = PSRCAT." -nohead -nonumber -o short -c \"\" $pulsar_name";
+    exec($command,$output);
+
+    if($output[0]=="") { // Pulsar is present
+
+      $commandPSR = PSRCAT." -nohead -nonumber -o short -c \"RAJD DECJD\" $pulsar_name";
+      exec($commandPSR, $outputPSR);
+      list($psr_rajd, $psr_decjd) = split("[ ]+", trim($outputPSR[0]));
             
-	// Remove the leading J and B
-	$output_psrname = ltrim($pulsar_name, "JBbj");
-
-	$angsepStringPSR = "degrees( acos( cos(radians(rajd-$psr_rajd))*cos(radians(decjd))*cos(radians($psr_decjd))+sin(radians(decjd))*sin(radians($psr_decjd))) )";
+      // Remove the leading J and B
+      $output_psrname = ltrim($pulsar_name, "JBbj");
+
+      $angsepStringPSR = "degrees( acos( cos(radians(rajd-$psr_rajd))*cos(radians(decjd))*cos(radians($psr_decjd))+sin(radians(decjd))*sin(radians($psr_decjd))) )";
       
-	$whereString .= " AND ( (($angsepStringPSR - 0.25*(bmaj+bmin)) < $radius) OR src_name LIKE '%$output_psrname' )";
+      //      $whereString .= " AND ( (($angsepStringPSR - 0.25*(bmaj+bmin)) < ".PSR_SEARCH_RADIUS.") OR src_name LIKE '%$output_psrname' )";
+      $whereString .= " AND ( (($angsepStringPSR - 0.25*(bmaj+bmin)) < $radius) OR src_name LIKE '%$output_psrname' )";
       
-	$selectString .= "$angsepStringPSR as distance, ";
+      $selectString .= "$angsepStringPSR as distance, ";
       
-      }
-      else{
-	$whereString .= "AND (1 = 0)"; // return nothing;
-	$selectString .= "0 as distance, ";
-	$psrNameOK = False;
-
-	$isError = True;
-	$errorMsg .= "<center><b>Error:</b> The pulsar name given, <b>$pulsar_name</b>, is not in the catalogue</center><br>\n";
-      }
-
-
-    } 
-    else{// if ($radius) {
-      ////////////////////////////
-      // Constraint on boundary
-      //  The pulsar name search takes precedence if both fields are filled in.
-
-      $angsepString = "(degrees( acos( cos(radians(rajd-$raj))*cos(radians(decjd))*cos(radians($decj))+sin(radians(decjd))*sin(radians($decj))) ) )";
+    }
+    else{
+      $whereString .= "AND (1 = 0)"; // return nothing;
+      $selectString .= "0 as distance, ";
+      $psrNameOK = False;
+
+      $isError = True;
+      $errorMsg .= "<center><b>Error:</b> The pulsar name given, <b>$pulsar_name</b>, is not in the catalogue</center><br>\n";
+    }
+
+
+  } 
+  else{// if ($radius) {
+  ////////////////////////////
+  // Constraint on boundary
+  //  The pulsar name search takes precedence if both fields are filled in.
+
+    $angsepString = "(degrees( acos( cos(radians(rajd-$raj))*cos(radians(decjd))*cos(radians($decj))+sin(radians(decjd))*sin(radians($decj))) ) )";
 		  
-      $whereString .= " AND (($angsepString - 0.25*(bmaj+bmin)) < $radius) ";
+    $whereString .= " AND (($angsepString - 0.25*(bmaj+bmin)) < $radius) ";
 		  
-      $selectString .= "$angsepString as distance, ";
-
-    }
-
-    $selectString .= $parameters;
-
-    ////////////////////////////
-    // Constraint on obs mode
-
-    if ($obs_mode == "search") {
-      $whereString .= " AND filename like '%.sf'";
-    }
-    else if($obs_mode == "timing"){
-      $whereString .= " AND filename not like '%.sf'";
-    }
-
-    ////////////////////////////
-    // Constraint on data type
-
-    if ($data_type) {
-      $whereString .= " AND data_type = '$data_type'";
-    }
-
-    ////////////////////////////
-    // Constraint on survey
-
-    if ($survey) {
-      $whereString .= " AND survey = '$survey'";
-    }
-
-    //////////////////////
-    // Constraint on MJD
-
-    $whereString .= " AND (MJD < $to_mjd AND MJD > $from_mjd)";
-
-    //////////////////////
-    // Constraint on freq
-
-    $bandString = "";
-    for ($i=0; $i < count($bandname); $i++) {
-      if($bandname[$i] = "70cm") $bandString .=" and (obsfreq<500.)";
-      if($bandname[$i] = "50cm") $bandString .=" and (obsfreq>600. and obsfreq<700.)";
-      if($bandname[$i] = "20cm") $bandString .=" and (obsfreq>1199.99 and obsfreq<1800.01)";
-      if($bandname[$i] = "13cm") $bandString .=" and (obsfreq>1999.99 and obsfreq<2500.01)";
-      if($bandname[$i] = "10cm") $bandString .=" and (obsfreq>2599.99 and obsfreq<3600.01)";
-      if($bandname[$i] = "6cm")  $bandString .=" and (obsfreq>4499.99 and obsfreq<5100.01)";
-      if($bandname[$i] = "5cm")  $bandString .=" and (obsfreq>5899.99 and obsfreq<6800.01)";
-      if($bandname[$i] = "3cm")  $bandString .=" and (obsfreq>8099.99 and obsfreq<8600.01)";
-      if($bandname[$i] = "1.3cm") $bandString .=" and (obsfreq>20999.99 and obsfreq<24000.01)";
-    }
-    for ($i=0; $i < count($bandname); $i++) {
-      if($bandname[$i] = "anyBand") $bandString = "";
-    }
-    $whereString .= $bandString;
-    ////////////////////////
-    //  Ordering the results
+    $selectString .= "$angsepString as distance, ";
+
+  }
+
+  $selectString .= $parameters;
+
+  ////////////////////////////
+  // Constraint on obs mode
+
+  if ($obs_mode == "search") {
+    $whereString .= " AND filename like '%.sf'";
+  }
+  else if($obs_mode == "timing"){
+    $whereString .= " AND filename not like '%.sf'";
+  }
+
+  ////////////////////////////
+  // Constraint on data type
+
+  if ($data_type) {
+    $whereString .= " AND data_type = '$data_type'";
+  }
+
+  ////////////////////////////
+  // Constraint on survey
+
+  if ($survey) {
+    $whereString .= " AND survey = '$survey'";
+  }
+
+  //////////////////////
+  // Constraint on MJD
+
+  $whereString .= " AND (MJD < $to_mjd AND MJD > $from_mjd)";
+
+  //////////////////////
+  // Constraint on freq
+
+  $bandString = "";
+  for ($i=0; $i < count($bandname); $i++) {
+    if($bandname[$i] = "70cm") $bandString .=" and (obsfreq<500.)";
+    if($bandname[$i] = "50cm") $bandString .=" and (obsfreq>600. and obsfreq<700.)";
+    if($bandname[$i] = "20cm") $bandString .=" and (obsfreq>1199.99 and obsfreq<1800.01)";
+    if($bandname[$i] = "13cm") $bandString .=" and (obsfreq>1999.99 and obsfreq<2500.01)";
+    if($bandname[$i] = "10cm") $bandString .=" and (obsfreq>2599.99 and obsfreq<3600.01)";
+    if($bandname[$i] = "6cm")  $bandString .=" and (obsfreq>4499.99 and obsfreq<5100.01)";
+    if($bandname[$i] = "5cm")  $bandString .=" and (obsfreq>5899.99 and obsfreq<6800.01)";
+    if($bandname[$i] = "3cm")  $bandString .=" and (obsfreq>8099.99 and obsfreq<8600.01)";
+    if($bandname[$i] = "1.3cm") $bandString .=" and (obsfreq>20999.99 and obsfreq<24000.01)";
+  }
+  for ($i=0; $i < count($bandname); $i++) {
+    if($bandname[$i] = "anyBand") $bandString = "";
+  }
+  $whereString .= $bandString;
+  ////////////////////////
+  //  Ordering the results
   
-    $orderString = " ORDER BY ";
-    $orderString .= $orderBy . " " . $orderDir;
-
-    // add other alternatives, in order of preference, if they haven't been selected first.
-    if($orderBy!="distance") $orderString .= ",distance asc";
-    if($orderBy!="filename") $orderString .= ",filename desc";
-    if($orderBy!="date") $orderString .= ",date asc";
-    if($orderBy!="obsfreq") $orderString .= ",obsfreq asc";
-
-
-    ///////////////////////////////
-    // Performing SQL query
-    //
-
-    $link = db_connect();
-
-    // Remove any leading or trailing AND and OR
-    $whereString = trim($whereString, " AND OR");
-
-    $query = "( $selectString FROM s70 WHERE $whereString ) UNION ( $selectString FROM obs WHERE $whereString )";
-
-    $query .= $orderString;
-
-//     $query .= " limit ".MAX_RESULTS; // limit the maximum number of results to be returned.
-
-//     $numquery = "select a.num+b.num as num from (select count(*) as num from s70 where $whereString) as a, (select count(*) as num from obs where $whereString) as b";
-//     $numresult = mysql_query($numquery);
-//     $numrows = mysql_fetch_assoc($numresult);
-//     if($numrows['num'] > MAX_RESULTS) {
-//       echo "<center><b>Note:</b> Your query returns more results (".$numrows['num'].") than the internal limit.<br>Only showing the first ".MAX_RESULTS." rows.</center><br>\n";
-//     }
-    
-    //    echo "$query<br>";
-
-    $result = mysql_query($query) or die('Main Query failed: ' . mysql_error() . "\n". $query);
-  
-    $all_results = array();
-
-    while ($line = mysql_fetch_assoc($result)) {
-      array_push($all_results, $line );
-    }
-		
-    $_SESSION['results'] = $all_results;
-	
-    mysql_free_result($result);
-
-    mysql_close($link);
-
-  }
-
+  $orderString = " ORDER BY ";
+  $orderString .= $orderBy . " " . $orderDir;
+
+  // add other alternatives, in order of preference, if they haven't been selected first.
+  if($orderBy!="distance") $orderString .= ",distance asc";
+  if($orderBy!="filename") $orderString .= ",filename desc";
+  if($orderBy!="date") $orderString .= ",date asc";
+  if($orderBy!="obsfreq") $orderString .= ",obsfreq asc";
+
+
+  ///////////////////////////////
+  // Performing SQL query
+  //
+
+  $link = db_connect();
+
+  // Remove any leading or trailing AND and OR
+  $whereString = trim($whereString, " AND OR");
+
+  $query = "( $selectString FROM s70 WHERE $whereString ) UNION ( $selectString FROM obs WHERE $whereString )";
+
+  $query .= $orderString;
+
+//    echo "$query<br>";
+
+  $result = mysql_query($query) or die('Main Query failed: ' . mysql_error() . "\n". $query);
+
+  $all_results = array();
+
+//   $temp_num_results = mysql_num_rows($result);
+//   echo "<br><br><br>$temp_num_results<br>\n";
+//   return 0;
+
+  while ($line = mysql_fetch_assoc($result)) {
+    array_push($all_results, $line );
+  }
+		
+  $_SESSION['results'] = $all_results;
+	
+  mysql_free_result($result);
+
+  mysql_close($link);
+	
  }
 	
@@ -589,11 +582,7 @@
       <input type="submit" value="Perform action">
       </td>
-      <td class="top_menu" align="right">
-      <?php 
-      $sizeMB = sprintf("%.1f MB", $total_cart_size_bytes/1000000);
-      echo "Cart size: <b><a href=".$PHP_SELF."?radius=".($radius*60)."&state=cart&startRange=1&endRange=".count($cart_items).">".count($cart_items);
-      echo " Item/s</a> (".$sizeMB.")\n";
-      ?>
-      <td class="top_menu" align="right" width="1%"><a href="<?php echo $PHP_SELF;?>?radius=".($radius*60)."&state=results&startRange=1&endRange=<?php echo MAX_DISPLAY_ROWS; ?>">
+      <td class="top_menu" align="right"><b><?php echo count($cart_items); ?></b>
+      Item/s (<?php printf("%.1f MB", $total_cart_size_bytes/1000000);?>)</td>
+      <td class="top_menu" align="right" width="1%"><a href="<?php echo $PHP_SELF;?>?state=results&startRange=1&endRange=<?php echo MAX_DISPLAY_ROWS; ?>">
       <img alt="Revert to query results" border="0" title="Revert to query results" src="/images/table_30px_white.png"></img></a>
       </td>
@@ -609,6 +598,6 @@
 	    <option>----- Profile Viewing Options -----</option>
 	    <option><?php echo VIEW_PROFILES; ?></option>
-echo "cals = $cals<br>\n";
 						    <?php 
+										  echo "cals = $cals<br>\n";
     if (isset($cals) && $cals != "") {
       echo "<option>".VIEW_PROFILES_CALS."</option>\n";
@@ -619,14 +608,7 @@
     <input type="submit" value="Perform action">
 	</td>
-
-
-    <td class="top_menu" align="right" width="20%">
-	<?php 
-	$sizeMB = sprintf("%.1f MB", $total_cart_size_bytes/1000000);
-      echo "Cart size: <b><a href=".$PHP_SELF."?&state=cart&startRange=1&endRange=".count($cart_items).">".count($cart_items);
-      echo " Item/s</a> (".$sizeMB.")\n";
-      ?>
- </td>
-     <td class=\"top_menu\" align=\"right\" width=\"1%\"><a href="<?php echo $PHP_SELF;?>?radius=".($radius*60)."&state=cart&startRange=1&endRange=<?php echo count($cart_items);?>">
+	<td class="top_menu" align="right" width="20%"><b><?php echo count($cart_items); ?></b>
+	<a href="<?php echo $PHP_SELF;?>?state=cart&startRange=1&endRange=<?php echo count($cart_items);?>">Item/s</a> (<?php printf("%.1f MB", $total_cart_size_bytes/1000000);?>)</td>
+	<td class=\"top_menu\" align=\"right\" width=\"1%\"><a href="<?php echo $PHP_SELF;?>?state=cart&startRange=1&endRange=<?php echo count($cart_items);?>">
     <img alt="View observation cart" border="0" title="View observation cart" src="/images/cart_30px_white.png"></img></a>
     </td>
@@ -650,6 +632,6 @@
     else{
       echo "<center>Sorry, no results matched your search</center><br>\n";
-      //    if(!$psrNameOK && $pulsar_name!="") echo "<center>The pulsar name given, <b>$pulsar_name</b>, is not in the catalogue</center><br>\n";
-    }
+    }
+    //    if(!$psrNameOK && $pulsar_name!="") echo "<center>The pulsar name given, <b>$pulsar_name</b>, is not in the catalogue</center><br>\n";
     echo "<center><a href=\"index.php\">Search again</a></center><br>\n";
   }
