<?php

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

require '../../include/loader.php';

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

<!--body start-->
	<?php
	require("config.php");
	require("setting.php");
	require("function.php");
	
	Cached :: loader($appid,"table.adsarea");
	
	//连接数据库
        System :: connect();
	
	$q = getgpc('q');
	$s = getgpc("s");
	$e = getgpc("e");
	if(!$e){
		$e="none";
	}
	
	$id = getgpc("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 `mod:adsarea` WHERE id=".$id;
		
		$row = System :: $db -> getOne( $sql );

		if( $row ){
					
			echo '
			<tr class="line">
			<td>'.$row["key"].'</td>
			<td>'.$_CACHE['adsview']['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 `mod:adsview` WHERE `state`>0 and type=".$row['id']." and expire>".time()." ORDER BY sort asc,id desc ";
					
					$row_count = System :: $db -> getCount( $sql );
					
					//有效广告&剩余广告
					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;
					
					$result2 = System :: $db -> getAll( $sql );
					
					foreach( $result2 as $row2 ){
					
						/*
						$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"];
						$state=$row2["state"];
						$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["state"] ){
							//正常状态
							$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>'.$_CACHE['system']['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<=$_G['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 `mod:adsview` WHERE `state`=3 and type=".$row['id']." ORDER BY sort asc,id desc ";
						
						$result3 = System :: $db -> getAll( $sql );

						foreach( $result3 as $row3 ){
							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

		//关闭数据库
        System :: connect();
								
		?>

<!--body end-->

<?php html_close();?>