<?php
/**
 * @package DJ-Events
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 * @developer Szymon Woronowski - szymon.woronowski@design-joomla.eu
 *
 */

defined('_JEXEC') or die('Restricted access');
if (version_compare(JVERSION, '4', '<')) { // Joomla 3) { // first must be the zoomer script
    JHtml::_('behavior.tooltip');

}

$user = JFactory::getUser();
$userId = $user->get('id');
$listOrder = $this->state->get('list.ordering');
$listDirn = $this->state->get('list.direction');

?>


<form action="<?php echo JRoute::_('index.php?option=com_djevents&view=cities'); ?>" method="post" name="adminForm"
      id="adminForm">
    <div class="<?php echo $this->classes->row ?>">
        <?php if (!empty($this->sidebar)): ?>
        <div id="j-sidebar-container" class="<?php echo $this->classes->col ?>2">
            <?php echo $this->sidebar; ?>
        </div>
        <div id="j-main-container" class="<?php echo $this->classes->col ?>10">
            <?php else: ?>
            <div id="j-main-container">
                <?php endif; ?>
                <div id="filter-bar" class="btn-toolbar">
                    <div class="filter-search btn-group pull-left">
                        <label class="element-invisible"
                               for="filter_search"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></label>
                        <input type="text" name="filter_search" id="filter_search"
                               value="<?php echo $this->escape($this->state->get('filter.search')); ?>"/>
                    </div>



                    <div class="btn-group pull-left">
                        <button type="submit" class="btn"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
                        <button type="button" class="btn"
                                onclick="jQuery('#filter_search').val(''); this.form.submit();"><?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?></button>
                    </div>

                    <div class="btn-group pull-right hidden-phone">
                        <label for="limit"
                               class="element-invisible"><?php echo JText::_('JFIELD_PLG_SEARCH_SEARCHLIMIT_DESC'); ?></label>
                        <?php echo $this->pagination->getLimitBox(); ?>
                    </div>

                    <div class="btn-group pull-right hidden-phone">
                        <select name="filter_published" class="input-medium" onchange="this.form.submit()">
                            <option value=""><?php echo JText::_('COM_DJEVENTS_SELECT_OPTION_STATE'); ?></option>
                            <?php
                            echo JHtml::_('select.options', array(JHtml::_('select.option', '1', 'JPUBLISHED'), JHtml::_('select.option', '0', 'JUNPUBLISHED')), 'value', 'text', $this->state->get('filter.published'), true);
                            ?>
                        </select>
                    </div>
                </div>
                <div class="clearfix"></div>

                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th width="1%" class="hidden-phone">
                            <input type="checkbox" name="checkall-toggle" value=""
                                   title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>"
                                   onclick="Joomla.checkAll(this)"/>
                        </th>
                        <th width="25%">
                            <?php echo JHtml::_('grid.sort', 'COM_DJEVENTS_NAME', 'a.name', $listDirn, $listOrder); ?>
                        </th>
                        <th width="10%">
                            <?php echo JHtml::_('grid.sort', 'COM_DJEVENTS_EVENT_CREATED', 'a.created', $listDirn, $listOrder); ?>
                        </th>
                        <?php
                        //todo obsługa published
                        /*
                         *   <th width="5%" class="center">
                            <?php echo JHtml::_('grid.sort', 'JSTATUS', 'a.published', $listDirn, $listOrder); ?>
                        </th>
                         */
                        ?>

                        <th width="1%" class="nowrap">
                            <?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
                        </th>
                    </tr>
                    </thead>
                    <tfoot>
                    <tr>
                        <td colspan="10">
                            <?php echo $this->pagination->getListFooter(); ?>
                        </td>
                    </tr>
                    </tfoot>
                    <tbody>
                    <?php foreach ($this->items as $i => $item) :
                        $canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->get('id') || $item->checked_out == 0;
                        ?>
                        <tr class="row<?php echo $i % 2; ?>">
                            <td class="center">
                                <?php echo JHtml::_('grid.id', $i, $item->id); ?>
                            </td>
                            <td>
                                <?php if ($item->checked_out) : ?>
                                    <?php echo JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'cities.', $canCheckin); ?>
                                <?php endif; ?>
                                <?php if (!$canCheckin): ?>
                                    <?php echo $this->escape($item->title); ?>
                                <?php else: ?>
                                    <span class="editlinktip hasTip"
                                          title="<?php echo JText::_('COM_DJEVENTS_EDIT_TOOLTIP'); ?>::<?php echo $this->escape($item->name); ?>">
							<a href="<?php echo JRoute::_('index.php?option=com_djevents&task=city.edit&id=' . $item->id); ?>">
								<?php echo $this->escape($item->name); ?></a>
							</span>
                                <?php endif; ?>
                                <?php if($item->alias) : ?>
                                    <small><?php echo $item->alias ?></small>
                                <?php endif; ?>
                            </td>
                            <td class="nowrap">
                                <?php if($item->created !== '0000-00-00 00:00:00') : ?>
                                    <?php echo JHtml::_('date', $item->created, 'Y-m-d H:i:s'); ?>
                                <?php endif; ?>

                            </td>
                            <?php
                            //todo obsługa published
                            /*
                             *  <td class="center">
                                <div class="btn-group">
                                    <?php echo JHtml::_('jgrid.published', $item->published, $i, 'cities.', true, 'cb'); ?>
                                </div>
                            </td>
                             */
                            ?>

                            <td class="center">
                                <?php echo (int)$item->id; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>

                <div>
                    <input type="hidden" name="task" value=""/>
                    <input type="hidden" name="boxchecked" value="0"/>
                    <input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>"/>
                    <input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>
                    <?php echo JHtml::_('form.token'); ?>
                </div>
            </div>
        </div>
</form>
