<?php
	include ("../koneksi.php");
	$slctahun = $_REQUEST["slctahun"];
?>
<!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>
						<!-- End Kanan -->
						<?php
						@ $action = $_REQUEST["action"];
						@ $id = $_REQUEST["id"];
						$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"];
								$title = $data["title"];
								$tempat = $data["tempat"]; 
								$tahun = $data["tahun"]; 
							}
						}

						if ($action=="ADD" || $action=="EDIT") {
							?>
							<table width="100%" cellpadding="5" cellspacing="0" border="0">
								<tr><td><strong>GALLERY ARCHIVES --> <?=$action?> GALLERY ARCHIVES</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>
													<td width="11%">Tahun</td>
													<td width="2%">:</td>
													<td>
														<?php 
														$tanggal = explode("-", $tanggal);						
														?>
														<select name="tgl">
															<?php																
															for($i=1; $i<=31; $i++) {
																?>
																<option <?php if($i == (int)$tanggal[2]) echo "selected";?> value="<?=$i?>"><?=$i?></option>
																<?php
															}
															?>
														</select>
														<select name="bln">
															<?php
															for($i=1; $i<=12; $i++) {
																?>
																<option <?php if($i == (int)$tanggal[1]) echo "selected";?> value="<?=$i?>"><?=$i?></option>
																<?php
															}
															?>
														</select>
														<select name="thn">
															<?php
															for($i=2006; $i<=2020; $i++) {
																?>
																<option <?php if($i == (int)$tanggal[0]) echo "selected";?> value="<?=$i?>"><?=$i?></option>
																<?php
															}
															?>
														</select>														
													</td>
												</tr>
												<tr valign="top">
													<td>Title</td>
													<td>:</td>
													<td><input type="text" name="title" size="55" value="<?=$title;?>"></td>
												</tr>												
												<tr valign="top">
													<td>Tempat</td>
													<td>:</td>
													<td><input type="text" name="tempat" size="55" value="<?=$tempat;?>"></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="id" value="<?=$idgallery;?>">
														<input type="hidden" name="module" value="gallery">
													</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 cellpadding="3" cellspacing="1" bgcolor="#666666">
												<tr bgcolor="#FFFFFF">
													<td>
														<table cellpadding="6">
															<tr>
																<td>Title</td>
																<td>:</td>
																<td><?php echo $title;?></td>
															</tr>
															<tr valign="top">
																<td>Tempat</td>
																<td>:</td>
																<td><?php echo $tempat;?></td>
															</tr>
															<tr>
																<td colspan="2"></td>
																<td>
																	<input type="submit" value="&nbsp;&nbsp;Yes&nbsp;&nbsp;">
																	<input type="button" value="&nbsp;&nbsp; No &nbsp;&nbsp;" onclick="javascript:history.go(-1)">
																	<input type="hidden" name="action" value="<?=$action?>">
																	<input type="hidden" name="module" value="gallery">
																	<input type="hidden" name="id" value="<?php echo $idgallery;?>">																		
																	<input type="hidden" name="tahun" value="<?php echo $tahun;?>">																		
																</td>
															</tr>
														</table>
													</td>
												</tr>
											</table>											
										</form>
									</td>
								</tr>
							</table>																							
							<?php
						} else {
							?>
							<table width="100%" cellpadding="5" cellspacing="0" border="0">
								<tr><td><strong>GALLERY ARCHIVES --> LIST GALLERY ARCHIVES</strong></td></tr>
								<tr valign="top">
									<td>
										<form method="post" action="arc_gallery.php?menu=5" enctype="multipart/form-data" name="form1" onSubmit="return submitForm();">														
											<table width="100%" cellpadding="0" cellspacing="0" border="0">
												<tr height="2"><td></td></tr>
												<tr>
													<td width="15%"><strong>LIST BY YEAR</strong></td>
													<td width="35%">
														<table width="100%" cellpadding="0" cellspacing="0" border="0">
															<tr valign="top">
																<td width="30%">
																	<select name="slctahun">
																		<?php 
																		if ($koneksi){																			
																			@ $nomor = 0;
																			$query="select distinct year(tanggal) as tahun from gallery order by tanggal desc";
																			$hasil=mysql_query($query);												
																			while($data=mysql_fetch_array($hasil)){													
																				if (!$slctahun) $slctahun=$data["tahun"];
																				?>
																				<option <?php if($data["tahun"]==$slctahun) echo "selected"; ?> value="<?=$data["tahun"];?>"><?=$data["tahun"];?></option>
																				<?php
																			}
																		}	
																		?>														
																	</select>
																</td>
																<td><input type="submit" value="Submit"></td>
															</tr>
														</table>
													</td>
													<td>
														<div align="right"><a href="arc_gallery.php?menu=5&action=ADD"><strong>Add New Gallery(s)</strong></a></div>												
													</td>
												</tr>
												<tr height="10"><td></td></tr>
											</table>
										</form>		
										<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>Year</strong></td>
												<td width="70%"><strong>Gallery Name</strong></td>
												<td width="15%" align="center"><strong>Action</strong></td>
											</tr>										
											<?php 
											if ($koneksi){
												@ $nomor = 0;
												$query="select *, year(tanggal) as tahun from gallery where year(tanggal)=".$slctahun." order by idgallery 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"><?php echo $data["tahun"]; ?> </td>
															<td>
																<a href="arc_gallery_gambar.php?menu=5&id=<?=$data["idgallery"];?>" <?php if($data["id"]==$parentid) echo "id='active'"; ?>><?php echo $data["title"]; ?></a>
															</td>
															<td align="center">
																<a href="arc_gallery.php?menu=5&action=EDIT&id=<?=$data["idgallery"];?>">Edit</a>&nbsp;|&nbsp;
																<a href="arc_gallery.php?menu=5&action=DELETE&id=<?=$data["idgallery"];?>">Delete</a>
															</td>
														</tr>
														<?php
													}
												}
											}	
											?>
										</table>
									</td>
								</tr>
							</table>		
							<?php
						}
						?>
					</td>	
				</tr>
			</table>
		</center>
	</body>
</html>	