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

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

use Joomla\CMS\Language\Text;
use BlackSheepResearch\Component\UserPoints\Site\UserPoints;
use BlackSheepResearch\Component\UserPoints\Site\Problems\SQL;

$user =  UserPoints::getUser();
?>
<?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; ?>
<?php
if ( $this->latestactivity ) {
?>
	<table class="category table table-striped table-bordered table-hover">
	<tbody>
<?php
		$i=0;
		foreach ($this->latestactivity as $activity) {
			$_user_info = UserPoints::getUserInfo ( $activity->referreid );
			$linktoprofil = getProfileLink( $this->linkToProfile, $_user_info );
			?>
		<tr class="cat-list-row<?php echo $i % 2; ?>">
			<?php
			if ( $this->useAvatarFrom && $this->params->get( 'showAvatar', 0)) {
				$avatar = getAvatar( $this->useAvatarFrom, $_user_info, $this->params->get( 'heightAvatar', '48' ) );
				// add link to profil if need
				$startprofil = '<a href="#" class="thumbnail">';
				$endprofil   = '</a>';
				if ( $this->params->get( 'show_links_to_users', 1) && $user->id || $this->params->get( 'show_links_to_users', 1) && !$user->id && $this->allowGuestUserViewProfil ){
					$startprofil =  '<a href="' . $linktoprofil . '" class="thumbnail">';
					$endprofil   =  '</a>';
				}
				?>
				<td headers="categorylist_header_title" class="list-title">
				<?php
				echo $startprofil.$avatar.$endprofil;
				?></td>
				<?php
			}
			?>
				<td headers="categorylist_header_title" class="list-title">
						<b>
						<?php
						// insert icon category if exist
						if ( $this->params->get( 'showIconCategory', 1) && $activity->category!='' ) {
							echo _getIconCategoryRule( $activity->category ) . '&nbsp;' ;
						}
						echo Text::_( $activity->rule_name);
						?>
						</b>
						<br />
						<?php
						switch ( $activity->plugin_function ) {
							case 'sysplgup_dailylogin':
								echo $this->presentDate('date', $activity->datareference, Text::_('DATE_FORMAT_LC1') );
								break;
							case 'plgaup_getcouponcode_vm':
							case 'plgaup_alphagetcouponcode_vm':
							case 'sysplgup_buypointswithpaypal':
								echo  '';
								break;
							default:
								echo $activity->datareference;
						}
						?>
						<br /><b>
						<?php
						if ( $this->params->get( 'show_links_to_users', 1) && $user->id || $this->params->get( 'show_links_to_users', 1) && !$user->id && $this->allowGuestUserViewProfil ){
							$profil =  "<a href=\"" . $linktoprofil . "\">" . $activity->usrname . "</a>";
						} else $profil = $activity->usrname ;
						echo $profil;
						 ?>
						</b>
						<span>
						<?php echo SQL::nicetime($activity->insert_date); ?>
						</span>
				</td>
				<td headers="categorylist_header_title" class="list-title">
					<?php
						$points_color = '';
						if ($activity->last_points >0)
						$points_color = 'badge badge-info';
						if ($activity->last_points<0)
						$points_color = 'badge badge-warning';
						if ($activity->last_points==0)
						$points_color = 'badge';
					?>
						<span class="<?php echo $points_color ; ?>">
						<?php
						$s = '';
						if($activity->last_points > 1)
							$s = 'S';

						echo getFormattedPoints( $activity->last_points ) . " " . Text::_( 'AUP_POINT'.$s ); ?>

                        </span>
				</td>
			</tr>
		<?php
			$i++;
		} // end foreach
		?>
			</tbody>
		</table>
		<?php
		echo '<div class="pagination">';
		echo $this->pagination->getPagesCounter().'<br />';
		echo $this->pagination->getPagesLinks();
		echo '</div>';
} // end if latest activities

	/**
	*
	*  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 ();
