<?php
/**
* 商铺图片列表
* @author moufer<moufer@163.com>
* @package modoer
* @copyright Moufer Studio(www.modoer.com)
* @version $Id: shop_pic.php 1 2007-8-13 $
*/

define('SCRIPTNAV','shop_pic');
require_once './include/inc_common.php';

if(!is_numeric($shopid) || $shopid <= 0){
    redirect('您查看的商铺不存在。', NULL);
    exit;
}

$sort = empty($sort) ? 'all' : $sort;

$shop = $db->get_one("SELECT sid,shopname,subname,classcode,status FROM {$dbpre}shops WHERE sid='$shopid'");
if(!$shop){
    redirect('您查看的商铺不存在或已删除。', NULL);
} elseif($shop['status'] == 2) {
    redirect('您查看的商铺尚未审核，暂时无法查看。');
} else {
    $shop['shopname'] .= $shop['subname'] ? "({$shop['subname']})" : "";
    $pcd = substr($shop['classcode'],0,2);
}

$arr_sort = array('all'=>'全部', '1'=>'环境', '2'=>'产品', '3'=>'其他');

$where = "shopid='$shopid' ";
//$sort=GetParam($_GET,'sort','all');
/*
if($sort == '1'){
    $where .="AND sort='1'";
}elseif($sort == '2') {
    $where .="AND sort='2'";
}elseif($sort == '3'){
    $where .="AND sort='3'";
}else {
    $sort='all';
}
*/

$where .= ' AND status=1 ';

$total = array('1'=>0,'2'=>0,'3'=>0); // 环境,样式,其他
$row = $db->get_one("SELECT COUNT(*) as c FROM {$dbpre}pictures WHERE $where");
$total['all'] = $row['c'];
if($total['all'] == '0'){
    $urls = array(
        1 => array(
            'name'=>'返回商铺页面',
            'url'=>'shop.php?shopid='.$shopid
        ),
        2 => array(
            'name'=>'我来上传图片',
            'url'=>'post.php?action=uploadpicture&amp;shopid='.$shopid
        )
    );
    redirect('商铺暂时没有图片。',$urls);
} else {
    $orderby = 'addtime DESC';
    $query = $db->query("SELECT * FROM {$dbpre}pictures WHERE $where ORDER BY $orderby");
    $flag = 0;
    while($picture = $db->fetch_array($query)) {
        $total[$picture['sort']] += 1;
        if(!$sort||$sort!='all') {
            if($picture['sort'] != $sort) continue;
        }
        $flag++;
        $picture['flag'] = $flag;
        $pictures[] = $picture;
    }
    $current_pic = &$pictures[0];
    $current_pic['width'] = intval($current_pic['width']) > 0 ? intval($current_pic['width']) : 650;
    $current_pic['height'] = intval($current_pic['height']) > 0 ? intval($current_pic['height']) : 420;
    $current_pic['imagetype'] = 'width="'.(min($current_pic['width'], 650)).'"';
    $current_pic['addtime'] = date('Y-m-d', $current_pic['addtime']);
    $db->update("UPDATE {$dbpre}pictures SET browse=browse+1 WHERE pid='{$fristpicture['pid']}'");
    //上传图片的会员
    $uploadmembers = $db->get_one("SELECT username FROM {$dbpre}members WHERE uid='{$current_pic['uid']}'");
    $current_pic['username'] = $uploadmembers['username'];
    unset($uploadmembers);
}

$thumb_width = $_picture_thumb['big']['width'];
$thumb_height = $_picture_thumb['big']['height'];

$subtitle = '图片中心_'.$shop['shopname'].'_'.$_classcodes[$pcd]['classname'];
require_once MUDDER_ROOT.'header.php';
require_once template('shop_pic');
footer();
?>