forked from jpatokal/openflights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trip.php
66 lines (54 loc) · 1.63 KB
/
trip.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
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
include 'locale.php';
include 'db_pdo.php';
$type = $_POST["type"];
$name = $_POST["name"];
$url = $_POST["url"];
$trid = $_POST["trid"];
$privacy = $_POST["privacy"];
if($type != "NEW" and (!$trid or $trid == 0)) {
die ('0;Trip ID '. $trid . ' invalid');
}
$uid = $_SESSION["uid"];
if(!$uid or empty($uid)) {
die ('0;' . _("Your session has timed out, please log in again."));
exit;
}
switch($type) {
case "NEW":
// Create new trip
$sth = $dbh->prepare("INSERT INTO trips(name,url,public,uid) VALUES(?,?,?,?)");
$success = $sth->execute([$name, $url, $privacy, $uid]);
break;
case "EDIT":
// Edit existing trip
$sth = $dbh->prepare("UPDATE trips SET name=?, url=?, public=? WHERE uid=? AND trid=?");
$success = $sth->execute([$name, $url, $privacy, $uid, $trid]);
break;
// Assign its flights to null and delete trip
case "DELETE":
$sth = $dbh->prepare("UPDATE flights SET trid=NULL WHERE trid=? AND uid=?");
$sth->execute([$trid, $uid]) or die ('0;Operation on trip ' . $name . ' failed.');
$sth = $dbh->prepare("DELETE FROM trips WHERE trid=? AND uid=?");
$success = $sth->execute([$trid, $uid]);
break;
default:
die ('0;Unknown operation ' . $type);
}
$success or die ('0;Operation on trip ' . $name . ' failed.');
if($sth->rowCount() != 1) {
die("0;No matching trip found");
}
switch($type) {
case "NEW":
$trid = $dbh->lastInsertId();
printf("1;%s;" . _("Trip successfully created"), $trid);
break;
case "DELETE":
printf("100;%s;" . _("Trip successfully deleted"), $trid);
break;
default:
printf("2;%s;" . _("Trip successfully edited."), $trid);
break;
}
?>