Blob


1 <?php
2 //
3 // OpenSMTPD Admin
4 // by Mischa Peters <mischa at high5 dot nl>
5 // Copyright (c) 2022 High5!
6 // License Info: LICENSE.TXT
7 //
8 // File: vacation.php
9 //
10 // Template File: users_vacation.tpl
11 //
12 // Template Variables:
13 //
14 // tMessage
15 // tSubject
16 // tBody
17 //
18 // POST / GET Variables:
19 //
20 // fSubject
21 // fBody
22 //
23 require_once './functions.inc.php';
24 include './languages/' . check_language() . '.lang';
26 $SESSID_USERNAME = check_session();
27 $ROLE = check_role($SESSID_USERNAME);
29 if ($ROLE == ADMIN_ROLE) {
30 $list_domains = list_domains();
31 $list_admins = list_admins();
32 } else {
33 $list_domains = list_domains($SESSID_USERNAME);
34 }
36 $USERID_DOMAIN = substr(strrchr($SESSID_USERNAME, "@"), 1);
38 if ($_SERVER['REQUEST_METHOD'] == "GET") {
39 $dbh = pdo_connect();
40 $sth = $dbh->prepare("SELECT COUNT(*) FROM vacation WHERE email=?");
41 $sth->execute(array($SESSID_USERNAME));
43 if ($sth->fetchColumn() == 1) {
44 $action = 'back';
45 $message = $LANG['Vacation_welcome_text'];
46 } else {
47 $action = 'away';
48 }
49 }
51 if ($_SERVER['REQUEST_METHOD'] == "POST") {
52 $subject = filter_input(INPUT_POST, 'subject', FILTER_DEFAULT);
53 $body = filter_input(INPUT_POST, 'body', FILTER_DEFAULT);
55 if (!empty($_POST['back'])) {
56 $action = 'back';
57 $dbh = pdo_connect();
58 $sth = $dbh->prepare("DELETE FROM vacation WHERE email=?");
59 $sth->bindParam(1, $SESSID_USERNAME, PDO::PARAM_STR);
60 $sth->execute();
61 if ($sth->rowCount() != 1) {
62 $message = $LANG['Vacation_result_error'];
63 } else {
64 $action = 'away';
65 $essage = $LANG['Vacation_result_succes'];
66 }
67 }
69 if (!empty($_POST['away'])) {
70 $action = 'away';
71 try {
72 $dbh = pdo_connect();
73 $sth = $dbh->prepare("INSERT INTO vacation (email,subject,body,cache,domain,created) VALUES (?,?,?,'',?,NOW())");
74 $sth->bindParam(1, $SESSID_USERNAME, PDO::PARAM_STR);
75 $sth->bindParam(2, $subject, PDO::PARAM_STR);
76 $sth->bindParam(3, $body, PDO::PARAM_STR);
77 $sth->bindParam(4, $USERID_DOMAIN, PDO::PARAM_STR);
78 $sth->execute();
79 header("Location: vacation.php");
80 } catch(PDOException $e) {
81 $message = $LANG['Vacation_result_error'] . " " . $e->getMessage();
82 }
83 }
85 }
86 include './templates/header.tpl';
87 include './templates/menu.tpl';
88 include './templates/vacation.tpl';
89 include './templates/footer.tpl';
90 ?>