<?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/amsystem.js')
;

$this->headLink()
    ->appendStylesheet('/css/styles-amsystem.css')

;

$lang = $this->lang;
$campaigns = $this->campaigns;
$error = $this->error;

?>

<?php if($error): ?>

    <section class="b-content__work error">
        <div class="wrapp">
            <h1><?= $error?></h1>
        </div>
    </section>

<?php else: ?>

    <section class="b-content__work">
        <div class="panel panel-info">
            <div class="panel-heading">
                <h1><?= _t('Список кампаний') ?></h1>
            </div>

            <div class="panel-body all">

                <table class="table table-striped campaigns" data-content="campaigns" data-action="/amsystem/campaigns/id/edit/">
                    <thead>
                        <tr>
                            <th width="1px"></th>
                            <th width="1px">#ID</th>
                            <th>Название кампании</th>
                            <th width="1px">Показы</th>
                            <th width="1px">Клики</th>
                            <th width="1px">CTR</th>
                            <th width="1px">Расход</th>
                            <th width="1px">Охват</th>
                            <th width="1px">eCPM</th>
                            <th width="1px">eCPC</th>
                        </tr>
                    </thead>
                    <tbody>

                    <?php foreach ($campaigns as $campaign) : ?>
                        <tr <?php if (!$campaign['active']): ?>class="disabled"<?php endif; ?>>
                            <?php
                                $campaign_id = $campaign['id'];
                                $stat = $stats[$campaign_id];
                                $target_class = ($campaign['target_action'] == 'load') ? 'load-target' : '';
                            ?>
                            <td>
                                <input class="is-active" type="checkbox" data-id="<?= $campaign_id ?>" <?php if ($campaign['active']): ?>checked<?php endif; ?> disabled>
                            </td>
                            <td>
                                <span class="item-id"><?= $campaign_id ?></span>
                            </td>
                            <td>
                                 <?php
                                    $btn_link = $this->url('user.cabinet.campaign', [
                                        'lang' => $this->lang,
                                        'id' => $campaign_id,
                                    ]);
                                 ?>
                                <span class="item-title"><a href="<?= $btn_link?>"><?= $campaign['title'] ?></a></span>
                            </td>
                            <td class="stat <?= $target_class ?>"><?= $stat['views'] ?></td>
                            <td class="stat"><?= $stat['clicks'] ?></td>
                            <td class="stat"><?= $stat['ctr'] ?></td>
                            <td class="stat"><?= $stat['money'] ?></td>
                            <td class="stat <?= $target_class ?>"><?= $stat['reach'] ?></td>
                            <td class="stat"><?= $stat['cpm'] ?></td>
                            <td class="stat"><?= $stat['cpc'] ?></td>
                        </tr>
                    <?php endforeach; ?>


                    </tbody>
                </table>

            </div>
            <div class="panel-footer">
            </div>    
        </div>
    </section>

<?php endif; ?>