<?php include("../../operainfo/getq2.php");
// Checked for PHP5.6 / 8.x compatibility
$usersecurity=getusersecurity();

$stkref=safetext2(isset($_GET['stkref']) ? $_GET['stkref'] : '');
$pricelist=safetext2(isset($_GET['pricelist']) ? $_GET['pricelist'] : '');
$hostcompanyid=safetext2(isset($_GET['hostcompanyid']) ? $_GET['hostcompanyid'] : '');

$sql = "SELECT * FROM specialprices_types WHERE code = ? AND hostcompanyid = ?";
$stmt = pdoquery($sql, array($pricelist, $hostcompanyid));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
    $nameis = $row['description'];
}

if ($usersecurity>7) {
	print "<button><a href=\"../iso_documents/adddoc.php$x&desc=$nameis Price List&type=PRICE&pricelist=$pricelist&hostcompanyid=$hostcompanyid\">ADD New <br>$nameis</a><br>Pricelist</button>";
}

print "<div class=\"sectionbreak\">Available $nameis Pricelists Linked to $stkref</div>";

print "<table class=CSSTable_n2><tr><td width=5%>ID</td><td width=50%>Document Name</td><td>Updated</td><td>Expiry Date</td><td>Notes</td></tr>";
$sql = "SELECT
ISO_quality_manual_files.documentexplain ,
ISO_quality_manual_files.docid,ISO_quality_manual_files.description ,
ISO_quality_manual_files.exp_date ,
ISO_quality_manual_files.addedon ,
ISO_quality_manual_files.hostcompany, ISO_quality_manual_files.pricelistcode
FROM ISO_quality_manual_files , ISO_quality_manual_stock_links WHERE
ISO_quality_manual_files.archived='' and ISO_quality_manual_files.type='PRICE'
AND ISO_quality_manual_files.docid=ISO_quality_manual_stock_links.docid AND
ISO_quality_manual_files.pricelistcode=? AND
ISO_quality_manual_stock_links.stock_ref=?

";
$stmt = pdoquery($sql, array($pricelist, $stkref));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
    $docid = $row['docid'];
    $hostcompanyid = $row['hostcompany'];
    $pricelistcode = $row['pricelistcode'];
    $pricelistpdflink = $hostcompanyid . "Z" . $pricelistcode;
    $haspricelist[$pricelistpdflink] = 1;
    if ($row['exp_date'] > 0) {
        $expdate = date("d M Y", $row['exp_date']);
    } else {
        $expdate = "Not Set";
    }

    if ($row['exp_date'] < $nowis && $row['exp_date'] > 0) {
        $expdate = "<font color=red><b>$expdate</b></font>";
    }

    if ($row['addedon'] > 0) {
        $addedon = date("d M Y", $row['addedon']);
    } else {
        $addedon = "Not Set";
    }
    print "<tr><td>$docid</td><td>" . linkdocid($x, $docid) . $row['description'] . "</td><td>$addedon</td><td>$expdate</td><td>" . $row['documentexplain'] . "</td></tr>";

}
print "</table><br><br>";


?>
