<?php
$conf_basedir	= "../../";	//相对主目录的位置
$conf_where		= "admin";	//选择调用相应模块
$directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
include_once($conf_basedir."base.inc.php");
checkAuth('15');	//判断登录和权限

$id = intval($id);

$infoarr = $dbback->GetRow("select id,housetbl,houseid,sort,info,surface from admin_house_check_log where id = '".$id."' and oper = 1");

if($infoarr['id'] > 0)
{
	$sql = "select count(*) from upload where tbl='".$infoarr['housetbl']."' and rowid='".$infoarr['houseid']."' and sort='".$infoarr['sort']."' and flg in (0,1)";
	$sortnum = $db->GetOne($sql);

	if($infoarr['sort'] == 2 && $sortnum >= 10)
	{
		echo "<script>alert('该房源的室内图已满10张。');</script>";
	}
	else if($infoarr['sort'] == 1 && $sortnum >= 5)
	{
		echo "<script>alert('该房源的外景图已满5张。');</script>";
	}
	else if($infoarr['sort'] == 0 && $sortnum >= 3)
	{
		echo "<script>alert('该房源的户型图已满3张。');</script>";
	}
	else
	{
		$time = time();
		$arr = array();
		$arr['tbl'] = $infoarr['housetbl'];
		$arr['rowid'] = $infoarr['houseid'];
		$arr['position'] = 'pic'.$time;
		$arr['filename'] = $infoarr['info'];
		$arr['sort'] = $infoarr['sort'];
		$arr['createtime'] = $time;
		$arr['flg'] = 0;
		$arr['isfrom'] = 2;
		$q = insert_sql("upload", $arr);
		$db->Execute($q);

        if($infoarr['surface'] == 1)
        {
            $q = "UPDATE ".$infoarr['housetbl']." set pic1 = '".$infoarr['info']."' where id = '".$infoarr['houseid']."'";
            $db->Execute($q);
            $moremsg = "该图已恢复为房源封面图！~";
        }

		$db->execute("update admin_house_check_log set oper = 3 where id = '".$id."'");
		echo "<script>alert('记录恢复成功。".$moremsg."');</script>";
	}
}
else
{
	echo "<script>alert('记录不存在或已恢复。');</script>";
}

echo "<script>window.opener.search_form.submit();window.close();</script>";
exit;
?>