Gazelle/sections/requests/takenew_edit.php

558 lines
16 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
//******************************************************************************//
//----------------- Take request -----------------------------------------------//
authorize();
2013-04-19 08:00:55 +00:00
if ($_POST['action'] != 'takenew' && $_POST['action'] != 'takeedit') {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-04-19 08:00:55 +00:00
$NewRequest = ($_POST['action'] == 'takenew');
2011-03-28 14:21:28 +00:00
2013-04-19 08:00:55 +00:00
if (!$NewRequest) {
2011-03-28 14:21:28 +00:00
$ReturnEdit = true;
}
2013-04-19 08:00:55 +00:00
if ($NewRequest) {
if (!check_perms('site_submit_requests') || $LoggedUser['BytesUploaded'] < 250 * 1024 * 1024) {
2011-03-28 14:21:28 +00:00
error(403);
}
} else {
$RequestID = $_POST['requestid'];
2013-04-19 08:00:55 +00:00
if (!is_number($RequestID)) {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-02-19 08:00:30 +00:00
2012-10-11 08:00:15 +00:00
$Request = Requests::get_requests(array($RequestID));
2011-03-28 14:21:28 +00:00
$Request = $Request['matches'][$RequestID];
2013-04-19 08:00:55 +00:00
if (empty($Request)) {
2011-03-28 14:21:28 +00:00
error(404);
}
2013-02-19 08:00:30 +00:00
2012-02-03 08:00:22 +00:00
list($RequestID, $RequestorID, $RequestorName, $TimeAdded, $LastVote, $CategoryID, $Title, $Year, $Image, $Description, $CatalogueNumber, $RecordLabel,
2013-04-19 08:00:55 +00:00
$ReleaseType, $BitrateList, $FormatList, $MediaList, $LogCue, $FillerID, $FillerName, $TorrentID, $TimeFilled, $GroupID, $OCLC) = $Request;
2011-03-28 14:21:28 +00:00
$VoteArray = get_votes_array($RequestID);
$VoteCount = count($VoteArray['Voters']);
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$IsFilled = !empty($TorrentID);
$CategoryName = $Categories[$CategoryID - 1];
2013-02-19 08:00:30 +00:00
2013-04-19 08:00:55 +00:00
$ProjectCanEdit = (check_perms('project_team') && !$IsFilled && (($CategoryID == 0) || ($CategoryName == 'Music' && $Year == 0)));
2011-03-28 14:21:28 +00:00
$CanEdit = ((!$IsFilled && $LoggedUser['ID'] == $RequestorID && $VoteCount < 2) || $ProjectCanEdit || check_perms('site_moderate_requests'));
2013-02-19 08:00:30 +00:00
2013-04-19 08:00:55 +00:00
if (!$CanEdit) {
2011-03-28 14:21:28 +00:00
error(403);
}
}
// Validate
2013-04-19 08:00:55 +00:00
if (empty($_POST['type'])) {
2011-03-28 14:21:28 +00:00
error(0);
}
$CategoryName = $_POST['type'];
$CategoryID = (array_search($CategoryName, $Categories) + 1);
2013-04-19 08:00:55 +00:00
if (empty($CategoryID)) {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-04-19 08:00:55 +00:00
if (empty($_POST['title'])) {
$Err = 'You forgot to enter the title!';
2011-03-28 14:21:28 +00:00
} else {
$Title = trim($_POST['title']);
}
2013-04-19 08:00:55 +00:00
if (empty($_POST['tags'])) {
$Err = 'You forgot to enter any tags!';
2011-03-28 14:21:28 +00:00
} else {
$Tags = trim($_POST['tags']);
}
2013-04-19 08:00:55 +00:00
if ($NewRequest) {
if (empty($_POST['amount'])) {
$Err = 'You forgot to enter any bounty!';
2011-03-28 14:21:28 +00:00
} else {
$Bounty = trim($_POST['amount']);
2013-04-19 08:00:55 +00:00
if (!is_number($Bounty)) {
$Err = 'Your entered bounty is not a number';
} elseif ($Bounty < 100 * 1024 * 1024) {
$Err = 'Minumum bounty is 100 MB.';
2011-03-28 14:21:28 +00:00
}
$Bytes = $Bounty; //From MB to B
}
}
2013-04-19 08:00:55 +00:00
if (empty($_POST['image'])) {
$Image = '';
2011-03-28 14:21:28 +00:00
} else {
2013-04-19 08:00:55 +00:00
ImageTools::blacklisted($_POST['image']);
if (preg_match('/'.IMAGE_REGEX.'/', trim($_POST['image'])) > 0) {
2011-03-28 14:21:28 +00:00
$Image = trim($_POST['image']);
} else {
2013-04-19 08:00:55 +00:00
$Err = display_str($_POST['image']).' does not appear to be a valid link to an image.';
2011-03-28 14:21:28 +00:00
}
}
2013-04-19 08:00:55 +00:00
if (empty($_POST['description'])) {
$Err = 'You forgot to enter a description.';
2011-03-28 14:21:28 +00:00
} else {
$Description = trim($_POST['description']);
}
2013-04-19 08:00:55 +00:00
if ($CategoryName == "Music") {
if (empty($_POST['artists'])) {
$Err = 'You did not enter any artists.';
2011-03-28 14:21:28 +00:00
} else {
$Artists = $_POST['artists'];
$Importance = $_POST['importance'];
}
2013-02-19 08:00:30 +00:00
2013-04-19 08:00:55 +00:00
if (!is_number($_POST['releasetype']) || !array_key_exists($_POST['releasetype'], $ReleaseTypes)) {
$Err = 'Please pick a release type';
2011-03-28 14:21:28 +00:00
}
$ReleaseType = $_POST['releasetype'];
2013-02-19 08:00:30 +00:00
2013-04-19 08:00:55 +00:00
if (empty($_POST['all_formats']) && count($_POST['formats']) != count($Formats)) {
2011-03-28 14:21:28 +00:00
$FormatArray = $_POST['formats'];
2013-04-19 08:00:55 +00:00
if (count($FormatArray) < 1) {
$Err = 'You must require at least one format';
2011-03-28 14:21:28 +00:00
}
} else {
$AllFormats = true;
}
2013-02-19 08:00:30 +00:00
2013-04-19 08:00:55 +00:00
if (empty($_POST['all_bitrates']) && count($_POST['bitrates']) != count($Bitrates)) {
2011-03-28 14:21:28 +00:00
$BitrateArray = $_POST['bitrates'];
2013-04-19 08:00:55 +00:00
if (count($BitrateArray) < 1) {
$Err = 'You must require at least one bitrate';
2011-03-28 14:21:28 +00:00
}
} else {
$AllBitrates = true;
}
2013-02-19 08:00:30 +00:00
2013-04-19 08:00:55 +00:00
if (empty($_POST['all_media']) && count($_POST['media']) != count($Media)) {
2013-02-19 08:00:30 +00:00
$MediaArray = $_POST['media'];
2013-04-19 08:00:55 +00:00
if (count($MediaArray) < 1) {
$Err = 'You must require at least one medium.';
2011-03-28 14:21:28 +00:00
}
} else {
$AllMedia = true;
}
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
//$Bitrates[1] = FLAC
2013-04-19 08:00:55 +00:00
if (!empty($FormatArray) && in_array(1, $FormatArray)) {
2011-03-28 14:21:28 +00:00
$NeedLog = empty($_POST['needlog']) ? false : true;
2013-04-19 08:00:55 +00:00
if ($NeedLog) {
if ($_POST['minlogscore']) {
2011-03-28 14:21:28 +00:00
$MinLogScore = trim($_POST['minlogscore']);
} else {
$MinLogScore = 0;
}
2013-04-19 08:00:55 +00:00
if (!is_number($MinLogScore)) {
$Err = 'You have entered a minimum log score that is not a number.';
2011-03-28 14:21:28 +00:00
}
2013-02-19 08:00:30 +00:00
}
2011-03-28 14:21:28 +00:00
$NeedCue = empty($_POST['needcue']) ? false : true;
//FLAC was picked, require either Lossless or 24 bit Lossless
2013-04-19 08:00:55 +00:00
if (!$AllBitrates && !in_array(8, $BitrateArray) && !in_array(9, $BitrateArray)) {
$Err = 'You selected FLAC as a format but no possible bitrate to fill it (Lossless or 24bit Lossless)';
2011-03-28 14:21:28 +00:00
}
if (($NeedCue || $NeedLog)) {
2013-02-07 08:00:47 +00:00
if (!(empty($_POST['all_media']) && $MediaArray[0] == 0)) {
2013-04-19 08:00:55 +00:00
$Err = 'Only CD is allowed as media for FLAC + log/cue requests.';
2011-03-28 14:21:28 +00:00
}
}
} else {
$NeedLog = false;
$NeedCue = false;
2013-02-19 08:00:30 +00:00
$MinLogScore = false;
2011-03-28 14:21:28 +00:00
}
2013-02-19 08:00:30 +00:00
2012-02-03 08:00:22 +00:00
// GroupID
if (!empty($_POST['groupid'])) {
$GroupID = trim($_POST['groupid']);
2013-04-19 08:00:55 +00:00
$URLRegex = '/^https?:\/\/(www\.|ssl\.)?'.SSL_SITE_URL.'\/torrents\.php\?(page=[0-9]+&)?id=([0-9]+)/i';
2012-02-03 08:00:22 +00:00
if (preg_match($URLRegex, $GroupID, $Matches)) {
$GroupID = $Matches[3];
}
if (is_number($GroupID)) {
2012-02-07 08:00:20 +00:00
$DB->query("SELECT 1 FROM torrents_group WHERE ID = '$GroupID' AND CategoryID = 1");
2012-02-03 08:00:22 +00:00
if ($DB->record_count() == 0) {
2013-04-19 08:00:55 +00:00
$Err = 'The torrent group, if entered, must correspond to a music torrent group on the site.';
2012-02-03 08:00:22 +00:00
}
} else {
2013-04-19 08:00:55 +00:00
$Err = 'The torrent group, if entered, must correspond to a music torrent group on the site.';
2012-02-03 08:00:22 +00:00
}
2013-03-31 08:00:37 +00:00
} elseif ($_POST['groupid'] == '0') {
$GroupID = 0;
2012-02-03 08:00:22 +00:00
}
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
//Not required
2013-04-19 08:00:55 +00:00
if (!empty($_POST['editioninfo'])) {
2011-03-28 14:21:28 +00:00
$EditionInfo = trim($_POST['editioninfo']);
} else {
2013-04-19 08:00:55 +00:00
$EditionInfo = '';
2011-03-28 14:21:28 +00:00
}
2013-04-19 08:00:55 +00:00
if (!empty($_POST['cataloguenumber'])) {
2011-03-28 14:21:28 +00:00
$CatalogueNumber = trim($_POST['cataloguenumber']);
} else {
2013-04-19 08:00:55 +00:00
$CatalogueNumber = '';
2011-03-28 14:21:28 +00:00
}
2013-04-19 08:00:55 +00:00
if (!empty($_POST['recordlabel'])) {
2012-02-03 08:00:22 +00:00
$RecordLabel = trim($_POST['recordlabel']);
} else {
2013-04-19 08:00:55 +00:00
$RecordLabel = '';
2012-02-03 08:00:22 +00:00
}
2011-03-28 14:21:28 +00:00
}
2013-04-19 08:00:55 +00:00
if ($CategoryName == 'Music' || $CategoryName == 'Audiobooks' || $CategoryName == 'Comedy') {
if (empty($_POST['year'])) {
$Err = 'You forgot to enter the year!';
2011-03-28 14:21:28 +00:00
} else {
$Year = trim($_POST['year']);
2013-04-19 08:00:55 +00:00
if (!is_number($Year)) {
$Err = 'Your entered year is not a number.';
2011-03-28 14:21:28 +00:00
}
}
}
2012-08-24 08:00:15 +00:00
//Apply OCLC to all types
if (!empty($_POST['oclc'])) {
$OCLC = trim($_POST['oclc']);
} else {
2013-04-19 08:00:55 +00:00
$OCLC = '';
2012-08-24 08:00:15 +00:00
}
2011-03-28 14:21:28 +00:00
//For refilling on error
2013-04-19 08:00:55 +00:00
if ($CategoryName == 'Music') {
2011-03-28 14:21:28 +00:00
$MainArtistCount = 0;
$ArtistNames = array();
$ArtistForm = array(
1 => array(),
2 => array(),
3 => array()
);
2013-04-19 08:00:55 +00:00
for ($i = 0, $il = count($Artists); $i < $il; $i++) {
if (trim($Artists[$i]) != '') {
if (!in_array($Artists[$i], $ArtistNames)) {
2011-03-28 14:21:28 +00:00
$ArtistForm[$Importance[$i]][] = array('name' => trim($Artists[$i]));
2013-04-19 08:00:55 +00:00
if (in_array($Importance[$i], array(1,4,5,6))) {
2011-03-28 14:21:28 +00:00
$MainArtistCount++;
}
$ArtistNames[] = trim($Artists[$i]);
}
}
}
2013-04-19 08:00:55 +00:00
if ($MainArtistCount < 1) {
$Err = 'Please enter at least one main artist, conductor, composer, or DJ.';
2011-03-28 14:21:28 +00:00
}
2013-04-19 08:00:55 +00:00
if (!isset($ArtistNames[0])) {
2011-03-28 14:21:28 +00:00
unset($ArtistForm);
}
}
2013-04-19 08:00:55 +00:00
if (!empty($Err)) {
2011-03-28 14:21:28 +00:00
error($Err);
2013-04-19 08:00:55 +00:00
$Div = $_POST['unit'] == 'mb' ? 1024 * 1024 : 1024 * 1024 * 1024;
2011-03-28 14:21:28 +00:00
$Bounty /= $Div;
include(SERVER_ROOT.'/sections/requests/new_edit.php');
die();
}
//Databasify the input
2013-04-19 08:00:55 +00:00
if ($CategoryName == 'Music') {
if (empty($AllBitrates)) {
foreach ($BitrateArray as $Index => $MasterIndex) {
if (array_key_exists($Index, $Bitrates)) {
2011-03-28 14:21:28 +00:00
$BitrateArray[$Index] = $Bitrates[$MasterIndex];
} else {
//Hax
error(0);
}
}
2013-04-19 08:00:55 +00:00
$BitrateList = implode('|', $BitrateArray);
2011-03-28 14:21:28 +00:00
} else {
2013-04-19 08:00:55 +00:00
$BitrateList = 'Any';
2011-03-28 14:21:28 +00:00
}
2013-04-19 08:00:55 +00:00
if (empty($AllFormats)) {
foreach ($FormatArray as $Index => $MasterIndex) {
if (array_key_exists($Index, $Formats)) {
2011-03-28 14:21:28 +00:00
$FormatArray[$Index] = $Formats[$MasterIndex];
} else {
//Hax
error(0);
}
}
2013-04-19 08:00:55 +00:00
$FormatList = implode('|', $FormatArray);
2011-03-28 14:21:28 +00:00
} else {
2013-04-19 08:00:55 +00:00
$FormatList = 'Any';
2011-03-28 14:21:28 +00:00
}
2013-04-19 08:00:55 +00:00
if (empty($AllMedia)) {
foreach ($MediaArray as $Index => $MasterIndex) {
if (array_key_exists($Index, $Media)) {
2011-03-28 14:21:28 +00:00
$MediaArray[$Index] = $Media[$MasterIndex];
} else {
//Hax
error(0);
}
}
2013-04-19 08:00:55 +00:00
$MediaList = implode('|', $MediaArray);
2011-03-28 14:21:28 +00:00
} else {
2013-04-19 08:00:55 +00:00
$MediaList = 'Any';
2011-03-28 14:21:28 +00:00
}
2013-02-19 08:00:30 +00:00
2013-04-19 08:00:55 +00:00
$LogCue = '';
if ($NeedLog) {
$LogCue .= 'Log';
if ($MinLogScore > 0) {
if ($MinLogScore >= 100) {
$LogCue .= ' (100%)';
2011-03-28 14:21:28 +00:00
} else {
2013-04-19 08:00:55 +00:00
$LogCue .= ' (>= '.$MinLogScore.'%)';
2011-03-28 14:21:28 +00:00
}
}
}
2013-04-19 08:00:55 +00:00
if ($NeedCue) {
if ($LogCue != '') {
$LogCue .= ' + Cue';
2011-03-28 14:21:28 +00:00
} else {
2013-04-19 08:00:55 +00:00
$LogCue = 'Cue';
2011-03-28 14:21:28 +00:00
}
}
}
//Query time!
2013-04-19 08:00:55 +00:00
if ($CategoryName == 'Music') {
if ($NewRequest) {
$DB->query('INSERT INTO requests (
2012-02-03 08:00:22 +00:00
UserID, TimeAdded, LastVote, CategoryID, Title, Year, Image, Description, RecordLabel,
2012-06-02 08:00:16 +00:00
CatalogueNumber, ReleaseType, BitrateList, FormatList, MediaList, LogCue, Visible, GroupID, OCLC)
2011-03-28 14:21:28 +00:00
VALUES
2013-04-19 08:00:55 +00:00
('.$LoggedUser['ID'].", '".sqltime()."', '".sqltime()."', ".$CategoryID.", '".db_string($Title)."', ".$Year.", '".db_string($Image)."', '".db_string($Description)."','".db_string($RecordLabel)."',
2012-06-02 08:00:16 +00:00
'".db_string($CatalogueNumber)."', ".$ReleaseType.", '".$BitrateList."','".$FormatList."', '".$MediaList."', '".$LogCue."', '1', '$GroupID', '".db_string($OCLC)."')");
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$RequestID = $DB->inserted_id();
2013-02-08 08:00:46 +00:00
2011-03-28 14:21:28 +00:00
} else {
2013-02-19 08:00:30 +00:00
$DB->query("UPDATE requests
2011-03-28 14:21:28 +00:00
SET CategoryID = ".$CategoryID.",
2013-02-19 08:00:30 +00:00
Title = '".db_string($Title)."',
Year = ".$Year.",
2011-03-28 14:21:28 +00:00
Image = '".db_string($Image)."',
Description = '".db_string($Description)."',
CatalogueNumber = '".db_string($CatalogueNumber)."',
2012-02-03 08:00:22 +00:00
RecordLabel = '".db_string($RecordLabel)."',
2011-03-28 14:21:28 +00:00
ReleaseType = ".$ReleaseType.",
BitrateList = '".$BitrateList."',
FormatList = '".$FormatList."',
MediaList = '".$MediaList."',
2012-02-03 08:00:22 +00:00
LogCue = '".$LogCue."',
2012-06-02 08:00:16 +00:00
GroupID = '".$GroupID."',
OCLC = '".db_string($OCLC)."'
2011-03-28 14:21:28 +00:00
WHERE ID = ".$RequestID);
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
//I almost didn't think of this, we need to be able to delete artists / tags
$DB->query("SELECT ArtistID FROM requests_artists WHERE RequestID = ".$RequestID);
$RequestArtists = $DB->to_array();
2013-04-19 08:00:55 +00:00
foreach ($RequestArtists as $RequestArtist) {
2011-03-28 14:21:28 +00:00
$Cache->delete_value('artists_requests_'.$RequestArtist);
}
$DB->query("DELETE FROM requests_artists WHERE RequestID = ".$RequestID);
$Cache->delete_value('request_artists_'.$RequestID);
}
2013-02-19 08:00:30 +00:00
2012-02-03 08:00:22 +00:00
if ($GroupID) {
$Cache->delete_value('requests_group_'.$GroupID);
}
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
/*
* Multiple Artists!
* For the multiple artists system, we have 3 steps:
* 1. See if each artist given already exists and if it does, grab the ID.
* 2. For each artist that didn't exist, create an artist.
2013-02-19 08:00:30 +00:00
* 3. Create a row in the requests_artists table for each artist, based on the ID.
2011-03-28 14:21:28 +00:00
*/
2013-04-19 08:00:55 +00:00
foreach ($ArtistForm as $Importance => $Artists) {
foreach ($Artists as $Num => $Artist) {
2011-03-28 14:21:28 +00:00
//1. See if each artist given already exists and if it does, grab the ID.
$DB->query("
SELECT
aa.ArtistID,
aa.AliasID,
2012-05-18 13:35:17 +00:00
aa.Name,
2011-03-28 14:21:28 +00:00
aa.Redirect
FROM artists_alias AS aa
2012-06-02 08:00:16 +00:00
WHERE aa.Name = '".db_string($Artist['name'])."'");
2013-02-19 08:00:30 +00:00
2013-04-19 08:00:55 +00:00
while (list($ArtistID, $AliasID, $AliasName, $Redirect) = $DB->next_record(MYSQLI_NUM, false)) {
if (!strcasecmp($Artist['name'], $AliasName)) {
if ($Redirect) {
2012-06-13 08:00:16 +00:00
$AliasID = $Redirect;
2012-05-18 13:35:17 +00:00
}
2012-06-13 08:00:16 +00:00
$ArtistForm[$Importance][$Num] = array('id' => $ArtistID, 'aliasid' => $AliasID, 'name' => $AliasName);
break;
2011-03-28 14:21:28 +00:00
}
2012-06-13 08:00:16 +00:00
}
2013-04-19 08:00:55 +00:00
if (!$ArtistID) {
2011-03-28 14:21:28 +00:00
//2. For each artist that didn't exist, create an artist.
$DB->query("INSERT INTO artists_group (Name) VALUES ('".db_string($Artist['name'])."')");
$ArtistID = $DB->inserted_id();
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$Cache->increment('stats_artist_count');
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$DB->query("INSERT INTO artists_alias (ArtistID, Name) VALUES (".$ArtistID.", '".db_string($Artist['name'])."')");
$AliasID = $DB->inserted_id();
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$ArtistForm[$Importance][$Num] = array('id' => $ArtistID, 'aliasid' => $AliasID, 'name' => $Artist['name']);
}
}
}
2013-02-19 08:00:30 +00:00
//3. Create a row in the requests_artists table for each artist, based on the ID.
2013-04-19 08:00:55 +00:00
foreach ($ArtistForm as $Importance => $Artists) {
foreach ($Artists as $Num => $Artist) {
2011-03-28 14:21:28 +00:00
$DB->query("INSERT IGNORE INTO requests_artists (RequestID, ArtistID, AliasID, Importance) VALUES (".$RequestID.", ".$Artist['id'].", ".$Artist['aliasid'].", '".$Importance."')");
$Cache->increment('stats_album_count');
$Cache->delete_value('artists_requests_'.$Artist['id']);
}
}
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
//End Music only
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
} else {
//Not a music request anymore, delete music only fields.
2013-04-19 08:00:55 +00:00
if (!$NewRequest) {
2011-03-28 14:21:28 +00:00
$DB->query("SELECT ArtistID FROM requests_artists WHERE RequestID = ".$RequestID);
$OldArtists = $DB->collect('ArtistID');
2013-04-19 08:00:55 +00:00
foreach ($OldArtists as $ArtistID) {
if (empty($ArtistID)) { continue; }
2011-03-28 14:21:28 +00:00
//Get a count of how many groups or requests use the artist ID
$DB->query("SELECT COUNT(ag.ArtistID)
2013-02-19 08:00:30 +00:00
FROM artists_group as ag
LEFT JOIN requests_artists AS ra ON ag.ArtistID=ra.ArtistID
2011-03-28 14:21:28 +00:00
WHERE ra.ArtistID IS NOT NULL
AND ag.ArtistID = '$ArtistID'");
list($ReqCount) = $DB->next_record();
$DB->query("SELECT COUNT(ag.ArtistID)
2013-02-19 08:00:30 +00:00
FROM artists_group as ag
LEFT JOIN torrents_artists AS ta ON ag.ArtistID=ta.ArtistID
2011-03-28 14:21:28 +00:00
WHERE ta.ArtistID IS NOT NULL
AND ag.ArtistID = '$ArtistID'");
list($GroupCount) = $DB->next_record();
2013-04-19 08:00:55 +00:00
if (($ReqCount + $GroupCount) == 0) {
2011-03-28 14:21:28 +00:00
//The only group to use this artist
2012-10-11 08:00:15 +00:00
Artists::delete_artist($ArtistID);
2011-03-28 14:21:28 +00:00
} else {
//Not the only group, still need to clear cache
$Cache->delete_value('artists_requests_'.$ArtistID);
}
}
$DB->query("DELETE FROM requests_artists WHERE RequestID = ".$RequestID);
}
2013-04-19 08:00:55 +00:00
if ($CategoryName == 'Audiobooks' || $CategoryName == 'Comedy') {
2011-03-28 14:21:28 +00:00
//These types require a year field.
2013-04-19 08:00:55 +00:00
if ($NewRequest) {
2013-02-19 08:00:30 +00:00
$DB->query("INSERT INTO requests (
2012-08-24 08:00:15 +00:00
UserID, TimeAdded, LastVote, CategoryID, Title, Year, Image, Description, Visible, OCLC)
2011-03-28 14:21:28 +00:00
VALUES
2012-08-24 08:00:15 +00:00
(".$LoggedUser['ID'].", '".sqltime()."', '".sqltime()."', ".$CategoryID.", '".db_string($Title)."', ".$Year.", '".db_string($Image)."', '".db_string($Description)."', '1', '".db_string($OCLC)."')");
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$RequestID = $DB->inserted_id();
2013-02-08 08:00:46 +00:00
2011-03-28 14:21:28 +00:00
} else {
2013-02-19 08:00:30 +00:00
$DB->query("UPDATE requests
2011-03-28 14:21:28 +00:00
SET CategoryID = ".$CategoryID.",
2013-02-19 08:00:30 +00:00
Title = '".db_string($Title)."',
Year = ".$Year.",
2011-03-28 14:21:28 +00:00
Image = '".db_string($Image)."',
2012-08-24 08:00:15 +00:00
Description = '".db_string($Description)."',
2013-02-19 08:00:30 +00:00
OCLC = '".db_string($OCLC)."'
2011-03-28 14:21:28 +00:00
WHERE ID = ".$RequestID);
}
} else {
2013-04-19 08:00:55 +00:00
if ($NewRequest) {
2013-02-19 08:00:30 +00:00
$DB->query("INSERT INTO requests (
2012-08-24 08:00:15 +00:00
UserID, TimeAdded, LastVote, CategoryID, Title, Image, Description, Visible, OCLC)
2011-03-28 14:21:28 +00:00
VALUES
2012-08-24 08:00:15 +00:00
(".$LoggedUser['ID'].", '".sqltime()."', '".sqltime()."', ".$CategoryID.", '".db_string($Title)."', '".db_string($Image)."', '".db_string($Description)."', '1', '".db_string($OCLC)."')");
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$RequestID = $DB->inserted_id();
2013-02-08 08:00:46 +00:00
2011-03-28 14:21:28 +00:00
} else {
2013-02-19 08:00:30 +00:00
$DB->query("UPDATE requests
2011-03-28 14:21:28 +00:00
SET CategoryID = ".$CategoryID.",
2013-02-19 08:00:30 +00:00
Title = '".db_string($Title)."',
2011-03-28 14:21:28 +00:00
Image = '".db_string($Image)."',
2012-08-24 08:00:15 +00:00
Description = '".db_string($Description)."',
OCLC = '".db_string($OCLC)."'
2011-03-28 14:21:28 +00:00
WHERE ID = ".$RequestID);
}
}
}
//Tags
2013-04-19 08:00:55 +00:00
if (!$NewRequest) {
2011-03-28 14:21:28 +00:00
$DB->query("DELETE FROM requests_tags WHERE RequestID = ".$RequestID);
}
$Tags = array_unique(explode(',', $Tags));
2013-04-19 08:00:55 +00:00
foreach ($Tags as $Index => $Tag) {
2012-10-11 08:00:15 +00:00
$Tag = Misc::sanitize_tag($Tag);
2013-01-30 08:00:20 +00:00
$Tag = Misc::get_alias_tag($Tag);
2011-03-28 14:21:28 +00:00
$Tags[$Index] = $Tag; //For announce
2013-02-19 08:00:30 +00:00
$DB->query("INSERT INTO tags
2011-03-28 14:21:28 +00:00
(Name, UserID)
2013-02-19 08:00:30 +00:00
VALUES
('".$Tag."', ".$LoggedUser['ID'].")
2011-03-28 14:21:28 +00:00
ON DUPLICATE KEY UPDATE Uses=Uses+1");
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$TagID = $DB->inserted_id();
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$DB->query("INSERT IGNORE INTO requests_tags
(TagID, RequestID)
2013-02-19 08:00:30 +00:00
VALUES
2011-03-28 14:21:28 +00:00
(".$TagID.", ".$RequestID.")");
}
2013-04-19 08:00:55 +00:00
if ($NewRequest) {
2011-03-28 14:21:28 +00:00
//Remove the bounty and create the vote
2013-02-19 08:00:30 +00:00
$DB->query("INSERT INTO requests_votes
2011-03-28 14:21:28 +00:00
(RequestID, UserID, Bounty)
VALUES
(".$RequestID.", ".$LoggedUser['ID'].", ".($Bytes * (1 - $RequestTax)).")");
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
$DB->query("UPDATE users_main SET Uploaded = (Uploaded - ".$Bytes.") WHERE ID = ".$LoggedUser['ID']);
$Cache->delete_value('user_stats_'.$LoggedUser['ID']);
2013-02-19 08:00:30 +00:00
2013-04-19 08:00:55 +00:00
if ($CategoryName == "Music") {
2013-02-19 08:00:30 +00:00
$Announce = "'".$Title."' - ".Artists::display_artists($ArtistForm, false, false)." https://".SSL_SITE_URL."/requests.php?action=view&id=".$RequestID." - ".implode(" ", $Tags);
2011-03-28 14:21:28 +00:00
} else {
2013-02-19 08:00:30 +00:00
$Announce = "'".$Title."' - https://".SSL_SITE_URL."/requests.php?action=view&id=".$RequestID." - ".implode(" ", $Tags);
2011-03-28 14:21:28 +00:00
}
2013-02-19 08:00:30 +00:00
send_irc('PRIVMSG #'.SSL_SITE_URL.'-requests :'.$Announce);
2011-03-28 14:21:28 +00:00
} else {
$Cache->delete_value('request_'.$RequestID);
$Cache->delete_value('request_artists_'.$RequestID);
}
2012-10-11 08:00:15 +00:00
Requests::update_sphinx_requests($RequestID);
2011-03-28 14:21:28 +00:00
header('Location: requests.php?action=view&id='.$RequestID);
?>