opensmtpdadmin/users/vacation.php

82 lines
2.1 KiB
PHP
Raw Normal View History

2022-08-18 14:01:52 +02:00
<?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
//
// Form POST \ GET Variables:
//
// fSubject
// fBody
//
2022-09-04 19:17:50 +02:00
require_once '../functions.inc.php';
include '../languages/' . check_language() . '.lang';
2022-08-18 14:01:52 +02:00
2022-09-04 19:17:50 +02:00
$SESSID_USERNAME = check_session('userid');
$USERID_DOMAIN = substr(strrchr($SESSID_USERNAME, "@"), 1);
2022-08-18 14:01:52 +02:00
if ($_SERVER['REQUEST_METHOD'] == "GET") {
2022-09-04 19:17:50 +02:00
$dbh = connect_db();
$sth = $dbh->prepare("SELECT COUNT(*) FROM vacation WHERE email=?");
$sth->execute(array($SESSID_USERNAME));
if ($sth->fetchColumn() == 1) {
$action = 'back';
$message = $LANG['UsersVacation_welcome_text'];
2022-08-18 14:01:52 +02:00
} else {
2022-09-04 19:17:50 +02:00
$action = 'away';
2022-08-18 14:01:52 +02:00
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
2022-09-04 19:17:50 +02:00
$subject = filter_input(INPUT_POST, 'subject', FILTER_DEFAULT);
$body = filter_input(INPUT_POST, 'body', FILTER_DEFAULT);
2022-08-18 14:01:52 +02:00
2022-09-04 19:17:50 +02:00
if (!empty($_POST['back'])) {
$action = 'back';
$dbh = connect_db();
$sth = $dbh->prepare("DELETE FROM vacation WHERE email=?");
$sth->bindParam(1, $SESSID_USERNAME, PDO::PARAM_STR);
$sth->execute();
if ($sth->rowCount() != 1) {
$message = $LANG['UsersVacation_result_error'];
2022-08-18 14:01:52 +02:00
} else {
2022-09-04 19:17:50 +02:00
$action = 'away';
$essage = $LANG['UsersVacation_result_succes'];
2022-08-18 14:01:52 +02:00
}
}
2022-09-04 19:17:50 +02:00
if (!empty($_POST['away'])) {
$action = 'away';
try {
$dbh = connect_db();
$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();
2022-08-18 14:01:52 +02:00
header("Location: main.php");
2022-09-04 19:17:50 +02:00
} catch(PDOException $e) {
$message = $LANG['UsersVacation_result_error'] . " " . $e->getMessage();
2022-08-18 14:01:52 +02:00
}
}
}
2022-09-04 19:17:50 +02:00
include '../templates/header.tpl';
include '../templates/users_menu.tpl';
include '../templates/users_vacation.tpl';
include '../templates/footer.tpl';
2022-08-18 14:01:52 +02:00
?>