<?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');
jimport('joomla.application.component.view');
jimport('joomla.html.html');
jimport('joomla.html.behavior');
JHTML::_('behavior.modal');
if (!class_exists('MarketplaceHelper')) {
    include JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.
    DIRECTORY_SEPARATOR.'com_marketplace'.DIRECTORY_SEPARATOR.'helpers'.
    DIRECTORY_SEPARATOR.'marketplace.php';
}
/**
 * MarketplaceViewMarketplace class
 * 
 * @category Component
 * @package  Joomla
 * @author   WebKul software private limited <support@webkul.com>
 * @license  http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @link     Technical Support:  webkul.uvdesk.com
 */
class MarketplaceViewMarketplace extends JViewLegacy
{
    protected $items;
    protected $pagination;
    protected $state;
    public $seller_info;
    /**
     * This is display function
     *
     * @param [type] $tpl var
     * 
     * @return void
     */
    public function display($tpl = null)
    {
        $this->items = $this->get('Items');
        $this->pagination = $this->get('Pagination');
        $this->state = $this->get('State');
        $this->filterForm    = $this->get('FilterForm');
        $this->activeFilters = $this->get('ActiveFilters');
        $this->form=$this->get('form');
        if ($this->getLayout() == 'sendmail') {
            $input = JFactory::getApplication()->input;
            $eName = $input->getCmd('e_name');
            $eName = preg_replace('#[^A-Z0-9\-\_\[\]]#i', '', $eName);
            $document = JFactory::getDocument();
            $document->setTitle(JText::_('COM_MARKETPLACE_SENDMAIL_TITLE'));
            $this->eName = &$eName;
            parent::display($tpl);
            return;
        } else {
            if (count($errors = $this->get('Errors'))) {
                JError::raiseError(500, implode('<br />', $errors));
                return false;
            }
            $this->addToolBar();
            $this->sidebar = JHtmlSidebar::render();
            parent::display($tpl);
        }
    }
    /**
     * This is addToolBar function
     *
     * @return void
     */
    protected function addToolBar()
    {
        include_once JPATH_COMPONENT . '/helpers/marketplace.php';
        JToolBarHelper::title(JText::_('COM_MARKETPLACE_SELLER'), 'marketplaces');
        $app = JFactory::getApplication();
        $layout = $app->input->getString("layout");
        $seller_id = $app->input->get('seller_id', 0);
        $chk_seller = MarketplaceHelper::checkSeller($seller_id);
        $url="index.php?option=com_marketplace&view=marketplace";
        $msg=JText::_('NO_SELLER_ACCESS');
        $msgType='error';
        if ($layout == 'edit_seller') {
            if (!$chk_seller) {
                $app->redirect($url, $msg, $msgType);
            }
            
            JToolBarHelper::title(JText::_('SELLER_INFORMATION'), 'users');
            $bar = JToolbar::getInstance('toolbar');
            $bar->appendButton(
                'Standard',
                'edit',
                'Edit',
                'marketplace.editseller',
                false
            );
            JToolbarHelper::cancel('marketplace.cancel1');
        } elseif ($layout=='edit_seller_form') {
            if (!$chk_seller) {
                $app->redirect($url, $msg, $msgType);
            }
            JToolBarHelper::title(JText::_('SELLER_INFORMATION'), 'pencil');
            JToolBarHelper::apply('marketplace.saveseller');
            JToolbarHelper::cancel('marketplace.cancel');
        } else {
            JToolBarHelper::addNew(
                'marketplace.add',
                JText::_('ACTIVATE_SELLER'),
                true
            );
            JToolbarHelper::custom(
                'marketplace.deny',
                'cancel',
                '',
                'DEACTIVATE_SELLER',
                true
            );
            JToolBarHelper::divider();
            JToolBarHelper::deleteList(
                'DELETE_SELLER_QUESTION',
                'marketplace.remove',
                JText::_('DELETE_SELLER'),
                true
            );
            JToolbarHelper::divider();
            JToolbarHelper::custom(
                'marketplace.mailtoseller',
                'mailtoseller',
                '',
                'MAIL_TO_SELLER',
                true
            );
        }
        JToolBarHelper::divider();
        JToolBarHelper::preferences('com_marketplace');
        JHtmlSidebar::setAction('index.php?option=com_marketplace&view=marketplace');
    }
}
