<?php

namespace Anax\View;

$imgPrefix = $_SERVER["SERVER_NAME"] == "www.student.bth.se" ? "/~rasb14/dbwebb-kurser/oophp/me/kmom10/proj/htdocs/image/" : "/image/";
$urlPrefix = $_SERVER["SERVER_NAME"] == "www.student.bth.se" ? "/~rasb14/dbwebb-kurser/oophp/me/kmom10/proj/htdocs/" : "";

if (!$resultset) {
    return;
}

$id = -1;
?>
<table>
    <?php foreach ($resultset as $row) : $id++ ?>
    <?php $imgSuffix = substr($row->image, -4) === '.gif' ? '': '?w=200'; ?>
    <tr>
        <td><img src="<?= $imgPrefix . $row->image . $imgSuffix ?>" alt="<?= $row->image ?>"></td>
        <td><a href="<?= $urlPrefix ?>product?id=<?= $row->id ?>"><?= $row->title ?></a></td>
        <td><?= $row->cost > 0 ? $row->cost : "Free" ?></td>
        <?php if ($isAdmin) : ?>
        <td>
            <a href="<?= $urlPrefix ?>product/edit?id=<?= $row->id ?>"><i class="fas fa-edit"></i></a>
            <a href="<?= $urlPrefix ?>product/delete?id=<?= $row->id ?>"><i class="fas fa-trash-alt"></i></a>
        </td>
        <?php endif; ?>
    </tr>
    <?php endforeach; ?>
</table>
