<?php
/*
 * @component UserPoints, Copyright (C) 2015-2022 Bernard Gilly - Adrien Roussel - Martin Brampton
 * @copyright Copyright (C) 2011 Mike Gusev (migus) - Updated by Bernard Gilly - Adrien Roussel for full compatibility Joomla 3.1.x on June 2013
 * @license : GNU/GPL
 * @Website : http://migusbox.com
 */

 // no direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Language\Text;

?>
<?php if ($this->params->get('show_page_heading',0)) : ?>
	<div class="page-header">
		<h1><?php echo $this->escape($this->params->get('page_heading','')); ?></h1>
	</div>
<?php endif; ?>
<div class="table-responsive">
	<table class="category table table-striped table-bordered table-hover">
	<thead>
			<tr>
<?php if ( $this->params->get( 'show_caticon', 1 ) ) { ?>
				<th id="caticon_header_title">
				</th>
<?php } ?>
				<th id="rulename_header_title">
					<?php echo Text::_('AUP_RULE_NAME'); ?>
				</th>
<?php if ( $this->params->get( 'show_desc', 1 ) ) { ?>
				<th id="ruledesc_header_title">
					<?php echo Text::_( 'AUP_RULE_DESC' ); ?>
				</th>
<?php } ?>
				<th id="points_header_title">
					<?php echo Text::_( 'AUP_POINTS' ); ?>
				</th>
<!--
<?php	if ( $this->params->get( 'show_published', 1 ) ) {?>
				<th id="published_header_title">
					<?php echo Text::_( 'AUP_RULEACTIVITY' ); ?>
				</th>
<?php } ?>
-->
<?php	if ( $this->params->get( 'show_approve', 1 ) ) {?>
		<th id="approve_header_title">
					<?php echo Text::_( 'AUP_RULEAPPROVAL' ); ?>
		</th>
<?php } ?>
		</tr>
	</thead>
		<tbody>
		<?php
                        $i = 0;
			foreach ($this->rules as $row)
			{

			?>
			<tr class="cat-list-row<?php echo $i % 2; ?>" >

<?php if ( $this->params->get( 'show_caticon', 1 ) ) { ?>
				<td headers="categorylist_header_title" class="list-title">
					<?php echo _getIconCategoryRule( $row->category ); ?>
				</td>
<?php } ?>
				<td headers="categorylist_header_title" class="list-title">
					<?php echo Text::_( $row->rule_name ); ?>
				</td>
<?php if ( $this->params->get( 'show_desc', 1 ) ) { ?>
				<td headers="categorylist_header_title" class="list-title">
					<?php echo Text::_( $row->rule_description ); ?>
				</td>
<?php } ?>
				<td headers="categorylist_header_title" class="list-title">
					<?php
					if ( $row->points || $row->points2 ) {
						$points = $row->points;
						$points2 = $row->points2;
						if ($row->points >0|| $row->points2 >0)
						$points_color = 'badge badge-info';
						if ($row->points <0 || $row->points2 <0)
						$points_color = 'badge badge-warning';
						if ($row->points==0 && $row->points2==0)
						$points_color = 'badge';
					?>
					<span class="<?php echo $points_color ; ?>">
					<?php switch ( $row->plugin_function ) {
						case 'sysplgup_referralpoints':
							echo getFormattedPoints( $points ) . " %";
							break;
						case 'sysplgup_unlockmenus':
						case (substr($row->plugin_function, 0, 21) == 'sysplgup_unlockmenus'):
							echo getFormattedPoints( $points2 );
							break;
						default:
							echo getFormattedPoints( $points ); ?>
					<?php } ?>
					</span>
					<?php
					} else 	echo '-';
					?>
					<?php if( !$row->published ) { ?>
					<span class="badge badge-warning">
					<?php echo Text::_( 'AUP_RULEINACTIVE' ); ?>
					</span>
					<?php } ?>
				</td>
<!--
<?php	if ( $this->params->get( 'show_published', 1 ) ) {?>
				<td headers="categorylist_header_title" class="list-title">
					<?php
						$icon = ( $row->published )? 'tick.png' : 'publish_x.png' ;
						$alt = ( $row->published )? 'AUP_RULEACTIVE' : 'AUP_RULEINACTIVE' ;
					?>
					<img src="components/com_userpoints/assets/images/<?php echo $icon; ?>" border="0" title="<?php echo Text::_( $alt ); ?>" alt="<?php echo Text::_( $alt ); ?>" />
				</td>
<?php } ?>
-->
<?php	if ( $this->params->get( 'show_approve', 1 ) ) {?>
				<td headers="categorylist_header_title" class="list-title">
					<?php
						switch ( $row->plugin_function ) {
						case 'sysplgup_excludeusers':
						case 'sysplgup_emailnotification':
						case 'sysplgup_winnernotification':
						case 'sysplgup_changelevel1':
						case 'sysplgup_changelevel2':
						case 'sysplgup_changelevel3':
						case 'sysplgup_archive':
							$imgA =  'publish_y.png';
							$altA = Text::_('AUP_NOTAPPROVEDRULE');
							break;
						default:
							$imgA = $row->autoapproved ? 'publish_g.png' :'publish_r.png';
							$altA = $row->autoapproved ? Text::_( 'AUP_AUTOAPPROVEDRULE' ) : Text::_( 'AUP_ADMINAPPROVEDRULE' );
						}
						?>
						<img src="components/com_userpoints/assets/images/<?php echo $imgA; ?>" border="0" title="<?php echo Text::_( $altA ); ?>" alt="<?php echo Text::_( $altA ); ?>" />
				</td>
<?php 
                $i++;
            } ?>
			</tr>
			<?php
				}
			?>
		</tbody>
	</table>
</div>
	<div class="pagination">
	<?php
	echo $this->pagination->getPagesCounter() . "<br />" ;
	echo $this->pagination->getPagesLinks();
	?>
	</div>
<?php
	/**
	*
	*  Provide copyright on frontend
	*  If you remove or hide this line below,
	*  please make a donation if you find UserPoints useful
	*  and want to support its continued development.
	*  Your donations help by hardware, hosting services and other expenses that come up as we develop,
	*  protect and promote UserPoints and other free components.
	*
	*/
	echo $this->getCopyrightNotice ();
