forked from froxlor/Froxlor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_message.php
150 lines (131 loc) · 4.75 KB
/
admin_message.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
149
150
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* 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 2
* 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, you can also view it online at
* https://files.froxlor.org/misc/COPYING.txt
*
* @copyright the authors
* @author Froxlor team <[email protected]>
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
*/
const AREA = 'admin';
require __DIR__ . '/lib/init.php';
use Froxlor\Database\Database;
use Froxlor\FroxlorLogger;
use Froxlor\UI\Panel\UI;
use Froxlor\UI\Request;
use Froxlor\UI\Response;
use Froxlor\User;
$id = (int)Request::any('id');
$note_type = null;
$note_msg = null;
if ($page == 'message') {
if ($action == '') {
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, 'viewed panel_message');
if (isset($_POST['send']) && $_POST['send'] == 'send') {
if ($_POST['recipient'] == 0 && $userinfo['customers_see_all'] == '1') {
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, 'sending messages to admins');
$result = Database::query('SELECT `name`, `email` FROM `' . TABLE_PANEL_ADMINS . "`");
} elseif ($_POST['recipient'] == 1) {
if ($userinfo['customers_see_all'] == '1') {
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, 'sending messages to ALL customers');
$result = Database::query('SELECT `firstname`, `name`, `company`, `email` FROM `' . TABLE_PANEL_CUSTOMERS . "`");
} else {
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, 'sending messages to customers');
$result = Database::prepare('
SELECT `firstname`, `name`, `company`, `email` FROM `' . TABLE_PANEL_CUSTOMERS . "`
WHERE `adminid` = :adminid");
Database::pexecute($result, [
'adminid' => $userinfo['adminid']
]);
}
} else {
Response::standardError('norecipientsgiven');
}
$subject = $_POST['subject'];
$message = wordwrap($_POST['message'], 70);
if (!empty($message)) {
$mailcounter = 0;
$mail->Body = $message;
$mail->Subject = $subject;
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$row['firstname'] = isset($row['firstname']) ? $row['firstname'] : '';
$row['company'] = isset($row['company']) ? $row['company'] : '';
$mail->AddAddress($row['email'], User::getCorrectUserSalutation([
'firstname' => $row['firstname'],
'name' => $row['name'],
'company' => $row['company']
]));
$mail->From = $userinfo['email'];
$mail->FromName = (isset($userinfo['firstname']) ? $userinfo['firstname'] . ' ' : '') . $userinfo['name'];
if (!$mail->Send()) {
if ($mail->ErrorInfo != '') {
$mailerr_msg = $mail->ErrorInfo;
} else {
$mailerr_msg = $row['email'];
}
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_ERR, 'Error sending mail: ' . $mailerr_msg);
Response::standardError('errorsendingmail', $row['email']);
}
$mailcounter++;
$mail->ClearAddresses();
}
Response::redirectTo($filename, [
'page' => $page,
'action' => 'showsuccess',
'sentitems' => $mailcounter
]);
} else {
Response::standardError('nomessagetosend');
}
}
} elseif ($action == 'showsuccess') {
$sentitems = isset($_GET['sentitems']) ? (int)$_GET['sentitems'] : 0;
if ($sentitems == 0) {
$note_type = 'info';
$note_msg = lng('message.norecipients');
} else {
$note_type = 'success';
$note_msg = str_replace('%s', $sentitems, lng('message.success'));
}
}
$recipients = [];
if ($userinfo['customers_see_all'] == '1') {
$recipients[0] = lng('panel.reseller');
}
$recipients[1] = lng('panel.customer');
$messages_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/messages/formfield.messages_add.php';
UI::view('user/form-note.html.twig', [
'formaction' => $linker->getLink(['section' => 'message']),
'formdata' => $messages_add_data['messages_add'],
'actions_links' => [
[
'href' => $linker->getLink([
'section' => 'settings',
'page' => 'overview',
'part' => 'system',
'em' => 'system_mail_use_smtp'
]),
'label' => lng('admin.smtpsettings'),
'icon' => 'fa-solid fa-gears',
'class' => 'btn-outline-secondary'
]
],
// alert-box
'type' => $note_type,
'alert_msg' => $note_msg
]);
}