<?php $_REQUEST['src']='ext'; require_once('global.php'); require_once('../includes/master/form_functions.php');
//GET WS DETAILS

$wsno="WS".$_REQUEST['wsnumber'];
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `writtenscheme` WHERE `id`=?")or die(mysqli_error($e="GET WS ENTRY: ".$GLOBALS['con']));
$stmt->bind_param('i',$_REQUEST['wsnumber']);$stmt->execute();$ws=$stmt->get_result();$stmt->close();
$wsd=mysqli_fetch_array($ws);

//GET CLIENT DETAILS
$stmt = $GLOBALS['con']->prepare("SELECT `clientnumber`,`clientname`,`address1`,`address2`,`town`,`county`,`postcode`,`contract_number` FROM `clientdetails` WHERE `clientnumber`='".$wsd['clientnumber']."' ")or die(mysqli_error("GET WS CLIENT: ".$GLOBALS['con']));
$stmt->execute();$cc=$stmt->get_result();$stmt->close();
$cd=mysqli_fetch_array($cc);

//CHECK DIR AND POPULATE
if(!file_exists('../output/wsfiles/'.$_REQUEST['clientnumber'])){
mkdir('../output/wsfiles/'.$_REQUEST['clientnumber']);	
}

function getWsSurveyorDetails($surveyor,$type){
$stmt2 = $GLOBALS['con']->prepare("SELECT `surname`,`forename`,`qual` FROM `surveyor` WHERE `id`=?")or die(mysqli_error("getSurveyorDetails: ".$GLOBALS['con']));
$stmt2->bind_param('i',$surveyor);$stmt2->execute();$sc=$stmt2->get_result();$stmt2->close();	
$sd=mysqli_fetch_array($sc);
switch($type){	
case"SURVEYOR_NAME":return $sd['forename']." ".$sd['surname'];break;
case"SURVEYOR_QUAL":return $sd['qual'];break;
case"SURVEYOR_SIGNITURE":return $surveyor;break;
}
}

//BUILD REVISION LIST
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `wsrevisions` WHERE `wsnumber`=? ORDER BY ABS(date) DESC")or die(mysqli_error($e="GET WSE ENTRY: ".$GLOBALS['con']));
$stmt->bind_param('i',$_REQUEST['wsnumber']);$stmt->execute();$wsi=$stmt->get_result();$stmt->close();
while($wsid=mysqli_fetch_array($wsi)){
$revList.='
<tr valign="top">
<td>'.date('d-m-Y',$wsid['date']).' </td>
<td>'.$wsid['description'].'</td>
<td><img src="../images/signatures/'.$wsid['surveyor'].'.jpg" style="width:120px; margin: 0; padding: 0;" /></td>
</tr>
';

}
if(!is_dir('../output/wsfiles/'.$_REQUEST['clientnumber'])){mkdir('../output/wsfiles/'.$_REQUEST['clientnumber']);}

$filestore='../output/wsfiles/'.$_REQUEST['clientnumber'].'/'.$wsno.'_revisions.pdf';
include('../includes/engines/ews.pdf.engine');	
?>