<?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::addIncludePath(JPATH_COMPONENT.'/helpers/html');
jimport('joomla.html.editor');
JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.modal');
JHtml::_('behavior.framework', true);
JHtml::_('behavior.multiselect');
JHtml::_('dropdown.init');
JHtml::_('formbehavior.chosen', 'select');
if (!class_exists('JHtmlMpusers')) {
    include JPATH_ADMINISTRATOR.
    '/components/com_marketplace/helpers/html/mpusers.php';
}
if (!class_exists('CurrencyDisplay')) {
    include JPATH_ADMINISTRATOR.
    "/componnets/com_virtuemart/helpers/currencydisplay.php";
}
$obj=CurrencyDisplay::getInstance();
$currencySymbol=$obj->getSymbol();
$doc=JFactory::getDocument();
$user = JFactory::getUser();
$userId = $user->get('id');
$listDirn = $this->state->get('list.direction');
$listOrder = $this->state->get('list.ordering');
$config = JFactory::getConfig();
$global_editor = $config->get('editor');
$editor = JFactory::getEditor();
$editor->display($global_editor, '', '200', '200', '5', '5', true);
$doc->addStyleDeclaration(
    '
    .toggle-editor {
        display: none;
    }

    .icon-mailtoseller::before {
        content: url("'.JURI::root().
        'administrator/components/com_marketplace/assets/images/icon-mass-mail.png");
        background-position: 0px 2px;
    }

    .icon-marketplaces {
        background-image: url("components/com_marketplace/assets/images/sprite-icon.png");
        background-repeat: no-repeat;
        background-position: -39px -66px !important;
        vertical-align: middle;
        width: 20px;
        height: 20px;
        margin-right: 0px!important;
    }
'
);
$jinput=JFactory::getApplication()->input;
$test=$jinput->get('wk_set');
$redirect=$jinput->get('wk_redirect');
if (isset($redirect)) {
    JFactory::getApplication()->redirect(
        'index.php?option=com_marketplace&view=marketplace',
        JText::_('MAIL_SENT_SUCCESS_TO_SELECTED_USERS')
    );
}
?>
<?php
if (isset($test)) {
    $valuse=$jinput->getVar('emails');
    $emails=unserialize(urldecode($valuse));
    $script="
    window.addEvent('domready', function () {
        SqueezeBox.initialize({
            size: {
                x: 800,
                y: 500
            },
        });
        SqueezeBox.open('index.php?option=com_marketplace&view=marketplace&layout=sendmail&tmpl=component&emails=".urlencode(serialize($emails))."', {
            handler: 'iframe'
        });
        SqueezeBox.addEvent('onClose', function () {

            window.location = 'index.php?option=com_marketplace&view=marketplace';
        });
    });
    ";
    $doc->addScriptDeclaration($script);
}
$saveOrder= $listOrder == 'a.ordering';
if ($saveOrder) {
    $saveOrderingUrl = 'index.php?option=com_marketplace&task=marketplace.saveOrderAjax&tmpl=component';
    JHtml::_(
        'sortablelist.sortable', 'articleList', 'adminForm',
        strtolower($listDirn), $saveOrderingUrl
    );
}
?>
<style type="text/css">
.wk_single {
    height: 14px;
    width: 21px;
    cursor: pointer;
}
</style>
<script type="text/javascript">
function modalcloseFunction() {
    window.parent.document.location.reload(true);
}
</script>
<form action="<?php
    echo 'index.php?option=com_marketplace&view=marketplace';
    ?>" 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;
            echo JLayoutHelper::render(
                'joomla.searchtools.default', array('view' => $this)
            );
        ?>
            <div class="clearfix"> </div>
            <table class="table table-striped table-bordered" id="articleList">
                <thead>
                    <tr bgcolor="#6994C4" style="color:#FFFFFF;vertical-align:top">
                        <th width="1%" class="nowrap">
                            <input type="checkbox" name="checkall-toggle" value="" title="<?php
                            echo JText::_('JGLOBAL_CHECK_ALL');
                            ?>" onclick="Joomla.checkAll(this)" />
                        </th>
                        <th width="10%" class="nowrap">
                            <?php echo JHtml::_(
                                'searchtools.sort', 'CUSTOMER_NAME', 'a.username',
                                $listDirn, $listOrder
                            ); ?>
                        </th>
                        <th width="15%" class="nowrap">
                            <?php echo JHtml::_(
                                'searchtools.sort', 'CUSTOMER_EMAIL', 'a.email',
                                $listDirn, $listOrder
                            ); ?>
                        </th>
                        <th width="10%" class="nowrap">
                            <?php echo JHtml::_(
                                'searchtools.sort', 'SELLER_COMMISSION', 'mc.commision',
                                $listDirn, $listOrder
                            ); ?>
                        </th>
                        <th width="5%" class="center">
                            <?php echo JHtml::_(
                                'searchtools.sort', 'IS_A_PARTNER', 'is_seller',
                                $listDirn, $listOrder
                            ); ?>
                        </th>
                        <th width="5%" class="center">
                            <?php echo JHtml::_(
                                'searchtools.sort', 'SELLER_EMAIL', '',
                                $listDirn, $listOrder
                            ); ?>
                        </th>
                        
                        <th width="1%">
                            <?php echo JHTML::_(
                                'searchtools.sort',  'ID', 'c.seller_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) > 0) {
                        $k = 0;
                        for ($i=0, $n=count($this->items); $i < $n; $i++) {
                            $item = &$this->items[$i];
                            $checked    = JHTML::_('grid.id', $i, $item->seller_id);
                    ?>
                    <tr class="<?php echo "row" . $k; ?>">
                        <td>
                            <?php  echo $checked; ?>
                        </td>
                        <td class="nowrap">
                            <a href="index.php?option=com_marketplace&view=marketplace&layout=edit_seller&seller_id=<?php
                            echo $item->seller_id;
                            ?>" title="">
                                <?php
                                echo JFactory::getUser($item->seller_id)->username;
                                ?>
                            </a>
                        </td>
                        <td class="nowrap">
                            <?php echo $this->escape($item->email); ?>
                        </td>
                        <td class="nowrap">
                            
                            <?php
                            $sign='';
                            if ($item->commision_type=='r') {
                                $sign='%';
                            } else {
                                $sign=$currencySymbol;
                            }
                            echo $item->commision.$sign;
                            ?>
                        </td>
                        <td class="center">
                            
                            <?php
                                echo JHtml::_(
                                    'jgrid.state', JHtmlMpusers::sellerStates(),
                                    $item->is_seller, $i, 'marketplace.',
                                    $item->seller_id
                                );
                            ?>
                        </td>
                        <td class="center">
                            <div class="wk_single_mail">
                                <a class="modal" rel="{handler: 'iframe', size: {x: 700, y: 500},onClose: function(){modalcloseFunction()}}" href="<?php echo JURI::root()?>administrator/index.php?option=com_marketplace&view=marketplace&layout=sendmail&tmpl=component&email=<?php echo $this->escape($item->email); ?>" title="Send Mail">
                                    <img class="wk_single" src="<?php echo JURI::root().'/administrator/components/com_marketplace/assets/images/mail.png'?>" title="Send Mail"/>
                                </a>
                            </div>
                            
                        </td>
                        <td class="nowrap">
                            <?php echo (int) $item->seller_id; ?>
                        </td>
                    </tr>
                    <?php
                    $k = 1 - $k;
                        }
                    ?>
                    <?php
                    } else {
                            echo "<tr ><td colspan='7'><div class='alert alert-info'>".
                            "<strong>Info!</strong>".JText::_('NO_RECORD_FOUND')."</div></td></tr>";
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <input type="hidden" name="task" value="" />
        <input type="hidden" name="boxchecked" value="0" />
        <?php echo JHTML::_('form.token'); ?>
    </form>
