<?php

	// include files
	require_once('php/config.php');
	require_once('php/db.php');
	require_once('php/login.php');
	require_once('php/info.php');
	require_once('php/status.php');
	//
	// query
	$page_name = "page";
	$level_name = "level";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo($admin_title);?></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<script src="script.js" language="javascript"></script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="18%" valign="top" style="padding:10px;"><?php include('menu.php'); ?></td>
    <td width="82%" valign="top" style="padding: 10px;">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top" class="adm_ct">
		<form name="form1" id="form1">
          <table width="100%" border="0" cellpadding="5" cellspacing="5">
            <tr>
              <td width="5%" valign="top"><strong>ID</strong></td>
              <td width="95%" valign="top" colspan="2"><strong>Page | Title | Updated | Level | Add page | Type | Edit page | Unlock / Lock | Sort | Delete </strong></td>
            </tr>
            <?php
			//
			$ln1 = 1;
			$lvhf1 = 1;
			$lv1 = 1;
			// query
			$result = mysql_query("SELECT * FROM $page_name WHERE level1 <> '0' AND level2 = '0' AND level3 = '0' AND hidden_status <> 3 ORDER by list_number ASC", $db);
			if(@$myrow = mysql_fetch_array($result))
			{
				//
				$resultl1 = mysql_query("SELECT * FROM $page_name WHERE level2 = '0' AND level3 = '0' AND hidden_status <> 3 ORDER by level1 DESC", $db);
				if(@$myrowl1 = mysql_fetch_array($resultl1))
				{
					$lv1 = $myrowl1['level1'];
					$lv1 = $lv1 + 1;
				}
				//
				$srt1 = 1;
				$resultls = mysql_query("SELECT * FROM $page_name WHERE level2 = '0' AND level3 = '0' AND hidden_status <> 3 ORDER by list_number DESC", $db);
				if(@$myrowls = mysql_fetch_array($resultls))
				{
					$srt1 = $myrowls['id'];
				}
				//
				do
				{
					//
					$level1 = $myrow['level1'];
					//echo('<b>1: '.$myrow['id'].'</b><br>');
					$resultl1b = mysql_query("SELECT * FROM $page_name WHERE level1 = '$level1' AND level2 <> '0' AND level3 = '0' AND hidden_status <> 3 ORDER by level2 DESC", $db);
					if(@$myrowl1b = mysql_fetch_array($resultl1b))
					{
						//$lv1b = mysql_num_rows($resultl1b);
						$lv1b = $myrowl1b['level2'];
						$lv1b = $lv1b + 1;
					}
					else
					{
						$lv1b = 1;
					}
					// code
					echo('<tr bgcolor="'.$col["1"].'">'."\n");
					echo('<td width="5%" valign="top">'."\n");
					echo($myrow['id']);
					echo('</td>'."\n");
					// result2
					echo('<td width="90%" valign="top">'."\n");
					// link
					echo('<img src="img/i1.gif" border="0" alt="cursor">&nbsp;');
					// title
					echo('<b>'.$myrow['title_global'].'</b>');
					// title
					if($myrow['title1'] != "")
					{
						echo(', <b>'.$myrow['title1'].'</b>');
					}
					// up date
					if($myrow['up_date'] != "")
					{
						echo(', '.$myrow['up_date'].'&nbsp;');
					}
					// level
					echo('('.$myrow['level1']);
					echo(' - '.$myrow['level2']);
					echo(' - '.$myrow['level3'].')');	
					echo(' <b>LN: '.$myrow['list_number'].'</b>');
					//
					echo('<br>');
					echo('</td>'."\n");
					echo('<td width="5%" valign="top">');
					// view city
					echo('<img src="img/t30bw.gif" border="0" alt="view city">&nbsp;');
					// add page
					$ln1 = $myrow['list_number'] + $shag;
					//echo('<a href="add_'.$page_name.'.php?event=add&level1='.$lv1.'&level2=0&level3=0&ln='.$ln1.'"><img src="img/t26.gif" border="0" alt="add page"></a>&nbsp;');
					// add page and menu
					//echo('<a href="add_'.$page_name.'.php?event=add&level1='.$myrow['level1'].'&level2='.$lv1b.'&level3=0&ln='.$lv1b.'"><img src="img/t27.gif" border="0" alt="add page and menu"></a>&nbsp;');
					// page type
					echo('<img src="img/pt'.$myrow['page_type'].'.gif" border="0" alt="page type">&nbsp;');
					// change
					echo('<a href="add_'.$page_name.'.php?id='.$myrow['id'].'&event=change"><img src="img/red.gif" border="0" alt="change"></a>&nbsp;');
					// status
					echo('<a href="javascript:hidden_status(\''.$myrow['id'].'\',\''.$myrow['hidden_status'].'\',\'change_status\',\'page\');"><img src="img/status'.$myrow['hidden_status'].'.gif" border="0" alt="hidden status"></a>&nbsp;');
					// done
					//echo('<img src="img/do'.$myrow['done'].'.gif" border="0" alt="done">&nbsp;');
					// up level
					//if($lvhf1 != 1)
					//{
						//echo('<a href="javascript:change_level(\'up\',\''.$myrow['id'].'\',\''.$myrow['list_number'].'\',\'change_level\',\'page\',\'lvhf1\',\''.$lvhf1.'\');"><img src="img/t23.gif" border="0" alt="up"></a>&nbsp;');
					//}
					//else
					//{
					//	echo('<img src="img/t23b.gif" border="0" alt="up"></a>&nbsp;');
					//}
					// down level
					//if($srt1 != $myrow['id'])
					//{
						//echo('<a href="javascript:change_level(\'down\',\''.$myrow['id'].'\',\''.$myrow['list_number'].'\',\'change_level\',\'page\',\'lvhf1\',\''.$lvhf1.'\');"><img src="img/t24.gif" border="0" alt="down"></a>&nbsp;');
					//}
					//else
					//{
					//	echo('<img src="img/t24b.gif" border="0" alt="up"></a>&nbsp;');
					//}
					// ln field
					echo('<input type="hidden" name="lvhf1'.$lvhf1.'" value="'.$myrow['list_number'].'">');
					$lvhf1 = $lvhf1 + 1;
					// delete
					//echo('<a href="javascript:delete_page(\''.$myrow['id'].'\',\'delete\',\'page\');"><img src="img/delete.gif" border="0" alt="delete"></a>');
					echo('</td>'."\n");
					echo('</tr>'."\n");
					//
					// meore done
					$lvhf2 = 1;
					// query
					$result2 = mysql_query("SELECT * FROM $page_name WHERE level1 = '$level1' AND level2 <> '0' AND level3 = '0' AND hidden_status <> 3 ORDER by list_number ASC", $db);
					if(@$myrow2 = mysql_fetch_array($result2))
					{
						//
						$srt2 = 1;
						//$level2 = $myrow2['level2'];
						//echo('<b>2: '.$myrow2['id'].'</b><br>');
						$resultl1g = mysql_query("SELECT * FROM $page_name WHERE level1 = '$level1' AND level2 <> '0' AND level3 = '0' AND hidden_status <> 3 ORDER by list_number DESC", $db);
						if(@$myrowl1g = mysql_fetch_array($resultl1g))
						{
							$srt2 = $myrowl1g['id'];
						}
						//
						do
						{
							//
							$lvl1 = $myrow['level1'];
							$lvl2 = $myrow2['level2'];
							//echo($myrow['level1']." - ".$myrow2['level2']);
							$resultl1c = mysql_query("SELECT * FROM $page_name WHERE level1 = '$lvl1' AND level2 = '$lvl2' AND level3 <> '0' AND hidden_status <> 3 ORDER by list_number DESC", $db);
							if(@$myrowl1c = mysql_fetch_array($resultl1c))
							{
								//$lv1c = mysql_num_rows($resultl1c);
								$lv1c = $myrowl1c['level3'];
								$lv1c = $lv1c + 1;
							}
							else
							{
								$lv1c = 1;
							}
							// code
							echo('<tr bgcolor="'.$col["2"].'">'."\n");
							echo('<td width="5%" valign="top">'."\n");
							echo($myrow2['id']);
							echo('</td>'."\n");
							// result2
							echo('<td width="90%" valign="top">'."\n");
							// line
							echo('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
							// link
							echo('<img src="img/i2.gif" border="0" alt="cursor">&nbsp;');
							// title
							echo('<b>'.$myrow2['title_global'].'</b>');
							// title
							if($myrow2['title1'] != "")
							{
								echo(', <b>'.$myrow2['title1'].'</b>');
							}
							// up date
							if($myrow2['up_date'] != "")
							{
								echo(', '.$myrow2['up_date'].'&nbsp;');
							}
							// level
							echo('('.$myrow2['level1']);
							echo(' - '.$myrow2['level2']);
							echo(' - '.$myrow2['level3'].')');
							echo(' <b>LN: '.$myrow2['list_number'].'</b>');
							//
							echo('<br>');
							echo('</td>'."\n");
							echo('<td width="5%" valign="top">');
							// view city
							echo('<a href="view_city.php?level1='.$myrow2['level1'].'&level2='.$myrow2['level2'].'&level3='.$myrow2['level3'].'&c1='.$myrow['title_global'].'&c2='.$myrow2['title_global'].'"><img src="img/t30.gif" border="0" alt="view city"></a>&nbsp;');
							// add page
							$ln2 = $myrow2['list_number'] + $shag;
							//echo('<a href="add_'.$page_name.'.php?event=add&level1='.$myrow['level1'].'&level2='.$lv1b.'&level3=0&ln='.$ln2.'"><img src="img/t26.gif" border="0" alt="add page"></a>&nbsp;');
							// add page and menu
							//echo('<a href="add_'.$page_name.'.php?event=add&level1='.$myrow['level1'].'&level2='.$myrow2['level2'].'&level3='.$lv1c.'&ln='.$lv1c.'"><img src="img/t27.gif" border="0" alt="add page and menu"></a>&nbsp;');
							//
							//echo('<img src="img/t27b.gif" border="0" alt="add page and menu">&nbsp;');
							// page type
							echo('<img src="img/pt'.$myrow2['page_type'].'.gif" border="0" alt="page type">&nbsp;');
							// change
							echo('<a href="add_'.$page_name.'.php?id='.$myrow2['id'].'&event=change"><img src="img/red.gif" border="0" alt="change"></a>&nbsp;');
							// status
							echo('<a href="javascript:hidden_status(\''.$myrow2['id'].'\',\''.$myrow2['hidden_status'].'\',\'change_status\',\'page\');"><img src="img/status'.$myrow2['hidden_status'].'.gif" border="0" alt="hidden status"></a>&nbsp;');
							// done
							//echo('<img src="img/do'.$myrow2['done'].'.gif" border="0" alt="done">&nbsp;');
							// up level
							//if($lvhf2 != 1)
							//{
								//echo('<a href="javascript:change_level(\'up\',\''.$myrow2['id'].'\',\''.$myrow2['list_number'].'\',\'change_level\',\'page\',\'lvhf2\',\''.$lvhf2.'\');"><img src="img/t23.gif" border="0" alt="up"></a>&nbsp;');
							//}
							//else
							//{
							//	echo('<img src="img/t23b.gif" border="0" alt="up"></a>&nbsp;');
							//}
							// down level
							//if($srt2 != $myrow2['id'])
							//{
								//echo('<a href="javascript:change_level(\'down\',\''.$myrow2['id'].'\',\''.$myrow2['list_number'].'\',\'change_level\',\'page\',\'lvhf2\',\''.$lvhf2.'\');"><img src="img/t24.gif" border="0" alt="down"></a>&nbsp;');
							//}
							//else
							//{
							//	echo('<img src="img/t24b.gif" border="0" alt="up"></a>&nbsp;');
							//}
							// ln field
							echo('<input type="hidden" name="lvhf2'.$lvhf2.'" value="'.$myrow2['list_number'].'">');
							$lvhf2 = $lvhf2 + 1;
							// delete
							//echo('<a href="javascript:delete_page(\''.$myrow2['id'].'\',\'delete\',\'page\');"><img src="img/delete.gif" border="0" alt="delete"></a>');
							echo('</td>'."\n");
							echo('</tr>'."\n");
							//
							// mesame done
							$lvhf3 = 1;
							// query
							$level2 = $myrow2['level2'];
							$result3 = mysql_query("SELECT * FROM $page_name WHERE level1 = '$level1' AND level2 = '$level2' AND level3 <> '0' AND hidden_status <> 3 ORDER by list_number ASC", $db);
							if(@$myrow3 = mysql_fetch_array($result3))
							{
								do
								{
									$srt3 = 1;
									$level3 = $myrow3['level3'];
									$resultl13 = mysql_query("SELECT * FROM $page_name WHERE level1 = '$level1' AND level2 = '$level2' AND level3 = '$level3' AND hidden_status <> 3 ORDER by list_number DESC", $db);
									if(@$myrowl13 = mysql_fetch_array($resultl13))
									{
										$srt3 = $myrowl13['id'];
									}
									// code
									echo('<tr bgcolor="'.$col["3"].'">'."\n");
									echo('<td width="5%" valign="top">'."\n");
									echo($myrow3['id']);
									echo('</td>'."\n");
									// result3
									echo('<td width="90%" valign="top">'."\n");
									// line
									echo('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
									// link
									echo('<img src="img/i3.gif" border="0" alt="cursor">&nbsp;');
									// title
									echo('<b>'.$myrow3['title_global'].'</b>');
									// title
									if($myrow3['title1'] != "")
									{
										echo(', <b>'.$myrow3['title1'].'</b>');
									}
									// up date
									if($myrow3['up_date'] != "")
									{
										echo(', '.$myrow3['up_date'].'&nbsp;');
									}
									// level
									echo('('.$myrow3['level1']);
									echo(' - '.$myrow3['level2']);
									echo(' - '.$myrow3['level3'].')');
									echo(' <b>LN: '.$myrow3['list_number'].'</b>');
									//
									echo('<br>');
									echo('</td>'."\n");
									echo('<td width="5%" valign="top">');
									$ln3 = $myrow3['list_number'] + $shag;
									// add page
									//echo('<a href="add_'.$page_name.'.php?event=add&level1='.$myrow['level1'].'&level2='.$myrow2['level2'].'&level3='.$lv1c.'&ln='.$ln3.'"><img src="img/t26.gif" border="0" alt="add page"></a>&nbsp;');
									// add page and menu
									echo('<img src="img/t27b.gif" border="0" alt="page and menu">&nbsp;');
									// page type
									echo('<img src="img/pt'.$myrow3['page_type'].'.gif" border="0" alt="page type">&nbsp;');
									// change
									echo('<a href="add_'.$page_name.'.php?id='.$myrow3['id'].'&event=change"><img src="img/red.gif" border="0" alt="change"></a>&nbsp;');
									// status
									echo('<a href="javascript:hidden_status(\''.$myrow3['id'].'\',\''.$myrow3['hidden_status'].'\',\'change_status\',\''.$page_name.'\');"><img src="img/status'.$myrow3['hidden_status'].'.gif" border="0" alt="hidden status"></a>&nbsp;');
									// done
									//echo('<img src="img/do'.$myrow3['done'].'.gif" border="0" alt="done">&nbsp;');
									// up level
									//if($lvhf3 != 1)
									//{
										echo('<a href="javascript:change_level(\'up\',\''.$myrow3['id'].'\',\''.$myrow3['list_number'].'\',\'change_level\',\''.$page_name.'\',\'lvhf3\',\''.$lvhf3.'\');"><img src="img/t23.gif" border="0" alt="up"></a>&nbsp;');
									//}
									//else
									//{
									//	echo('<img src="img/t23b.gif" border="0" alt="up"></a>&nbsp;');
									//}
									// down level
									//if($srt3 != $myrow3['id'])
									//{
										echo('<a href="javascript:change_level(\'down\',\''.$myrow3['id'].'\',\''.$myrow3['list_number'].'\',\'change_level\',\''.$page_name.'\',\'lvhf3\',\''.$lvhf3.'\');"><img src="img/t24.gif" border="0" alt="down"></a>&nbsp;');
									//}
									//else
									//{
									//	echo('<img src="img/t24b.gif" border="0" alt="up"></a>&nbsp;');
									//}
									// ln field
									echo('<input type="hidden" name="lvhf3'.$lvhf3.'" value="'.$myrow3['list_number'].'">');
									$lvhf3 = $lvhf3 + 1;
									// delete
									echo('<a href="javascript:delete_page(\''.$myrow3['id'].'\',\'delete\',\''.$page_name.'\');"><img src="img/delete.gif" border="0" alt="delete"></a>');
									echo('</td>'."\n");
									echo('</tr>'."\n");
									//
								} 
								while($myrow3 = mysql_fetch_array($result3));
							}
							// end mesame done
						} 
						while($myrow2 = mysql_fetch_array($result2));
					}
					// end meore done
				} 
				while($myrow = mysql_fetch_array($result));
			}
			//else
			//{
				// code
				echo('<tr bgcolor="'.$col["1"].'">'."\n");
				echo('<td width="100%" valign="top" colspan="3">'."\n");
				// add page
				//echo('<a href="add_'.$page_name.'.php?event=add&level1='.$lv1.'&level2=0&level3=0&ln='.$ln1.'"><img src="img/t26.gif" border="0" alt="add page"></a>&nbsp;');
				//
				//echo('<a href="add_'.$page_name.'.php?event=add&level1='.$lv1.'&level2=0&level3=0&ln='.$ln1.'" class="t2">Add page</a>');
				echo('</td>'."\n");
				echo('</tr>'."\n");
			//}
			?>
          </table>
		  </form>
		  </td>
      </tr>
    </table>
	</td>
  </tr>
</table>
</body>
</html>