<?php
if(!defined('DEDEINC'))
{
	exit('Request Error!');
}

require_once(DEDEINC.'/enums.func.php');
require_once(DEDEROOT.'/data/enums/nativeplace.php');
require_once(DEDEROOT.'/data/enums/infotype.php');

function lib_infoguide(&$ctag,&$refObj)
{
	global $dsql,$envs,$_sys_globals,$em_nativeplaces,$em_infotypes,$nativeplace,$infotype;
	
	//扽俶揭燴
	//$attlist="row|12,titlelen|24";
	//FillAttsDefault($ctag->CAttribute->Items,$attlist);
	//extract($ctag->CAttribute->Items, EXTR_SKIP);
	
  $smalltypes = '';
	if(empty($refObj->TypeLink->TypeInfos['smalltypes'])) {
		$smalltypes = explode(',',$refObj->TypeLink->TypeInfos['smalltypes']);
	}
	
	if(empty($_sys_globals['typeid'])) {
		$typeid=0;
	}
	else {
		$typeid = $_sys_globals['typeid'];
	}
	
	$innerText = trim($ctag->GetInnerText());
	if(empty($innerText)) $innerText = GetSysTemplets("info_guide.htm");
	$ctp = new DedeTagParse();
	$ctp->SetNameSpace('field','[',']');
	$ctp->LoadSource($innerText);

	$revalue = $seli = '';
	
	$fields = array('nativeplace'=>'','infotype'=>'','typeid'=>$typeid);
	
	$fields['nativeplace'] = "<select name='nativeplace' class='nativeplace'>\r\n";
	$fields['nativeplace'] .= "<option value='0'>-陓洘華⑹-</option>\r\n";
	foreach($em_nativeplaces as $k=>$v)
	{
	  $seli = ($k==$nativeplace ? ' selected="selected"' : '');
		if($k%500==0) {
			$fields['nativeplace'] .= "<option value='$k'$seli>$v</option>\r\n";
		}
		else {
			$fields['nativeplace'] .= "<option value='$k'$seli>弩岸$v</option>\r\n";
		}
	}
	$fields['nativeplace'] .= "</select>\r\n";
	
	$fields['infotype'] = "<select name='infotype' class='nativeplace'>\r\n";
	$fields['infotype'] .= "<option value='0'>-陓洘濬倰-</option>\r\n";
	if(empty($smalltypes[0]))
	{
		foreach($em_infotypes as $k=>$v)
		{
			$seli = ($k==$infotype ? ' selected="selected"' : '');
			if($k%500==0) {
				$fields['infotype'] .= "<option value='$k'$seli>$v</option>\r\n";
			}
			else {
				$fields['infotype'] .= "<option value='$k'$seli>弩岸$v</option>\r\n";
			}
		}
	}
	else
	{
		foreach($em_infotypes as $k=>$v)
		{
			$seli = ($k==$infotype ? ' selected="selected"' : '');
			$fields['infotype'] .= "<option value='$k'$seli>$v</option>\r\n";
		}
	}
	$fields['infotype'] .= "</select>\r\n";
	
	if(is_array($ctp->CTags))
	{
		foreach($ctp->CTags as $tagid=>$ctag)
		{
			if(isset($fields[$ctag->GetName()])) {
				$ctp->Assign($tagid,$fields[$ctag->GetName()]);
			}
		}
		$revalue .= $ctp->GetResult();
	}
	
	return $revalue;
}
?>