<?php
require("konf.php");
mysql_connect($mysql_host, $mysql_user, $mysql_password);
mysql_select_db($db);
?>
<html>
<head>
  <title>Putukate andmebaas</title>
	<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
	<table width="100%">
		<caption>Putukate andmebaas</caption>
  	<tr>
    	<td width="100%" align="center">
				<a href="#" onclick="javascript:window.open('edit_bug.php?id=-1',null,'height=250,width=400,left=50,top=50,status=no,toolbar=no,menubar=no,location=no');" title="Lisa uus putukas">Lisa uus sisestus</a>
				&nbsp;<a href="search.php">Otsing</a>
      </td>
    </tr>
  </table>
	<table width="100%">
  	<tr>
    	<td width="100%" align="center">
      	<table>
<?php
	$lae = mysql_query("SELECT id, liik, aeg FROM bugs ORDER BY aeg DESC");
  while($row = mysql_fetch_array($lae)){
	  $row[2] = substr($row[2], 6, 2)."/".substr($row[2], 4, 2)."/".substr($row[2], 0, 4)."&nbsp;".substr($row[2], -4, 2).":".substr($row[2], -2);
    $MASS[$row[0]] = array('id' => $row[0], 'liik' => $row[1], 'aeg' => $row[2]);
	}
  foreach($MASS as $m){
?>
        	<tr>
          	<td>
            	<?php echo $m[liik]; ?>&nbsp;(<?php echo $m[aeg]; ?>)
            </td>
          	<td width="120" align="right">
              <a href="#" onclick="javascript:window.open('edit_bug.php?id=<?php echo $m[id] ?>',null,'height=250,width=400,left=50,top=50,status=no,toolbar=no,menubar=no,location=no');" title="Muuda andmeid">
            		Muuda andmeid
              </a>
            </td>
          </tr>
<?php
	}
?>
        </table>
			</td>
    </tr>
  </table>
</body>
</html>