<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	2011/6/5 Lay
*/

require '../../include/loader.php';
html_start("广告编辑 - VeryIDE");
?>

<!--body start-->
<?php

	//module
	require 'naver.php';	
	
	//返回列表页参数
	$jump = getgpc('jump');
	
	//加载替补缓存
	Cached :: loader( $appid, 'table.adsarea' );
	
	//////////////////////////////
	
	//连接数据库
	System :: connect();
	
	$action = getgpc('action');
	$type = getnum("type",0);
	$parent = getnum("parent",0);		
	
	if ($action){
		
		//基本信息
		$id = getnum('id',0);
		$name = getgpc('name');
		$state = getnum('state',0);
		$link = getgpc("link");
		$file = getgpc("adsview");
		$sort = getnum("sort",0);
		$tags = getgpc("tags");
		$zone = getgpc("zone");
		
		//财务信息
		$owner = getnum("owner",0);
		$contract = getgpc("contract");
		$custom = getgpc("custom");
		$contact = getgpc("contact");
		$ar = getnum("ar",0);
		$pr = getnum("pr",0);
		
		//配置
		$config = $_POST['config'];		
		$config = format_json( fix_json( $config ) );		
		$category = getgpc("category");		
		
		//开始时间
		$start = getgpc('start');
		
		if( !$start || !isDateTime($start["date"]." ".$start["time"]) ){
			$start = time();				
		}else{				
			$start = strtotime($start["date"]." ".$start["time"]);
		}
		
		//结束时间
		$expire = getgpc("expire");
		
		if( !$expire || !isDateTime($expire["date"]." ".$expire["time"]) ){
			$expire = time();				
		}else{				
			$expire = strtotime($expire["date"]." ".$expire["time"]);
		}
		
		//权限检查
		$script=$_POST["script"];
		
		$width = getnum("width",0);
		$height = getnum("height",0);
		
		$form = getnum("form",0);
		$spare = getnum("spare",0);
		
		//共享广告
		$share = getgpc("share");
		$share_old = getgpc("share_old");		
		
		switch($action){
			
			case "add":
			
				//检查权限
				System :: check_func("mod-adsview-add", false );		
			
				$sql="INSERT INTO `mod:adsview`(name,state,link,file,dateline,type,parent,script,aid,account,width,height,form,start,expire,end,spare,sort,tags,share,zone,owner,contract,custom,ar,pr,description,config,category) 
				values('".$name."',".$state.",'".$link."','".$file."','".time()."','".$type."','".$parent."','".$script."',".$_SESSION['Manager']['id'].",'".$_SESSION['Manager']['account']."',".$width.",".$height.",".$form.",'".$start."','".$expire."',null,".$spare.",'".$sort."','".$tags."','".$share."','".$zone."','".$owner."','".$contract."','".$custom."','".$ar."','".$pr."','".$description."','".$config."','".$category."')";
		
				System :: $db -> execute( $sql );	
				
			break;
			
			case "update":
		
				//检查权限
				System :: check_func("mod-adsview-mod", false );		
				
				//广告启示录用才会有投放状态
				$sql="UPDATE `mod:adsview` SET name='".$name."',file='".$file."',link='".$link."',type='".$type."',parent='".$parent."',script='".$script."',height=".$height.",width=".$width.",form=".$form.",start='".$start."',expire='".$expire."',spare='".$spare."',sort='".$sort."',tags='".$tags."',share='".$share."',zone='".$zone."',owner='".$owner."',ar='".$ar."',pr='".$pr."',description='".$description."',contract='".$contract."',custom='".$custom."',contact='".$contact."',config='".$config."',category='".$category."',`modify`=".time().",`state`='".$state."',mender='".$_SESSION['Manager']['account']."' WHERE id=".$id;
				
				System :: $db -> execute( $sql );			
				
			break;
			
			case "edit":
		
				$sql="SELECT * FROM `mod:adsview` WHERE id=".$id;
				
				$row = System :: $db -> getOne( $sql );

				if( $row ){					
					$config = fix_json($row['config']);					
				}
				
			break;
					
		}
		
		if( $action != "edit" ){
			
			//更新当前广告位缓存
			Adsview :: create("SELECT * FROM `mod:adsarea` WHERE id =".$type);
			
			//更新共享广告位缓存
			Adsview :: create("SELECT * FROM `mod:adsarea` WHERE id in(".$share."0)");
			
			//修改时
			if( $share_old && $share_old != $share ){
				Adsview :: create("SELECT * FROM `mod:adsarea` WHERE id in(".$share_old."0)");
			}
			
			//缓存广告缓存
			Cached :: rows( $appid, "SELECT * FROM `mod:adsview` WHERE id=".$id, array( 'jsonde' => array('config') ) );		
			
			//更新替补缓存
			Cached :: multi( $appid, "SELECT * FROM `mod:adsview` WHERE spare=1 and `state`>0 and `state`<3 ORDER BY sort asc,id desc", "table.alternate", array( 'alias'=>'alternate', 'jsonde' => array('config') ) );
			
			System :: redirect( ( $action == 'add' ? 'adsview.list.php?mark='.$id : ( $jump ? $jump : 'adsview.list.php' ) ), ( $action == 'update' ? '广告修改成功!' : '广告增加成功!' ) );
			
		}
		
	}

?>
<!--main-->

	<?php   

	//缓存更新时间
	$rnd = @filemtime(VI_ROOT.$_G['project']['cache'].$appid."/script.adsarea.js");

	echo loader_script(array(VI_BASE."cache/".$appid."/script.adsarea.js?rnd=".$rnd),$_G['product']['charset'],$_G['product']['version']);

	///////////////////////////

	echo loader_script(array(VI_BASE."js/mo.china.js",VI_BASE."js/mo.calendar.js","function.js"),"utf-8",$_G['product']['version']);
	?>
    
	<script type="text/javascript">
	
	//广告展现形式
	var SHOW = <?php echo "['". implode("','",$_G['module']['adsview']["type"]) ."']";?>;
	
	//广告数据
	var DATA = <?php echo $row['config'] ? $row['config'] : '{}';?>;
	
	</script>
    
	<?php
	
	//显示权限状态
	switch($action){
		case "":
			echo System :: check_func("mod-adsview-add",true);
		break;
		
		case "edit":
			echo System :: check_func("mod-adsview-mod",true);
		break;
	}
	
	?>
    
    <div id="box">

	    <form action="?" method="post" name="from1" mode="edit" verify="true">
                
        	<table cellpadding="0" cellspacing="0" class="form">
		<tbody>
        
        	<tr><td colspan="2" class="section"><strong>基本信息</strong></td></tr>
        
        	<tr>
            	<td width="60"><strong>广告名称：</strong></td>
                <td>
                    <input type="text" name="category" id="category" class="text digi" fix_name="内容分类" fix_null="yes" onclick="Mo.Soler( this, event, this.value, 'mo-soler', { '内容分类' : ['<?php echo implode("','",explode(" ",trim($_G['setting']['global']['category'])));?>'] }, function( value ){ this.value = value; }, 1 , 23 );" readonly="true" value="<?php echo $row["category"];?>" onfocus="this.blur();" />
                    
					<input name="name" type="text" class="text" id="name" value="<?php echo $row['name'];?>" size="59" fix_name="广告名称" fix_desc="请输入广告名称" fix_null="yes" />
                    
				</td>
            </tr>
        
        	<tr>
            	<td><strong>广告位置：</strong></td>
                <td>
					<select name="parent" id="parent" style="width:179px;">
                    
					<?php
					foreach($_CACHE['adsview']['adsarea'] as $key){
						if($key["parent"]=="0"){
							echo '<option value="'.$key["id"].'">'.$key["name"].'</option>';
						}
					}
					?>
                    
					</select>
					-
					<select name="type" id="type" style="width:179px;">
					<?php
					foreach($_CACHE['adsview']['adsarea'] as $key){
						if($key["parent"]==$parent && $parent){
							echo '<option value="'.$key["id"].'">'.$key["name"].'</option>';
						}
					}
					?>
					</select>
					-
                    <input type="text" name="sort" id="sort" title="显示排序" class="text digi" onclick="Mo.Soler( this, event, this.value, 'mo-soler', { '显示数量' : (function(){ var a = []; for(var i=0;i<=34;i++){a.push(i);} return a; })() }, function( value ){ this.value = value; }, 1 , 23 );" readonly="true" value="<?php echo $row["sort"] ? $row["sort"] : "0";?>" />
                    
					<script type="text/javascript">Mo.Tools("Tip","<strong>显示排序</strong><br /> 广告显示的顺序，从小到大");</script>
                </td>
                
            </tr>
        
        	<tr>
            	<td><strong>广告属性：</strong></td>
                <td id="ad_info">
                    
                </td>
                
            </tr>        
        
        	<tr>
            	<td><strong>起止时间：</strong></td>
                <td>
                    <input name="start[date]" type="text" class="text date" value="<?php echo date("Y-m-d",($row['start']?$row['start']:time()));?>" size="12" readonly="true" onclick="return showCalendar(this,'y-mm-dd');" title="年-月-日">
                    
                    <input name="start[time]" type="text" title="小时:分钟" class="text time" onclick="Mo.Timer(this,this.value);" readonly="true" value="<?php echo $row['start'] ? date("H:i",$row['start']) : "00:00";?>" />
                    
                    -
                    <input name="expire[date]" type="text" class="text date" value="<?php echo date("Y-m-d",($row['expire']?$row['expire']:time()+604800));?>" size="12" readonly="true" onclick="return showCalendar(this,'y-mm-dd');" title="年-月-日">
                    
                    <input name="expire[time]" type="text" title="小时:分钟" class="text time" onclick='Mo.Timer(this,this.value);' readonly="true" value="<?php echo $row['expire'] ? date("H:i",$row['expire']) : "23:59";?>" />
                </td>
                
            </tr>        
            
            <tr>
                <td><strong>广告状态：</strong></td>
                <td>
                    <label>
                    <input type="radio" class="radio" name="state" value="1" checked> 
                    启用状态
                    </label>
                    <label>
                    <input type="radio" class="radio" name="state" value="0">
                    禁用状态
                    </label>
                    
                    <?php
			if( in_array( $row['state'], array(2,3) ) ){
			?>
                    <label style=" background:#eee; display:inline-block; ">
                    <input type="radio" class="radio" name="state" value="2" readonly>
                    在播状态
                    </label>
                    <label style=" background:#eee; display:inline-block; ">
                    <input type="radio" class="radio" name="state" value="3" readonly>
                    预定状态
                    </label>
                    
                    <?php
			}
			?>
                </td>
                
            </tr>
        
        	<tr id="ad_form">
            	<td><strong>广告形式：</strong></td>
                <td>
					<label>
					<input name="form" type="radio" class="radio" value="0" checked="checked" /> 
					普通广告
					</label>
                    
					<label>
					<input name="form" type="radio" class="radio" value="1" />
					代码广告
					</label>
					<span id="ad_form_script"> (广告代码填入下方 &quot; 广告内容 &quot; 框中,只支持JavaScript文本形式)</span>
                </td>
            </tr>
        </tbody>
		
        <tbody id="ad_form_1" style="display:none;">
        	<tr>
            	<td width="60"><strong>脚本支持：</strong></td>
                <td>
					<div>
						<a href="javascript:void(0);" onclick="_inScript(this.innerHTML)" title="获取一个ID为n的对象">$();</a>
						|
						<a href="javascript:void(0);" onclick="_inScript(this.innerHTML)" title="输出HTML内容">write();</a>
						|
						<a href="javascript:void(0);" onclick="_inScript(this.innerHTML)" title="销毁对象">remove();</a>
						|
						<a href="javascript:void(0);" onclick="_inScript(this.innerHTML)" title="获取对象的绝对位置">position();</a>
						|
						<a href="javascript:void(0);" onclick="_inScript(this.innerHTML)" title="输出一个SCRIP标签">script</a>
						|
						<a href="javascript:void(0);" onclick="Mo('#ad_form_html').toggle();" title="显示/隐藏 HTML转JS工具">HTML 转 JS ?</a>
					</div>
					
				</td>
                
            </tr>
        
        	<tr id="ad_form_html" style="display:none;">
            	<td width="60"><strong>代码转换：</strong></td>
                <td>    
                    1. 请将HTML代码粘贴到下面文本框中: <a href="http://www.veryide.com/archive.php?id=9" target="_blank">阅读教程&raquo;</a><br>
                    <textarea id="oResult" onpropertychange="_adHTML()" oninput="_adHTML()" ondblclick='this.select();oResult.createTextRange().execCommand("Copy")' title="双击复制" cols="75" rows="10" style="float:left;"></textarea>
                    
                    <div style="clear:both;"></div>                
    
                    2. 自动生成相应的 JavaScript 代码: <br />
                    <textarea id="Re" ondblclick='this.select();this.createTextRange().execCommand("Copy")' title="双击复制" cols="75" rows="10" style="float:left;"></textarea>
                    <div style="clear:both;"></div>
                    <strong>&nbsp;</strong>3. 将上面的 JavaScript 代码复制到下面的广告内容中: <br />
				</td>
			</tr>
        
        	<tr text="* 广告内容 只支持 JS 形式，请参阅：<br /> <a href=&quot;http://www.veryide.com/archive.php?id=9&quot; target=&quot;_blank&quot;>投放 Google Adsense 和 阿里妈妈 广告</a>">
            	<td><strong>广告内容：</strong></td>
                <td><textarea name="script" cols="75" rows="10" id="script" style="font-family:Verdana;"><?php echo $row["script"];?></textarea>
                </td>
                
            </tr>
        
        	<tr>
            	<td width="60"><strong>智能标签：</strong></td>
                <td>
					<div>
						<a href="javascript:void(0);" onmouseover='Mo.Tips(this,event,"mo-tips","放在需要统计的URL前，用于统计代码广告的点击","mouseout",0,-40);' onclick="Mo('#script').value(this.innerHTML,true)">{LINK}</a>
						
						<a href="javascript:void(0);" onmouseover='Mo.Tips(this,event,"mo-tips","放在需要统计的URL中，用于统计点击的路径，可以用于不同链接的区分","mouseout",0,-40);' onclick="Mo('#script').value(this.innerHTML,true)">{VAR}</a>
					</div>
				</td>
			</tr>
        
        </tbody>
		
		
        <tbody id="ad_form_2" style="display:none;">
        	<tr>
            	<td width="60"><strong>展示模板：</strong></td>
                <td>
			<div id="ad_temp"></div>		
		</td>                
            </tr>
        
        	<tr>
            	<td width="60"><strong>数据表单：</strong></td>
                <td>
					<div id="ad_data">
						
					</div>
                    <div id="ad_file" style="display:none;">
                    <script type="text/javascript">
					new Serv.Upload("_file_","<?php echo $row["file"];?>",{'format':['<?php echo implode("','",$_G['upload']['image']);?>','<?php echo implode("','",$_G['upload']['flash']);?>'],'again':true,'recovery':true,'input':true,'callback':doCall});
					</script>
                    </div>
				</td>                
            </tr>
        
        </tbody>
		
        <tbody id="ad_form_0">
        
        	<tr>
            	<td><strong>广告信息：</strong></td>
                <td>
                	<table cellpadding="0" cellspacing="1" border="0" class="gird">
                    <thead>
                        <td>
                         链接地址
                        </td>
                        <td>
                        打开方式
                        </td>
                    </thead>
                    <tr>
                        <td>
                        <input name="link" type="text" class="text" id="_link" value="<?php echo $row['link'];?>" size="45" fix_name="链接地址" fix_desc="请输入链接地址" fix_null="no" />
                        </td>
                        <td>
                        <select id="LINK-TARGET" name="config[LINK-TARGET]">
							<option value="">打开方式</option>
							<option value="_blank">新窗口</option>
							<option value="_self">本窗口</option>
							<option value="_top">父窗口</option>
						</select>
                        </td>
                    </tr>
                    <thead>
                        <td colspan="2">
                          广告文件
                        </td>
                    </thead>
                    <tr>
                        <td colspan="2">
                        <script type="text/javascript">
						new Serv.Upload("<?php echo $appid;?>","<?php echo $row["file"];?>",{'format':['<?php echo implode("','",$_G['upload']['image']);?>','<?php echo implode("','",$_G['upload']['flash']);?>'],'again':true,'recovery':true,'input':true,'callback':doSize});
						</script>
                        </td>
                    </tr>
                    <thead>
                        <td>
                        广告标签
                        </td>
                        <td>
                         广告尺寸
                        </td>
                    </thead>
                    <tr>
                        <td>
                        <input name="tags" size="42" class="text" value="<?php echo $row["tags"];?>" fix_desc="请输入关键字或广告描述信息" />
						<script>Mo.Tools("Tip","本广告的关键字，用于搜索广告或文本广告信息显示");</script>
                        </td>
                        <td>
                        <input name="width" type="text" class="text" id="width" value="<?php echo $row["width"];?>" size="5" fix_name="广告宽度" fix_number="no">
                        ×
                        <input name="height" type="text" class="text" id="height" value="<?php echo $row["height"];?>" size="5" fix_name="广告高度" fix_number="no" />
                        
                        <script>Mo.Tools("Tip","默认为0；图片或Flash需要设置这里，否则广告可能无法显示");</script>
                        </td>
                    </tr>
                 </table>
                </td>
            </tr>
        
        	<tr><td colspan="2" class="section"><strong>扩展设置</strong></td></tr>
            
			<tr>
				<td><strong>替补广告：</strong></td>
				<td>
                
                	<table cellpadding="0" cellspacing="1" border="0" class="gird">
                    	<thead>
                            <td colspan="2">设置替补</td>
                        </thead>
                        <tr>
                            <td colspan="2">
                                <label>
                                <input name="spare" id="spare" type="radio" class="radio" value="0" checked="checked"> 
                                否 (只有条件允许才会显示)
                                </label>
                                <label>
                                <input name="spare" id="spare" type="radio" class="radio" value="1"> 
                                是 (在缺少广告时将会被无条件显示)
                                </label>
                            </td>
                        </tr>
                        
                        <?php
                        //编辑时出现
                        if( $action == "edit" && $row["type"] ){
                            
                            //加载替补缓存
                            Cached :: loader($appid,"table.alternate");				
                            
                            //替补列表
                            $spare = array();
                            foreach( $_CACHE['adsview']['alternate'] as $a ){
                                if( $a['type'] == $row["type"] ){
                                    $spare[] = $a;
                                }
                            }
                            
                            //////////////////////////////
                            
                            //已有广告数
                            $sql="SELECT count(id) FROM `mod:adsview` WHERE `state`>0 and `type`=".$row['id']." and expire>".time();
                            $count = System :: $db -> getValue($sql);
                            
                        ?>
                    	<thead>
                            <td>
                            	<b>显示数量：</b><b class="text-yes"><?php echo $_CACHE['adsview']['adsarea'][$row["type"]]["number"];?></b> 个
                                （<b class="text-yes"><?php echo $count;?></b> 个有效广告）
                                <script>Mo.Tools("Tip","此广告位最多同时显示广告的数量");</script>
                            </td>
                            <td>
                                <b>替补数量：</b><b class="text-yes"><?php echo $_CACHE['adsview']['adsarea'][$row["type"]]["number"] - $count;?></b> 个
                                （<b class="text-yes"><?php echo count($spare);?></b> 个有效替补）
                                <script>Mo.Tools("Tip","当前广告位替补广告的数量");</script>
                            </td>
                        </thead>
                        <?php
						$x = 1;
						foreach( $spare as $a ){
						?>
                         <tr>
                            <td colspan="2">
                            	<b class="text-yes"><?php echo $x++;?>.</b>
								<?php echo $a["name"];?>
                                                <?php
                                if( $a["id"] == $row['id'] ){
                                    echo '<span class="text-no">（当前）</span>';
                                }
                                ?>
                            </td>
                        </tr>
                        <?php
						}
						?>
                        
						<?php
                        }
                        ?>
                    </table>
					
				</td>
				
			</tr>
        
        	<tr text="">
            	<td><strong>展示控制：</strong></td>
                <td>
                    
                    <table cellpadding="0" cellspacing="1" border="0" class="gird">
                    	<thead>
                            <td>展示时间</td>
                            <td>展示间隔</td>
                        </thead>
                        <tr>
                            <td>
                                <input type="text" size="10" id="SHOW-TIME" name="config[SHOW-TIME]" value="<?php echo $config["SHOW-TIME"];?>" fix_name="展示时间" fix_number="no" />
                                秒钟
                                <script>Mo.Tools("Tip","<strong>展示时间</strong><br /> 只针对 落幅广告 / 滑出广告 / 滚动广告 3种广告有效<br />广告在页面上展示的时间，单位为秒钟，N 秒钟后自动消失");</script>
                            </td>
                            <td>
                            <input type="text" size="10" id="SHOW-SPACE" name="config[SHOW-SPACE]" value="<?php echo $config["SHOW-SPACE"];?>" fix_name="展示时间" fix_number="no" />
                            小时
                            <script>Mo.Tools("Tip","<strong>展示间隔</strong><br /> 对所有广告类型都有效<br />广告两次展示的时间间隔，单位为小时，每隔 N 小时展示一次");</script>
                            </td>
                        </tr>
                    	<thead>
                            <td colspan="2">附加样式</td>
                        </thead>
                        <tr>
                            <td colspan="2">
                                <input type="text" size="35" id="SHOW-STYLE" name="config[SHOW-STYLE]" value="<?php echo $config["SHOW-STYLE"];?>" />
								<script>Mo.Tools("Tip","为广告文件附加的CSS样式，如：<br />color:red; font-size:20px;");</script>
                            </td>
                        </tr>
                    </table>
                    
                </td>
                
            </tr>
         
        	<tr id="bind_slide">
            	<td><strong>收缩广告：</strong></td>
                <td>
                
                
                	<table cellpadding="0" cellspacing="1" border="0" class="gird">
                    
                    <thead>
                        <td>
                        广告文件
                        </td>
                    </thead>
                    
                    <tr>
                        <td>
                        <input type="hidden" size="35" name="config[THUMB-FILE]" value="<?php echo $config["THUMB-FILE"];?>" />
						<script type="text/javascript">
                        new Serv.Upload("_mini_","<?php echo $config["THUMB-FILE"];?>",{'format':['<?php echo implode("','",$_G['upload']['image']);?>','<?php echo implode("','",$_G['upload']['flash']);?>'],'again':true,'recovery':true,'input':false,'callback':doThumb});
                        </script>
                        </td>
                    </tr>
                    
                    <thead>
                        <td>
                         广告尺寸
                        </td>
                    </thead>
                    
                    <tr>
                        <td>
                        <input name="config[THUMB-WIDTH]" type="text" class="text" value="<?php echo $config["THUMB-WIDTH"];?>" size="5" fix_name="广告宽度" fix_number="no">
                        ×
                        <input name="config[THUMB-HEIGHT]" type="text" class="text" value="<?php echo $config["THUMB-HEIGHT"];?>" size="5" fix_name="广告高度" fix_number="no" />
                        
                        <script>Mo.Tools("Tip","默认为0；图片或Flash需要设置这里，否则广告可能无法显示");</script>
                        </td>
                    </tr>
                    
                    </table>
                    
                </td>                
            </tr>
            
            
            <?php
			//商业版开始
			if( $_G['licence']['type']!="free" ){
			?>
		
			<tr>
				<td><strong>统计功能：</strong></td>
				<td>
                    <label><input type="checkbox" class="checkbox" id="STAT-VIEWS" name="config[STAT-VIEWS]" value="Y" /> 统计显示数</label>
                    <label><input type="checkbox" class="checkbox" id="STAT-CLICK" name="config[STAT-CLICK]" value="Y" /> 统计点击数</label>
				</td>
			</tr>
            
            <?php
			}
			?>
        
        	<!--tr text="控制广告最大展示与点击次数">
            	<td><strong>投放控制：</strong></td>
                <td>
					
                    <table cellpadding="0" cellspacing="1" border="0" class="gird">
                        <tr>
                            <td>
                            最大展示<br />
                            <input type="text" size="10" id="MAX-VIEWS" name="MAX-VIEWS" onchange="cfg.setValue(this.value,this.id,this.value,function(S){$('config').value = S;});" value="<?php echo $config["MAX-VIEWS"];?>" fix_name="最大展示" fix_number="no" /> 次数
                            </td>
                            <td>
                            最大点击<br />
                            <input type="text" size="10" id="MAX-CLICKS" name="MAX-CLICKS" onchange="cfg.setValue(this.value,this.id,this.value,function(S){$('config').value = S;});" value="<?php echo $config["MAX-CLICKS"];?>" fix_name="最大点击" fix_number="no" /> 次数
                            <script>Mo.Tools("Tip","对代码广告无效");</script>
                            </td>
                        </tr>
                    </table>
                    
                </td>
                
            </tr-->
        
        </tbody>        
		
		<tr>
			<td colspan="2" class="section pointer" onclick=" Mo('#box-financial').toggle( 0, function( ele, vis ){ if( vis ){ Mo('#sel-financial').attr({ 'class' : 'open' }); }else{ Mo('#sel-financial').attr({ 'class' : 'close' }); } } ); "><a id="sel-financial" class="close"></a><strong>财务信息</strong></td>                
		</tr>
	
		<tbody id="box-financial" style="display:none;">
	
		<tr>
			<td width="60"><strong>合同信息：</strong></td>
			<td>
				
                <table cellpadding="0" cellspacing="1" border="0" class="gird">
                	<tr>
                    	<td>
                        合同名称或编号<br />
                        <input name="contract" type="text" class="text" id="contract" value="<?php echo $row["contract"];?>" size="35" />
                        </td>
                    	<td>
                        销售人员<br />
                        <select name="owner" id="owner">
                        	<option value=''></option>
                            <?php
							foreach( $_CACHE['system']['admin'] as $aid => $acc ){
								echo '<option value="'.$aid.'">'.$acc["account"].'</option>';	
							}
							?>
                        </select>
                        </td>
                    </tr>
                </table>
                
			</td>
			
		</tr>
		
		<tr>
			<td width="60"><strong>收款情况：</strong></td>
			<td>
                
                <table cellpadding="0" cellspacing="1" border="0" class="gird">
                	<tr>
                    	<td>
                        应收款<br />
                        <input name="ar" type="text" class="text" id="ar" value="<?php echo $row["ar"];?>" size="20">
                        </td>
                    	<td>
                        实收款<br />
                        <input name="pr" type="text" class="text" id="pr" value="<?php echo $row["pr"];?>" size="20">
                        </td>
                    </tr>
                </table>
                
			</td>
			
		</tr>
        
        <?php
		//商业版开始
		if( $_G['licence']['type']=="free" ){
		?>
        </tbody>
        
        <?php
		}else{
		?>
		
		<tr>
			<td width="60"><strong>客户信息：</strong></td>
			<td>
                
                <table cellpadding="0" cellspacing="1" border="0" class="gird">
                	<tr>
                    	<td>
                        客户名称<br />
                        <input name="custom" type="text" class="text" id="custom" value="<?php echo $row["custom"];?>" size="35" fix_name="客户名称" fix_null="no" />
                        </td>
                    	<td>
                        联系方式<br />
                        <input name="contact" type="text" class="text" id="contact" value="<?php echo $row["contact"];?>" size="35" />
                        </td>
                    </tr>
                </table>
                
			</td>
			
		</tr>
		
		</tbody>
		
		<tr>
			<td colspan="2" class="section pointer" onclick=" Mo('#box-share').toggle( 0, function( ele, vis ){ if( vis ){ Mo('#sel-share').attr({ 'class' : 'open' }); }else{ Mo('#sel-share').attr({ 'class' : 'close' }); } } ); "><a id="sel-share" class="close"></a><strong>共享广告</strong></td>                
		</tr>
		  
        <tbody id="box-share" style="display:none;">
		
			<tr>
				<td><strong>选择位置：</strong></td>
				<td>
				
					<label>
					<select name="s_parent" id="s_parent" style="width:150px;" onchange="_adAREA(Mo('select[name=s_parent]').value(),Mo('select[name=s_type]').item(0));Mo('select[name=s_type]').value('<?php echo $type;?>');">
					<?php
					foreach($_CACHE['adsview']['adsarea'] as $key){
						if($key["parent"]=="0"){
							echo '<option value="'.$key["id"].'">'.$key["name"].'</option>';
						}
					}
					?>
					</select><select name="s_type" id="s_type" style="width:150px;">
					<?php echo $sub_option;?>
					</select>
					</label>
				
					<input type="button" class="button" name="button" value="添 加" onclick="SelectAppend('list',Mo('select[name=s_parent]').text()+' > '+Mo('select[name=s_type]').text(),Mo('select[name=s_type]').value());SelectValue('list','share');" />
					<script>Mo.Tools("Tip","<strong>共享广告</strong><br /> 用于将一个广告同时投放到多个广告位");</script>
					
				</td>
				
			</tr>
		
			<tr>
				<td><strong>已选位置：</strong></td>
				<td>
				
					<select name="list" id="list" size="8" style="width:300px;">
                    <?php
					
					if( $row["share"] ){
					
						//共享广告位				
						$share = explode(",",$row["share"]);
						
						for($i=0;$i<count($share);$i++){
							
							$sid = intval($share[$i]);
							
							if( $sid ){
								echo '<option value="'.$sid.'"> '.$_CACHE['adsview']['adsarea'][$_CACHE['adsview']['adsarea'][$sid]["parent"]]["name"].' > '.$_CACHE['adsview']['adsarea'][$sid]["name"].'</option>';
							}
							
						}
					
					}
					
					?>
					</select>
					<input type="button" class="button" name="button" style="vertical-align:top;" value="删 除" onclick="SelectDelete('list','share');" />
					<input name="share" id="share" type="hidden" value="<?php echo $row["share"];?>" />
					<input name="share_old" id="share_old" type="hidden" value="<?php echo $row["share"];?>" />
				
				</td>
				
			</tr>
		</tbody>
		
        <tr><td colspan="2" class="section pointer" onclick=" Mo('#box-zone').toggle( 0, function( ele, vis ){ if( vis ){ Mo('#sel-zone').attr({ 'class' : 'open' }); }else{ Mo('#sel-zone').attr({ 'class' : 'close' }); } } ); "><a id="sel-zone" class="close"></a><strong>地区限制</strong></td></tr>
		  
        <tbody id="box-zone" style="display:none;">
		
			<tr text="按 Ctrl + 单击 进行多选，按 Shift + 单击 进行连续多选">
				<td><strong>选择地区：</strong></td>
				<td valign="top">
				
                  <select id="province" size="10" style="width:140px;" multiple="multiple" onclick="Mo.China.getValue( [Mo('#province').item(0), Mo('#city').item(0)], Mo('#zone').item(0) );">
                    <option value="">不限地区</option>
                  </select>
                    <?php echo loader_image("icon/plus.png");?>
                  <select id="city" size="10" style="width:140px;" multiple="multiple" onclick="Mo.China.getValue( [Mo('#province').item(0), Mo('#city').item(0)], Mo('#zone').item(0) );">
                    <option value="">不限城市</option>
                  </select>
                    <?php echo loader_image("icon/right.png");?>
                  <textarea rows="11" id="zone" name="zone" style="vertical-align:top; width:200px;"><?php echo $row["zone"];?></textarea>
                  <script>Mo.Tools("Tip","多个请用逗号 ( , ) 分隔，访问者地理位置匹配才会出现相应广告");</script>
                   
                   <?php
                   //IP 数据库检查
                   
                   if( !file_exists( VI_ROOT.'source/ipdata/wry.dat' ) ) {
                   
                        echo "<div id='state' class='failure'>IP 数据库没有找到，请到 <a href='http://update.cz88.net/soft/qqwry.rar' target='_blank'>这里下载</a> 并解压缩上传至 /source/ipdata/</div>";
                   
                   }
                   
                   ?>
				
				</td>
			</tr>
		
        </tbody>
        
        <script type="text/javascript">

		_adAREA( Mo("#s_parent").value(), Mo("#s_type").item(0) );
		
		Mo.reader(function(){
			Mo.China( Mo("#province").item(0), 'province' );
			Mo.China( Mo("#city").item(0), 'city');
			
			Mo.China.setValue( [Mo("#province").item(0), Mo("#city").item(0)], Mo("#zone").item(0) );
		});
		
		</script>
        
        <?php
		}
		//商业版结束
		
		//广告扩展
		if( file_exists("include.extend.php") ){
			include("include.extend.php");	
		}
		
		?>
        
        <tbody>
        <tr class="nobr">
            <td><strong></strong></td>
            <td>
                <?php
                if ($action=="edit"){                
                    echo '
                    <input type="submit" name="Submit" value="修改此广告" class="submit" />
                    <input name="id" type="hidden" id="id" value="'.$row['id'].'" />
                    <input name="action" type="hidden" id="action" value="update" />
                    ';
                }else{
                    echo '
                    <input type="submit" name="Submit" value="新增此广告" class="submit" />
                    <input name="action" type="hidden" id="action" value="add" />
                    ';
                }
                
                echo '<input name="jump" type="hidden" id="jump" value="'.$jump.'" />';
                ?>
            </td>
            
        </tr>
        </tbody>
        
        </table>
            
	 </form>
     
	<?php
    if( $action ){
				
		$link = "adsview.preview.php?action=ad&id=".$row['id'];

    ?>
    <table cellpadding="0" cellspacing="0" class="form">
    <tbody>
    
        <tr><td class="section"><span><a href="<?php echo $link;?>" target="_blank">新窗口预览&raquo;</a></span><strong>广告预览</strong></td></tr>
    
        <tr>
            <td>
                <iframe id="iframe" src="<?php echo $link;?>" frameborder="0" style="width:100%; height:<?php echo ($row["height"]+50);?>px;"></iframe>
            </td>
        </tr>
	</tbody>
	</table>
    
	<?php
    }
    ?>
	
	<script type="text/javascript">
	
		Mo("input[name=state]").value("<?php echo isset($row['state']) ? $row['state'] : 1;?>");
		
		//切换广告形式
		Mo("input[name=form]").bind("click",doForm).value("<?php echo isset($row['form']) ? $row['form'] : 0;?>");
		
        doForm();
		
		Mo("input[name=spare]").value("<?php echo $row["spare"];?>");
		Mo("#owner").value( "<?php echo $row["owner"];?>" );
		
		////////////////////////
		
		<?php
		
		if( $_G['setting'][$appid]["stat"] == "on" && !$action ){
			$config['STAT-VIEWS'] = 'Y';
			$config['STAT-CLICK'] = 'Y';
		}
		
		?>
		
		Mo("input[name='config[STAT-VIEWS]']").value("<?php echo $config['STAT-VIEWS'];?>");
		Mo("input[name='config[STAT-CLICK]']").value("<?php echo $config['STAT-CLICK'];?>");
		
		////////////////////////////////////
		
		//频道
		Mo("#parent").bind("change",function(){
		
			//筛选广告位
			_adAREA( Mo(this).value(), Mo('#type').item(0) );
			
			//输出广告位信息
			getAdInfo( Mo("#type").value() );
		
		}).value( "<?php echo $row["parent"];?>" );
		
		//筛选广告位
		_adAREA( Mo("#parent").value(), Mo("#type").item(0) );
		
		//////////////////
		
		//广告位
		Mo("#type").bind("change",function(){
		
			//输出广告位信息
			getAdInfo( Mo(this).value() );
										   
		}).value( "<?php echo $row["type"];?>" );
		
		//输出广告位信息
		getAdInfo( Mo("#type").value() );
		
		///////////////////////////////////////
		
		Mo("select[name='config[LINK-TARGET]']").value("<?php echo isset($config['LINK-TARGET']) ? $config['LINK-TARGET'] : '_blank';?>");
		
    </script>
  
	</div>
	
	<?php		  
	  
	//关闭数据库
	System :: connect();
	
	?>
    
<!--body end-->

<?php html_close();?>