<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?
    //添加
	$status=$_POST['status'];
	if($status=="add")
	{
		$indate=date('Y-n-j H:i:s');
		$booklet_type=$_POST['booklet_type'];//链接类型
		$booklet_name=$_POST['booklet_name'];//链接标题
		$link_url=$_POST['link_url'];//链接地址
		$picture=$_POST['picture'];//图片
		$is_verify=$_POST['is_verify'];//审核
		//sortid
		$sql="select max(sortid) as sortid from  ".$TableBbs_link;
		$rowsortid=$db->getRow($sql);
		$sortid=(int)$rowsortid['sortid']+1;
		//
	   	$file_name = $_FILES["file"]['name'];
		$picture=substr($file_name,strrpos($file_name,'.'),strlen($file_name)-strrpos($file_name,'.'));
	   	if(!empty($picture))
			$picture=getRandomNum().$picture;
		
		 $sql="insert into  ".$TableBbs_link."(is_verify,booklet_type,booklet_name,link_url,picture,sortid)values($is_verify,".$booklet_type.",'".$booklet_name."','".$link_url."','".$picture."','".$sortid."')";
		 $query=$db->query($sql);
		if(!empty($file_name))
	    {
			
			if($query)
			{
				$sql="select max(id) as id from  ".$TableBbs_link;
				$row=$db->getRow($sql);
				$FileName=$UploadPath."upload/bbs_link/".$picture;
				$file = $_FILES['file']['tmp_name'];
			   if(copy($file,$FileName))
			   {
				  unlink($file);
			   }
			}
		}
		if($query) $message=1;
		
	}
?>
<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="add";
		 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 align="center"  class='tr2' >
               					 <td colspan="2">
                  					<font  class="message">
                                                               <?
                                                                    if($message=="1")
                                                                    {
                                                                        echo "添加成功";
                                                                    }
                                                               ?>
                                                          </font>                				         </td>
              				</tr>
								
								<tr  class='tr2' >
									<td >链接标题:</td>
									<td ><input name="booklet_name" type="text" id="booklet_name" ></td>
								</tr>
								<tr  class='tr2' >
									<td >链接地址:</td>
									<td ><input name="link_url" type="text" id="link_url" value="http://" ></td>
								</tr>
								<tr  class='tr2' >
									<td >审核:</td>
									<td >									
									<?
										for($i=1;$i<=count($T_Is_YesNO);$i++)
										{
											if((int)$is_verify==$i||(empty($is_verify)&&$i==1))
												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)$booklet_type==$i||(empty($booklet_type)&&$i==1))
												echo "<input onClick='Ads_change(".$i.")' name='booklet_type' type='radio' checked  value=".$i.">".$T_Booklet_type[$i];
											else
												echo "<input onClick='Ads_change(".$i.")' name='booklet_type' 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' style="display:none;" id='tr_picture' >
									<td >图片:</td>
									<td ><input type="file" name="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="">
</form>
</body>
</html>
<? $db->close_db();?>
 

