<?php
// save instrument descriptot file
header("Content-Type: text/plain");

require("../phpVars.php");

 $svydir='';
 $rootdir=$_SERVER['DOCUMENT_ROOT'];
 $dsvydir=$rootdir.'dSurvey/';
 $instruments_dir=$dsvydir.'instruments/';

 $break = Explode('/',$_SERVER['SCRIPT_NAME']);
 $myScriptName = $break[count($break) - 1];

 $aname=extractRequestVar('FILE','','No FILE ins saveDesc');

 $lchar=substr($instruments_dir,strlen($instruments_dir)-1,1);
 if ($lchar=='/') {
  $newfile=$instruments_dir.$aname;
 } else {
   $newfile=$instruments_dir.'/'.$aname;
 }

 $overwrite=extractRequestVar('OVERWRITEFILE','0','');
 if ($overwrite!=='1') {
     if (file_exists($newfile)) {
       print "Sorry. $newfile already exists ";
       return 0;
  }
 }
 $content=extractRequestVar('CONTENT','0','');

 $fnum=fopen($newfile,'w');
 if (!$fnum) {
     print "- Error Unable to open (for writing) file: $newfile ";
     return 0 ;
  }
  if (!fwrite($fnum,$content)) {
       print "- Error  Unable to write to file: $newfile ";
       return 0 ;
  }
  print 'ok. File created: ' . $newfile ;
  fclose($fnum);
  return 0 ;


?>