Gazelle/sections/collages/manage_handle.php

76 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2012-07-11 08:00:16 +00:00
<?php
2013-05-04 08:00:48 +00:00
authorize();
$CollageID = $_POST['collageid'];
if (!is_number($CollageID)) {
error(404);
}
2013-07-13 08:00:46 +00:00
$DB->query("
SELECT UserID, CategoryID
FROM collages
WHERE ID = '$CollageID'");
2013-05-04 08:00:48 +00:00
list($UserID, $CategoryID) = $DB->next_record();
2013-07-13 08:00:46 +00:00
if ($CategoryID === '0' && $UserID !== $LoggedUser['ID'] && !check_perms('site_collages_delete')) {
2013-05-04 08:00:48 +00:00
error(403);
}
2013-05-25 08:01:03 +00:00
2013-05-04 08:00:48 +00:00
$GroupID = $_POST['groupid'];
if (!is_number($GroupID)) {
error(404);
}
2013-07-13 08:00:46 +00:00
if ($_POST['submit'] === 'Remove') {
$DB->query("
DELETE FROM collages_torrents
WHERE CollageID = '$CollageID'
AND GroupID = '$GroupID'");
2013-05-04 08:00:48 +00:00
$Rows = $DB->affected_rows();
2013-07-13 08:00:46 +00:00
$DB->query("
UPDATE collages
SET NumTorrents = NumTorrents - $Rows
WHERE ID = '$CollageID'");
$Cache->delete_value("torrents_details_$GroupID");
$Cache->delete_value("torrent_collages_$GroupID");
$Cache->delete_value("torrent_collages_personal_$GroupID");
2013-05-04 08:00:48 +00:00
} elseif (isset($_POST['drag_drop_collage_sort_order'])) {
@parse_str($_POST['drag_drop_collage_sort_order'], $Series);
$Series = @array_shift($Series);
if (is_array($Series)) {
$SQL = array();
foreach ($Series as $Sort => $GroupID) {
if (is_number($Sort) && is_number($GroupID)) {
$Sort = ($Sort + 1) * 10;
$SQL[] = sprintf('(%d, %d, %d)', $GroupID, $Sort, $CollageID);
2012-07-11 08:00:16 +00:00
}
2013-05-04 08:00:48 +00:00
}
2012-07-11 08:00:16 +00:00
2013-07-13 08:00:46 +00:00
$SQL = '
INSERT INTO collages_torrents
(GroupID, Sort, CollageID)
VALUES
' . implode(', ', $SQL) . '
2013-09-06 08:00:41 +00:00
ON DUPLICATE KEY UPDATE
Sort = VALUES (Sort)';
2012-07-11 08:00:16 +00:00
2013-05-04 08:00:48 +00:00
$DB->query($SQL);
}
2012-07-11 08:00:16 +00:00
2013-05-04 08:00:48 +00:00
} else {
$Sort = $_POST['sort'];
if (!is_number($Sort)) {
error(404);
2012-07-11 08:00:16 +00:00
}
2013-07-13 08:00:46 +00:00
$DB->query("
UPDATE collages_torrents
SET Sort = '$Sort'
WHERE CollageID = '$CollageID'
AND GroupID = '$GroupID'");
2013-05-04 08:00:48 +00:00
}
2013-02-22 08:00:24 +00:00
2013-07-13 08:00:46 +00:00
$Cache->delete_value("collage_$CollageID");
header("Location: collages.php?action=manage&collageid=$CollageID");