Location: PHPKode > projects > Netautor Professional > netautor/napro4/admin/database/sqladm_tabwork.php
<?php
/* +----------------------------------------------------------------------+
   | Netautor Professional Application Server                             |
   +----------------------------------------------------------------------+
   | Copyright (C) 1998-2005 digiconcept GmbH. <www.digiconcept.net>      |
   +----------------------------------------------------------------------+
   | This file is subject to license, that is bundled with this package   |
   | in the file LICENSE.TXT, and is available at through the             |
   | world-wide-web at http://www.netautor.com/license/                   |
   |                                                                      |
   | If you did not receive a copy of the license and are unable to       |
   | obtain it through the world-wide-web, please send a note to          |
   | hide@address.com so we can mail you a copy.                      |
   +----------------------------------------------------------------------+
   | Authors: Stefan Rottensteiner <hide@address.com>    |
   |          Marek  Kadziela      <hide@address.com>	      |
   |          Gregor Wollner                                              |
   |          Christian Unger                                             |
   |          Helli  Kleinhans  									      |
   +----------------------------------------------------------------------+
   | @version	$Revision: 1.19 $										  |
   +----------------------------------------------------------------------+*/

/**
 * A simple but usefull site to show table definitions
 *
 * @author Helli Kleinhans
 * @author Marek Kadziela
 */

require_once('../../include/init.inc');

if(!$GLOBALS['USER']->check_feature('Admin') && !$GLOBALS['USER']->check_feature('ac_database'))
{
	$GLOBALS['USER']->login_call();
}

includeNaPro('mdb,array');

$GLOBALS['LOCALE']->textdomain('database');

$table = array();

$tables = $sql_world->get_tables();

$result = $sql_world->get_table_def($table_name,$table);

if(substr($table['name'],0,3) == 'na_')
{
	$table_id = explode('_',substr($table['name'],3));
}

$width	=	( empty($result_window) ? 975 : 750 );

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>digiconcept/netautor/</title>
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<meta http-equiv="pragma" 			content="no-cache"> 
		<meta http-equiv="cache-control" 	content="no-cache">
		<meta name		="robots" 			content="noindex">
		<link href="../../include/netautor.css" rel="stylesheet" type="text/css">	
	</head>
	<script language="JavaScript">
	<!-- 
	function new_window()
	{
		top.main.document.getElementById('f_datenbank').rows='190,*,24';
		
		window.open('<?php echo $_SERVER['PHP_SELF']; ?>','SQL_DATABASE','width=800,height=600,scrollbars=yes,resizable=yes');
		document.forms[0].target = 'SQL_DATABASE';
		document.forms[0].elements['result_window'].value = 'yes';
		setTimeout('reset_frame()',200);
	}
	
	function reset_frame()
	{
		document.forms[0].submit()
		
		document.forms[0].target = '_self';
		document.forms[0].elements['result_window'].value = '';
		document.forms[0].elements['table_name'].selectedIndex = 0;
		setTimeout('document.forms[0].submit()',200);
	}
	
	function insert_into_query(wert)
	{
	<?php 
	if(empty($result_window))
	{
	 ?>
		cont = parent.frames['sqlmain'].document.forms[0].elements['request'].value;
		cont = cont+' '+wert+' ';
		parent.frames['sqlmain'].document.forms[0].elements['request'].value = cont;
		parent.frames['sqlmain'].document.forms[0].elements['request'].focus();
	<?php 
	}
	 ?>
	}
	// -->
	</script>
<body class="blue">
<?php 
if(empty($result_window))
{
?>
<table width="<?php echo($width); ?>" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="457" align="left" valign="center" class="text">
			<img src="../../grafik/pixel.gif" width="457" height="4"><br>
			<img src="../../grafik/pixel.gif" width="4" height="1"><a href="#" class="text" onClick="javascript:if(top.main.document.getElementById('f_datenbank').rows=='190,*,24'){top.main.document.getElementById('f_datenbank').rows='190,0,*';}else{top.main.document.getElementById('f_datenbank').rows='190,*,24';}"><?php echo( $GLOBALS['LOCALE']->gettext('database') ); ?></a><br>
		</td>
		<td width="63" align="left" valign="top">
			<img src="../../grafik/updown.gif" width="63" height="21" border="0" usemap="#updown"><br>
			<map name="updown">
				<area shape="circle" coords="12,9,9" href="#" onClick="top.main.document.getElementById('f_datenbank').rows='190,0,*';">
				<area shape="circle" coords="50,9,9" href="#" onClick="top.main.document.getElementById('f_datenbank').rows='190,*,24';">
			</map>
		</td>
		<td width="455" align="right" valign="center" class="text">
			<img src="../../grafik/pixel.gif" width="455" height="4"><br>
			<a href="#" onClick="new_window();" class="link"><?php echo( $GLOBALS['LOCALE']->gettext('new_window') ); ?></a><br>
		</td>
	</tr>
</table>
<?php 
}
?>
<?php
	$result	= $sql_world->select('SELECT mn_name,mn_naid FROM mnames',0,0);

	$SCHEMA_NAMES	= array();
	foreach ($result as $index => $rs)
	{
		$result_elements = $sql_world->select("SELECT me_id,me_name,me_me_id FROM melements WHERE me_mn_naid = ".$rs['mn_naid']." AND me_multiple = 1",0,0);
		
		$SCHEMA_NAMES[ $rs['mn_naid'] ]['name'] = $rs['mn_name'];
		foreach($result_elements as $idx => $element)
		{
			$SCHEMA_NAMES[ $rs['mn_naid'] ][ $element['me_id'] ] = $element['me_name'];
		}
	}

?>
<table width="<?php echo($width); ?>" border="0" cellspacing="0" cellpadding="4">
	<form name="database" size="1" action="<?php echo $_SERVER['PHP_SELF']; ?>" target="_self">
	<input type="hidden" name="result_window" value="<?php if(!empty($result_window)) echo($result_window); ?>">
	<tr>
		<td width="<?php echo($width); ?>" align="center" valign="top" class="text">
			<br>
			<span class="head">
			<?php echo( $GLOBALS['LOCALE']->gettext('db_structure') ); ?><br>
			</span>
			<img src="../../grafik/pixel.gif" width="1" height="4"><br>
			<select name="table_name" size="1" class="select" onChange="this.form.submit();">
				<option></option>
				<?php 
				foreach($tables as $idx=>$wert)
				{
					$sel = '';
					if(!empty($table_name) && $table_name == $wert) $sel = ' selected';

					$match = array();
					$check = preg_match('/na_([0-9]+)(_([0-9]+))?/',$wert,$match);
					$text= $wert;
					if ($check && !empty($SCHEMA_NAMES[ $match[1]])) $text.=" [{$SCHEMA_NAMES[ $match[1]]['name']}";
					if ($check && !empty($match[3]))
					{
						$text.=" | {$SCHEMA_NAMES[ $match[1]][ $match[3] ]}";
					}
					if($check && !empty($SCHEMA_NAMES[ $match[1]])) $text.="]";

				?>
				<option value="<?php echo($wert); ?>"<?php echo($sel); ?>><?php echo($text); ?></option>
				<?php
				}
				?>
			</select><br>
			<img src="../../grafik/pixel.gif" width="1" height="12"><br>
<?php 
if(!empty($table))
{
?>
			<table border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td align="left" valign="center" class="dbhead1left">
						<nobr>&nbsp;<?php echo( $GLOBALS['LOCALE']->gettext('name') ); ?>&nbsp;</nobr><br>
					</td>
					<td align="left" valign="top" class="dbhead1right">
						<table width="100%" border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td align="left" valign="top" class="dbcellblack">
									<?php 
									$match = array();
									$text = $table['name'];
									$check = preg_match('/na_([0-9]+)(_([0-9]+))?/',$text,$match);
									if ($check && !empty($SCHEMA_NAMES[ $match[1]])) $text.=" [{$SCHEMA_NAMES[ $match[1]]['name']}";
									if ($check && !empty($match[3]))
									{
										$text.=" | {$SCHEMA_NAMES[ $match[1]][ $match[3] ]}";
									}
									if($check && !empty($SCHEMA_NAMES[ $match[1]])) $text.="]";
									$text = '<a href="javascript:insert_into_query(\''.$table['name'].'\')" class="dbcellblack">'.$text.'</a>';
									echo($text); 
									?><br>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td align="left" valign="center" class="dbhead2left">
						<nobr>&nbsp;<?php echo( $GLOBALS['LOCALE']->gettext('columns') ); ?>&nbsp;</nobr><br>
					</td>
					<td align="left" valign="top" class="dbhead2right">
						<table width="100%" border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('nr') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('name') ); ?><br>
								</td>
<?php 
	if(!empty($table_id))
	{
 ?>
								<td align="left" valign="top" class="dbcellwhite">
									NA <?php echo( $GLOBALS['LOCALE']->gettext('name') ); ?><br>
								</td>
<?php 
	}
 ?>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('type') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('length') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('null') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('default') ); ?><br>
								</td>
							</tr>
						<?php 
							$i=1;
							foreach($table['columns'] as $idx => $wert)
							{
								$a_href_pre = '<a href="javascript:insert_into_query(\''.$table['name'].'.'.$wert['name'].'\')" class="dbcellblack">';
								$a_href_post = '</a>';
						?>
							<tr>
								<td align="left" valign="top" class="dbcellblack" ><?php echo($i); ?><br></td>
								<td align="left" valign="top" class="dbcellblack" ><?php echo($a_href_pre.$wert['name'].$a_href_post); ?><br></td>
								<?php 
										if(!empty($table_id))
										{
											$na_name = '';
											if(substr($wert['name'],0,3) == 'na_')
											{
												$field_id 		= substr($wert['name'],3);
												$select_string 	= "SELECT me_name FROM melements WHERE me_id = ".$field_id." AND me_mn_naid = ".$table_id[0]." ";
												$temp 			= $sql_world->select($select_string,0,1,0);
												$na_name 		= $temp[0][0];
											}
								 ?>
									<td align="left" valign="top" class="dbcellblack" ><?php echo($a_href_pre.$na_name.$a_href_post); ?><br></td>
								<?php 
										}
								 ?>
								<td align="left" valign="top" class="dbcellblack" ><?php echo($wert['type']); ?><br></td>
								<td align="left" valign="top" class="dbcellblack" ><?php echo($wert['type_len']); ?><br></td>
								<td align="left" valign="top" class="dbcellblack" ><?php echo($wert['null']); ?><br></td>
								<td align="left" valign="top" class="dbcellblack" ><?php echo($wert['default']); ?><br></td>
							</tr>
						<?php
								$i++;
							}
						?>
						</table>
					</td>
				</tr>
				<tr>
					<td align="left" valign="center" class="dbhead1left">
						<nobr>&nbsp;<?php echo( $GLOBALS['LOCALE']->gettext('prim_key') ); ?>&nbsp;</nobr><br>
					</td>
					<td align="left" valign="top" class="dbhead1right">
						<table width="100%" border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td align="left" valign="top" class="dbcellblack">
									<?php echo($table['primary']); ?><br>
								</td>
							</tr>
						</table>
					</td>
				</tr>
<?php
	if(!empty($table['index']))
	{
?>
				<tr>
					<td align="left" valign="center" class="dbhead2left">
						<nobr>&nbsp;<?php echo( $GLOBALS['LOCALE']->gettext('indexes') ); ?>&nbsp;</nobr><br>
					</td>
					<td align="left" valign="top" class="dbhead2right">
						<table width="100%" border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('nr') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('name') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('columns') ); ?><br>
								</td>
							</tr>
<?php 
		$i=1;
		foreach($table['index'] as $idx => $wert)
		{
?>
								<tr>
									<td align="left" valign="top" class="dbcellblack"><?php echo($i); ?><br></td>
									<td align="left" valign="top" class="dbcellblack"><?php echo($wert['name']); ?><br></td>
									<td align="left" valign="top" class="dbcellblack"><?php echo($wert['columns']); ?><br></td>
								</tr>
<?php
			$i++;
		}
?>
						</table>
					</td>
				</tr>
<?php
	}

	if(!empty($table['unique']))
	{
?>
				<tr>
					<td align="left" valign="center" class="dbhead1left">
						<nobr>&nbsp;<?php echo( $GLOBALS['LOCALE']->gettext('uniques') ); ?>&nbsp;</nobr><br>
					</td>
					<td align="left" valign="top" class="dbhead1right">
						<table width="100%" border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('nr') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('name') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('columns') ); ?><br>
								</td>
							</tr>
<?php
		$i=1;
		foreach($table['unique'] as $idx => $wert)
		{
?>
								<tr>
									<td align="left" valign="top" class="dbcellblack"><?php echo($i); ?><br></td>
									<td align="left" valign="top" class="dbcellblack"><?php echo($wert['name']); ?><br></td>
									<td align="left" valign="top" class="dbcellblack"><?php echo($wert['columns']); ?><br></td>
								</tr>
<?php
			$i++;
		}
?>
						</table>
					</td>
				</tr>
<?php
	}

	if(!empty($table['fkey']))
	{

		$cascade = array( '-','X');
?>
				<tr>
					<td align="left" valign="center" class="dbhead1left">
						<nobr>&nbsp;<?php echo( $GLOBALS['LOCALE']->gettext('f_keys') ); ?>&nbsp;</nobr><br>
					</td>
					<td align="left" valign="top" class="dbhead1right">
						<table width="100%" border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('nr') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('name') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('column') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('f_table') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('f_column') ); ?><br>
								</td>
								<td align="left" valign="top" class="dbcellwhite">
									<?php echo( $GLOBALS['LOCALE']->gettext('del_cascade') ); ?><br>
								</td>
							</tr>
<?php
		$i=1;
		foreach($table['fkey'] as $idx => $wert)
		{
?>
								<tr>
									<td align="left" valign="top" class="dbcellblack"><?php echo($i); ?></td>
									<td align="left" valign="top" class="dbcellblack"><?php echo($wert['name']); ?></td>
									<td align="left" valign="top" class="dbcellblack"><?php echo($wert['column']); ?></td>
									<td align="left" valign="top" class="dbcellblack"><?php echo($wert['ref_tab']); ?></td>
									<td align="left" valign="top" class="dbcellblack"><?php echo($wert['ref_col']); ?></td>
									<td align="left" valign="top" class="dbcellblack"><?php echo($cascade[ $wert['ref_del'] ]); ?></td>
								</tr>
<?php
			$i++;
		}
?>
						</table>
					</td>
				</tr>
<?php
	}
?>
			</table>
<?php 
}
?>
		</td>
	</tr>
	<tr>
		<td width="<?php echo($width); ?>"><img src="../../grafik/pixel.gif" width="<?php echo($width); ?>" height="1"><br></td>
	</tr>
</table>
		<br>
		</form>
	</body>
</html>
Return current item: Netautor Professional