punbb/delete.php
changeset 7 98bbc533541c
equal deleted inserted replaced
6:5e1f1e916419 7:98bbc533541c
       
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2008  PunBB.org
       
     5 
       
     6   This file is part of PunBB.
       
     7 
       
     8   PunBB is free software; you can redistribute it and/or modify it
       
     9   under the terms of the GNU General Public License as published
       
    10   by the Free Software Foundation; either version 2 of the License,
       
    11   or (at your option) any later version.
       
    12 
       
    13   PunBB is distributed in the hope that it will be useful, but
       
    14   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16   GNU General Public License for more details.
       
    17 
       
    18   You should have received a copy of the GNU General Public License
       
    19   along with this program; if not, write to the Free Software
       
    20   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
       
    21   MA  02111-1307  USA
       
    22 
       
    23 ************************************************************************/
       
    24 
       
    25 
       
    26 // if (!defined('PUN_ROOT'))
       
    27 // 	define('PUN_ROOT', './');
       
    28 // require PUN_ROOT.'include/common.php';
       
    29 
       
    30 // import globals (I really hope this isn't dangerous)
       
    31 foreach ( $GLOBALS as $key => $_ )
       
    32 {
       
    33   $$key =& $GLOBALS[$key];
       
    34 }
       
    35 
       
    36 ($hook = get_hook('dl_start')) ? eval($hook) : null;
       
    37 
       
    38 if ($pun_user['g_read_board'] == '0')
       
    39 	message($lang_common['No view']);
       
    40 
       
    41 // Load the delete.php language file
       
    42 require PUN_ROOT.'lang/'.$pun_user['language'].'/delete.php';
       
    43 
       
    44 
       
    45 $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
       
    46 if ($id < 1)
       
    47 	message($lang_common['Bad request']);
       
    48 
       
    49 
       
    50 // Fetch some info about the post, the topic and the forum
       
    51 $query = array(
       
    52 	'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.first_post_id, t.closed, p.poster, p.poster_id, p.message, p.hide_smilies',
       
    53 	'FROM'		=> 'posts AS p',
       
    54 	'JOINS'		=> array(
       
    55 		array(
       
    56 			'INNER JOIN'	=> 'topics AS t',
       
    57 			'ON'			=> 't.id=p.topic_id'
       
    58 		),
       
    59 		array(
       
    60 			'INNER JOIN'	=> 'forums AS f',
       
    61 			'ON'			=> 'f.id=t.forum_id'
       
    62 		),
       
    63 		array(
       
    64 			'LEFT JOIN'		=> 'forum_perms AS fp',
       
    65 			'ON'			=> '(fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].')'
       
    66 		)
       
    67 	),
       
    68 	'WHERE'		=> '(fp.read_forum IS NULL OR fp.read_forum=1) AND p.id='.$id
       
    69 );
       
    70 
       
    71 ($hook = get_hook('dl_qr_get_post_info')) ? eval($hook) : null;
       
    72 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
       
    73 if (!$pun_db->num_rows($result))
       
    74 	message($lang_common['Bad request']);
       
    75 
       
    76 $cur_post = $pun_db->fetch_assoc($result);
       
    77 
       
    78 // Sort out who the moderators are and if we are currently a moderator (or an admin)
       
    79 $mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
       
    80 $pun_user['is_admmod'] = ($session->user_level >= USER_LEVEL_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
       
    81 
       
    82 $cur_post['is_topic'] = ($id == $cur_post['first_post_id']) ? true : false;
       
    83 
       
    84 // Do we have permission to delete this post?
       
    85 if (($pun_user['g_delete_posts'] == '0' ||
       
    86 	($pun_user['g_delete_topics'] == '0' && $cur_post['is_topic']) ||
       
    87 	$cur_post['poster_id'] != $pun_user['id'] ||
       
    88 	$cur_post['closed'] == '1') &&
       
    89 	!$pun_user['is_admmod'])
       
    90 	message($lang_common['No permission']);
       
    91 
       
    92 
       
    93 // User pressed the cancel button
       
    94 if (isset($_POST['cancel']))
       
    95 	pun_redirect(pun_link($pun_url['post'], $id), $lang_common['Cancel redirect']);
       
    96 
       
    97 // User pressed the delete button
       
    98 else if (isset($_POST['delete']))
       
    99 {
       
   100 	($hook = get_hook('dl_form_submitted')) ? eval($hook) : null;
       
   101 
       
   102 	if (isset($_POST['req_confirm']))
       
   103 	{
       
   104 		if ($cur_post['is_topic'])
       
   105 		{
       
   106 			// Delete the topic and all of it's posts
       
   107 			delete_topic($cur_post['tid'], $cur_post['fid']);
       
   108 
       
   109 			pun_redirect(pun_link($pun_url['forum'], $cur_post['fid']), $lang_delete['Topic del redirect']);
       
   110 		}
       
   111 		else
       
   112 		{
       
   113 			// Delete just this one post
       
   114 			delete_post($id, $cur_post['tid'], $cur_post['fid']);
       
   115 
       
   116 			pun_redirect(pun_link($pun_url['topic'], $cur_post['tid']), $lang_delete['Post del redirect']);
       
   117 		}
       
   118 	}
       
   119 	else
       
   120 		pun_redirect(pun_link($pun_url['post'], $id), $lang_common['No confirm redirect']);
       
   121 }
       
   122 
       
   123 // Run the post through the parser
       
   124 require PUN_ROOT.'include/parser.php';
       
   125 $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
       
   126 
       
   127 // Setup form
       
   128 $pun_page['set_count'] = $pun_page['fld_count'] = 0;
       
   129 $pun_page['form_action'] = pun_link($pun_url['delete'], $id);
       
   130 
       
   131 $pun_page['hidden_fields'][] = '<input type="hidden" name="form_sent" value="1" />';
       
   132 if ($pun_user['is_admmod'])
       
   133 	$pun_page['hidden_fields'][] = '<input type="hidden" name="csrf_token" value="'.generate_form_token($pun_page['form_action']).'" />';
       
   134 
       
   135 // Setup form information
       
   136 $pun_page['frm_info'] = array(
       
   137 	'<li><span><strong>'.$lang_common['Forum'].':</strong> '.htmlspecialchars($cur_post['forum_name']).'</span></li>',
       
   138 	'<li><span><strong>'.$lang_common['Topic'].':</strong> '.htmlspecialchars($cur_post['subject']).'</span></li>',
       
   139 	'<li><span>'.sprintf((($cur_post['is_topic']) ? $lang_delete['Delete topic info'] : $lang_delete['Delete post info']), $cur_post['poster'], format_time($cur_post['posted'])).'</span></li>'
       
   140 );
       
   141 
       
   142 // Setup main heading
       
   143 $pun_page['main_head'] = sprintf(($cur_post['is_topic']) ? $lang_delete['Delete topic head'] : $lang_delete['Delete post head'], $cur_post['poster'], format_time($cur_post['posted']));
       
   144 
       
   145 // Setup breadcrumbs
       
   146 $pun_page['crumbs'] = array(
       
   147 	array($pun_config['o_board_title'], pun_link($pun_url['index'])),
       
   148 	array($cur_post['forum_name'], pun_link($pun_url['forum'], $cur_post['fid'])),
       
   149 	array($cur_post['subject'], pun_link($pun_url['topic'], $cur_post['tid'])),
       
   150 	(($cur_post['is_topic']) ? $lang_delete['Delete topic'] : $lang_delete['Delete post'])
       
   151 );
       
   152 
       
   153 ($hook = get_hook('dl_pre_header_load')) ? eval($hook) : null;
       
   154 
       
   155 define ('PUN_PAGE', 'postdelete');
       
   156 require PUN_ROOT.'header.php';
       
   157 
       
   158 ?>
       
   159 <div id="pun-main" class="main">
       
   160 
       
   161 	<h1><span><?php echo end($pun_page['crumbs']) ?></span></h1>
       
   162 
       
   163 	<div class="main-head">
       
   164 		<h2><span><?php echo $pun_page['main_head'] ?></span></h2>
       
   165 	</div>
       
   166 	<div class="main-content frm">
       
   167 		<div class="frm-info">
       
   168 			<ul>
       
   169 				<?php echo implode("\n\t\t\t\t", $pun_page['frm_info'])."\n" ?>
       
   170 			</ul>
       
   171 		</div>
       
   172 		<div class="post-entry">
       
   173 			<div class="entry-content">
       
   174 				<?php echo $cur_post['message']."\n" ?>
       
   175 			</div>
       
   176 		</div>
       
   177 		<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $pun_page['form_action'] ?>">
       
   178 			<div class="hidden">
       
   179 				<?php echo implode("\n\t\t\t\t", $pun_page['hidden_fields'])."\n" ?>
       
   180 			</div>
       
   181 			<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
       
   182 				<legend class="frm-legend"><strong><?php echo $lang_delete['Delete post'] ?></strong></legend>
       
   183 				<div class="checkbox radbox">
       
   184 					<label for="fld<?php echo ++$pun_page['fld_count'] ?>"><span class="fld-label"><?php echo $lang_common['Please confirm'] ?></span><br /><input type="checkbox" id="fld<?php echo $pun_page['fld_count'] ?>" name="req_confirm" value="1" checked="checked" /> <?php printf(((($cur_post['is_topic'])) ? $lang_delete['Delete topic head'] : $lang_delete['Delete post head']), $cur_post['poster'], format_time($cur_post['posted'])) ?>.</label>
       
   185 				</div>
       
   186 			</fieldset>
       
   187 			<div class="frm-buttons">
       
   188 				<span class="submit"><input type="submit" name="delete" value="<?php echo $lang_delete['Delete'] ?>" /></span>
       
   189 				<span class="cancel"><input type="submit" name="cancel" value="<?php echo $lang_common['Cancel'] ?>" /></span>
       
   190 			</div>
       
   191 		</form>
       
   192 	</div>
       
   193 
       
   194 </div>
       
   195 <?php
       
   196 
       
   197 ($hook = get_hook('dl_end')) ? eval($hook) : null;
       
   198 
       
   199 require PUN_ROOT.'footer.php';