<?php
include("common_db.php");
include("functions.php");
dbconnect($host, $username, $password);
$strings = loadStrings($lang, 'TPROPS');
headers();
html();
head($strings['TP_TITLE'], array('xhr/create-xhr.php?target=\'xhr/get-data.php?action=tl-ops\'%2BString.fromCharCode(38)%2B\'db=\'%2Bindb&caller=reloadTables&tid=tbl&tfunc=clearElem(\'tbl\');'));
menu();
navpane();
echo('<div id="mainpane">');
if(isset($_REQUEST['database'])) {
$db = $_REQUEST['database'];
} else {
if($_SESSION['current_db'] != '') {
$db = $_SESSION['current_db'];
} else {
//we don't know, so we reuse printRequestForm (same principle
//as documented in functions.php and the record viewer.)
printRequestForm('tblproperties.php');
}
}
if(isset($_REQUEST['table'])) {
$tbl = $_REQUEST['table'];
} else {
printRequestForm('tblproperties.php', $db);
}
mysql_select_db($db) or die("Couldn't select database $db");
if(isset($_REQUEST['newpri']) && ($_SESSION['session_user_status'] == 'admin' || $_SESSION['session_user_status'] == 'normal')) {
$newpri = mysql_escape_string($_REQUEST['newpri']);
$query = "ALTER TABLE `$tbl` DROP PRIMARY KEY";
mysql_query($query); //N.B.: This query may (depending on ver.) fail if there is no primary key
$query = "ALTER TABLE `$tbl` ADD PRIMARY KEY(`$newpri`)";
(mysql_query($query)) or ($error = sprintf($strings['TP_UNABLETOSETPRIMARY'], mysql_error()));
}
mysql_connect($host, $username, $password) or die("Couldn't connect to $host");
//Get the current users status
$user_status = get_currentuser_status();
$table_info_query = "DESCRIBE `$tbl`";
($result = mysql_query($table_info_query)) or die("$table_info_query query unsuccessful");
printf("<h2>$strings[TP_HEADING]</h2>", $tbl);
if(isset($error)) {
echo('<p class="error">' . $error . '</p>');
}
echo '<table class="browse">';
echo '<thead>';
echo '<tr align="center" class="firstrow">';
for($i=0; $i < mysql_num_fields($result); $i++) {
echo "<th>";
echo mysql_field_name($result, $i);
echo "</th>";
}
echo "</tr></thead><tbody>";
$banded = false;
while($row = mysql_fetch_array($result)) {
echo '<tr' . ($banded ? ' class="banded"' : '') . '>';
for($i=0; $i < mysql_num_fields($result); $i++) {
echo '<td>' . $row[$i];
if($i == 3 && $row[$i] != 'PRI' && ($_SESSION['session_user_status'] == 'admin' || $_SESSION['session_user_status'] == 'normal')) {
// the key
echo('<a href="tblproperties.php?database=' . htmlspecialchars($db, ENT_QUOTES) . '&table=' . htmlspecialchars($tbl, ENT_QUOTES) . '&newpri=' . htmlspecialchars($row['Field'], ENT_QUOTES) . '">' . $strings['TP_MAKEPRIMARY'] . '</a>');
}
echo "</td>";
}
echo "</tr>";
$banded = !$banded;
}
echo "</tbody></table>";
//Other details (from SHOW TABLE STATUS)
$query = "SHOW TABLE STATUS LIKE '$tbl'";
($result = mysql_fetch_array(mysql_query($query))) or die("err!");
echo<<<TS
<dl>
<dt>$strings[TP_NUMRECS]</dt>
<dd>$result[Rows]</dd>
<dt>$strings[TP_ROWLEN]</dt>
<dd>$result[Avg_row_length]</dd>
<dt>$strings[TP_DISCSPACE]</dt>
<dd>
TS;
printf($strings['TP_DTSPACE'],$result['Data_length']);
echo<<<TS
</dd> <dt>$strings[TP_CREATED]</dt>
<dd>$result[Create_time]</dd>
<dt>$strings[TP_UPDATE]</dt>
<dd>$result[Update_time]</dd>
</dl>
TS;
echo('</div>');
endhtml();
?>