Location: PHPKode > projects > HypatiaDB > hypatiadb/xhr/addReportSort.php
<?php
include('../common_db.php');
include('../functions.php');
dbconnect($host, $username, $password);

$strings = loadStrings($lang,'REPORT4');
header("Content-Type: application/xml");

echo('<');?>?xml version="1.0" encoding="UTF-8"?>
<li xmlns="http://www.w3.org/1999/xhtml" id="sort<?php
$report_id = intval($_REQUEST['rid']);
$field = intval($_REQUEST['field']);
$type = $_REQUEST['type'];
if($type != 'desc')
	$type = 'asc';

//get the next priority
//Note that priority flows in a descending order,
//so "1" is the highest priority
$query = "SELECT MAX(priority) FROM report_sorts WHERE report = '$report_id'";
$mp = mysql_fetch_row(mysql_query($query));
if(is_null($mp[0])) {
	$priority = 1;
} else {
	$priority = $mp[0] + 1;
}

//report, field, type, priority
$query = "INSERT INTO report_sorts(report, field, type, priority) VALUES ('$report_id', '$field', '$type', '$priority')";
mysql_query($query) or print(mysql_error . $query);	//TODO:L10N
$id = mysql_insert_id();
echo($id . '">');	//root element

//we also need to pull down the database and table that the
//lvalue references
$query = "SELECT tbl, col FROM report_fields WHERE id = '$field'";

$field_fr = mysql_fetch_array(mysql_query($query));

printf($strings['R4_SORTLI'], "$field_fr[tbl].$field_fr[col]", $type == 'asc' ? $strings['R4_ASC'] : $strings['R4_DESC']);

echo("[<span class=\"ll\" onclick=\"removeSort($id);\">$strings[R4_REMOVESORT]</span>]");

?></li>
Return current item: HypatiaDB