	<?php	
	$targetPage = $thisPage;
	//echo "<br> Target : ".$targetPage;
	$basicUrl = $thisUrl;
	
	$targetDir = "";
	//$targetPage .= "/";
	$homeDir = $targetPage;

	$tmp = $thisUrl."functions/clear_data.php";
	include ($tmp);

	$targetPage .= "content/";
	$targetDir  .= "content/";

	//echo "<br> Ta	rget Dir : ".$targetDir;

	if (!file_exists($targetDir)) {
		//echo "<br>".$targetDir;
		mkdir($basicUrl.$targetDir , 0755);
	}
	
	$sql = "select * from menus_level_0 ";
	if ($hasil = mysql_query($sql)) {
		while ($data = mysql_fetch_array($hasil)) {
			$whenCreateMenu = "";
			$current_url = $data["namaMenu"];
			$current_url = str_replace('& ', '', $current_url);		
			$current_url = str_replace(', ', '', $current_url);		
			$current_url = explode(' ',$current_url);
			foreach ($current_url as $url) {
				if ($whenCreateMenu != "") {
					$whenCreateMenu .= "-";
					//$targetPage .= "-";
					//$targetDir .= "-";
				}	
				$whenCreateMenu .= strtolower($url);
				//$targetPage .= strtolower($url);
				//$targetDir .= strtolower($url);
			}
			$targetDir1 = $targetDir.$whenCreateMenu.'/';
			//echo "<br> targetDir1 : ".$targetDir1;
			//echo "<br> Link: ".$data["menuLINK"];
			if ($data["namaMenu"]=="Home") {
				// echo "<br>Menu : ".$whenCreateMenu."<br>Page : ".$thisPage;
				if ($data["menuLINK"] != $thisPage) {
					$sql3 = "update menus_level_0 set menuLINK= '$thisPage' where id = ".$data["id"];
					mysql_query($sql3);
				}
			} else {
				/* Menu Head Section  */ 
				if (!file_exists($targetDir1)) {
					mkdir($basicUrl.$targetDir1 , 0755);
					//echo "<br>".$targetDir1;
				}				
				if ($data["menuLINK"] != $targetDir1 && $data["menuLINK"] != "#" ) {
					$sql3 = "update menus_level_0 set menuLINK= '$targetDir1' where id = ".$data["id"];
					mysql_query($sql3);
				}
				// echo "<br> Files : ".$indexFiles;
				$indexFiles = $targetDir1.'index.php'; 
				$tmp = $thisUrl."functions/createUrl.php";
				include ($tmp);				
				/* Menu Head Section End  */ 
				
				/* Menu Sub Head Section  */ 
				$sql2 = "select * from menus_level_1 where menus_lv_0 = ".$data["id"];
				if ($hasil2 = mysql_query($sql2)) {
					while ($data2 = mysql_fetch_array($hasil2)) {
                        $whenCreateMenu = "";
                        $current_url = $data2["namaMenu_lv_1"];
                        $current_url = str_replace('& ', '', $current_url);	
                        $current_url = str_replace(', ', '', $current_url);	

                        $current_url = explode(' ',$current_url);
                        foreach ($current_url as $url) {
                            if ($whenCreateMenu != "") {
                                $whenCreateMenu .= "-";
                                //$targetPage .= "-";
                                //$targetDir .= "-";
                            }	
                            $whenCreateMenu .= strtolower($url);
                            //$targetPage .= strtolower($url);
                            //$targetDir .= strtolower($url);
						}
					
						$targetDir2 = $targetDir1.$whenCreateMenu.'/'; 
						// echo "<br> Pages : ".$targetDir2;

						$indexFiles = $targetDir2.'index.php';
						//echo "<br> Pages Index : ".$indexFiles;
						
						if (!file_exists($targetDir2)) {
							mkdir($basicUrl.$targetDir2 , 0755);
							//echo "<br>".$targetDir2;
							//echo  $sql3;
						}

						if ($data2["link_lv_1"] != $targetDir2) {
							$sql3 = "update menus_level_1 set link_lv_1 = '$targetDir2' where id_level_1 = ".$data2["id_level_1"];
							mysql_query($sql3);
						}
						 
						if ($targetDir2) {
							//echo "<br> File : ".$indexFiles;
							//include ("createUrl.php");						
							$tmp = $thisUrl."functions/createUrl.php";
							include ($tmp);
							// echo "<br> Temp : ".$tmp;
							// mkdir($indexFiles , 0755);
							
						}

						$imagesFolder = $basicUrl.$targetDir2.'images/'; 
						if (!file_exists($imagesFolder)) {
							//mkdir($imagesFolder , 0755);
							mkdir($imagesFolder , 0755);
							//echo "<br>".$imagesFolder;
						}

						// Menu Level 2
						$sql3 = "select * from menus_level_2 where menus_lv_1 = ".$data2["id_level_1"];
						if ($hasil3 = mysql_query($sql3)) {
							while ($data3 = mysql_fetch_array($hasil3)) {
								$whenCreateMenu = "";
								$current_url = $data3["namaMenu_lv_2"];
								$current_url = str_replace('& ', '', $current_url);	
								$current_url = str_replace(', ', '', $current_url);	
								$current_url = str_replace('(', '', $current_url);	
								$current_url = str_replace(')', '', $current_url);	
		
								$current_url = explode(' ',$current_url);
								foreach ($current_url as $url) {
									if ($whenCreateMenu != "") {
										$whenCreateMenu .= "-";
										//$targetPage .= "-";
										//$targetDir .= "-";
									}	
									$whenCreateMenu .= strtolower($url);
									//$targetPage .= strtolower($url);
									//$targetDir .= strtolower($url);
								}
							
								$targetDir3 = $targetDir2.$whenCreateMenu.'/'; 
								//echo "<br> Pages : ".$targetDir3;
		
								$indexFiles = $targetDir3.'index.php';
								//echo "<br> Pages Index : ".$indexFiles;
								
								if (!file_exists($targetDir3)) {
									mkdir($basicUrl.$targetDir3 , 0755);
									//echo "<br>".$targetDir3;
									//echo  $sql3;
								}
		
								if ($data3["link_lv_2"] != $targetDir3) {
									$sql4 = "update menus_level_2 set link_lv_2 = '$targetDir3' where id_level_2 = ".$data3["id_level_2"];
									mysql_query($sql4);
								}
								 
								if ($targetDir3) {
									//echo "<br> File : ".$indexFiles;
									//include ("createUrl.php");						
									$tmp = $thisUrl."functions/createUrl.php";
									include ($tmp);
									// echo "<br> Temp : ".$tmp;
									// mkdir($indexFiles , 0755);
								}
		
								$imagesFolder = $basicUrl.$targetDir3.'images/'; 
								if (!file_exists($imagesFolder)) {
									//mkdir($imagesFolder , 0755);
									mkdir($imagesFolder , 0755);
									//echo "<br>".$imagesFolder;
								}

								/* Organize Content Begin */
								$sql5 = "select * from content where level_0= '".$data["id"]."' and level_1 = '".$data2["id_level_1"]."' and level_2 = '".$data3["id_level_2"]."' order by idContent ";
								if ($hasil5 = mysql_query($sql5)) {
									while ($data5 = mysql_fetch_array($hasil5)) {
										$whenCreateMenu = "";
										$current_url = $data5["pageTitle"];
										$current_url = str_replace('& ', '', $current_url);	
										$current_url = str_replace(', ', '', $current_url);	
										$current_url = str_replace('(', '', $current_url);	
										$current_url = str_replace(')', '', $current_url);	
										$current_url = str_replace('?', '', $current_url);	
										$current_url = str_replace("'", "", $current_url);	
										$current_url = str_replace('"', '', $current_url);	
				
										$current_url = explode(' ',$current_url);
										foreach ($current_url as $url) {
											if ($whenCreateMenu != "") {
												$whenCreateMenu .= "-";
												//$targetPage .= "-";
												//$targetDir .= "-";
											}	
											$whenCreateMenu .= strtolower($url);
											//$targetPage .= strtolower($url);
											//$targetDir .= strtolower($url);
										}
									
										$targetDir4 = $targetDir3.$whenCreateMenu.'/'; 
										//echo "<br> Pages : ".$targetDir3;
				
										$indexFiles = $targetDir4.'index.php';
										//echo "<br> Pages Index : ".$indexFiles;

										if (!file_exists($targetDir4)) {
											mkdir($basicUrl.$targetDir4 , 0755);
											//echo "<br>".$targetDir3;
											//echo  $sql3;
										}
										if ($data5["targetPage"] != $targetDir4) {
											$sql6 = "update content set targetPage = '$targetDir4' where idContent = ".$data5["idContent"];
											mysql_query($sql6);
										}
										
										if ($targetDir4) {
											//echo "<br> File : ".$indexFiles;
											//include ("createUrl.php");						
											$tmp = $thisUrl."functions/createUrl.php";
											include ($tmp);
											// echo "<br> Temp : ".$tmp;
											// mkdir($indexFiles , 0755);
										}
				
										$imagesFolder = $basicUrl.$targetDir4.'images/'; 
										if (!file_exists($imagesFolder)) {
											//mkdir($imagesFolder , 0755);
											mkdir($imagesFolder , 0755);
											//echo "<br>".$imagesFolder;
										}
									
									}
								}
								/* Organize Content End */
							}
						}
					}
				}
				/* Menu Sub Head Section End  */ 
			}
		}
	}
	
	// echo "<br><br>imageUrl : ".$imageUrl;
	// echo "<br> Targe : ".$targetPage;
	?>