	<script type="text/javascript" src="../functions/cleanhtml.js"></script>
	
	<?php	
	if ($menu==19) {
		include("direktori-province.php");
	} else if ($menu==20) {
		include("direktori-cities.php");
	} else if ($menu==21) {
		include("direktori-category.php");
	} else {
		$tipe = $_REQUEST["tipe"];
		$regForm = $_REQUEST["regForm"];
		$idContent = $_REQUEST["id"];	
		if ($action=="add" || $action=="edit" || $action=="delete") {
			if ($regForm == "Submit Data") {
				$nama = $_POST["nama"];	
				$alamat = $_POST["alamat"];	
				$cities = $_POST["cities"];	
				$propinsi = $_POST["propinsi"];	
				$telpon = $_POST["telpon"];	
				$fax = $_POST["fax"];	
				$email1 = $_POST["email1"];	
				$email2 = $_POST["email2"];	
				$email3 = $_POST["email3"];	
				$website = $_POST["website"];	
				$pax = $_POST["pax"];
				if (!$pax) $pax='0';
				$fasilitas = $_POST["fasilitas"];

				$category = $_POST["category"];	
				if ($action=="add") {
					$query="insert into direktori_trans values(null, '$nama', '$alamat', '$cities', '$propinsi', '$telpon', '$fax', '$email1', '$email2', '$email3', '$website', '$pax', '$fasilitas')";		
					//echo "<br>Query Add: ".$query."<br>";
					$hasil=mysql_query($query);
					if ($hasil) {
						$id_last = mysql_fetch_array(mysql_query("select id from direktori_trans order by id 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];
						}
						foreach ($category as $arr) {
							$insert2 = "insert into direktori_link_category values(null, '$idContent', '$arr')";
							//echo $insert2."<br>";
							mysql_query($insert2);
						}
						
						// echo "<br><br>targetPage : ".$targetPage;
						// echo "<br>Dir:".$targetDir;
					}
				} else if ($action=="edit") {
					$update2 = "update direktori_trans set nama='$nama', alamat='$alamat', cities='$cities', propinsi='$propinsi', telpon='$telpon', fax='$fax', email1='$email1', email2='$email2', email3='$email3', website='$website', pax='$pax', fasilitas='$fasilitas' where id='$idContent' ";
					$hasil = mysql_query($update2);
					if ($hasil) {
						$delete2 = "delete from direktori_link_category where linkTrans='$idContent' ";
						mysql_query($delete2);
						foreach ($category as $arr) {
							$insert2 = "insert into direktori_link_category values(null, '$idContent', '$arr')";
							//echo $insert2."<br>";
							mysql_query($insert2);
						}
					}

				} else if ($action=="delete") {				
					$delete2 = "delete from direktori_trans where id='$idContent' ";
					$hasil = mysql_query($delete2);
					if ($hasil) {
						$delete2 = "delete from direktori_link_category where linkTrans='$idContent' ";
						mysql_query($delete2);
					}
				}	
				
				$alamat  = '<script language=JavaScript>';
				$alamat .= ' location.href = "?menu='.$menu.'&tipe='.$tipe."&propinsi=".$propinsi;
				$alamat .= ' "; ';
				$alamat .= '</script>';
				echo $alamat;
			} 
			else {
				if ($action!="add") {
					$sql = "select * from direktori_trans where id='$idContent' ";
					// echo $sql;
					if ($hasil = mysql_query($sql)) {
						while ($data = mysql_fetch_array($hasil)) {
							$idContent = $data["id"];
							$nama = $data["nama"];
							$alamat = $data["alamat"];
							$cities = $data["cities"];
							$propinsi = $data["propinsi"];
							$telpon = $data["telpon"];
							$fax = $data["fax"];
							$email1 = $data["email1"];
							$email2 = $data["email2"];
							$email3 = $data["email3"];
							$website = $data["website"];
							$pax = $data["pax"];
							$fasilitas = $data["fasilitas"];
							//echo "Nama : ".$nama;
						}
					}
				}			
				// echo "<br>Sql : ".$title."<br>";
				
				if ($action=="add" || $action=="edit") {
					?>
					<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="10" cellspacing="0" border="0" bgcolor="#999999">
										<tr bgcolor="#f6f6f6">
											<td width="150" align="right"><strong>Nama Perusahaan</strong></td> 
											<td><input type="text" name="nama" value="<?php echo $nama;?>" 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>Alamat</strong></td>
											<td><textarea cols="57" rows="5" name="alamat"><?php echo $alamat; ?></textarea></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr valign="top" bgcolor="#f6f6f6">
											<td align="right"><strong>16 Kota Destinasi MICE</strong></td>
											<td>
												<?php
												$opsi = "";
												$ctr = 0;
												$query4="select * from direktori_cities ";
												if ($hasil4 = mysql_query($query4)) {
													while ($data4=mysql_fetch_array($hasil4)) {
														if ($ctr == 0) {
															$opsi .= '<select name="cities" id="cities">';
															$opsi .= '	<option value="0"> Tidak Termasuk </option>';
														}
														$opsi .= '<option value="'.$data4["idCities"].'" ';
														if ($cities == $data4["idCities"])
															$opsi .= ' selected ';
														$opsi .= '>'.ucwords($data4["namaCities"]);
														$opsi .= '</option>';
														$ctr++;
													}
													if ($ctr > 0) {
														$opsi .= '</select>';
														echo $opsi;
													}
												}
												?>
											</td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr valign="top" bgcolor="#f6f6f6">
											<td align="right"><strong>Propinsi</strong></td>
											<td>
												<?php
												$opsi = "";
												$ctr = 0;
												$query4="select * from direktori_propinsi ";
												if ($hasil4 = mysql_query($query4)) {
													while ($data4=mysql_fetch_array($hasil4)) {
														if ($ctr == 0) {
															$opsi .= '<select name="propinsi" id="propinsi">';
															$opsi .= '	<option value="0"> Pilih Propinsi </option>';

															$overSelected = "";
															if ($propinsi == '99') $overSelected = " selected ";
															$opsi .= '	<option '.$overSelected.' value="99"> Overseas </option>';
														}
														$opsi .= '<option value="'.$data4["idPropinsi"].'" ';
														if ($propinsi == $data4["idPropinsi"])
															$opsi .= ' selected ';
														$opsi .= '>'.ucwords($data4["namaPropinsi"]);
														$opsi .= '</option>';
														$ctr++;
													}
													if ($ctr > 0) {
														$opsi .= '</select>';
														echo $opsi;
													}
												}
												?>
											</td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Nomor Telpon</strong></td>
											<td><input type="text" name="telpon" value="<?php echo $telpon; ?>" size="50"></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Nomor Fax</strong></td>
											<td><input type="text" name="fax" value="<?php echo $fax; ?>" size="50"></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Email 1</strong></td>
											<td><input type="text" name="email1" value="<?php echo $email1; ?>" size="75"></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Email 2</strong></td>
											<td><input type="text" name="email2" value="<?php echo $email2; ?>" size="75"></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Email 3</strong></td>
											<td><input type="text" name="email3" value="<?php echo $email3; ?>" size="75"></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Alamat Website</strong></td>
											<td><input type="text" name="website" value="<?php echo $website; ?>" size="75"></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr bgcolor="#f6f6f6">
											<td align="right"><strong>Jumlah Pax</strong></td> 
											<td><input type="text" name="pax" value="<?php echo $pax;?>" 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>Fasilitas</strong></td>
											<td><textarea cols="57" rows="5" name="fasilitas"><?php echo $fasilitas; ?></textarea></td>
										</tr>
										<tr bgcolor="#f6f6f6"><td colspan="2"><div id="grs-lurus"></div></td></tr>
										<tr valign="top" bgcolor="#f6f6f6">
											<td align="right"><strong>MICE' Category</strong></td>
											<td>
												<?php							
												$opsi = '';
												$query4="select * from direktori_category ";
												if ($hasil4 = mysql_query($query4)) {
													while ($data4=mysql_fetch_array($hasil4)) {
														$selected='';
														$query5="select * from direktori_link_category where linkTrans='$idContent' and linkCategory='".$data4["idCategory"]."' ";
														// echo $query5;
														if ($hasil5 = mysql_query($query5)) {
															while ($data5=mysql_fetch_array($hasil5)) {
																//echo $query5;
																$selected=' checked ';
															}
														}
														
														if ($opsi == "") {
															$opsi .= '<table cellpadding="5" cellspacing="0" border="0">';
														}
														$opsi .= '<tr>';
														$opsi .= '	<td><input type="checkbox"'.$selected.'name="category[]" value="'.$data4["idCategory"].'"></td>';
														$opsi .= '	<td>'.strtoupper($data4["namaCategory"]).'</td>';
														$opsi .= '</tr>';													
													}
													if ($opsi != "") {
														$opsi .= '</table>';
														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="id" value="<?php echo $idContent; ?>">
												<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 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="10" cellspacing="1" border="0" bgcolor="#999999">
										<tr bgcolor="#FFFFFF">
											<td align="center">
												<div style="padding:10px 0px 14px 0px;">
													<strong>Anda Akan Menghapus Data Berikut Ini</strong>
												</div>
												<table cellpadding="10" cellspacing="0" border="0" bgcolor="#999999">
													<tr bgcolor="#f6f6f6">
														<td width="150" align="right"><strong>Nama Perusahaan</strong></td> 
														<td><?php echo $nama;?></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="tipe" value="<?php echo $tipe; ?>">
															<input type="hidden" name="propinsi" value="<?php echo $propinsi; ?>">
															<div id="spasi1"></div>
														</td>
													</tr>
												</table>											
											</td>
										</tr>
									</table>
								</form>
							</td>
						</tr>
					</table>																													
					<?php
				}
			}
		} 
		else {
			$propinsi = $_REQUEST["propinsi"];
			$perusahaan = $_REQUEST["perusahaan"];
			?>
        	<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>
						<div align="right">
							<div id="box" style="width:107px;" onClick="location='<?php echo "?menu=".$menu."&tipe=".$tipe."&action=add"."&propinsi=".$propinsi;?>'">
								<strong>Add New Data</strong>
							</div>
						</div>
						<div>
							<div><strong>Filter Data</strong></div>
							<form method="post" action="?menu=18&tipe=Direktori" enctype="multipart/form-data" name="form">
                                <table cellpadding="0" cellspacing="0" border="0">
                                    <tr height="7"><td></td></tr>
                                    <tr>
                                        <td width="100">Nama Propinsi</td>
                                        <td width="5%" align="center">:</td>
                                        <td>
                                            <?php
                                            $opsi = "";
                                            $ctr = 0;
                                            $query4="select * from direktori_propinsi ";
                                            if ($hasil4 = mysql_query($query4)) {
                                                while ($data4=mysql_fetch_array($hasil4)) {
                                                    if ($ctr == 0) {
                                                        $opsi .= '<select name="propinsi" id="propinsi">';
                                                        $opsi .= '	<option value="0"> Pilih Propinsi </option>';
                                                        $overSelected = "";
                                                        if ($propinsi == '99') $overSelected = " selected ";
                                                        $opsi .= '	<option '.$overSelected.' value="99"> Overseas </option>';
                                                    }
                                                    $opsi .= '<option value="'.$data4["idPropinsi"].'" ';
                                                    if ($propinsi == $data4["idPropinsi"])
                                                        $opsi .= ' selected ';
                                                    $opsi .= '>'.ucwords($data4["namaPropinsi"]);
                                                    $opsi .= '</option>';
                                                    $ctr++;
                                                }
                                                if ($ctr > 0) {
                                                    $opsi .= '</select>';
                                                    echo $opsi;
                                                }
                                            }
                                            ?>
                                        </td>
                                    </tr>
                                    <tr height="7"><td></td></tr>
                                    <tr>
                                        <td>Nama Perusahaan</td>
                                        <td align="center">:</td>
                                        <td><input type="text" value="<?php echo $perusahaan; ?>" name="perusahaan" id="perusahaan" size="55" /></td>
                                    </tr>
                                    <tr height="7"><td></td></tr>
                                    <tr>
                                        <td colspan="3">
                                            <input type="submit" value=" Submit " />
                                        </td>
                                    </tr>
                                </table>
                            </form>
						</div><br>
						<table width="100%" cellpadding="6" cellspacing="1" bgcolor="#CCCCCC">
							<tr bgcolor="#EEEEEE">
								<td width="5%" align="center"><strong>ID</strong></td>
								<td width="50%"><strong>Nama</strong></td>
								<td width="30%"><strong>Propinsi</strong></td>
								<td width="15%" align="center"><strong>Action</strong></td>
							</tr>										
							<?php 
							if ($koneksi){
								if ($propinsi=='99'){
									$query = "select * from direktori_trans where propinsi='$propinsi' ";
									//echo "<br>propinsi : ".$query;
								} else {
									$query = "select * from direktori_trans, direktori_propinsi where propinsi=idPropinsi ";
									if ($propinsi) $query .= " and propinsi='$propinsi' ";
									if ($perusahaan) $query .= " and lower(nama) like lower('%$perusahaan%') ";
								}
								$query .= "order by id desc";

								$max = mysql_num_rows(mysql_query($query));
								$perhalaman = 14;
								$page = $_GET["page"];
								if (isset($page)){
									$start=($page - 1) * $perhalaman;
								} else {
									$start=0;
								}
																
								$nomor = $start;
								$query .= " LIMIT $start, $perhalaman ";
								if ($hasil=mysql_query($query)) {
									// echo "<br>query : ".$query;
									while($data=mysql_fetch_array($hasil)){													
										$nomor=$nomor+1;
										?>
										<tr bgcolor="#FFFFFF">
											<td align="center"><?php echo $nomor; ?> </td>
											<td><?php echo $data["nama"]; ?></td>
											<td><?php echo ($propinsi=='99' ? 'Overseas' : $data["namaPropinsi"]) ; ?></td>
											<td align="center">
												<a href="<?php echo "?menu=".$menu."&id=".$data["id"]."&action=edit&tipe=".$tipe."&propinsi=".$data["propinsi"];?>">Edit</a>
												&nbsp; | &nbsp; 
												<a href="<?php echo "?menu=".$menu."&id=".$data["id"]."&action=delete&tipe=".$tipe."&propinsi=".$data["propinsi"];?>">Delete</a>
											</td>
										</tr>
										<?php
									}
								}
							}	
							?>
						</table>
					</td>
				</tr>
			</table>				
			<?php	
			echo "<div id=spasi1 align='center'>";
					$tmp = "fungsi_paging-direktori.php";
					include($tmp);
					halaman($max, $perhalaman, 3, "?");
			echo "</div>"; 
		}
	}
	?>