<?php

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

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

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

	//module
	require("naver.php");	
	
	//返回列表页参数
	$jump = GetQuery("jump");
	
	//////////////////////////////
	
	//mysql open
	reader_mysql();
	
	if( !loader_cache($appid,"table.adsarea") ){
		
		//更新分类数组缓存
		cache_table($appid,$mysql,VI_DBMODPRE."adsarea",'<option value=\'{table:id}\'>{table:name}</option>');
		
		//更新分类脚本缓存
		cache_script($appid,$mysql,"SELECT id,name,parent FROM ".VI_DBMODPRE."adsarea where parent>0","ADSAREA","mod.adsarea",'	#var[{table:id}] = new Array({table:id},{table:parent},"{table:name}");'.chr(13));
	}
	
	$action = GetQuery("action");
	$type = GetNumber("type",0);
	$parent = GetNumber("parent",0);		
	
	if ($action){
		
		//基本信息
		$id = GetNumber("id",0);
		$name = GetQuery("name");
		$status = GetNumber("status",0);
		$link = GetQuery("link");
		$file = GetQuery("adsview");
		$sort = GetNumber("sort",0);
		$tags = GetQuery("tags");
		$zone = GetQuery("zone");
		
		//财务信息
		$owner = GetNumber("owner",0);
		$contract = GetQuery("contract");
		$custom = GetQuery("custom");
		$a_contact = GetQuery("a_contact");
		$ar = GetNumber("ar",0);
		$pr = GetNumber("pr",0);
		
		//配置
		$config = $_POST["config"];
		$config = format_json( fix_json( $config ) );
		
		$category = GetQuery("category");		
		
		//开始时间
		$start = GetQuery("start");
		$start_time = GetQuery("start_time");
		
		if( !$start || !isDateTime($start." ".$start_time) ){
			$start = time();				
		}else{				
			$start = strtotime($start." ".$start_time);
		}
		
		//结束时间
		$expire = GetQuery("expire");
		$expire_time = GetQuery("expire_time");
		
		if( !$expire || !isDateTime($expire." ".$expire_time) ){
			$expire = time();
		}else{
			$expire = strtotime($expire." ".$expire_time);
		}
		
		//权限检查
		$script=$_POST["script"];
		
		$width = GetNumber("width",0);
		$height = GetNumber("height",0);
		
		$form = GetNumber("form",0);
		$spare = GetNumber("spare",0);
		
		//共享广告
		$share = GetQuery("share");
		$share_old = GetQuery("share_old");		

		//重置默认广告
		if($spare){
			$sql="update ".VI_DBMODPRE."adsview set spare=0 where type=".$type;
			mysql_query($sql,$mysql);
			
			$Project["queries"]++;
		}
		
		switch($action){
			case "add":
			
				//检查权限
				checker_func("mod-adsview-add");		
			
				$sql="insert into ".VI_DBMODPRE."adsview(name,status,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."',".$status.",'".$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."')";
		
				mysql_query($sql,$mysql);
				
				$Project["queries"]++;
				
				$id = mysql_insert_id($mysql);
				
				//错误处理
				if (!$id) {
					trigger_error($sql, E_USER_ERROR);
					exit();
				}		
				
				//生成广告
				ad_create("SELECT * FROM ".VI_DBMODPRE."adsarea where id =".$type ,$mysql);
			
				//共享广告
				ad_create("SELECT * FROM ".VI_DBMODPRE."adsarea where id in(0,".$share.")",$mysql);
				
				//缓存广告缓存
				cache_rows($appid,$mysql,VI_DBMODPRE."adsview","select * from ".VI_DBMODPRE."adsview where id=".$id);

				reader_redirect("adsview.list.php?mark=".$id,"广告增加成功!");
				
			break;
			
			case "update":
		
				//检查权限
				checker_func("mod-adsview-mod");		
				
				//广告启示录用才会有投放状态
				$sql="update ".VI_DBMODPRE."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='".$a_contact."',config='".$config."',category='".$category."',modify=".time().",status='".$status."',mender='".$_SESSION["Manager"]["account"]."' where id=".$id;
				
				mysql_query($sql,$mysql);
				
				$Project["queries"]++;
				
				//生成广告
				ad_create("SELECT * FROM ".VI_DBMODPRE."adsarea where id =".$type,$mysql);
				
				//共享广告
				ad_create("SELECT * FROM ".VI_DBMODPRE."adsarea where id in(0,".$share.")",$mysql);
				
				if($share_old != $share){
					ad_create("SELECT * FROM ".VI_DBMODPRE."adsarea where id in(0,".$share_old.")",$mysql);
				}
				
				//缓存广告缓存
				cache_rows($appid,$mysql,VI_DBMODPRE."adsview","select * from ".VI_DBMODPRE."adsview where id=".$id);		

				if(!$jump){
					$jump="adsview.list.php";
				}
				
				reader_redirect($jump,"广告修改成功!");
				
			break;
			
			case "edit":
		
				//检查权限
				//checker_func("mod-adsview-mod");		
		
				$sql="select * from ".VI_DBMODPRE."adsview where id=".$id;
				$result=mysql_query($sql,$mysql);
				
				$Project["queries"]++;
				
				if(mysql_num_rows($result)==1){
					$row=mysql_fetch_assoc($result);
					
					$config = fix_json($row["config"]);
					
					//共享广告位				
					$share = $row["share"];
					
					$share_select=explode(",",$share);
					
					for($i=0;$i<count($share_select);$i++){
						$sid=intval($share_select[$i],0);
						
						if($sid){								
							$share_option.='<option value="'.$sid.'"> '.$VICACHE["mod.adsarea"][$VICACHE["mod.adsarea"][$sid]["parent"]]["name"].' > '.$VICACHE["mod.adsarea"][$sid]["name"].'</option>';
						}
					}
					
				}
				
			break;
					
		}
		
	}
	  
	  
	//mysql close
	reader_mysql(true);

?>
<!--main-->

	<?php   
	
	//缓存更新时间
	$rnd = @filemtime(VI_ROOT."/".$Project["cache"]."/".$appid."/script.adsarea.js");
		
    echo loader_script(array(VI_BASE."cache/".$appid."/script.adsarea.js?rnd=".$rnd),$Project["charset"],$Project["version"]);
	
	///////////////////////////
		
    echo loader_script(array(VI_BASE."js/mo.china.js",VI_BASE."js/mo.calendar.js"),"utf-8",$Project["version"]);    
    ?>
    
	<script type="text/javascript">
	
	function _adAREA(P,O){
		var A = ADSAREA;
		
		O.length=0;
		
		for(var B in A){
			if(P == A[B][1]){
				O.options[O.length] = new Option(A[B][2],A[B][0]);
			}
		}
	}
	
	function _inScript(s){
    	if(s=="script"){
      		Mo("#script").value( Mo("#script").value()+='\nVAD.$V(\'<scr\'+\'ipt type="text/javascript" src="" charset=""></scr\'+\'ipt>\');' );
		}else{
      		Mo("#script").value( Mo("#script").value()+="\nVAD."+s.replace("()",'("")') );
		}
	}
	
	function _adForm(){
		var o = Mo("input[name=form]").value();
		
		if( o == 1 ){
			Mo("#ad_form_0").hide();
			Mo("#ad_form_script").show();
		}else{
			Mo("#ad_form_1").hide();
			Mo("#ad_form_script").hide();
		}
		
		Mo("#ad_form_"+o).show();
	}
	
	function _adHTML(){
		Mo("#Re").value( "VAD.$V(\""+Mo("#oResult").value().replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\'/g,"\\\'").replace(/\"/g,"\\\"").split('\r\n').join("\");\nVAD.$V(\"")+"\");" );
	}
	
	function _adSzie( o ){
		
		if( Mo("#width").size() == 0 ){
			return;
		}
		
		var image = o["image"];
		
		if( image["width"] && image["height"] ){
			Mo("#width").value( image["width"] );
			Mo("#height").value( image["height"] );
		}else{
			Mo("#width").value("");
			Mo("#height").value("");
		}
	}
	
	function getAdInfo( id ){
		
		var SHOW = <?php echo "['". implode("','",$Modules[$appid]["type"]) ."']";?>;
		
		if( ADSAREA[id] ){
			Mo('#ad_info').html( '类型：'+ SHOW[ADSAREA[id][3]] + ' - 尺寸：'+ ADSAREA[id][4] + ' - 数量：'+ ADSAREA[id][5] );
		}else{
			Mo('#ad_info').html( '' );	
		}
	}
	</script>
    
	<?php
	
	//显示权限状态
	switch($action){
		case "":
			echo checker_func("mod-adsview-add",true);
		break;
		
		case "edit":
			echo checker_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 text='按内容性质进行分类归档'>
                <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($Global["category"])));?>'] }, function( value ){ this.value = value; }, 1 , 23 );" readonly="true" value="<?php echo $row["category"];?>" onfocus="this.blur();" />                    
                </td>
            </tr>
        
        	<tr>
            	<td width="60"><strong>广告名称：</strong></td>
                <td>
					<input name="name" type="text" class="text" id="name" value="<?php echo $row["name"];?>" size="45" fix_name="广告名称" fix_null="yes" />
            
                    <!--input type="text" name="sort" id="sort" title="显示排序" class="text digi" onclick="Mo.Soler(this,this.value,this.title,-9,10,10);" readonly="true" value="<?php echo $row["sort"] ? $row["sort"] : "0";?>" /-->
                    
                    <input type="text" name="sort" id="sort" title="显示排序" class="text digi" onclick="Mo.Soler(this,this.value,this.title,(function(){ var a = []; for(var i=-9;i<=10;i++){ a.push(i);} return a; })(),10);" readonly="true" value="<?php echo $row["sort"] ? $row["sort"] : "0";?>" />
                    
					<script>Mo.Tools("Tip","<strong>显示排序</strong><br /> 广告显示的顺序，从小到大");</script>
				</td>
            </tr>
        
        	<tr>
            	<td><strong>广告位置：</strong></td>
                <td>
					<select name="parent" id="parent" style="width:179px;" onChange="_adAREA(Mo('select[name=parent]').value(),$('type'));setSelect('type','<?php echo $row["type"];?>');">
                    
					<?php
					//var_dump($VICACHE["mod.adsarea"]);
					foreach($VICACHE["mod.adsarea"] as $key){
						if($key["parent"]=="0"){
							echo '<option value="'.$key["id"].'">'.$key["name"].'</option>';
						}
					}
					?>
                    
					</select>
					-
					<select name="type" id="type" style="width:179px;" onchange="getAdInfo(Mo(this).value());">
					<?php
					foreach($VICACHE["mod.adsarea"] as $key){
						if($key["parent"]==$parent && $parent){
							echo '<option value="'.$key["id"].'">'.$key["name"].'</option>';
						}
					}
					
					?>
					
					</select>
                </td>
                
            </tr>
        
        	<tr>
            	<td><strong>广告属性：</strong></td>
                <td id="ad_info">
                    
                </td>
                
            </tr>        
        
        	<tr>
            	<td><strong>起止时间：</strong></td>
                <td>
                    <input name="start" 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 type="text" name="start_time" 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" 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 type="text" name="expire_time" 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>
					<input name="tags" id="tags" size="58" class="text" value="<?php echo $row["tags"];?>" />
					<script>Mo.Tools("Tip","本广告的关键字，用于搜索广告或文本广告信息显示");</script>
				</td>
			</tr>
            
            <tr>
                <td><strong>广告状态：</strong></td>
                <td>
                    <label>
                    <input type="radio" class="radio" name="status" value="1" checked> 
                    启用状态
                    </label>
                    <label>
                    <input type="radio" class="radio" name="status" value="0">
                    禁用状态
                    </label>
                </td>
                
            </tr>
        
        	<tr>
            	<td><strong>广告形式：</strong></td>
                <td>
					<label>
					<input name="form" type="radio" class="radio" value="0" checked="checked" onclick="_adForm();"> 
					普通广告
					</label>
					<label>
					<input name="form" type="radio" class="radio" value="1" onclick="_adForm();$('script').focus();">
					代码广告
					</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内容">$V();</a>
						|
						<a href="javascript:void(0);" onclick="_inScript(this.innerHTML)" title="获取对象">getObject();</a>
						|
						<a href="javascript:void(0);" onclick="_inScript(this.innerHTML)" title="销毁对象">delObject();</a>
						|
						<a href="javascript:void(0);" onclick="_inScript(this.innerHTML)" title="获取对象的绝对位置">getPosition();</a>
						|
						<a href="javascript:void(0);" onclick="_inScript(this.innerHTML)" title="输出一个SCRIP标签">script</a>
						|
						<a href="javascript:void(0);" onclick="toggle('ad_form_html');" title="显示/隐藏 HTML转JS工具">HTML 转 JS ?</a>
					</div>
					
					<div id="ad_form_html" style="display:none;">
						<p><strong>源代码区：</strong>
							
							1. 请将HTML代码粘贴到下面文本框中: <br>
							<strong>&nbsp;</strong>
							<textarea id="oResult" onpropertychange="_adHTML()" ondblclick='this.select();oResult.createTextRange().execCommand("Copy")' title="双击复制" rows="10"></textarea>
						</p>
						
						<p><strong>结果代码：</strong>
			
							2. 自动生成相应的 JavaScript 代码: <br />
							<strong>&nbsp;</strong>
							<textarea id="Re" ondblclick='this.select();this.createTextRange().execCommand("Copy")' title="双击复制" cols="10" rows="10"></textarea>
							<br />
							<strong>&nbsp;</strong>3. 将上面的 JavaScript 代码复制到下面的广告内容中: <br />
						</p>
					</div>
				</td>
                
            </tr>
        
        	<tr>
            	<td width="60"><strong>智能标签：</strong></td>
                <td>
					<div>
						<a href="javascript:void(0);" onmouseover='Mo.Tips(event,this,"tips","放在需要统计的URL前，用于统计代码广告的点击",this,"mouseout",this.offsetWidth);' onclick="setValue('script',this.innerHTML,'add')">{LINK}</a>
						
						<a href="javascript:void(0);" onmouseover='Mo.Tips(event,this,"tips","放在需要统计的URL中，用于统计点击的路径，可以用于不同链接的区分",this,"mouseout",this.offsetWidth);' onclick="setValue('script',this.innerHTML,'add')">{VAR}</a>
					</div>
				</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" rows="10" id="script" style="font-family:Verdana;"><?php echo $row["script"];?></textarea>
                </td>
                
            </tr>
        
        </tbody>
		
        <tbody id="ad_form_0" style="display:none;">
        
        	<tr>
            	<td width="60"><strong>链接地址：</strong></td>
                <td>
					<input name="link" type="text" class="text" id="link" value="<?php echo $row["link"];?>" size="45" fix_name="链接地址" fix_null="no">
                    <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>

			<tr>
				<td><strong>广告文件：</strong></td>
				<td>
					<script type="text/javascript">
					new Serv.Upload("<?php echo $appid;?>","<?php echo $row["file"];?>",{'format':['<?php echo implode("','",$Upload["image"]);?>','<?php echo implode("','",$Upload["flash"]);?>'],'again':true,'recovery':true,'input':true,'ubb':"description",'callback':_adSzie});
					</script>
				</td>

			</tr>
        
        	<tr>
            	<td><strong>广告尺寸：</strong></td>
                <td>				
					<input name="width" type="text" class="text" id="width" value="<?php echo $row["width"];?>" style="width:101px;" fix_name="广告宽度" fix_number="no">
					×
					<input name="height" type="text" class="text" id="height" value="<?php echo $row["height"];?>" style="width:101px;" fix_name="广告高度" fix_number="no" />
                    
                    <script>Mo.Tools("Tip","默认为0；图片或Flash需要设置这里，否则广告可能无法显示");</script>
                </td>
                
            </tr>
        
        	<tr><td colspan="2" class="section"><strong>扩展设置</strong></td></tr>
            
			<tr>
				<td><strong>替补广告：</strong></td>
				<td>
				
					<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>
         
        	<tr>
            	<td><strong>广告样式：</strong></td>
                <td>
                    <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>
        
        	<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="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>
                            展示间隔<br />
                            <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>
                    </table>
                    
                    
                </td>
                
            </tr>
		
			<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>
        
        	<!--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' }); ele.scrollIntoView(true); }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 echo $VICACHE["sys.admin.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( $Licence["type"]=="full" ){
		?>
		
		<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' }); ele.scrollIntoView(true); }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(),$('s_type'));setSelect('s_type','<?php echo $type;?>');">
					';
					<?php
					foreach($VICACHE["mod.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="add2Select('list',getSelect('s_parent').text+' > '+getSelect('s_type').text,getSelect('s_type').value);loadSelect('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 echo $share_option;?>
					</select>
					<input type="button" class="button" name="button" style="vertical-align:top;" value="删 除" onclick="delete2Select('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' }); ele.scrollIntoView(true); }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>
					  
					  <br />
					   <span class="text-key"><?php echo loader_image("icon/bubble.png");?> 区域广告代码必须使用 <a href="http://www.veryide.com/archive.php?id=51" target="_blank">搜索广告代码</a> 进行投放</span>
                       
                       <?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> 并解压缩上传至 /veryide/source/ipdata/</div>";
					   
					   }
					   
					   ?>
				
				</td>
			</tr>
		
        </tbody>
        
        <?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=status]").value("<?php echo $row["status"] ? $row["status"] : 1;?>" );
		
		Mo("input[name=form]").value("<?php echo $row["form"] ? $row["form"] : 0;?>");
        _adForm();
		
		Mo("input[name=spare]").value("<?php echo $row["spare"];?>");
		Mo("#owner").value( "<?php echo $row["owner"];?>" );
		
		////////////////////////
		
		<?php
		
		if( $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").value( "<?php echo $row["parent"];?>" );
		
		_adAREA( Mo("#parent").value(), Mo("#type").item(0) );	
		
		Mo("#type").value( "<?php echo $row["type"];?>" );
		
		///////////////////////////////////////
		
		Mo("input[name='config[LINK-TARGET]']").value("<?php echo $config['LINK-TARGET'];?>");
		
		<?php
		//商业版开始
		if( $Licence["type"]=="full" ){
		?>

		_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) );
		});
		
		<?php
		}
		//商业版结束
		?>
		
    </script>
  
	</div>
    
<!--body end-->

<?php html_close();?>