<?php
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\HTML\HTMLHelper;
/**
 * @version        5.6.3
 * @package        Joomla
 * @subpackage     Joom Donation
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2009 - 2023 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;
$percent            =  100 - DonationHelper::getConfigValue('percent_commission') ;
$bootstrapHelper    = $this->bootstrapHelper;
$rowFluidClass   	= $bootstrapHelper->getClassMapping('row-fluid');
$span12Class   	    = $bootstrapHelper->getClassMapping('span12');
$span8Class   	    = $bootstrapHelper->getClassMapping('span8');
$span4Class   	    = $bootstrapHelper->getClassMapping('span4');
?>
<div class="<?php echo $rowFluidClass?>">
    <div class="<?php echo $span8Class;?>">
        <h1 class="jd-title"><?php echo $this->page_heading;?></h1>
    </div>
	<?php
	if(Factory::getUser()->authorise('core.manage','com_jdonation'))
	{
	?>
		<div class="<?php echo $span4Class; ?> donorstoolbar">
			<a href="index.php?option=com_jdonation&task=export" class="btn btn-primary">
			<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16">
			  <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/>
			  <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/>
			</svg>
			&nbsp;<?php echo Text::_('JD_EXPORT_DONORS')?></a>
		</div>
	<?php
	}	
	?>
</div>
<form action="<?php echo Route::_('index.php?option=com_jdonation&view=donors&Itemid='.$this->Itemid); ?>" method="post" name="adminForm" id="adminForm">
<?php
if($this->config->use_campaign)
{
?>
	<div class="<?php echo $rowFluidClass?> donors_filter_campaigns">
		<div class="<?php echo $span12Class;?>">
			<?php
			echo $this->lists['campaign_id'];
			?>
		</div>
	</div>
<?php
}	
?>
	<div class="<?php echo $rowFluidClass?>">
		<div class="<?php echo $span12Class;?>">
			<table class="table table-striped table-bordered table-condensed" id="table-donors">
				<thead>
					<tr>
						<th width="40%">
							<?php echo Text::_('JD_DONOR') ; ?>
						</th>
						<th>
							<?php echo Text::_('JD_CAMPAIGN') ?>
						</th>
						<th>
							<?php echo Text::_('JD_DONATION_DATE') ; ?>
						</th>
						<th>
							<?php echo Text::_('JD_DONATION_AMOUNT') ; ?>
						</th>
					</tr>
				</thead>
				<tbody>
				<?php
					for ($i = 0 , $n = count($this->items) ; $i < $n ; $i++)
					{
						$row = $this->items[$i] ;
						if ($row->hide_me == 1)
						{
							$row->first_name = Text::_('JD_ANONYMOUS');
							$row->last_name = '' ;
						}
					?>
						<tr>
							<td data-label="<?php echo Text::_('JD_FIRST_NAME') ; ?>">
								<strong><?php echo $row->first_name; ?>&nbsp;<?php echo $row->last_name ; ?></strong>
								<?php
								if($row->show_dedicate == 1 && $this->config->activate_tributes){
									echo DonationHelper::getDedicateType($row->dedicate_type)." <strong>".$row->dedicate_name."</strong>";
								}
								?>
							</td>
							<td data-label="<?php echo Text::_('JD_CAMPAIGN') ; ?>">
								<?php echo $row->title; ?>
							</td>
							<td data-label="<?php echo Text::_('JD_DONATION_DATE') ; ?>">
								<?php echo  HTMLHelper::_('date', $row->created_date, $this->config->date_format, null); ?>
							</td>
							<td data-label="<?php echo Text::_('JD_DONATION_AMOUNT') ; ?>">
								<?php 
								if(DonationHelper::isMultipleCurrencies())
								{
									if(($row->amount_converted > 0) && ($row->currency_converted != $row->currency_code) && $row->currency_converted !='' )
									{
										$show_amount = 1;
										
										echo number_format($row->amount_converted , 2);
										echo "&nbsp;";
										echo $row->currency_converted;
										?>
										<div class="clearfix"></div>
										<?php
										
										if($this->config->convert_currency_before_donation)
										{
											$show_amount = 1;
											
											echo number_format($row->amount , 2);
											echo "&nbsp;";
											if($row->currency_code != "")
											{
												echo $row->currency_code;
											}
											else
											{
												echo $this->config->currency;
											}
												
										}
									}
									else
									{
										$show_amount = 1;
										
										echo number_format($row->amount , 2);
										echo "&nbsp;";
										if($row->currency_code != "")
										{
											echo $row->currency_code;
										}
										else
										{
											echo $this->config->currency;
										}
											
									}
								}

								if($show_amount == 0)
								{
									
									echo number_format($row->amount , 2);
									echo "&nbsp;";
									if($row->currency_code != "")
									{
										echo $row->currency_code;
									}
									else
									{
										echo $this->config->currency;
									}
										
								}	
								
								?>
							</td>
						</tr>
					<?php
					}
					if ($this->pagination->total > $this->pagination->limit)
					{
					?>
						<tr>
							<td colspan="5" align="center">
								<div class="pagination"><?php echo $this->pagination->getPagesLinks(); ?></div>
							</td>
						</tr>
					<?php
					}
				?>
				</tbody>
			</table>
		</div>
	</div>
</form>
