<?
	require_once("user__check.php");

	// 获取或设置参数
	$job=trim($job);

	// 已提交表单 (添加|修改|删除|改变状态)
	if($check=="ok"){	

		if($job==""){
			$flag="error";
			show_msg("错误：未知操作！","-1");
		}
		else{
			if($job=="add" or $job=="modify"){
				if(strlen($name)<1){
					$flag="error";
					show_msg("错误：没有输入方案名称！","-1");
				}
			}
			else{
				if($id<>""){
					$ids=array($id);
				}
				else{
					$ids=split(",",$ids);
				}
			}
		}

		if($flag<>"error"){
			$style=floor($style);
			$choose1=floor($choose1);
			$choose2=floor($choose2);
			switch($job){
				case "add":
					// 添加内容
					$sql="insert into ".TBL_POST."(name,style,choose1,choose2,status,uid) values('".$name."',".$style.",".$choose1.",".$choose2.",2,".$uid.")";
					mysql_query($sql);
					$id=mysql_insert_id();
					break;
				case "modify":
					// 修改内容
					$sql="update ".TBL_POST." set name='".$name."',style=".$style.",choose1=".$choose1.",choose2=".$choose2." where uid=".$uid." and id=".floor($id);
					mysql_query($sql);
					break;
				case "delete":
					// 删除内容
					foreach($ids as $id){
						$sql="update ".TBL_POST." set status=-1 where uid=".$uid." and id=".floor($id);
						mysql_query($sql);		
					}				
					break;
				default:
					// 改变状态
					foreach($ids as $id){
						$sql="update ".TBL_POST." set ".$job."=3-".$job." where uid=".$uid." and id=".floor($id);
						mysql_query($sql);
					}
					break;		
			}

			if(mysql_error()<>""){
				show_msg("数据库操作出错，请联系客服！");			
			}
			else{
				// 数据添加成功则变成修改数据
				$job=$job=="add"?"modify":$job;
				if($job=="modify"){
					$str="Eachgain_uid=$uid;\r\nEachgain_cid=$id;\r\nEachgain_style=$style;\r\nEachgain_choose1=$choose1;\r\nEachgain_choose2=$choose2;\r\nEachgain_status=2;";
					$folder=$path["root"]."/code/data/".$uid."/";
					if(!is_dir($folder)){
						mkdir($folder,0777);
					}
					$filename=$folder.$id.".js";
					$handle=fopen($filename,"w");
					fwrite($handle,$str);
					fclose($handle);
					show_msg("数据更新成功！","?m=$m&n=$n&goto=".basename(__FILE__,".php")."_code.php&id=$id");
				}
				else{
					// 更新脚本代码
					show_msg("数据更新成功！","-1");
				}
			}

		}

	}

	// 未提交表单
	$content=array();
	if($job=="modify"){
		$content=mysql_fetch_array(mysql_query("select * from ".TBL_POST." where uid=".$uid." and id=".floor($id)));
	}
?>

<fieldset>代码投放 - 方案配置</fieldset>

<form method="post" onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<td width="150" align="right">代码样式&nbsp;&nbsp;<br><br>及代码显示位置：</td>
		<td height="260" valign="middle">
			<label onclick="show_style(11)">&nbsp;1、图文混排</label><br>
			<span id="style_a" style="width:260px;margin-left:40px;background:#F6F6F6;display:none;">
				<input type="radio" id="option11" name="style" value="11">&nbsp;<label for="option11">位置固定，大小为[ 760x240 ]</label> [<a href="../code/data/?sid=11" target="preview">预览</a>] <br>
				<input type="radio" id="option12" name="style" value="12">&nbsp;<label for="option12">位置固定，大小为[ 996x130 ]</label> [<a href="../code/data/?sid=12" target="preview">预览</a>] <br>
				<input type="radio" id="option13" name="style" value="13">&nbsp;<label for="option13">位置固定，大小为[ 500x240 ]</label> [<a href="../code/data/?sid=13" target="preview">预览</a>] <br>
				<input type="radio" id="option14" name="style" value="14">&nbsp;<label for="option14">位置固定，大小为[ 250x440 ]</label> [<a href="../code/data/?sid=14" target="preview">预览</a>] <br>
				<input type="radio" id="option15" name="style" value="15">&nbsp;<label for="option15">位置固定，大小为[ 760x130 ]</label> [<a href="../code/data/?sid=15" target="preview">预览</a>] <br>
				<input type="radio" id="option16" name="style" value="16">&nbsp;<label for="option16">位置固定，大小为[ 250x350 ]</label> [<a href="../code/data/?sid=16" target="preview">预览</a>] <br>
				<input type="radio" id="option17" name="style" value="17">&nbsp;<label for="option17">位置固定，大小为[ 500x130 ]</label> [<a href="../code/data/?sid=17" target="preview">预览</a>] <br>
				<input type="radio" id="option18" name="style" value="18">&nbsp;<label for="option18">位置固定，大小为[ 250x230 ]</label> [<a href="../code/data/?sid=18" target="preview">预览</a>] <br>
				<input type="radio" id="option19" name="style" value="19">&nbsp;<label for="option19">位置固定，大小为[ 250x130 ]</label> [<a href="../code/data/?sid=19" target="preview">预览</a>] <br>
			</span>			
			<label onclick="show_style(21)">&nbsp;2、纯文字链</label><br>
			<span id="style_b" style="width:300px;margin-left:40px;background:#F6F6F6;display:none;">
				<input type="radio" id="option21" name="style" value="21">&nbsp;<label for="option21">页面漂浮，始终处在页面的左上角</label> [<a href="../code/data/?sid=21" target="preview">预览</a>] <br>
				<input type="radio" id="option22" name="style" value="22">&nbsp;<label for="option22">页面漂浮，始终处在页面的左下角</label> [<a href="../code/data/?sid=22" target="preview">预览</a>] <br>
				<input type="radio" id="option23" name="style" value="23">&nbsp;<label for="option23">页面漂浮，始终处在页面的右上角</label> [<a href="../code/data/?sid=23" target="preview">预览</a>] <br>
				<input type="radio" id="option24" name="style" value="24">&nbsp;<label for="option24">页面漂浮，始终处在页面的右下角</label> [<a href="../code/data/?sid=24" target="preview">预览</a>] <br>
			</span>
			<label onclick="show_style(31)">&nbsp;3、图片网摘</label><br>
			<span id="style_c" style="width:400px;margin-left:40px;background:#F6F6F6;display:none;">
				<input type="radio" id="option31" name="style" value="31">&nbsp;<label for="option31">页面跟随，跟随滚动条移动且始终处在屏幕正左方（小）</label> [<a href="../code/data/?id=31" target="preview">预览</a>] <br>
				<input type="radio" id="option32" name="style" value="32">&nbsp;<label for="option32">页面跟随，跟随滚动条移动且始终处在屏幕正右方（小）</label> [<a href="../code/data/?id=32" target="preview">预览</a>] <br>
				<input type="radio" id="option33" name="style" value="33">&nbsp;<label for="option33">页面跟随，跟随滚动条移动且始终处在屏幕正左方（大）</label> [<a href="../code/data/?id=33" target="preview">预览</a>] <br>
				<input type="radio" id="option34" name="style" value="34">&nbsp;<label for="option34">页面跟随，跟随滚动条移动且始终处在屏幕正右方（大）</label> [<a href="../code/data/?id=34" target="preview">预览</a>] <br>
			</span>
		</td>
	</tr>
	<tr>
		<td align="right">缺省标签类型：</td>
		<td>
			<input type="radio" id="option51" name="choose1" value="0" <?=$content["choose1"]=="0"?"checked":"";?>> <label for="option51">热点</label>
			<input type="radio" id="option52" name="choose1" value="1" <?=$content["choose1"]=="1"?"checked":"";?>> <label for="option52">娱乐</label>
			<input type="radio" id="option53" name="choose1" value="2" <?=$content["choose1"]=="2"?"checked":"";?>> <label for="option53">生活</label>
			<input type="radio" id="option54" name="choose1" value="3" <?=$content["choose1"]=="3"?"checked":"";?>> <label for="option54">其他</label>
			<span class="help" onclick="show_help(1201)"></span>	
		</td>
	</tr>
	<tr>
		<td align="right">缺省内容（图片）级别：</td>
		<td>
			<input type="radio" id="option61" name="choose2" value="0" <?=$content["choose2"]=="0"?"checked":"";?>> <label for="option61">普通级别</label>
			<input type="radio" id="option62" name="choose2" value="1" <?=$content["choose2"]=="1"?"checked":"";?>> <label for="option62">火爆级别</label>
			<input type="radio" id="option63" name="choose2" value="2" <?=$content["choose2"]=="2"?"checked":"";?>> <label for="option63">限制级别</label>
			<span class="help" onclick="show_help(1202)"></span>		
		</td>
	</tr>
	<tr>
		<td align="right">方案名称：</td>
		<td><input type="text" name="name" value="<?=$content["name"]?>"></td>
	</tr>
	<tr align="left">
		<td>
			<input type="hidden" name="check" value="ok">
		</td>
		<td>
			<button type="submit">保存</button>
			&nbsp;
			<button type="button" onclick="location.reload()">还原</button>
		</td>
	</tr>
</table>
</form>

<div id="toolbar">
	<button class="b1" onclick="go('')">返回方案列表</button>
</div>

<script language="javascript">
function validate(obj)
{
	flag=true;
	if(obj.name.value.length<1)
	{
		flag=false;
		show_tip("请输入方案名称");
	}	
	return flag;
}

function show_style(id)
{
	if(id<=0 || id>=40)
	{
		id=11;
	}
	if(id<=20)
	{
		arr=new Array("block","none","none");
	}
	else{
		if(id<=30)
		{
			arr=new Array("none","block","none");
		}
		else{
			arr=new Array("none","none","block");
		}
	}
	document.all.style_a.style.display=arr[0];
	document.all.style_b.style.display=arr[1];
	document.all.style_c.style.display=arr[2];
	obj=eval("document.all.option"+id);
	obj.click();
	return true;
}
show_style(<?=floor($content["style"]);?>);
</script>