<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	$Id: ,v1 10:39 2008-9-19 Leilei $
*/

require("../../include/header.php");

html_start("广告位列表 - VeryIDE");
?>

<!--body start-->
	<?php
		require("config.php");
		require("setting.php");
		require("function.php");
		
		loader_cache($appid,"table.adsarea");
		
		//mysql open
		reader_mysql();
		
		$q = GetQuery("q");
		$s = GetQuery("s");
		$e = GetQuery("e");
		if(!$e){
			$e="none";
		}
		
		$id = GetQuery("id");
	?>
	
	<div id="box">

		<table width="100%" border="0" cellpadding="1" cellspacing="1" class="table">
		  <tr class="title">
			<td>标识</td>
			<td>所属分类</td>
			<td>广告位</td>
			<td>数量</td>
			<td>价格</td>
			<td>添加人</td>
		  </tr>
		<?php
		
		//缓存用户
		//ad_user($mysql);
		
		$sql="select * from ".VI_DBMODPRE."adsarea where id=".$id;
		$result=mysql_query($sql,$mysql);
		
		if(mysql_num_rows($result)==1){
			$row=mysql_fetch_assoc($result);	
		
			
			/*
			$u_name=$row["u_name"];
			$t_id=$row["t_id"];
			$t_pid=$row["t_pid"];
			$t_name=$row["t_name"];
			$t_key=$row["t_key"];
			$t_link=$row["t_link"];
			$a_logo=$row["a_logo"];
			$status=$row["status"];
			$t_preview=$row["t_preview"];
			$t_number=$row["t_number"];
			$t_price=$row["t_price"];
			$t_unit=$row["t_unit"];
			$t_note=$row["t_note"];
			$t_show=$row["t_show"];
			$t_date=$row["t_date"];
			
			//广告父分类
			$sql="select t_name,t_key,t_link from ".VI_DBMODPRE."adsarea where t_id=".$t_pid;
			$result2=mysql_query($sql,$mysql);
			
			if(mysql_num_rows($result2)==1){
				$row2=mysql_fetch_assoc($result2);
				
				$t_p_name=$row2["t_name"];
				$t_p_key=$row2["t_key"];
				$t_p_link=$row2["t_link"];
			}
			
			*/
			
			echo '
			<tr class="line">
			<td>'.$row["key"].'</td>
			<td>'.$VICACHE["mod.adsarea"][$row["parent"]]["name"].'</td>
			<td><script>Mo.Tools("RsImage","'.$t_preview.'",true);</script><a href="'.$row["link"].'" target="_blank" title="'.$row["link"].'">'.$row["name"].'</a></td>
			<td>'.$row["number"].'</td>
			<td align="right"><span class="text-yes">'.$row["price"].'/'.$row["unit"].'</span></td>
			<td><a href="?s=account&q='.urlencode($row["account"]).'">'.$row["account"].'</a></td>
		  </tr>
			<tr id="type-'.$t_id.'">
				<td colspan="8" class="block">
					';
					
					$sql="SELECT * FROM ".VI_DBMODPRE."adsview where status>0 and type=".$row["id"]." and expire>".time()." order by sort asc,id desc ";
					$result2=mysql_query($sql,$mysql);	
					
					$row_count=mysql_num_rows($result2);
					
					//有效广告&剩余广告
					echo '<strong class="text-yes">有效广告: '.$row_count.' / 空闲广告: '.($row["number"]-$row_count).'</strong>';
					
					echo '					
					<br />
					<table width="100%" border="0" cellpadding="1" cellspacing="1" class="table">
						<tr class="title">
						<td>序号</td>
						<td>广告名称</td>
						<td>所有者</td>								
						<td>投放天数</td>
						<td>已投放</td>
						<td>加入日期</td>
						<td>停止日期</td>
						</tr>';
					
					$n=0;
					while($row2=mysql_fetch_assoc($result2)){
					
						/*
						$a_id=$row2["a_id"];
						$a_owner=$row2["a_owner"];
						$a_order=$row2["a_order"];
						
						$u_name=$row2["u_name"];
						$u_id=$row2["u_id"];
						$a_link=$row2["a_link"];
						$status=$row2["status"];
						$a_name=$row2["a_name"];
						$a_file=$row2["a_file"];
						$t_pid=$row2["t_pid"];
						$t_id=$row2["t_id"];
						
						$a_width=$row2["a_width"];
						$a_height=$row2["a_height"];
						$a_view=$row2["a_view"];
						$a_click=$row2["a_click"];
						
						$a_date=$row2["a_date"];
						$a_order=$row2["a_order"];
						
						$a_start=$row2["start"];
						
						$expire=$row2["expire"];
						
						//记录本广告过期时间
						$expire_array[$n]=array($expire,true);
						
						$end=$row2["end"];
						
						*/
						
						//广告投放天数
						if ( $row2["status"] ){
							//正常状态
							$l_days=DateDiff("d",$row2["start"],$row2["expire"]);
						}else{
							//已过期
							$l_days=DateDiff("d",$row2["start"],$row2["end"]);
						}
						
						//到期倒记时
						$e_days=DateDiff("d",mktime(0, 0, 0, date("m"), date("j"), date("Y")),$row2["expire"]);
						
						echo '<tr class="line">';
						echo '<td>'.$row2["sort"].'</td>';
						echo '<td><a href="'.$row2["link"].'" target="_blank">'.$row2["name"].'</a></td>';
						echo ' <td>'.$VICACHE["sys.admin"][$row2["owner"]].'</td>';
						echo '<td>'.$l_days.' 天</td>';
						 
						echo '<td>';
						$s_days=DateDiff("d",mktime(0, 0, 0, date("m"), date("j"), date("Y")),$row2["start"]);
						if($s_days>0){
							echo '<span class="text-no">开始于 '.$s_days.' 天后</span>';
						}else{
							echo '<span class="text-yes">已投放 '.abs($s_days).' 天</span>';
						}						 
						echo '</td>';
						echo '<td>'.date("Y-m-d",$row["dateline"]).'</td>';
						
						echo '<td>';
						if ($e_days>0){
							echo date("Y-m-j",$row2["expire"]).'<br />';
							if($e_days<=$Setting[$appid]["expire"]){								
								echo '<span class="text-no">'.$e_days." 天后过期</span>";
							}else{
								echo '<span class="text-yes">'.abs($e_days)." 天后过期</span>";
							}
						}else{
							if(!$e_days){
								echo '<span class="text-yes" title="'.$end.'">今天到期<br />本广告已停止</span>';
							}else{
								echo '<span class="text-yes" title="'.$end.'">'.abs($e_days).' 天前过期<br />'.date("Y-m-d",$row["end"]).' 停止</span>';
							}
						}
						
						echo '</td>';
						echo '</tr>';
						
						$n++;
					}
					echo '</table>';
					//有效广告_结束
					
						
					//预定广告
					echo '<br /><strong class="text-yes">预定中的广告</strong>';
					
					echo '
					<br />
					<table width="100%" border="0" cellpadding="1" cellspacing="1" class="table">
						<tr class="title">
						<td>优先级</td>
						<td>开始日期</td>
						<td>加入日期</td>
						</tr>';
						
						
						$sql="SELECT * FROM ".VI_DBMODPRE."adsview where status=3 and type=".$row["id"]." order by sort asc,id desc ";
						$result3=mysql_query($sql,$mysql);

						while($row3=mysql_fetch_assoc($result3)){
						
							//$row3=mysql_fetch_assoc($result3);

							echo '
							<tr class="line">
							<td>'.$row3["sort"].'</td>
							<td>'.$row3["start"].'</td>
							<td>'.date("Y-m-j").'</td>
							</tr>';

						}
							

					echo '</table>';
					//预定广告_结束
						
					echo '
						
					</td>
			</tr>
			';
		  
		}
		?>
		</table>
		
		</div>
		
		<?php

		//mysql close
		reader_mysql(true);
								
		?>

<!--body end-->

<?php html_close();?>