<?php
# $Id: checks.php 86 2010-10-05 12:19:27Z rediculum $
#
# Includes
####################################################################
include "includes/session.inc.php";
include "includes/layout.inc.php";
include "includes/functions.inc.php";
include "includes/db.inc.php";
include "includes/variables.inc.php";
$status = "OK";
function statusOK($status)
{
require("includes/layout.inc.php");
if ($status == "OK")
{
echo "<tr><td><img src=\"images/ok.gif\"> All OK</td></tr>";
}
}
# Main
#####################################################################?>
<html>
<head>
<?php echo "$headtitle $head";?>
</head>
<body>
<div id=menu>
<?php include("includes/menu.inc.php");?>
</div>
<div id=mainframe>
<b> Content checks of entries in DB:</b><br>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>
<table bgcolor=#EEEEEE>
<tr><td> <u>Unknown maincategories in entries:</u></td></tr>
<?
$kats = mysql_query("SELECT DISTINCT hk_id,id FROM verbuchungen ORDER BY hk_id ASC");
while ($kat = mysql_fetch_array($kats))
{
$kat_verify = mysql_fetch_row(mysql_query("SELECT hk_id,hk_name FROM hauptkategorien WHERE hk_id='$kat[0]'"));
if ($kat_verify == "")
{
echo "<tr><td><img src=\"images/nok.gif\"> Entryno. <i>$kat[1]</i>: hk_id $kat[0] not known in database </td></tr>";
$status = "NOK";
}
}
statusOK($status);
$status = "OK";?>
</table><p>
<hr>
<table bgcolor=#EEEEEE>
<tr><td> <u>Unknown subcategories in entries:</u></td></tr>
<?php $kats = mysql_query("SELECT DISTINCT sk_id,id FROM verbuchungen ORDER BY sk_id ASC");
while ($kat = mysql_fetch_array($kats))
{
$kat_verify = mysql_fetch_row(mysql_query("SELECT sk_id,sk_name FROM subkategorien WHERE sk_id='$kat[0]'"));
if ($kat_verify == "")
{
echo "<tr><td><img src=\"images/nok.gif\"> Entryno. <i>$kat[1]</i>: sk_id $kat[0] not known in database </td></tr>";
$status = "NOK";
}
}
statusOK($status);
$status = "OK";?>
</table><p>
<hr>
<table bgcolor=#EEEEEE>
<tr><td> <u>Referential integrity from subcategory to maincategory in entries:</u></td></tr>
<?php $entries = mysql_query("SELECT id,hk_id,sk_id FROM verbuchungen ORDER BY id ASC");
while ($entry = mysql_fetch_array($entries))
{
$hk_f = mysql_fetch_row(mysql_query("SELECT hk_id,hk_name FROM hauptkategorien WHERE hk_id='$entry[1]'"));
$kat = mysql_fetch_row(mysql_query("SELECT sk_name,hk_id,sk_id FROM subkategorien WHERE sk_id='$entry[2]'"));
$hk_r= mysql_fetch_row(mysql_query("SELECT hk_id,hk_name FROM hauptkategorien WHERE hk_id='$kat[1]'"));
if ($entry[1] != $kat[1])
{
echo "<tr><td><img src=\"images/nok.gif\"> Entryno. <i>$entry[0]</i>: \"$hk_f[1]($hk_f[0])_$kat[0]\" is wrong. Correct: \"$hk_r[1]($hk_r[0])_$kat[0]\"</td></tr>";
$status = "NOK";
}
}
statusOK($status);
$status = "OK";?>
</table><p>
<hr>
<table bgcolor=#EEEEEE>
<tr><td> <u>Wrong date in entries:</u></td></tr>
<?php $entries = mysql_query("SELECT id FROM verbuchungen WHERE tag >'31'");
while ($entry = mysql_fetch_array($entries))
{
echo "<tr><td><img src=\"images/nok.gif\"> Entryno. <i>$entry[0]</i>: day over 31</td></tr>";
$status = "NOK";
}
$entries = mysql_query("SELECT id FROM verbuchungen WHERE monat >'12'");
while ($entry = mysql_fetch_array($entries))
{
echo "<tr><td><img src=\"images/nok.gif\"> Entryno. <i>$entry[0]</i>: month over 12</td></tr>";
$status = "NOK";
}
statusOK($status);
$status = "OK";?>
</table>
</td></tr>
</table>
<p>
<b> Content checks of categories in DB:</b><br>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>
<table bgcolor=#EEEEEE>
<tr><td> <u>Referential integrity from subcategory to maincategory in DB:</u></td></tr>
<?php $entries = mysql_query("SELECT sk_name,sk_id,hk_id FROM subkategorien ORDER BY sk_id ASC");
while ($entry = mysql_fetch_array($entries))
{
$hk_f = mysql_fetch_row(mysql_query("SELECT hk_name,hk_id FROM hauptkategorien WHERE hk_id='$entry[2]'"));
if ($hk_f[0] == NULL)
{
echo "<tr><td><img src=\"images/nok.gif\"> Category <i>$entry[0]</i> has an unknown reference </td></tr>";
$status = "NOK";
}
}
statusOK($status);
$status = "OK";
?>
</td></tr>
</table>
</td></tr>
</table>
<p>
Version: <?php echo $version;?>
<p>
<?php echo mysql_result(mysql_query("SELECT COUNT(*) FROM hauptkategorien"),0) ." Maincategories";?><br>
<?php echo mysql_result(mysql_query("SELECT COUNT(*) FROM subkategorien"),0) ." Subcategories";?><br>
<?php echo mysql_result(mysql_query("SELECT COUNT(*) FROM verbuchungen"),0) . " Entries";?>
<p>
<?php echo "Database Version: MySQL " . mysql_result(mysql_query("SELECT VERSION()"),0) ?>
<br>
<?php echo "Webserver Version: " . $_SERVER['SERVER_SOFTWARE'] ?>
</div>
</body>
</html>