<?
  if (basename(__FILE__) == basename($PHP_SELF))
    die("Darf nur als include benutzt werden\n");
?>
<?
function check_login ($user_name,$user_passwort)
{
  $user_id=0;
  $sql = "select user_id from user where user_name = '" . $user_name . "' and user_passwort = '" . $user_passwort . "'";
  $res=send_sql($sql);
  for ($count = 0; $row = mysql_fetch_row ($res); ++$count)
  {
    $user_id=$row[0];
  }
  return $user_id;
}

function check_kasse ($kasse,$user_id,$kasse_bestand_eingang)
{
  $sql = "select kasse from kasse where kasse = $kasse and datum = curdate()";
  $res=send_sql($sql);
  $anz=mysql_num_rows($res);
  if ($anz==0)
  {
    $sql = "insert kasse set datum = curdate(),kasse = $kasse, user_id = $user_id, kasse_bestand_eingang='".$kasse_bestand_eingang."'";
    $res=send_sql_IDback($sql);
    return $res;
  }
  else
  {
    $sql = "select kasse_id from kasse where kasse = $kasse and datum = curdate() and user_id = $user_id";
    $res=send_sql($sql);
    $anz=mysql_num_rows($res);
    if ($anz==1)
    {
      $res=mysql_result($res,0,0);
      return $res;
    }
    else return 0;
  }
}

function create_Session_ID($user_id,$kasse_id)
{
  srand(time());
  $Session_id = md5(uniqid(rand()));
  $sql = "update user set Session_ID = '" . $Session_id . "', kasse_id = '".$kasse_id."' where user_ID = '" . $user_id . "'";
  $res=send_sql($sql);

  return $Session_id;
}

function destroy_Session_ID($session_id,$status)
{
  $sql = "update user set Session_ID = null where session_ID = '" . $session_id . "'";
  $res=send_sql($sql);
  if (mysql_affected_rows()>=1)
    return 1;
}


function check_Session_ID($session_id)
{
  $sql = "select u.user_id, u.name, u.vorname, u.status, k.kasse_id, k.kasse from user as u, kasse as k where u.session_ID = '" . $session_id . "' and u.user_id = k.user_id and u.kasse_id=k.kasse_id and k.datum = curdate()";
  $res=send_sql($sql);
  if (mysql_num_rows($res) == 0)
  {
    return 0;
  }
  else
  {
    $res = mysql_fetch_array($res, MYSQL_ASSOC);
    return $res;
  }
}
?>