public static function isMainType($type_id)
 {
     if (!is_numeric($type_id)) {
         return array('0' => false, 'message' => "参数应为整型");
     }
     $tree = DataTree::getInstance();
     $result = $tree->getANodeByOtherNode($type_id, 1);
     if ($result[0]) {
         //查找成功
         $node = $result[1];
         // $root=$tree->getOneTreeNode();
         $maintype = self::getMainTypeId();
         if ($maintype[0]) {
             $maintype_id = $maintype[1];
         } else {
             return array('0' => false, 'message' => "未查找到主分类id");
         }
         if ($node->type_id == $maintype_id) {
             return array('0' => true, 'ismaintype' => true);
         } else {
             return array('0' => true, 'ismaintype' => false);
         }
     } else {
         return array('0' => false, 'message' => "查找祖先节点失败");
     }
 }
/**
 *
 *  excellent_setting.inc.php 2016-1-5 龚成
 */
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
if (defined('DISCUZ_ROOT')) {
    $path = DISCUZ_ROOT . "source\\plugin\\excellent_shared\\";
}
require_once $path . "class/DiscuzDataTree.class.php";
require_once $path . "function/function_makeCache.php";
require_once "class/TypeArray.class.php";
//require_once ("class/CenterGradation.class.php");
$tree = DataTree::getInstance();
echo "josn_menu:" . $tree->getOneTreeNodeJson() . "<br/>";
$new_json = <<<EOT
\t\t{\t"father_type_id":null,
\t\t\t"type_id":"37",
\t\t\t"type_name":"root",
\t\t\t"type_level":0,
\t\t\t"child_type_id":{
\t\t\t\t"0":"65535",
\t\t\t\t"1":"65535"
\t\t\t},
\t\t\t"child":{
\t\t\t\t"0":{
\t\t\t\t\t"father_type_id":"37",
\t\t\t\t\t"type_id":"65535",
\t\t\t\t\t"type_name":"gongcheng",
 public static function beCategoried($tid)
 {
     //若参数不是数字,则报错
     if (!is_numeric($tid)) {
         //echo "参数错误<br/>";
         return array(intval(-1), "参数错误");
     }
     //查找数据库
     $db = GCDB::getInstance();
     $sql = "SELECT type_id,rate FROM `{$db->tablepre}forum_gc_excellent_thread` WHERE tid={$tid};";
     //echo "sql:{$sql}";
     $sqldata = $db->query($sql);
     if (!$sqldata) {
         //echo "查询数据库出错<br/>";
         return array(intval(-1), "数据库查询错误sql:" . $sql);
     }
     $row = $sqldata->fetch_assoc();
     if (empty($row)) {
         //没有分类
         return array(false, "未找到该分类");
     }
     //已分类
     $tree = DataTree::getInstance();
     $type_array = array();
     $type_array[0] = array();
     $type_array[0]['type_id'] = $row['type_id'];
     $type_array[0]['rate'] = $row['rate'];
     $type_array[0]['type_name'] = $tree->getOneTreeNode($row['type_id'])->type_name;
     $i = 1;
     while ($row = $sqldata->fetch_assoc()) {
         $type_array[$i]['type_id'] = $row['type_id'];
         $type_array[$i]['rate'] = $row['rate'];
         $type_array[$i]['type_name'] = $tree->getOneTreeNode($row['type_id'])->type_name;
         $i += 1;
     }
     return array(true, $type_array);
 }
 public static function insertThreadTypeSFun($tid, $type_id, $rate)
 {
     //参数检查
     if (empty($tid) || !is_array($type_id) || empty($type_id)) {
         echo "参数错误<br/>";
         return false;
     }
     //检查评论项,更改其格式(为空则置NULL,为str则加上单引号)
     if ($rate == NULL || !is_string($rate)) {
         $rate = "NULL";
     } else {
         $rate = "'{$rate}'";
     }
     //获取type的level,构造type数组(type_id=>type_level)
     $type = ThreadWithType::getTypeSFun($type_id);
     if (!$type) {
         echo "请检查type_id参数";
         return false;
     }
     //获取其数据库操作对象
     $db = GCDB::getInstance();
     //检查数据库是否已经存在该分类
     $sql = "";
     foreach ($type_id as $key => $value) {
         $sql = "SELECT count(*) as 'num' FROM `{$db->tablepre}forum_gc_excellent_thread` WHERE tid={$tid} AND type_id={$value};";
         $sqldata = $db->query($sql);
         $row = $sqldata->fetch_assoc();
         if ($row['num'] > 0) {
             //说明已存在该类关系,则去掉数组值
             unset($type_id[$key]);
             unset($type[$value]);
         }
     }
     if (empty($type)) {
         echo "{__LINE__}:该分类关系已经存在<br/>";
         return true;
     }
     //上面函数已经检查好参数
     //先进行数据库查重
     //构造sql语句
     //开始事务
     $db->start_transaction();
     //数据库查重
     foreach ($type as $id => $level) {
         $sql = "DELETE FROM `{$db->tablepre}forum_gc_excellent_thread` WHERE tid={$tid} AND ( 0 ";
         //此处加空格,直接删除同类型的tid联系
         if ($level < 30) {
             //是树节点,需要查找其所有的子节点,看是否有重复
             $tree = DataTree::getInstance();
             //获取其所有子节点id
             //参数为空则是获取所有节点
             $childid_array = $tree->getOneTreeNodeAllTypeid();
             foreach ($childid_array as $value) {
                 $sql .= " OR type_id={$value} ";
             }
         } else {
             //是多重分类,则按照每一层进行查找
             $leveltype = TypeArray::getInstance();
             $brotherid = $leveltype->getArrayTypeid($level);
             if (!$brotherid) {
                 //返回错误
                 echo "{__LINE__}:无法获取同类多重类型id<br/>";
                 return false;
             }
             foreach ($brotherid as $value) {
                 $sql .= " OR type_id={$value} ";
             }
         }
         $sql .= ");";
         echo "{__LINE__}:sql:" . $sql . "<br/>";
         //执行sql语句
         if (!$db->query($sql)) {
             echo "数据库除重失败!<br/>";
             //事务回滚
             $db->rollback_transaction();
             return false;
         }
     }
     //插入数据库
     $sql = "INSERT INTO `{$db->tablepre}forum_gc_excellent_thread`(`tid`,`type_id`,`rate`) VALUES ";
     foreach ($type_id as $value) {
         $sql .= "({$tid},{$value},{$rate}),";
     }
     //sql语句去掉最后一个逗号,并加上分号
     $sql = substr($sql, 0, -1);
     $sql .= ";";
     echo "{__LINE__}:INSERT:{$sql}<br/>";
     //运行sql语句
     if (!$db->query($sql)) {
         echo "插入操作失败<br/>";
         $db->rollback_transaction();
         return false;
     }
     //提交事务
     $db->commit_transaction();
     //返回
     return true;
 }
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
if ($_G[uid] == 0) {
    //showmessage('not_loggedin', null, 'NOPERM');
    showmessage('请选登录', '', array(), array('login' => true));
}
require_once "class/DiscuzDataTree.class.php";
require_once "class/TypeArray.class.php";
//获取type_id数组,如果未给出type_id数组,则直接获取根节点id
require_once "class/ThreadWithType.class.php";
require_once "function/function_showThreadWithTable.php";
require_once "function/function_showAttachmentDownload.php";
require_once "function/function_getAttachType.php";
require_once "function/function_showSearchTPL.php";
//获取分类下的帖子
$type_id = $_POST[type_id];
//print_r(ThreadWithType::beCategoried(1));
$datatree = $datatree = DataTree::getInstance();
//获取所有分类对象
$data_array = $datatree->getDataArray();
showSearchTPL($data_array);
if (empty($type_id)) {
    $type_id = array();
    $type_id[] = $datatree->getOneTreeNode()->type_id;
    //获取根节点的type_id
}
$result = ThreadWithType::getThreadSFun($type_id)[1];
//第二个参数为显示风格,0为panel显示风格,1为table显示风格
showThreadWithTable($result, 0);