<?php
include("common_db.php");
include("functions.php");
dbconnect($host, $username, $password); //from common_db.php
$strings = loadStrings($lang, 'REPORT1');
if(isset($_REQUEST['report_id'])) {
//the user has jumped back here
$report_id = intval($_REQUEST['report_id']);
} else {
//new report, so we create new data
$query = "INSERT INTO reports(temp) VALUES (1)";
mysql_select_db('HypatiaDB');
mysql_query($query) or die(sprintf($_strings['R1_ERR_NEWRPTFAILED'], mysql_error()));
$report_id = mysql_insert_id();
}
mysql_select_db('HypatiaDB');
//Now we need to get the data back out of the database
$report_details = mysql_fetch_array(mysql_query("SELECT * FROM reports WHERE id = '$report_id'"));
//And the tables associated with this
$report_tables = mysql_query("SELECT DISTINCT tbl FROM report_fields WHERE report = '$report_id'");
headers();
html();
head($strings['R1_TITLE'], array('xhr/create-xhr.php?target=\'xhr/get-report-tl.php?db=\'%2Br1db&caller=getTables&tid=tbls&tfunc=clearElem(\'tbls\');'));
menu();
navpane();
?>
<div id="mainpane">
<?php getReportSteps(1, $report_id); echo($strings['R1_INTRO']); ?>
<form action="report2.php" method="post" class="standalone lblock">
<label for="db"><?php echo($strings['R1_DATABASE']); ?><select name="db" onchange="r1db = this.value; getTables();">
<option selected="selected">Choose a database</option>
<?php
echo(listDbs('<option value="%1$s">%1$s</option>', $report_details['db'], '<option value="%1$s" selected="selected">%1$s</option>')); ?>
</select></label><label for="table"><?php echo($strings['R1_TABLE']); ?><span id="tbls">
<?php
//TODO: add a Javascript prompt, warning the user that changing the db or table
//will nuke stored conditions, sorts, fields, et cetera
//print a warning indicating that changing this will remove any fields, conditions or sort that
//are reliant on a specific table in the database
if(!is_null($report_details['db'])) {
if(mysql_num_rows($report_tables) != 0) {
echo("<p class=\"alert\">$strings[R1_TABLEWARNING]</p>");
//there are some existing tables that we need to select for the user
while($r = mysql_fetch_array($report_tables)) {
$selected_tables[] = $r['tbl'];
}
}
echo('<select name="tables[]" rows="10"' /* multiple="multiple"*/ . '>');
mysql_select_db($report_details['db']);
$tables = mysql_query("SHOW TABLES");
while($table = mysql_fetch_array($tables)) {
echo('<option' . (in_array($table[0], $selected_tables) ? ' selected="selected"' : '' ) . " value=\"$table[0]\">$table[0]</option>");
}
echo('</select>');
}
echo('</span></label>');
echo('<input type="hidden" name="report_id" value="' . $report_id . '" />');
?>
<input value="Next Page" type="submit" />
</form>
</div>
<?php
endhtml();
?>