<?php
include ('admin_global.php');
/*
$sql="select * from gameclass";
$query_fid=$db->findall("gameclass");
while ($row=$db->fetch_array($query_fid)) {
    	echo $row[name];
}*/
$cmd = $_GET["cmd"];
if($cmd=="list"){
    $args=$_POST;
    $t_sql="select id from gameclass where";
    
    $sql="select * from gameclass where";
    $search=$args[searchKey];
    if($search==null || $search==""){
        $sql.=" 1=1 ";
        $t_sql.=" 1=1 ";
    }else{
        $sql.=" name like '%$search%' ";
        $t_sql.=" name like '%$search%' ";
    }

    $total=mysql_num_rows($db->query($t_sql));  //计算结果集总条数用于分页

    if($args[limit]!=""){
        if($args[start]!="" || $args[start]!=0){
         $start=$args[start];
        }else{
            $start=0;
        }
         $sql.="limit ".$start.",$args[limit]";
    }
    $query=$db->query($sql);
    while ($row=$db->fetch_array($query)) {
        $i=0;
        $data.="{id:".$row[id].",fid:".$row[fid].",name:\"".iconv("GBK", "utf-8", $row[name])."\",jianjie:\"".iconv("GBK", "utf-8", $row[jianjie])."\"}";
        if($i<  (count($row)-1)){
           $data.=",";
        }
        $i++;
    }
    $str="{rowCount:".$total.",result:[".$data."]}";
    echo $str;
}
if($cmd=="save"){
    $args=$_POST;
    $name=iconv("utf-8", "gbk", $args[name]);
    $jianjie=iconv("utf-8", "gbk", $args[jianjie]);
    $sql="insert into gameclass values(null,0,'$name','$jianjie')";
    $query=$db->query($sql);
    if($query){
        echo "{success:true,info:'新增成功'}";
    }else{
        echo "{failure:true,info:'新增失败'}";
    }
}

if($cmd=="update"){
    $args=$_POST;
    $name=iconv("utf-8", "gbk", $args[name]);
    $jianjie=iconv("utf-8", "gbk", $args[jianjie]);
    $sql="update gameclass set name='$name',jianjie='$jianjie' where id=$args[id]";
    $query=$db->query($sql);
    if($query){
        echo "{success:true,info:'修改成功'}";
    }else{
        echo "{failure:true,info:'修改失败'}";
    }
}

if($cmd=="remove"){
    $sql_card="delete from card where gameclassid=$_POST[id]";
    $query=$db->query($sql_card);
    $sql="delete from gameclass where id=$_POST[id]";
    $query=$db->query($sql);
    if($query){
        echo "{success:true,info:'删除成功'}";
    }else{
        echo "{failure:true,info:'删除失败'}";
    }
}
?>
