opensmtpdadmin/vacation.php

91 lines
2.2 KiB
PHP

<?php
//
// OpenSMTPD Admin
// by Mischa Peters <mischa at high5 dot nl>
// Copyright (c) 2022 High5!
// License Info: LICENSE.TXT
//
// File: vacation.php
//
// Template File: users_vacation.tpl
//
// Template Variables:
//
// tMessage
// tSubject
// tBody
//
// POST / GET Variables:
//
// fSubject
// fBody
//
require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
$ROLE = check_role($SESSID_USERNAME);
if ($ROLE == ADMIN_ROLE) {
$list_domains = list_domains();
$list_admins = list_admins();
} else {
$list_domains = list_domains($SESSID_USERNAME);
}
$USERID_DOMAIN = substr(strrchr($SESSID_USERNAME, "@"), 1);
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$dbh = pdo_connect();
$sth = $dbh->prepare("SELECT COUNT(*) FROM vacation WHERE email=?");
$sth->execute(array($SESSID_USERNAME));
if ($sth->fetchColumn() == 1) {
$action = 'back';
$message = $LANG['Vacation_welcome_text'];
} else {
$action = 'away';
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$subject = filter_input(INPUT_POST, 'subject', FILTER_DEFAULT);
$body = filter_input(INPUT_POST, 'body', FILTER_DEFAULT);
if (!empty($_POST['back'])) {
$action = 'back';
$dbh = pdo_connect();
$sth = $dbh->prepare("DELETE FROM vacation WHERE email=?");
$sth->bindParam(1, $SESSID_USERNAME, PDO::PARAM_STR);
$sth->execute();
if ($sth->rowCount() != 1) {
$message = $LANG['Vacation_result_error'];
} else {
$action = 'away';
$essage = $LANG['Vacation_result_succes'];
}
}
if (!empty($_POST['away'])) {
$action = 'away';
try {
$dbh = pdo_connect();
$sth = $dbh->prepare("INSERT INTO vacation (email,subject,body,cache,domain,created) VALUES (?,?,?,'',?,NOW())");
$sth->bindParam(1, $SESSID_USERNAME, PDO::PARAM_STR);
$sth->bindParam(2, $subject, PDO::PARAM_STR);
$sth->bindParam(3, $body, PDO::PARAM_STR);
$sth->bindParam(4, $USERID_DOMAIN, PDO::PARAM_STR);
$sth->execute();
header("Location: vacation.php");
} catch(PDOException $e) {
$message = $LANG['Vacation_result_error'] . " " . $e->getMessage();
}
}
}
include './templates/header.tpl';
include './templates/menu.tpl';
include './templates/vacation.tpl';
include './templates/footer.tpl';
?>