<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id lis.inc.php 2 2008-08-24 11:39 $
*/
(!defined('IN_ADMIN') || !defined('IN_MUDDER')) && exit('Access Denied');

if($dosubmit) {

    empty($op) && cpmsg("没有选择操作行为，请返回选择。");
    empty($articleid) && empty($articleids) && cpmsg("没有选择操作对象，请返回选择。");
    (empty($articleids) || !is_array($articleids)) && $articleids = array();
    $articleid && array_push($articleids, $articleid);

    $op == 'check' && article_check($articleids, $admin->adminname);
    $op == 'delete' && article_delete($articleids);
    $op == 'att' && article_att($articleids, $att);

    cpmsg('操作完毕！',$_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:'admincp.php?action=article&file=list');

} else {

    $articleclass = read_cache_articleclass();

    $multiurl = 'admincp.php?action=article&file=list';
    if($search) foreach($search as $key => $val) {
        $multiurl .= '&search'.rawurlencode('['.$key.']').'='.rawurlencode($val);
    }

    $where = array();
    $search['status'] && $where[] = "status='{$search['status']}'";
    $search['classid'] && $where[] = "classid='{$search['classid']}'";
    $search['att'] && $where[] = "att='{$search['att']}'";
    $search['shopid'] && $where[] = "shopid='{$search['shopid']}'";
    $search['keyword'] && $where[] = "(subject LIKE '%{$search['keyword']}%' OR keywords LIKE '%{$search['keyword']}%')";
    $where = 'WHERE '.(!empty($where) ? implode(' AND ',$where) : '1=1');
    $total = $db->get_value("SELECT COUNT(*) FROM {$dbpre}articles $where");
    if($total > 0) {
        $offset = 20;
        $multipage = multi($total, $offset, $page, $multiurl);
        $limit = get_limit($page, $offset);
        empty($search['order']) && $search['order'] = 'dateline';
        empty($search['ordertype']) && $search['ordertype'] = 'DESC';
        $orderby = $search['order'] .' '. $search['ordertype'];
        $query = $db->query("SELECT * FROM {$dbpre}articles $where ORDER BY $orderby LIMIT $limit");
    }

    include cptpl('list', MOD_ROOT.'./admin/templates/');
}
?>