﻿<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
 	
   $write='';
   $imgpath= '/www2/skybni/video_img/logo/';
   $tfile1="fileToUpload1";
   $vimg=date('ymdHis'); //250203170830
   //lbg_ext001 2001 lbg_ext002 2002 
   $imagename=$_POST['yimage']; 
 
   if($_FILES[$tfile1]["name"]<>''){
	  
		   $ext1= explode('.',$_FILES[$tfile1]['name']) ;
	       $imgext1=strtolower($ext1[count($ext1)-1]); //取最後一筆
		   $imgextarr=array('png','jpg','jpeg');
		   if( in_array($imgext1,$imgextarr)){
			 $imagename= $vimg.'.'.$imgext1; 
			 $pic1=$imgpath.$imagename;
		     move_uploaded_file($_FILES[$tfile1]["tmp_name"],$pic1);
		    } 
			
			
  } 
   	
   $updateSQL = sprintf("UPDATE youvideo SET ydoc=%s, ykid=%s, ylink=%s,yflag=%s,yindex=%s,yimage=%s where yid=%s",
                       GetSQLValueString($_POST['ydoc'], "text"),
					   GetSQLValueString($_POST['ykid'], "text"),
                       GetSQLValueString($_POST['ylink'], "text"),
					   GetSQLValueString($_POST['yflag'], "text"),
					   GetSQLValueString($_POST['yindex'], "int"),
					   GetSQLValueString($imagename, "text"), 
					   GetSQLValueString($_POST['yid'], "int"));

   mysql_select_db($database_BE2, $BE2);
   $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());
  

  $updateGoTo =$_POST['url']; 
  echo  "<script>alert('更新完成 ..');location.href='".$updateGoTo."';</script>"; 
  
//$_GET['id']=$_POST['lid'];
}
 
 
// $ykid=array("","旅遊網.景點影片","旅遊網.廣告影片","旅遊網.商業影片","購物網.廣告影片","購物網.商業影片","VIP會員網.廣告影片","VIP會員網.商業影片","VIP會員網.商業模式,VIP會員網.招商簡報,VIP會員網.商業簡報");
$colname_Rt2 = "-1";
if (isset($_GET['id'])) {
  $colname_Rt2 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}

mysql_select_db($database_BE2, $BE2);
$query_R1 = sprintf("SELECT * FROM youvideo where yid = '%s'", $colname_Rt2);
$R1 = mysql_query($query_R1, $BE2) or die(mysql_error());
$row_R1 = mysql_fetch_assoc($R1);
 
mysql_select_db($database_BE2, $BE2);
$query_R2 = "SELECT * FROM video_master where 1 order by vkid,vdoc";
$R2 = mysql_query($query_R2, $BE2) or die(mysql_error());
$row_R2 = mysql_fetch_assoc($R2);


?> 
<form action="" method="post" name="form1" id="form1" enctype="multipart/form-data">
 
  <table width="50%" align="center">
    <tr valign="baseline">
      <th height="38" colspan="3" align="center" valign="middle" nowrap="nowrap">&nbsp;</th>
    </tr>
    <tr valign="baseline">
      <th height="42" align="center" valign="middle" nowrap="nowrap"><span class="font2">分類：</span></th>
      <td valign="middle"><select name="ykid" id="ykid">
       <? do{
		   $vdoc=($row_R2['video']=='Y')?'-影片':'-圖檔';
		   ?>
       
        <option value="<?= $row_R2['vid'] ?>" <? if($row_R2['vid']==$row_R1['ykid']){ echo 'selected="selected"'; } ?> ><?= $row_R2['vkid'].$row_R2['vdoc'].$vdoc?></option>
       <? }while ($row_R2 = mysql_fetch_assoc($R2)); ?> 
      </select></td>
      <td width="13%" valign="baseline">&nbsp;</td>
    </tr>
    <tr valign="baseline">
      <th height="42" align="center" valign="middle" nowrap="nowrap"><span class="font2">說明</span>：</th>

      <td valign="middle"><input name="ydoc" type="text" id="ydoc" value="<?=$row_R1['ydoc'] ?>" size="32" /></td>
      <td width="13%" valign="baseline">&nbsp;</td>
    </tr>
    <tr valign="baseline">
      <th width="16%" height="38" align="center" valign="middle" nowrap="nowrap"><span class="font2">連結</span>:</th>
      <td width="71%" valign="middle"><input name="ylink" type="text" id="ylink" value="<?=$row_R1['ylink'] ?>" size="32" /></td>
      <td width="13%" valign="baseline">&nbsp;</td>
    </tr>
    <tr valign="baseline">
      <th height="42" align="center" valign="middle" nowrap="nowrap"><span class="font2">主圖：</span></th>
      <td valign="middle"><input name="fileToUpload1" type="file" id="fileToUpload1" />
        130 x 108px (非 youtube 影音 ) </td>
      <td valign="baseline">&nbsp;</td>
    </tr>
    <tr valign="baseline">
      <th height="31" align="center" valign="middle" nowrap="nowrap"><span class="font2">排序值：</span></th>
      <td valign="middle"><input name="yindex" type="text" id="yindex" value="<?=$row_R1['yindex'] ?>" size="32" /></td>
      <td valign="baseline">&nbsp;</td>
    </tr>
    <tr valign="baseline">
      <td height="30" align="center" valign="middle" nowrap="nowrap"><span class="font2">啟用：</span></td>
      <td height="30" align="left" valign="middle" nowrap="nowrap"><label for="select"></label>
        <select name="yflag" id="yflag">
          <option value="Y" <? if($row_R1['yflag']=='Y'){ echo 'selected="selected"'; } ?>>Y</option>
          <option value="N" <? if($row_R1['yflag']=='N'){ echo 'selected="selected"'; } ?>>N</option>
      </select></td>
      <td align="left" valign="middle" nowrap="nowrap">&nbsp;</td>
    </tr>
    <tr valign="baseline">
      <td height="34" colspan="3" align="center" valign="middle" nowrap="nowrap">連結如下例 :   https://www.youtube.com/watch?v=<font color="red">qN4PwY4jEsY</font></td>
    </tr>
    <tr valign="baseline">
      <td height="40" colspan="3" align="center" valign="middle" nowrap="nowrap"><input type="submit" value="更新" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" id="MM_update" value="form1" />
  <input type="hidden" name="yid" id="yid" value="<?=$row_R1['yid'] ?>" />
  <input name="url" type="hidden" id="url" value="<?= $_SERVER['HTTP_REFERER']; ?>" />
  <input type="hidden" name="yimage" id="yimage" value="<?=$row_R1['yimage'] ?>" />
</form>
 
<?
mysql_free_result($R1);
mysql_free_result($R2);

?> 