<?php

if(! defined('OT_ROOT')) {
	exit('Access Denied');
}


class TplBottom{

	// 友情链接
	public static function LogoBox($judGet=true){
		global $DB,$tpl;

		$judCache = false;
		$cacheName='func_LogoBox_'. strlen($tpl->webPathPart);

		if ($retStr = Cache::CheckWebCache($cacheName)){ $judCache = true; }
		if ($judCache == false){

			$retStr = '';
			$todayDate = TimeDate::Get('date');
			$logoexe=$DB->query('select IM_ID,IM_theme,IM_URL,IM_alt from '. OT_dbPref ."infoMove where IM_state=1 and IM_isImg=0 and IM_type='logo' and IM_startDate<=". $DB->ForTime($todayDate) .' and IM_endDate>='. $DB->ForTime($todayDate) .' order by IM_rank ASC');
			$logoRow = $logoexe->fetchAll();
			if ($logoRow){
				$rowCount = count($logoRow);
				for ($i=0; $i<$rowCount; $i++){
					if ($i>=1){ $retStr .= '<span class="font1_1d">&ensp;|&ensp;</span>'; }
					$retStr .= '<a href="'. $logoRow[$i]['IM_URL'] .'" class="font1_1" target="_blank" title="'. $logoRow[$i]['IM_alt'] .'">'. $logoRow[$i]['IM_theme'] .'</a>';
				}

				$retStr .= '<br />';
			}
			$logoexe = null;

			$logoexe=$DB->query('select IM_ID,IM_theme,IM_URL,IM_imgMode,IM_img,IM_alt from '. OT_dbPref ."infoMove where IM_state=1 and IM_isImg>=1 and IM_type='logo' and IM_startDate<=". $DB->ForTime($todayDate) .' and IM_endDate>='. $DB->ForTime($todayDate) .' order by IM_rank ASC');
			while ($row = $logoexe->fetch()){
				if ($row['IM_imgMode'] == 'upImg'){ $imgUrl=$tpl->webPathPart . ImagesFileDir . $row['IM_img']; }else{ $imgUrl=$row['IM_img']; }
				$imgAlt = Str::MoreReplace($row['IM_theme'],'input');
				$retStr .= '<a href="'. $row['IM_URL'] .'" class="font1_1" target="_blank" title="'. $row['IM_alt'] .'"><img src="'. $imgUrl .'" alt="'. $imgAlt .'" title="'. $imgAlt .'" class="img" /></a>'. PHP_EOL;
			
			}
			unset($logoexe);

			Cache::WriteWebCache($cacheName,$retStr);

		}

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}


	// 底部栏目
	public static function BottomMenu($judGet=true){
		global $DB,$tpl;

		$judCache = false;
		$cacheName='func_BottomMenu_'. strlen($tpl->webPathPart);

		if ($retStr = Cache::CheckWebCache($cacheName)){ $judCache = true; }
		if ($judCache == false){

			$retStr = '';
			$bMenuNum=0;
			$webexe=$DB->query('select IW_ID,IW_theme,IW_themeStyle,IW_mode,IW_URL,IW_isEncUrl from '. OT_dbPref ."infoWeb where IW_state=1 and IW_type='bottom' order by IW_rank ASC");
			while ($row = $webexe->fetch()){
				if ($row['IW_mode'] == 'sitemap'){
					$webURL		= $tpl->webHost .'sitemap.html';
					$webTarget	= ' target="_blank"';
				}elseif ($row['IW_mode'] == 'message'){
					$webURL		= $tpl->webHost .'message.php';
					$webTarget	= ' target="_blank"';
				}elseif ($row['IW_mode'] == 'url'){
					$webURL		= Url::WebUrl($row['IW_URL'],$row['IW_isEncUrl'],$row['IW_ID'],$tpl->webPathPart);
					$webTarget	= ' target="_blank"';
				}else{
					$webURL		= Url::WebID($row['IW_ID']);
					$webTarget	= '';
				}
				$bMenuNum ++;
				if ($bMenuNum>1){ $retStr .= '&ensp;-&ensp;'; }
				$retStr .= '<a href="'. $webURL .'" style="'. $row['IW_themeStyle'] .'" class="font1_1"'. $webTarget .'>'. $row['IW_theme'] .'</a>';
			}
			unset($webexe);

			Cache::WriteWebCache($cacheName,$retStr);

		}

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}
}

?>