<?php 
class Ads_mod  extends HC_Controller
{
	public function __construct()
	{
		parent::__construct();
		if(empty($this -> db)){
			$this -> load_db();
		}
	}
	
	
	//广告显示代码
	function get_ads( $instr = '1,2,3,4,5,6,7,8,9,10,11' )
	{
		//时间还不起作用。没处理
		$nowtime  = time();
		$sql = " SELECT p.adp_id, p.adp_width,p.adp_height,p.adp_style,ad.ad_name,ad.ad_url,ad.ad_media_type,ad.ad_desc,ad.ad_start_time,ad.ad_end_time  FROM  ".$this -> db -> prefix."ad_position as p left join ".$this -> db -> prefix."ad as ad on p.adp_id = ad.adp_id  WHERE p.adp_id in ( $instr ) and  ad.ad_id  is not null and ad_end_time > $nowtime  and ad_start_time < $nowtime  GROUP BY p.adp_id ORDER BY p.adp_id LIMIT 50  ";
		
		$info = $this -> db -> select_info($sql);
		//var_dump($info);
		$adsRe = array();

		//1 图片,2 FLASH, 3代码, 4 文字。
		foreach ((array)$info as $row)
		{
			//默认样式
			if($row["adp_style"]=='default')
			{
				if( $row["ad_media_type"] == 1)
				{
					$adsRe[$row["adp_id"]]["relurl"] = '<a href="'.$row["ad_url"].'" target="_blank"><img src="'.BASE_WEBURL.$row["ad_desc"].'" width="'.$row["adp_width"].'" height="'.$row["adp_height"].'" border="0" ></a>';
				}else if($row["ad_media_type"] == 2)
				{
					$adsRe[$row["adp_id"]]["relurl"] = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'.$row["adp_width"].'" height="'.$row["adp_height"].'"><param name="movie" value="'.BASE_WEBURL.$row["ad_desc"].'" /><param name="quality" value="high" /><embed src="'.BASE_WEBURL.$row["ad_desc"].'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'.$row["adp_width"].'" height="'.$row["adp_height"].'"></embed></object>';
				}else if($row["ad_media_type"] == 3)
				{
					$adsRe[$row["adp_id"]]["relurl"] = $row["ad_desc"];
				}else if($row["ad_media_type"] == 4){
					
					$adsRe[$row["adp_id"]]["relurl"] = '<div style="width:'.$row["adp_width"].'px;height:'.$row["adp_height"].'px; word-wrap: break-word; word-break: normal;" >'.$row["ad_desc"].'</div>';
				}else{
						$adsRe[$row["adp_id"]]["relurl"] = '';
				}
			
			//左边对联样式
			}else if($row["adp_style"]=='heartleft')
			{
				if($row["ad_media_type"] == 1)
				{
					$adsRe[$row["adp_id"]]["relurl"] =  '<script language="javascript">heartleftcode="<DIV id=\'lovexin12\' style=\'left:22px;POSITION:absolute;TOP:69px;\'><a href=JavaScript:; onclick=\"lovexin12.style.visibility=\'hidden\'\"><img border=0 src=\''.BASE_WEBURL.'/images/sys/close.gif\'></a><br><a href=\''.$row["ad_url"].'\' target=\'_blank\'><img border=0 src=\''.BASE_WEBURL.$row["ad_desc"].'\' width=\"'.$row["adp_width"].'\" height=\"'.$row["adp_height"].'\"></div>"; </script>';
				}else if($row["ad_media_type"] == 2)
				{
					$adsRe[$row["adp_id"]]["relurl"] = '<script language="javascript">heartrightcode="<DIV id=\'lovexin12\' style=\'left:22px;POSITION:absolute;TOP:69px;\'><object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\' width=\''.$row["adp_width"].'\' height=\''.$row["adp_height"].'\'><param name=\'movie\' value=\''.BASE_WEBURL.$row["ad_desc"].'\' /><param name=\'quality\' value=\'high\' /><embed src=\''.BASE_WEBURL.$row["ad_desc"].'\' quality=\'high\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\' type=\'application/x-shockwave-flash\' width=\''.$row["adp_width"].'\' height=\''.$row["adp_height"].'\'></embed></object></div>";</script>';
					
				}else if($row["ad_media_type"] == 3)
				{
					$adsRe[$row["adp_id"]]["relurl"] = '<script language="javascript">heartleftcode="<DIV id=\'lovexin12\' style=\'left:22px;POSITION:absolute;TOP:69px;\'>'.$row["ad_desc"];
					
				}else if($row["ad_media_type"] == 4){
					
					$adsRe[$row["adp_id"]]["relurl"] = '<div style="width:'.$row["adp_width"].'px;height:'.$row["adp_height"].'px; word-wrap: break-word; word-break: normal;" >'.$row["ad_desc"].'</div>';
				}else{
						$adsRe[$row["adp_id"]]["relurl"] = '';
				}
			
			//右边对联样式
			}else if($row["adp_style"]=='heartright')
			{


				if($row["ad_media_type"] == 1)
				{
					$adsRe[$row["adp_id"]]["relurl"] =  '<script language="javascript">heartrightcode="<DIV id=\'lovexin14\' style=\'right:22px;POSITION:absolute;TOP:69px;\'><a href=JavaScript:; onclick=\"lovexin14.style.display = \'none\'\"><img border=0 src=\''.BASE_WEBURL.'/images/sys/close.gif\'><br><a href=\''.$row["ad_url"].'\' target=\'_blank\'><img border=0 src=\''.BASE_WEBURL.$row["ad_desc"].'\' width=\"'.$row["adp_width"].'\" height=\"'.$row["adp_height"].'\"></div>";</script>';	
				}else if($row["ad_media_type"] == 2)
				{
					$adsRe[$row["adp_id"]]["relurl"] = '<script language="javascript">heartrightcode="<DIV id=\'lovexin14\' style=\'right:22px;POSITION:absolute;TOP:69px;\'><a href=JavaScript:; onclick=\"lovexin14.style.visibility=\'hidden\'\"><img border=0 src=\''.BASE_WEBURL.'/images/sys/close.gif\'></a><br><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"'.$row["adp_width"].'\" height=\"'.$row["adp_height"].'\"><param name=\"movie\" value=\"'.BASE_WEBURL.$row["ad_desc"].'\" /><param name=\"quality\" value=\"high\" /><embed src=\"'.BASE_WEBURL.$row["ad_desc"].'\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"'.$row["adp_width"].'\" height=\"'.$row["adp_height"].'\"></embed></object></div>";</script>';
					
				}else if($row["ad_media_type"] == 3)
				{
					$adsRe[$row["adp_id"]]["relurl"] = $row["ad_desc"];
					
				}else if($row["ad_media_type"] == 4){
					
					$adsRe[$row["adp_id"]]["relurl"] = '<div style="width:'.$row["adp_width"].'px;height:'.$row["adp_height"].'px; word-wrap: break-word; word-break: normal;" >'.$row["ad_desc"].'</div>';
				}else{
						$adsRe[$row["adp_id"]]["relurl"] = '';
				}
			
			//默认样式
			}else{
				
				if( $row["ad_media_type"] == 1)
				{
					$adsRe[$row["adp_id"]]["relurl"] = '<a href="'.$row["ad_url"].'" target="_blank"><img src="'.BASE_WEBURL.$row["ad_desc"].'" width="'.$row["adp_width"].'" height="'.$row["adp_height"].'" border="0" ></a>';
				}else if($row["ad_media_type"] == 2)
				{
					$adsRe[$row["adp_id"]]["relurl"] = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'.$row["adp_width"].'" height="'.$row["adp_height"].'"><param name="movie" value="'.BASE_WEBURL.$row["ad_desc"].'" /><param name="quality" value="high" /><embed src="'.BASE_WEBURL.$row["ad_desc"].'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'.$row["adp_width"].'" height="'.$row["adp_height"].'"></embed></object>';
				}else if($row["ad_media_type"] == 3)
				{
					$adsRe[$row["adp_id"]]["relurl"] = $row["ad_desc"];
					
				}else if($row["ad_media_type"] == 4){
					
					$adsRe[$row["adp_id"]]["relurl"] = '<div style="width:'.$row["adp_width"].'px;height:'.$row["adp_height"].'px; word-wrap: break-word; word-break: normal;" >'.$row["ad_desc"].'</div>';
				}else{
						$adsRe[$row["adp_id"]]["relurl"] = '';
				}
			}
		}
 
		return $adsRe;	
	}


} 