<?php

defined ( '_JEXEC' ) or die ( 'Restricted access' );
/*
 * @component Calc Builder 
 * @copyright Copyright (C) January 2017. 
 * @license GPL 3.0 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details. 
 * See <http://www.gnu.org/licenses/>. 
 * More info www.moonsoft.es 
 * gestion@moonsoft.es
 */
$pathImagen = JURI::base () . 'components/com_calcbuilder/assets/img/export.png';
$document = JFactory::getDocument ();
$css = $this->__getCSS ();
foreach ( $css as $style ) {
	$document->addStyleSheet ( $style );
}
$js = $this->__getJS ();
foreach ( $js as $jscript ) {
	?><script src="<?php echo $jscript;?>"></script><?php
}
?>
<form action="index.php" method="post" name="adminForm" id="adminForm">
	<div id="editcell" class="cb_table_wrapper">
		<table class="table table-hover">
			<thead>
				<tr>
					<th width="20"><input type="checkbox" name="toggle" value=""
						onclick="Joomla.checkAll(this);" /></th>
					<th width="5">
                <?php echo JText::_( 'ID' ); ?>
            </th>
            <?php if ($this->permissions->get('core.admin')){?>
            <th width="5">
                <?php echo JText::_( 'EXPORT' ); ?>
            </th>
            <?php }?>
            <th width="20%">
                <?php echo JText::_( 'NAME' ); ?>
            </th>
					<th width="75%">
                <?php echo JText::_( 'INFORMATION' ); ?>
            </th>
				</tr>
			</thead>
    <?php
				$k = 0;
				foreach ( $this->items as &$row ) {
					$checked = JHTML::_ ( 'grid.id', - 1, $row->id );
					$this->permissions = $this->getActions ();
					if ($this->permissions->get ( 'core.edit' )) {
						$link = JRoute::_ ( 'index.php?option=com_calcbuilder&controller=utility&task=edit&' . JSession::getFormToken () . '=1&cid[]=' . $row->id );
						$linkExport = JRoute::_ ( 'index.php?option=com_calcbuilder&controller=utility&task=export&format=exml&' . JSession::getFormToken () . '=1&cid[]=' . $row->id );
					} else {
						$link = '#';
						$linkExport = '#';
					}
					?>
        <tr class="<?php echo "row$k"; ?>">
				<td>
                <?php echo $checked; ?>
            </td>
				<td>
                <?php echo $row->id; ?>
            </td>
            <?php if ($this->permissions->get('core.admin')){?>
            <td><img src="<?php echo $pathImagen;?>"
					onclick="javascript:document.location.href='<?php echo $linkExport;?>'"
					style="cursor: pointer" /></td>
            <?php }?>
            <td><a href="<?php echo $link; ?>"><?php echo $row->name; ?></a>
				</td>
				<td>
                <?php echo $row->info; ?>
            </td>
			</tr>
        <?php
					$k = 1 - $k;
				}
				?>
    <tfoot>
				<td colspan="6"><?php echo $this->pagenav->getListFooter();?></td>
			</tfoot>
		</table>
	</div>

	<input type="hidden" name="option" value="com_calcbuilder" /> <input
		type="hidden" name="task" value="show" /> <input type="hidden"
		name="boxchecked" value="0" /> <input type="hidden" name="controller"
		value="utility" />
<?php echo JHtml::_( 'form.token' ); ?>
</form>

