Commit e5d19bee authored by S.Holzhauer's avatar S.Holzhauer

server.php now handles all camera activity.

Camera should call this file and the server shoud call it every minute.
parent 5210721a
......@@ -10,7 +10,6 @@ $time = date("H:i:sa");
$date = date("Y-m-d");
$day = date("w");
$movement = 0;
error_log($day);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
......
<?php
require_once 'dbconnection.php';
global $conn;
$ID = $_REQUEST['ID'];
date_default_timezone_set("Europe/Amsterdam");
$time = date("H:i:sa");
$date = date("Y-m-d");
if ($ID == "IRPS001" ){
$sql = "SELECT *
FROM Camera;";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()){
$OuderID = $row["AlleenstaandeOuder_OuderID"];
$sql = "SELECT *
FROM Activiteiten
WHERE OuderID='$OuderID'
AND StartTime < '$time'
AND EndTime <= '$time'
AND Status = '0';";
$result = $conn->query($sql);
while ($row = $result->fetch_assoch()){
$starttime = $row['StartTime'];
$endtime = $row['EndTime'];
$Activity = $row['Activity'];
$daydate = $row['DayDate'];
if ($row['Movement'] == 0){
$sql = "UPDATE Activiteiten
SET Status = '1'
WHERE StartTime = '$starttime'
AND EndTime = '$endtime'
AND Activity = '$Activity'
AND DayDate = '$daydate'
AND OuderID = '$OuderID';";
$conn->query($sql);
}
if ($row['Movement'] == 1){
$message = "The scheduled activity:
\n Activity: '$Activity'
\n StartTime: '$starttime'
\n EndTime: '$endtime'
\n Did not register today ('$daydate'). We recommend taking action.";
$sql = "INSERT INTO Berichten (`Time`,`Message`,`Subject`,`Date`)
VALUES ('$time', '$message','Failed Activity','$daydate';";
$result = $conn->query($sql);
if ($result === TRUE) {
$last_id = $conn->insert_id;
}
$sql = "SELECT Account_AccountID FROM Account_has_AlleenstaandeOuder WHERE AlleenstaandeOuder_OuderID='$OuderID'";
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($result && ($row = $result->fetch_assoc()))
{
$AccountID=$row["Account_AccountID"];
//Get the email adres connected to the account
$sql = "SELECT Emailadres FROM Account WHERE AccountID='$AccountID'";
$result = $conn->query($sql2);
if ($result->num_rows > 0) {
// output data of each row
$row = $result->fetch_assoc();
//Binding the return value to $Email
$Email=$row["Emailadres"];
} else {
echo "0 results";
}
//Get the Name connected to the account
$sql = "SELECT Voorletters,Achternaam FROM Account WHERE AccountID='$AccountID'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$row = $result->fetch_assoc();
//Binding the return to $AcName
$AcName=$row["Voorletters"] . " " . $row["Achternaam"];
} else {
echo "0 results";
}
//sending the mail, $Email is initialized previously, $Msg is created above & $headers changes the sender information to irp@stienos.nl.
$headers = 'From: <activitychecker@irp.nl>';
mail($Email,"Camera Alert","Beste $AcName $message",$headers);
//Connect the message to the account with status 0 "Not Read"
$sql = "INSERT INTO Account_has_Berichten (Berichten_BerichtID,Account_AccountID,Status) VALUES ($last_id,$AccountID,0)";
$result = $conn->query($sql);
}
}
}
}
}
}
if ($ID != NULL){
$sql = "SELECT AlleenstaandeOuder_OuderID
FROM Camera
WHERE CameraID = '$ID';";
$result = $conn->query($sql);
$row = $resul->fetch_assoc();
$OuderID = $row['AlleenstaandeOuder_OuderID'];
$sql = "UPDATE Activiteiten
SET Status = 1
WHERE StartTime <= '$time'
AND EndTime >= '$time'
AND DayDate = '$date';";
$conn->query($sql);
}
if ($ID == NULL){
error_log("unrecognized call to server.php");
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment