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

if(!check_submit('reviewssubmit')) {

    if($op == 'changeclosed' && is_numeric($tagid) && $tagid > 0) {
        $closed = $closed ? '1' : '0';
        $db->query("UPDATE {$dbpre}tags SET closed='$closed' WHERE tagid='$tagid'");
    }

    $search_tagname = trim($search_tagname);
    $search_tagnameenc = rawurlencode($search_tagname);
    if($search_tagname) $where[] = "tagname='$search_tagname'";
    if($search_panelcode) $where[] = "panelcode='$search_panelcode'";
    if($search_closed == '0' || $search_closed == '1') $where[] = "closed='$search_closed'";
    if($where && is_array($where)) {
        $where_sql = 'WHERE '.implode(' AND ', $where);
    }
    $offset = 15;
    $limit = get_limit($page, $offset);
    $result = $db->get_one("SELECT COUNT(*) AS total FROM {$dbpre}tags $where_sql");
    $total = $result['total'];
    $query = $db->query("SELECT * FROM {$dbpre}tags $where_sql ORDER BY total DESC LIMIT $limit");
    while($tag = $db->fetch_array($query)) {
        $tag['closedname'] = $tag['closed']== 0 ? '<font color="green">正常</font>' : '<font color="red">停用</font>';
        $tag['panelname'] = $_panels[$tag['panelcode']];
        $tags[] = $tag;
    }
    $multurl = "admincp.php?action=$action&file=$file&search_tagname=".rawurlencode($search_tagname)."&search_panelcode=$search_panelcode&search_closed=$search_closed";
    $multipage = multi($total, $offset, $page, $multurl);

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

} else {

    if($tagnames && is_array($tagnames)) {
        foreach($tagnames as $tagname) {
            $db->query("DELETE FROM {$dbpre}shoptags WHERE tagname='$tagname'");
            $db->query("DELETE FROM {$dbpre}tags WHERE tagname='$tagname'");
        }
        cpmsg('删除完毕。');
    } else {
        cpmsg('请至少选择一个要删除的标签，请返回修改。');
    }
}
?>