<?php
/**
* FILE_NAME : pictures.php
*
* @copyright Copyright (c) www.shuangyulin.com
* @author 双鱼林设计
* @package 前台图片展示
* @subpackage
* @version QQ:287307421或254540457
*/

require_once './include/common.inc.php';

/*--  对一些系统变量赋值  --*/
$template->assign("css_root",$css_root);
$template->assign("siteurl",$_CFG['siteurl']);
$template->assign("sitename",$_CFG['sitename']);

/*--  初始化 url 传值  --*/
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 1;

/*--  查询自己，判断url提交是否正确  --*/
$sql = $allpic = '';
$oneself = $cates = array();

$sql = "SELECT * FROM {$dbprefix}picturecontent WHERE prid = $id";
$oneself = $DB->fetch_one_array($sql);
if (!$oneself) {
	showmessage("您查看的页面不存在，3秒后跳到主页","inde.php");
}

/*--  查询父级分类，方便小导航显示  --*/
$sql = "SELECT catid,name,covertemplate,template FROM {$dbprefix}picturecategories WHERE catid = '".$oneself['catid']."'";
$parcate = $DB->fetch_one_array($sql);
$parcateurl = "picture.php?id=".$parcate['catid'];
$parcatename = $parcate['name'];

/*--  查询最新图片列表  --*/
$sql = "SELECT prid,catid,title FROM {$dbprefix}picturecontent ORDER BY dateline DESC LIMIT 10";
$query = $DB->query($sql);
while ($row = $DB->fetch_array($query)) {
	$row['sysurl'] = "pictures.php?id=".$row['prid'];
	$newpic[] = $row;
}

/*--  查询图片内容  --*/
$sql = "SELECT * FROM {$dbprefix}picturecontent WHERE prid = '".$id."'";
$query = $DB->query($sql);
while ($row = $DB->fetch_array($query)) {
	$row['sysurl'] = "pictures.php?id=".$row['prid'];
	/*--  处理图片内容  --*/
	$row['content'] = unserialize($row['content']);

	/*--  构造图片展示数组  --*/
	$piclist = array();
	for ($i=0;$i<count($row['content'])-2;$i++) {
		/*--  取扩展名  --*/
		$ext = strrchr($row['content'][$i],'.');
		$basename = basename($row['content'][$i],$ext);
		$row['thumb_name'] = $basename.'_thumb'.$ext;
		
		$piclist[$i]['thumb_name'] = $web_url.substr($row['content']['thumb_dir'],3).$row['thumb_name'];
		$piclist[$i]['url'] = $web_url.substr($row['content']['pic_dir'],3).'/'.$basename.$ext;
	}
	$piclist =$piclist;
}
/*--  更新浏览次数  --*/
$sql = "UPDATE {$dbprefix}picturecontent SET viewnum = '".($row['viewnum']+1)."' WHERE prid = '".$id."'";
$DB->query($sql);

/*--  当该分类的自定义模板为空，使用默认模板  --*/
$pagetpl = '';
if (!$parcate['template'] && !$parcate['covertemplate']) {	
	$pagetpl = "pictures.tpl";	
}
elseif ($parcate['covertemplate']) {
	$pagetpl = $parcate['covertemplate'];
}
elseif ($parcate['template']) {
	$pagetpl = $parcate['template'];
}

require_once 'header.php';

/*--  对模板进行赋值  --*/
$template->assign("oneselfname",$oneself['title']);
$template->assign("oneselurl",$php_self);

/*--  对父级分类赋值  --*/
$template->assign("parcateurl",$parcateurl);
$template->assign("parcatename",$parcatename);

/*--  对左边栏的最新图片赋值  --*/
$template->assign("newpic",$newpic);
/*--  对图片组赋值  --*/
$template->assign("piclist",$piclist);

$template->display($pagetpl);

require_once 'footer.php';
?>