	<?php
	function createMenu($thisUrl, $dirName="", $menuName="", $parent=0) {
		$sql7 = "select * from menus WHERE menusIDParent = '$parent' ORDER BY menusOrder ";
		if ($hasil7 = mysql_query($sql7)) {
			while ($data7 = mysql_fetch_array($hasil7)) {
				$whenCreateMenu = "";
				$current_url = $data7["menusName"];
				$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);
				}
				
				if ($dirName == '') {
					$menuName = $whenCreateMenu."/";
				} else {
					$menuName = $dirName.$whenCreateMenu."/";
				}

				$folderName = $menuName;
				if ($data7["menusIDParent"] == '0') {
					$ext = "";
				} else {
					$ext = "#".$data7["menusID"];
				}
				$folderNameUpload = $folderName;
				//echo "<br> folderName : "."#".$data7["menusID"];
				
				if ($data7["menusLink"] != $folderName && $data7["menusLink"] != "#" ) {
					$sql8 = "update menus set menusLink = '$folderNameUpload' where menusID = ".$data7["menusID"];
					if (mysql_query($sql8)) {
					}				
				}
				
				if (!file_exists($thisUrl.$folderName)) {
					if (mkdir($folderName , 0755)) {
					} else {
						if (chmod($folderName , 0755)) {}
					}
				}

				$indexFiles = $thisUrl.$folderName.'index.php'; 
				$tmp = $thisUrl."functions/createUrl.php";
				include ($tmp);				

				$folderName = $folderName."images/";
				if (!file_exists($thisUrl.$folderName)) {
					if (mkdir($folderName , 0755)) {}
				}
				
				createMenu($thisUrl, $menuName, $menuName, $data7["menusID"]);
			}
		}
	}

	$tmp = $thisUrl."functions/clear_data.php";
	include ($tmp);
	createMenu($thisUrl, "", "", 0);
	//echo $menuName;
	?>
