<?php

        if(!defined('IN_DISCUZ')) {

            exit('Access Denied');

        }

        require_once libfile('function/forumlist');

        odz_loadforum();

        $tmp = array_keys($_G['forum']['threadsorts']['types']);

	$sortid = isset($tmp[0])?$tmp[0]:'';

        //清楚空格

        function clear_blank($str, $glue=''){

            $replace = array(" ", "\r", "\n", "\t"); return str_replace($replace, $glue, $str);

        }

        //无限分类

        function genCate_select($array,$parentid=0){

            $result = array();

            foreach($array as $key => $val){

                if($val['parentid'] == $parentid) {

                $tmp = $array[$key];

                unset($array[$key]);

                count(genCate_select($array,$val['id'])) > 0 && $tmp['children'] = genCate_select($array,$val['id']);

                $result[] = $tmp;

                }

            }

            return $result;

        }

        $optionlist=array();

        if($sortid){

            $typevar= C::t('forum_typevar')->fetch_all_by_sortid($sortid,'ASC');

            $optionlist = array();

            foreach($typevar as $key=>$option) {

                $query= DB::fetch_all('SELECT * FROM '.DB::table('forum_typeoption')." WHERE optionid = ".$option['optionid']);

//              $query = C::t('forum_typeoption')->fetch_all_by_optionid($option['optionid']);

                $query[0]['required']=   $option['required'];

                $query[0]['protect']=   unserialize($query[0]['protect']);

                if($query[0]['rules']){

                    $query[0]['rules']  =   unserialize($query[0]['rules']);

                }else{

                    unset($query[0]['rules']);

                }

                if($query[0]['type']=='radio'||$query[0]['type']=='checkbox'){



                   $string= explode("\r", $query[0]['rules']['choices']);

                   $strings='';

                   foreach($string as $ks=>$val) {

                       $string1= explode("=", $val);

                       if(!$string1[1]) continue;

                        $strings['choices'][$ks]=$string1[1];

                   }

                   $query[0]['rules']=$strings;

                }

                if($query[0]['type']=='select'){

                   $string= explode("\r", $query[0]['rules']['choices']);

                   $strings='';

                   foreach($string as $ks=>$val) {

                       $choices=clear_blank($val);

                       $p=clear_blank($ks);

                       if(!$choices) continue;

                       $strings[$p]=$choices;

                   }

                   $query[0]['rules']['choices']=$strings;

                }

                $optionlist[]=$query[0];

            }

        }

       odz_result(array('optionlist'=>$optionlist));

?>