<?php
require_once 'dbappinclude.php';

  if (isset($_GET["taskname"])) { $taskname = $_GET["taskname"]; }
  $rsStart = query("select UNIX_TIMESTAMP(logdate) as log  from times where user = $user and task = \"$taskname\" and code = 1");
  if ($row = mysql_fetch_assoc($rsStart)) {
    $seconds = $row["log"];
    query("update times set code = 3 where user = $user and 
           task = \"$taskname\" and code = 1");
    //
    query("insert into times values ($user, '$taskname', now(), 5,1000 )");
    $rsFinish = query("select UNIX_TIMESTAMP(logdate) as log from times where user = $user and 
                    task = \"$taskname\" and code = 5");
    if ($row2 = mysql_fetch_assoc($rsFinish)) {
       $seconds2 = $row2["log"]-$seconds;
       query("update times set seconds = $seconds2 where user = $user and 
           task = \"$taskname\" and code = 5");
       query("update times set code = 3 where user = $user and 
           task = \"$taskname\" and code = 5");
    } 
  } else {
    //start
    query("insert into times values ($user, '$taskname', now(), 1,0 )");
  }
  include ('index.php');
// this is clutsy
?>
