<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id 4 2008-10-05 01:25 $
*/
if(!check_submit('otherssubmit')) {
    $tplname = 'filter';
    $total = $db->get_value("SELECT COUNT(*) FROM {$dbpre}words");
    if($total > 0) {
        $limit = get_limit($page, $offset=15);
        $multipage = multi($total, $offset, $page, 'admincp.php?action='.$action.'&file='.$file);
        $query = $db->query("SELECT * FROM {$dbpre}words ORDER BY id LIMIT $limit");
    }
    include cptpl($tplname);
} else {
    if(is_array($deleteids) && count($deleteids) > 0) {
        $ids = "'".implode("','",$deleteids)."'";
        $db->query("DELETE FROM {$dbpre}words WHERE id IN($ids) AND ('$admin->id'=1 OR admin='$admin->adminname')");
    }

    if(is_array($filter)) {
        foreach($filter as $id => $val) {
            if(strlen($val['keyword']) < 3) {
                cpmsg('过滤词语过短，请返回修改。');
            }
            $db->update_new($dbpre.'words',"id='$id' AND ('$admin->id'=1 OR admin='$admin->adminname')",$val);
        }
    }

    if($newfilter['keyword'] != '') {
        if(strlen($newfilter['keyword']) < 3) {
            cpmsg('过滤词语过短，请返回修改。');
        }
        if($oldrecord = $db->get_one("SELECT * FROM {$dbpre}words WHERE keyword='{$newfilter['keyword']}'")) {
            cpmsg('过滤词语已存在，请返回修改。');
        }
        $newfilter['admin'] = $admin->adminname;
        $db->insert_new($dbpre.'words', $newfilter);
    }
    cache_filters();
    cpmsg('词语过滤更新完毕！', 'admincp.php?action='.$action.'&file='.$file);
}
?>