<?php
// Return an XML file containing the clientid database (the contents uploaded by each client)

require("phpVars.php");


$sessName=extractRequestVar('NAME SESSION','',' - Error. No NAME or SESSSION in getUserList') ;
$sessName=trim($sessName);

// does this session exist?
checkXmlExists($sessName,$sessions_dir,"- Error. No such session: $sessName (getUserList) ");


// === connect to mysql databases
$link=connectDsurveyDatabase($sessName);
$mdata=$currentDatabase ;

 $sql="SELECT content FROM clientids WHERE clientid LIKE '_created'" ;
 $qq=mysql_query($sql,$link);
 if (!$qq) {
     header("Content-Type: text/plain");
     print '- Error. Unable to read clientId (_created) from clientids  table in mysql database ' . $mdata . ': '  . mysql_error();
     mysql_close($link);
     return 0;
 }
 $row = mysql_fetch_array($qq);
 $created=$row['content'];

 $sql="SELECT content FROM clientids WHERE clientid  NOT LIKE '_created'" ;
 $qq=mysql_query($sql,$link);
 if (!$qq) {
     header("Content-Type: text/plain");
     print '- Error. Unable to read clientId data from  clientids   table in mysql database ' . $mdata . ': '  . mysql_error();
     mysql_close($link);
     return 0;
 }

 // read current value of users
 $stuff='<?xml version="1.0" encoding="UTF-8" ?>
<users>
<session value="' . $sessName . '" />
<created>' . $created . ' </created>
';

 while($row = mysql_fetch_array($qq)) {
       $cvar=$row['content'];
       $stuff=$stuff . $cvar . "\n ";
 }

$stuff=$stuff . "\n</users>\n";

header("Content-Type: text/xml");
print $stuff ;
exit ;



?>