<!DOCTYPE html>
<html lang="ro-RO">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
    <title>Manager Cotatii - Anunturi mica publicitate - Anuțuri presa scrisă - Rofusion Advertising Srl</title>
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <link href="/css/materialize.css" type="text/css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link href="/css/kalendae.css" type="text/css" rel="stylesheet">
    <link href="/css/styleadd.css" type="text/css" rel="stylesheet">
</head>
<body id="top" class="scrollspy">
<div id="loader-wrapper">
    <div id="loader"></div>
    <div class="loader-section section-left"></div>
    <div class="loader-section section-right"></div>
</div>
<div class="navbar-fixed">
    <nav role="navigation">
        <div class="container">
            <div class="nav-wrapper">
                <a href="/" class="brand-logo" title="Anunturi mica publicitate"><img src="../img/logo.svg"
                                                                                      alt="Anunturi mica publicitate"></a>
                <ul id="nav-mobile" class="right">
                    <li>
                        <?php if (!$loggedIn) { ?>
                    <li><a href="/autentificare" class="waves-effect waves-light btn-large btnmo">Autentificare</a></li>
                    <?php } else { ?>
                        <?php if (!$admin) { ?>
                            <li><a href="/contul-meu" class="waves-effect waves-light btn-large btnmo">Contul meu</a>
                            </li>
                        <?php } else { ?>
                            <li><a href="/admin/cotatii" class="waves-effect waves-light btn-large btnmo pink darken-4">Manager
                                    Cotatii</a></li>
                        <?php } ?>
                        <li><a href="/logout" class="waves-effect waves-light btn-large btnmo">Logout</a></li>
                    <?php } ?>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</div>

<div class="container cotatii">
    <h1>Manager Cotatii</h1>

    <table class="striped highlight responsive-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>Id anunt</th>
            <th>Nume client</th>
            <th>Companie</th>
            <th>Data</th>
            <th>Tip anunt</th>
            <th>Publicatii</th>
            <th>Fisier</th>
            <th>Pret</th>
            <th>Status</th>
            <th>Actiuni</th>
        </tr>
        </thead>

        <tbody>
        <?php
        foreach ($quotes as $quote) {
            $quoteDetails = json_decode($quote['details'], true);
            $statusClass = $quote["status"] == 7 ? 'red' : 'cyan darken-3';
            $quoteContact = $quoteDetails["contact"];
            if (is_string($quoteDetails["contact"])) {
                $quoteContact = json_decode($quoteDetails["contact"], true);
            }
            $adDetails = $quoteDetails["columns"];
            if (is_string($quoteDetails["columns"])) {
                $adDetails = json_decode($quoteDetails["columns"], true);
            }
            ?>
            <tr>
                <td><?= $quote['id'] ?></td>
                <td>
                    <?php echo !empty($quoteDetails['ad_id']) ? $quoteDetails['ad_id'] : '-' ?>
                </td>
                <td><?= $quoteContact["firstName"] . " " . $quoteContact["lastName"] ?></td>
                <td><?= $quoteContact["name"] ?></td>
                <td>
                    <?php
                    $date = date_create_from_format('Y-m-d H:i:s', $quote['created_at']);
                    $fDate = date_format($date, "H:i d-m-Y");
                    ?>
                    <?= $fDate; ?></td>
                <td>
                    <?php echo $adTypes[$quoteDetails['selectedKind']] ?>
                </td>
                <td>
                    <?php
                    foreach ($adDetails as $column) {
                        ?>

                        <?php if (!empty($column["publicationName"])) { ?>
                            <p>
                                Publicatie: <?= $column["publicationName"] ?> <br>
                                Categorie:
                                <?= $column["columnName"] ?> <br>
                            </p>

                        <?php } ?>

                    <?php } ?>
                </td>
                <td>
                    <?php
                    if (!empty($quote['file'])) {
                        ?>
                        <!-- <a href="<?php echo '/uploads/' . $quote['id']; ?>"><?= $quote['file'] ?></a> -->
                        <a href="<?php echo '/uploads/' . $quote['id']; ?>">Descarca</a>
                    <?php } ?>
                </td>
                <td class="right-align blue-grey darken-1 white-text">
                    <?php
                    if (empty($quote['price'])) {
                        ?>
                        <!-- <input min="0" step="0.01" placeholder="Pret" name="price" type="number" id="price-quote-<?php echo $quote['id']; ?>" value=""/> -->
                        -
                        <?php
                    } else {
                        ?>
                        <?= $quote['price'] ?> lei
                        <?php
                    }
                    ?>
                </td>

                <td>
                      <span class="new badge <?php echo $statusClass ?>" data-badge-caption="">
                      <?= $statuses[$quote['status']] ?>
                      </span>
                </td>
                <td>
                    <?php
                    if ($quote['status'] == 1) {
                        ?>
                        <a class="waves-effect waves-light btn btn-small modal-trigger"
                           href="#modal-send-<?php echo $quote['id']; ?>" data-quote="<?php echo $quote['id'] ?>">Trimite</a>

                        <div id="modal-send-<?php echo $quote['id'] ?>" class="modal">
                            <div class="modal-content">
                                <div>
                                    <b>Trimite cotatia cu id: <?php echo $quote['id'] ?></b><br><br>
                                </div>
                                <div class="input-field">
                                    <textarea id="textarea1"
                                              placeholder="Scrie anunțul aici."
                                              class="materialize-textarea "
                                    ></textarea>
                                    <label for="textarea1">Text Anunț</label>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <a class=" send-quote-price waves-effect waves-light btn btn-small action-btn"
                                   data-quote="<?php echo $quote['id'] ?>">Trimite</a>
                            </div>
                        </div>
                    <?php } ?>
                </td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
    <?php
    $limit = 10;

    $numberOfPages = ($total / $limit) > 1 ? $total / $limit : 1;

    if (!empty($_GET['offset'])) {
        $currentOffset = $_GET['offset'];
        $currentPage = ($_GET['offset'] / $limit) + 1;
    } else {
        $currentPage = 1;
        $currentOffset = 0;
    }

    ?>
    <ul class="pagination">
        <li <?php if ($currentOffset / $limit - 1 < 0) { ?> style="pointer-events: none;" <?php } ?>
                class="<?php echo ($currentPage == 1) ? 'disabled' : ''; ?> waves-effect"><a
                    href="/admin/cotatii?limit=<?php echo $limit; ?>&offset=<?php echo $currentOffset - $limit; ?>"><i
                        class="material-icons">chevron_left</i></a></li>
        <?php for ($i = 1; $i <= $numberOfPages; $i++) { ?>
            <?php $offset = ($i - 1) * $limit;
            ?>
            <li class="<?php echo ($currentPage == $i) ? 'active' : ''; ?>"><a
                        href="/admin/cotatii?limit=<?php echo $limit; ?>&offset=<?php echo $offset; ?>"><?php echo $i; ?></a>
            </li>
        <?php } ?>
        <li <?php if ($currentOffset / $limit + 1 == $numberOfPages) { ?> style="pointer-events: none;" <?php } ?>
                class="waves-effect <?php echo ($currentPage == $numberOfPages) ? 'disabled' : ''; ?>"><a
                    href="/admin/cotatii?limit=<?php echo $limit; ?>&offset=<?php echo $currentOffset + $limit; ?>"><i
                        class="material-icons">chevron_right</i></a></li>
    </ul>
</div>

<footer class="page-footer default_color scrollspy">
    <div class="container">
        <div class="row">
            <div class="col l6 s12">
                <h5 class="white-text">Rofusion Advertising Srl</h5>
                <p class="white-text text-lighten-4">Anunturi mica publicitate<br>Anuțuri presa scrisă</p>
                <ul>
                    <li><a href="termeni-si-conditii-mica24.html" class="white-text" title="Termeni și Condiții">Termeni
                            și Condiții</a></li>
                </ul>
            </div>
            <div class="col l6 s12 right-align">
                <h5 class="white-text" id="contact">Contact</h5>
                <ul class="white-text">
                    <li>Bd. Ion Mihalache nr. 140 S<br>Sector 1, București</li>
                    <li>Telefon</li>
                </ul>
            </div>
        </div>
    </div>
    <div class="footer-copyright z-depth-1">
        <div class="container">
            <b>&copy; Rofusion Advertising Srl</b>
            <span class="right">dezvoltat de <a href="http://www.activemall.ro" class="white-text" target="_blank"
                                                title="activemall.ro">activemall.ro</a></span>
        </div>
    </div>
</footer>

<div id="reguli" class="modal">
    <div class="modal-content">
        <h4>Reguli de redactare a unui anunț</h4>
        <p>1. Nu scrieți cuvinte jignitoare sau ofensatoare.<br>2. Nu scrieți cuvintele legate între ele.<br>3. Numărul
            minim de cuvinte taxate este de 10, indiferent de lungimea anunțului dvs.</p>
    </div>
    <div class="modal-footer">
        <a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">OK</a>
    </div>
</div>
<script src="/js/jquery-3.1.0.min.js"></script>
<script src="/js/materialize.js"></script>
<script src="/js/quotes.js"></script>


</body>
</html>
