<?php
// return a space delimited string containing names of  scenario list files, for an instrument or a session    (9011)

require("phpVars.php");


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

  }

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

if ($sessName=='' && $instName=='') {
    print 'Error: you did not specify a SESSION or an INSTRUMENT ';
    return 0;
}
if ($instName!='') {                                // get from instruments
    $adir=$instruments_dir . $instName . '/'  ;
} else {
    $adir=$sessions_dir . $sessName . '/'  ;
}
if (!file_exists($adir)) {
   print 'No such directory: ' . $adir ;
   return 0;
}

$dlist='';

$idir=opendir($adir);
while (!($filename= readdir($idir)) === FALSE) {
  if (is_file($adir . $filename)) {
    $af=strtoupper($filename);
    if (substr($af,0,3) =='SL_' && (strPos($af,'.XML')!==false) ) {
        $dlist=$dlist . $filename . ' ' ;
    }
  }
}
closedir($idir);

//header("Content-Type: text/plain");
print $dlist ;
?>