<?php
/**
 
 * @package     pkg_dearflip
 * @subpackage  com_dearflip
 * @since       1.0.0
 * @copyright   Copyright © 2007 Free Software Foundation, Inc. All rights reserved.
 * @license   GNU General Public License version 3 or later; see https://www.gnu.org/licenses/gpl-3.0.en.html
 
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Session\Session;
JHtml::_('formbehavior.chosen', 'select');


$document = JFactory::getDocument();
$listOrder     = $this->escape($this->state->get('list.ordering'));
$listDirn      = $this->escape($this->state->get('list.direction'));

$user = JFactory::getUser();
$userId = $user->get('id');
$saveOrder = $listOrder == 'ordering';

if ($saveOrder)
{
    $saveOrderingUrl = 'index.php?option=com_dearflip&task=dearflipcats.saveOrderAjax&tmpl=component';
    JHtml::_('sortablelist.sortable', 'dearflipcatList', 'adminForm', strtolower($listDirn), $saveOrderingUrl);
}
?>
  
  <script>
    jQuery(document).ready(function () {
      var comClass  = jQuery(".com_dearflip")
      var addnewbtn= comClass.children().find('.button-new');
      addnewbtn.addClass("df_addbtn_class");
      var editbtn= comClass.children().find('.button-edit');
      editbtn.addClass("df_toolbarbtn_class");
      var deletebtn= comClass.children().find('.button-delete');
      deletebtn.addClass("df_toolbarbtn_class");
      deletebtn.find('.icon-delete').addClass('df_icon_border')
      editbtn.find('.icon-edit').addClass('df_icon_border');
      var comHeader=comClass.children().find('.header');
      comHeader.addClass("df_header_class")
      
     
      


    });
  </script>
  
  <style>
      .df_addbtn_class{
          background: #3071a9 !important;
          border-color: white;
          color: white !important;
      }
      .df_header_class{
          background-color: #3071a9 !important;

      }
      .df_toolbarbtn_class{
          border-color: #3071a9 !important;
      }
      .df_icon_border{
          border-color: #3071a9 !important;

      }
      .df_code_block{
          padding: 3px 5px 2px 5px;
          margin: 0 1px;
          width: fit-content;
          background: #eaeaea;j
      background: rgba(0,0,0,.07);
          font-size: 13px;
          font-family: Consolas,Monaco,monospace
      }

     /* .icon-dearflip::before {
          content: "\e271";

      }
      
      
      #toolbar-link .icon-link::before {
        content: "\e271";
      }*/
      .add_dfcat{
        margin:auto;
        width: 90%;
        
      }
      #toolbar-edit_global .icon-edit_global::before {
          content: "\2b";
      }
      
      
      
  
  </style>
  <div class="add_dfcat">
  <form action="index.php?option=com_dearflip&view=dearflipcats" method="post" id="adminForm" name="adminForm">
    <div class="row-fluid ">
      <div class="span6">
        <?php echo JText::_('COM_DEARFLIP_DEARFLIPS_FILTER'); ?>
          <?php
          echo JLayoutHelper::render(
              'joomla.searchtools.default',
              array( 'view' => $this )
          );
          ?>
        

      </div>
    </div>
    <table class="table table-striped table-hover" id="dearflipcatList">
      <thead>
      <tr>
        <th width="1%"><?php echo JText::_('COM_DEARFLIP_NUM'); ?></th>
        <th width="2%">
          <?php echo JHtml::_('grid.checkall'); ?>
        </th>
        <th width="40%">
          <?php echo JHtml::_('searchtools.sort', 'COM_DEARFLIP_CATEGORY_MANAGER_CATEGORY_LIST_CATEGORY_NAME', 'cat_title', $listOrder, $listDirn); ?>
        </th>
        <th width="25%">
          <?php echo JText::_( 'COM_DEARFLIP_CATEGORY_MANAGER_CATEGORY_LIST_SHORTCODE'); ?>
        </th>
        <th width="20%">
          <?php echo JText::_('COM_DEARFLIP_CATEGORY_MANAGER_CATEGORY_LIST_BOOK_COUNT'); ?>
        </th>

        <th width="15%">
          <?php echo JHtml::_('searchtools.sort', 'COM_DEARFLIP_PUBLISHED', 'published', $listOrder, $listDirn); ?>
        </th>
       
        <th width="12%">
          <?php echo JHtml::_('searchtools.sort', 'COM_DEARFLIP_ID', 'id', $listOrder, $listDirn); ?>
        </th>
      </tr>
      </thead>
      <tfoot>
      <tr>
        <td colspan="7">
      
          <?php echo $this->pagination->getListFooter(); ?>
        </td>
      </tr>
      </tfoot>
      <tbody>
      
      <?php
      
      
      if (!empty($this->items)) : ?>
        <?php foreach ($this->items as $i => $row) :
          
          $link = JRoute::_('index.php?option=com_dearflip&task=dearflipcat.edit&id=' . $row->id);
     
        
          ?>
          
          <tr>
            <td>
              <?php echo $this->pagination->getRowOffset($i); ?>
            </td>
            <td>
              <?php echo JHtml::_('grid.id', $i, $row->id); ?>
            </td>
            <td>
              <a href="<?php echo $link; ?>" title="<?php echo JText::_('COM_DEARFLIP_EDIT_DEARFLIP'); ?>">
                <?php
                if($row->cat_title==''){
                  echo '[no title]';
                }
                else{echo $row->cat_title;}
                ?>
            </td>
            
            <td>
              <div class="df_code_block">
                <?php echo "{dearflip category_id=" . $row->id . "}"; ?>  </div>
            </td>
            <td>
              <?php
             
                $catID=$row->id;
                /*$row->$parentID->cat_title;*/
               
                $db         = JFactory::getDbo();
                $query      = $db->getQuery( true );
  
  
                $conditions = array(
                    $db->quoteName( 'df_cat' ) . ' =' . $catID
  
                );
                $query->select( array( 'id' ) )
                    ->from( $db->quoteName( '#__dearflip' ) )
                    ->where( $conditions );
  
  
                $db->setQuery( $query );
  
  
                $parentrow = $db->loadAssocList();
                echo count($parentrow);
                
  
  
  
  
              
              
              ?>
              
            </td>
            <td align="center">
              <?php echo JHtml::_('jgrid.published', $row->published, $i, 'dearflipcats.', true, 'cb'); ?>
            </td>
            
            <td align="center">
              <?php echo $row->id; ?>
            </td>
          </tr>
      
        <?php endforeach; ?>
      <?php endif; ?>
      </tbody>
    </table>
    
    <input type="hidden" name="task" value=""/>
    <input type="hidden" name="boxchecked" value="0"/>
      <?php echo JHtml::_('form.token'); ?>
  </form>
