(file) Return to howtolist.php CVS log (file) (dir) Up to [HallC] / Documents / Howtos

File: [HallC] / Documents / Howtos / howtolist.php (download)
Revision: 1.4, Wed Aug 18 19:58:09 2004 UTC (20 years, 1 month ago) by saw
Branch: MAIN
CVS Tags: mar2005, hks05
Changes since 1.3: +14 -0 lines
For new PHP, get passed variables out of POST or GET arrays

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>List of Hall C Howtos</title>
<body>
<h1>Table of Hall C Howtos</h1>
The following is a table of Hall C howtos and references.
To sort the listing, click on column heading for the column
that you would like to sort on.
<p>
If you are writing a howto and would like to cite a howto in this list,
use the command <tt>\cite{howto:</tt><i>filename</i><tt>}</tt>, where
<i>filename</i> is the filename of the other howto.
<p>
To read a howto online, click on the title for that howto.  To download a
postscript file suitable for printing, click on the appropriate link in
the "PS" column.
<p>
<?php

switch ($_SERVER["REQUEST_METHOD"])
{ 
 case "POST": 
   $sortby = $HTTP_POST_VARS['sortby'];
   $reverse = $HTTP_POST_VARS['reverse'];
   break; 

 case "GET":
   $sortby = $HTTP_GET_VARS['sortby'];
   $reverse = $HTTP_GET_VARS['reverse'];
   break;
}


//$thisfilename = "howtolist.php";
$thisfilename = $_SERVER['PHP_SELF'];
$databasefilename = "howtolist.text";
if(!$sortby) {
  $sortby = "Filename";
}

function chop_newline($str)
{
 return preg_replace("/\r?\n$|\r[^\n]$/", "", $str);
}

function lastname($name)
{
  // If name contains a ",", just return it.  Otherwise put last name
  // first.
  if(preg_match("/^([^,]*) ([^,]*)$/", $name, $matches)) {
    $name = "$matches[2], $matches[1]";
  }
  return($name);
}
		

function array_qsort2 (&$array, $column=0, $order=SORT_ASC, $first=0, $last= -2)
{
 // $array  - the array to be sorted
 // $column - index (column) on which to sort
 //          can be a string if using an associative array
 // $order  - SORT_ASC (default) for ascending or SORT_DESC for descending
 // $first  - start index (row) for partial array sort
 // $last   - stop index (row) for partial array sort

  if($column == "Author") {
    $namesort = 1;
  }
  if($last == -2) $last = count($array) - 1;
  if($last > $first) {
    $alpha = $first;
    $omega = $last;
    $guess = strtolower($array[$alpha][$column]);
    if($namesort) {
      $guess_name = strtolower(lastname($guess));
    }
    while($omega >= $alpha) {
      if($namesort) {
	if($order == SORT_ASC) {
	  $alpha_name = strtolower(lastname($array[$alpha][$column]));
	  $omega_name = strtolower(lastname($array[$omega][$column]));
	  while($alpha_name < $guess_name) {
	    $alpha++;
	    $alpha_name = strtolower(lastname($array[$alpha][$column]));
	  }
	  while($omega_name > $guess_name) {
	    $omega--;
	    $omega_name = strtolower(lastname($array[$omega][$column]));
	  }
	} else {
	  $alpha_name = strtolower(lastname($array[$alpha][$column]));
	  $omega_name = strtolower(lastname($array[$omega][$column]));
	  while($alpha_name > $guess_name) {
	    $alpha++;
	    $alpha_name = strtolower(lastname($array[$alpha][$column]));
	  }
	  while($omega_name < $guess_name) {
	    $omega--;
	    $omega_name = strtolower(lastname($array[$omega][$column]));
	  }
	}
      } else {
	if($order == SORT_ASC) {
	  while(strtolower($array[$alpha][$column]) < $guess) $alpha++;
	  while(strtolower($array[$omega][$column]) > $guess) $omega--;
	} else {
	  while(strtolower($array[$alpha][$column]) > $guess) $alpha++;
	  while(strtolower($array[$omega][$column]) < $guess) $omega--;
	}
      }
      if($alpha > $omega) break;
      $temporary = $array[$alpha];
      $array[$alpha++] = $array[$omega];
      $array[$omega--] = $temporary;
    }
    array_qsort2 ($array, $column, $order, $first, $omega);
    array_qsort2 ($array, $column, $order, $alpha, $last);
  }
} 

$howtolist = fopen($databasefilename,"r");
$columns = split('\|',chop_newline(fgets($howtolist,4096)));
$colcount=count($columns);
#for ($i=0; $i<$colcount; $i++) {
#  print "$i $columns[$i]\n";
#}

$howtoarray = Array();
while(!feof($howtolist) && ($howtoline=fgets($howtolist,4096))) {
  $fieldvals = split('\|',chop_newline($howtoline,4096));
  $tmparr = Array();
  for($i=0;$i<$colcount;$i++) {
    $tmparr[$columns[$i]] = $fieldvals[$i];
  }
  $howtoarray[] = $tmparr;
#  print "$howtoline\n";
}
#$howtoarray = qsort_multiarray($howtoarray, "Title");
if($reverse) {
  array_qsort2($howtoarray, $sortby, SORT_DESC);
} else {
  array_qsort2($howtoarray, $sortby);
}

$ndocs = count($howtoarray);
#print "$ndocs documents\n";
#print "<table border cellpadding=3 cellspacing=0>\n
#<tr><th>Filename</th><th>Category</th><th>Type</th><th>Author</th><th>Title</th><th>PS</th></tr><tr></tr>\n";
print "<table border cellpadding=3 cellspacing=0>\n";
print "<tr>";
for($col=0;$col<$colcount;$col++) {
  $colname = $columns[$col];
  if($colname == "PS") {
    print "<th>$colname</th>";
  } else if ($colname != "HTML") {
    if($colname == $sortby && !$reverse) {
      print "<th><a href=\"$thisfilename?sortby=$colname&reverse=1\">$colname</a></th>";
    } else {
      print "<th><a href=\"$thisfilename?sortby=$colname\">$colname</a></th>";
    }
  }
}
print "</tr>";

for ($i=0; $i<$ndocs;$i++) {
  $tmparr = $howtoarray[$i];
#  print "<tr><td>$tmparr[Filename]</td><td>$tmparr[Category]</td>
#<td>$tmparr[Type]</td><td>$tmparr[Author]</td>
#<td><a href=\"$tmparr[HTML]\">$tmparr[Title]</a></td>
#<td><a href=\"$tmparr[PS]\">PS</a></td></tr>\n";
  print "<tr>";
  for($col=0;$col<$colcount;$col++) {
    $colname = $columns[$col];
    if($colname != "HTML") {
      if($colname == "PS") {
	print "<td><a href=\"$tmparr[$colname]\">PS</a></td>";
      } elseif ($colname == "Title") {
	print "<td><a href=\"$tmparr[HTML]\">$tmparr[$colname]</a></td>";
      } else {
	print "<td>$tmparr[$colname]</td>";
      }
    }
  }
  print "</tr>\n";
}

print "</table>\n";
$date = date("F d, Y",filemtime($databasefilename));
print "<p>Last modified $date\n";
?>
</body>
</html>

Analyzer/Replay: Mark Jones, Documents: Stephen Wood
Powered by
ViewCVS 0.9.2-cvsgraph-1.4.0