<?php
	include ("../koneksi.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>WEBSITE BACKOFFICE</title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<link href="style.css" rel="stylesheet" type="text/css">
	</head>	
	<body>
		<center>
			<table width="800">
				<tr valign="top">
					<td width="162" class="bg">
						<?php include("kiri.php"); ?>
					</td>
					<td>
						<!-- Begin Kanan -->
						<table width="166">
							<tr height="28"><td></td></tr>
							<tr>
								<td align="right">
									<img src="images/LOGO_PENTA_putih.jpg" border="0"><br>
									<font size="3"><strong>WEBSITE BACKOFFICE</strong></font>
								</td>
							</tr>
							<tr height="25"><td></td></tr>
						</table>
						<?php
						@ $action = $_REQUEST["action"];
						@ $id = $_REQUEST["id"];
						@ $idgambar = $_REQUEST["idgambar"];
						$idgallery = "";
						$tanggal = "";
						$title = "";
						$tempat = ""; 
						
						if ($id) {
							$query="select *, year(tanggal) as tahun from gallery where idgallery = ".$id;
							// echo  $query;
							$hasil=mysql_query($query);												
							while($data=mysql_fetch_array($hasil)){	
								$idgallery = $data["idgallery"];
								$tanggal = $data["tanggal"];
								$tahun = $data["tahun"];								
								$title = $data["title"];
								$tempat = $data["tempat"]; 
							}
						}
						
						if ($idgambar) {
							$query="select * from gallery_gambar where idgambar = ".$idgambar;
							// echo  $query;
							$hasil=mysql_query($query);												
							while($data=mysql_fetch_array($hasil)){	
								//$idgambar = $data["idgambar"];
								//$parent_id = $data["parent_id"];
								$gambar = $data["gambar"];
								$keterangan = $data["keterangan"];
							}
						}							

						if ($action=="ADD" || $action=="EDIT") {
							?>
							<table width="100%" cellpadding="5" cellspacing="0" border="0">
								<tr><td><strong>IMAGE GALLERY --> <?=$action?> IMAGE GALLERY</strong></td></tr>
								<tr valign="top">
									<td>									
										<form method="post" action="proses.php" enctype="multipart/form-data" name="form1" onSubmit="return submitForm();">
											<table width="100%" cellpadding="3">
												<tr valign="top">
													<td>Image</td>
													<td>:</td>
													<td>
														<?php 
														if($gambar) {
															?><img width="250" src="../images/gallery/<?=$tahun?>/<?=$gambar?>" border="0"> <br><?php
														}
														?>
														<input type="file" name="gambar" size="15">
													</td>
												</tr>
												<tr>
													<td>Description</td>
													<td>:</td>
													<td>
														<textarea name="keterangan" cols="60" rows="10"><?php echo $keterangan;?></textarea>
													</td>
												</tr>
												<tr>
													<td colspan="2"></td>
													<td>
														<input type="submit" value="Submit">
														<input type="button" value="Cancel" onclick="javascript:history.go(-1)">
														<input type="hidden" name="action" value="<?=$action?>">
														<input type="hidden" name="module" value="gall_gambar">														
														<input type="hidden" name="idgallery" value="<?php echo $idgallery; ?>">
														<input type="hidden" name="idgambar" value="<?php echo $idgambar; ?>">
														<input type="hidden" name="tahun" value="<?php echo $tahun; ?>">
														<input type="hidden" name="oldgambar" value="<?php echo $gambar; ?>">
													</td>
												</tr>
											</table>											
										</form>
									</td>
								</tr>
							</table>																																					
							<?php
						} else if ($action=="DELETE") {
							?>
							<table width="100%" cellpadding="5" cellspacing="0" border="0">
								<tr><td><strong>GALLERY ARCHIVES --> DELETE GALLERY ARCHIVES </strong></td></tr>
								<tr valign="top">
									<td>									
										<form method="post" action="proses.php" enctype="multipart/form-data" name="form1" onSubmit="return submitForm();">
											Are you sure you want to delete the following data
											<table width="250" cellpadding="3" cellspacing="1" border="0" bgcolor="#CCCCCC">
												<tr bgcolor="#FFFFFF">
													<td>
														<img width="250" src="../images/gallery/<?=$tahun?>/<?=$gambar?>" border="0">
														<div id="spasi1"><?php echo $keterangan;?></div>
													</td>
												</tr>
												<tr>
													<td>
														<input type="submit" value="Submit">
														<input type="button" value="Cancel" onclick="javascript:history.go(-1)">
														<input type="hidden" name="action" value="<?=$action?>">
														<input type="hidden" name="module" value="gall_gambar">														
														<input type="hidden" name="idgallery" value="<?php echo $idgallery; ?>">
														<input type="hidden" name="idgambar" value="<?php echo $idgambar; ?>">
														<input type="hidden" name="tahun" value="<?php echo $tahun; ?>">
														<input type="hidden" name="oldgambar" value="<?php echo $gambar; ?>">
													</td>
												</tr>
											</table>											
										</form>
									</td>
								</tr>
							</table>																							
							<?php
						} else {
							?>
							<table width="100%" cellpadding="5" cellspacing="0" border="0">
								<tr><td colspan="3"><strong>GALLERY GAMBAR --> LIST GALLERY GAMBAR</strong></td></tr>
								<tr bgcolor="#f2f2f2">
									<td width="15%">Date</td>
									<td width="1%" align="center">:</td>
									<td><?php echo date("F d, Y", strtotime($tanggal)) ?></td>
								</tr>
								<tr>
									<td>Gallery Title</td>
									<td align="center">:</td>
									<td><?=$title?></td>
								</tr>
								<tr bgcolor="#f2f2f2">
									<td>Gallery Venue</td>
									<td align="center">:</td>
									<td><?=$tempat?></td>
								</tr>
								<tr height="10"><td></td></tr>
								<tr><td colspan="3"><strong>LIST OF IMAGES For <?=$title?> </strong></td></tr>
								<tr>
									<td colspan="3">
										<div align="right"><a href="arc_gallery_gambar.php?menu=5&action=ADD&id=<?=$idgallery?>"><strong>Add New Image(s)</strong></a></div>
										<table width="100%" cellpadding="6" cellspacing="1" bgcolor="#CCCCCC">
											<tr bgcolor="#EEEEEE">
												<td width="5%" align="center"><strong>ID</strong></td>
												<td align="center" width="10%"><strong>Image</strong></td>
												<td width="70%"><strong>Description</strong></td>
												<td width="15%" align="center"><strong>Action</strong></td>
											</tr>										
											<?php 
											if ($koneksi){
												@ $nomor = 0;
												$query="select * from gallery_gambar where parent_id=".$idgallery." order by idgambar desc ";
												// echo $query;
												$hasil=mysql_query($query);												
												if ($hasil) {
													while($data=mysql_fetch_array($hasil)){													
														$nomor=$nomor+1;
														?>
														<tr bgcolor="#FFFFFF">
															<td align="center"><?php echo $nomor; ?> </td>
															<td align="center"><img width="100" src="../images/gallery/<?=$tahun?>/<?=$data["gambar"]?>" border="0"></td>
															<td><?php echo $data["keterangan"]; ?></td>
															<td align="center">
																<a href="arc_gallery_gambar.php?menu=5&action=EDIT&id=<?=$idgallery?>&idgambar=<?=$data["idgambar"]?>">Edit</a>&nbsp;|&nbsp;
																<a href="arc_gallery_gambar.php?menu=5&action=DELETE&id=<?=$idgallery?>&idgambar=<?=$data["idgambar"]?>">Delete</a>
															</td>
														</tr>
														<?php
													}
												}
											}	
											?>
										</table>
									
									</td>
								</tr>
							</table>		
							<?php
						}
						?>
						<!-- Begin Kanan -->
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>	