<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php
$wwwpath="/www2/skybni"; 
$picpath= "/user_img/"; 
$write='';
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
    $aeimg=$_POST['aeimg'];
    $aeimgext=$_POST['aeimgext'];
	$tfile="fileToUpload1";
 	 if($_FILES[$tfile]["name"]<>''){
	   $imgext='';  
	   $ext= explode('.',$_FILES[$tfile]['name']) ;
	   $aeimgext=strtolower($ext[count($ext)-1]); //取最後一筆
	   
	   $pic=$wwwpath.$picpath.$aeimg.".".$aeimgext;
       move_uploaded_file($_FILES[$tfile]["tmp_name"],$pic);
	 }
  
  $updateSQL = sprintf("update big5link set aedoc='%s',aelink='%s',aeimg='%s',aeimgext='%s',linktag='%s' WHERE ae1='%s'",$_POST['aedoc'],$_POST['aelink'],$aeimg,$aeimgext,$_POST['linktag'],$_POST['ae1']);//$_POST['ae1']
  mysql_select_db($database_BE2, $BE2);
  $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());  
  $write='資料已更新...';
  
  
 $insertGoTo = $_POST['url'];
 // header(sprintf("Location: %s", $insertGoTo)); 
 echo  "<script>alert('".$write."');location.href='".$_POST['url']."';</script>";
  }
 

$bid=-1;
if(isset($_GET['id'])){
	$bid=$_GET['id'];
	}  

mysql_select_db($database_BE2, $BE2);
//$query_Rt2 = sprintf("SELECT a.*,b.* FROM ap1 as a ,adpic as b WHERE a.raid=b.bid AND b.id='%s'",$bid);
$query_Rt2 = sprintf("SELECT * FROM big5link where ae1='%s'",$bid);
 
$Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);
$totalRows_Rt2 = mysql_num_rows($Rt2);
 // if($myadmin){ echo $query_Rt2; } 

 



?>




<form id="form1" name="form1" method="POST" enctype="multipart/form-data" action="">
<table border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th nowrap="nowrap" class="font2" >&nbsp;</th>
    <th colspan="5" nowrap="nowrap" class="font2" ><?= $row_Rt2['aedoc']?></th>
    </tr>
  <tr>
    <th nowrap="nowrap" class="font2" >&nbsp;</th>
    <th nowrap="nowrap" class="font2" >圖片說明</th>
    <th nowrap="nowrap" class="font2" >&nbsp;</th>
    <th nowrap="nowrap" class="font2" >啟用</th>
    <th nowrap="nowrap" class="font2" >&nbsp;</th>
    <th nowrap="nowrap" class="font2" >&nbsp;</th>
    </tr>
 
    <tr >
      <td>&nbsp;</td>
      <td>
     <? $aeimg=($row_Rt2['aeimg']=="")?date("YmdHis").sprintf("%04d",rand(1,9999)):$row_Rt2['aeimg']; ?>
      <input name="mid" type="hidden" id="mid" value="<?= $row_Rt2['mid'];?>" />
      <input name="aeimg" type="hidden" id="aeimg" value="<?= $aeimg?>" />
      <input name="aeimgext" type="hidden" id="aeimgext" value="<?= $row_Rt2['aeimgext']?>" />
        </td>
      <td></td>
      <td><label for="select"></label>
            <select name="mflag" id="mflag">
              <option value="Y" <?php if (!(strcmp("Y", $row_Rt2['mflag']))) {echo "selected=\"selected\"";} ?>>Y</option>
              <option value="_self" <?php if (!(strcmp("_self", $row_Rt2['linktag']))) {echo "selected=\"selected\"";} ?>>N</option>
            </select></td>
      <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <th align="right">說明</th>
      <td><textarea name="mdoc" cols="40" rows="4" id="mdoc"><? echo $row_Rt2['mdoc'];?></textarea></td>
      <td>&nbsp;</td>
      <td colspan="2">
      <? 
	   $pic=$wwwpath.$picpath.$aeimg.".".$row_Rt2['aeimgext'];
	   $img=(file_exists($pic))?$picpath.$aeimg.".".$row_Rt2['aeimgext']:""; ?>
      <img src="<?= $img;?>" alt="" id="webpicid"/></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2"><input name="fileToUpload1" type="file" id="fileToUpload1" />
        () </td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="2">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td colspan="2">PS:picture = 150 X 150</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="送出" /></td>
    <td>&nbsp;</td>
    </tr>
</table> 

<input name="MM_update" type="hidden" id="MM_update" value="form1">
 
<input name="url" type="hidden" id="url" value="<? echo $_SERVER['HTTP_REFERER']; ?>" />
</form>
<?php
mysql_free_result($Rt2);
 
?>
