<?php

/*
	[Discuz!] (C)2001-2006 Comsenz Technology Ltd.
	This is NOT a freeware, use is subject to license terms

	$RCSfile: magic_del.inc.php,v $
	$Revision: 1.7 $
	$Date: 2007/01/22 07:38:39 $
*/

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

if(submitcheck('usesubmit')) {

	if(empty($pid)) {
		showmessage('magics_info_nonexistence');
	}

	$post = getpostinfo($pid, 'pid', array('tid', 'fid', 'authorid', 'first'));
	checkmagicperm($magicperm['forum'], $post['fid']);

	if($post['authorid'] != $discuz_uid) {
		showmessage('magics_operation_nopermission');
	}

	require_once DISCUZ_ROOT.'./include/post.func.php';

	if($post['first']) {
		foreach(array('threads', 'threadsmod', 'relatedthreads', 'posts', 'polls', 'polloptions', 'trades', 'activities', 'activityapplies', 'attachments', 'favorites', 'mythreads', 'myposts', 'subscriptions') as $value) {
			$db->query("DELETE FROM {$tablepre}$value WHERE tid='$post[tid]'", 'UNBUFFERED');
		}
		updateforumcount($post['fid']);
	} else {
		$db->query("DELETE FROM {$tablepre}posts WHERE pid='$pid'", 'UNBUFFERED');
		$db->query("DELETE FROM {$tablepre}myposts WHERE pid='$pid'", 'UNBUFFERED');
		$db->query("DELETE FROM {$tablepre}attachments WHERE pid='$pid'", 'UNBUFFERED');
		updatethreadcount($post['tid']);
	}

	usemagic($magicid, $magic['num']);
	updatemagiclog($magicid, '2', '1', '0', '0', $pid);
	showmessage('magics_operation_succeed', 'magic.php?action=user');

}

function showmagic() {
	global $pid, $lang;
	magicshowtype($lang['option'], 'top');
	magicshowsetting($lang['target_pid'], 'pid', $pid, 'text');
	magicshowtype('', 'bottom');
}

?>