Gazelle/sections/ajax/send_recommendation.php

66 lines
1.7 KiB
PHP
Raw Normal View History

2013-03-05 08:00:26 +00:00
<?php
2013-10-30 08:01:19 +00:00
$FriendID = (int)$_POST['friend'];
2013-03-05 08:00:26 +00:00
$Type = $_POST['type'];
2013-10-30 08:01:19 +00:00
$ID = (int)$_POST['id'];
2013-03-05 08:00:26 +00:00
$Note = $_POST['note'];
2013-04-19 08:00:55 +00:00
if (empty($FriendID) || empty($Type) || empty($ID)) {
2013-07-13 08:00:46 +00:00
echo json_encode(array('status' => 'error', 'response' => 'Error.'));
2013-03-05 08:00:26 +00:00
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("
2013-07-13 08:00:46 +00:00
SELECT f.FriendID, u.Username
2013-04-19 08:00:55 +00:00
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-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2013-07-13 08:00:46 +00:00
echo json_encode(array('status' => 'error', 'response' => 'Not on friend list.'));
2013-03-05 08:00:26 +00:00
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-07-13 08:00:46 +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':
2013-07-13 08:00:46 +00:00
$Article = 'an';
$Link = "artist.php?id=$ID";
$DB->query("
SELECT Name
FROM artists_group
WHERE ArtistID = '$ID'");
2013-04-19 08:00:55 +00:00
break;
case 'collage':
2013-07-13 08:00:46 +00:00
$Link = "collages.php?id=$ID";
$DB->query("
SELECT Name
FROM collages
WHERE ID = '$ID'");
2013-04-19 08:00:55 +00:00
break;
2013-03-05 08:00:26 +00:00
}
list($Name) = $DB->next_record();
2013-07-13 08:00:46 +00:00
$Subject = $LoggedUser['Username'] . " recommended you $Article $Type!";
2014-02-27 08:00:30 +00:00
$Body = $LoggedUser['Username'] . " recommended you the $Type [url=".site_url()."$Link]$Name".'[/url].';
2013-04-19 08:00:55 +00:00
if (!empty($Note)) {
2013-07-13 08:00:46 +00:00
$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-07-13 08:00:46 +00:00
echo json_encode(array('status' => 'success', 'response' => 'Sent!'));
2013-03-05 08:00:26 +00:00
die();