<?php
include("common_db.php");
include("functions.php");
if(isset($_REQUEST['report_id'])) {
$report_id = intval($_REQUEST['report_id']);
} else {
//TODO: panic
die('panic!!!');
}
dbconnect($host, $username, $password); //from common_db.php
mysql_select_db('HypatiaDB');
($repqry = mysql_query("SELECT * FROM reports WHERE id = '$report_id'")) or die(mysql_error()); //TODO: L10N
$report_details = mysql_fetch_array($repqry);
//Thankfully, there is no data to be accepted from the previos form,
//as that's all handled by in situ Javascript.
$strings = loadStrings($lang, 'REPORT4');
headers();
html();
head($strings['R4_TITLE'], array('js/rep4.php?rid=' . $report_id));
menu();
navpane();
?>
<div id="mainpane">
<?php getReportSteps(4, $report_id);
//We can echo out all the selected fields and give the user a choice of an ascending sort, a
//descending sort or no sort at all. We use the uds from the report_fields database.
echo($strings['R4_INTRO']);
$query = "SELECT tbl,col,id FROM report_fields WHERE report = '$report_id'"; //get the valid fields for sorting
$sortable_fields = mysql_query($query);
$query = "SELECT field FROM report_sorts WHERE report = '$report_id'"; //get the fields that have already been
$sorted_fields = mysql_query($query); //sorted so that the user can't sort
//them twice
while($f = mysql_fetch_array($sorted_fields)) {
$sf[] = $f[0];
}
echo('<form>
<select name="sort_field" id="sort_field">');
while($f = mysql_fetch_array($sortable_fields)) {
if(!in_array($f['id'], $sf)) {
echo("<option value=\"$f[id]\">$f[tbl].$f[col]</option>");
}
}
echo(' </select>
<label for="type"><input type="radio" name="type" id="asort" value="asc" checked="checked" />' . $strings['R4_SORTASC'] . '</label>
<label for="type"><input type="radio" name="type" id="dsort" value="desc" />' . $strings['R4_SORTDESC'] . '</label>
<br /><span onclick="addSort();" class="ll">' . $strings['R4_ADDSORT'] . '</span>
</form>');
$query = "SELECT report_sorts.*, CONCAT(report_fields.tbl, '.', report_fields.col) AS fname FROM report_sorts, report_fields WHERE report_sorts.report = '$report_id' AND report_fields.id = report_sorts.field ORDER BY priority ASC";
($fields = mysql_query($query)) or die(mysql_error()); //TODO: L10N
echo('<h2>' . $strings['R4_SORTSHEADING'] . '</h2>');
echo('<ol id="sorts">');
while($sort = mysql_fetch_array($fields)) {
echo('<li id="sort' . $sort['id'] . '">' . sprintf($strings['R4_SORTLI'], $sort['fname'], $sort['type'] == 'asc' ? $strings['R4_ASC'] : $strings['R4_DESC']) . ' [<span class="ll" onclick="removeSort(' . $sort['id'] . ');">' . $strings['R4_REMOVESORT'] . '</span>]</li>');
}
echo('</ol><form action="report5.php" method="post"><input type="hidden" name="report_id" value="' . $report_id . '" />');
?>
<input type="submit" value="<?php echo($strings['R4_NEXTPAGE']); ?>" />
</form>
</div>
<?php
endhtml();
?>