

<?php





$todaytms=time();

$namefilezip=$idtrf.'-'.$todaytms.".zip";

$namefilezippath="uploaddocuments/zip/".$idtrf.'-'.$todaytms.".zip";

$zipnamefile=$namefilezip;

// change path ... name for link on pdf with website address

$namefilezippathpdf=$linkglobal."public/uploaddocuments/zip/".$idtrf.'-'.$todaytms.".zip";



$documentlist = new WA_MySQLi_RS("documentlist",$cmctrfdb,0);

$documentlist->setQuery("SELECT * FROM fileattached WHERE fileattached.idtrfdetails='$idtrf'");

$documentlist->execute();



$photolist = new WA_MySQLi_RS("photolist",$cmctrfdb,0);

$photolist->setQuery("SELECT * FROM `trf-details` WHERE `trf-details`.idtrfdetails='$idtrf'");

$photolist->execute();



$zip = new ZipArchive;



if ($zip->open($namefilezippath, ZipArchive::CREATE) === TRUE)

{



if (!empty($documentlist->getColumnVal("idfileattached"))) {





    // Add files to the zip file

	$wa_startindex = 0;

while(!$documentlist->atEnd()) {

 $wa_startindex = $documentlist->Index;

	



	$newdocname=$documentlist->getColumnVal("filename_fileattached");

$pathnewdocname="uploaddocuments/".$newdocname;



$zip->addFile($pathnewdocname, $newdocname);

  

    

 

   $documentlist->moveNext();

}

$documentlist->moveFirst(); //return RS to first record

unset($wa_startindex);

unset($wa_repeatcount);

}

 //  add photos to zip

 if (!empty($photolist->getColumnVal("photofilename"))) {

 $newdocname=$photolist->getColumnVal("photofilename");

$pathnewdocname="uploadimages/".$newdocname;



$zip->addFile($pathnewdocname, $newdocname);

}

 if (!empty($photolist->getColumnVal("photoone"))) {

 $newdocname=$photolist->getColumnVal("photoone");

$pathnewdocname="uploaddocuments/".$newdocname;



$zip->addFile($pathnewdocname, $newdocname);

}

 if (!empty($photolist->getColumnVal("phototwo"))) {

 $newdocname=$photolist->getColumnVal("phototwo");

$pathnewdocname="uploaddocuments/".$newdocname;



$zip->addFile($pathnewdocname, $newdocname);

}



    

    // All files are added, so close the zip file.

    $zip->close();



}

?>