<?php
/*
渝海软件[HaiPHP.COM] 
*/
include_once './config.php';

$history=$text_class->openFile();
sort($history,SORT_NUMERIC);
$smarty->assign(history,$history);

if($_POST[query]){
	$_GET[id]="";
	$_GET[rout_id]="";
	$_GET[type]="";
	$result_q=mysql_query("select * from `chengyu_list` where title like '%".$_POST[query]."%' limit 0,100");
	if(mysql_num_rows($result_q)=='0')$title_n="<script language='javascript'> alert('没有符合条件的成语，请从新查询。');history.back();</script>";
	while($row_q=mysql_fetch_array($result_q)){
		$title[]=array(id=>$row_q[id],title_1=>$row_q[title]);
	}
}
if($_GET[rout_id]){
	$rout_id=$_GET[rout_id].':';
	$result_t=mysql_query("select * from `chengyu_type` where rout_id like '%".$rout_id."%'");
	while($row_t=mysql_fetch_array($result_t)){
		$title_m=explode(':',$row_t[rout_char]);
		$smarty->assign("title_m",$title_m[0]);
		$type[]=array(type=>$row_t[type],rout_id=>$row_t[rout_id]);
	}
	$result=mysql_query("select * from `chengyu_type` where rout_id!='".$_GET[rout_id]."'");
	while($row=mysql_fetch_array($result)){
		if($row[uid]=='0'){
			$row_1[]=array(uid=>$row[type],id=>$row[id],rout_id=>$row[rout_id]);
		}
	}
}else{
	$result=mysql_query("select * from `chengyu_type`");
	while($row=mysql_fetch_array($result)){
		if($row[uid]=='0'){
			$row_1[]=array(uid=>$row[type],id=>$row[id],rout_id=>$row[rout_id]);
		}
	}
}
if($_GET[type]){
	$result_q=mysql_query("select * from `chengyu_list` where type='".$_GET[type]."'");
	if(mysql_num_rows($result_q)=='0')$title_n='没有符合条件的成语，请从新查询。';
	while($row_q=mysql_fetch_array($result_q)){
		$title[]=array(id=>$row_q[id],title_1=>$row_q[title]);
	}
}
if($_GET[id]){
	$result_list=mysql_query("select * from `chengyu_list` where id='".$_GET[id]."'");
	$row_list=mysql_fetch_object($result_list);
	
	$content_txt=array(id=>$row_list->id,ip=>$ip,time=>time(),data=>$row_list->title);
	$text_class->add_line($content_txt);

	$smarty->assign("hr",'<hr>');
	$smarty->assign("list_title",'&nbsp;&nbsp;'.$row_list->title);
	$smarty->assign("list_title_1",$row_list->title_1);
	$smarty->assign("list_explain",'&nbsp;&nbsp;<font color=green>解释：</font>'.$row_list->explain);
	$smarty->assign("list_made",'&nbsp;&nbsp;<font color=green>出处：</font>'.$row_list->made);
	$smarty->assign("list_examples",'&nbsp;&nbsp;<font color=green>例子：</font>'.$row_list->examples);
}
$smarty->assign("type",$type);
$smarty->assign("uid_1",$row_1);
$smarty->assign("uid_2",$row_2);
$smarty->assign("title_n",$title_n);
$smarty->assign("title",$title);
$smarty->display('index.html');
?>