<?php
session_start();
include("connect.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" href="bootstrap/css/base.css">
<link rel="stylesheet" href="bootstrap/css/skeleton.css">
<link rel="stylesheet" href="bootstrap/css/layout.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="bootstrap/js/jquery-1.6.1.min.js" type="text/javascript"></script>
<link type"text/css" rel="Stylesheet" href="bootstrap/css/bootstrap.css" />
<meta charset="UTF-8">
<link rel="stylesheet" href="bootstrap/css/prettyPhoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" />
<script src="bootstrap/js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
				$(document).ready(function(){
					$("area[rel^='prettyPhoto']").prettyPhoto();
					
					$("a[rel^='prettyPhoto']").prettyPhoto({ animation_speed:'normal',theme:'light_square',slideshow:3000, autoplay_slideshow: true });
					$("a[rel^='prettyPhoto']").prettyPhoto({ animation_speed:'fast',slideshow:3000, hideflash: true });
			
				});
				$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto({
social_tools:false,
});
});
			</script>
<title>AFM ASS</title>
		<style type="text/css" media="screen">

			ul li { display: inline; }

		</style>
</head>

<body>
<?php
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
	$strSQL = "UPDATE gallery SET Galleryname = '".$_POST["txtEditCustomerID"]."'
				WHERE GalleryID = '".$_POST["hdnEditGalleryID"]."' ";
	$objQuery = mysql_query($strSQL);
	if($_FILES["filUpload"]["name"] != "")
	{
		if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
		{

			//*** Delete Old File ***//			
			@unlink("myfile/".$_POST["hdnOldFile"]);
			
			//*** Update New File ***//
			$strSQL = "UPDATE gallery SET GalleryShot = '".$_FILES["filUpload"]["name"]."' 
			WHERE GalleryID = '".$_POST["hdnEditGalleryID"]."' ";
			$objQuery = mysql_query($strSQL);		

			echo "Copy/Upload Complete<br>";

		}
	}
}
?>
<form name="frmMain" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>?img_id=<?php echo $_GET['img_id'] ; ?>" role="form" enctype="multipart/form-data">
<input type="hidden" name="hdnCmd" value="">
	<div class="row clearfix">
		<div class="col-md-12 column">
		</div>
	</div>
    	<div class="row clearfix">
		<div class="col-md-12 column">
		</div>
	</div>
    	<div class="row clearfix">
		<div class="col-md-12 column">
		</div>
	</div>
<div class="container">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<div class="page-header">
				<h1>
					AFM Asset Management <small>ระบบการจัดการสินทรัพย์บริษัท เอ เอฟ เอ็ม จำกัด</small>
				</h1>
			</div>
			<?php include("navbartop.php"); ?>
<?php

	$_SESSION['imgid'] = $_GET["img_id"];
	$strSQL = "SELECT * FROM gallery where Gadget_id = '".$_GET["img_id"]."' ";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table class="table">
<tr>
<th> <div align="center">ID </div></th>
<th> <div align="center">รูปภาพ</div></th>
<th> <div align="center">ชื่อภาพ</div></th>
<th> <div align="center">แก้ไขภาพ</div></th>
<th> <div align="center">ลบภาพ</div></th>
</tr>
<?php
	while($objResult = mysql_fetch_array($objQuery))
	{
?>
 <?php
 	  $GalleryID = (isset($_GET["GalleryID"])) ? $_GET["GalleryID"] : '';
	  $Action = (isset($_GET["Action"])) ? $_GET["Action"] : '';
	if($objResult["GalleryID"] == $GalleryID and $Action == "Edit")
	{
	
	//ส่วนของเมนู เมื่อ กด Edit 
  ?>
                <tr>
                <td><div align="center"><?php echo $objResult["GalleryID"];?></div>
                <input type="hidden" name="hdnEditGalleryID" size="5" value="<?php echo $objResult["GalleryID"];?>">
                </td>
                
                <td><center>
                    <a href="myfile/<?php echo $objResult["GalleryShot"];?>" target="_blank">
                    <img src="myfile/<?php echo $objResult["GalleryShot"];?>" width="100" height="100"></a>
                    <input type="file" name="filUpload" class="form-control">
                    </center></td>
                
                <td><center>
                    <input type="text" name="txtEditCustomerID" size="5" value="<?php echo $objResult["Galleryname"];?>">
                    <input type="hidden" name="hdnOldFile" value="<?php echo $objResult["GalleryShot"];?>">
                    </center></td>
                
                <td><center>

                
                 <td colspan="2" align="right"><div align="center">
          <input name="btnUpdate" type="button" class="btn btn-primary" id="btnUpdate" onClick="frmMain.hdnCmd.value='Update';frmMain.submit();" value="อัพเดตข้อมูล" />
          <input name="btnCancel" type="button" class="btn btn-warning" id="btnCancel" onClick="window.location='<?php echo $_SERVER['PHP_SELF'];?>?img_id=<?php echo $_GET['img_id'] ; ?>';" value="ยกเลิก" />
        </div></td>
                
                
                
                

                
                
                
                
                
                
                
                
                
                
                </tr>
  <?php
	}
  else
	{
  ?>
                <tr>
                <td><div align="center"><?php echo $objResult["GalleryID"];?></div></td>
                
                <td><center><a href="myfile/<?php echo $objResult["GalleryShot"];?>" target="_blank"><img src="myfile/<?php echo $objResult["GalleryShot"];?>" width="100" height="100"></a></center></td>
                
                <td><center><?php 
                    $noname = 'ยังไม่มีชื่อภาพ' ;
                    if($objResult["Galleryname"]== ""){
                    echo $noname ;}else{ echo $objResult["Galleryname"];}
                    ;?></center></td>
                
               <td align="center"><button class="btn btn-link">
                <a href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Edit&GalleryID=<?php echo $objResult["GalleryID"];?>&img_id=<?php echo $_GET["img_id"];?>">แก้ไข</a></button></td>
                
              <td align="center"><button class="btn btn-link">
              <a href="delimg.php?GalleryID=<?php echo $objResult["GalleryID"];?>?imgid=<?php echo $_GET["img_id"];?>">ลบภาพ</a></button></td>
                </tr>
<?php
	}
?>
<?php
}
?>
</table>
<div align="center" class="form-group">
<a href="viewgadget.php?view_id=<?php echo $_GET["img_id"];?>">
<button class="btn btn-warning" type="button">ย้อนกลับ</button></a>
</div>
</form>
<?php
mysql_close($objConnect);
?>
<script src="js/jquery.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
</body>
</html>

