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

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

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

if (stristr( $_SERVER['SERVER_SOFTWARE'], 'win32' )) {
	define( 'JPATH_BASE', realpath(dirname(__FILE__).'\..\..\..\..' ));
} else {
    define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../..' ));
}


require_once ( JPATH_BASE.'/includes/defines.php' );
require_once ( JPATH_BASE.'/includes/framework.php' );
$app = Factory::getApplication('site');
$app->initialise();

jimport( 'joomla.plugin.plugin' );
jimport( 'joomla.environment.uri' );

$lang = Factory::getLanguage();
$lang->load( 'com_userpoints', JPATH_SITE);	

$username = str_replace("'", "", Factory::getApplication()->input->get( 'n', '', 'username' ));

$baseimg = str_replace('ajax', 'images', Uri::base());

$url_tick_img = $baseimg . 'tick.png';
$url_load_img = $baseimg . 'loader.gif';

if ( strlen($username)>3  ) 
	{
	$db	   = SQL::getInstance();	
        $q = "SELECT id FROM #__users WHERE `username`={$db->quote(trim($username))} LIMIT 1";
	$db->setQuery( $q );
	$userexist = $db->loadResult();
	
	if( $userexist )
		{
		echo '<img src="'.$url_tick_img.'" alt="" align="absmiddle" />';
		}
		else
		{
		echo '<font color="red">'.Text::_( 'AUP_THIS_USERNAME_NOT_EXIST' ).'</font>';
		}
	}
	else 
	{	
	echo '<img src="'.$url_load_img.'" alt="" align="absmiddle" /> ';
	}
