<?php
/**
 * @package    JBusinessDirectory
 *
 * @author CMSJunkie http://www.cmsjunkie.com
 * @copyright  Copyright (C) 2007 - 2021 CMSJunkie. All rights reserved.
 * @license   https://www.gnu.org/licenses/agpl-3.0.en.html
 */ 
defined('_JEXEC') or die('Restricted access');
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
// Load the tooltip behavior.
JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
 JBusinessUtil::initializeChosen();

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;

$listOrder	= $this->escape($this->state->get('list.ordering'));
$listDirn	= $this->escape($this->state->get('list.direction'));
$filterCompanyId = $this->state->get('filter.companyId');
?>

<script type="text/javascript">
window.addEventListener('load', function() {
	Joomla.submitbutton = function(task) {
		if (task != 'companypricelists.delete' || confirm('<?php echo JText::_("LNG_ARE_YOU_SURE_YOU_WANT_TO_DELETE", true);?>')) {
			Joomla.submitform(task);
		}
    }
});
</script>
<div id="jbd-container" class="jbd-container">
    <form action="<?php echo JRoute::_('index.php?option=com_jbusinessdirectory&view=companypricelists');?>" method="post" name="adminForm" id="adminForm">
        <div id="j-main-container" class="j-main-container">
            <?php
            // Search tools bar
            echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this, 'options' => array('filtersHidden' => false)));
            ?>
        </div>
        <div class="clr clearfix"></div>
            <?php if (empty($this->items)) { ?>
                <div class="alert alert-warning">
                    <?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
                </div>
            <?php } else { ?>

                <table class="jtable" id="itemList">
                    <thead class="jtable-head">
                        <tr class="jtable-head-row">
                            <th class="jtable-head-row-data" width="1%">#</th>
                            <th class="jtable-head-row-data" width="5%">
                                <div class="d-flex justify-content-center align-items-center">
                                    <div class="jradio">
                                        <input id="jradio-2" type="checkbox" title="<?php echo JText::_('JGLOBAL_CHECK_ALL');?>" onclick="Joomla.checkAll(this)" />
                                        <label for="jradio-2"></label>
                                    </div>
                                </div>
                            </th>
                            <th class="jtable-head-row-data" width="18%"><?php echo HTMLHelper::_('searchtools.sort', 'LNG_COMPANY', 'cp.name', $listDirn, $listOrder); ?></th>
                            <th class="jtable-head-row-data" width="18%"><?php echo JText::_('LNG_SERVICES'); ?></th>
                            <th class="jtable-head-row-data" width="1%"><?php echo HTMLHelper::_('searchtools.sort', 'LNG_COMPANY_ID', 'cp.id', $listDirn, $listOrder); ?></th>
                        </tr>
                    </thead>

                    <tfoot>
                        <tr>
                            <td colspan="15"><?php echo $this->pagination->getListFooter(); ?></td>
                        </tr>
                    </tfoot>

                    <tbody class="jtable-body">
                    <?php $nrcrt = 1; $i=0;
                    foreach( $this->items as $item) { ?>
                        <tr class="jtable-body-row">

                            <td class="jtable-body-row-data">
		                        <?php echo $nrcrt++; ?>
                            </td>

                            <td class="jtable-body-row-data px-3">
		                        <?php echo HTMLHelper::_('jbdgrid.id', $i, $item->companyId); ?>
                            </td>

                            <td class="jtable-body-row-data jtable-body-name">
                                <span class="jtable-body-row-data-title">
                                    <a href='<?php echo JRoute::_( 'index.php?option=com_jbusinessdirectory&task=companypricelist.edit&id='. $item->companyId )?>'
                                       title="<?php echo JText::_('LNG_CLICK_TO_EDIT'); ?>">
                                        <b><?php echo $item->companyName?></b>
                                    </a>
                                </span>
                            </td>

                            <td class="jtable-body-row-data">
		                        <?php
		                        $services = explode(' - ',$item->services[0]);
		                        $section = $services[1];
		                        echo '<strong>'.$section.'</strong><br/>';
		                        foreach ($item->services as $service){
			                        $service1 = explode(' - ',$service);
			                        if ($service1[1] != $section){
				                        echo '<strong>'.$service1[1].'</strong><br/>';
				                        $section = $service1[1];
			                        }
			                        echo $service1[2]. ' ' .JBusinessUtil::getPriceFormat($service1[3]).'<br/>';
		                        }
		                        ?>
                            </td>

                            <td class="jtable-body-row-data">
		                        <?php echo (int) $item->companyId; ?>
                            </td>

                        </tr>
                        <?php
                        $i++;
                    } ?>
                    </tbody>
                </table>
            <?php } ?>
    	<input type="hidden" name="option"	value="<?php echo JBusinessUtil::getComponentName()?>" />
    	<input type="hidden" name="task" value="" /> 
    	<input type="hidden" name="id" value="" />
    	<input type="hidden" name="boxchecked" value="0" />
    	<?php echo JHTML::_( 'form.token' ); ?> 
    </form>
</div>
