<?php
/* $Id: left.php,v 1.19 2002/02/18 23:12:46 kkemp102294 Exp $ */

include("lib.inc.php");
?>

<html>
<head>
<title><?php echo $cfgProgName; ?></title>
<base target="main">

 <!-- Collapsible tables list scripts -->
<script type="text/javascript" language="javascript1.2">
<!--
    var isDOM      = (typeof(document.getElementsByTagName) != 'undefined') ? 1 : 0;
    var isIE4      = ((typeof(document.all) != 'undefined') && (parseInt(navigator.appVersion) >= 4)) ? 1 : 0;
    var isNS4      = (typeof(document.layers) != 'undefined') ? 1 : 0;
    var capable    = (isDOM || isIE4 || isNS4) ? 1 : 0;
    // Uggly fix for Konqueror and Opera that are not fully DOM compliant
    if (capable && typeof(navigator.userAgent) != 'undefined') {
        var browserName = ' ' + navigator.userAgent.toLowerCase();
        if (browserName.indexOf('opera') > 0) {
            capable = 0;
        }
    }
    var fontFamily = 'verdana, helvetica, arial, geneva, sans-serif';
    var isServer   = true;
    //-->
</script>
<script src="left.js" type="text/javascript" language="javascript1.2"></script>
<noscript>
<style type="text/css">
<!--
        div {color: #000000}
        .heada {font-family: verdana, helvetica, arial, geneva, sans-serif; font-size: 10pt}
        .parent {font-family: verdana, helvetica, arial, geneva, sans-serif; color: #000000; text-decoration: none}
        .child {font-family: verdana, helvetica, arial, geneva, sans-serif; font-size: 8pt; color: #333399; text-decoration: none}
        .item, .item:active, .item:hover, .tblItem, .tblItem:active {color: #333399; text-decoration: none}
        .tblItem:hover {color: #FF0000; text-decoration: underline}
        //-->
</style>
</noscript>

<style type="text/css">
<!--
    body {font-family: verdana, helvetica, arial, geneva, sans-serif; font-size: 10pt}
    //-->
</style>
</head>

<body bgcolor="#D0DCE0">
<DIV ID="el1Parent" CLASS="parent">
      
      <A class="item" HREF="main.php?server=<?php echo $server; ?>"><FONT color="black" class="heada"><?php echo $strHome;?></FONT></A><br>
	  <?php if ($server) { ?>
      <A class="item" HREF="all_db.php?server=<?php echo $server; ?>"><FONT color="black" class="heada"><?php echo $strAllDatabases;?></FONT></A>
	  <?php } ?>
	  
</DIV>

<?php
// Don't display database info if $server==0 (no server selected)
if ($server > 0) {
?>
      <DIV ID="el1Child" CLASS="child">
      </DIV>
<?php

	if (empty($cfgServer["only_db"])) {
		// list all dbs
		// If the user isn't super then filter what they can see
		if (!$bSuperUser && $cfgUserDatabases) {
			$sql_get_dbs = "SELECT datname FROM pg_database WHERE datname NOT LIKE 'template_' AND pg_get_userbyid(datdba) = CURRENT_USER ORDER BY datname";
		} else {
			$sql_get_dbs = "SELECT datname FROM pg_database WHERE datname NOT LIKE 'template_' ORDER BY datname";
		}
		$dbs = pg_exec($link, pre_query($sql_get_dbs)) or pg_die(pg_errormessage(), $sql_get_dbs, __FILE__, __LINE__);
		$num_dbs = pg_numrows($dbs);
	
		for ($i = 0; $i < $num_dbs; $i++) {
			$db = pg_result($dbs, $i, "datname");
			$j = $i+2;

			$conn_str = build_connstr(array("dbname"=>$db, "user"=>$PHP_PGADMIN_USER, "password"=>$PHP_PGADMIN_PW));
			if ($dbh_tbl = @pg_connect($conn_str)) {
			
?>

<div ID="el<?php echo $j;?>Parent" CLASS="parent">
<a class="item" HREF="db_details.php?server=<?php echo $server; ?>&db=<?php echo $db; ?>" onClick="expandBase('el<?php echo trim($j);?>', true); return false;">
    <img NAME="imEx" ID="el<?php echo $j;?>Img" SRC="images/plus.gif" BORDER="0" ALT="+" width="9" height="9"></a>
<a class="item" HREF="db_details.php?server=<?php echo $server; ?>&db=<?php echo $db; ?>" onClick="expandBase('el<?php echo trim($j);?>', false);">
    <font color="black" class="heada"><?php echo trim($db);?></font></a>
</div>

<div ID="el<?php echo $j; ?>Child" CLASS="child" style="margin-bottom: 5px">
<?php
				if (!isInArray($db, $cfgNoTables)) {

					$sql_get_tbls = "SELECT tablename FROM pg_tables WHERE tablename !~* 'pg_*' ORDER BY tablename";
		
					$tbl_res = pg_exec($dbh_tbl, pre_query($sql_get_tbls));
					$num_tbl = pg_numrows($tbl_res);

					for ($j = 0; $j < $num_tbl; $j++) {
						$table = pg_result($tbl_res, $j, "tablename");
?>
    <nobr><img src="images/spacer.gif" border="0" width="9" height="9" alt="" />
    <a target="main" href="sql.php?sql_query=<?php echo urlencode("SELECT * FROM $cfgQuotes$table$cfgQuotes");?>&server=<?php echo $server;?>&db=<?php echo urlencode($db);?>&table=<?php echo urlencode($table);?>&goto=tbl_properties.php">
        <img src="images/browse.gif" border="0" alt="<?php echo "$strBrowse $strTable: $table"; ?>"></a>
    <a class="item" target="main" HREF="tbl_properties.php?server=<?php echo $server;?>&db=<?php echo $db;?>&table=<?php echo urlencode($table);?>"><?php echo $table;?></a></nobr><br />

<?php
					}
					pg_freeresult($tbl_res);
					pg_close($dbh_tbl);
				} else {
					echo "&nbsp;&nbsp;<span class=\"item\">$strNotDisplayed</span>";
				}
				echo "</div>\n";
			}
		}
	} else {
		// only_db is set
		$db = $cfgServer[only_db];
	?>

<div ID="el100Parent" CLASS="parent">
    <a class="item" HREF="db_details.php?server=<?php echo $server; ?>&db=<?php echo $db; ?>" onClick="expandBase('el100', true); return false;">
        <img NAME="imEx" ID="el100Img" SRC="images/plus.gif" BORDER="0" ALT="+" width="9" height="9"></a>
    <a class="item" HREF="db_details.php?server=<?php echo $server; ?>&db=<?php echo $db; ?>" onClick="expandBase('el100', false);">
        <font color="black" class="heada"><?php echo trim($db);?></font></a>
</div>

<div ID="el100Child" CLASS="child" style="margin-bottom: 5px">
<?php
		$conn_str = build_connstr(array("dbname"=>$db, "user"=>$PHP_PGADMIN_USER, "password"=>$PHP_PGADMIN_PW));

		$dbh_tbl = pg_connect($conn_str) or pg_die(pg_errormessage(), $conn_str, __FILE__, __LINE__);
		$sql_get_tbls = "SELECT tablename FROM pg_tables WHERE tablename !~* 'pg_*' ORDER BY tablename";

		$tbl_res = pg_exec($dbh_tbl, pre_query($sql_get_tbls));
		$num_tbl = pg_numrows($tbl_res);

		for ($j = 0; $j < $num_tbl; $j++) {
			$table = pg_result($tbl_res, $j, "tablename");
?>
    <nobr><img src="images/spacer.gif" border="0" width="9" height="9" alt="" />
    <a target="main" href="sql.php?sql_query=<?php echo urlencode("SELECT * FROM $cfgQuotes$table$cfgQuotes");?>&server=<?php echo $server;?>&db=<?php echo urlencode($db);?>&table=<?php echo urlencode($table);?>&goto=tbl_properties.php">
        <img src="images/browse.gif" border="0" alt="<?php echo "$strBrowse $strTable: $table"; ?>"></a>
    <a class="item" target="main" HREF="tbl_properties.php?server=<?php echo $server;?>&db=<?php echo $db;?>&table=<?php echo urlencode($table);?>"><?php echo $table;?></a></nobr><br />

<?php
		}
		pg_freeresult($tbl_res);
		pg_close($dbh_tbl);
		echo "</div>\n";
	}
}
?>
<?php
	if ($bSuperUser && $cfgSysTables) {
?>
<p>
<div ID="el200Parent" CLASS="parent">
    <a class="item" HREF="javascript:void(0)" onClick="expandBase('el200', true); return false;">
        <img NAME="imEx" ID="el200Img" SRC="images/plus.gif" BORDER="0" ALT="+" width="9" height="9"></a>
    <a class="item" onClick="expandBase('el200', false);">
        <font color="black" class="heada"><?php echo $strSystemTables; ?></font></a>
</div>

<div ID="el200Child" CLASS="child">
<?php
			$db = $cfgDefaultDB;
			$conn_str = build_connstr(array("dbname"=>$db, "user"=>$PHP_PGADMIN_USER, "password"=>$PHP_PGADMIN_PW));
			
			$dbh_tbl = pg_connect($conn_str) or pg_die(pg_errormessage(), $conn_str, __FILE__, __LINE__);
			$sql_get_tbls = "select relname from pg_class where relname ~ 'pg_.*' and relkind = 'r' or relkind = 'v' order by relname";
			$tbl_res = pg_exec($dbh_tbl, pre_query($sql_get_tbls));
	
			$num_tables = @pg_numrows($tbl_res);
			for ($j = 0; $j < $num_tables; $j++) {
				$table = pg_result($tbl_res, $j, "relname");
				
				$query_str = "sql_query=" . urlencode("SELECT * FROM $cfgQuotes$table$cfgQuotes") . "&server=$server&db=$db&table=" . urlencode($table);
	?>
    <nobr><img src="images/spacer.gif" border="0" width="3" height="9" alt="" />
    <a target="main" href="sql.php?<?php echo $query_str; ?>&goto=tbl_properties.php">
        <img src="images/browse.gif" border="0" alt="<?php echo "$strBrowse $strTable: $table"; ?>"></a>
    <a class="item" target="main" HREF="tbl_properties.php?server=<?php echo $server;?>&db=<?php echo $db;?>&table=<?php echo urlencode($table);?>"><?php echo $table;?></a></nobr><br />

<?php
			}
	echo "</div>\n";
	}	

	if ($bSuperUser && $cfgUserAdmin) {
		echo "
			<div ID=\"el300Parent\" CLASS=\"parent\">
				<p>
				<a class=\"item\" href=\"user_admin.php?server=$server\" target=main>$strUserAdmin</a><br>
				<a class=\"item\" href=\"grp_admin.php?server=$server\" target=main>$strGroupAdmin</a>
			</div>
		";
	}
	if ($cfgReports && $server) {
		echo "
			<div ID=\"el300Parent\" CLASS=\"parent\">
				<a class=\"item\" href=\"reports.php?server=$server\" target=main>$strReports</a>
			</div>
		";
	}
?>
 <!-- Arrange collapsible/expandable db list at startup -->
<script type="text/javascript" language="javascript1.2">
<!--
    if (isNS4) {
      firstEl  = 'el1Parent';
      firstInd = nsGetIndex(firstEl);
      nsShowAll();
      nsArrangeList();
    }
    expandedDb = '';
    //-->
</script>
</body>
</html>
