<?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\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\HTML\HTMLHelper;
use BlackSheepResearch\Component\UserPoints\Site\UserPoints;
use BlackSheepResearch\Component\UserPoints\Site\Problems\SQL;

$app = Factory::getApplication();

$rows = $this->top10;
$rowsPA = $this->unapproved10;
$rowsLA = $this->lastactivities;

if ($this->needSync && $this->synch != 'start') {
    $error = Text::_('AUP_MSG_NEEDSYNCUSERS');
    $app->enqueueMessage($error, 'notice');
}

if ($this->synch == 'end') {
    $app->enqueueMessage(Text::_('AUP_ALLUSERSSYNC'));
} elseif ($this->synch != 'start' && $this->synch != 'end' && $this->synch != '') {
    $app->enqueueMessage($this->synch);
}

if ($this->recalculate == 'end') {
    $app->enqueueMessage(Text::_('AUP_SUCCESSFULLYRECALCULATE'));
} elseif ($this->recalculate != 'start' && $this->recalculate != 'end' && $this->recalculate != '') {
    $app->enqueueMessage($this->recalculate);
}

if (!function_exists('curl_init')) {
    $app->enqueueMessage(Text::_('AUP_CURLMUSTBEENABLE'), 'notice');
}

$template = $app->getTemplate();
?>
<script type="text/javascript">
<!--
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
        if (init == true)
            with (navigator) {
                if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
                    document.MM_pgW = innerWidth;
                    document.MM_pgH = innerHeight;
                    onresize = MM_reloadPage;
                }
            }
        else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH)
            location.reload();
    }
    MM_reloadPage(true);


    Joomla.submitbutton = function (task)
    {
        //if (task == 'cancelrule' || document.formvalidator.isValid(document.id('cpanel-form'))) {
        Joomla.submitform(task, document.getElementById('cpanel-form'));
        //}
        //else {
        //alert('<?php echo $this->escape(Text::_('JGLOBAL_VALIDATION_FORM_FAILED')); ?>');
        //}
    }
//-->
</script>
<?php
// force new style for icon
echo '<style type="text/css">
	a.thumbnail:hover {
    border-color: #59B8E8;
    box-shadow: 0 0 2px 2px rgba(0, 105, 214, 0.25);
}
</style>
';
?>
<div id="j-main-container">
    <div class="span7">
        <div id="cpanel">
            <?php
            $javascript_alert_no_auth = "onclick=\"return alert('" . Text::_('JERROR_ALERTNOAUTHOR') . "')\"";

            if (UserPoints::getUser()->authorise('core.rules', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=rules';
                $this->aup_createIconPanel($link, 'aupbe-icon-list', Text::_('AUP_RULES'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-list', Text::_('AUP_RULES'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.users', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=statistics';
                $this->aup_createIconPanel($link, 'aupbe-icon-users', Text::_('AUP_USERS'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-users', Text::_('AUP_USERS'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.activity', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=activities';
                $this->aup_createIconPanel($link, 'aupbe-icon-activity', Text::_('AUP_ACTIVITY'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-activity', Text::_('AUP_ACTIVITY'), $javascript_alert_no_auth);
            }


            if (UserPoints::getUser()->authorise('core.templatesinvite', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=templateinvite';
                $this->aup_createIconPanel($link, 'aupbe-icon-templates', Text::_('AUP_TEMPLATES_INVITE'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-templates', Text::_('AUP_TEMPLATES_INVITE'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.usersynch', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=usersync';
                $javascript_sync_users = "onclick=\"return confirm('" . Text::_('AUP_CONFIRM_STARTPROCESS') . "')\"";
                $this->aup_createIconPanel($link, 'aupbe-icon-sync', Text::_('AUP_USERSYNC'), $javascript_sync_users);
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-sync', Text::_('AUP_USERSYNC'), $javascript_alert_no_auth);
            }


            if (UserPoints::getUser()->authorise('core.recalculate', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=recalculate';
                $javascript_recalculate_points = "onclick=\"return confirm('" . Text::_('AUP_CONFIRM_STARTPROCESS') . "')\"";
                $this->aup_createIconPanel($link, 'aupbe-icon-recalc', Text::_('AUP_RECALCULATE'), $javascript_recalculate_points);
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-recalc', Text::_('AUP_RECALCULATE'), $javascript_alert_no_auth);
            }


            if (UserPoints::getUser()->authorise('core.resetallpoints', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=resetpoints';
                $javascript_reset_points = "onclick=\"return confirm('" . Text::_('AUP_DO_YOU_WANT_RESET_ALL_POINTS') . "')\"";
                $this->aup_createIconPanel($link, 'aupbe-icon-reset', Text::_('AUP_RESETPOINTS'), $javascript_reset_points);
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-reset', Text::_('AUP_RESETPOINTS'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.setmaxpoints', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=setmaxpoints';
                $this->aup_createIconPanel($link, 'aupbe-icon-maxpoints', Text::_('AUP_SETMAXPOINST'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-maxpoints', Text::_('AUP_SETMAXPOINST'), $javascript_alert_no_auth);
            }


            if (UserPoints::getUser()->authorise('core.purgeexpiredpoints', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=purge';
                $this->aup_createIconPanel($link, 'aupbe-icon-purgexpire', Text::_('AUP_PURGEEXPIRESPOINTS'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-purgexpire', Text::_('AUP_PURGEEXPIRESPOINTS'), $javascript_alert_no_auth);
            }


            if (UserPoints::getUser()->authorise('core.categories', 'com_userpoints')) {
                $link = "index.php?option=com_categories&view=categories&extension=com_userpoints";
                $this->aup_createIconPanel($link, 'aupbe-icon-categories', Text::_('JCATEGORIES'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-categories', Text::_('JCATEGORIES'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.couponcodes', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=couponcodes';
                $this->aup_createIconPanel($link, 'aupbe-icon-coupon', Text::_('AUP_COUPON_CODES'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-coupon', Text::_('AUP_COUPON_CODES'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.raffles', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=raffle';
                $this->aup_createIconPanel($link, 'aupbe-icon-raffle', Text::_('AUP_RAFFLE'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-raffle', Text::_('AUP_RAFFLE'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.levelrank', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=levelrank';
                $this->aup_createIconPanel($link, 'aupbe-icon-ranks', Text::_('AUP_LEVEL_RANK'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-ranks', Text::_('AUP_LEVEL_RANK'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.viewstats', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=stats';
                $this->aup_createIconPanel($link, 'aupbe-icon-stats', Text::_('AUP_STATISTICS'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-stats', Text::_('AUP_STATISTICS'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.exportactiveusers', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=exportactiveusers';
                $this->aup_createIconPanel($link, 'aupbe-icon-exportusers', Text::_('AUP_EXPORTACTIVEUSERS'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-exportusers', Text::_('AUP_EXPORTACTIVEUSERS'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.exportemails', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=exportemails';
                $this->aup_createIconPanel($link, 'aupbe-icon-exportmail', Text::_('AUP_EXPORTEMAILS'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-exportmail', Text::_('AUP_EXPORTEMAILS'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.combineactivities', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=archiveActivities';
                $this->aup_createIconPanel($link, 'aupbe-icon-combine', Text::_('AUP_COMBINE_ACTIVITIES'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-combine', Text::_('AUP_COMBINE_ACTIVITIES'), $javascript_alert_no_auth);
            }

            if (UserPoints::getUser()->authorise('core.reportsystem', 'com_userpoints')) {
                $link = 'index.php?option=com_userpoints&task=reportsystem';
                $this->aup_createIconPanel($link, 'aupbe-icon-report', Text::_('AUP_REPORT_SYSTEM'));
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-report', Text::_('AUP_REPORT_SYSTEM'), $javascript_alert_no_auth);
            }
            if (UserPoints::getUser()->authorise('core.plugins', 'com_userpoints') && USERPOINTS_SHOW_DEPRECATED_PLUGIN_INSTALL == '1') {
                $link = 'index.php?option=com_userpoints&task=plugins';
                $this->aup_createIconPanel($link, 'aupbe-icon-link', Text::_('AUP_PLUGINS'));
            } elseif (!UserPoints::getUser()->authorise('core.plugins', 'com_userpoints') && USERPOINTS_SHOW_DEPRECATED_PLUGIN_INSTALL == '1') {
                $link = '';
                $this->aup_createIconPanel($link, 'aupbe-icon-link', Text::_('AUP_PLUGINS'), $javascript_alert_no_auth);
            }

            // auto-detect rules in third components, plugins and modules
            $msg = Text::_('AUP_NONE');
            if (UserPoints::getUser()->authorise('core.autodetectplugins', 'com_userpoints')) {
                if (!Factory::getApplication()->input->get('scanAUPRules', 0, 'int')) {
                    $link = 'index.php?option=com_userpoints&task=cpanel&scanAUPRules=1';
                    $this->aup_createIconPanel($link, 'aupbe-icon-autodetect', Text::_('AUP_AUTODETECTPLUGINS'));
                } else {
                    $aup_rule_files = array(
                        'userpoints_rule.xml',
                        'altauserpoints_rule.xml',
                        'alphauserpoints_rule.xml'
                    );

                    jimport('joomla.filesystem.file');
                    jimport('joomla.filesystem.folder');

                    $pathToScan = array(0 => 'components',
                        1 => 'modules',
                        2 => 'plugins');

                    foreach ($pathToScan as $scan) {
                        $scan_path = JPATH_ROOT . '/' . $scan;

                        if (!is_dir($scan_path)) {
                            continue;
                        }

                        $scan_folders = Folder::folders($scan_path, '.', true, true);

                        $count = 0;

                        foreach ($scan_folders as $folder) {
                            foreach ($aup_rule_files as $aup_rule_file) {
                                $xmlRuleFile = $folder . '/' . $aup_rule_file;

                                if (file_exists($xmlRuleFile)) {
                                    $parser = simplexml_load_file($xmlRuleFile);
                                    if ($parser AND in_array($parser->getName(), ['userpoints', 'altauserpoints', 'alphauserpoints']) AND !empty($parser->rules->rule)) {
                                        $component = (string)$parser->component;
                                        foreach ($parser->rules->rule as $rule) {
                                            $nameRule = addslashes((string)$rule->name);
                                            $descriptionRule = addslashes((string)$rule->description);
                                            $pluginRule = (string)$rule->plugin_function;
                                            $fixed_points = intval(empty($rule->fixed_points) OR 'true' === trim(strtolower($rule->fixed_points)));
                                            $percentage = intval(empty(!$rule->percentage) AND 'true' === trim(strtolower($rule->percentage)));
                                            $allow_referral = intval(empty($rule->allow_referral) OR 'true' === trim(strtolower($rule->allow_referral)));
                                            $category = (empty((string)$rule->category)) ? 'ot' : (string)$rule->category;
                                            $display_message = (empty($rule->display_message)) ? 1 : intval($rule->display_message);
                                            $email_notification = (empty($rule->email_notification)) ? 0 : intval($rule->email_notification);
                                            $method = (empty($rule->method)) ? 0 : intval($rule->method);

                                            // insert in AUP table if not exist
                                            if ($nameRule != '' && $descriptionRule != '' && $pluginRule != '') {

                                                $db = SQL::getInstance();
                                                // check if already exist...
                                                $query = "SELECT COUNT(*) FROM #__alpha_userpoints_rules WHERE `plugin_function` = {$db->quote($pluginRule)}";
                                                $db->setQuery($query);
                                                $resultCount = $db->loadResult();
                                                if (!$resultCount) {
                                                    $query = "INSERT INTO #__alpha_userpoints_rules VALUES (0, {$db->quote($nameRule)}, {$db->quote($descriptionRule)}, {$db->quote($component)}, {$db->quote($pluginRule)}, 0, {$db->quote($component)}, '', '', 0.0, 0.0, $percentage, '1000-01-01 00:00:00', '', '', '', '', 0, 0, 0, 0, 1, $fixed_points, $allow_referral, {$db->quote($category)}, $display_message, '', $method, $email_notification, '', '', 0, 0, 0, 0, 0, 1 )";
                                                    $db->setQuery($query);
                                                    if ($db->execute()) {
                                                        $count++;
                                                    }
                                                }
                                            }
                                        }//end foreach


                                        if ($count) {
                                            $msg = Text::_('AUP_NEW_RULE_INSTALLED_SUCCESSFULLY') . " (" . $count . ")";
                                            $app->enqueueMessage($msg);
                                        } else {
                                            $msg = Text::_('AUP_NONE');
                                        }
                                    }
                                }
                            }
                        }
                    }

                    $link = 'index.php?option=com_userpoints&task=cpanel&scanAUPRules=1';
                    $this->aup_createIconPanel($link, 'auto-detect-rules.png', $msg);
                }
            } else {
                $link = '';
                $this->aup_createIconPanel($link, 'auto-detect-rules_2.png', Text::_('AUP_AUTODETECTPLUGINS'), $javascript_alert_no_auth);
            }
            $msg = '';

            // TODO -> import export feature
            /*
              $link = 'index.php?option=com_userpoints&task=importexportTableActivities';
              $this->aup_createIconPanel($link, 'icon-48-exportcsv.png', Text::_('AUP_IMPORT_EXPORT'));
             */

            $link = 'index.php?option=com_userpoints&task=about';
            $this->aup_createIconPanel($link, 'aupbe-icon-info', Text::_('AUP_ABOUT'));

            $link = '#';
            if (file_exists(JPATH_COMPONENT . "/help/" . $this->tag . "/screen.how_create_plugin.html")) {
                $javascript = "onclick=\"Joomla.popupWindow('components/com_userpoints/help/" . $this->tag . "/screen.how_create_plugin.html', 'Help', 640, 480, 1)\"";
            } else
                $javascript = "onclick=\"popupWindow('components/com_userpoints/help/en-GB/screen.how_create_plugin.html', 'Help', 640, 480, 1)\"";
            $this->aup_createIconPanel($link, 'aupbe-icon-howto', Text::_('AUP_HOWTO'), $javascript);

            $link = 'https://remository.com/downloads/User-Points/';
            $this->aup_createIconPanel($link, 'aupbe-icon-ruleslist', Text::_('AUP_MORERULES'));

            $javascript = "";
            $link = '#';
            if (file_exists(JPATH_COMPONENT . "/help/" . $this->tag . "/screen.userpoints.html")) {
                $javascript = "onclick=\"Joomla.popupWindow('components/com_userpoints/help/" . $this->tag . "/screen.userpoints.html', 'Help', 640, 480, 1)\"";
            } else
                $javascript = "onclick=\"popupWindow('components/com_userpoints/help/en-GB/screen.userpoints.html', 'Help', 640, 480, 1)\"";
            $this->aup_createIconPanel($link, 'aupbe-icon-help', Text::_('HELP'), $javascript);

            // add new button module position
            $document = Factory::getDocument();
            $renderer = $document->loadRenderer('modules');
            $options = array('style' => 'none');
            echo $renderer->render('UserPoints CPanel', $options, null);

            $link4welcome = "<a href=\"#\" $javascript>";
            $endlinkwelcome = "</a>";
            ?>
        </div>
        <div class="clearfix"></div>
    </div>

    <div class="span5">
        <div class="well"><h2><?php echo Text::_('AUP_TOTAL_COMMUNITY_POINTS') . ":&nbsp;&nbsp;" . $this->getFormattedPointsAdm($this->communitypoints); ?></h2></div>
            <?php
            echo $this->pane->startPane("content-pane");

            echo $this->pane->startPanel(Text::_('AUP_WELCOMETOBETAUSERPOINTS'), "cpanel-panel-welcome");
            echo Text::sprintf('AUP_WELCOMEPANELTEXT', $link4welcome, $endlinkwelcome);
            $sqldate = SQL::datetimeSQL();
            echo Text::sprintf('AUP_SYSTEM_DATE_INFO', $sqldate);

            echo $this->pane->endPanel();

            echo $this->pane->startPanel(Text::_('AUP_HIGHT_SCORE'), "cpanel-panel-usersawards");

            if ($rows) {
                ?>
            <table class="table table-bordered table-striped table-hover table-condensed">
                <tr>
                    <td class="title">
                        <strong><?php echo Text::_('AUP_NAME'); ?></strong>
                    </td>
                    <td class="title">
                        <strong><?php echo Text::_('AUP_USERNAME'); ?></strong>
                    </td>
                    <td class="title">
                        <strong><?php echo Text::_('AUP_POINTS'); ?></strong>
                    </td>
                </tr>
            <?php
            foreach ($rows as $row) {
                ?>
                    <tr>
                        <td>
        <?php echo htmlspecialchars($row->name, ENT_QUOTES, 'UTF-8'); ?>
                        </td>
                        <td>
        <?php echo $row->username; ?>
                        </td>
                        <td align="right">
        <?php echo $this->getFormattedPointsAdm($row->points); ?>
                        </td>
                    </tr>
                    <?php
                }
                ?>
            </table>

    <?php
}
echo $this->pane->endPanel();

// Last activity
echo $this->pane->startPanel(Text::_('AUP_LASTACTIVITY'), "cpanel-panel-latest-activities");

if ($rowsLA) {
    ?>
            <table class="table table-bordered table-striped table-hover table-condensed">
                <tr>
                    <td class="title">
                        <strong><?php echo Text::_('AUP_DATE'); ?></strong>
                    </td>
                    <td class="title">
                        <strong><?php echo Text::_('AUP_RULENAME'); ?></strong>
                    </td>
                    <td class="title">
                        <strong><?php echo Text::_('AUP_NAME'); ?></strong>
                    </td>
                    <td class="title">
                        <strong><?php echo Text::_('AUP_USERNAME'); ?></strong>
                    </td>
                    <td class="title">
                        <strong><?php echo Text::_('AUP_POINTS'); ?></strong>
                    </td>
                </tr>
    <?php
    foreach ($rowsLA as $rowLA) {
        ?>
                    <tr>
                        <td>
        <?php echo SQL::nicetime($rowLA->insert_date); ?>
                        </td>
                        <td>
        <?php echo Text::_($rowLA->rule_name); ?>
                        </td>
                        <td>
        <?php
        $linkLA = "<a href=\"index.php?option=com_userpoints&task=showdetails&cid=" . $rowLA->referreid . "&name=" . htmlspecialchars($rowLA->uname, ENT_QUOTES, 'UTF-8') . "\">";
        echo $linkLA . htmlspecialchars($rowLA->uname, ENT_QUOTES, 'UTF-8') . "</a>";
        ?>
                        </td>
                        <td>
        <?php echo $rowLA->usrname; ?>
                        </td>
                        <td align="right">
        <?php echo $this->getFormattedPointsAdm($rowLA->last_points); ?>
                        </td>
                    </tr>
        <?php
    }
    ?>
            </table>
                        <?php
                    }

                    echo $this->pane->endPanel();

                    // pending approval
                    $nb = ( $rowsPA ) ? ' <span class="badge badge-important">' . $this->totalunapproved . '</span>' : ' <span class="badge badge-success">0</span>';

                    echo $this->pane->startPanel(Text::_('AUP_PENDING_APPROVAL') . $nb, "cpanel-panel-pending-approval");

                    if ($rowsPA) {
                        ?>
            <form action="index.php" method="post" name="adminForm">
                <table class="table table-bordered table-striped table-hover table-condensed">
                    <tr>
                        <td width="3%" class="title">
                            <input type="checkbox" name="checkall-toggle" value="" title="<?php echo Text::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
                        </td>
                        <td class="title">
                            <strong><?php echo Text::_('AUP_DATE'); ?></strong>
                        </td>
                        <td class="title">
                            <strong><?php echo Text::_('AUP_RULENAME'); ?></strong>
                        </td>
                        <td class="title">
                            <strong><?php echo Text::_('AUP_NAME'); ?></strong>
                        </td>
                        <td class="title">
                            <strong><?php echo Text::_('AUP_USERNAME'); ?></strong>
                        </td>
                        <td class="title">
                            <strong><?php echo Text::_('AUP_POINTS'); ?></strong>
                        </td>
                        <td class="title">&nbsp;

                        </td>
                    </tr>
    <?php
    $k = 0;
    for ($i = 0, $n = count($rowsPA); $i < $n; $i++) {
        $rowPA = & $rowsPA[$i];
        ?>
                        <tr>
                            <td align="center">
        <?php echo HTMLHelper::_('grid.id', $i, $rowPA->cid); ?>
                            </td>
                            <td>
        <?php echo $rowPA->insert_date; ?>
                            </td>
                            <td>
                        <?php echo Text::_($rowPA->rule_name); ?>
                            </td>
                            <td>
                        <?php
                        $linkPA = "<a href=\"index.php?option=com_userpoints&task=showdetails&cid=" . $rowPA->referreid . "&name=" . htmlspecialchars($rowPA->name, ENT_QUOTES, 'UTF-8') . "\">";

                        echo $linkPA . htmlspecialchars($rowPA->name, ENT_QUOTES, 'UTF-8') . "</a>";
                        ?>
                            </td>
                            <td>
                                <?php echo $rowPA->username; ?>
                            </td>
                            <td align="right">
                                <?php echo $this->getFormattedPointsAdm($rowPA->pendingapprovalpoints); ?>
                            </td>
                            <td>
                                <?php
                                $linkDeletePA = '<a href="index.php?option=com_userpoints&task=deletependingapproval&cid=' . $rowPA->cid . '">';
                                echo $linkDeletePA . '<img src="' . Uri::base(true) . '/components/com_userpoints/assets/images/trash-16.png" alt="" style="vertical-align:middle;" /></a>';
                                ?>
                            </td>
                        </tr>
                                <?php
                            }
                            ?>
                </table>
                <table class="adminform">
                    <tr>
                        <td>
                            <input type="submit" name="Submit" value="<?php echo Text::_('AUP_APPROVE'); ?>">
                        </td>
                    </tr>
                </table>
                <input type="hidden" name="option" value="com_userpoints" />
                <input type="hidden" name="task" value="approve" />
                <input type="hidden" name="table" value="alpha_userpoints_details" />
                <input type="hidden" name="redirect" value="cpanel" />
                <input type="hidden" name="boxchecked" value="0" />
            </form>
                    <?php
                } else
                    echo "<p>" . Text::_('AUP_NO_PENDING_APPROVAL') . "</p>";


                echo $this->pane->endPanel();

                // add new slider module position
                $document = Factory::getDocument();
                $renderer = $document->loadRenderer('modules');
                $options = array('style' => 'none');
                echo $renderer->render('UserPoints CPanel Slider', $options, null);

                echo $this->pane->endPane();
                ?>
    </div>
    <div class="clearfix"></div>

    <div align="center">
        <form action="index.php" method="post" name="cpanel-form" id="cpanel-form" class="form-validate">
            <input type="hidden" name="option" value="com_userpoints" />
            <input type="hidden" name="task" value="cpanel" />
        </form>
    </div>
</div>
