-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_activity_action.php
More file actions
66 lines (52 loc) · 2.73 KB
/
edit_activity_action.php
File metadata and controls
66 lines (52 loc) · 2.73 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require("util.php");
if( ! isset($_SESSION["current_user"])) {
die("finnished deleting the files");
}
/*if( ! ( is_numeric($_POST["hour"]) AND is_numeric($_POST["minute"]) ) ) {
die("die");
}*/
$name = $_POST["name"];
$room = $_POST["room"];
$responsible_staff = $_POST["responsible_staff"];
$summary = $_POST["summary"];
$type = $_POST["type"];
$explicit = (int) ! empty($_POST["explicit"]);
$start_time = sprintf("%s:00", $_POST["start_time"]);
$end_time = sprintf("%s:00", $_POST["end_time"]);
$activity_id = null;
if(empty($_POST["activity_id"])) {
$stmt = $conn->prepare("INSERT INTO activities (name, type, responsible_staff, summary, explicit) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("ssssi", $name, $type, $responsible_staff, $summary, $explicit);
$stmt->execute();
$activity_id = $conn->insert_id;
$stmt = $conn->prepare("INSERT INTO activities_time_and_place (activity_id, room, start_time, end_time) VALUES (?, ?, ?, ?)");
$stmt->bind_param("isss", $activity_id, $room, $start_time, $end_time);
$stmt->execute();
} else {
$activity_id = $_POST["activity_id"];
$stmt = $conn->prepare("UPDATE activities SET name = ?, type = ?, responsible_staff = ?, summary = ?, explicit = ? WHERE id = ?;");
$stmt->bind_param("ssssii", $name, $type, $responsible_staff, $summary, $explicit, $activity_id);
$stmt->execute();
$stmt = $conn->prepare("INSERT INTO activities_time_and_place (activity_id, room, start_time, end_time) VALUES (?, ?, ?, ?)");
$stmt->bind_param("isss", $activity_id, $room, $start_time, $end_time);
$stmt->execute();
if(isset($_POST["purge_old_times"]) AND !empty($_POST["purge_old_times"])) {
$stmt = $conn->prepare("DELETE FROM `activities_time_and_place` WHERE id IN
( SELECT id FROM ( SELECT id, ROW_NUMBER() OVER(ORDER BY timestamp DESC) AS rownum
FROM activities_time_and_place WHERE activity_id = ? ) AS row_numbers
WHERE rownum > 1 );");
$stmt->bind_param("i", $activity_id);
$stmt->execute();
}
if(isset($_POST["create_notification"]) AND !empty($_POST["create_notification"])) {
$notification_stmt = $conn->prepare("INSERT INTO notifications (message, expiration_time) VALUES (?, ?)");
$datetime = new DateTime($_POST["start_time"], new DateTimeZone("Europe/Stockholm"));
$datetime->modify('+15 minutes');
$notification_expiration_time = $datetime->format('H:i:s');
$notification_stmt->bind_param("ss", $_POST["notification_message"], $notification_expiration_time);
$notification_stmt->execute();
}
}
header("Location: edit_activity.php?activity_id=". $activity_id)
?>