<?php if(file_exists('../../../'.$_REQUEST['tenant'].'/config.php')){require_once('../../../'.$_REQUEST['tenant'].'/config.php');}
if(file_exists('/config.php')){require_once('/config.php');}

$files = glob('../output/reports/'.$_REQUEST['clientnumber'].'/*.zip');
foreach($files as $file){if(is_file($file))unlink($file);}

$path='../../../'.TENANT_URL.'/output/reports/'.$_REQUEST['clientnumber'].'/';
$path2='../../../'.TENANT_URL.'/output/wsfiles/'.$_REQUEST['clientnumber'].'/';
$arrays=explode('|',$_REQUEST['items']);
if($_REQUEST['mode']=="full" || $_REQUEST['mode']=="internal"){$theZip='WS'.$_REQUEST['wsnumber'].'_full.zip';}
if($_REQUEST['mode']=="single"){$theZip='WS'.$_REQUEST['wsnumber'].'_ws.zip';}
$zip = new ZipArchive;
if($zip->open($path2.$theZip, ZipArchive::CREATE) === TRUE){

$zip->addFile($path2."WS".$_REQUEST['wsnumber'].'.pdf',"WS".$_REQUEST['wsnumber'].'.pdf');

if($_REQUEST['mode']=="full" || $_REQUEST['mode']=="internal"){$zip->addFile($path2."WS".$_REQUEST['wsnumber'].'_reportcover.pdf',"WS".$_REQUEST['wsnumber'].'_reportcover.pdf');}

if($_REQUEST['mode']!="internal"){
$zip->addFile($path2."WS".$_REQUEST['wsnumber'].'_revisions.pdf',"WS".$_REQUEST['wsnumber'].'_revisions.pdf');
}

if($_REQUEST['mode']=="full" || $_REQUEST['mode']=="internal"){
foreach($arrays as $a){
$zip->addFile($path.$a.'.pdf',$a.'.pdf');
}
}
$zip->close();
echo $theZip;
}
else{echo "error";}


?>