<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?
	$status=$_POST['status'];
	$id=$_POST['id'];
	
	if($status=="removePic")
	{
		$sql=" select * from ".$TableBbs_link."  where id=".$id;
		$row=$db->getRow($sql);
		$FileName=$UploadPath."upload/bbs_link/".$row['picture'];
		if(file_exists($FileName)&&!empty($row['picture']))
		{
			unlink($FileName);
		}
		$sql="update  ".$TableBbs_link." set 	picture='' where id=".$id;
		$query=$db->query($sql);
	}
	
	if($status=="edit")
	{
			$indate=date('Y-n-j H:i:s');
		$id=$_POST['id'];//
		$booklet_type=$_POST['booklet_type'];//链接类型
		$booklet_name=$_POST['booklet_name'];//链接标题
		$link_url=$_POST['link_url'];//链接地址
		$picture=$_POST['picture'];//图片
		$is_verify=$_POST['is_verify'];//审核
		$file_name = $_FILES["file"]['name'];
		$picture=substr($file_name,strrpos($file_name,'.'),strlen($file_name)-strrpos($file_name,'.'));
		if(!empty($picture))
			$picture=getRandomNum().$picture;
			
		if(!empty($file_name))
		{
			//delete old
			$sql="select * from  ".$TableBbs_link."  where id=".$id;
		   $row=$db->getRow($sql);
		   $FileName=$UploadPath."upload/bbs_link/".$row['picture'];
			 if(file_exists($FileName)&&!empty($row['picture']))
			{
			   unlink($FileName);
			}
				
			$sql="update  ".$TableBbs_link." set is_verify=".$is_verify.",	booklet_type=".$booklet_type.",	booklet_name='".$booklet_name."',	link_url='".$link_url."',	picture='".$picture."' where id=".$id;
			$query=$db->query($sql);
			if($query)
			{
				$FileName=$UploadPath."upload/bbs_link/".$picture;
				$file = $_FILES['file']['tmp_name'];
				if(copy($file,$FileName))
				{
					unlink($file);
				}
			}
		}
		else
		{
			$sql="update  ".$TableBbs_link." set is_verify=".$is_verify.",	booklet_type=".$booklet_type.",	booklet_name='".$booklet_name."',	link_url='".$link_url."' where id=".$id;
			$query=$db->query($sql);
		}
		header("location: bbs_link.php");
			return;
	}
	$sql="select * from  ".$TableBbs_link."  where id=".$id;
	$row=$db->getRow($sql);
?>
<html>
<head>
<title><?=$TitleName?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../css/css.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../../js/check.js"></script>

</head>
<script language="javascript">
	function back()
	{
		location="bbs_link.php";
	}

	function Check()
	{
		var form=form1;
		if(form.booklet_name.value=="")
		{
			alert("请输入 链接标题!");
			form.booklet_name.focus();
			return;
		}
		if(form.link_url.value=="")
		{
			alert("请输入 链接地址!");
			form.link_url.focus();
			return;
		}
		
		 form.status.value="edit";
		 form.submit();
  	}
	function removePic()
  	{
  		var form=form1;
  		if(confirm("真的想要删除吗?")==false)
  			return;
  		form.status.value="removePic";
  		form.submit();
  	}
</script>
<body>
<form action=""  method="post"  name="form1"  enctype="multipart/form-data">
  <table class="firsttable">
      <tr>
    	<td align="center" valign="top">
        	    <table class="centertable">
          	<tr>
            		<td></td>
          	</tr>
          	<tr>
            		<td align="center" class="addborder">
					<table  class="addTable" border='0'  cellpadding='0'  cellspacing='1'>
								
								<tr  class='tr2' >
									<td >链接标题:</td>
									<td ><input name="booklet_name" type="text" id="booklet_name"  value="<?=$row['booklet_name']?>" ></td>
								</tr>
								<tr  class='tr2' >
									<td >链接地址:</td>
									<td ><input name="link_url" type="text" id="link_url"  value="<?=$row['link_url']?>" ></td>
								</tr>
								<tr  class='tr2' >
									<td >审核:</td>
									<td >									<?
										for($i=1;$i<=count($T_Is_YesNO);$i++)
										{
											if((int)$row['is_verify']==$i)
												echo "<input name='is_verify' type='radio' checked  value=".$i.">".$T_Is_YesNO[$i];
											else
												echo "<input name='is_verify' type='radio'   value=".$i.">".$T_Is_YesNO[$i];
										}
									?></td>
					  </tr>
                      <tr  class='tr2' >
									<td width="156" >链接类型:</td>
									<td width="632" >									<?
										for($i=1;$i<=count($T_Booklet_type);$i++)
										{
											if((int)$row['booklet_type']==$i)
												echo "<input name='booklet_type'  onClick='Ads_change(".$i.")' type='radio' checked  value=".$i.">".$T_Booklet_type[$i];
											else
												echo "<input name='booklet_type' onClick='Ads_change(".$i.")'  type='radio'   value=".$i.">".$T_Booklet_type[$i];
										}
									?>									</td>
								</tr>
                                <script language="javascript">
									function Ads_change(flag)
									{
										if(flag==1)
										{
											document.getElementById('tr_picture').style.display="none";
										}
										if(flag==2)
										{
											document.getElementById('tr_picture').style.display="";
										}
									}
								</script>
								<tr  class='tr2'  id='tr_picture' <? if($row['booklet_type']==1) echo "style='display:none;';"; ?>>
									<td >图片:</td>
									<td ><?	
										if(!empty($row['picture']))	
										{
									?>
                                      <a target="_blank" href="../../upload/bbs_link/<?=$row['picture']?>"  ><img width="100" height="80"  src="../../upload/bbs_link/<?=$row['picture']?>" border="0" ></a>
                                      <input type="button" class='button' onClick="removePic()" value="删除">
                                      <?	
								 		 }
								  ?>
                                      <br>
                                    <input type="file" name="file"  id="file"></td>
								</tr>
              				<tr  class='tr2' >
                				        <td colspan="2" align="center">
							     <input type="button"  class='button' name="Button" value="提交" onClick="Check()">
							    &nbsp;&nbsp;&nbsp;&nbsp;
      						    <input type="button"  class='button' name="Submit2" value="返回" onClick="back()">						        </td>
              				</tr>
           			  </table>
			  </td>
          		</tr>
          		<tr>
            		  <td></td>
          		</tr>
       	           </table>
    	   </td>
     </tr>
</table>
<input type="hidden" name="status" value="">
<input type="hidden" name="id" value=<?=$id?>>
</form>
</body>
</html>
<? $db->close_db();?>
 

