<?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\HTML\HTMLHelper;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Uri\Uri;
use BlackSheepResearch\Component\UserPoints\Site\UserPoints;

//Ordering allowed ?
$ordering = ($this->lists['order_rank'] == 'ordering');

// HTMLHelper::_('behavior.formvalidation');


?>
<script type="text/javascript">
	Joomla.submitbutton = function(task)
	{
		//if (task == 'cpanel' || document.formvalidator.isValid(document.id('levelranks-form'))) {
			Joomla.submitform(task, document.getElementById('adminForm'));
		//}
		//else {
			//alert('<?php echo $this->escape(Text::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>');
		//}
	}
</script>
<div id="j-main-container">
<form action="index.php?option=com_userpoints" method="post" name="adminForm" id="adminForm" class="form-validate">
<div id="filter-bar" class="btn-toolbar">
	<table>
		<tr>
			<td align="left" width="100%">&nbsp;
				<?php //echo Text::_( 'Filter' ); ?>
				<!--<input type="text" name="search" id="search" value="<?php echo @$this->lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
				<button onclick="this.form.submit();"><?php echo Text::_( 'Go' ); ?></button>
				<button onclick="document.getElementById('search').value='';this.form.submit();"><?php echo Text::_( 'Reset' ); ?></button>-->
			</td>
			<td nowrap="nowrap" align="right">
				<select name="filter_category_id" class="inputbox" onchange="this.form.submit()">
					<option value=""><?php echo Text::_('JOPTION_SELECT_CATEGORY');?></option>
					<?php echo HTMLHelper::_('select.options', HTMLHelper::_('category.options', 'com_userpoints'), 'value', 'text', $this->lists['filter_category_id']);?>
				</select>
			</td>
		</tr>
	</table>
</div>
	<div class="clearfix"> </div>
	<table class="table table-striped">
		<thead>
			<tr>
				<th width="2%" class="title">
					<?php echo Text::_( 'NUM' ); ?>
				</th>
				<th width="3%" class="title">
					<input type="checkbox" name="checkall-toggle" value="" title="<?php echo Text::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
				</th>
				<th width="5%" class="title" >
					<?php echo Text::_('AUP_ICON'); ?>
				</th>
				<th width="10%" class="title">
					<?php echo Text::_('AUP_NAME'); ?>
				</th>
				<th class="title">
					<?php echo Text::_( 'AUP_DESCRIPTION' ); ?>
				</th>
				<th width="10%" class="title" nowrap="nowrap">
					<?php echo Text::_( 'JCATEGORY' ); ?>
				</th>
				<th width="10%" class="title" nowrap="nowrap">
					<?php echo Text::_('AUP_TYPE'); ?>
				</th>
				<th width="10%" class="title" nowrap="nowrap">
					<?php echo Text::_( 'AUP_LEVEL_POINTS' ); ?>
				</th>
				<th width="12%" class="title" nowrap="nowrap">
					<?php echo Text::_( 'AUP_IMAGE' ); ?>
				</th>
				<th width="3%" class="title" nowrap="nowrap">
					<?php echo Text::_( 'AUP_AWARDED' ); ?>
				</th>
				<th width="15%" class="title" nowrap="nowrap">
					<?php echo Text::_( 'AUP_ATTACH_TO_A_RULE' ); ?>
				</th>
				<th width="10%" class="title" nowrap="nowrap">&nbsp;
					<?php
					// echo HTMLHelper::_('grid.sort',   Text::_('AUP_REORDER'), 'ordering', @$this->lists['order_Dir_rank'], @$this->lists['order_rank'] );
						echo Text::_('AUP_REORDER');
					?>
					<?php echo HTMLHelper::_('grid.order',  $this->levelrank ); ?>
				</th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="12">
					<?php echo $this->pagination->getListFooter(); ?>
				</td>
			</tr>
		</tfoot>
		<tbody>
		<?php
			$i = $k = 0;
			$last = count( $this->levelrank )-1;

			foreach ($this->levelrank as $row)
			{
				if ($row->icon ) {
					$pathicon = Uri::root() . 'components/com_userpoints/assets/images/awards/icons/';
					$icone = '<img src="'.$pathicon . $row->icon.'" width="16" height="16" border="0" alt="" />';
				} else $icone ='';
				if ($row->image ) {
					$pathimage = Uri::root() . 'components/com_userpoints/assets/images/awards/large/';
					$image = '<img src="'.$pathimage . $row->image.'" height="32" border="0" alt="" />';
				} else $image ='';

				$typerank = ( $row->typerank ) ? Text::_( 'AUP_MEDAL' ) : Text::_( 'AUP_RANK' );

				$link 	= 'index.php?option=com_userpoints&amp;task=editlevelrank&amp;cid[]='. $row->id. '';

			?>
			<tr class="<?php echo "row$k"; ?>">
				<td>
					<?php echo $i+1+$this->pagination->limitstart;?>
				</td>
				<td align="center">
					<?php echo HTMLHelper::_('grid.id', $i, $row->id ); ?>
				</td>
				<td>
					<div align="center">
					<?php echo $icone; ?>
					</div>
				</td>
				<td>
				<?php
				if (UserPoints::getUser()->authorise('core.edit', 'com_userpoints')) {
				?>
					<a href="<?php echo $link; ?>">
				<?php
				}
				?>
						<?php echo Text::_( $row->rank ); ?>
				<?php
				if (UserPoints::getUser()->authorise('core.edit', 'com_userpoints')) {
				?>
					</a>
				<?php
				}
				?>

				</td>
				<td>
					<div align="center">
					<?php echo Text::_( $row->description ); ?>
					</div>
				</td>
				<td>
					<div align="center">
					<?php echo Text::_( $row->category_title ); ?>
					</div>
				</td>
				<td>
					<div align="center">
					<?php echo $typerank; ?>
					</div>
				</td>
				<td>
					<div align="center">
					<?php echo $this->getFormattedPointsAdm( $row->levelpoints ); ?>
					</div>
				</td>
				<td>
					<div align="center">
					<?php echo $image; ?>
					</div>
				</td>
				<td>
					<div align="center">
					<?php
					$num = ( $row->typerank ) ? $row->nummedals : $row->numrank;
					if ( $num ) {
						echo '<b><a href="index.php?option=com_userpoints&amp;task=detailrank&amp;cid='.$row->id.'&amp;typerank='.$row->typerank.'">'.$num.'</a></b>';
					} else 	{
                                            echo '-';
                                        }
					?>
					</div>
				</td>
				<td>
					<div align="center">
					<?php echo $row->rulename; ?>
					</div>
				</td>
				<td class="order">
					<span><?php echo $this->pagination->orderUpIcon( $i, $row->typerank == @$this->levelrank[$i-1]->typerank, 'orderup', Text::_( 'AUP_MOVE_UP' ), $ordering ); ?></span>
					<span><?php echo $this->pagination->orderDownIcon( $i, $n,  $row->typerank == @$this->levelrank[$i+1]->typerank, 'orderdown', Text::_( 'AUP_MOVE_DOWN' ), $ordering ); ?></span>
					<?php $disabled = $ordering ?  '' : 'disabled="disabled"'; ?>
					<input type="text" name="order[]" size="5" value="<?php echo $row->ordering; ?>" <?php echo $disabled ?> class="text_area" style="text-align: center" />
				</td>
			</tr>
			<?php
				$k = 1 - $k;
                                $i++;
				}
			?>
		</tbody>
	</table>
	<input type="hidden" name="option" value="com_userpoints" />
	<input type="hidden" name="task" value="levelrank" />
	<input type="hidden" name="table" value="alpha_userpoints_levelrank" />
	<input type="hidden" name="redirect" value="levelrank" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order_rank" value="<?php echo @$this->lists['order_rank']; ?>" />
	<input type="hidden" name="filter_order_Dir_rank" value="<?php echo @$this->lists['order_Dir_rank']; ?>" />
</form>
</div>
<div class="clr"></div>
<!-- File Upload Form -->
<form action="<?php echo Uri::base(); ?>index.php?option=com_userpoints&amp;task=upload&amp;tmpl=component&amp;<?php echo Session::getFormToken();?>=1" name="uploadForm" id="uploadForm" method="post" enctype="multipart/form-data">
<div class="width-100 fltrt">
	<fieldset class="adminform">
		<legend><?php echo Text::_( 'Upload File' ); ?> [ <?php echo Text::_( 'Max' ); ?>&nbsp;<?php echo (10000000 / 1000000); ?>M ]</legend>
		<fieldset class="actions">
			<input type="file" id="file-upload" name="Filedata[]" />
			<fieldset id="jform_folder" class="radio"><?php echo $this->lists['folder'] . "&nbsp;" ; ?></fieldset>
			<input type="submit" id="file-upload-submit" value="<?php echo Text::_('Start Upload'); ?>"/>
			<span id="upload-clear"></span>
		</fieldset>
		<ul class="upload-queue" id="upload-queue">
			<li style="display: none" />
		</ul>
	</fieldset>
</div>
	<input type="hidden" name="return-url" value="<?php echo base64_encode('index.php?option=com_userpoints&task=levelrank'); ?>" />
</form>