<?php
  	//$regexp = "/^[^0-9][A-z0-9_-]+([.][A-z0-9_]+)*[@][A-z0-9_-]+([.][A-z0-9_-]+)*[.][A-z]{2,6}$/";
	$regexp = "/^[a-zA-Z0-9_.-]+[@][A-z0-9_-]+([.][A-z0-9_-]+)*[.][A-z]{2,6}$/";
	$bool = "0";
	if(isset($_POST[Download]))
	{
	  $bool = "1";
	  if(empty($_POST[Name]))
	  {
		$bool = "0";
	  }
	  if(!preg_match($regexp, $_POST[Email]))
	  {
		$bool = "0";
	  }
	  if(empty($_POST[Affiliation]))
	  {
		$bool = "0";
	  }
	}
	if($bool)
	{
	  $text = $_POST[Name]."\n".$_POST[Email]."\n".$_POST[Affiliation]."\n".$_POST[Hear]."\n".$_POST[Version];
	  //We really don't want to be informed about downloads anymore.
	  //mail("dennis.guck@rwth-aachen.de","IMCA download",$text);
		$info = "Dear ".$_POST[Name].",\n\n thank you for downloading IMCA.\n\n For more recent versions, please visit https://github.com/buschko/imca \n\n Best regards,\n Dennis Guck";
		mail($_POST[Email],"IMCA download",$info);
	  header('Content-type: application/zip');
	  $ver=$_POST[Version];
	  if($ver=="1.6")
			{
				header('Content-Disposition: attachment; filename="imca_1.6_beta.zip"');
				readfile('imca_1.6_beta.zip');
			}
		if($ver=="1.5.1")
	  {
	  	header('Content-Disposition: attachment; filename="imca_1.5.1_beta.zip"');
	  	readfile('imca_1.5.1_beta.zip');
	  }
      if($ver=="1.5")
	  {
	  	header('Content-Disposition: attachment; filename="imca_1.5_beta.zip"');
	  	readfile('imca_1.5_beta.zip');
	  }
	  if($ver=="1.4.1")
	  {
	  	header('Content-Disposition: attachment; filename="imca_1.4_beta_examples.zip"');
	  	readfile('imca_1.4_beta_examples.zip');
	  }
	  else if($ver=="1.4")
	  {
	  	header('Content-Disposition: attachment; filename="imca_1.4_beta.zip"');
	  	readfile('imca_1.4_beta.zip');
	  }
	  else if($ver=="1.3")
	  {
	  	header('Content-Disposition: attachment; filename="imca_1.3_beta.zip"');
	  	readfile('imca_1.3_beta.zip');
	  }
	  else if($ver=="1.2")
	  {
	  	header('Content-Disposition: attachment; filename="imca_1.2_beta.zip"');
	  	readfile('imca_1.2_beta.zip');
	  }
	  else
	  {
	  	header('Content-Disposition: attachment; filename="imca_1.1.zip"');
	  	readfile('imca_1.1.zip');
	  }
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IMC Analyzer - Download</title>
<link rel="stylesheet" type="text/css" href="common.css" />
<!--[if lte IE 7]>
<style>
.content { margin-right: -1px; }
ul.nav a { zoom: 1; }
</style>
<![endif]-->
</head>

<body>

<div class="container">
  <div class="header"><a href="index.html"><img src="logo.png" alt="IMCA" name="logo" width="250" height="99" id="logo" style="background: #6F7D94; display:block;" /></a>
    <!-- end .header --></div>
  <div class="sidebar1">
    <ul class="nav">
      <li><a href="index.html">Home</a></li>
      <li><a href="docu.html">Documentation</a></li>
      <li><a href="case_studies.html">Case Studies</a></li>
      <li><a href="download.php"><font color="white">Download</font></a></li>
      <li><a href="contact.html">Contact</a></li>
    </ul>
    <h4>Info</h4>
    <p><font size="2">The IMCA tool is written in C++. It compiles on Linux systems, if all needed libraries are available. It was also testetd succesfully under Mac OSX and Windows with cygwin.</font></p>
    <!-- end .sidebar1 --></div>
  <div class="content">
    <h1>Download</h1>
    <p>Please fill in <b>all</b> fields below.</p>
    <p>
	<?php
	  $regexp = "/^[^0-9][A-z0-9_-]+([.][A-z0-9_]+)*[@][A-z0-9_-]+([.][A-z0-9_-]+)*[.][A-z]{2,4}$/";
	  if(isset($_POST[Download]))
	  {
		$bool = "1";
		echo "<font color=\"red\"><ul>";
		if(empty($_POST[Name]))
		{
		  echo "<li>Please enter a valid name.</li>";
		}
	    if(!preg_match($regexp, $_POST[Email]))
		{
	      echo "<li>Please enter a valid email address.</li>";
		}
		if(empty($_POST[Affiliation]))
		{
		  echo "<li>Please enter a valid affiliation.</li>";
		}
	  echo "</ul></font>";
	  }
    ?>
    </p>
    <form method="post" action="download.php">
    	<table>
          <tr>
          	<td style="padding-left:12px;"><b>Version</b></td>
            <td style="padding-left:6px;">
              <select name="Version">
				<option value="1.6">1.6 beta</option>
				<option value="1.5.1">1.5.1 beta</option>
				<option value="1.5">1.5 beta</option>
				<option value="1.4.1">1.4 beta with examples</option>
				<option value="1.4">1.4 beta</option>
              	<option value="1.3">1.3 beta</option>
              	<option value="1.2">1.2 beta</option>
                <option value="1.1">1.1</option>
              </select>
            </td>
          </tr>

          <tr>
          	<td style="padding-left:12px;"><b>Distribution</b></td>
            <td style="padding-left:6px;">
              <select name="Distribution">
                <option value="Source">Source</option>
              </select>
            </td>
          </tr>

          <tr>
          	<td style="padding-left:12px;"><b>Name</b></td>
            <td style="padding-left:6px;">
              <input name="Name" size="30" maxlength="50" value="<?php echo $_POST[Name]; ?>"/>
              <i>e.g. John Doe</i>
            </td>
          </tr>

          <tr>
          	<td style="padding-left:12px;"><b>Email address</b></td>
            <td style="padding-left:6px;">
              <input name="Email" size="30" maxlength="50" value="<?php echo $_POST[Email]; ?>"/>
              <i>e.g. John.Doe@rwth-aachen.de</i>
            </td>
          </tr>

          <tr>
          	<td style="padding-left:12px;"><b>Affiliation</b></td>
            <td style="padding-left:6px;">
              <input name="Affiliation" size="30" maxlength="50" value="<?php echo $_POST[Affiliation]; ?>"/>
              <i>e.g. RWTH Aachen</i>
            </td>
          </tr>
        </table>
      <p>
      <b>Where did you hear about IMCA?</b>
      <select name="Hear">
        <option value="_">--------</option><option value="publication">Publication</option><option value="mouth">Word of mouth</option><option value="other">Other</option>
      </select>
      </p>
      <p>
	  <input type="submit" name="Download" value="Download" style="width: 100px; height: 30px; background-color: blue; font-weight: 900; color: white"/>
	  <input type="reset" name="Clear" value="Clear"/  style="width: 100px; height: 30px; background-color: blue; font-weight: 900; color: white"/>
	  </p>
    </form>
    <!-- end .content --></div>
  <div class="sidebar2">
    <h2>News</h2>
		<h3>10.07.2014</h3>
		<p>IMCA 1.6 beta available. Includes full support of Markov automata with rewards.</p>
		<p>More recent versions available at <a href="https://github.com/buschko/imca">github</a>!</p>
	<h3>08.03.2013</h3>
	<p>IMCA 1.5 beta update available. Includes bcg2imca translator and an interval step output for time-bounded reachability.</p>
	<h3>14.02.2013</h3>
	<p>IMCA 1.5 beta available. Changes in MEC decomposition for long-run average computation, small bugfixes and new examples.</p>
	<h3>08.11.2012</h3>
	<p>IMCA 1.4 beta available. Bugfixes and extension with time- and step-bounded reachability for Markov automata.</p>
    <h3>29.03.2012</h3>
    <p>IMCA 1.3 beta available as command-line tool. Usage of the <a href="http://soplex.zib.de/" target="_blank">SoPlex library</a> and Markov Automata support. Functionality reduction to unbounded reachability, expected-time and long-run average. Full functionality will follow.</p>
    <h3>05.01.2012</h3>
    <p>IMCA 1.2 beta available, including LP Solve library and LRA computation.</p>
    <h3>20.01.2011</h3>
    <p>Update of the IMCA tool to version 1.1.</p>
    <h3>10.10.2010</h3>
    <p>First release of the IMCA tool.</p>
  <!-- end .sidebar2 --></div>
  <div class="footer">
    <!-- end .footer --></div>
  <!-- end .container --></div>
</body>
</html>
