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

if($_REQUEST['mode']=="split"){}
else{require_once('../../includes/master/form_functions.php');}
$ret='';
foreach($_REQUEST['items'] 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($GLOBALS['con']));
$rd=mysqli_fetch_array($rc);

$ic=mysqli_query($GLOBALS['con'],"SELECT * FROM `itemdetails` WHERE `itemnumber`='".$item[1]."' ")or die(mysqli_error($GLOBALS['con']));
$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['reptype']=="503" || $rd['reptype']=="518"){$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" target="_BLANK">'.$tag.'</a></td>
</tr>';
}

}

$postData='
';

$pdf='<table id="coverDetails" class="table-sm" width="100%">
<thead>
<tr><td colspan="10">
<table id="" class="table-sm" width="100%">
<tbody>
<tr valign="top">';
if(!empty($_REQUEST['site'])){
$pdf.='<td width="60%" 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>
<td width="20%" align="right" valign="top" style="font-family: serif; font-size: 8pt; color: #000000; font-weight: bold;">'.getFullLocation($_REQUEST['site']).'</td>
';}
else {
$pdf.='
<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>
';}
$pdf.='
</tr>
</tbody>
</table>
</td></tr>

<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";
$cover="yes";
if($_REQUEST['mode']=="split"){
$filestore='../../../'.TENANT_URL.'/output/reports/'.$_REQUEST['clientnumber'].'/report_cover_'.$name.'.pdf';
include('../../includes/engines/ext.pdf.engine');

}
else{
$filestore='../../../'.TENANT_URL.'/output/reports/'.$_REQUEST['clientnumber'].'/report_cover.pdf';
include('../../includes/engines/ext.pdf.engine');
echo $postData;
exit();
}

?>