*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* \file agendwrapper/agendwrapperindex.php
* \ingroup agendwrapper
* \brief AgendWrapper Statusseite
*/
// Dolibarr-Umgebung laden
$res = 0;
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
}
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
$tmp2 = realpath(__FILE__);
$i = strlen($tmp) - 1;
$j = strlen($tmp2) - 1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
$i--;
$j--;
}
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
}
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
}
if (!$res && file_exists("../main.inc.php")) {
$res = @include "../main.inc.php";
}
if (!$res && file_exists("../../main.inc.php")) {
$res = @include "../../main.inc.php";
}
if (!$res && file_exists("../../../main.inc.php")) {
$res = @include "../../../main.inc.php";
}
if (!$res) {
die("Include of main fails");
}
dol_include_once('/agendwrapper/class/IcsProxy.class.php');
dol_include_once('/agendwrapper/lib/agendwrapper.lib.php');
/**
* @var Conf $conf
* @var DoliDB $db
* @var Translate $langs
* @var User $user
*/
$langs->loadLangs(array("agendwrapper@agendwrapper"));
$action = GETPOST('action', 'aZ09');
// Zugriffskontrolle
if (!$user->admin) {
accessforbidden();
}
/*
* Aktionen
*/
$proxy = new IcsProxy($db);
if ($action == 'clearcache' && $user->admin) {
$proxy->clearCache();
setEventMessages($langs->trans("CacheCleared"), null, 'mesgs');
header('Location: '.$_SERVER["PHP_SELF"]);
exit;
}
if ($action == 'warmcache' && $user->admin) {
for ($c = 1; $c <= 2; $c++) {
$calName = getDolGlobalString('AGENDWRAPPER_CAL'.$c.'_NAME');
if (empty($calName)) {
continue;
}
$proxy->clearCache($c);
$result = $proxy->getCleanIcs($c);
if ($result === false) {
setEventMessages($langs->trans('CacheWarmFailed', $proxy->error), null, 'errors');
} else {
$eventCount = $proxy->countEvents($result);
setEventMessages($langs->trans('CacheWarmed', $eventCount, $c), null, 'mesgs');
}
}
}
/*
* Ansicht
*/
llxHeader("", $langs->trans("AgendWrapperArea"), '', '', 0, 0, '', '', '', 'mod-agendwrapper page-index');
print load_fiche_titre($langs->trans("AgendWrapperArea"), '', 'fa-calendar-alt');
// Konfiguration pruefen
$ncUrl = getDolGlobalString('AGENDWRAPPER_NEXTCLOUD_URL');
$ncUser = getDolGlobalString('AGENDWRAPPER_NEXTCLOUD_USER');
$ncPass = getDolGlobalString('AGENDWRAPPER_NEXTCLOUD_PASS');
$apiKey = getDolGlobalString('AGENDWRAPPER_API_KEY');
if (empty($ncUrl) || empty($ncUser) || empty($ncPass) || empty($apiKey)) {
print '
';
}
// === Cache-Status ===
print load_fiche_titre($langs->trans("CacheStatus"), '', 'fa-database');
$cacheDuration = (int) getDolGlobalString('AGENDWRAPPER_CACHE_DURATION', '300');
print '';
print '';
print '| '.$langs->trans("Parameter").' | ';
print ''.$langs->trans("CacheStatus").' | ';
print ''.$langs->trans("EventCount").' | ';
print ''.$langs->trans("CacheAge").' | ';
print '
';
for ($c = 1; $c <= 2; $c++) {
$calName = getDolGlobalString('AGENDWRAPPER_CAL'.$c.'_NAME');
$info = $proxy->getCacheInfo($c);
print '';
print '| Kalender '.$c;
if (!empty($calName)) {
print ' ('.dol_escape_htmltag($calName).')';
}
print ' | ';
if (empty($calName)) {
print ''.$langs->trans("CalendarNotConfigured", $c).' | ';
} elseif (!$info['exists']) {
print ''.$langs->trans("CacheEmpty").' | ';
print '- | ';
print '- | ';
} else {
// Status
if ($info['age'] <= $cacheDuration) {
print ''.$langs->trans("CacheFresh", $info['age']).' | ';
} else {
print ''.$langs->trans("CacheExpired", $info['age']).' | ';
}
// Event-Anzahl
print ''.$info['event_count'].' | ';
// Alter
print ''.dol_print_date(time() - $info['age'], 'dayhour').' | ';
}
print '
';
}
print '
';
print '
';
// Buttons
print '';
print '
';
// === Proxy-URLs ===
if (!empty($apiKey)) {
$cal1 = getDolGlobalString('AGENDWRAPPER_CAL1_NAME');
$cal2 = getDolGlobalString('AGENDWRAPPER_CAL2_NAME');
if (!empty($cal1) || !empty($cal2)) {
print load_fiche_titre($langs->trans("ProxyUrlSection"), '', 'fa-link');
$baseProxyUrl = DOL_MAIN_URL_ROOT.'/custom/agendwrapper/proxy.php';
print '';
print $langs->trans("ProxyUrlInfo").'
';
if (!empty($cal1)) {
$proxyUrl1 = $baseProxyUrl.'?cal=1&key='.urlencode($apiKey);
print ''.$langs->trans("ProxyUrlCal1").' ('.$cal1.'):
';
print ''.dol_escape_htmltag($proxyUrl1).'
';
}
if (!empty($cal2)) {
$proxyUrl2 = $baseProxyUrl.'?cal=2&key='.urlencode($apiKey);
print ''.$langs->trans("ProxyUrlCal2").' ('.$cal2.'):
';
print ''.dol_escape_htmltag($proxyUrl2).'
';
}
print '
';
}
}
llxFooter();
$db->close();