-
Notifications
You must be signed in to change notification settings - Fork 0
/
claimItem.php
98 lines (77 loc) · 2.74 KB
/
claimItem.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once "vendor/autoload.php";
include_once "db_connection.php";
if(isset($_GET["itemID"]) && isset($_GET["mislayerID"]))
{
$itemID = $_GET["itemID"];
$mislayerID = $_GET["mislayerID"];
$itemSQL = "SELECT * FROM Items WHERE ID='$itemID'";
$itemResult = $conn->query($itemSQL);
$itemRow = $itemResult->fetch_assoc();
$finderID = $itemRow["FinderID"];
$mislayerSQL = "SELECT * FROM Users WHERE ID='$mislayerID'";
$mislayerResult = $conn->query($mislayerSQL);
$mislayerRow = $mislayerResult->fetch_assoc();
$finderSQL = "SELECT * FROM Users WHERE ID='$finderID'";
$finderResult = $conn->query($finderSQL);
$finderRow = $finderResult->fetch_assoc();
$matchedSQL = "SELECT * FROM Matched WHERE FinderID='$finderID' AND MislayerID='$mislayerID' AND ItemID='$itemID' ";
$matchedResult = $conn->query($matchedSQL);
$isInDB = false;
if($matchedResult->num_rows == 0)
{
$insertSQL = "INSERT INTO Matched (FinderID, MislayerID, ItemID, Status) VALUES ('$finderID', '$mislayerID', '$itemID', '0') ";
if($conn->query($insertSQL) === TRUE)
{
echo "New row added";
$msg = "The " . $itemRow["ItemName"] . " lost on " . $itemRow["Date"] . " around " . $itemRow["Location"] . " received a match by " . $mislayerRow["Name"] . ". In order to come in contact with the mislayer please email " . $mislayerRow["Email"] . ".";
$mail = new PHPMailer(TRUE);
try {
$mail->setFrom('[email protected]', 'Lost & Found');
$mail->addAddress($finderRow["Email"], $finderRow["Name"]);
$mail->Subject = 'Lost & Found: Matched case';
$mail->Body = $msg;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = 'tls';
$mail->Username = '[email protected]';
$mail->Password = 'lost&found';
$mail->Port = 587;
/* Disable some SSL checks. */
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
/* Enable SMTP debug output. */
//$mail->SMTPDebug = 4;
$mail->send();
}
catch (Exception $e)
{
echo $e->errorMessage();
}
catch (\Exception $e)
{
echo $e->getMessage();
}
//mail($finderRow["Email"], "Lost & Found: Matched case", $msg);
//echo $msg;
}
else
echo "Problem with inserting";
}
else
{
echo "Row already added";
}
header("Location: items.php");
}
else
header("Location: items.php");
?>