punbb/delete.php
author Dan
Wed, 11 Jul 2007 21:01:48 -0400
changeset 0 f9ffdbd96607
child 2 a8a21e1c7afa
permissions -rw-r--r--
Initial population
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     1
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     2
/***********************************************************************
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     3
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     5
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     7
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    12
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    17
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    22
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    23
************************************************************************/
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    24
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    25
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    26
define('PUN_ROOT', './');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    27
require PUN_ROOT.'include/common.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    28
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    29
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    30
if ($pun_user['g_read_board'] == '0')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    31
	message($lang_common['No view']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    32
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    33
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    34
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    35
if ($id < 1)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    36
	message($lang_common['Bad request']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    37
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    38
// Fetch some info about the post, the topic and the forum
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    39
$result = $db->query('SELECT f.id AS fid, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.id AS tid, t.subject, t.posted, t.closed, p.poster, p.poster_id, p.message, p.hide_smilies FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.id='.$id) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    40
if (!$db->num_rows($result))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    41
	message($lang_common['Bad request']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    42
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    43
$cur_post = $db->fetch_assoc($result);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    44
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    45
// Sort out who the moderators are and if we are currently a moderator (or an admin)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    46
$mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    47
$is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    48
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    49
// Determine whether this post is the "topic post" or not
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    50
$result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$cur_post['tid'].' ORDER BY posted LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    51
$topic_post_id = $db->result($result);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    52
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    53
$is_topic_post = ($id == $topic_post_id) ? true : false;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    54
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    55
// Do we have permission to edit this post?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    56
if (($pun_user['g_delete_posts'] == '0' ||
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    57
	($pun_user['g_delete_topics'] == '0' && $is_topic_post) ||
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
	$cur_post['poster_id'] != $pun_user['id'] ||
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    59
	$cur_post['closed'] == '1') &&
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    60
	!$is_admmod)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    61
	message($lang_common['No permission']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
// Load the delete.php language file
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    64
require PUN_ROOT.'lang/'.$pun_user['language'].'/delete.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    65
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    67
if (isset($_POST['delete']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    68
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    69
	if ($is_admmod)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
		confirm_referrer('delete.php');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
	require PUN_ROOT.'include/search_idx.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
	if ($is_topic_post)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    76
		// Delete the topic and all of it's posts
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
		delete_topic($cur_post['tid']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    78
		update_forum($cur_post['fid']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
		redirect('viewforum.php?id='.$cur_post['fid'], $lang_delete['Topic del redirect']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    82
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    83
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    84
		// Delete just this one post
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
		delete_post($id, $cur_post['tid']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
		update_forum($cur_post['fid']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    87
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    88
		redirect('viewtopic.php?id='.$cur_post['tid'], $lang_delete['Post del redirect']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    89
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    90
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    91
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    92
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    93
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_delete['Delete post'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    94
require PUN_ROOT.'header.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    95
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    96
require PUN_ROOT.'include/parser.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   100
<div class="linkst">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   101
	<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   102
		<ul><li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li><li>&nbsp;&raquo;&nbsp;<a href="viewforum.php?id=<?php echo $cur_post['fid'] ?>"><?php echo pun_htmlspecialchars($cur_post['forum_name']) ?></a></li><li>&nbsp;&raquo;&nbsp;<?php echo pun_htmlspecialchars($cur_post['subject']) ?></li></ul>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   103
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   104
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   105
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   106
<div class="blockform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
	<h2><span><?php echo $lang_delete['Delete post'] ?></span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
	<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
		<form method="post" action="delete.php?id=<?php echo $id ?>">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   110
			<div class="inform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   111
				<fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   112
					<legend class="warntext"><?php echo $lang_delete['Warning'] ?></legend>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
					<div class="infldset">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   114
						<div class="postmsg">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
							<p><?php echo $lang_common['Author'] ?>: <strong><?php echo pun_htmlspecialchars($cur_post['poster']) ?></strong></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
							<?php echo $cur_post['message'] ?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
						</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   118
					</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
				</fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   120
			</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
			<p><input type="submit" name="delete" value="<?php echo $lang_delete['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
		</form>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   123
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   125
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
require PUN_ROOT.'footer.php';