Exemple #1
0
            $db->query("UPDATE " . $ecs->table('nav') . "SET ifshow = 0 WHERE ctype = 'c' AND cid = '" . $id . "' AND type = 'middle'");
        }
        clear_cache_files();
        make_json_result($val);
    } else {
        make_json_error($db->error());
    }
}
/*------------------------------------------------------ */
//-- 切换是否显示
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'toggle_is_show') {
    check_authz_json('cat_manage');
    $id = intval($_POST['id']);
    $val = intval($_POST['val']);
    if (cat_update($id, array('is_show' => $val)) != false) {
        clear_cache_files();
        make_json_result($val);
    } else {
        make_json_error($db->error());
    }
}
/*------------------------------------------------------ */
//-- 删除商品分类
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'remove') {
    check_authz_json('cat_manage');
    /* 初始化分类ID并取得分类名称 */
    $cat_id = intval($_GET['id']);
    $cat_name = $db->getOne('SELECT cat_name FROM ' . $ecs->table('category') . " WHERE cat_id='{$cat_id}'");
    /* 当前分类下是否有子分类 */
        $db->query("DELETE FROM " . $ecs->table('nav') . "WHERE  ctype = 'a' AND cid = '{$id}' AND type = 'middle'");
        clear_cache_files();
        admin_log($cat_name, 'remove', 'category');
    }
    $url = 'articlecat.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']);
    ecs_header("Location: {$url}\n");
    exit;
}
/*------------------------------------------------------ */
//-- 切换是否显示在导航栏
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'toggle_show_in_nav') {
    check_authz_json('cat_manage');
    $id = intval($_POST['id']);
    $val = intval($_POST['val']);
    if (cat_update($id, array('show_in_nav' => $val)) != false) {
        if ($val == 1) {
            //显示
            $nid = $db->getOne("SELECT id FROM " . $ecs->table('nav') . " WHERE ctype='a' AND cid='{$id}' AND type = 'middle'");
            if (empty($nid)) {
                //不存在
                $vieworder = $db->getOne("SELECT max(vieworder) FROM " . $ecs->table('nav') . " WHERE type = 'middle'");
                $vieworder += 2;
                $catname = $db->getOne("SELECT cat_name FROM " . $ecs->table('article_cat') . " WHERE cat_id = '{$id}'");
                $uri = build_uri('article_cat', array('acid' => $id), $_POST['cat_name']);
                $sql = "INSERT INTO " . $ecs->table('nav') . " (name,ctype,cid,ifshow,vieworder,opennew,url,type) " . "VALUES('" . $catname . "', 'a', '{$id}','1','{$vieworder}','0', '" . $uri . "','middle')";
            } else {
                $sql = "UPDATE " . $ecs->table('nav') . " SET ifshow = 1 WHERE ctype='a' AND cid='{$id}' AND type = 'middle'";
            }
            $db->query($sql);
        } else {