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

error fixing

parent cfbd6ae3
...@@ -32,100 +32,100 @@ if ($ID == "IRPS001" ){ ...@@ -32,100 +32,100 @@ if ($ID == "IRPS001" ){
AND Status = '0';"; AND Status = '0';";
$result = $conn->query($sql); $result = $conn->query($sql);
//loop trough every activity //loop trough every activity
while ($row = $result->fetch_assoc()){ while ($result && ($row = $result->fetch_assoc())){
$starttime = $row['StartTime']; $starttime = $row['StartTime'];
$endtime = $row['EndTime']; $endtime = $row['EndTime'];
$Activity = $row['Activity']; $Activity = $row['Activity'];
$daydate = $row['DayDate']; $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 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){ if ($row['Movement'] == 0){
$sql = "UPDATE Activiteiten $sql = "UPDATE Activiteiten
SET Status = '1' SET Status = '1'
WHERE StartTime = '$starttime' WHERE StartTime = '$starttime'
AND EndTime = '$endtime' AND EndTime = '$endtime'
AND Activity = '$Activity' AND Activity = '$Activity'
AND DayDate = '$daydate' AND DayDate = '$daydate'
AND OuderID = '$OuderID';"; AND OuderID = '$OuderID';";
$conn->query($sql); $conn->query($sql);
} }
//if the movement shoudl be 1 but status is 0 there is a fail //if the movement shoudl be 1 but status is 0 there is a fail
if ($row['Movement'] == 1){ if ($row['Movement'] == 1){
$message = "The scheduled activity: $message = "The scheduled activity:
\n Activity: '$Activity' \n Activity: '$Activity'
\n StartTime: '$starttime' \n StartTime: '$starttime'
\n EndTime: '$endtime' \n EndTime: '$endtime'
\n Did not register today ('$daydate'). We recommend taking action."; \n Did not register today ('$daydate'). We recommend taking action.";
//the notification is added to the database //the notification is added to the database
$sql = "INSERT INTO Notificatie (`Date`,`Time`,`Message`, `Title`) $sql = "INSERT INTO Notificatie (`Date`,`Time`,`Message`, `Title`)
VALUES ('$daydate','$time','$message','Failed Activity';"; 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); $result = $conn->query($sql);
if ($result->num_rows > 0){ if ($result === TRUE) {
while($result && ($row = $result->fetch_assoc())) $last_id = $conn->insert_id;
{
$AccountID=$row["Account_AccountID"];
//Get the email adres connected to the account //see what accounts are connected to this elder.
$sql = "SELECT Emailadres FROM Account WHERE AccountID='$AccountID'"; $sql = "SELECT Account_AccountID FROM Account_has_AlleenstaandeOuder WHERE AlleenstaandeOuder_OuderID='$OuderID'";
$result = $conn->query($sql); $result = $conn->query($sql);
if ($result->num_rows > 0) { if ($result->num_rows > 0){
// output data of each row while($result && ($row = $result->fetch_assoc()))
$row = $result->fetch_assoc(); {
//Binding the return value to $Email $AccountID=$row["Account_AccountID"];
$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";
}
//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. //Get the email adres connected to the account
$sql = "SELECT * $sql = "SELECT Emailadres FROM Account WHERE AccountID='$AccountID'";
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); $result = $conn->query($sql);
if ($result === TRUE) { if ($result->num_rows > 0) {
$last_id = $conn->insert_id; // output data of each row
$row = $result->fetch_assoc();
//Binding the return value to $Email
$Email=$row["Emailadres"];
} 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: <activityalert@irp.nl>'; //Get the Name connected to the account
mail($Email,"Camera Alert","Beste $AcName $message",$headers); $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";
}
//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);
$sql = "INSERT INTO Account_has_Berichten (Berichten_BerichtID,Account_AccountID,Status) //see how many notifications an account already has.
VALUES ($last_id,$AccountID,0"; $sql = "SELECT *
$conn-query($sql); 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);
}
} }
} }
} }
} }
} }
}
} }
} }
//if the ID is not null it comes from a camera and thus the status for the current event is updated. //if the ID is not null it comes from a camera and thus the status for the current event is updated.
......
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