<?php /*                                     * /
      $root='/cpmarchive';  /* for main site */
      $root='';             /* for local site */
      $sitevars=$root.'site/html/variables.php'; include $sitevars;
    ?>

<?php

	// MINIXED is a minimal but nice-looking PHP directory indexer.
	// More at https://github.com/lorenzos/Minixed

	// =============================
	// Configuration                
	// =============================
	
	// $browseDirectories = false; // Navigate into sub-folders
	$browseDirectories = true; // Navigate into sub-folders
	// $title = 'Index of {{path}}';
	$title = '{{path}}';
	$subtitle = '{{files}} objects in this folder, {{size}} total'; // Empty to disable
	$showParent = false; // Display a (parent directory) link
	$showDirectories = true;
	$showHiddenFiles = false; // Display files starting with "." too
	$alignment = 'left'; // You can use 'left' or 'center'
	$showIcons = false;
	// $dateFormat = 'd/m/y H:i'; // Used in date() function
	$dateFormat = 'y/m/d H:i'; // Used in date() function
	$sizeDecimals = 1;
	$robots = 'noindex, nofollow'; // Avoid robots by default
	$showFooter = false; // Display the "Powered by" footer
	$openIndex = $browseDirectories && true; // Open index files present in the current directory if browseDirectories is enabled
	
	// =============================
	// =============================
	
	// Who am I?
	$_self = basename($_SERVER['PHP_SELF']);
	$_path = str_replace('\\', '/', dirname($_SERVER['PHP_SELF']));
	$_total = 0;
	$_total_size = 0;
	
	// Directory browsing
	$_browse = null;
	if ($browseDirectories) {
		$_GET['b'] = trim(str_replace('\\', '/', $_GET['b']), '/ ');
		$_GET['b'] = str_replace(array('/..', '../'), '', $_GET['b']); // Avoid going up into filesystem
		if (!empty($_GET['b']) && $_GET['b'] != '..' && is_dir($_GET['b'])) $_browse = $_GET['b'];
	}
	
	// Index open
	if (!empty($_browse) && $openIndex) {
		$_index = null;
		if (file_exists($_browse . "/index.htm")) $_index = "/index.htm";
		if (file_exists($_browse . "/index.html")) $_index = "/index.html";
		if (file_exists($_browse . "/index.php")) $_index = "/index.php";
		if (!empty($_index)) {
			header('Location: ' . $_browse . $_index);
			exit();
		}
	}

	// Encoded images generator
	if (!empty($_GET['i'])) {
		header('Content-type: image/png');
		switch ($_GET['i']) {
			case       'asc': exit(base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAAFUlEQVQImWNgoBT8x4JxKsBpAhUAAPUACPhuMItPAAAAAElFTkSuQmCC'));
			case      'desc': exit(base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAAF0lEQVQImWNgoBb4j0/iPzYF/7FgCgAADegI+OMeBfsAAAAASUVORK5CYII='));
			case 'directory': exit(base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAASklEQVQYlYWPwQ3AMAgDb3Tv5AHdR5OqTaBB8gM4bAGApACPRr/XuujA+vqVcAI3swDYjqRSH7B9oHI8grbTgWN+g3+xq0k6TegCNtdPnJDsj8sAAAAASUVORK5CYII='));
			case      'file': exit(base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAPklEQVQYlcXQsQ0AIAhE0b//GgzDWGdjDCJoKck13CsIALi7gJxyVmFmyrsXLHEHD7zBmBbezvoJm4cL0OwYouM4O3J+UDYAAAAASUVORK5CYII='));
		}
	}
	
	// I'm not sure this function is really needed...
	function ls($path, $show_folders = false, $show_hidden = false) {
		global $_self, $_total, $_total_size;
		$ls = array();
		$ls_d = array();
		if (($dh = @opendir($path)) === false) return $ls;
		if (substr($path, -1) != '/') $path .= '/';
		while (($file = readdir($dh)) !== false) {
			if ($file == $_self) continue;
			if ($file == '.' || $file == '..') continue;
			if (!$show_hidden) if (substr($file, 0, 1) == '.') continue;
			$isdir = is_dir($path . $file);
			if (!$show_folders && $isdir) continue;
			$item = array('name' => $file, 'isdir' => $isdir, 'size' => $isdir ? 0 : filesize($path . $file), 'time' => filemtime($path . $file));
			if ($isdir) $ls_d[] = $item; else $ls[] = $item;
			$_total++;
			$_total_size += $item['size'];
		}
		return array_merge($ls_d, $ls);
	}
	
	// Get the list of files
	$items = ls('.' . (empty($_browse) ? '' : '/' . $_browse), $showDirectories, $showHiddenFiles);
	
	// Sort it
	function sortByName($a, $b) { return ($a['isdir'] == $b['isdir'] ? strtolower($a['name']) > strtolower($b['name']) : $a['isdir'] < $b['isdir']); }
	function sortBySize($a, $b) { return ($a['isdir'] == $b['isdir'] ? $a['size'] > $b['size'] : $a['isdir'] < $b['isdir']); }
	function sortByTime($a, $b) { return ($a['time'] > $b['time']); }
	switch (@$_GET['s']) {
		case 'size': $_sort = 'size'; usort($items, 'sortBySize'); break;
		case 'time': $_sort = 'time'; usort($items, 'sortByTime'); break;
		default    : $_sort = 'name'; usort($items, 'sortByName'); break;
	}
	
	// Reverse?
	$_sort_reverse = (@$_GET['r'] == '1');
	if ($_sort_reverse) $items = array_reverse($items);
	
	// Add parent
	if ($showParent && $_path != '/' && empty($_browse)) array_unshift($items, array(
		'name' => '..',
		'isparent' => true,
		'isdir' => true,
		'size' => 0,
		'time' => 0
	));

	// Add parent in case of browsing a sub-folder
	if (!empty($_browse)) array_unshift($items, array(
		'name' => '..',
		'isparent' => false,
		'isdir' => true,
		'size' => 0,
		'time' => 0
	));
	
	// 37.6 MB is better than 39487001
	function humanizeFilesize($val, $round = 0) {
		$unit = array('','K','M','G','T','P','E','Z','Y');
		do { $val /= 1024; array_shift($unit); } while ($val >= 1000);
		return sprintf('%.'.intval($round).'f', $val) . ' ' . array_shift($unit) . 'B';
	}
	
	// Titles parser
	function getTitle($title) {
		global $_path, $_browse, $_total, $_total_size, $sizeDecimals;
		$path = $_path;
		if (!empty($_browse)) $path = $path . ($path != '/' ? '/' : '') . $_browse;
		return str_replace(array('{{path}}', '{{files}}', '{{size}}'), array($path, $_total, humanizeFilesize($_total_size, $sizeDecimals)), $title);
	}
	
	// Link builder
	function buildLink($changes) {
		global $_self;
		$params = $_GET;
		foreach ($changes as $k => $v) if (is_null($v)) unset($params[$k]); else $params[$k] = $v;
		foreach ($params as $k => $v) $params[$k] = urlencode($k) . '=' . urlencode($v);
		return empty($params) ? $_self : $_self . '?' . implode($params, '&');
	}

# Above is the original MINIXED script. The following functions were added by NCJEC for *HUMONGOUS* CP/M.

	function message() {
	// Allows returning a message at the top of the file listing if we are in a certain folder. 
	// Specify enough of the folder path to be unique, then the message to be displayed. 
	// The message may include html code. The string to be searched does not contain a trailing slash. Use this to distinguish between a parent and a child dir.
	// Use stripos for a case-insensitive search.
	//	if  (strpos($_GET['b'], 'path/to/directory') !== false ) return "Your message goes here." ;
		if ((strpos($_GET['b'], 'ns/EBMM'     ) !== false ) && (strpos($_GET['b'], 'ns/EBMM/'     ) == false )) return "<p style='text-align: center'>The East Bay MicroMate Users Group collection. To access the IMD images, use Dave Dunfield's <a href='http://www.classiccmp.org/dunfield/img/index.htm'>ImageDisk utilities</a> to convert them to RAW format. You can then access the raw images with cpmtools using the 'pmc101' format.</p>" ; 
		if  (strpos($_GET['b'], 'ns/FOG/ARC'  ) !== false )                                                     return "<p style='text-align: center'>These are LBR files wrapped in ARC archives. Under CP/M use UNARC or UNARCZ and LU to extract them.</p>" ; 
		if  (strpos($_GET['b'], 'ns/FOG/IMD'  ) !== false )                                                     return "<p style='text-align: center'>These images from <a href='/home/nathanael/temp/FOGCPM/www.bitsavers.org/bits/Users_Groups/FOG/FOG_Master_Disks/'>Bitsavers</a> were created from the original FOG master disks. However, the collection is complete only through vol. 214. Use Dave Dunfield's <a href='http://www.classiccmp.org/dunfield/img/index.htm'>ImageDisk utilities</a> to convert these to RAW format, then access the RAW files via cpmtools using the 'osborne' format.</p>" ; 
		if  (strpos($_GET['b'], 'us/SIGM/v184') !== false )                                                     return "<p style='text-align: center'>These files were expunged from the original <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm%2Fvols100'>WalnutCD</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm%2Fvol184'>OAK</a> collections.</p>" ; 
		if  (strpos($_GET['b'], 'us/SIGM/v185') !== false )                                                     return "<p style='text-align: center'>These files were expunged from the original <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm%2Fvols100'>WalnutCD</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm%2Fvol185'>OAK</a> collections.</p>" ; 
		if  (strpos($_GET['b'], 'us/SIGM/v186') !== false )                                                     return "<p style='text-align: center'>These files were expunged from the original <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm%2Fvols100'>WalnutCD</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm%2Fvol186'>OAK</a> collections.</p>" ; 
		if  (strpos($_GET['b'], 'us/SIGM/v187') !== false )                                                     return "<p style='text-align: center'>These files were expunged from the original <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm%2Fvols100'>WalnutCD</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm%2Fvol187'>OAK</a> collections.</p>" ; 
		if  (strpos($_GET['b'], 'us/SIGM/v188') !== false )                                                     return "<p style='text-align: center'>These files were expunged from the original <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm%2Fvols100'>WalnutCD</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm%2Fvol188'>OAK</a> collections.</p>" ; 
		if  (strpos($_GET['b'], 'us/SIGM/v189') !== false )                                                     return "<p style='text-align: center'>These files were expunged from the original <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm%2Fvols100'>WalnutCD</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm%2Fvol189'>OAK</a> collections.</p>" ; 
		if  (strpos($_GET['b'], 'us/SIGM/v190') !== false )                                                     return "<p style='text-align: center'>These files were expunged from the original <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm%2Fvols100'>WalnutCD</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm%2Fvol190'>OAK</a> collections.</p>" ; 
		if  (strpos($_GET['b'], 'us/SIGM/v191') !== false )                                                     return "<p style='text-align: center'>These files were expunged from the original <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm%2Fvols100'>WalnutCD</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm%2Fvol191'>OAK</a> collections.</p>" ; 
		if  (strpos($_GET['b'], 'us/SIGM/v192') !== false )                                                     return "<p style='text-align: center'>These files were expunged from the original <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm%2Fvols100'>WalnutCD</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm%2Fvol192'>OAK</a> collections.</p>" ; 
		# This /cpmug must come before .edu/pub/cpm to avoid confusing it for the latter
		if  (strpos($_GET['b'], 'l/cpmug'     ) !== false )                                                     return "<p style='text-align: center'>The CP/M User Group software distribution disks. Extract with ARC20 or ARK11, <a href='ftp.php?b=cpm/Software/WalnutCD/enterprs/cpm/utils/a/'>here</a>. The missing CPMUG #39 is <a href='ftp.php?b=cpm/Software/CPM_DOSGG/CPM00/39'>here</a>; the new #93 is <a href='ftp.php?b=cpm/Software/CPM_DOSGG/CPM00/93'>here</a>. CPMUG #55-77 duplicate <a href='ftp.php?b=cpm/Software/WalnutCD/simtel/sigm/vols000'>SIGM</a> #1,2,11,4-10,13-25.</p>" ;
		if ((strpos($_GET['b'], 's/CPMUG'     ) !== false ) && (strpos($_GET['b'], 's/CPMUG/'     ) == false )) return "<p style='text-align: center'>The complete CP/M User Group software distribution disk collection. Restores the missing vols. 39 and 55-77, and includes vol. 93, released after WalnutCD." ;
		if ((strpos($_GET['b'], 'sourdough'   ) !== false ) && (strpos($_GET['b'], 'sourdough/'   ) == false )) return "<p style='text-align: center'>Jim's Sourdough CP/M Archives Disk. Much of the material here is drawn from other collections (CPMUG, SIGM, OAK). But some of it, in particular the Kaypro stuff, is not found elsewhere. The PC-Blue MS-DOS and Windows 95 collections are omitted from FTP browsing, but still available in the <a href='downloads/sourdough_jims_cpm_archive.zip'>ISO</a>.</p>" ;
		if ((strpos($_GET['b'], 'WalnutCD'    ) !== false ) && (strpos($_GET['b'], 'WalnutCD/'    ) == false )) return "<p style='text-align: center'>The Walnut Creek CP/M CD-ROM. Includes the <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fcpm'>MIT-MC Repository</a>, the <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel'>SIMTEL-20 Archives</a> (with <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fcpmug'>CPMUG</a> and <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm'>SIG/M</a>), the <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fdemon'>Demon Archives</a>, the <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Ffog'>First Osborne Group</a> and the <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fmbug'>Microbee User Group</a> software collections, and more.</p>" ;
		if ((strpos($_GET['b'], 'DOSGG/CPM00' ) !== false ) && (strpos($_GET['b'], 'DOSGG/CPM00/' ) == false )) return "<p style='text-align: center'>For missing volumes, see the <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fcpmug'>CPMUG collection</a> on the Walnut Creek CD.</p>" ; 
		if ((strpos($_GET['b'], 'DOSGG/CPM10' ) !== false ) && (strpos($_GET['b'], 'DOSGG/CPM10/' ) == false )) return "<p style='text-align: center'>For missing volumes, see the <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm'>SIGM collection</a> on the Walnut Creek CD.</p>" ; 
		if ((strpos($_GET['b'], 'sigm/vols100') !== false ) && (strpos($_GET['b'], 'sigm/vols100/') == false )) return "<p style='text-align: center'>Vols. 184-192 were expunged from the original SIGM collections. Find them <a href='ftp.php?b=cpm/Software/CPM_DOSGG/CPM11/'>here</a>.</p>" ;
		if ((strpos($_GET['b'], 'pub/sigm'    ) !== false ) && (strpos($_GET['b'], 'pub/sigm/'    ) == false )) return "<p style='text-align: center'>The Special Interest Group CP/M (SIG/M) distribution disks. Vols. 184-192 and portions of 216 are missing. Find them <a href='ftp.php?b=cpm/Software/Humongous/Collctns/SIGM'>here</a>.</p>" ;
		if ((strpos($_GET['b'], 'and.edu/pub' ) !== false ) && (strpos($_GET['b'], 'and.edu/pub/' ) == false )) return "<p style='text-align: center'>Oakland.edu's OAK Repository, featuring a mirror of the <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fcpm'>MIT-MC Repository</a> and the <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fcpmug'>CPMUG</a> and <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fsigm'>SIG/M</a> distribution disks. The MIT-MC portion here, from 1996, has some updates over the <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fcpm'>version</a> on the Walnut CD.</p>";
		if ((strpos($_GET['b'], '.edu/pub/cpm') !== false ) && (strpos($_GET['b'], '.edu/pub/cpm/') == false )) return "<p style='text-align: center'>The MIT-MC Repository (MIT-MC.ARPA). This is a newer mirror, with additions, than <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fcpm'>that</a> on the Walnut Creek CD.</p>";
		if ((strpos($_GET['b'], 'WalnutCD/cpm') !== false ) && (strpos($_GET['b'], 'WalnutCD/cpm/') == false )) return "<p style='text-align: center'>The MIT-MC Repository (MIT-MC.ARPA). A newer mirror, with a large number of additions, is <a href='ftp.php?b=cpm%2Fmirrors%2Foak.oakland.edu%2Fpub%2Fcpm'>here</a>.</p>";
		if ((strpos($_GET['b'], 'demon'       ) !== false ) && (strpos($_GET['b'], 'demon/'       ) == false )) return "<p style='text-align: center'>The Demon Archives. A more recent mirror of Demon is <a href='ftp.php?b=cpm/mirrors/ftp.demon.com/pub/cpm/'>here</a>.</p>";
		if ((strpos($_GET['b'], 'mbug'        ) !== false ) && (strpos($_GET['b'], 'mbug/'        ) == false )) return "<p style='text-align: center'>The Microbee User Group software distribution disks. To browse individual archives in this collection, see <a href='ftp.php?b=cpm/Software/Humongous/Collctns/MBUG/'>here</a>.</p>";
		if  (strpos($_GET['b'], 'ls200/vol226') !== false )                                                     return "<p style='text-align: center'>Most of the files from this volume are missing. They may be found <a href='ftp.php?b=cpm%2FSoftware%2FHumongous%2FSIGM%2Fv226'>here</a>.</p>" ;
		if  (stripos($_GET['b'], 'tel/sigm'   ) !== false )                                                     return "<p style='text-align: center'>The SIG/M (Special Interest Group CP/M) software distribution disks. Vols. 184-192 and portions of 216 are missing. Find them <a href='ftp.php?b=cpm/Software/Humongous/Collctns/SIGM'>here</a>.</p>" ;
		if ((strpos($_GET['b'], '/simtel'     ) !== false ) && (strpos($_GET['b'], '/simtel/'     ) == false )) return "<p style='text-align: center'>Keith Peterson's (KPETERSEN@Simtel20.ARPA) SIMTEL-20 Archives, featuring <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fcpmug'>CPMUG</a> and <a href='ftp.php?b=cpm%2FSoftware%2FWalnutCD%2Fsimtel%2Fsigm'>SIG/M</a>."; # Display in .../simtel but not any child dirs.
		}

	function getDescriptionFile() { # Returns the path/name of the description file along with the column of the start of the description on each line in that file.
		if (stripos($_GET['b'], 'm/vol')     !== false ) 
		 { # WalnutCD's SIGM description files are inconsistently named; must check for all of these possibilities.
		   $f=$_GET['b']. '/catalog.'.substr($_GET['b'], -3, 3); if (file_exists($f)) return array($f, 34);
		   $f=$_GET['b'].'/-catalog.'.substr($_GET['b'], -3, 3); if (file_exists($f)) return array($f, 34);
		   $f=$_GET['b'].'/0catalog.'.substr($_GET['b'], -3, 3); if (file_exists($f)) return array($f, 34);
		   $f=$_GET['b']. '/CATALOG.'.substr($_GET['b'], -3, 3); if (file_exists($f)) return array($f, 34);
		   $f=$_GET['b'].'/-CATALOG.'.substr($_GET['b'], -3, 3); if (file_exists($f)) return array($f, 34);
		   $f=$_GET['b'].'/0CATALOG.'.substr($_GET['b'], -3, 3); if (file_exists($f)) return array($f, 34);
		   }
#		echo $_GET['b'].'<br/>'; # Enable this for debugging

#       if path-to-current-working-dir has this string                        then                      descript file is       cwd         +      relpath+filename                                    ; return descript file and starting col of description                                                                                                                         
#                                                                                                                                                                                                                                                                                                                                                                                  
		if (stripos($_GET['b'], 's/FOG/'         ) !== false )                                                     { $f=       $_GET['b']         .'/../filelist.txt'                                 ; if (file_exists($f)) return array($f, 33); }	# UserGroups/FOG
		if (stripos($_GET['b'], 's/CPMUG/'       ) !== false )                                                     { $f=       $_GET['b']         .'/../00-index.txt'                                 ; if (file_exists($f)) return array($f, 33); }	# UserGroups/CPMUG
		if (stripos($_GET['b'], 's/EBMMUG/'      ) !== false )                                                     { $f=       $_GET['b']         .'/00-index.txt'                                    ; if (file_exists($f)) return array($f, 33); }	# UserGroups/EBMMUG
		if (stripos($_GET['b'], 's/MBUG/'        ) !== false )                                                     { $f=       $_GET['b']         .'/../00-index.txt'                                 ; if (file_exists($f)) return array($f, 35); }	# UserGroups/MBUG
		if (stripos($_GET['b'], 's/SIGM/'        ) !== false )                                                     { $f=       $_GET['b']         .'/../00-index.txt'                                 ; if (file_exists($f)) return array($f, 33); }	# UserGroups/SIGM
#		if (stripos($_GET['b'], '0/vol'          ) !== false )                                                     { $f=       $_GET['b']         .'/0catalog.'.substr($_GET['b'], -3, 3)             ; if (file_exists($f)) return array($f, 34); }	# OAK SIGM's lowest-level, individual vol dir uses 0catalog.xxx
		if ((strpos($_GET['b'], 'sigm/vols000'   ) !== false ) && (strpos($_GET['b'], 'sigm/vols000/') == false )) { $f=                            'cpm/Software/sigmindx.txt'                       ; if (file_exists($f)) return array($f, 33); }	# Note first strpos test string has no trailing backslash, 2nd does; means "Are we in the dir itself, not a dir below it?"
		if ((strpos($_GET['b'], 'sigm/vols100'   ) !== false ) && (strpos($_GET['b'], 'sigm/vols100/') == false )) { $f=                            'cpm/Software/sigmindx.txt'                       ; if (file_exists($f)) return array($f, 33); }	# 
		if ((strpos($_GET['b'], 'sigm/vols200'   ) !== false ) && (strpos($_GET['b'], 'sigm/vols200/') == false )) { $f=                            'cpm/Software/sigmindx.txt'                       ; if (file_exists($f)) return array($f, 33); }	# 
		if ((strpos($_GET['b'], 'sigm/vols300'   ) !== false ) && (strpos($_GET['b'], 'sigm/vols300/') == false )) { $f=                            'cpm/Software/sigmindx.txt'                       ; if (file_exists($f)) return array($f, 33); }	# 
		if ((strpos($_GET['b'], '/sigm'          ) !== false ) && (strpos($_GET['b'], '/sigm/'       ) == false )) { $f=                            'cpm/Software/sigmindx.txt'                       ; if (file_exists($f)) return array($f, 33); }	# 
#		if  (stripos($_GET['b'], 'tel/sigm/'     ) !== false )                                                     { $f=substr($_GET['b'], 0, -15 ).'/sigm'.(substr($_GET['b'], -3, 1) + 1).'.idx'    ; if (file_exists($f)) return array($f,  0); }	# WalnutCD's SIG/M; use SIGMx.IDX; strip last 15 chars from path; use SIGMx.IDX, where "x" is +1 of volume hundreds digit; trailing slash in stripos match ensure we don't process the SIGM dir itself, where we want to use 00-index.txt instead. SIGMx.IDX is CSV, so startpos isn't used; just return 0.
		if  (stripos($_GET['b'], '/rlee/'        ) !== false )                                                     { $f=       $_GET['b']          .'/../00-index.txt'                                ; if (file_exists($f)) return array($f, 33); }	# 
		if  (stripos($_GET['b'], '/LOOSECPM/'    ) !== false )                                                     { $f=       $_GET['b']          .'/../00-index.txt'                                ; if (file_exists($f)) return array($f, 50); }	# 
#		if  (stripos($_GET['b'], 'ollctns/MBUG/' ) !== false )                                                     { $f=       $_GET['b']          .'/../00-index.txt'                                ; if (file_exists($f)) return array($f, 37); }	# 
#		if  (stripos($_GET['b'], 'ollctns/CPMUG/') !== false )                                                     { $f=       $_GET['b']          .'/../00-index.txt'                                ; if (file_exists($f)) return array($f, 33); }	# 
#		if  (stripos($_GET['b'], 'ollctns/CPMUG/') !== false )                                                     { $f=                            '../00-index.txt'                                 ; if (file_exists($f)) return array($f,  0); }	# WalnutCD's SIG/M; use SIGMx.IDX; strip last 15 chars from path; use SIGMx.IDX, where "x" is +1 of volume hundreds digit; trailing slash in stripos match ensure we don't process the SIGM dir itself, where we want to use 00-index.txt instead. SIGMx.IDX is CSV, so startpos isn't used; just return 0.
		if  (stripos($_GET['b'], 'pub/sigm/'     ) !== false )                                                     { $f=substr($_GET['b'], 0,  -7 ).'/sigm'.(substr($_GET['b'], -3, 1) + 1).'-fi.idx' ; if (file_exists($f)) return array($f,  0); }	# OAK's rather than WalnutCD's SIG/M: strip last 7 chars from path
		if  (stripos($_GET['b'], 'emon.com/'     ) !== false )                                                     { $f=       $_GET['b']          .'/00INDEX'                                        ; if (file_exists($f)) return array($f, 21); }	# demon.com collection
		if  (stripos($_GET['b'], 'pub/cpmug'     ) !== false )                                                     { $f=       $_GET['b']          .'/cpmug-fi.idx'                                   ; if (file_exists($f)) return array($f, 50); }	# OAK's CPMUG collection, use cpmug-fi.idx
		if  (stripos($_GET['b'],  'pub/cpm/'     ) !== false )                                                     { $f=       $_GET['b']          .'/00-index.txt'                                   ; if (file_exists($f)) return array($f, 31); }	# OAK's CPM collection, subdirs use local 00-index.txt
		if  (stripos($_GET['b'],   'pub/cpm'     ) !== false )                                                     { $f=                            'cpm/Software/WalnutCD/cpm/00-index.txt'          ; if (file_exists($f)) return array($f, 31); }	# OAK's CPM collection, root dir uses 00-index.txt in WalnutCD's CPM/
		if  (stripos($_GET['b'],     'rlee/'     ) !== false )                                                     { $f=                            'cpm/Software/rlee/00-index.txt'                  ; if (file_exists($f)) return array($f, 33); }	# RLee collection use rlee/00-index.txt
		if  (stripos($_GET['b'], 'CPM_DOSGG'     ) !== false )                                                     { $f=                            'cpm/Software/cpmdosgg.txt'                       ; if (file_exists($f)) return array($f, 33); }	# RLee collection use rlee/00-index.txt
#		if  (stripos($_GET['b'], 'WalnutCD/'     ) !== false )                                                     { $f=                            'cpm/Software/WalnutCD/00-index.txt'              ; if (file_exists($f)) return array($f, 34); }	# Child dirs of WalnutCD/
		                                                                                                           { $f=       $_GET['b']          .'/dirs.txt'                                       ; if (file_exists($f)) return array($f, 33); }	# These two lines should be last as they're the defaults
		                                                                                                           { $f=       $_GET['b']          .'/00-index.txt'                                   ; if (file_exists($f)) return array($f, 33); }	# Look for "00-index.txt" in cur dir, return if found
		return array('No description file found', 0);	# if nothing found
		}

	function getDescription($searchterm,$descriptionfile,$startingposition) { #Parses $descriptionfile for $searchterm (the file name whose description we want) then extracts the tail of the line beginning at $startingposition
	      if (stripos($_GET['b'], 'trs80') !== false )         return '';				  # On the TRS80 side we want null returned; this causes the description column to collapse to 0, leaving max room for the long filenames there.
	      if ($descriptionfile == 'No description file found') return '&nbsp;';                       # There is no description file, so just return empty.
	      if ($searchterm == '..')                             return 'Parent dir';                   # Label the double-dot.
#	      if (stripos($descriptionfile, '/rlee') !== false ) { $searchterm=$searchterm.'    '; }      # In the rlee dir, directory names are just a single letter; pad with spaces to prevent everything matching 
	      $dfile=file($descriptionfile); $s='/\b'.$searchterm.'\b/i';				# Complete-word, case-insensitive search for $searchterm 
	      foreach($dfile as $line_num => $currentline) 
	       {
	#	$c=substr($currentline,0,$startingposition);						# Want to search only the first part of the line, not the description part
	#	if (preg_match($s, $c) == "1" ) 
	        $c=substr($currentline,0,$startingposition); $c = str_replace(' ', '', $c); 						# Want to search only the first part of the line, not the description part
		if (stripos($c, $searchterm) !== false ) 
		  {
		    if (stripos($currentline, 'No description available') == true )   return '&nbsp;';	# Decluttering: if description says "No description available" or ...
		    if (strlen($currentline) < ($startingposition + 3))               return '&nbsp;';	# ... line too short to to contain a description (+3 for cr/lf)
		    if (stripos($descriptionfile, 'sigm/s'   ) !== false ) return str_replace('"','',substr($currentline,strripos($currentline, '"', -3)));	# Get tail of $currentline beginning at 2nd-to-last quotation mark (-3 skips very last), strip all '"'
		    if (stripos($descriptionfile, 'pub/cpmug') !== false ) return str_replace('"','',substr($currentline,strripos($currentline, '"', -3)));	# Get tail of $currentline beginning at 2nd-to-last quotation mark (-3 skips very last), strip all '"'
		    return substr($currentline, $startingposition).'&nbsp;';					# Default if none of the above. Postpend &nbsp; in case description is null to prevent description column from collapsing and forcing file sizes to the right.
		  } # if preg_match
	       } # foreach loop
	      return '&nbsp;';
	}

	function breadcrumb() {
          $p=explode('/',$_GET['b']); $bc=''; $bc1='';
          for ($i = 0; $i <= count($p)-1; $i++) {
            $bc1=$bc1.$p[$i].'/';
            $bc=$bc.'<a style="background: #060" href="ftp.php?b='.$bc1.'">'.$p[$i].'</a>/';		# <h1> styling doesn't reach in here for whatever reason, so I have to force it.
          }
          return $bc;	  
	}
        
?>

<!DOCTYPE HTML>
<html lang="en-US">
<head>
  <meta charset="UTF-8">
  <meta name="robots" content="<?php echo htmlentities($robots) ?>">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title><?php echo htmlentities(getTitle($title)) ?></title>
	
  <style type="text/css">

	* { margin: 0; padding: 0; border: none; }

	body {
	font-family: computer1, courier new, LucidaTerminal, monospace;
	color: #0f0;
	background-color:#000; 
	text-align: left;
	font-size: 12pt; 	/* Dunno why but this ends up controlling the line spacing w/o changing the actual font size */	
	/*	text-align: center;
	font-family: sans-serif;
	font-size: 13px;
	color: #000000;
	*/}

	a, a:visited {   
        /* color:#0a4 
	color: yellow;
        border-bottom: solid 1px #0f0;
        text-decoration: none;
        text-decoration: underline; 
        text-transform: uppercase;
        font-weight: bold; */
        text-decoration: none;
        padding-bottom: 2px;
        /* border-bottom: dashed 1px; */
	color: #0f0;
	background-color:#000; 
	font-weight: bold;
        line-height: 100%;
	}

	a:hover { /* inherit everything from a -- just reverse colors */
        border-color: #0f0;
        background-color:#0f0;
        color: #000;
        }

	#wrapper {
	max-width: 800px;
	*width: 800px;
	margin: 0 auto;
	text-align: left;
	}
		
	body#left { text-align: left; }

	body#left #wrapper { margin: 0 20px; }
		
	h1 {
	font-size: 21px;
	padding: 3px 10px;                      /* 3px top-bottom padding prevents the breadcrumb from spilling out */
	margin: 20px 0 0;
	font-weight: bold;
	background: #060;
	color: #ff0;
	text-shadow: 2px 2px #222;
	border-radius: 6px;
	box-shadow:                              /* This provides the beveled effect */
	  0 1px 2px #444,                        /*bottom external highlight*/
	  0 -1px 1px #444,                       /*top external shadow*/ 
	  inset 0 -1px 1px rgba(0,0,0,0.5),      /*bottom internal shadow*/ 
	  inset 0 1px 1px rgba(255,255,255,0.8); /*top internal highlight*/
	}
		
	h2 {                             /* xxx objects in this folder, xx.x GB total */
	font-size: 14px;
	padding: 0 10px;
	margin: 10px 0 0;
	color: #999999;
	font-weight: normal;
	}

	a { text-decoration: none; }
		
	ul#header {	
	margin-top: 20px;
	background: #000;
	color: #0f0;
	}
		
	ul li {
	display: block;
	list-style-type: none;
	overflow: hidden;
	padding: 1px;
	}
		
	ul li:hover {
	/* background-color: #f3f3f3;
	background-color: #0f0;
	color: #000; */
	}
		
	ul li .date {
	text-align: left;
	width: 520px;
	font-size: 16px;
	padding-left: 10px;
	}
		
	ul li .size {
	text-align: right;
	width: 90px;
	font-size: 12px;
	}
		
	ul li .date, ul li .size { /* "Last modified" and "Size" columns */
	float: right;
	display: block;
/*	color: #666666;
*/	color: #cccccc;
	}
		
	ul#header li {
	font-size: 11px;
	font-weight: bold;
	/* border-bottom: 1px solid #cccccc; */
	}

	ul#header li:hover { background-color: transparent; }
		
	ul#header li * {                     /* "Name - Last modified - size" line */
	color: #000000;
	font-size: 14px;
	background: #000; color: #0F0;
	}

	ul#header li a:hover { /* color: #666666; */ color: #cccccc; }

	ul#header li .asc span, ul#header li .desc span {
	padding-right: 15px;
	background-position: right center;
	background-repeat: no-repeat;
	}

	ul#header li .asc span { background-image: url('<?php echo $_self ?>?i=asc'); }

	ul#header li .desc span { background-image: url('<?php echo $_self ?>?i=desc'); }

	ul li.item { /* border-top: 1px solid #f3f3f3; */ }

	ul li.item:first-child { border-top: none; }
		
	ul li.item .name {
	/* color: #003399; */
	color: #0f0;
	font-weight: bold;
	}
		
	ul li.item .name:hover {
	/* color: #0066cc; */
	color: #000;
	background: #0f0;
	}

	ul li.item a:hover { /* text-decoration: underline; */ }
		
	ul li.item .directory, ul li.item .file { /* Text of items, name column only */
	padding-left: 20px;
	background-position: left center;
	background-repeat: no-repeat;
	font-size: 18px;
	}

	ul li.item .directory { background-image: url('<?php echo $_self ?>?i=directory'); }
		
	ul li.item .file {
	background-image: url('<?php echo $_self ?>?i=file');
	font-weight: normal;
	}
		
	#footer {
	font-size: 11px; text-shadow: 1px 1px #000;
	margin-top: 40px;
	margin-bottom: 20px;
	padding: 0 10px;
	clear:both; 
	border-radius: 6px;
	box-shadow:                              /* This provides the beveled effect */
	  0 1px 2px #444,                        /*bottom external highlight*/
	  0 -1px 1px #444,                       /*top external shadow*/ 
	  inset 0 -1px 1px rgba(0,0,0,0.5),      /*bottom internal shadow*/ 
	  inset 0 1px 1px rgba(255,255,255,0.8); /*top internal highlight*/
	text-align: center;
	background:#000; 
	/*background-color:#00a040;  */
	background: #060;
	color:#FFFFFF; 
	}

	#footer a { color: #cccccc; font-weight: bold; }

	#footer a:hover { color: #999999; }
		
  </style>
</head>

<body <?php if ($alignment == 'left') echo 'id="left"' ?>>

  <div id="wrapper">
    <h1><?php echo breadcrumb(); ?></h1> <!-- Show the breadcrumb at the top -->
    <?php echo message(); ?>             <!-- Display a message for the current directory; see function message() -->
    <ul id="header">
      <li>
      <a href="<?php echo buildLink(array('s' => 'time', 'r' => (!$_sort_reverse && $_sort == 'time') ? '1' : null)) ?>" class="date <?php if ($_sort == 'time') echo $_sort_reverse ? 'desc' : 'asc' ?>"><span>Description</span></a>
      <a href="<?php echo buildLink(array('s' => 'size', 'r' => (!$_sort_reverse && $_sort == 'size') ? '1' : null)) ?>" class="size <?php if ($_sort == 'size') echo $_sort_reverse ? 'desc' : 'asc' ?>"><span>Size</span></a>
      <a href="<?php echo buildLink(array('s' =>  null , 'r' => (!$_sort_reverse && $_sort == 'name') ? '1' : null)) ?>" class="name <?php if ($_sort == 'name') echo $_sort_reverse ? 'desc' : 'asc' ?>"><span>Name</span></a>
      </li>
    </ul> <!-- header -->

    <ul>
	<?php list($DescFile, $StartPos) = getDescriptionFile(); ?> <!-- Name of description file and starting column of description passed back; list parses values into separate vars -->
        <?php foreach ($items as $item): ?>
	<li class="item">
	  <span class="date"><?php echo getDescription($item['name'],$DescFile,$StartPos); ?></span>
<!--	  <span class="date">< ?php echo (@$item['isparent'] || empty($item['time'])) ? '-' : date($dateFormat, $item['time']) ?></span>
-->	  <span class="size"><?php echo $item['isdir'] ? '[DIR]' : humanizeFilesize($item['size'], $sizeDecimals) ?></span>
	  <?php
	    if ($item['isdir'] && $browseDirectories && !@$item['isparent']) {
	      if ($item['name'] == '..') { $itemURL = buildLink(array('b' => substr($_browse, 0, strrpos($_browse, '/')))); } 
	        else { $itemURL = buildLink(array('b' => (empty($_browse) ? '' : (string)$_browse . '/') . $item['name']));}
	      } 
	     else { $itemURL = (empty($_browse) ? '' : (string)$_browse . '/') . $item['name']; }
	  ?>
	  <a href="<?php echo htmlentities($itemURL) ?>" class="name <?php if ($showIcons) echo $item['isdir'] ? 'directory' : 'file' ?>"><?php echo htmlentities($item['name']) . ($item['isdir'] ? ' /' : '') ?></a>
    	</li>

      <?php endforeach; ?>
    </ul>

    <h2><?php echo htmlentities(getTitle($subtitle)) ?></h2>

    <?php if ($showFooter): ?><p id="footer">Powered by <a href="https://github.com/lorenzos/Minixed" target="_blank">Minixed</a>, a PHP directory indexer</p><?php endif; ?>
    <?php include $sitefooter; ?>

  </div> <!-- wrapper -->

</body>
</html>
