<?php
error_reporting(0);
if (!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit();}
close_browse();
global $db, $CcTvAi_com_userid;
if ($CcTvAi_com_userid) {
	if (!IsNumID($CcTvAi_com_userid)) {exit();}
	$cd_id=unescape(SafeRequest("pidArr", "post"));
	if (strstr($CcTvAi_com_points, "-")) {exit('002');}
	$row=$db->getrow("Select cd_uid from " . tname('pic') . " where cd_id in(" . $cd_id . ")");
	if ($row['cd_uid']==$CcTvAi_com_userid) {
		$query=$db->query("select cd_id,cd_uid,cd_uname,cd_url from " . tname('pic') . " where cd_id in(" . $cd_id . ")");
		while ($row=$db->fetch_array($query)) {
			//删除图片
			$db->query("delete from " . tname('pic') . " where cd_uid='" . $row['cd_uid'] . "' and cd_id='" . $row['cd_id'] . "'");
			//删除评论
			$db->query("delete from " . tname('comment') . " where cd_channel=7 and cd_dataid='" . $row['cd_id'] . "'");
			//惩罚经验
			if (cd_userdeletepicpoints>=1) { //大于1才记录
				//记录账单
				$setarr=array(
					'cd_type' => 0, //1为加,0为减
					'cd_uid' => $row['cd_uid'],
					'cd_uname' => $row['cd_uname'],
					'cd_icon' => 'album',
					'cd_title' => '照片被删除',
					'cd_points' => cd_userdeletepicpoints,
					'cd_addtime' => date('Y-m-d H:i:s')
				);
				inserttable('bill', $setarr, 1);
			}
			$db->query('update ' . tname('user') . " set cd_points=cd_points-'" . cd_userdeletepicpoints . "',cd_rank=cd_rank-'" . cd_userdeletepicrank . "' where cd_id='" . $CcTvAi_com_userid . "'");
			if (delunlink($row['cd_url'])==true) {
				@unlink("../upload/album/" . $row['cd_url'] . ".thumb." . fileext($row['cd_url']));
				@unlink("../upload/album/" . $row['cd_url'] . ".thumb_180x180." . fileext($row['cd_url']));
				@unlink("../upload/album/" . $row['cd_url']);
			}
		}
		exit('004');
	} else {
		exit('003');
	}
} else {
	exit('001');
}
?>