-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_delete_room.php
executable file
·40 lines (37 loc) · 1.34 KB
/
manager_delete_room.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require_once('config.php');
require_once('loginneeded.php');
require_once('manageronly.php');
$roomid=$_GET['id'];
if (empty($roomid)) {
echo "INVALID ROOM";
$smarty->assign("error","<p>Try again, that room is invalid.");
$smarty->display('error.tpl');
die();
}
$sql = "SELECT roomname,floorid FROM rooms WHERE roomid='$roomid' limit 1";
$result2 = $conn->query($sql);
$num_rows = mysqli_num_rows($result2);
if ($num_rows<1) {
$smarty->assign("error","<p>That Room does not exist, mayby another manager removed it?");
$smarty->display('error.tpl');
die();
}
$row2 = $result2->fetch_assoc();
$roomname=$row2['roomname'];
$floorid=$row2['floorid'];
$sql = "DELETE FROM rooms WHERE roomid='$roomid' LIMIT 1";
if ($conn->query($sql) === TRUE) {
log2db ("ROOM","DELETE",$roomid,$roomname);
$deleteroom['id']=$roomid;
$pubnub->setAuthKey($key);
print_r($pubnub->publish('room_delete',$deleteroom));
$url="manager_floor.php?id=$floorid";
header("Location: $url");
die();
} else {
echo "Error deleting record: " . $conn->error;
$smarty->assign("error","<p>Something went wrong, mayby you refreshed and tried to delete twice?, or did someone else delete this room? <p>Please also check that there are no devices in this room.");
$smarty->display('error.tpl');
die();
}