<?php
//    return submitted data (entry field
//    Or if todo=405, return the messages (comment field)
//  clientid varchar(40) NOT NULL ,    -- from client
//  round int(4) not null ,            -- from client
//     PRIMARY KEY (clientid,round)  ,
//  servertime int,                  -- COMPUTED by server upon reciept of submitted data
//  clienttime varchar(40) ,         -- from client
//  notFinal int(2),                  -- from client
//  ct int(2),                       -- from client
//  entry text,                      -- from client
//  comment tinytext         -- from client


require("phpVars.php");

  $sessName='';
  $atodo='';
  foreach ($_REQUEST as $vname=>$oof) {
     $avar=trim(strtoupper($vname)) ;
     if ($avar=='NAME' || $avar=='SESSION') $sessName=trim($oof);
     if ($avar=='TODO'  ) $atodo=trim($oof);
  }


if ($sessName=='') {
  header('Content-type:text/plain');
  print '- Error. No NAME or SESSION= in call to   getSubmitted.php ';
  exit ;
}


$link=connectDsurveyDatabase($sessName);
$mdata=$currentDatabase ;

 $sql="SELECT * FROM submitted  WHERE clientid != '_created' " ;

 $qq=mysql_query($sql,$link);
 if (!$qq) {
      header('Content-type:text/plain');
     print '- Error. Unable to read server variable ' .$cvar . ' in STATUSVARS  table in mysql database ' . $mdata . ': '  . mysql_error();
      mysql_close($link);
     return 0;
 }

 if ($atodo=='405') {
     header('Content-Type: text/plain charset=iso-8859-1');
     $stuff='';
 } else {
      header('Content-type:text/xml');
      $stuff='<?xml version="1.0" encoding="UTF-8" ?>' . " \n";
      $stuff=$stuff . "<submittedData> \n";
 }

 while($row = mysql_fetch_array($qq)) {
       if ($atodo=='405') {
          $aline=$row['comment'];
       } else {
          $aline=$row['entry'];                 // 'entry' contains origional submission, which was an "xml-line"
       }
       $stuff=$stuff . "$aline \n";
 }
  if ($atodo!='405') $stuff=$stuff . "</submittedData> \n";

  mysql_close($link);


 print $stuff;
 exit ;
 ?>

