Location: PHPKode > projects > Php Motion Detect > phpmotiondetect-0.82/functions.php
<?

function get_latest_entries($db) {
  // GET LAST ENTRY IN LOG
  $result = mysql_query("SELECT id,timestamp FROM log ORDER BY timestamp DESC LIMIT 0,1",$db);
  $nresults= mysql_affected_rows();
  $myrow = mysql_fetch_array($result);
  $timestamp_log=$myrow["timestamp"];
  $last_log_id=$myrow["id"];
  list ($year,$month,$day,$hour,$minute,$second,$timestring_log)=timestamp($timestamp_log);
  
  // GET LAST INSERTED IMAGE
  $result = mysql_query("SELECT id,timestamp FROM images ORDER BY timestamp DESC LIMIT 0,1",$db);
  $nresults= mysql_affected_rows();
  $myrow = mysql_fetch_array($result);
  $timestamp_image=$myrow["timestamp"];
  $last_image_id=$myrow["id"];
  list ($year,$month,$day,$hour,$minute,$second,$timestring_images)=timestamp($timestamp_image);
  $dtime=$timestamp_image-$timestamp_log;
  return array($timestring_log,$timestring_images,$last_log_id,$last_image_id,$dtime);
}

function listbox_images($imageselect,$limit) {
require("conf.php");
 
if ($limit<1) {
  $limit=5;
}
 
 $db = mysql_connect($host, $user, $password);
 mysql_select_db($usebase,$db);

$result = mysql_query("SELECT id,timestamp FROM images ORDER BY timestamp DESC LIMIT 0,$limit",$db);
$nresults= mysql_affected_rows();

echo "<SELECT style=\"width:200px;\" name=imageselect size=1 >\n";

if ($imageselect==0) {
   printf(" <OPTION SELECTED value=0>%s\n","Latest Picture");
} else {
   printf(" <OPTION value=0>%s\n","Latest Picture");
}


if ($myrow = mysql_fetch_array($result)) {
do {
      $id=$myrow["id"];
      $timestamp=$myrow["timestamp"];

      list ($year,$month,$day,$hour,$minute,$second)=timestamp($timestamp);
      $year= $timestamp[0] .$timestamp[1] . $timestamp[2] . $timestamp[3];
      $name=sprintf("%s-%s-%s %sh%sm%ss",$year,$month,$day,$hour,$minute,$second);

      if ($imageselect==$id) {
        printf(" <OPTION SELECTED value=%s>%s\n",$id,$name);
                } else {
        printf(" <OPTION value=%s>%s\n",$id,$name);

        }

    } while ($myrow = mysql_fetch_array($result));
} else {
        echo "No records found";
}
echo "</SELECT>\n";
}



function getimageinfo($id) {
  require("conf.php");
  $db = mysql_connect($host, $user, $password);
  mysql_select_db($usebase,$db);

  $result = mysql_query("SELECT width,height,type,timestamp FROM images WHERE id=$id ",$db);
  if ($row = mysql_fetch_array($result)) {
    $width=$row["width"];
    $height=$row["height"];
    $type=$row["type"];
    $timestamp=$row["timestamp"];
    return array($width,$height,$type,$timestamp);

  }
}


function timestamp($timestamp) {
  $year= $timestamp[0] .$timestamp[1] . $timestamp[2] . $timestamp[3];
  $month= $timestamp[4] .$timestamp[5];
  $day= $timestamp[6] .$timestamp[7];

  $hour= $timestamp[8] .$timestamp[9];
  $minute= $timestamp[10] .$timestamp[11];
  $second= $timestamp[12] .$timestamp[13];

  $timestring=sprintf("%s-%s-%s %sh%sm%ss<BR>",$year,$month,$day,$hour,$minute,$second);

  return array($year,$month,$day,$hour,$minute,$second,$timestring);

}



?>
Return current item: Php Motion Detect