<html><head>
<link rel="stylesheet" href="style.css">
<title>Eclipse Dirigible Downloads</title></head>
<body>
	<table style="background-color: #444; width: 100%; height: 105px;">
		<tr>
			<td style="width: 150px; padding-left: 10px"><img src="http://download.eclipse.org/dirigible/dirigible.png" height="86"/></td>
			<td><font class=indextop>Eclipse Dirigible Downloads</font><br/>
			<font class=indexsub>latest downloads from the Eclipse Dirigible project</font></td>
		</tr>
	</table>
	<br/>
	<table width="100%" cellspacing=0 cellpadding=3 align=center>
		<!-- The Eclipse Projects --> 
<td align=LEFT valign=TOP colspan="2" bgcolor="#444"><b><font color="#FFFFFF" face="Arial,Helvetica">Latest 
Downloads</font></b></td></tr> <!-- The Eclipse Projects --> <tr> <td>
		<tr><td> 
			<p>On this page you can find the latest Dirigible builds.</p>
			<?php
				$lastLabel="";
				if (file_exists('build.label')) {
					$lastLabel=file_get_contents('build.label');
				}
				if ($lastLabel != "") {
					echo "<p>Build <a href=\"drops/$lastLabel/index.html\">$lastLabel</a> was started on the <a href=\"http://dirigible.eclipse.org/\">test server</a> and Docs are <a href=\"http://help.dirigible.io/\">here</a>.";
				}
			?>
			<p>All downloads are provided under the terms and conditions of the <a href="http://www.eclipse.org/legal/epl/notice.php" target="_top">Eclipse Foundation Software User Agreement</a> unless otherwise specified.</p>
			<p>Old Dirigible builds are available from <a href="http://archive.eclipse.org/dirigible">archive.eclipse.org</a>. Other <B>eclipse.org project</B> downloads are available <A HREF="http://www.eclipse.org/downloads/index.php">here</A>.</p>
		</td></tr> 
	</table>
	
	<?php
	$contents = substr(file_get_contents('dlconfig.txt'),0,-1);
	$contents = str_replace("\n", "", $contents);

	#split the content file by & and fill the arrays
	$elements = explode("&",$contents);
	$t = 0; 
	$p = 0;
	for ($c = 0; $c < count($elements)-1; $c++) {
		$tString = "dropType";
		$pString = "dropPrefix";
		if (strstr($elements[$c],$tString)) {
			$temp = preg_split("/=/",$elements[$c]);
			$dropType[$t] = $temp[1];
			$t++;
		}
		if (strstr($elements[$c],$pString)) {
			$temp = preg_split("/=/",$elements[$c]);
			$dropPrefix[$p] = $temp[1];
			$p++;
		}
	}
	
	for ($i = 0; $i < count($dropType); $i++) {
		$typeToPrefix[$dropType[$i]] = $dropPrefix[$i];
	}
		
	$aDirectory = dir("drops");
	while ($anEntry = $aDirectory->read()) {
	
		// Short cut because we know aDirectory only contains other directories.
	
		if ($anEntry != "." && $anEntry!=".." && $anEntry!="TIME" && $anEntry!="promote.sh") {
			$parts = explode("-", $anEntry);
			if (count($parts) == 3) {
	
				$buckets[$parts[0]][] = $anEntry;
		
				$timePart = $parts[2];
				$year = substr($timePart, 0, 4);
				$month = substr($timePart, 4, 2);
				$day = substr($timePart, 6, 2);
				$hour = substr($timePart,8,2);
				$minute = substr($timePart,10,2);
				$timeStamp = mktime($hour, $minute, 0, $month, $day, $year);
				$timeStamps[$anEntry] = date("D, j M Y -- H:i (O)", $timeStamp);
				if (! isset($latestTimeStamp) || ! isset($latestTimeStamp[$parts[0]]) || $timeStamp > $latestTimeStamp[$parts[0]]) {
					$latestTimeStamp[$parts[0]] = $timeStamp;
					$latestFile[$parts[0]] = $anEntry;
				}
			}
	
			if (count($parts) == 2) {
	
				$buildType=substr($parts[0],0,1);
				$buckets[$buildType][] = $anEntry;
				$datePart = substr($parts[0],1);
				$timePart = $parts[1];
				$year = substr($datePart, 0, 4);
				$month = substr($datePart, 4, 2);
				$day = substr($datePart, 6, 2);
				$hour = substr($timePart,0,2);
				$minute = substr($timePart,2,2);
				$timeStamp = mktime($hour, $minute, 0, $month, $day, $year);
				$timeStamps[$anEntry] = date("D, j M Y -- H:i (O)", $timeStamp);
                        	if (! isset($latestTimeStamp) || ! isset($latestTimeStamp[$buildType]) || $timeStamp > $latestTimeStamp[$buildType]) {
					$latestTimeStamp[$buildType] = $timeStamp;
					$latestFile[$buildType] = $anEntry;
				}
			}

			if (count($parts) == 1) {
				$buildType=substr($parts[0],0,1);
				$buckets[$buildType][] = $anEntry;
				$datePart = substr($parts[0],1, 8);
				$timePart = substr($parts[0],9,12);
				$year = substr($datePart, 0, 4);
				$month = substr($datePart, 4, 2);
				$day = substr($datePart, 6, 2);
				$hour = substr($timePart,0,2);
				$minute = substr($timePart,2,2);
				$timeStamp = mktime($hour, $minute, 0, $month, $day, $year);
				$timeStamps[$anEntry] = date("D, j M Y -- H:i (O)", $timeStamp);
                        	if (! isset($latestTimeStamp) || ! isset($latestTimeStamp[$buildType]) || $timeStamp > $latestTimeStamp[$buildType]) {
					$latestTimeStamp[$buildType] = $timeStamp;
					$latestFile[$buildType] = $anEntry;
				}
			}
		}
	}
 	?> 
 	<table width="100%" cellspacing=0 cellpadding=3 align=center> 
 		<td align=left> 
			<TABLE  width="100%" CELLSPACING=0 CELLPADDING=3> 
				<tr> <td width=\"30%\">
					<b>Build Type</b></td><td><b>Build Name</b></td><td><b>Build Date</b>
				</td></tr> 
				<?php
					foreach($dropType as $value) {
						$prefix=$typeToPrefix[$value];
						if (array_key_exists($prefix, $latestFile)) {
							$fileName = $latestFile[$prefix];
							echo "<tr>
								<td width=\"30%\">$value</td>";
						
							$parts = explode("-", $fileName);
						
							// Uncomment the line below if we need click through licenses.
							// echo "<td><a href=license.php?license=drops/$fileName>$parts[1]</a></td>";
						
							// Comment the line below if we need click through licenses.
							if (count($parts)==3)
								echo "<td><a href=\"drops/$fileName/index.html\">$parts[1]</a></td>";
							if (count($parts)==2 || count($parts)==1)
								echo "<td><a href=\"drops/$fileName/index.html\">$fileName</a></td>";
				
							echo "<td>$timeStamps[$fileName]</td>";
							echo "</tr>";
						}
					}
				?>
			</table>
		</td>
	</table>&nbsp;<?php
		foreach($dropType as $value) {
			$prefix=$typeToPrefix[$value];
			echo "
			<table width=\"100%\" cellspacing=0 cellpadding=3 align=center>
			<tr bgcolor=\"#444\">
			<td align=left width=\"30%\"><b><a name=\"$value ($prefix)\"><font color=\"#FFFFFF\" face=\"Arial,Helvetica\">$value";
			echo "s</font></b></a></td>
			</TR>
			<TR>
			<td align=left>
			<TABLE  width=\"100%\" CELLSPACING=0 CELLPADDING=3>
			<tr>
			<td width=\"30%\"><b>Build Name</b></td>
			<td><b>Build Date</b></td>
			</tr>";
			
			if (array_key_exists($prefix, $buckets)) {
				$aBucket = $buckets[$prefix];
				if (isset($aBucket)) {
					rsort($aBucket);
					foreach($aBucket as $innerValue) {
						$parts = explode("-", $innerValue);
						echo "<tr>";
					
						// Uncomment the line below if we need click through licenses.
						// echo "<td><a href=\"license.php?license=drops/$innerValue\">$parts[1]</a></td>";
						
						// Comment the line below if we need click through licenses.
						if (count ($parts)==3)
							echo "<td><a href=\"drops/$innerValue/index.html\">$parts[1]</a></td>";
						if (count($parts)==2 || count($parts)==1)
							echo "<td><a href=\"drops/$innerValue/index.html\">$innerValue</a></td>";
	
						echo "<td>$timeStamps[$innerValue]</td>
						</tr>";
					}
				}
			}
			echo "</table></table>&nbsp;";
		}
	?> &nbsp; 
</body>
</html>