<?php
function sql($query)
{
  $link = mysql_pconnect("mysql.nehlsen.se", "motion", "alskling")
    or die("Could not connect");
  mysql_select_db("motion")
    or die("Could not select database");
  // Performing SQL query
  $result = mysql_query($query)
    or die("Query $query failed");
  return $result;
}
//$resultat=sql("select DATE_ADD(DATE(DATE_SUB(NOW(), INTERVAL (DAYOFWEEK(NOW())-1) DAY)), INTERVAL 1 DAY) as wstart");
$resultat=sql("select DATE_ADD(DATE(DATE_SUB(NOW(), INTERVAL 8 DAY)), INTERVAL 1 DAY) as wstart");
$w=mysql_fetch_assoc($resultat);
$wstart=$w['wstart'];
$resultat=sql("select DATE_ADD(DATE(DATE_SUB(NOW(), INTERVAL 1 DAY)), INTERVAL 7 DAY) as wend");
$w=mysql_fetch_assoc($resultat);
$wend=$w['wend'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>

<body>
<div id="rubrik" style="position:absolute; left:50px; top:-36px; width:570px; height:136px; z-index:1; visibility: visible;"><a href="index.php"><img src="hemsida/veckanswebb.gif" width="389" height="193" border="0"></a></div>
<div id="dennavecka" style="position:absolute; left:21px; top:105px; width:622px; height:132px; z-index:2; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000; visibility: visible;">
  <table width="963" height="72" border="0" cellspacing="20" bordercolor="#999999">
    <tr>
      <th width="157" scope="col">&nbsp;</th>   
       <?php
         $result=sql("select DAYOFWEEK(datum) as day from steg where user=1 and datum>='" . $wstart . "' and datum<='" . $wend . "' order by datum asc");
           while ($temp=mysql_fetch_assoc($result))
           {
	     echo '<th width="90" scope="col"><img src="hemsida/' . $temp['day'] . '.gif"></th>';
           }
        ?>
      <th width="118" scope="col">&nbsp;</th>
    </tr>
    <tr>
      <th scope="row"><img src="hemsida/mariawebb.gif" width="102" height="44"></th>
      <?php
	 $resultat=sql("select * from users");
	 while ($temp=mysql_fetch_assoc($resultat))
	 {
	   $result=sql("select steg, DAYOFWEEK(datum) as day from steg where user=" . $temp['id'] . " and datum>='" . $wstart . "' and datum<='" . $wend . "' order by datum asc");
	   $steg=0;
	   while ($temp=mysql_fetch_assoc($result))
	   {
	     $dag++;
	     echo "<td><div align='center'>" . $temp['steg'] .  "</div></td>";
	     $steg+=$temp['steg'];
	   }
	   echo '<td><div align="center"><strong>' . $steg . '</strong></div></td>';
	   echo "</tr>";
           echo "<tr>";       
           echo '<th scope="row"><img src="hemsida/mikaelwebb.gif" width="111" height="44"></th>';
	 }
	 ?>
    </tr>
  </table>
</div>
<div id="Layer1" style="position:absolute; left:20px; top:296px; width:82px; height:42px; z-index:5; visibility: visible;"><img src="hemsida/streckwebb.gif" width="712" height="126"></div>
<div id="historik" style="position:absolute; left:374px; top:436px; width:58px; height:55px; z-index:7; visibility: visible;"><a href="stegraknare3.php"><img src="hemsida/historywebb.gif" width="148" height="68" border="0"></a></div>
<div id="cirekl" style="position:absolute; left:332px; top:386px; width:25px; height:34px; z-index:6; visibility: visible;"><img src="hemsida/cirektlwebb.gif" width="256" height="154"></div>
<div id="Layer2" style="position:absolute; left:61px; top:432px; width:102px; height:74px; z-index:8">
  <table width="200" border="0">
    <tr>
      <td><img src="hemsida/mariawebb.gif" width="102" height="44"></td>
      <td><img src="hemsida/mikaelwebb.gif" width="111" height="44"></td>
    </tr>
    <tr>
      <?php
	 $resultat=sql("select * from users");
	 while ($temp=mysql_fetch_assoc($resultat))
	 {
	   $result=sql("select sum(steg) as steg from steg where user=" . $temp['id']);
	   $steg=mysql_fetch_assoc($result);
	   echo "<td><div align='center'>" . $steg['steg'] . "</div></td>";
	 }
	 ?>
    </tr>
  </table>
</div>
</body>
</html>
