<?php
/**
* @package		UserPoints for Joomla 4.x
* @copyright	Copyright (C) 2015-2016. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

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

use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ModuleHelper;
use BlackSheepResearch\Component\UserPoints\Site\Problems\SQL;

// Include the syndicate functions only once
require_once (dirname(__FILE__).'/helper.php');

// Import file dependencies if needed
if (!function_exists('getProfileLink')) {
	require_once (JPATH_ROOT.'/components/com_userpoints/helpers/helpers.php');
}

$curr_month   = date("m", SQL::unixtime());
$current_year = date("Y", SQL::unixtime());
$jinput = Factory::getApplication()->input;

$selectmonth  = $jinput->post->getInt('mod_aup_ms_month', $curr_month );
$current_year = $jinput->post->getInt('mod_aup_ms_current_year', $current_year);
$previousyear = $jinput->post->getInt('mod_aup_ms_previousyear', $current_year);

if ($curr_month == $selectmonth) {
	$searchdate= $current_year."-".str_pad($selectmonth, 2, "0", STR_PAD_LEFT )."-";
} else {
	$searchdate= $previousyear."-".str_pad($selectmonth, 2, "0", STR_PAD_LEFT )."-";
}

$list = modUserPointsMonthlyStatsHelper::getList($searchdate, $params);
$currentmonthlist = modUserPointsMonthlyStatsHelper::getCurrentMonthList($selectmonth, $params);
require(ModuleHelper::getLayoutPath('mod_userpoints_monthly_stats'));
