<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
*/
(!defined('IN_ADMIN') || !defined('IN_MUDDER')) && exit('Access Denied');
if(!$dosubmit) {

    if($search && is_array($search)) {
        if($search['classcode']) $where_and[] = "b.classcode like '{$search['classcode']}%'";
        if($search['areacode']) {
            if(strlen($search['areacode']) == 6) {
                $where_and[] = "b.streetcode='".$search['areacode']."'";
            } else {
                $where_and[] = "b.areacode='{$search['areacode']}%'";
            }
        }
        if($search['author']) $where_and[] = "c.username='{$search['author']}'";
        if($search['keyword']) {
            $where_or[] = "a.title like '%{$search['keyword']}%' OR a.tags like '%{$search['keyword']}%'";
            $where_or[] = "CONCAT(b.shopname,b.subname) like '%{$search['keyword']}%'";
        }
        $where = $where_and ? implode(' AND ', $where_and) : '';
        $where .= $where ? ($where_or ? ' AND '.implode(' OR ', $where_or) : '') : ($where_or ? implode(' OR ', $where_or) : '');
        $where = $where ? 'WHERE a.status<>2 AND '.$where : 'WHERE a.status<>2 ';
        $total = $db->get_one("SELECT COUNT(*) as count FROM {$dbpre}pictures a LEFT JOIN {$dbpre}shops b ON(a.shopid=b.sid) LEFT JOIN {$dbpre}members c ON(a.uid=c.uid) $where");
        if($total['count'] > 0) {
            $offset = 20;
            $limit = get_limit($page, $offset);
            $query = $db->query("SELECT a.pid,a.uid,a.shopid,a.title,a.filename,a.folder,a.width,a.height,a.status,a.size,a.sort,a.browse,a.addtime,b.shopname,b.subname,c.username FROM {$dbpre}pictures a LEFT JOIN {$dbpre}shops b ON(a.shopid=b.sid) LEFT JOIN {$dbpre}members c ON(a.uid=c.uid) $where ORDER BY a.addtime DESC LIMIT $limit");
            while($picture = $db->fetch_array($query)) {
                $status_arr = array('1'=>'正常','2'=>'未审核','6'=>'隐藏显示');
                $sort_arr = array('1'=>'环境','2'=>'产品','3'=>'其他');
                $picture['statusname'] = $status_arr[$picture['status']];
                $picture['sortname'] = $sort_arr[$picture['sort']];
                $picture['addtime'] = date('Y-m-d H:i:s', $picture['addtime']);
                $pictures[] = $picture;
            }
            $multurl = "admincp.php?action=$action&search%5Bclass%5D={$search['class']}&search%5Bclasscode%5D={$search['classcode']}&search%5Bareacode%5D={$search['areacode']}&search%5Bauthor%5D=".rawurlencode($search['author'])."&search%5Bkeyword%5D=".rawurlencode($search['keyword']);
            $multipage = multi($total['count'], $offset, $page, $multurl);
        }
    }
    include cptpl('picturelist', MOD_ROOT.'./admin/templates/');

} else {

    if($pictureid && is_array($pictureid)) {
        if($operation && is_array($operation) && $operation['delete']) {
            if(!function_exists('deletePicture')) {
                require_once(MOD_ROOT.'./include/fun_picture.php');
            }
            deletePicture($pictureid,'pid',-1,$operation['subpoint'],true);
        }
        cpmsg('图片删除完毕。',"admincp.php?action=$action&file=$file");
    } else {
        cpmsg('请至少选择一张图片进行删除，请返回修改。');
    }

}
?>