punbb/delete.php
author Dan
Thu, 12 Jul 2007 01:04:01 -0400
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 5 e3d7322305bf
permissions -rw-r--r--
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
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
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    26
//define('PUN_ROOT', './');
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    27
//require PUN_ROOT.'include/common.php';
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    28
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    29
global $pun_db, $pun_user, $pun_config, $lang_common;
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    30
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    31
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    32
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    33
if ($pun_user['g_read_board'] == '0')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    34
	message($lang_common['No view']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    35
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    36
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    37
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    38
if ($id < 1)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    39
	message($lang_common['Bad request']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    40
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    41
// Fetch some info about the post, the topic and the forum
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    42
$result = $pun_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 '.$pun_db->prefix.'posts AS p INNER JOIN '.$pun_db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$pun_db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$pun_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__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    43
if (!$pun_db->num_rows($result))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    44
	message($lang_common['Bad request']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    45
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    46
$cur_post = $pun_db->fetch_assoc($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    47
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    48
// Sort out who the moderators are and if we are currently a moderator (or an admin)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    49
$mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    50
$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
    51
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    52
// Determine whether this post is the "topic post" or not
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    53
$result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'posts WHERE topic_id='.$cur_post['tid'].' ORDER BY posted LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    54
$topic_post_id = $pun_db->result($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    55
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    56
$is_topic_post = ($id == $topic_post_id) ? true : false;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    57
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
// Do we have permission to edit this post?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    59
if (($pun_user['g_delete_posts'] == '0' ||
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    60
	($pun_user['g_delete_topics'] == '0' && $is_topic_post) ||
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    61
	$cur_post['poster_id'] != $pun_user['id'] ||
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
	$cur_post['closed'] == '1') &&
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
	!$is_admmod)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    64
	message($lang_common['No permission']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    65
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
// Load the delete.php language file
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    67
require PUN_ROOT.'lang/'.$pun_user['language'].'/delete.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    68
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    69
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
if (isset($_POST['delete']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
	if ($is_admmod)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
		confirm_referrer('delete.php');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
	require PUN_ROOT.'include/search_idx.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    76
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
	if ($is_topic_post)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    78
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
		// Delete the topic and all of it's posts
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
		delete_topic($cur_post['tid']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
		update_forum($cur_post['fid']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    82
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    83
		pun_redirect('viewforum.php?id='.$cur_post['fid'], $lang_delete['Topic del redirect']);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    84
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    87
		// Delete just this one post
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    88
		delete_post($id, $cur_post['tid']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    89
		update_forum($cur_post['fid']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    90
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    91
		pun_redirect('viewtopic.php?id='.$cur_post['tid'], $lang_delete['Post del redirect']);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    92
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    93
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    94
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    95
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    96
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_delete['Delete post'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
require PUN_ROOT.'header.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
require PUN_ROOT.'include/parser.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   100
$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   101
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   102
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   103
<div class="linkst">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   104
	<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   105
		<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
   106
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
<div class="blockform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   110
	<h2><span><?php echo $lang_delete['Delete post'] ?></span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   111
	<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   112
		<form method="post" action="delete.php?id=<?php echo $id ?>">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
			<div class="inform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   114
				<fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
					<legend class="warntext"><?php echo $lang_delete['Warning'] ?></legend>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
					<div class="infldset">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
						<div class="postmsg">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   118
							<p><?php echo $lang_common['Author'] ?>: <strong><?php echo pun_htmlspecialchars($cur_post['poster']) ?></strong></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
							<?php echo $cur_post['message'] ?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   120
						</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
					</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
				</fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   123
			</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
			<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
   125
		</form>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   128
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   129
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   130
require PUN_ROOT.'footer.php';