<?php

/*
 * @component UserPoints
 * @copyright Copyright (C) 2015-2022 Bernard Gilly - Adrien Roussel - Martin Brampton
 * @license : GNU/GPL
 * @Website : https://remository.com
 */

defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\HTML\HTMLHelper;
use BlackSheepResearch\Component\UserPoints\Site\Problems\SQL;
// JHtml::_('behavior.formvalidation');
// JHtml::_('formbehavior.chosen', 'select');

$show = function ($string) {
    return htmlspecialchars($string, ENT_QUOTES, false);
};

echo <<<TABLE_HEAD

<div id="j-main-container">
    <form action="index.php" method="post" name="adminForm" id="adminForm" class="form-validate">
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th width="2%" class="title">
                        {$show(Text::_('NUM'))}
                    </th>
                    <!--<th width="3%" class="title">
                            <input type="checkbox" name="checkall-toggle" value="" title="{$show(Text::_('JGLOBAL_CHECK_ALL'))}" onclick="Joomla.checkAll(this)" />
                    </th>-->
                    <th width="20%" class="title" nowrap="nowrap">
                        {$show(Text::_('AUP_DATE'))}
                    </th>
                    <th width="20%" class="title">
                        {$show(Text::_('AUP_RULE'))}
                    </th>
                    <th width="5%" class="title" >
                        {$show(Text::_('AUP_POINTS'))}
                    </th>
                    <th width="20%" class="title" nowrap="nowrap">
                        {$show(Text::_('AUP_EXPIRE'))}
                    </th>
                    <th width="5%" class="title" >
                        {$show(Text::_('AUP_APPROVED'))}
                    </th>
                    <th class="title" nowrap="nowrap">
                        {$show(Text::_('AUP_DATA'))}
                    </th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <td colspan="7">
                        {$this->pagination->getListFooter()}
                    </td>
                </tr>
            </tfoot>

            <tbody>
        
TABLE_HEAD;

if (count($this->userDetails)) {
    foreach ($this->userDetails as $i => $row2) {
        $link = 'index.php?option=com_userpoints&amp;task=edituserdetails&amp;cid[]=' . $row2->id . '&amp;name=' . $this->row->name . '';
        $imgA = $row2->approved ? 'icon-16-add.png' : 'publish_x.png';
        $taskA = $row2->approved ? 'unapprove' : 'approve';
        $altA = $row2->approved ? Text::_('AUP_APPROVE') : Text::_('AUP_NOTAPPROVE');
        $actionA = $row2->approved ? Text::_('AUP_NOTAPPROVE') : Text::_('AUP_APPROVE');
        if ($row2->status) {
            // already approved !
            $approved = "<img src=\"" . Uri::base(true) . "/components/com_userpoints/assets/images/icon-16-allowinactive.png\" border=\"0\" title=\"" . Text::_('AUP_ALREADY_APPROVED') . "\" alt=\"" . Text::_('AUP_ALREADY_APPROVED') . "\" /></a>";
        } else {
            $approved = '<img src="' . Uri::base(true) . '/components/com_userpoints/assets/images/' . $imgA . '" border="0" alt="' . $altA . '" />';
        }
        $style = ( $row2->points < 0 ) ? 'style="color:red;"' : '';

        echo <<<TABLE_ELEMENT
                    
                    <tr class="row{$show($i % 2)}" $style>
                        <td>
                            {$show($i + 1 + $this->pagination->limitstart)}
                        </td>
                        <!--<td align="center">
                            {$show(HTMLHelper::_('grid.id', $i, $row2->id))}
                        </td>-->
                        <td>				
                            <i class="icon-calendar"></i>
                            {$this->displayDateTime($row2->insert_date)}
                        </td>				
                        <td>
                            {$show(Text::_($row2->rule_name))}					
                        </td>
                        <td align="center">
                            {$this->getFormattedPointsAdm($row2->points)}
                        </td>
                        <td align="center">
                            <i class="icon-calendar"></i>
                            {$this->displayDateTime($row2->expire_date)}
                        </td>
                        <td align="center">
                            $approved
                        </td>
                        <td>				
                            $row2->datareference
                        </td>
                    </tr>
                                    
TABLE_ELEMENT;
    }
    $cid = $row2->id;
    $c2id = $row2->referreid;
}

else {
    echo <<<NO_ACTIVITY
    
                    <tr class="row0">
                        <td colspan="6">
                            {$show(Text::_('AUP_NO_ACTIVITY'))}
                        </td>
                    </tr>
    
NO_ACTIVITY;

    $cid = $this->row->id;
    $c2id = $this->row->referreid;
}


echo <<<FORM_FOOT

            </tbody>
        </table>
        <input type = "hidden" name = "option" value = "com_userpoints" />
        <input type = "hidden" name = "task" value = "edituser" />
        <input type = "hidden" name = "cid" value = "$cid" />
        <input type = "hidden" name = "c2id" value = "$c2id" />
        <input type = "hidden" name = "name" value = "{$this->row->name}" />
        <input type = "hidden" name = "boxchecked" value = "0" />
    </form>
    <a href = "index.php?option=com_userpoints&task=showdetails&cid={$this->row->referreid}&name={$this->row->name}">
        {$show(Text::_('AUP_SHOW_DETAIL_ACTIVITIES'))}
    </a>
</div>

FORM_FOOT;
