<?php
/**
* FILE_NAME : produces.php
*
* @copyright Copyright (c) 2009 - 2010 www.dali.edu.cn
* @author DaLi University 2009 Graduation Design
* @package 前台商品详细信息页
* @subpackage
* @version Tue Nov 03 12:48:54 GMT 2009
*/

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}produces WHERE prid = $id";
$oneself = $DB->fetch_one_array($sql);
if (!$oneself) {
	showmessage("您查看的页面不存在，3秒后跳到主页","inde.php");
}

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

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

/*--  查询商品详细内容  --*/
$sql = "SELECT p.prid,p.catid,p.title,p.username,p.note,p.coverpic,p.dateline,p.viewnum,c.prid,c.content FROM {$dbprefix}produces p LEFT JOIN {$dbprefix}producecontent c ON p.prid = c.prid WHERE p.prid = '".$id."'";
$query = $DB->query($sql);
while ($row = $DB->fetch_array($query)) {
	$row['sysurl'] = "produces.php?id=".$row['prid'];
	$row['dateline'] = formatdate($_CFG['format_type'],$row['dateline']);
	/*--  处理封面图片  --*/
	$row['coverpic'] = unserialize($row['coverpic']);
	//处理封面图片的路径
	$row['coverpic'] = $web_url.substr($row['coverpic']['cover_dir'],3).$row['coverpic']['cover_name'];
	$produce = $row;
}
/*--  更新浏览次数  --*/
$sql = "UPDATE {$dbprefix}produces SET viewnum = '".($row['viewnum']+1)."' WHERE prid = '".$id."'";
$DB->query($sql);

/*--  当该分类的自定义模板为空，使用默认模板  --*/
$pagetpl = '';
if (!$parcate['template'] && !$parcate['covertemplate']) {	
	$pagetpl = "produces.html";	
}
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("newpro",$newpro);

/*--  对商品详细信息赋值  --*/
$template->assign("pro_title",$produce['title']);
$template->assign("pro_note",$produce['note']);
$template->assign("pro_coverpic",$produce['coverpic']);
$template->assign("pro_dateline",$produce['dateline']);
$template->assign("pro_viewnum",$produce['viewnum']);
$template->assign("pro_content",$produce['content']);

$template->display($pagetpl);

require_once 'footer.php';
?>