Gazelle/sections/ajax/send_recommendation.php

60 lines
1.7 KiB
PHP
Raw Normal View History

2013-03-05 08:00:26 +00:00
<?php
$FriendID = (int) $_POST['friend'];
$Type = $_POST['type'];
$ID = (int) $_POST['id'];
$Note = $_POST['note'];
2013-04-19 08:00:55 +00:00
if (empty($FriendID) || empty($Type) || empty($ID)) {
2013-03-05 08:00:26 +00:00
echo json_encode(array("status" => "error", "response" => "Error."));
die();
}
// Make sure the recipient is on your friends list and not some random dude.
2013-04-19 08:00:55 +00:00
$DB->query("
SELECT
f.FriendID,
u.Username
FROM friends AS f
RIGHT JOIN users_enable_recommendations AS r
ON r.ID = f.FriendID AND r.Enable = 1
RIGHT JOIN users_main AS u
ON u.ID = f.FriendID
WHERE f.UserID = '$LoggedUser[ID]'
AND f.FriendID = '$FriendID'");
2013-03-05 08:00:26 +00:00
2013-04-19 08:00:55 +00:00
if ($DB->record_count() == 0) {
2013-03-05 08:00:26 +00:00
echo json_encode(array("status" => "error", "response" => "Not on friend list."));
die();
}
$Type = strtolower($Type);
2013-04-19 08:00:55 +00:00
$Link = '';
2013-03-05 08:00:26 +00:00
// "a" vs "an", english language is so confusing.
2013-05-16 08:00:10 +00:00
// https://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an
2013-04-19 08:00:55 +00:00
$Article = 'a';
switch ($Type) {
2013-03-05 08:00:26 +00:00
case 'torrent':
2013-04-19 08:00:55 +00:00
$Link = "torrents.php?id=".$ID;
$DB->query("SELECT Name FROM torrents_group WHERE ID = '$ID'");
2013-03-05 08:00:26 +00:00
break;
case 'artist':
$Article = "an";
$Link = "artist.php?id=".$ID;
2013-04-19 08:00:55 +00:00
$DB->query("SELECT Name FROM artists_group WHERE ArtistID = '$ID'");
break;
case 'collage':
$Link = "collages.php?id=".$ID;
$DB->query("SELECT Name FROM collages WHERE ID = '$ID'");
break;
2013-03-05 08:00:26 +00:00
}
list($Name) = $DB->next_record();
$Subject = $LoggedUser['Username'] . " recommended you $Article " . $Type . "!";
2013-04-19 08:00:55 +00:00
$Body = $LoggedUser['Username'] . " recommended you the ".$Type." [url=https://".SSL_SITE_URL."/$Link]$Name".'[/url].';
if (!empty($Note)) {
$Body = $Body . "\n\n". $Note;
2013-03-05 08:00:26 +00:00
}
2013-03-10 08:00:41 +00:00
Misc::send_pm($FriendID, $LoggedUser['ID'], $Subject, $Body);
2013-03-05 08:00:26 +00:00
echo json_encode(array("status" => "success", "response" => "Sent!"));
die();