<?php

define('CURSCRIPT', 'product');
require_once './engine/common.inc.php';
require_once './engine/attachment.func.php';
require_once './clientdata/cache/cache_navigation.php';
require_once './engine/gateweicode.func.php';
$rpp=5;
$productid=isset($productid)?intval($productid):0;
$curpage=isset($page)?$page:1;
$startrecord=($curpage-1)*$rpp;
$floor=($curpage==1)?2:(($curpage-1)*$rpp+2);

	$q = $db->query("SELECT a.* , b.* , c.storename FROM g_product_content b , g_products a left join g_attachments c On a.productid=c.bid and  c.typeid=2 and c.islogo=1 where a.productid=$productid and a.productid=b.productid");
	$allproduct=$db->fetch_array($q);
	if($allproduct['storename']){
	$allproduct['logo']="./clientdata/attachment/product/".replaceimg($allproduct['storename']);
	}else{
	$allproduct['logo']="./images/common/g_non_image.gif";
	}
	$view=++$allproduct['view'];
	$categoryid=$allproduct['categoryid'];
$siteheadtitle=implode(' ',array($allproduct['producttitle'],$productcategory[$categoryid]['categorytitle'],$productname,$sitename,$sitekeywords));
	$db->query("UPDATE g_products SET view = $view WHERE productid =$productid LIMIT 1");
	$aq = $db->query("SELECT * FROM g_attachments WHERE bid=$productid and typeid=2");
	/* add icon index into attach array */
	while($q_attachs=$db->fetch_array($aq)){
		$q_attachs['icon']=attachtype(fileext($q_attachs['storename'])."\t".$q_attachs['type']);
		$allattachs[$q_attachs['fid']]=$q_attachs;
	}
	$rq=$db->query("SELECT a.*,b.uid,b.userid,b.userface,b.gid,b.postcount,b.registertime FROM g_replys a left join g_members b ON a.reply_uid=b.uid where a.typeid = 2 and a.bid = $productid limit $startrecord,$rpp");

		while($q_reply=$db->fetch_array($rq)){
			$q_reply=ismemberexist($q_reply);
			$replys[]=$q_reply;
			$raq = $db->query("SELECT * FROM g_attachments WHERE bid = {$q_reply['rid']} and typeid=4");
				while($q_attachs=$db->fetch_array($raq)){
					$q_attachs['icon']=attachtype(fileext($q_attachs['storename'])."\t".$q_attachs['type']);
					$replyattachs[$q_reply['rid']][$q_attachs['fid']]=$q_attachs;
	}
}

$totalrecord=$db->result($db->query("SELECT count(*) FROM g_replys WHERE typeid = 2 and bid = $productid"),0);
$allproduct['productintro']=nl2br($allproduct['productintro']);
$message=gateweicode($allproduct['content']);

foreach($replys as $key => $val){
	$rrrid=$val['rid'];
	$replys[$key]['content']=gateweicode($val['content']);
	$replys[$key]['ip']=$val['ip1'].'.'.$val['ip2'].'.*.*';//此处设置调整显示ip显示的位数
	$replys[$key]['floor']=$floor;
	$floor++;
}

if(!empty($allattachs)){
		foreach($allattachs as $key => $val){
				if(!in_array($key,$displayattachs)&&!$val['islogo']){
				$downattachs[$key]=$val;
			}
		}
	}

if(!empty($replyattachs)){
		foreach($replyattachs as $keys => $vals){
			foreach($vals as $key => $val){
				if(!in_array($key,$displayattachs)){
				$replydownattachs[$keys][$key]=$val;
				}
			}
		}
	}

$multipage=multi($totalrecord, 5, $curpage, "viewproduct.php?productid=".$productid);
include($templatedir."viewproduct.tpl.php");
