<?php
//    return user status info (from clientstatus database)
//       name=sessname
//  Example of return:
//nowTime=1298793191000
//id=511 &  servertime=1298778044 &  time=12:33 &  state=Ask2 &  message=I ask more &  var=xxx &  value=6
//id=5311 &  servertime=1298778097 &  time=12:33 &  state=Ask2 &  message=I ask me &  var=zready &  value=zz71


require("phpVars.php");

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

 header("Content-Type: text/plain");

if ($sessName=='') {
  print '- ERROR: No SESSION=  in call to   readServerVar.php ';
  exit ;
}

$idate =time();

$link=mysql_connect('localhost','dsurveyAdmin','admin');
if (!$link) {
   print ' - Error. Could not connect to mysql (with username=`dsurveyAdmin` and password=`admin`): ' . mysql_error();
   exit ;
}

$mdata=$hdrMysql . $sessName ;
$qq=mysql_select_db($mdata, $link);
if (!$qq) {
   print '- Error. Unable to select mysql database ' . $mdata . ': '  . mysql_error();
   mysql_close($link);
  return 0;
}

 $sql="SELECT * FROM  clientstatus " ;

 $qq=mysql_query($sql,$link);
 if (!$qq) {
     print '- Error. Unable to read status info ' .$cvar . ' in STATUSVARS  table in mysql database ' . $mdata . ': '  . mysql_error();
      mysql_close($link);
     return 0;
 }
  $stuff='nowTime=' . $idate . '000  ';
  print "$stuff
";
  while($row = mysql_fetch_array($qq)) {
     if ($row['clientid']=='_created') continue ;
     $aline="id=" . $row['clientid'] . ' &  ';
     $aline .="servertime=" . $row['servertime'] . ' &  ';
     $aline .="time=" . $row['clienttime'] . ' &  ';
     $aline .="state=" . $row['state'] . ' &  ';
     $aline .="message=" . $row['message'] . ' &  ';
     $aline .="var=" . $row['varname'] . ' &  ';
     $aline .="value=" . $row['varvalue'] ;
     print "$aline
";
//     $stuff=$stuff . $aline . ' \n ';
  }

// clientstatus (clientid,servertime,clienttime,state,message,varname,varvalue)

 mysql_close($link);
 exit;


?>

