This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmailtemplates.php
148 lines (123 loc) · 4.35 KB
/
mailtemplates.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
require_once(dirname(__FILE__) . "/config.inc.php");
require_once(VPANEL_UI . "/session.class.php");
$session = $config->getSession();
$ui = $session->getTemplate();
if (!$session->isSignedIn()) {
$ui->viewLogin();
exit;
}
require_once(VPANEL_CORE . "/mailtemplate.class.php");
function parseMailTemplateFormular($ui, $session, &$template = null) {
$label = stripslashes($_POST["label"]);
$body = stripslashes($_POST["body"]);
if ($template == null) {
$gliederung = $session->getStorage()->getGliederung($session->getVariable("gliederungid"));
if (!$session->isAllowed("mailtemplates_create", $gliederung->getGliederungID())) {
$ui->viewLogin();
exit;
}
$template = new MailTemplate($session->getStorage());
$template->setGliederung($gliederung);
} else {
$gliederung = $template->getGliederung();
if (!$session->isAllowed("mailtemplates_modify", $gliederung->getGliederungID())) {
$ui->viewLogin();
exit;
}
}
$template->setLabel($label);
$template->setBody($body);
// Headerfelder
$headerfields = $session->getListVariable("headerfields");
$headervalues = $session->getListVariable("headervalues");
$headerfieldsindex = array_map('strtolower', $headerfields);
foreach ($template->getHeaders() as $field => $header) {
if (empty($field) || !in_array(strtolower($field), $headerfieldsindex)) {
$template->delHeader($field);
}
}
$headers = array_combine($headerfields, $headervalues);
foreach ($headers as $field => $value) {
if (!empty($field)) {
$template->setHeader($field, $value);
}
}
$template->save();
}
switch ($session->hasVariable("mode") ? $session->getVariable("mode") : null) {
case "createattachment":
$template = $session->getStorage()->getMailTemplate($session->getIntVariable("templateid"));
if (!$session->isAllowed("mailtemplates_modify", $template->getGliederungID())) {
$ui->viewLogin();
exit;
}
if ($session->getBoolVariable("save")) {
$file = $session->getFileVariable("attachment");
if ($file != null) {
$template->addAttachment($file);
$template->save();
}
$ui->redirect();
}
$ui->viewMailTemplateCreateAttachment($template);
exit;
case "deleteattachment":
$template = $session->getStorage()->getMailTemplate($session->getIntVariable("templateid"));
if (!$session->isAllowed("mailtemplates_modify", $template->getGliederungID())) {
$ui->viewLogin();
exit;
}
$template->delAttachment($session->getIntVariable("fileid"));
$template->save();
$ui->redirect();
exit;
case "details":
$templateid = $session->getIntVariable("templateid");
$template = $session->getStorage()->getMailTemplate($templateid);
if ($session->getBoolVariable("save")) {
parseMailTemplateFormular($ui, $session, $template);
//$ui->redirect($session->getLink("mailtemplates_details", $template->getTemplateID()));
}
$ui->viewMailTemplateDetails($template);
exit;
case "create":
$gliederung = null;
if ($session->hasVariable("gliederungid")) {
$gliederung = $session->getStorage()->getGliederung($session->getVariable("gliederungid"));
}
if ($session->getBoolVariable("save")) {
$template = null;
parseMailTemplateFormular($ui, $session, &$template);
$ui->redirect($session->getLink("mailtemplates_details", $template->getTemplateID()));
}
$gliederungen = $session->getStorage()->getGliederungList($session->getAllowedGliederungIDs("mailtemplates_create"));
$ui->viewMailTemplateCreate($gliederungen, $gliederung);
exit;
case "delete":
$template = $session->getStorage()->getMailTemplate($session->getIntVariable("templateid"));
if (!$session->isAllowed("mailtemplates_delete", $template->getGliederungID())) {
$ui->viewLogin();
exit;
}
$template->delete();
$ui->redirect($session->getLink("mailtemplates"));
exit;
default:
$gliederung = null;
if ($session->hasVariable("gliederungid")) {
if (!$session->isAllowed("mailtemplates_show", $session->getVariable("gliederungid"))) {
$ui->viewLogin();
exit;
}
$gliederungid = $session->getVariable("gliederungid");
$gliederung = $session->getStorage()->getGliederung($gliederungid);
} else {
$gliederungid = $session->getAllowedGliederungIDs("mailtemplates_show");
}
$templates = $session->getStorage()->getMailTemplateList($gliederungid);
$gliederungen = $session->getStorage()->getGliederungList($session->getAllowedGliederungIDs("mailtemplates_show"));
$ui->viewMailTemplateList($templates, $gliederungen, $gliederung);
exit;
}
?>