<?php
/**
 * Marketplace - Component Marketplace 
 * ******************************************************************
 *
 * PHP version 7.0
 *
 * @category   Component
 * @package    Joomla
 * @author     WebKul software private limited <support@webkul.com>
 * @copyright  2010 WebKul software private limited
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @version    GIT:5.2
 * @filesource http://store.webkul.com
 * @link       Technical Support:  webkul.uvdesk.com
 * ******************************************************************
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$doc=JFactory::getDocument();
$doc->addStyleDeclaration(
    '.icon-addseller::before {
    content: url("'.JURI::root().'administrator/components/com_marketplace/assets/images/addseller.png");
}

.icon-mpusers {
    background-image: url("components/com_marketplace/assets/images/sprite-icon.png");
    background-repeat: no-repeat;
    background-position: -39px -264px !important;
    vertical-align: middle;
    width: 20px;
    height: 20px;
    margin-right: 0px!important;
}'
);
$saveOrder = $listOrder == 'a.ordering';
if ($saveOrder) {
    $saveOrderingUrl = 'index.php?option=com_marketplace&task=mpusers.saveOrderAjax&tmpl=component';
    JHtml::_(
        'sortablelist.sortable', 'articleList',
        'adminForm', strtolower($listDirn), $saveOrderingUrl
    );
}
$loggeduser = JFactory::getUser();
if (!class_exists('JHtmlMpusers')) {
    include JPATH_ADMINISTRATOR.
    '/components/com_marketplace/helpers/html/mpusers.php';
}
?>
<form action="<?php
echo 'index.php?option=com_marketplace&view=mpusers';
    ?>" method="post" name="adminForm" id="adminForm">
    <?php if (!empty($this->sidebar)) : ?>
    <div id="j-sidebar-container" class="span2">
        <?php echo $this->sidebar; ?>
    </div>
    <div id="j-main-container" class="span10">
        <?php else : ?>
        <div id="j-main-container">
        <?php endif;?>
        <?php
        $canChange = $loggeduser->authorise(
            'core.edit.state', 'com_marketplace'
        );
        echo JLayoutHelper::render(
            'joomla.searchtools.default', array('view' => $this)
        );
        ?>
        <?php if (empty($this->items)) : ?>
            <div class="alert alert-no-items">
                <?php echo JText::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
            </div>
            <?php else : ?>
            <table class="table table-striped table-bordered" id="userList">
                <thead>
                    <tr bgcolor="#6994C4" style="color:#FFFFFF;vertical-align:top">
                        <th width="1%" class="nowrap center">
                            <?php echo JHtml::_('grid.checkall'); ?>
                        </th>
                        <th class="" width="10%">
                            <?php echo JHtml::_('searchtools.sort', 'COM_USERS_HEADING_NAME', 'a.name', $listDirn, $listOrder); ?>
                        </th>
                        <th width="10%" class="nowrap">
                            <?php echo JHtml::_('searchtools.sort', 'JGLOBAL_USERNAME', 'a.username', $listDirn, $listOrder); ?>
                        </th>
                        <th width="5%" class="nowrap center">
                            <?php echo JHtml::_('searchtools.sort', 'COM_USERS_HEADING_ENABLED', 'a.block', $listDirn, $listOrder); ?>
                        </th>
                        <th width="5%" class="nowrap center ">
                            <?php echo JHtml::_('searchtools.sort', 'COM_USERS_HEADING_ACTIVATED', 'a.activation', $listDirn, $listOrder); ?>
                        </th>
                        <th class="center">
						<?php echo JHtml::_('searchtools.sort', 'COM_USERS_IS_SELLER', 'a.activation', $listDirn, $listOrder); ?>
						</th>
                        <th width="15%" class="nowrap ">
                            <?php echo JHtml::_('searchtools.sort', 'JGLOBAL_EMAIL', 'a.email', $listDirn, $listOrder); ?>
                        </th>
                        <th width="15%" class="nowrap ">
                            <?php echo JHtml::_('searchtools.sort', 'COM_USERS_HEADING_LAST_VISIT_DATE', 'a.lastvisitDate', $listDirn, $listOrder); ?>
                        </th>
                        <th width="10%" class="nowrap ">
                            <?php echo JHtml::_('searchtools.sort', 'COM_USERS_HEADING_REGISTRATION_DATE', 'a.registerDate', $listDirn, $listOrder); ?>
                        </th>
                        <th width="1%" class="nowrap ">
                            <?php echo JHtml::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
                        </th>
                    </tr>
                </thead>
                <tfoot>
                <tr>
                    <td colspan="15">
                        <?php  echo $this->pagination->getListFooter(); ?>
                    </td>
                </tr>
                </tfoot>
                <tbody>
                    <?php
                    if (count($this->items)) {
                        foreach ($this->items as $i => $item) :
                            $canEdit   = $this->canDo->get('core.edit');
                    
                            if ((!$loggeduser->authorise('core.admin')) && JAccess::check($item->id, 'core.admin')) {
                                $canEdit   = false;
                                $canChange = false;
                            }
                    ?>
                    <tr class="row<?php echo $i % 2; ?>">
                        <td class="center">
                            
                            <?php echo JHtml::_('grid.id', $i, $item->id); ?>
                        </td>
                        <td>
                            <div class="name">
                                <?php echo $this->escape($item->name); ?>
                            </div>
                        </td>
                        <td>
                            <?php echo $this->escape($item->username); ?>
                        </td>
                        <td class="center">
                            <?php
                            $self = $loggeduser->id == $item->id;
                            echo JHtml::_('jgrid.state', JHtmlMpusers::blockStates($item->id), $item->block, $i, 'mpusers.', !$self);
                            ?>
                            
                        </td>
                        <td class="center ">
                            <?php
                            $activated = empty($item->activation)?0:1;
                            echo JHtml::_(
                                'jgrid.state', JHtmlMpusers::activateStates(), $activated, $i,
                                'mpusers.', (boolean) $activated
                            );
                            ?>
                        </td>
                        <?php
                        $model=$this->getModel();
                        $is_seller=$model->checkSeller($item->id);
                        if (is_object($is_seller)) {
                            $yes= JText::_('Y_ES');
                        } else {
                            $yes=JText::_('N_O');
                        } ?>
                        <td class="center"> <?php echo $yes; ?></td>
                        <td class="">
                            <?php
                            echo JStringPunycode::emailToUTF8(
                                $this->escape($item->email)
                            );
                            ?>
                        </td>
                        <td class="">
                            <?php
                            if ($item->lastvisitDate != '0000-00-00 00:00:00') :
                            ?>
                            <?php
                            echo JHtml::_(
                                'date', $item->lastvisitDate, 'Y-m-d H:i:s'
                            );
                            ?>
                            <?php else:?>
                            <?php echo JText::_('JNEVER'); ?>
                            <?php endif;?>
                        </td>
                        <td class="">
                            <?php echo JHtml::_('date', $item->registerDate, 'Y-m-d H:i:s'); ?>
                        </td>
                        
                        <td class="">
                            <?php echo (int) $item->id; ?>
                        </td>
                    </tr>
                        <?php endforeach; ?>
                    <?php
                    } else {
                        echo "<tr ><td colspan='9'><div class='alert alert-info'>".
                        "<strong>Info!</strong>".JText::_('NO_RECORD_FOUND').
                        "</div></td></tr>";
                    }
                    ?>
                </tbody>
            </table>
            <?php endif; ?>
            <input type="hidden" name="task" value="" />
            <input type="hidden" name="boxchecked" value="0" />
            <?php echo JHtml::_('form.token'); ?>
        </div>
    </div>
</form>
