<?php

    require("../authenticate.php");
    require("../pagecomponents.php");

    check_auth();

    $tableName = getuserdata('tableName', 0);
    $keyField = getuserdata('keyField', 0);
    $keyValue = getuserdata('keyValue', 0);
    $valueField = getuserdata('valueField', 0);
    
    $errorMessage = "";

    header('Content-Type: text/xml');
    echo "<?xml version=\"1.0\" ?>\n<fields>";
    
    $q = mysql_query("SELECT $keyField, $valueField FROM $tableName ORDER BY $valueField ASC");
    while ($r = mysql_fetch_assoc($q))
    {
        echo "\n\t<field key=\"".$r[$keyField]."\" value=\"".$r[$valueField]."\"";
        if ($r["$keyField"] == $keyValue) echo ' selected="1"/>';
                                     else echo ' selected="0"/>';
    }
    
    echo "\n</fields>";
?>