<?php

/**
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access.
defined('_JEXEC') or die;

jimport('joomla.application.component.view');

class SPStgSrvViewLog_v2 extends JView {

    protected $items;
    protected $pagination;
    protected $form;
    protected $state;

    /**
     * @since	1.6
     */
    public function display($tpl = null) {
        
        //live update
        jimport('spcyend.utilities.remoteupdate');
        $remoteupdate = CYENDModelRemoteUpdate::getInstance('RemoteUpdate', 'CYENDModel');
        if ($remoteupdate->setDownloadId()) {
            $remoteupdate->updateDownloadId('pkg_spstgsrv');
            $remoteupdate->updateDownloadId('kainotomo');
        }
        
        // Get data from the model
        $this->state = $this->get('State');
        $this->items = $this->get('Items');
        $this->pagination = $this->get('Pagination');
        $this->form = $this->get('Form');
        //$this->dbTestConnection = $this->get('TestConnection');

        // Check for errors.
        if (count($errors = $this->get('Errors'))) {
            JFactory::getApplication()->enqueueMessage(implode("\n", $errors), 'error');
            return false;
        }

        //Check if there are no matching items
        if (!count($this->items)) {
            JFactory::getApplication()->enqueueMessage(
                    JText::_('COM_SPSTGSRV_MSG_MANAGE_NOEXTENSION')
                    , 'warning'
            );
        }

        $this->addToolBar();
        
        // Display the view
        parent::display($tpl);
    }

    /**
     * Add the page title and toolbar.
     *
     * @since	1.6
     */
    protected function addToolbar() {
        require_once JPATH_COMPONENT . '/helpers/spstgsrv.php';

        $canDo = SpStgSrvHelper::getActions();

        JToolBarHelper::title(JText::_('COM_SPSTGSRV_LOG_TITLE'), 'install.png');

        if ($canDo->get('core.admin')) {
            $bar = JToolBar::getInstance('toolbar');
            if ($canDo->get('core.delete')) {
                $bar->appendButton('Confirm', 'COM_SPSTGSRV_CONFIRM_MSG', 'delete', 'COM_SPTRANSFER_LOG_DELETE', 'log.delete', false);
                $bar->appendButton('Confirm', 'COM_SPSTGSRV_CONFIRM_MSG', 'purge', 'COM_SPTRANSFER_LOG_MASS_DELETE', 'log.mass_delete', false);
                $bar->appendButton('Confirm', 'COM_SPSTGSRV_ARE_YOU_SURE', 'archive', 'COM_SPSTGSRV_EXPORT', 'log.export', false);
            }
            JToolBarHelper::divider();
            JToolBarHelper::preferences('com_spstgsrv');
        }
        $bar = JToolBar::getInstance('toolbar');
        $bar->appendButton('Help', 'help', 'JTOOLBAR_HELP', 'https://www.kainotomo.com/extensions/components/documentation/88-user-guide-sp-transfer', 640, 480);
    }

}
