<?php if(file_exists('../../../'.$_REQUEST['tenant'].'/config.php')){require_once('../../../'.$_REQUEST['tenant'].'/config.php');}
if(file_exists('/config.php')){require_once('/config.php');}
require_once('../../includes/master/form_functions.php');
$ite=explode("|",$_REQUEST['items']);
foreach($ite as $itemdata){
$col='';$tag='';
$item=explode('_',$itemdata);
$rc=mysqli_query($GLOBALS['con'],"SELECT * FROM `reportitems` WHERE `repnumber`='".$item[0]."' AND `itemnumber`='".$item[1]."' ")or die(mysqli_error());
$rd=mysqli_fetch_array($rc);

$ic=mysqli_query($GLOBALS['con'],"SELECT * FROM `itemdetails` WHERE `itemnumber`='".$item[1]."' ")or die(mysqli_error());
$id=mysqli_fetch_array($ic);
if($item[0]!=""){
$clientnumber=$rd['clientnumber'];
$details=getItemDetailed($item[0],$item[1]);
$det=explode("|",$details);

if($rd['result']=="DEFECTS" ){$col="#F4AA09";$tag="DEFECTS";$title="DEFECTS<br>".$dta['bdefect'];$file="file-exclamation";}
if($rd['result']=="URGENT" ){$col="#e96152";$tag="URGENT";$title="URGENT<br>".$adefect[0];$file="file-excel";}
if($rd['result']=="PASS" ){$col="#007E33";$tag="Pass"; $title="Pass";$file="file-powerpoint";}
if($rd['result']=="OBS" ){$col="#333333";$tag="Obs"; $title="OBS<br>".$dta['obs'];$file="file-alt";}
if($rd['result']=="PNA" ){$col="#cccccc";$tag="PNA"; $title="PNA";$file="file";}
if($rd['result']=="" ){$col="";$tag="P2UD"; $title="";$file="file";}
$ret.='
<tr>
<td align="center"><a class="btn-info" href="https://[REPORT_PATH]/preview.php?repnumber='.$item[0].'" alt="View full report online" title="View full report online">&nbsp;&nbsp;'.$item[1].'&nbsp;&nbsp;</a></td>
<td>'.$item[0].'</td>
<td>'.$det[0].'</td>
<td>'.getItemLocation($item[1],'name').'</td>
<td>'.$det[1].'</td>
<td>'.$det[2].'</td>
<td>'.$det[10].'</td>
<td>'.date('d-m-Y',$rd['insdate']).'</td>
<td>'.date('d-m-Y',$rd['nextDate']).'</td>
<td align="center" style="background-color:'.$col.'; color:#ffffff"><a style="text-decoration:none;color:#ffffff" href="https://[REPORT_PATH]/preview.php?repnumber='.$item[0].'" alt="View full report online" title="View full report online">'.$tag.'</a></td>
</tr>';
}

}

$postData='
<table id="repDetails" class="table-sm" width="100%">
<tbody>
<tr valign="top">
<td width="80%" valign="top"><h3>Report Summary - '.getClientName($clientnumber).'</h3></td>
<td width="20%" align="right" valign="top" style="font-family: serif; font-size: 8pt; color: #000000; font-weight: bold;">'.getClientAddress($clientnumber).'</td>
</tr>
</tbody>
</table>';

$pdf='<table id="coverDetails" class="table-sm" width="100%">
<thead><tr><th>Item No</th><th>Report No</th><th>Description</th><th>Location</th><th>Plant No</th><th>Serial No</th><th>SWL</th><th>Last Inspection</th><th>Next Inspection</th><th>Status</th></tr></thead>
<tbody>
'.$ret.'
</tbody>
</table>';
$orientation="L";
$default_header="";
$default_footer="";
$generic="yes";
$filestore='../output/wsfiles/'.$_REQUEST['clientnumber'].'/WS'.$_REQUEST['wsnumber'].'_reportcover.pdf';

include('../includes/engines/ext.pdf.engine');
echo $postData;
exit();
?>