<?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.framework', true);
JHtml::_('behavior.multiselect');
JHtml::_('dropdown.init');
JHtml::_('jquery.framework');
JHtml::_('formbehavior.chosen', 'select');
if (!class_exists('JHtmlMpusers')) {
    include JPATH_ADMINISTRATOR.
    '/components/com_marketplace/helpers/html/mpusers.php';
}
if (!class_exists('MarketplaceHelper')) {
    include JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.
    DIRECTORY_SEPARATOR.'com_marketplace'.DIRECTORY_SEPARATOR.'helpers'.
    DIRECTORY_SEPARATOR.'marketplace.php';
}
if (!class_exists('VmConfig')) {
    include JPATH_ADMINISTRATOR.
    '/components/com_virtuemart/helpers/config.php';
}
if (!class_exists('ShopFunctions')) {
    include JPATH_ADMINISTRATOR.
    '/components/com_virtuemart/helpers/shopfunctions.php';
}
VmConfig::loadConfig();
VmConfig::loadJLang('com_virtuemart');
$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");
}

.icon-suggested {
    background-image: url("components/com_marketplace/assets/images/sprite-icon.png");
    background-repeat: no-repeat;
    background-position: -39px -321px !important;
    vertical-align: middle;
    width: 20px;
    height: 20px;
    margin-right: 0px!important;
}
td {
    word-break: break-all;
}
'
);
$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=suggestedcategory', 
        JText::_('MAIL_SENT_SUCCESS_TO_SELECTED_USERS')
    );
}
if (isset($test)) {
    $valuse=$jinput->get('emails', "", "raw");
    $emails=unserialize(urldecode($valuse));
    $script="
window.addEvent('domready', function () {
    SqueezeBox.initialize({
        size: {
            x: 700,
            y: 500
        },
    });

    SqueezeBox.open('index.php?option=com_marketplace&view=suggestedcategory&layout=sendmail_category&tmpl=component&emails=".urlencode(serialize($emails))."', {
        handler: 'iframe'
    });
    SqueezeBox.addEvent('onClose', function () {
        window.location = 'index.php?option=com_marketplace&view=suggestedcategory';
    });
});
";
    $doc->addScriptDeclaration($script);
}
?>
<style type="text/css">
    .wk_single{
    
        height: 14px;
        width: 21px;
        cursor: pointer;
    }
</style>
<form action="<?php
echo 'index.php?option=com_marketplace&view=suggestedcategory';
?>" 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 wk_suggested" 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', 'CATEGORY_NAME', 'c.category_name', $listDirn, $listOrder); ?>
                        </th>
                        <th width="15%" class="nowrap">
                            <?php echo JHtml::_('searchtools.sort', 'CATEGORY_DESC', 'c.category_desc', $listDirn, $listOrder); ?>
                        </th>
                        <th width="10%" >
                            <?php echo JText::_('PARENT_CATEGORY_SELECTION');?>
                        </th>
                        <th width="10%" class="nowrap">
                            <?php echo JHtml::_('searchtools.sort', 'CATEGORY_ADDITIONAL_INFO', 'c.additional_info', $listDirn, $listOrder); ?>
                        </th>
                        <th width="10%" class="center">
                            <?php echo JHtml::_('searchtools.sort', 'REQUESTED_BY', 'c.requested_by', $listDirn, $listOrder); ?>
                        </th>
                        <th width="3%" class="center">
                            <?php echo JText::_('SELLER_EMAIL'); ?>
                        </th>
                        <th width="5%" class="center">
                            
                            <?php echo JHtml::_('searchtools.sort', 'STATUS', 'c.status', $listDirn, $listOrder); ?>
                        </th>
                        <th width="5%" class="center">
                            <?php echo JHtml::_('searchtools.sort', 'REQUESTED_DATE', 'c.requested_date', $listDirn, $listOrder); ?>
                        </th>
                        <th width="1%">
                            <?php echo JHTML::_('searchtools.sort',  'ID', 'c.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->id);
                    ?>
                    <tr class="<?php echo "row" . $k; ?>">
                        <td>
                            <?php  echo $checked; ?>
                        </td>
                        <td>
                            <?php echo $this->escape($item->category_name); ?>
                        </td>
                        <td >
                            <?php echo $this->escape($item->category_desc); ?>
                        </td>
                        <td>
                            <select id="product_parent_id" class="inputbox category width-100-mp text-padd" size="1" name="">
                                <option value="0" ><?php echo JText::_('COM_VIRTUEMART_UNCATEGORIZED_SUGGESSION') ?></option>
                                <?php echo ShopFunctions::categoryListTree(); ?>
                            </select>
                        </td>
                        <td>
                            <?php echo $this->escape($item->additional_info); ?>
                        </td>
                        <td>
                            <?php
                            $seller_id=MarketplaceHelper::getUserIdByEmail(
                                $item->requested_by
                            );
                            $seller_data = MarketplaceHelper::getSeller(
                                $seller_id, array('u.username')
                            );
                            if (!empty($seller_data)
                                && isset($seller_data->username)
                            ) {
                                echo '<a href="index.php?option=com_marketplace&view=marketplace&layout=edit_seller&seller_id='
                                .$seller_id.'">'.$seller_data->username.'</a>';
                            } else {
                                echo JText::_('NA');
                            }
                            
                            ?>
                        </td>
                        <td class="center">
                            <div class="wk_single_mail">
                                <a class="modal" rel="{handler: 'iframe', size: {x: 700, y: 500}}" href="<?php echo JURI::root()?>administrator/index.php?option=com_marketplace&view=suggestedcategory&layout=sendmail_category&tmpl=component&email=<?php echo $this->escape($item->requested_by); ?>" 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="center">
                            <?php
                                echo JHtml::_(
                                    'jgrid.state', JHtmlMpusers::requestStates(),
                                    $item->status, $i,
                                    'suggestedcategory.', $item->id
                                );
                            ?>
                            <input type="hidden" name="selected_cat" id="selected_cat" value=""/>
                        </td>
                        <td class="center">
                            <?php echo $item->requested_date;?>
                        </td>
                        <td class="nowrap">
                            <?php echo (int) $item->id; ?>
                        </td>
                    </tr>
                    <?php
                        $k = 1 - $k;
                        }
                    } else {
                        echo "<tr ><td colspan='11'><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>
<script type="text/javascript">
jQuery(function () {
    jQuery('input[name="cid[]"]').change(function () {
        if (jQuery(this).is(':checked')) {
            jQuery(this).parent().next().next().next().children().attr('name', 'product_parent_id[]');
        } else {
            jQuery(this).parent().next().next().next().children().removeAttr('name');
        }

    });
    jQuery('input[name="checkall-toggle"]').on('change', function () {
        if (jQuery(this).is(':checked')) {
            jQuery('input[name="cid[]"]').parent().next().next().next().children().attr('name', 'product_parent_id[]');
        } else {
            jQuery('input[name="cid[]"]').parent().next().next().next().children().removeAttr('name');
        }
    });
    jQuery('.wk_suggested .btn-micro').on('click', function () {
        jQuery(this).parent().prev().prev().prev().children().attr('name', 'product_parent_id[]');
    });
    jQuery('#product_parent_id').on('change', function () {

        jQuery(this).parent().next().next().next().children("#selected_cat").val(jQuery(this).val());
    });
});
</script>
