// 2008-Jan-25 Brockman NCSSM IWP
// Simple PHP replacement for legacy .cgi script.
// Lists all the problems for easy copy + paste.
include_once('common.inc');
common_header("Problem List");
?>
IWP Problem List
If you wish to submit new problems to this list, please email Loren Winters, winters@ncssm.edu
$problemFiles = recurseFind($problemPath, '/.iwp$/');
foreach ( $problemFiles as $file ) {
$problemUrl = preg_replace("!$problemPath!", "", $file);
$problemUrl = preg_replace("!^/!", "", $problemUrl ); // take of front slash.
echo "$problemUrl
\n";
}
common_footer();
?>
// Directory helper functions.
function topLevelDirectories($dir)
{
return megaRecurseFind($dir, false, 1, true, false);
}
// This method is a recursive directory find
// Rather than call find . |grep iwp, I use the readdir to make it system agnos
function recurseFind($dir, $pattern) {
return megaRecurseFind($dir, $pattern, -1, false);
}
// This method is a generic version used by the topLevelDirs + the recursefind.
function megaRecurseFind($dir, $pattern, $maxLevels, $returnDirectories)
{
return megaRecurseFind_r(1, $dir, $pattern, $maxLevels, $returnDirectories);
}
// This is the actual method that is called recursively.
function megaRecurseFind_r($level, $dir, $pattern, $maxLevels, $returnDirectories)
{
// we're done!
if ( $maxLevels > 0 && $level > $maxLevels ) { return array(); }
global $filesep;
$subFiles = array();
$subDirs = array();
$dh = opendir($dir);
while ( false != ($file = readdir($dh)) ) {
if ( $file != '.' && $file != '..' ) {
$fullFile = $dir . $filesep . $file;
if ( is_dir($fullFile) ) {
array_push($subDirs, $fullFile);
} else {
if ( ! $pattern or preg_match($pattern, $fullFile) ) {
array_push($subFiles, $fullFile);
}
}
}
}
closedir($dh);
foreach ( $subDirs as $subDir ) {
foreach ( megaRecurseFind_r($level, $subDir, $pattern, $maxLevels, $returnDirectories) as $subsubFile ) {
array_push($subFiles, $subsubFile );
}
}
if ( $returnDirectories ) {
return $subDirs;
} else {
return $subFiles;
}
}
?>