<?php
/**
 *      [Dzz!] (C)2010-2011 dzz.cc
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: market_index.php 1000 2011-6-31 15:41:43 by angelrain $
 */
 /**
 * ============================================================================
 * 版权所有 2010-2011 Dzz!Desktop，并保留所有权利。
 * 网站地址: http://dzz.cc；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式、任何目的的再发布。
 * ============================================================================
*/
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$tospace = $pic = $blog = $album = $share = $poll = array();

include_once libfile('class/bbcode');
$bbcode = & bbcode::instance();
require_once './dzz/comment/function_comment.php';
if($_POST['idtype'] == 'uid' && ($seccodecheck || $secqaacheck)) {
	$seccodecheck = 0;
	$secqaacheck = 0;
}

if(submitcheck('commentsubmit', 0, $seccodecheck, $secqaacheck)) {
	if(!checkperm('allowcomment')) {
		showmessage('no_privilege_comment', '', array(), array('return' => true));
	}
	cknewuser();
	$waittime = interval_check('post');
	if($waittime > 0) {
		showmessage('operating_too_fast', '', array('waittime' => $waittime), array('return' => true));
	}

	$id = intval($_POST['id']);
	$idtype = $_POST['idtype'];
	$message = getstr($_POST['message'], 0, 1, 1, 2);
	$cid = empty($_POST['cid'])?0:intval($_POST['cid']);

	if(strlen($message) < 2) {
		showmessage('content_is_too_short', '', array(), array('return' => true));
	}
	$cidarr = add_comment($message, $id, $idtype, $cid);
	if($cidarr['cid'] != 0) {
		showmessage($cidarr['msg'], dreferer(), $cidarr['magvalues'], $_GET['quickcomment'] ? array('msgtype' => 3, 'showmsg' => true) : array('showdialog' => 3, 'showmsg' => true, 'closetime' => true));
	} else {
		showmessage('no_privilege_comment', '', array(), array('return' => true));
	}
}

$cid = empty($_GET['cid'])?0:intval($_GET['cid']);

if($_GET['do'] == 'edit') {
	if($_G['adminid'] != 1 && $_GET['modcommentkey'] != modauthkey($_GET['cid'])) {
		$sqladd = "AND authorid='$_G[uid]'";
	} else {
		$sqladd = '';
	}
	$query = DB::query("SELECT * FROM ".DB::table('dzz_comment')." WHERE cid='$cid' $sqladd");
	if(!$comment = dstripslashes(DB::fetch($query))) {
		showmessage('no_privilege_comment_edit');
	}

	if(submitcheck('editsubmit')) {

		$message = getstr($_POST['message'], 0, 1, 0, 2);
		if(strlen($message) < 2) showmessage('content_is_too_short');
		$message = censor($message);
		if(censormod($message)) {
			$comment_status = 1;
		} else {
			$comment_status = 0;
		}
		if($comment_status == 1) {
			manage_addnotify('verifycommontes');
		}
		DB::update('dzz_comment', array('message'=>$message, 'status'=>$comment_status), array('cid' => $comment['cid']));
		showmessage('do_success', dreferer(), array('cid' => $comment['cid'],'message'=>$message,'idtype' => $comment['idtype']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
	}

	$comment['message'] = $bbcode->html2bbcode($comment['message']);

} elseif($_GET['do'] == 'delete') {
	$pcid=intval($_GET['pcid']);
	$comment=DB::fetch_first('select * from '.DB::table('dzz_comment')." where cid='{$cid}'");
	if(submitcheck('deletesubmit')) {
		$setarr=array($cid);
		if($cid>0){
			$query=DB::query("SELECT cid  FROM ".DB::table('dzz_comment')." WHERE pcid='$cid' ");
			while($value=DB::fetch($query)){
				$setarr[]=$value['cid'];
			}
		}
		if(dzz_deletecomments($setarr)) {
			showmessage('do_success', dreferer(), array('cid' => $cid,'pcid'=>$pcid,'idtype'=>$comment['idtype'],'id'=>$comment['id']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
		} else {
			showmessage('no_privilege');
		}
	}
} elseif($_GET['do'] == 'reply') {
	$pcid=intval($_GET['pcid']);
	$query = DB::query("SELECT * FROM ".DB::table('dzz_comment')." WHERE cid='$cid'");
	if(!$comment = DB::fetch($query)) {
		showmessage('comments_do_not_exist');
	}
	if($comment['idtype'] == 'uid' && ($seccodecheck || $secqaacheck)) {
		$seccodecheck = 0;
		$secqaacheck = 0;
	}
} else {

	showmessage('undefined_action');
}

include dzztemplate('comment/comment');
?>