<?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.shoptags like '%{$search['keyword']}%' OR a.producttags 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}reviews 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.*,b.shopname,b.subname,c.username FROM {$dbpre}reviews a LEFT JOIN {$dbpre}shops b ON(a.shopid=b.sid) LEFT JOIN {$dbpre}members c ON(a.uid=c.uid) $where ORDER BY posttime DESC LIMIT $limit");
                while($review = $db->fetch_array($query)) {
                    $status_arr = array('1'=>'正常','2'=>'未审核','6'=>'隐藏显示');
                    $review['statusname'] = $status_arr[$review['status']];
                    $review['content'] = trimmed_title(html_special_chars(str_replace("\n", ".", $review['content'])), 18);
                    $reviews[] = $review;
                }
                $multurl = "admincp.php?action=$action&file=$file&search%5Bclass%5D={$search['class']}&search%5Bclasscode%5D={$search['classcode']}&search%5Bareacode%5D={$search['areacode']}&search%5Bauthor%5D={$search['author']}&search%5Bkeyword%5D={$search['keyword']}";
                $multipage = multi($total['count'], $offset, $page, $multurl);
            }
        }

    include cptpl('reviewlist', MOD_ROOT.'./admin/templates/');

} else {

    if($reviewid && is_array($reviewid)) {
        if($operation && is_array($operation) && $operation['delete']) {
            deleteReview($reviewid,'rid',-1,false,$operation['subpoint']);
            cpmsg('点评删除完毕。',"admincp.php?action=$action&file=$file");
        } else {
            cpmsg('未选择操作行为，请返回修改。');
        }
    } else {
        cpmsg('请至少选择一个点评进行删除，请返回修改。');
    }

}
?>