Commit 9207a70d authored by S.Holzhauer's avatar S.Holzhauer

COMMENTSSSZZZ

parent 92b8213a
......@@ -6,25 +6,35 @@ date_default_timezone_set("Europe/Amsterdam");
$time = date("H:i:sa");
$date = date("Y-m-d");
//if the ID is the server ID
if ($ID == "IRPS001" ){
//select all values from Camera table to check all elder activities
$sql = "SELECT *
FROM Camera;";
$result = $conn->query($sql);
//loop every elder.
while ($row = $result->fetch_assoc()){
$OuderID = $row["AlleenstaandeOuder_OuderID"];
/*select everything from this elder in the activity table
* with status 0 (false)
* starttime earlier then current time
* and endtime earlier or the same. Other activities haven't started yet.
*/
$sql = "SELECT *
FROM Activiteiten
WHERE OuderID='$OuderID'
AND StartTime < '$time'
AND StartTime < '$time'
AND EndTime <= '$time'
AND Status = '0';";
$result = $conn->query($sql);
//loop trough every activity
while ($row = $result->fetch_assoc()){
$starttime = $row['StartTime'];
$endtime = $row['EndTime'];
$Activity = $row['Activity'];
$daydate = $row['DayDate'];
//if the movement should be 0 and the status is 0 then it's a success scenario so status is updated to 1 (true/succes)
if ($row['Movement'] == 0){
$sql = "UPDATE Activiteiten
SET Status = '1'
......@@ -35,19 +45,22 @@ if ($ID == "IRPS001" ){
AND OuderID = '$OuderID';";
$conn->query($sql);
}
//if the movement shoudl be 1 but status is 0 there is a fail
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';";
//the notification is added to the database
$sql = "INSERT INTO Notificatie (`Date`,`Time`,`Message`, `Title`)
VALUES ('$daydate','$time','$message','Failed Activity';";
$result = $conn->query($sql);
if ($result === TRUE) {
$last_id = $conn->insert_id;
}
//see what accounts are connected to this elder.
$sql = "SELECT Account_AccountID FROM Account_has_AlleenstaandeOuder WHERE AlleenstaandeOuder_OuderID='$OuderID'";
$result = $conn->query($sql);
if ($result->num_rows > 0){
......@@ -79,13 +92,32 @@ if ($ID == "IRPS001" ){
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)";
//Connect the previous made notification to the appropriat accounts
$sql = "INSERT INTO Account_has_Notificatie (Notificatie_NotificatieID,Account_AccountID,Status)
VALUES ($last_id,$AccountID,0)";
$result = $conn->query($sql);
//see how many notifications an account already has.
$sql = "SELECT *
FROM Account_has_Notificatie
WHERE Account_AccountID = $AccountID;";
$result = $conn->query($sql);
//if there are more then 1 notifications this means that multiple activities have failed and thus a email is send.
if ($result->num_rows > 1){
$sql = "INSERT INTO Berichten (Time,Message,Subject,Date)
VALUES ('$time','$message','Second Failed Activity','$date')";
$result = $conn->query($sql);
if ($result === TRUE) {
$last_id = $conn->insert_id;
}
//sending the mail, $Email is initialized previously, $Msg is created above & $headers changes the sender information to irp@stienos.nl.
$headers = 'From: <activityalert@irp.nl>';
mail($Email,"Camera Alert","Beste $AcName $message",$headers);
$sql = "INSERT INTO Account_has_Berichten (Berichten_BerichtID,Account_AccountID,Status)
VALUES ($last_id,$AccountID,0";
$conn-query($sql);
}
}
}
......@@ -93,11 +125,16 @@ if ($ID == "IRPS001" ){
}
}
}
//if the ID is not null it comes from a camera and thus the status for the current event is updated.
if ($ID != NULL){
$sql = "SELECT AlleenstaandeOuder_OuderID
FROM Camera
WHERE CameraID = '$ID';";
$result = $conn->query($sql);
//if no camera with the given ID is found a error entrie is created.
if ($result == FALSE){
error_log("No camera with '$ID' is registerd.");
}
$row = $result->fetch_assoc();
$OuderID = $row['AlleenstaandeOuder_OuderID'];
......@@ -108,6 +145,7 @@ if ($ID != NULL){
AND DayDate = '$date';";
$conn->query($sql);
}
//if the ID is null error_log
if ($ID == NULL){
error_log("unrecognized call to server.php");
}
......
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