<?
//block functions
//论坛精华//
function insert_ut() {
	global $catetree,$PlusDB,$site_conf;
	$nume=15;
$sql = "SELECT id,subject FROM forum.ut_topics where boardId !=20 and boardId !=17  and boardId !=41  and boardId !=15  and boardId !=16  and boardId !=36  and boardId !=27  and boardId !=42   and boardId !=43  and boardId !=5  ORDER BY lastPostTime DESC "; 
$rt = $PlusDB->SelectLimit($sql,$nume,0); 
if ($rt) { 
while ($r = $rt->fetchRow($rt)) 
{ 
$id = $r["id"]; 
$subject = $r["subject"]; 
$boardId = $r["boardId"]; 
$anonymous =$r ["anonymous"];
$ret.= "<img src=/images/point.gif border=0><a href=/cgi-bin/forum/topic_show.cgi?id=$id target=_blank>";
$ret.= msubstr($subject,0,34);
$ret.="</a></li><br>"; 
} 
} 
else 
{ 
$ret.= "No data."; 
}
return $ret;
}

//活动与招聘//
function insert_job() {
	global $catetree,$PlusDB,$site_conf;
	$num=15;
	$query = "SELECT id,subject FROM forum.ut_topics where boardId=46 ORDER BY lastPostTime DESC "; 
	//$query = "SELECT id,subject FROM forum.ut_topics where boardId=46 ORDER BY lastPostTime DESC LIMIT $num"; 
	$rt=$PlusDB->SelectLimit($query,$num,0);
if ($rt) { 
while ($r = $rt->fetchRow($rt)) 
{ 
$id = $r["id"]; 
$subject = $r["subject"]; 
$boardId = $r["boardId"]; 
$anonymous =$r ["anonymous"];
$ret.= "<img src=/images/point.gif border=0><a href=/cgi-bin/forum/topic_show.cgi?id=$id target=_blank>";
$ret.= msubstr($subject,0,34);
$ret.="</a></li><br>"; 
} 
} 
else 
{ 
$ret.= "No data."; 
}
return $ret;
}

function insert_article($var){
	global $catetree,$PlusDB,$site_conf;
	//$onum = 2;//循环步长
	$html_path=$site_conf[system][html_path];
	$html_ext = $site_conf[system][html_ext];
	$adb=$PlusDB->prefix(articles);
	$cdb = $PlusDB->prefix(category);
	$cid=$var[cid];
	if($site_conf[system][outhtml]=="yes"){
	$cate_path=PLUS_URL."/$html_path".getCategoryPath($cid)."index.".$html_ext ;
	}else{
	$cate_path=PLUS_URL."/index.php?cid=".$cid;
	}
	$limit=$var[limit];
	$ismore= $var[ismore];
	$ismax = $var[ismax];
	$mark = $var[mark];
	$date_format = $var[date_format];
	$order_by = $var[order_by];
	$isimg =$var[isimg];
	$isfirst = $var[isfirst];
	$mix = $var[mix];
	$onum =  $var[onum]?$var[onum]:1;
	$template=$var[template]?$var[template]:"default.tpl";
	#cid
	if(!intval($cid) || $cid<0){
	 	$arg_cid = "";
	}else{
		$cids= getsubcids($cid,-1,$catetree);
		$arg_cid = " and cid in ($cids) ";
	}
	#mark
	$mark = $mark>""?$mark:"&middot;";
	#ismax
	$ismax = $ismax>0?$ismax:0;
	#limit
	if(!intval($limit) || $limit<0) $limit=10;
	#switch order
	switch($order_by){
		case "date_asc": $arg= " order by ctime asc";break;
		case "hit_asc":$arg=" order by hits asc";break;
		case "hit_desc":$arg =  " order by hits desc";break;
		case "date_desc":default:$arg=" order by ctime desc ";
	}

	if($isimg=='yes') $sarg= " and isimg='yes' ";
	if($isfirst=='yes') $sarg.= " and first='yes' ";
	$showimg = $var[showimg];
	if($showimg=='yes') $sarg.= " and img>'' ";
	#template file
	$path= "template/".$site_conf[template][site_template]."/blocks/".$template;
	if(!file_exists($path)) $path="template/".$site_conf[template][site_template]."/blocks/default.tpl";
	#thistime 
	$thistime = date("Y-m-d");
	//add get the first article
	if($mix=="yes"){
		$sql_mix = "select id,title,intro,cid,thumb,hits,ctime ,author,source from   $adb where active='yes' $arg_cid and first='yes'  $sarg $arg  ";
	}
	//add new end
	$sql="select id,title,intro,cid,thumb,hits,ctime ,author,source from   $adb where active='yes' $arg_cid  $sarg $arg  ";
	$rt=$PlusDB->SelectLimit($sql,$limit,0);
	$num=$rt->RecordCount();
	if($num==0){
		echo "无数据!";	
	}else{
			$i=1;
			//2005-3-16 23:13
			if($mix=="yes"){
					$row = $PlusDB->GetRow($sql_mix);
					$ddtime = explode(" ",$row[ctime]);
					$row[ctitle]=$catetree[$row[cid]][name];
					$row[dtime] = str_replace("-","",$ddtime[0]);
					$this_cate_path=PLUS_URL."/$html_path".getCategoryPath($row[cid]);
					if($ismax!=0 && strlen($row[title])>$ismax) $row[title]=msubstr($row[title],0,$ismax)."...";
					$this_cate_path = PLUS_URL."/$html_path".getCategoryPath($row[cid]);
						if($site_conf[system][outhtml]=="yes"){
						$row[aurl]=$this_cate_path . $row[dtime]."/".$row[cid].",".$row[id].",0.".$html_ext;
						}else{
						$row[aurl]="index.php?cid=$row[cid]&action=Article&aid=$row[id]";
						}
					$row[thumb]=file_exists($row[thumb])?$row[thumb]:"images/none.gif";;
					$row[num]=$i;
					$i++;
					$ret[]=$row;
		}
		//end 2005-3-16 23:13
		while($row=$rt->fetchRow()){
			$ddtime = explode(" ",$row[ctime]);
			$row[ctitle]=$catetree[$row[cid]][name];
			$row[dtime] = str_replace("-","",$ddtime[0]);
			$this_cate_path=PLUS_URL."/$html_path".getCategoryPath($row[cid]);
			if($ismax!=0 && strlen($row[title])>$ismax) $row[title]=msubstr($row[title],0,$ismax)."...";
			$this_cate_path = PLUS_URL."/$html_path".getCategoryPath($row[cid]);
				if($site_conf[system][outhtml]=="yes"){
				$row[aurl]=$this_cate_path . $row[dtime]."/".$row[cid].",".$row[id].",0.".$html_ext;
				}else{
				$row[aurl]="index.php?cid=$row[cid]&action=Article&aid=$row[id]";
				}
					$row[thumb]=file_exists($row[thumb])?$row[thumb]:"images/none.gif";;
			$row[num]=$i;
			if($i==$onum) $i=0;
			$i++;
			$ret[]=$row;
		}
		include "include/smarty.php";
		$smarty->assign("onum",$onum);
		$smarty->assign("list",$ret);
		$smarty->assign("mark",$mark);
		$smarty->assign("cid",$cid);
		$smarty->assign("cate_path",$cate_path);
		$smarty->assign("ismore",$ismore);
		return $smarty->fetch($path);
}
}

function insert_viewArticle($var){
	global $art;
	$art->viewArticle($var[aid],$var[start]);
}
function insert_viewImageArticle($var){
	global $art;
	return $art->showImageArticle($var[cid],$var[limit],$var[template]);
}
function insert_member_block($vars){
	$login_template = $vars[login];
	$member_template = $vars[member];
	return "<script src=".PLUS_URL."/member.php?l=$login_template&m=$member_template></script>";
}
function insert_news($var){
	global $art;
	//$art->showNewsBlock2($var[cid],$var[limit]);
	$art->showNewsBlock($var[limit]);
}
function insert_board($var){
	global $art;
	$art->showNewsBlock2($var[cid],$var[limit]);
}
function insert_first($var){
	global $art;
	return $art->showFirstArticle($var[cid],$var[limit],$var[col],$var[template]);
}
function insert_update($var){
	global $art;
	return $art->showNewArticle($var[cid],$var[limit],$var[col],$var[template]);
}
function insert_vmenu($var){
	global $catetree;
	$topcid=$var[cid];
	$exp=array();
	$exp=explode("|",$var[exp_id]);
	$topcid=intval($topcid)?$topcid:0;
	global $cid;
	$thisid=$cid;
	$ret= "
	<script language=\"JavaScript1.2\">
		<!--
		var head=\"display:''\"
		function doit(header){
		var head=header.style
		if (head.display==\"none\")
		head.display=\"\"
		else
		head.display=\"none\"
		}
		//-->
		</script>
	<table width=100% border=0 cellpadding=0 cellspacing=0>";
	foreach($catetree[$topcid][child] as $cid){
		if(in_array($cid,$exp)) continue;
		if(count($catetree[$cid][child])>0){
			$sids=getsubcids($cid,1,$catetree);
			$s_ids=explode(",",$sids);
		$ret.= "<tr><td height=24  style=\"cursor:hand;\" onClick=\"doit(menu$cid)\") background=template/sebb/images/BG1.gif><img src=images/arrow.gif> <a href=index.php?cid=$cid>".$catetree[$cid][name]."</a></td></tr>";
			$style=in_array($thisid ,$s_ids)?"display:;":"display:none;";
			$ret.= "<tr id=menu$cid style=\"$style\"><td><table width=100%><tr></td>";
			foreach($catetree[$cid][child] as $sid){
				$ret.= "<tr><td><img src=images/arrows.gif> <a href=index.php?cid=$sid>".$catetree[$sid][name]."</a></td></tr>";
			}	
			$ret.= "</td></tr></table></td></tr>";
		}else{
		$ret.= "<tr><td height=24   background=template/sebb/images/BG1.gif><img src=images/arrow.gif> <a href=index.php?cid=$cid>".$catetree[$cid][name]."</a></td></tr>";
	
	}
	}
	$ret.= "</table>";
	return $ret;
}

function insert_vmenu2($var){
	global $catetree;
	$topcid=$var[cid];
	$exp=array();
	$exp=explode("|",$var[exp_id]);
	$topcid=intval($topcid)?$topcid:0;
	global $cid;
	$thisid=$cid;
	$ret= "<table width=100% border=0 cellpadding=0 cellspacing=0>";
	foreach($catetree[$topcid][child] as $cid){
		if(in_array($cid,$exp)) continue;
		if(count($catetree[$cid][child])>0){
			$sids=getsubcids($cid,1,$catetree);
			$s_ids=explode(",",$sids);
		$ret.= "<tr><td height=24  style=\"cursor:hand;\" onClick=\"doit(menu$cid)\") background=template/sebb/images/BG2.gif><img src=images/arrow.gif> <a href=index.php?cid=$cid>".$catetree[$cid][name]."</a></td></tr>";
			$style=in_array($thisid ,$s_ids)?"display:;":"display:none;";
			$ret.= "<tr id=menu$cid style=\"$style\"><td><table width=100%><tr></td>";
			foreach($catetree[$cid][child] as $sid){
				$ret.= "<tr><td><img src=images/arrows.gif> <a href=index.php?cid=$sid>".$catetree[$sid][name]."</a></td></tr>";
			}	
			$ret.= "</td></tr></table></td></tr>";
		}else{
		$ret.= "<tr><td height=24   background=template/sebb/images/BG1.gif><img src=images/arrow.gif> <a href=index.php?cid=$cid>".$catetree[$cid][name]."</a></td></tr>";
	
	}
	}
	$ret.= "</table>";
	return $ret;
}

function insert_count($var){
	global $PlusDB;
	$aid=$var[id];
	$type=$var[ctype];
	$ret.= "<script src=".PLUS_URL."/count.php?aid=$aid&type=$type></script>";
	return $ret;
}

function insert_link($var){
	global $PlusDB;
	$limit=$var[limit];
	$onum=$var[onum]>0?$var[onum]:1;
	$sql="select * from ".$PlusDB->prefix(link)." where 1=1";
	$rt=$PlusDB->SelectLimit($sql,$limit,0);
	$i=0;
	while($row=$rt->fetchRow($rt)){
		$i++;
		$row[num]=$i;
		$row[icon]=$row[icon]!=""?$row[icon]:"images/no_icon.gif";
		$ret[]=$row;
		if($i==$onum) $i=0;
		//echo "<a href=$row[url] target=_blank title=\"$row[title]\"><img src=$row[icon] border=0></a><br>";
	}
	include "include/smarty.php";
	$smarty->assign("onum",$onum);
	$smarty->assign("links",$ret);
	return $smarty->fetch("template/links.tpl");
}



function insert_poll($vars){
	$pid =$vars[id];
	$direct = $vars["dir"]?$vars["dir"]:"h";
	$show= $vars["show"]?$vars["show"]:"yes";
	$template = $vars["template"];
	return "<script src=".PLUS_URL."/poll.php?id=$pid&template=$template&dir=$direct&show=$show></script>";
}

function insert_ad($vars){
	$aid =$vars[aid];
	$tid = $vars[tid];
	return "<script src=".PLUS_URL."/adshow.php?aid=$aid&tid=$tid></script>";
}

function insert_search($var){
	global $art;
	$topid=$var[id];
	$template=$var[template];
	return $art->searchForm($topid,$template);
}
/*
(insert name=topic  tid=topicid limit=limit ismax=wordlimit mark=&middot;}
*/
function insert_topic($var){
    global $catetree,$site_conf,$PlusDB;
	$adb = $PlusDB->prefix(articles);
    $tdb = $PlusDB->prefix(topics);
	$tadb=$PlusDB->prefix(topic_links);
	$tid = $var[tid];
	$page = $var[limit];
	$ismax = $var[ismax];
	$mark = $var[mark];
    $html_path=$site_conf[system][html_path];
	$html_ext = $site_conf[system][html_ext];
	$template=$var[template]?$var[template]:"default.tpl";
	#cid
	if(!intval($cid) ||  empty($cid)) $cid=0;
	$ctitle = $catetree[$cid][name];

	#mark
	$mark = $mark>""?$mark:"&middot;";
	#switch order
	#template file
	$path= "template/".$site_conf[template][site_template]."/blocks/".$template;
	if(!file_exists($path)  || is_dir($path)) $path="template/".$site_conf[template][site_template]."/blocks/default.tpl";
	#thistime 
	$thistime = date("Y-m-d H:i:s");
	$sql="select title from $tdb where id=$tid";
	$row=$PlusDB->query_firstrow($sql);
	$ctitle = $row[title];
	$sql="select count(*) as num from   $adb a,$tadb t where t.aid=a.id and a.active='yes' and t.tid=$tid ";
	$numrow=$PlusDB->query_firstrow($sql);
	$num=$numrow[num];
	if($num==0){
		$content= _NO_DATA;	
	}else{
		$start =0;
		if(!doCheck("int",$page) ||  $page==0) $page = 20;
		$sql="select a.id,a.title,a.cid,a.ctime,a.intro,a.hits,a.thumb from   $adb a,$tadb t where t.aid=a.id and a.active='yes' and t.tid=$tid  order by a.ctime desc ";
		//trace($sql);
		$rt=$PlusDB->SelectLimit($sql,$page,$start);
		$i=0;
		while($row=$rt->fetchRow($rt)){
			$i++;
			//echo $row[ctime]."<br>";
			$ddtime = explode(" ",$row[ctime]);
			$row[dtime] = str_replace("-","",$ddtime[0]);
			if($ismax!=0 && strlen($row[title])>$ismax) $row[title]=msubstr($row[title],0,$ismax)."...";
			$row[intro]=strlen($row[intro])>50?msubstr($row[intro],0,100)."...":$row[intro];
			$row[intro]=format_text($row[intro],1,0,1,0);
			$row[thumb]=file_exists($row[thumb])?$row[thumb]:"images/none.gif";
		        $info = getimagesize($row[thumb]);
			$str = ($info[0]>$info[1])?"width=135":"height=135";
			$row[str]=$str;
			$row[format] = strtoupper(str_replace(".", "", strrchr($row[url], ".")));
			$row[oid]=$i;
			$this_cate_path = PLUS_URL."/$html_path".getCategoryPath($row[cid]);
			if($site_conf[system][outhtml]=="yes"){
			$row[aurl]=$this_cate_path . $row[dtime]."/".$row[cid].",".$row[id].",0.".$html_ext;
			}else{
			$row[aurl]="index.php?cid=$row[cid]&action=Article&aid=$row[id]";
			}
			$ret[]=$row;
			if($i==$col) $i=0;	
			}	
					include "include/smarty.php";
					$smarty->assign("ctitle",$ctitle);
					$smarty->assign("cid",$cid);
					$smarty->assign("col",$col);
					$smarty->assign("root",PLUS_URL);
					$smarty->assign("list",$ret);
					$smarty->assign("mark",$mark);
					$smarty->assign("cate_path",$url);
					$smarty->assign("page_break",$page_break);
					$content = $smarty->fetch($path);
	}
			return  $content;	    
}
function insert_scate_article($vars){
		global $PlusDB,$site_conf;
		$html_path=$site_conf[system][html_path];
		$html_ext = $site_conf[system][html_ext];
		$template_path = $site_conf[template][site_template];//站点模板目录
		$aid = $vars[aid];//文章ID
		$ismax = $vars[ismax];//文章标题截取
		$limit = $vars[limit];//文章数目
		$template = $vars[template];//带入的模板
		$r_template = "template/" . $template_path ."/blocks/". $template;//带入模板的地址
		if(!file_exists($r_template) || is_dir($r_template)) $r_template = 'template/default_cate_list.tpl';//如果带入的模板不存在，就用默认的
		$adb = $PlusDB->prefix(articles);
		$sql="select cid from $adb where id=$aid";
		$row=$PlusDB->query_firstrow($sql);
		$cid=$row[cid];
		$sql="select * from $adb where cid='$cid' and id!='$aid' and active='yes' order by rand()  ";
		$rt=$PlusDB->SelectLimit($sql,$limit,0);
		$num= $rt->RecordCount($rt);
		if($num>0){
		$i=1;
		while($row=$rt->fetchRow($rt)){
			$ddtime = explode(" ",$row[ctime]);
			$row[dtime] = str_replace("-","",$ddtime[0]);
			$this_cate_path=PLUS_URL."/$html_path".getCategoryPath($row[cid]);
			if($ismax!=0 && strlen($row[title])>$ismax) $row[title]=msubstr($row[title],0,$ismax)."...";
			$this_cate_path = PLUS_URL."/$html_path".getCategoryPath($row[cid]);
				if($site_conf[system][outhtml]=="yes"){
				$row[aurl]=$this_cate_path . $row[dtime]."/".$row[cid].",".$row[id].",0.".$html_ext;
				}else{
				$row[aurl]="index.php?cid=$row[cid]&action=Article&aid=$row[id]";
				}
					$row[thumb]=file_exists($row[thumb])?$row[thumb]:"images/none.gif";
			        $info = getimagesize($row[thumb]);
        			$str = ($info[0]>$info[1])?"width=55":"height=55";
        			$row[str]=$str;
			$row[num]=$i;
			$i++;
			$ret[]=$row;
		}
		include "include/smarty.php";
		$smarty->assign("list",$ret);
		$smarty->assign("num",$num);
		//trace($r_template);
		return $smarty->fetch($r_template);
	}
}

function insert_skey_article($vars){
		global $PlusDB,$site_conf;
		$html_path=$site_conf[system][html_path];
		$html_ext = $site_conf[system][html_ext];
		$template_path = $site_conf[template][site_template];//站点模板目录
		$aid = $vars[aid];//文章ID
		$ismax = $vars[ismax];//文章标题截取
		$limit = $vars[limit];//文章数目
		$template = $vars[template];//带入的模板
		$r_template = "template/" . $template_path ."/blocks/". $template;//带入模板的地址
		if(!file_exists($r_template) || is_dir($r_template)) $r_template = 'template/default_key_list.tpl';//如果带入的模板不存在，就用默认的
		$kadb = $PlusDB->prefix(keyword_links);
		$adb = $PlusDB->prefix(articles);
		$sql="select kid from $kadb where aid=$aid";
		$rt=$PlusDB->query($sql);
		while($row=$rt->fetchRow($rt)){
			$key[]=$row[kid];
		}
		if(count($key)>0){
		$kids =implode(',',$key);
		$sql="select a.* from $adb a left join $kadb k on (k.aid=a.id) where k.kid in ($kids) and a.id!='$aid' and  active='yes' order by rand()  ";
		//trace($sql);
		$rt=$PlusDB->SelectLimit($sql,$limit,0);
		$num= $rt->RecordCount($rt);
		}else{
		$num=0;
		}
		if($num>0){
		$i=1;
		while($row=$rt->fetchRow($rt)){
			$ddtime = explode(" ",$row[ctime]);
			$row[dtime] = str_replace("-","",$ddtime[0]);
			$this_cate_path=PLUS_URL."/$html_path".getCategoryPath($row[cid]);
			if($ismax!=0 && strlen($row[title])>$ismax) $row[title]=msubstr($row[title],0,$ismax)."...";
			$this_cate_path = PLUS_URL."/$html_path".getCategoryPath($row[cid]);
				if($site_conf[system][outhtml]=="yes"){
				$row[aurl]=$this_cate_path . $row[dtime]."/".$row[cid].",".$row[id].",0.".$html_ext;
				}else{
				$row[aurl]="index.php?cid=$row[cid]&action=Article&aid=$row[id]";
				}
					$row[thumb]=file_exists($row[thumb])?$row[thumb]:"images/none.gif";
			        $info = getimagesize($row[thumb]);
        			$str = ($info[0]>$info[1])?"width=55":"height=55";
        			$row[str]=$str;
			$row[num]=$i;
			$i++;
			$ret[]=$row;
		}
	}
		include "include/smarty.php";
		$smarty->assign("list",$ret);
		$smarty->assign("num",$num);
		//trace($r_template);
		return $smarty->fetch($r_template);
}

function insert_topic_one($var){
		global $PlusDB,$site_conf;
		$tid= $var[tid];
		$ismax = $var[ismax];
		$template = $var[template];
		$limit = $var[limit];
		$sids =  $var[sids];
		$tdb = $PlusDB->prefix("topics");
		$sql="select id,title,intro,image from $tdb ";
		if($sids>"") $sql.=" where id in ($sids) ";
		$sql.= "order by ctime desc";
		$rt=$PlusDB->SelectLimit($sql,$limit,0);
		while($row= $rt->fetchRow($rt)){
				$ret[]=$row;
		}
		include "include/smarty.php";
		$smarty->assign("topics",$ret);
		$template=$var[template]?$var[template]:"topic_list.tpl";	
		$path= "template/".$site_conf[template][site_template]."/blocks/".$template;
		if(!file_exists($path)) $path="template/".$site_conf[template][site_template]."/blocks/topic_list.tpl";
		return $smarty->fetch($path);
}

function insert_block($var){
		$bid = $var[bid];
		global $PlusDB;
		$bdb = $PlusDB->prefix("blocks");
		$sql="select * from $bdb where id='$bid'";
		$row = $PlusDB->GetRow($sql);
		return $row[content];
}

function insert_css($var){
	$cid = $var[cid];
	$pid = getTopId($cid);
	return $pid.".css";	
}
/*插入酒店介绍*/
function insert_hotel_intro($var){
	global $PlusDB;
	$aid = $var[id];
	$adb = $PlusDB->prefix("articles");
	$edb = $PlusDB->prefix("extra_contents");
	$idb = $PlusDB->prefix("images");
	$rdb = $PlusDB->prefix("hotel_room");
	$sql="select * from $adb where id='$aid'";
	$hotel =$PlusDB->GetRow($sql);
	switch($hotel[author]){
	case 0:$hotel[author] = "*暂时未评级";break;
	default:
		$hotel[author]=str_repeat("<img src=".PLUS_URL."/images/star.gif border=0>",$hotel[author]);
	}
	/*酒店信息*/
	$sql="select * from $edb where aid='$aid'";
	$row =$PlusDB->GetRow($sql);
	$info=$row;
	/*房间信息*/
	$sql="select * from $rdb where aid='$aid'";
	$rt = $PlusDB->query($sql);
	while($row=$rt->fetchRow()){
		//if($row[content]=="" || empty($row[content])) continue;
		$room[]=$row;
	}
	//trace($room);
	/*图片信息*/
	$sql="select * from $idb where aid='$aid'";
	$rt = $PlusDB->query($sql);
	$i=1;
	while($row=$rt->fetchRow()){
		//if($row[content]=="" || empty($row[content])) continue;
		$row[onum]=$i;
		$image[]=$row;
		if($i==3) $i=0;
		$i++;
	}
	include "include/smarty.php";
	$smarty->assign("hotel",$hotel);
	$smarty->assign("info",$info);
	$smarty->assign("room",$room);
	$smarty->assign("images",$image);
	return $smarty->fetch("template/hotel_info.tpl");
}

/*插入线路介绍*/
function insert_travel_intro($var){
	global $PlusDB;
	$aid = $var[id];
	$adb = $PlusDB->prefix("articles");
	$edb = $PlusDB->prefix("extra_contents");
	$idb = $PlusDB->prefix("images");
	$rdb = $PlusDB->prefix("hotel_room");
	$sql="select * from $adb where id='$aid'";
	$hotel =$PlusDB->GetRow($sql);
	/*景点信息*/
	$sql="select * from $edb where aid='$aid'";
	$row =$PlusDB->GetRow($sql);
	$info=$row;
	include "include/smarty.php";
	$smarty->assign("travel",$hotel);
	$smarty->assign("info",$info);
	$smarty->display("template/travel_info.tpl");
}
/*章节列表*/
	function insert_ch_select($var){
		global $PlusDB,$site_conf;
		$html_path = $site_conf[system][html_path];
        $html_ext = $site_conf[system][html_ext];
		$chdb = $PlusDB->prefix(contents);
		$adb = $PlusDB->prefix(articles);

		$aid = $var[aid];
		$chid = $var[chid];
		$sql="select id,title from $chdb where aid='$aid' order by o_num,id";
		$rt=$PlusDB->query($sql);
		$num=$rt->RecordCount();
		if($num<2){
			$ret= "";
		}else{
			$sql="select cid,ctime,title from $adb where id='$aid'";
			$row = $PlusDB->GetRow($sql);
			$atitle = $row[title];
			$cid = $row[cid];
			$ddtime = explode(" ",$row[ctime]);
			$dtime=str_replace("-","",$ddtime[0]);
			$url = PLUS_URL . "/$html_path" . getCategoryPath($cid). $dtime . "/" . $cid . "," . $aid ;
			$ret= "<select style=\"FONT-SIZE: 9pt; FONT-FAMILY: Arial\" name=page onChange=\"javascript:location.href=this.options[selectedIndex].value\">";
			$i=0;
			while($row=$rt->fetchRow()){
				if($site_conf[system][outhtml] == "yes"){
				$html_url = $url.",$i".".". $html_ext;
				}else{
				$html_url="index.php?cid=$cid&action=Article&aid=$aid&start=$i";
				}
				$selected = ($row[id]==$chid)?"selected":"";
				$title = (strlen($row[title])==0)?$atitle."[".($i+1)."]":$row[title];
				$ret.= "<option value='$html_url'  $selected>$title";
				$i++;
			}
			$ret.= "</select>";
		}
		return $ret;
	}

function insert_sitemap($var){
	global $catetree;
	$onum  = $var[onum];//列数
	if(!is_numeric($onum)) $onum=4;
	$ret= "<table width=100% border=0 cellpadding=0 cellspacing=0>";
	foreach($catetree[0][child] as $sid){
	if($catetree[$sid][status]!='yes') continue;
	$url = ge_url($sid);
	$ret.= "<tr height=22><td width=80 nowarp><img src=images/tree_img/folder.gif border=0 align=absmiddle><a href=$url>".$catetree[$sid][name]."</td><td >";
		if(count($catetree[$sid][child])>0){
			$ret.= "<table width=100% border=0>";
			$i=1;
			foreach($catetree[$sid][child] as $ssid){
				if($i==1) $ret."<tr>";
				if($catetree[$ssid][status]!='yes') continue;
				$surl = ge_url($ssid);
				$ret.= "<td><a href=$surl>".$catetree[$ssid][name]."</a> </td> ";
			if($i==$onum){
				 $ret.="</tr>";
				 $i=1;
				}else{
				$i++;	
			}
			}//end for
		$ret.= "</table>";
		}//end if
		$ret.= "&nbsp;</td></tr>";
	}//end for
	$ret.= "</table>";
	return $ret;
}

function insert_article_vote($vars){
	global $PlusDB;
	$aid=$vars["aid"];
	$str = '<!--评分开始-->
<table width=100% border=0 cellpadding=0 cellspacing=0><form name=vote action="'.PLUS_URL.'/vote.php?aid='.$aid.'" method=get><tr><TD align=right><script src='.PLUS_URL.'/comments.php?action=showMark&id='.$aid.'></script>评分:'.$mark.'&nbsp;
<select name=vote style="FONT-SIZE: 9pt; FONT-FAMILY: Arial" >
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select>
<input name=aid value='.$aid.' type=hidden>
<input name=submit value=vote type=submit style="FONT-SIZE: 9pt; FONT-FAMILY: Arial" ></td></tr></form></table>';
return $str;
}

function insert_bbs($var){
//code {insert name=bbs limit=10 cid=2 order_by=date_desc}
	$cid=$var[cid];
	$limit = $var[limit];
	$order_by =$var[order_by];
	$ret="<script src=".PLUS_URL."/js_index.php?ctype=bbs&limit=$limit&cid=$cid&order=$order_by></script>";
	return $ret;
}

function insert_keywords($vars){
		global $PlusDB,$site_conf;
		$keys=array();
		$kadb = $PlusDB->prefix(keyword_links);
		$kdb = $PlusDB->prefix(keyword);
		$aid =  $vars[aid];//文章ID
		$sql="select title  from $kdb k left join $kadb a on (a.kid=k.id)  where a.aid=$aid";
		$rt=$PlusDB->query($sql);
		while($row=$rt->fetchRow($rt)){
			$keys[]=$row[title];
		}
		$num=count($keys);
		if($num>0) return "关键词:".implode(",",$keys);
}


?>
<?
function insert_sitemap2(){
	global $PlusDB,$catetree;
	$pid = 0;//一级栏目ID为5
	//获取2级栏目的ID
	$sids=$catetree[$pid][child];
	$s_ids = implode(",",$sids);
	//从数据库查询3级ID的时间并排序
	//分类的表格
	$cdb = $PlusDB->prefix("category");
	$sql="select id,title from $cdb where pid in ($s_ids) order by ctime desc";
	$rt= $PlusDB->selectLimit($sql,5,0);//显示最新的5个
	$ret= "<table><tr><td>";
	while($row= $rt->fetchRow()){
		$sid = $row[id];//栏目的ID
		$title = $row[title];//栏目标题
		if($catetree[$sid][status]!='yes') continue;
		$url = ge_url($sid);
		$ret.= "<a href=$url>$title</a><br>";
	}//end for
	$ret.= "</td></tr></table>";
	return $ret;
}

function insert_human_extra($var){
	global $site_conf,$PlusDB;
	$template = $var[template];
	$path= "template/".$site_conf[template][site_template]."/detail/".$template;
	$path = file_exists($template)?$path:"template/".$site_conf[template][site_template]."/detail/human_extra.tpl";
	$aid = $var[aid];
	$edb = $PlusDB->prefix("extra_contents");
	$sql="select * from $edb  where aid = '$aid'";
	$row = $PlusDB->getrow($sql);
	include "include/smarty.php";
	$smarty->assign("extra",$row);
	$smarty->display($path);
}

function insert_auction_extra($var){
	global $site_conf,$PlusDB;
	$template = $var[template];
	$path= "template/".$site_conf[template][site_template]."/detail/".$template;
	$path = file_exists($template)?$path:"template/".$site_conf[template][site_template]."/detail/auction_extra.tpl";
	$aid = $var[aid];
	$edb = $PlusDB->prefix("extra_contents");
	$sql="select * from $edb  where aid = '$aid'";
	$row = $PlusDB->getrow($sql);
	include "include/smarty.php";
	$smarty->assign("extra",$row);
	$smarty->display($path);
}

function insert_human_search($var){
	$cid = $var[cid];
	echo "<form name=hsearch action=".PLUS_URL."/index.php?doSearch method=get>";
	echo "<input type=hidden name=cid value=$cid>";
	echo "<input type=hidden name=module value=human>";
	echo "<table widht=100% border=0 celllpadding=0><tr><td>姓&nbsp;名:</td><td><INPUT TYPE=\"text\" NAME=\"title\" value=\"\" size=\"20\"></td></tr>";
	echo "<tr><td>职&nbsp;称:</td><td><INPUT TYPE=\"text\" NAME=\"field_01\" value=\"\" size=\"20\"></td></tr>";
	echo "<tr><td>年龄段:</td><td><INPUT TYPE=\"text\" NAME=\"age_area\" value=\"\" size=\"20\"><br>例如30,50,表示30到50岁</td></tr>";
	echo "<tr><td>单&nbsp;位:</td><td><INPUT TYPE=\"text\" NAME=\"intro\" value=\"\" size=\"20\"></td></tr></table>";
	echo "<INPUT TYPE=\"submit\" name=\"submit\" value=\"搜索\">&nbsp;&nbsp;&nbsp;<INPUT TYPE=\"reset\" name=\"reset\" value=\"重置\"></form>";
}

function insert_keywordCateList($var){
	global $PlusDB;
	$kcid = $var[cid];
	$limit = $var[limit];
	$kdb = $PlusDB->prefix(keyword);
	$sql="select * from $kdb where cid='$kcid'";
	$rt=$PlusDB->selectLimit($sql);
	$num=$rt->recordcount();
	if($num==0){
		return "";
	}else{
		while($row=$rt->fetchRow()){
			$ret[]="<a href=index.php?action=listKeywordC&kid=$row[id] target=_blank>$row[title]</a>";
		}
		$str=implode(",",$ret);
		return $str;
	}
}
function insert_extra($var){
	global $PlusDB;
	static $erow;
	$fname = $var[field_name];
	$aid = $var[aid];
	if(is_array($erow)){
		
	}else{
	$edb = $PlusDB->prefix("extra_contents");
	$sql="select * from $edb  where aid = '$aid'";
	$erow = $PlusDB->getrow($sql);
	}
	return $erow[$fname];
}
function insert_comments($var){
$aid = $var[aid];
$limit = $var[limit];
$ctype = $var[ctype]?$var[ctype]:"showList";
$ret ="<script src=\"".PLUS_URL."/comments.php?id=$aid&limit=$limit&action=$ctype\"></script>";
return $ret;
}
function insert_area($var){
	global $PlusDB,$member;
	$id = $var[id];
	if($member->checkAdmin2()){
		$ret= "<div align=right><a href=b_edit.php?id=$id target=_blank>[edit]</a></div>"	;
	}
	$filename ="temp/block_".$id.".tpl";
	if(!file_exists($filename)){
			$fp = fopen($filename,"w");
			fclose( $fp );
	}
	include "include/smarty.php";
	$ret.=$smarty->fetch($filename);
	return $ret;
}
?>