<?php

/**
 * @author Joas Schilling <*****@*****.**>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
$application = new \OCA\PopularityContestClient\AppInfo\Application();
\OCP\API::register('post', '/apps/popularitycontestclient/api/v1/report', [$application->getContainer()->query('EndpointController'), 'sendReport'], 'popularitycontestclient', \OCP\API::ADMIN_AUTH);
\OCP\API::register('post', '/apps/popularitycontestclient/api/v1/monthly', [$application->getContainer()->query('EndpointController'), 'enableMonthly'], 'popularitycontestclient', \OCP\API::ADMIN_AUTH);
\OCP\API::register('delete', '/apps/popularitycontestclient/api/v1/monthly', [$application->getContainer()->query('EndpointController'), 'disableMonthly'], 'popularitycontestclient', \OCP\API::ADMIN_AUTH);
/**
 * ownCloud Workflow
 *
 * @author Joas Schilling <*****@*****.**>
 * @copyright 2015 ownCloud, Inc.
 *
 * This code is covered by the ownCloud Commercial License.
 *
 * You should have received a copy of the ownCloud Commercial License
 * along with this program. If not, see <https://owncloud.com/licenses/owncloud-commercial/>.
 *
 */
use OCP\Template;
\OCP\Util::addScript('popularitycontestclient', 'admin');
\OCP\Util::addStyle('popularitycontestclient', 'admin');
$application = new \OCA\PopularityContestClient\AppInfo\Application();
$collector = $application->getContainer()->query('OCA\\PopularityContestClient\\Collector');
$lastSentReportTime = (int) \OC::$server->getConfig()->getAppValue('popularitycontestclient', 'last_sent', 0);
if ($lastSentReportTime === 0) {
    $lastSentReportDate = \OC::$server->getL10NFactory()->get('popularitycontestclient')->t('Never');
} else {
    $lastSentReportDate = \OC::$server->getDateTimeFormatter()->formatDate($lastSentReportTime);
}
$lastReport = \OC::$server->getConfig()->getAppValue('popularitycontestclient', 'last_report', '');
if ($lastReport !== '') {
    $lastReport = json_encode(json_decode($lastReport, true), JSON_PRETTY_PRINT);
}
$template = new Template('popularitycontestclient', 'admin');
$template->assign('is_enabled', \OC::$server->getJobList()->has('OCA\\PopularityContestClient\\MonthlyReport', null));
$template->assign('last_sent', $lastSentReportDate);
$template->assign('last_report', $lastReport);