<?php
// copy template files to new instrument
header("Content-Type: text/plain");



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

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

 $instruments_dir=$dsvydir.'instruments/';

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

 $aname=extractRequestVar('NAME','','No NAME in copyTemplates');

 $baseDir=$instruments_dir.$aname  ; /* root directory of this instrument */

 $a1=extractRequestVar('TODIR','','No  TODIR in copyTemplates');

 $toDir=$baseDir.$a1 ;
 $a2=extractRequestVar('FROMDIR','','No  FROMDIR in copyTemplates');
 $fromDir=$dsvydir2.$a2;
 $filelist=extractRequestVar('FILELIST','','No  FILELIST in copyTemplates');

$f12=explode(',',$filelist);
$icopied=0;
for ($i=0 ; $i<count($f12) ; $i++) {
     $afile=trim($f12[$i]);
     if ($afile=='')   continue ;
     $f12b=explode('=',$afile);
     $afile1=$f12b[0];  $afile2=$afile1;
     if (count($f12b)>1) $afile2=$f12b[1];

      $fromF=$fromDir . $afile1 ;
      $toF=$toDir . $afile2 ;
//      print $baseDir . ' and ' . $dsvydir2 . '== ' . $fromF . ' and ' . $toF;
//      return 0;
      if (copy($fromF,$toF)) {
         $icopied++ ;
      } else {
          print "Unable to copy $fromF to $toF ";
          return 0;
      }
  }

  print "Ok. Success copying $icopied files: $filelist " ;
  return 0;
?>