<?php
/**
 * Copyright (c) 2016 Serhii Borodai <clarifying@gmail.com>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 *
 */


/** @var $this \Zend\View\Renderer\PhpRenderer */

$this->headScript()
    ->appendFile('/js/adm/supports.js')
;


/** @var $layoutInfo \App\Entity\LayoutInfo */
$layoutInfo = $this->layoutInfo;

$lang = $this->lang;

/** @var \Zend\Db\ResultSet\HydratingResultSet $supports */
$supports = $this->supports;
?>
<section class="b-content__work">
    <form method="post" action="<?= $this->url('adm.supports', ['lang' => $this->lang]) ?>">
        <div class="panel panel-info">
            <div class="panel-heading">
                <h1 style="padding: 0 0 10px 0;"><?= _t('Менеджеры') ?></h1>
                <div class="btn-toolbar">
                    <div class="btn-group" role="group">
                        <a role="button" class="btn btn-primary" href="<?= $this->url('adm.supports.create',['lang' => $this->lang]) ?>"><?= _t('Добавить менеджера') ?></a>
                    </div>
                </div>
            </div>
            <div class="panel-body">
                <table class="table table-striped">
                    <thead>
                    <tr>                        
                        <th>
                            <?= _t('#ID') ?>
                        </th>
                        <th>
                            <?= _t('Менеджер') ?>
                        </th>
                        <th>
                            <?= _t('Добавлен') ?>
                        </th>
                        <th>
                            <?= _t('Роль') ?>
                        </th>
                        <th></th>                            
                    </tr>
                    </thead>
                    <?php /** @var \App\Entity\Support $support */
                    foreach ($supports as $support) :?>
                        <tr>                            
                            <td>
                                <?= $support->getId() ?>
                            </td>
                            <td>
                                <?php
                                    $editLink = $this->url('adm.supports.edit', [
                                        'lang' => $lang,
                                        'id' => $support->getId(),
                                    ]);
                                ?>
                                <div class="user-email">
                                    <?php if($support->getId() != 1): ?>
                                        <a href="<?= $editLink ?>"><?= $support->getEmail() ?></a>
                                    <?php else: ?>
                                        <?= $support->getEmail() ?>
                                    <?php endif; ?>
                                </div>
                                <div class="user-name"><?= $support->getFullname() ?></div>
                                                                
                            </td>
                            <td>
                                <?= $support->getDateCreate() ?>
                            </td>
                            <td>
                                <?= $support->getRoleId() ?>
                            </td>
                            <td>
                                <?php if ($support->getId() !== 1) : ?>
                                    <?php
                                        $btn_link = $this->url('adm.index', [
                                            'lang' => $this->lang,
                                        ]);
                                    ?>
                                    <button type="button" class="btn  btn-primary" data-link="<?= $btn_link.'#manager='.$support->getId() ?>"><?= _t(Статистика) ?></button>
                                
                                    <?php
                                        $btn_link_del = $this->url('adm.supports.delete', [
                                            'lang' => $this->lang,
                                            'id' => $support->getId()
                                        ]);
                                    ?>
                                    <button type="button" class="btn btn-danger" data-delete="<?= $btn_link_del ?>"><?= _t('Удалить') ?></button>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            </div>
            <div class="panel-footer">
            </div>
        </div>
    </form>
    </div>
</section>
