*
* 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/admin/setup.php
* \ingroup agendwrapper
* \brief AgendWrapper Einstellungsseite
*/
// 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) {
die("Include of main fails");
}
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
require_once '../lib/agendwrapper.lib.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
$langs->loadLangs(array("admin", "agendwrapper@agendwrapper"));
// Zugriffskontrolle
if (!$user->admin) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
/*
* Aktionen
*/
if ($action == 'update' && $user->admin) {
$db->begin();
$error = 0;
// Nextcloud-URL
$val = GETPOST('AGENDWRAPPER_NEXTCLOUD_URL', 'alpha');
$res = dolibarr_set_const($db, 'AGENDWRAPPER_NEXTCLOUD_URL', trim($val), 'chaine', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
// Benutzername
$val = GETPOST('AGENDWRAPPER_NEXTCLOUD_USER', 'alpha');
$res = dolibarr_set_const($db, 'AGENDWRAPPER_NEXTCLOUD_USER', trim($val), 'chaine', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
// Passwort (nur wenn ausgefuellt, verschluesselt speichern)
$pass = GETPOST('AGENDWRAPPER_NEXTCLOUD_PASS', 'none');
if (!empty($pass)) {
$res = dolibarr_set_const($db, 'AGENDWRAPPER_NEXTCLOUD_PASS', dolEncrypt($pass), 'chaine', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
}
// Kalender 1
$val = GETPOST('AGENDWRAPPER_CAL1_NAME', 'alpha');
$res = dolibarr_set_const($db, 'AGENDWRAPPER_CAL1_NAME', trim($val), 'chaine', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
// Kalender 2
$val = GETPOST('AGENDWRAPPER_CAL2_NAME', 'alpha');
$res = dolibarr_set_const($db, 'AGENDWRAPPER_CAL2_NAME', trim($val), 'chaine', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
// Cache-Dauer
$val = GETPOSTINT('AGENDWRAPPER_CACHE_DURATION');
if ($val < 30) {
$val = 300;
}
$res = dolibarr_set_const($db, 'AGENDWRAPPER_CACHE_DURATION', $val, 'chaine', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
// API-Key
$val = GETPOST('AGENDWRAPPER_API_KEY', 'alpha');
if (!empty($val)) {
$res = dolibarr_set_const($db, 'AGENDWRAPPER_API_KEY', trim($val), 'chaine', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
}
if (!$error) {
$db->commit();
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
$db->rollback();
setEventMessages($langs->trans("Error"), null, 'errors');
}
}
// Verbindungstest
if ($action == 'testconnection' && $user->admin) {
dol_include_once('/agendwrapper/class/IcsProxy.class.php');
$proxy = new IcsProxy($db);
$testResults = array();
for ($c = 1; $c <= 2; $c++) {
$calName = getDolGlobalString('AGENDWRAPPER_CAL'.$c.'_NAME');
if (empty($calName)) {
continue;
}
$rawIcs = $proxy->fetchFromNextcloud($calName);
if ($rawIcs === false) {
setEventMessages($langs->trans('ConnectionFailed', $proxy->error), null, 'errors');
} else {
$eventCount = $proxy->countEvents($rawIcs);
setEventMessages($langs->trans('ConnectionSuccess', $eventCount).' (Kalender '.$c.': '.$calName.')', null, 'mesgs');
}
}
if (empty(getDolGlobalString('AGENDWRAPPER_CAL1_NAME')) && empty(getDolGlobalString('AGENDWRAPPER_CAL2_NAME'))) {
setEventMessages($langs->trans('CalendarNotConfigured', '1+2'), null, 'warnings');
}
}
/*
* Ansicht
*/
$form = new Form($db);
$title = "AgendWrapperSetup";
$help_url = '';
llxHeader('', $langs->trans($title), $help_url, '', 0, 0, '', '', '', 'mod-agendwrapper page-admin');
$linkback = ''.$langs->trans("BackToModuleList").'';
print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');
$head = agendwrapperAdminPrepareHead();
print dol_get_fiche_head($head, 'settings', $langs->trans($title), -1, "agendwrapper@agendwrapper");
print ''.$langs->trans("AgendWrapperSetupPage").'
';
// Formular
print '
';
print '
';
// === Verbindungstest ===
print '';
print '
';
// === Proxy-URLs anzeigen ===
$apiKey = getDolGlobalString('AGENDWRAPPER_API_KEY');
$cal1 = getDolGlobalString('AGENDWRAPPER_CAL1_NAME');
$cal2 = getDolGlobalString('AGENDWRAPPER_CAL2_NAME');
if (!empty($apiKey) && (!empty($cal1) || !empty($cal2))) {
print load_fiche_titre($langs->trans("ProxyUrlSection"), '', 'fa-link');
print '';
print $langs->trans("ProxyUrlInfo").'
';
$baseProxyUrl = DOL_MAIN_URL_ROOT.'/custom/agendwrapper/proxy.php';
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 '
';
} else {
print ''.$langs->trans("ProxyNotConfigured").'
';
}
print dol_get_fiche_end();
// JavaScript fuer API-Key-Generierung
print '';
llxFooter();
$db->close();