Gazelle/sections/collages/edit_handle.php

73 lines
2.9 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
authorize();
$CollageID = $_POST['collageid'];
2012-11-03 08:00:19 +00:00
if (!is_number($CollageID)) {
error(0);
}
2011-03-28 14:21:28 +00:00
2012-11-03 08:00:19 +00:00
$DB->query("SELECT UserID, CategoryID, Locked, MaxGroups, MaxGroupsPerUser FROM collages WHERE ID='$CollageID'");
list($UserID, $CategoryID, $Locked, $MaxGroups, $MaxGroupsPerUser) = $DB->next_record();
if ($CategoryID == 0 && $UserID != $LoggedUser['ID'] && !check_perms('site_collages_delete')) {
error(403);
}
2011-03-28 14:21:28 +00:00
2011-04-29 13:49:03 +00:00
$DB->query("SELECT ID,Deleted FROM collages WHERE Name='".db_string($_POST['name'])."' AND ID!='$CollageID' LIMIT 1");
2012-11-03 08:00:19 +00:00
if ($DB->record_count()) {
2011-04-29 13:49:03 +00:00
list($ID, $Deleted) = $DB->next_record();
2012-11-03 08:00:19 +00:00
if ($Deleted) {
2011-04-29 13:49:03 +00:00
$Err = 'A collage with that name already exists but needs to be recovered, please <a href="staffpm.php">contact</a> the staff team!';
} else {
2012-11-03 08:00:19 +00:00
$Err = "A collage with that name already exists: <a href=\"/collages.php?id=$ID\">$_POST[name]</a>.";
2011-04-29 13:49:03 +00:00
}
2012-11-03 08:00:19 +00:00
$ErrNoEscape = true;
include(SERVER_ROOT.'/sections/collages/edit.php');
die();
2011-04-29 13:49:03 +00:00
}
2011-03-28 14:21:28 +00:00
$TagList = explode(',',$_POST['tags']);
2012-11-03 08:00:19 +00:00
foreach ($TagList as $ID=>$Tag) {
2012-10-11 08:00:15 +00:00
$TagList[$ID] = Misc::sanitize_tag($Tag);
2011-03-28 14:21:28 +00:00
}
$TagList = implode(' ',$TagList);
2012-11-03 08:00:19 +00:00
$Updates = array("Description='".db_string($_POST['description'])."', TagList='".db_string($TagList)."'");
2011-03-28 14:21:28 +00:00
if (!check_perms('site_collages_delete') && ($CategoryID == 0 && $UserID == $LoggedUser['ID'] && check_perms('site_collages_renamepersonal'))) {
2012-11-03 08:00:19 +00:00
if (!stristr($_POST['name'], $LoggedUser['Username'])) {
error("Your personal collage's title must include your username.");
}
}
if (isset($_POST['featured']) && $CategoryID == 0 && (($LoggedUser['ID'] == $UserID && check_perms('site_collages_personal')) || check_perms('site_collages_delete'))) {
$DB->query("UPDATE collages SET Featured=0 WHERE CategoryID=0 and UserID=$UserID");
2012-11-03 08:00:19 +00:00
$Updates[] = 'Featured=1';
}
if (check_perms('site_collages_delete') || ($CategoryID == 0 && $UserID == $LoggedUser['ID'] && check_perms('site_collages_renamepersonal'))) {
2012-11-03 08:00:19 +00:00
$Updates[] = "Name='".db_string($_POST['name'])."'";
}
if (isset($_POST['category']) && !empty($CollageCats[$_POST['category']]) && $_POST['category'] != $CategoryID && ($_POST['category'] != 0 || check_perms('site_collages_delete'))) {
$Updates[] = 'CategoryID='.$_POST['category'];
2011-03-28 14:21:28 +00:00
}
2012-11-03 08:00:19 +00:00
if (check_perms('site_collages_delete')) {
if (isset($_POST['locked']) != $Locked) {
$Updates[] = 'Locked=' . ($Locked ? "'0'" : "'1'");
}
if (isset($_POST['maxgroups']) && ($_POST['maxgroups'] == 0 || is_number($_POST['maxgroups'])) && $_POST['maxgroups'] != $MaxGroups) {
$Updates[] = 'MaxGroups=' . $_POST['maxgroups'];
}
if (isset($_POST['maxgroups']) && ($_POST['maxgroupsperuser'] == 0 || is_number($_POST['maxgroupsperuser'])) && $_POST['maxgroupsperuser'] != $MaxGroupsPerUser) {
$Updates[] = 'MaxGroupsPerUser=' . $_POST['maxgroupsperuser'];
}
2011-03-28 14:21:28 +00:00
}
2012-11-03 08:00:19 +00:00
if (!empty($Updates)) {
$DB->query("UPDATE collages SET ".implode(', ', $Updates)." WHERE ID=$CollageID");
}
2011-03-28 14:21:28 +00:00
$Cache->delete_value('collage_'.$CollageID);
header('Location: collages.php?id='.$CollageID);
?>