Froxlor/admin_message.php

151 lines
4.7 KiB
PHP
Raw Normal View History

<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
2022-04-28 18:48:00 +00:00
* 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.
*
2022-04-28 18:48:00 +00:00
* 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.
*
2022-04-28 18:48:00 +00:00
* 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 <team@froxlor.org>
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
*/
const AREA = 'admin';
require __DIR__ . '/lib/init.php';
use Froxlor\Database\Database;
2022-04-28 18:48:00 +00:00
use Froxlor\FroxlorLogger;
use Froxlor\UI\Panel\UI;
2022-04-28 18:48:00 +00:00
use Froxlor\UI\Request;
use Froxlor\UI\Response;
use Froxlor\User;
$id = (int)Request::any('id');
$note_type = null;
$note_msg = null;
2013-04-27 07:56:34 +00:00
if ($page == 'message') {
if ($action == '') {
2022-04-28 18:48:00 +00:00
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, 'viewed panel_message');
2013-04-27 07:56:34 +00:00
if (Request::post('send') == 'send') {
if (Request::post('recipient', -1) == 0 && $userinfo['customers_see_all'] == '1') {
2022-04-28 18:48:00 +00:00
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, 'sending messages to admins');
$result = Database::query('SELECT `name`, `email` FROM `' . TABLE_PANEL_ADMINS . "`");
} elseif (Request::post('recipient', -1) == 1) {
if ($userinfo['customers_see_all'] == '1') {
2022-04-28 18:48:00 +00:00
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, 'sending messages to ALL customers');
$result = Database::query('SELECT `firstname`, `name`, `company`, `email` FROM `' . TABLE_PANEL_CUSTOMERS . "`");
2013-04-27 07:56:34 +00:00
} else {
2022-04-28 18:48:00 +00:00
$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");
2022-04-28 18:48:00 +00:00
Database::pexecute($result, [
'adminid' => $userinfo['adminid']
2022-04-28 18:48:00 +00:00
]);
}
2013-04-27 07:56:34 +00:00
} else {
2022-04-28 18:48:00 +00:00
Response::standardError('norecipientsgiven');
}
$subject = Request::post('subject');
$message = wordwrap(Request::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'] : '';
2022-04-28 18:48:00 +00:00
$mail->AddAddress($row['email'], User::getCorrectUserSalutation([
'firstname' => $row['firstname'],
'name' => $row['name'],
'company' => $row['company']
2022-04-28 18:48:00 +00:00
]));
$mail->From = $userinfo['email'];
$mail->FromName = (isset($userinfo['firstname']) ? $userinfo['firstname'] . ' ' : '') . $userinfo['name'];
if (!$mail->Send()) {
2013-04-27 07:56:34 +00:00
if ($mail->ErrorInfo != '') {
$mailerr_msg = $mail->ErrorInfo;
2013-04-27 07:56:34 +00:00
} else {
$mailerr_msg = $row['email'];
}
2022-04-28 18:48:00 +00:00
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_ERR, 'Error sending mail: ' . $mailerr_msg);
Response::standardError('errorsendingmail', $row['email']);
}
$mailcounter++;
$mail->ClearAddresses();
}
2022-04-28 18:48:00 +00:00
Response::redirectTo($filename, [
'page' => $page,
'action' => 'showsuccess',
'sentitems' => $mailcounter
2022-04-28 18:48:00 +00:00
]);
2013-04-27 07:56:34 +00:00
} else {
2022-04-28 18:48:00 +00:00
Response::standardError('nomessagetosend');
}
}
} elseif ($action == 'showsuccess') {
$sentitems = Request::get('sentitems', 0);
2013-04-27 07:56:34 +00:00
if ($sentitems == 0) {
$note_type = 'info';
2022-04-28 18:48:00 +00:00
$note_msg = lng('message.norecipients');
2013-04-27 07:56:34 +00:00
} else {
$note_type = 'success';
2022-04-28 18:48:00 +00:00
$note_msg = str_replace('%s', $sentitems, lng('message.success'));
}
}
$recipients = [];
if ($userinfo['customers_see_all'] == '1') {
2022-04-28 18:48:00 +00:00
$recipients[0] = lng('panel.reseller');
}
2022-04-28 18:48:00 +00:00
$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', [
2022-04-28 18:48:00 +00:00
'formaction' => $linker->getLink(['section' => 'message']),
'formdata' => $messages_add_data['messages_add'],
2022-04-28 18:48:00 +00:00
'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
]);
}