	<script type="text/javascript" src="../functions/cleanhtml.js"></script>

	<?php	
	$tipe = $_REQUEST["tipe"];
	if ($tipe == "Ads") {
		include ("ads.php");
	} else if ($tipe == "Direktori") {
		include ("direktori.php");
	} else {
		$regForm = $_REQUEST["regForm"];
		$idContent = $_REQUEST["id"];	
		if ($action=="add" || $action=="edit" || $action=="delete") {
			if ($regForm == "Submit Data") {
				$kategori = $menu;
				$subKategori = "0";			
				$title = $_POST["title"]; // htmlspecialchars(, ENT_QUOTES);
				//echo "<br><br> title :".$title;
				
				$curtitle = $_POST["curtitle"];
				$metatagDes = htmlspecialchars($_POST["metatagDes"], ENT_QUOTES);
				$tags = htmlspecialchars($_POST["tags"], ENT_QUOTES);
				$foreword = htmlspecialchars($_POST["foreword"], ENT_QUOTES);
				$description = clear_data4($_POST["description"]); 			
				$gambar1 = $_FILES['gambar1']['name'];
				$gambar1_text = htmlspecialchars($_POST["gambar1_text"], ENT_QUOTES);
				$old_gambar1 = $_POST["old_gambar1"];
				$author = $_POST["author"];
				$rekomendasi = $_POST["rekomendasi"];
					if (!$rekomendasi) $rekomendasi=0;
				$targetPage = $_POST["targetPage"];
	
				$img="";	
				if ($gambar1) {
					$segment = split ("[.]", $gambar1);
					$ext = $segment[count ($segment) - 1];
					$img = "venuemagz-" . date("YmdGis") . "." . $ext;
				}
	
				if ($action=="add") {
					$tanggal = date('Y-m-d H:i:s');		
					$tahun = date('Y');
					$bulan = date('n');		
					$query="insert into content values(null, '$kategori', '0', '$tanggal', '$title', '$metatagDes', '$author', '$foreword', '$description', '$tags', '$img', '$gambar1_text', '', '$rekomendasi', '1')";		
					// echo "<br>Query Add: ".$query."<br>";
					$hasil=mysql_query($query);
					if ($hasil) {
						$id_last = mysql_fetch_array(mysql_query("select idContent from content order by idContent desc limit 0,1"));
						// echo "<br>Last ID : ".$id_last[0]."<br>";
						// $targetPage = getUrl($nama_menu, $tahun, $title, $id_last[0]);
						
						if (!$idContent) {
							$idContent = $id_last[0];
						}
						include ("../functions/getUrl.php");			
						include ("../functions/createUrl.php");			
						
						// echo "<br> ID Content: ".$idContent."<br>";
						$update2 = "update content set targetPage = '".$targetPage."' where idContent='".$id_last[0]."'";
						mysql_query($update2);
						
						// echo "<br><br>targetPage : ".$targetPage;
						// echo "<br>Dir:".$targetDir;
					}
				} else if ($action=="edit") {				
					$tanggal = $_POST["tanggal"];		
					$tahun = $_POST["tahun"];
					$bulan = $_POST["bulan"];	
	
					include ("../functions/getUrl.php");
					
					//echo "<br><br>"."target Dir : " . $targetDir;
					//echo "<br><br>"."target page : " . $targetPage;
					
					$query="update content set kategori='$kategori' , subKategori='$subKategori' , tanggal='$tanggal' , title='$title' , metatagDes='$metatagDes' , author='$author' , foreword='$foreword' , description='$description' , tags='$tags' ";		
					if ($gambar1) $query .= " ,gambar1='$img' ";
					$query .= " ,gambar1_text='$gambar1_text' ,targetPage='$targetPage' ,rekomendasi = '$rekomendasi' ";
					$query .= " where idContent='$idContent' ";
					//echo "<br><br>".$query."<br>";
					
					if ($hasil=mysql_query($query)) {
						include ("../functions/createUrl.php");			
					}
					
					// echo "targetPage : ".$targetPage;
					// echo $query;
				} else if ($action=="delete") {				
					$tanggal = $_POST["tanggal"];		
					$tahun = $_POST["tahun"];
					$bulan = $_POST["bulan"];	

					$query = "delete from content where idContent = '$idContent' ";		
					//echo "Pages : ".$targetPage;
					if ($hasil=mysql_query($query)) {
						//echo "<br>".$query."<br>";
						//$ctr=1;
						include ("../functions/getUrl.php");
						include ("../functions/deleteFiles.php");
						//echo $targetDir;
						Delete($targetDir);
					}
					
				}	
					
				if ($gambar1) {
					$uploaddir = $fileDir."/images/";
					chmod($uploaddir , 0755);
					if (move_uploaded_file($_FILES['gambar1']['tmp_name'], $uploaddir.$gambar1)){										
						if (rename ($uploaddir.$gambar1, $uploaddir.$img)) {
							if ($old_gambar1) {
								unlink ($uploaddir.$old_gambar1);
							}
						}
					}
				}
				
				$alamat  = '<script language=JavaScript>';
				$alamat .= ' location.href = "?menu='.$menu.'&tipe='.$tipe;
				$alamat .= ' "; ';
				$alamat .= '</script>';
				echo $alamat;
			} 
			else {
				if ($action=="edit" || $action=="delete") {
					$sql = "select *, year(tanggal) as tahun, month(tanggal) as bulan from content where idContent='$idContent'";
					// echo $sql;
					if ($hasil = mysql_query($sql)) {
						while ($data = mysql_fetch_array($hasil)) {
							$kategori = $data["kategori"];
							$subKategori = $data["subKategori"];
							$tanggal = $data["tanggal"];
							$tahun = $data["tahun"];
							$bulan = $data["bulan"];
							$title = htmlentities($data["title"]);
							$metatagDes = clear_data($data["metatagDes"]);
							$curtitle = $data["title"];
							
							$author = $data["author"];
							$foreword = $data["foreword"];
							$description = clear_data($data["description"]);
							
							$tags = $data["tags"];
							$gambar1 = $data["gambar1"];
							$gambar1_text = $data["gambar1_text"];
							$targetPage = $data["targetPage"];
							$rekomendasi = $data["rekomendasi"];
							// include ("../functions/getUrl.php");			
						}
					}
				}			
				// echo "<br>Sql : ".$title."<br>";
				if ($action=="edit" || $action=="add") {
					?>
					<table width="100%" cellpadding="5" cellspacing="0" border="0">
						<tr><td><strong><?php echo strtoupper($nama_menu); ?> >> <?php echo strtoupper($action)." ".strtoupper($nama_menu); ?></strong></td></tr>
						<tr valign="top">
							<td>									
								<form method="post" action="<?php echo '?menu='.$menu.'&action='.$action;?>" enctype="multipart/form-data" name="form1" onSubmit="submitForm(); cleanHTML();">
									<table cellpadding="7" cellspacing="0" border="0" bgcolor="#999999">
										<tr bgcolor="#f6f6f6">
											<td width="150" align="right"><strong>Title</strong></td> 
											<td><input type="text" name="title" value="<?php echo $title;?>" size="76"></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>								
										<tr valign="top" bgcolor="#f6f6f6">
											<td align="right"><strong>Metatag Description</strong></td>
											<td><textarea cols="57" rows="5" name="metatagDes"><?php echo $metatagDes; ?></textarea></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Tags</strong></td>
											<td><input type="text" name="tags" value="<?php echo $tags; ?>" size="76"></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Foreword</strong>s</td>
											<td><textarea cols="57" rows="5" name="foreword"><?php echo $foreword; ?></textarea></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6"> 
											<td align="right"><strong>Description</strong>s</td>
											<td>
												<script language="JavaScript" type="text/javascript">
													<!--
														//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
														writeRichText('description', '<?php echo $description; ?>', 10, 200, true, false);
													//-->
												</script>															
											</td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Image</strong></td>
											<td>
												<?php
												if ($gambar1) {
													echo '<img width="350" src="'.$targetPage.'images/'.$gambar1.'" border="0">';
												}
												?>									
												<input type="file" name="gambar1" size="76">
											</td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Image Descriptions</strong></td>
											<td><textarea cols="57" rows="3" name="gambar1_text"><?php echo $gambar1_text; ?></textarea></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Author</strong></td>
											<td><input type="text" name="author" value="<?php echo $author; ?>" size="75"></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Show on</strong></td>
											<td>
												<?php							
												$opsi = "";
												$ctr = 0;
												$query4="select * from rekomendasi";
												if ($hasil4 = mysql_query($query4)) {
													while ($data4=mysql_fetch_array($hasil4)) {
														if ($ctr == 0) {
															$opsi .= '<select name="rekomendasi" id="rekomendasi">';
															$opsi .= '	<option value="0"> Select Option </option>';
														}
														$opsi .= '<option value="'.$data4["id"].'" ';
														if ($rekomendasi == $data4["id"])
															$opsi .= ' selected ';
														$opsi .= '>'.ucwords($data4["rekomendasi"]);
														$opsi .= '</option>';
														$ctr++;
													}
													if ($ctr > 0) {
														$opsi .= '</select>';
														echo $opsi;
													}
												}
												?>
											</td>
										</tr>
										<tr bgcolor="#ffffff">
											<td align="center" colspan="2">
												<div id="spasi1"></div>
												<input type="submit" name="regForm" value="Submit Data">
												<input type="hidden" name="old_gambar1" value="<?php echo $gambar1; ?>">
												<input type="hidden" name="tanggal" value="<?php echo $tanggal; ?>">
												<input type="hidden" name="tahun" value="<?php echo $tahun; ?>">
												<input type="hidden" name="bulan" value="<?php echo $bulan; ?>">
												<input type="hidden" name="id" value="<?php echo $idContent; ?>">
												<input type="hidden" name="curtitle" value="<?php echo $curtitle; ?>">
												<input type="hidden" name="targetPage" value="<?php echo $targetPage; ?>">
												<input type="hidden" name="tipe" value="<?php echo $tipe; ?>">
												<div id="spasi1"></div>
											</td>
										</tr>
									</table>											
								</form>
							</td>
						</tr>
					</table>																													
					<?php
				} else if ($action=="delete") {
					?>
					<table cellpadding="5" cellspacing="0" border="0">
						<tr><td><strong><?php echo strtoupper($nama_menu); ?> >> <?php echo strtoupper($action)." ".strtoupper($nama_menu); ?></strong></td></tr>
						<tr valign="top">
							<td>									
								<div align="center"><strong>Hapus Data Dibawah Ini ?</strong></div>
								<form method="post" action="<?php echo '?menu='.$menu.'&action='.$action;?>" enctype="multipart/form-data" name="form1" onSubmit="submitForm(); cleanHTML();">
									<table cellpadding="3" cellspacing="1" border="0" bgcolor="#CCC">
										<tr bgcolor="#FFFFFF">
											<td>
												<table cellpadding="7" cellspacing="0" border="0" bgcolor="#999999">
													<tr bgcolor="#f6f6f6">
														<td width="150" align="right"><strong>Title</strong></td> 
														<td><?php echo $title;?></td>
													</tr>
													<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
													<tr bgcolor="#f6f6f6">
														<td align="right"><strong>Image</strong></td>
														<td>
															<?php
															if ($gambar1) {
																echo '<img width="350" src="'.$targetPage.'images/'.$gambar1.'" border="0">';
															}
															?>									
														</td>
													</tr>
													<tr bgcolor="#ffffff">
														<td align="center" colspan="2">
															<div id="spasi1"></div>
															<input type="submit" name="regForm" value="Submit Data">
															<input type="hidden" name="id" value="<?php echo $idContent; ?>">
															<input type="hidden" name="targetPage" value="<?php echo $targetPage; ?>">
															<input type="hidden" name="tipe" value="<?php echo $tipe; ?>">
															
															<input type="hidden" name="tanggal" value="<?php echo $tanggal; ?>">
															<input type="hidden" name="tahun" value="<?php echo $tahun; ?>">
															<input type="hidden" name="bulan" value="<?php echo $bulan; ?>">
															<input type="hidden" name="title" value="<?php echo $title; ?>">
															<div id="spasi1"></div>
														</td>
													</tr>
												</table>											
											</td>
										</tr>
									</table>
								</form>
							</td>
						</tr>
					</table>																													
					<?php
				}
			}
		} 
		else {
			?>
			<table width="100%" cellpadding="5" cellspacing="0" border="0">
				<tr><td><strong>MENU SELECTED >> <?php echo strtoupper($nama_menu); ?></strong></td></tr>
				<tr valign="top">
					<td>
						<table width="100%" cellpadding="6" cellspacing="0" border="0">
							<tr>
								<td>
									<?php 
									include ("search-box.php"); 
									echo $kotak_cari;
									?>
								</td>
								<td>
									<div align="right">
										<div id="box" style="width:107px;" onClick="location='?menu=<?php echo $menu; ?>&tipe=<?php echo $tipe;?>&action=add'">
											<strong>Add New Data</strong>
										</div>
									</div>
								</td>
							</tr>
						</table>
						<table width="100%" cellpadding="6" cellspacing="1" bgcolor="#CCCCCC">
							<tr bgcolor="#EEEEEE">
								<td width="5%" align="center"><strong>ID</strong></td>
								<td width="24%"><strong>Date</strong></td>
								<td width="56%"><strong>Title</strong></td>
								<td width="15%" align="center"><strong>Action</strong></td>
							</tr>										
							<?php 
							if ($koneksi){
								$nomor = 0;
								$query  = "select * from content where kategori='$menu'  ";
								if ($txt_cari) $query .= "and title like '%$txt_cari%' ";
								$query .= "order by tanggal desc ";
							
								
								if ($hasil=mysql_query($query)) {
									while($data=mysql_fetch_array($hasil)){													
										$nomor=$nomor+1;
										?>
										<tr bgcolor="#FFFFFF">
											<td align="center"><?php echo $nomor; ?> </td>
											<td><?php echo date("l, F  d,  Y", strtotime($data["tanggal"])); ?></td>
											<td><?php echo $data["title"]; ?></td>
											<td align="center">
												<a href="<?php echo "?menu=".$menu."&id=".$data["idContent"]."&action=edit&tipe=".$tipe; ?>">Edit</a>
												&nbsp; | &nbsp; 
												<a href="<?php echo "?menu=".$menu."&id=".$data["idContent"]."&action=delete&tipe=".$tipe; ?>">Delete</a>
											</td>
										</tr>
										<?php
									}
								}
							}	
							?>
						</table>
					</td>
				</tr>
			</table>				
			<?php	
		}
	}
	?>