<?php session_start();
	if (!$_SESSION['nama']){
		echo "<script language=JavaScript>";
		echo "location.href = 'login.php';";
		echo "</script>";
	}
	include ("../koneksi.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
		<link href="style.css" rel="stylesheet" type="text/css">

		<title> WEBSITE BACKOFFICE </title>

		<script language="JavaScript" type="text/javascript" src="richtext.js"></script>
		<script language="JavaScript" type="text/javascript">
		<!--
		function submitForm() {
			//make sure hidden and iframe value are in sync before submitting form
			//to sync only 1 rte, use updateRTE(rte)
			//to sync all rtes, use updateRTEs
			updateRTE('deskripsi');
			updateRTE('deskripsi2');
			//updateRTEs();
			//alert("rte1 = " + document.RTEDemo.content.value);
			
			//change the following line to true to submit form
			return true;
		}
		
		//Usage: initRTE(imagesPath, includesPath, cssFile)
		initRTE("images/", "", "");
		//-->
		</script>				
	</head>	
	<body>
		<center>
			<table width="1000">
				<tr valign="top">
					<td width="162" class="bg">
						<?php include("kiri.php"); ?>
					</td>
					<td width="10"></td>
					<td width="783">
						<!-- Begin Kanan -->
						<?php include ("logo.php"); ?>
						<hr color="#EEEEEE" size="1">
						<table><tr height="9"><td></td></tr></table>
						<?php 
						$action = $_REQUEST["action"];
						if ($action=="add") {
							$id = $_REQUEST["id"];
							?>
							<table width="100%" cellpadding="5" cellspacing="0" border="0">
								<tr><td><strong>NEWS --> ADD NEWS</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>Date</td>
													<td>:</td>
													<td>
														<select name="tgl">
															<?php
															for($i=1; $i<=31; $i++) {
																?>
																<option value="<?php echo $i?>"><?php echo $i?></option>
																<?php
															}
															?>
														</select>
														<select name="bln">
															<?php
															for($i=1; $i<=12; $i++) {
																?>
																<option value="<?php echo $i?>"><?php echo $i?></option>
																<?php
															}
															?>
														</select>
														<select name="thn">
															<?php
															for($i=2015; $i<=2020; $i++) {
																?>
																<option value="<?php echo $i?>"><?php echo $i?></option>
																<?php
															}
															?>
														</select>														
													</td>
												</tr>												
												<tr>
													<td>Title</td>
													<td>:</td>
													<td><input type="text" name="title" size="75"></td>
												</tr>
												<tr valign="top">
													<td>Descriptions</td>
													<td>:</td>
													<td>
														<script language="JavaScript" type="text/javascript">
															<!--
																//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
																writeRichText('deskripsi', '<?php echo $deskripsi; ?>', 10, 200, true, false);
															//-->
														</script>															
													</td>
												</tr>
												<tr valign="top">
													<td>News Image</td>
													<td>:</td>
													<td><input type="file" name="gambar" size="15"></td>
												</tr>
												<tr valign="top">
													<td>Image Descriptions</td>
													<td>:</td>
													<td>
														<script language="JavaScript" type="text/javascript">
															<!--
																//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
																writeRichText('deskripsi2', '<?php echo $deskripsi2; ?>', 10, 80, true, false);
															//-->
														</script>															
													</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="add">
														<input type="hidden" name="id" value="<?php echo $id?>">
														<input type="hidden" name="module" value="news">														
													</td>
												</tr>
											</table>											
										</form>
									</td>
								</tr>
							</table>																													
							<?php
						} else if ($action=="edit") {
						} else if ($action=="delete") {
							$id2 = $_REQUEST["id2"];
							$query="select * from news where id = ".$id2;
							//echo $query;
							$hasil=mysql_query($query);												
							while($data=mysql_fetch_array($hasil)){	
								?>
								<table width="100%" cellpadding="5" cellspacing="0" border="0">
									<tr><td><strong>NEWS --> DELETE NEWS</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><?=$data["title"]?></td>
																</tr>
																<tr valign="top">
																	<td>Descriptions</td>
																	<td>:</td>
																	<td><?php echo $data["deskripsi"];?></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:location='?menu=5&id=<?=$id?>'">
																		<input type="hidden" name="action" value="delete">
																		<input type="hidden" name="module" value="news">
																		<input type="hidden" name="id" value="<?php echo $id;?>">
																		<input type="hidden" name="id2" value="<?php echo $data["id"];?>">
																		<input type="hidden" name="gambar" value="<?php echo $data["gambar"];?>">
																	</td>
																</tr>
															</table>
														</td>
													</tr>
												</table>											
											</form>
										</td>
									</tr>
								</table>								
								<?php
							}	
						} else {
							if ($id) {
								$query="select count(*) as jumlah from news where type='".$id."'";
								// echo $query;
								$total = mysql_fetch_array(mysql_query($query));
								$total = $total["jumlah"];
								//echo "<br> total: ".$total;
								if ($total>0) {
									?>
									<table width="100%" cellpadding="5" cellspacing="0" border="0">
										<tr><td><strong>LIST OF NEWS</strong></td></tr>
										<tr valign="top">
											<td>
												<div align="right"><a href="?menu=5&id=<?=$id?>&action=add"><strong>ADD News</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 width="61%"><strong>News title</strong></td>
														<td width="14%" align="center"><strong>Home page</strong></td>
														<td width="20%" align="center"><strong>Action</strong></td>
													</tr>										
													<?php 
													if ($koneksi){
														@ $nomor = 0;
														$query="select * from news where type='".$id."' order by id desc";
														$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 strip_tags(substr(stripslashes($data["title"]),0,55))."...";?></td>
																<td align="center">
																	<?php
																	if ($data["tampil"]==1) {
																		?><div style="color:#009966;">YES</div><?php
																	} else {
																		?><div style="color:#990000;">NO</div><?php
																	}
																	?>
																</td>
																<td align="center">
																	<a href="news.php?menu=5&id2=<?=$data["id"]?>">Edit</a>
																	&nbsp; | &nbsp; 
																	<a href="news.php?menu=5&id=<?=$id?>&id2=<?=$data["id"]?>&action=delete">Delete</a>
																</td>
															</tr>
															<?php
														}
													}	
													?>
												</table>
											</td>
										</tr>
									</table>				
									<?php
								} else {
									// no detil 
									$query2="select * from news where id='".$id."'";
									if ($hasil2=mysql_query($query2)) {
										while($data2=mysql_fetch_array($hasil2)){	
											$deskripsi=$data2["deskripsi"];
											$deskripsi = str_replace("'", "&acute;", $deskripsi);	
											$deskripsi = str_replace(chr(13), "", $deskripsi);
											$deskripsi = str_replace(chr(10), "", $deskripsi);								
											?>
											<table width="100%" cellpadding="5" cellspacing="0" border="0">
												<tr><td><strong>NEWS  --> EDIT DATA</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>Title</td>
																	<td>:</td>
																	<td><input type="text" name="title" size="50" value="<?=$data2["title"]?>"></td>
																</tr>
																<tr valign="top">
																	<td>Descriptions</td>
																	<td>:</td>
																	<td>
																		<script language="JavaScript" type="text/javascript">
																			<!--
																				//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
																				writeRichText('deskripsi', '<?php echo $deskripsi; ?>', 10, 300, true, false);
																			//-->
																		</script>															
																	</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="edit">
																		<input type="hidden" name="module" value="experiences">
																		<input type="hidden" name="id" value="<?=$data2["id"]?>">
																	</td>
																</tr>
															</table>											
														</form>
													</td>
												</tr>
											</table>																																					
											<?php
										}
									}
									// no detil
								}
							} else if ($id2) {
								// no detil 
								$query2="select * from content where id='".$id2."'";
								if ($hasil2=mysql_query($query2)) {
									while($data2=mysql_fetch_array($hasil2)){	
										$deskripsi=$data2["deskripsi"];
										$deskripsi = str_replace("'", "&acute;", $deskripsi);	
										$deskripsi = str_replace(chr(13), "", $deskripsi);
										$deskripsi = str_replace(chr(10), "", $deskripsi);								

										$deskripsi2=$data2["ket_gambar"];
										$deskripsi2 = str_replace("'", "&acute;", $deskripsi2);	
										$deskripsi2 = str_replace(chr(13), "", $deskripsi2);
										$deskripsi2 = str_replace(chr(10), "", $deskripsi2);			
										
										$tanggal = explode("-", $data2["tanggal"]);					
										
										?>
										<table width="100%" cellpadding="5" cellspacing="0" border="0">
											<tr><td><strong>NEWS --> EDIT NEWS</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="45%">Date</td>
																<td>:</td>
																<td>
																	<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=2013; $i<=2020; $i++) {
																			?>
																			<option <?php if($i == (int)$tanggal[0]) echo "selected";?> value="<?=$i?>"><?=$i?></option>
																			<?php
																		}
																		?>
																	</select>														
																</td>
															</tr>												
															<tr>
																<td>Source</td>
																<td>:</td>
																<td><input type="text" name="source" size="50" value="<?=$data2["source"]?>"></td>
															</tr>
															<tr>
																<td>Link</td>
																<td>:</td>
																<td><input type="text" name="link" size="50" value="<?=$data2["link"]?>"></td>
															</tr>
															<tr>
																<td>Title</td>
																<td>:</td>
																<td><input type="text" name="title" size="50" value="<?=$data2["title"]?>"></td>
															</tr>
															<tr valign="top">
																<td>Descriptions</td>
																<td>:</td>
																<td>
																	<script language="JavaScript" type="text/javascript">
																		<!--
																			//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
																			writeRichText('deskripsi', '<?php echo $deskripsi; ?>', 10, 200, true, false);
																		//-->
																	</script>															
																</td>
															</tr>
															<tr valign="top">
																<td>Image</td>
																<td>:</td>
																<td>
																	<img src="../images/news/<?=$data2["gambar"]?>" width="200" border="0"> <br>
																	<input type="file" name="gambar" size="15">
																</td>
															</tr>
															<tr valign="top">
																<td>Image Descriptions</td>
																<td>:</td>
																<td>
																	<script language="JavaScript" type="text/javascript">
																		<!--
																			//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
																			writeRichText('deskripsi2', '<?php echo $deskripsi2; ?>', 10, 80, true, false);
																		//-->
																	</script>															
																</td>
															</tr>
															<tr>
																<td>Show on Home</td>
																<td>:</td>
																<td>
																	<select name="tampil">
																		<option value="">-select-</option>
																		<option value="1" <?php if ($data2["tampil"]=="1") echo "selected"; ?>>YES</option>
																		<option value="0" <?php if ($data2["tampil"]=="0") echo "selected"; ?>>NO</option>
																	</select>
																</td>
															</tr>
															<tr>
																<td colspan="2"></td>
																<td>
																	<input type="submit" value="Submit">
																	<input type="button" value="Cancel" onclick="javascript:location='news.php?menu=5&id=<?=$data2["type"]?>'">
																	<input type="hidden" name="action" value="edit">
																	<input type="hidden" name="module" value="news">
																	<input type="hidden" name="id" value="<?=$data2["id"]?>">
																	<input type="hidden" name="type" value="<?=$data2["type"]?>">
																	<input type="hidden" name="old_gambar" value="<?=$data2["gambar"]?>">
																</td>
															</tr>
														</table>											
													</form>
												</td>
											</tr>
										</table>																																					
										<?php
									}
								}
								// no detil
							} else {
								?>
								<table width="100%" cellpadding="5" cellspacing="0" border="0">
									<tr><td><strong>NEWS</strong></td></tr>
									<tr valign="top">
										<td>
											<div align="right"><a href="?menu=2&id=<?php echo $id?>&action=add"><strong>ADD News</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 width="20%"><strong>Date</strong></td>
													<td width="60%"><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=2 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="news.php?menu=2&id2=<?php echo $data["id"]?>&action=edit">Edit</a>
																	&nbsp; | &nbsp; 
																	<a href="news.php?menu=2&id=<?php echo $data["id"]?>&action=delete">Delete</a>
																</td>
															</tr>
															<?php
														}
													}
												}	
												?>
											</table>
										</td>
									</tr>
								</table>				
								<?php
							}
						}
						?>
						<!-- Begin Kanan -->
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>	