punbb/delete.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 5 e3d7322305bf
equal deleted inserted replaced
1:8f6143115bf5 2:a8a21e1c7afa
    21   MA  02111-1307  USA
    21   MA  02111-1307  USA
    22 
    22 
    23 ************************************************************************/
    23 ************************************************************************/
    24 
    24 
    25 
    25 
    26 define('PUN_ROOT', './');
    26 //define('PUN_ROOT', './');
    27 require PUN_ROOT.'include/common.php';
    27 //require PUN_ROOT.'include/common.php';
       
    28 
       
    29 global $pun_db, $pun_user, $pun_config, $lang_common;
       
    30 
    28 
    31 
    29 
    32 
    30 if ($pun_user['g_read_board'] == '0')
    33 if ($pun_user['g_read_board'] == '0')
    31 	message($lang_common['No view']);
    34 	message($lang_common['No view']);
    32 
    35 
    34 $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
    37 $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
    35 if ($id < 1)
    38 if ($id < 1)
    36 	message($lang_common['Bad request']);
    39 	message($lang_common['Bad request']);
    37 
    40 
    38 // Fetch some info about the post, the topic and the forum
    41 // Fetch some info about the post, the topic and the forum
    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());
    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());
    40 if (!$db->num_rows($result))
    43 if (!$pun_db->num_rows($result))
    41 	message($lang_common['Bad request']);
    44 	message($lang_common['Bad request']);
    42 
    45 
    43 $cur_post = $db->fetch_assoc($result);
    46 $cur_post = $pun_db->fetch_assoc($result);
    44 
    47 
    45 // Sort out who the moderators are and if we are currently a moderator (or an admin)
    48 // Sort out who the moderators are and if we are currently a moderator (or an admin)
    46 $mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
    49 $mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
    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;
    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;
    48 
    51 
    49 // Determine whether this post is the "topic post" or not
    52 // Determine whether this post is the "topic post" or not
    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());
    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());
    51 $topic_post_id = $db->result($result);
    54 $topic_post_id = $pun_db->result($result);
    52 
    55 
    53 $is_topic_post = ($id == $topic_post_id) ? true : false;
    56 $is_topic_post = ($id == $topic_post_id) ? true : false;
    54 
    57 
    55 // Do we have permission to edit this post?
    58 // Do we have permission to edit this post?
    56 if (($pun_user['g_delete_posts'] == '0' ||
    59 if (($pun_user['g_delete_posts'] == '0' ||
    75 	{
    78 	{
    76 		// Delete the topic and all of it's posts
    79 		// Delete the topic and all of it's posts
    77 		delete_topic($cur_post['tid']);
    80 		delete_topic($cur_post['tid']);
    78 		update_forum($cur_post['fid']);
    81 		update_forum($cur_post['fid']);
    79 
    82 
    80 		redirect('viewforum.php?id='.$cur_post['fid'], $lang_delete['Topic del redirect']);
    83 		pun_redirect('viewforum.php?id='.$cur_post['fid'], $lang_delete['Topic del redirect']);
    81 	}
    84 	}
    82 	else
    85 	else
    83 	{
    86 	{
    84 		// Delete just this one post
    87 		// Delete just this one post
    85 		delete_post($id, $cur_post['tid']);
    88 		delete_post($id, $cur_post['tid']);
    86 		update_forum($cur_post['fid']);
    89 		update_forum($cur_post['fid']);
    87 
    90 
    88 		redirect('viewtopic.php?id='.$cur_post['tid'], $lang_delete['Post del redirect']);
    91 		pun_redirect('viewtopic.php?id='.$cur_post['tid'], $lang_delete['Post del redirect']);
    89 	}
    92 	}
    90 }
    93 }
    91 
    94 
    92 
    95 
    93 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_delete['Delete post'];
    96 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_delete['Delete post'];