<!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>Cotatii - Anunturi mica publicitate - Anuțuri presa scrisă - Rofusion Advertising Srl</title>
    <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 pink darken-4 btnmo">Contul
                                    meu</a></li>
                        <?php } else { ?>
                            <li><a href="/admin/cotatii" class="waves-effect waves-light btn-large btnmo">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>Cotatii mele</h1>
    <table class="striped highlight responsive-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>Data</th>
            <th>Tip anunt</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';
            ?>
            <tr>
                <td><?= $quote['id'] ?></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
                    if (!empty($quote['file'])) {
                        ?>
                        <a href="<?php echo '/uploads/' . $quote['id']; ?>"><?= $quote['file'] ?></a>
                    <?php } ?>
                </td>
                <td class="right-align blue-grey darken-1 white-text">
                    <?= empty($quote['price']) ? '' : $quote['price'] . ' lei' ?>
                </td>
                <td>
                      <span class="new badge <?php echo $statusClass ?>" data-badge-caption="">
                      <?= $statuses[$quote['status']] ?>
                      </span>
                </td>
                <td class="right-align">
                    <?php
                    if ($quote['status'] == 2) {
                        ?>
                        <a class="waves-effect waves-light btn btn-small modal-trigger"
                           href="#modal-accept-<?php echo $quote['id']; ?>" data-quote="<?php echo $quote['id'] ?>">Accepta</a>

                        <a class="waves-effect waves-light btn btn-small red modal-trigger"
                           href="#modal-decline-<?php echo $quote['id'] ?>">Refuza</a>
                        <div id="modal-accept-<?php echo $quote['id'] ?>" class="modal">
                            <div class="modal-content">
                                <h4>Accepta cotatia cu id: <?php echo $quote['id'] ?></h4>
                            </div>
                            <div class="modal-footer">
                                <a class="accept-quote waves-effect waves-light btn btn-small"
                                   data-quote="<?php echo $quote['id'] ?>">Accepta</a>
                            </div>
                        </div>
                        <div id="modal-decline-<?php echo $quote['id'] ?>" class="modal">
                            <div class="modal-content">
                                <h4>Refuzati cotatia cu id: <?php echo $quote['id'] ?></h4>
                            </div>
                            <div class="modal-footer">
                                <a class="deny-quote waves-effect waves-light btn btn-small red"
                                   data-quote="<?php echo $quote['id'] ?>">Refuza</a>
                            </div>
                        </div>
                    <?php } else if ($quote['status'] == 3 && $quoteDetails['invoicePerAd'] == 0) { ?>
                        <a class=" waves-effect waves-light btn pay-quote" data-quote="<?php echo $quote['id'] ?>">Plateste</a>
                        <form action="/payment-quote" method="POST">
                            <input name="ad_id" type="hidden" value="<?php echo $quoteDetails['ad_id']; ?>"/>
                            <input name="quote_id" type="hidden" value="<?php echo $quote['id']; ?>"/>
                        </form>
                    <?php } else if ($quote['status'] == 7) { ?>
                        <a class="  waves-effect waves-light btn btn-small modal-trigger red"
                           href="#modal-delete-<?php echo $quote['id']; ?>">Sterge</a>

                        <div id="modal-delete-<?php echo $quote['id'] ?>" class="modal">
                            <div class="modal-content">
                                <h4>Sterge cotatia cu id: <?php echo $quote['id'] ?></h4>
                            </div>
                            <div class="modal-footer">
                                <a class=" waves-effect waves-light btn btn-small red delete-quote"
                                   data-quote="<?php echo $quote['id'] ?>">Sterge</a>
                            </div>
                        </div>

                    <?php } ?>
                </td>
            </tr>
        <?php } ?>
        </tbody>
    </table>

    <?php
    $limit = !empty($_GET['limit']) ? $_GET['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="/contul-meu?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="/contul-meu?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="/contul-meu?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>
