Grundfunktionalität zum Senden von E-Mails

This commit is contained in:
Thomas Günther 2024-03-24 19:52:32 +01:00
parent 5e766bc2e5
commit e9740e86b5
7 changed files with 221 additions and 11 deletions

View File

@ -15,6 +15,7 @@
use Bdp\Modules\Gruppen\Controllers\MainController as GruppenMain;
use Bdp\Modules\KompassSettings\Controllers\SettingsPage as KomnpassSettings;
use Bdp\Modules\LimitLoginAttempts\Controllers\OptionsPage as OptionsPageAlias;
use Bdp\Modules\Mail\Controllers\MailController;
use Bdp\Modules\Security\Security;
use Bdp\Modules\Seo\Seo;
@ -47,6 +48,7 @@ add_action('admin_menu', function () {
new OptionsPageAlias();
new KomnpassSettings();
new GruppenMain();
new MailController();
});

View File

@ -30,7 +30,7 @@ function add_custom_admin_bar_item() {
'id' => 'kompass_gruppen',
'title' => '<span class="ab-icon dashicons-groups"></span>' .
'<span class="ab-label">' .__('Groups', BDP_LV_PLUGIN_SLUG) . '</span>',
'href' => 'admin.php?page=kompass-groups',
'href' => get_admin_url() . 'admin.php?page=kompass-groups',
];

View File

@ -25,16 +25,20 @@ foreach (glob($directoryPath . '*.php') as $file) {
require_once $file;
}
$modules = ['KompassSettings', 'LimitLoginAttempts', 'PasswordStrength', 'seo', 'Gruppen'];
$subdirs = ['includes', 'Controllers', 'Views', 'Requests', 'Actions'];
foreach ($modules as $curModule) {
foreach ($subdirs as $dir) {
$directoryPath = BDP_LV_PLUGIN_DIR . 'modules/' . $curModule . '/' . $dir . '/';
foreach (glob($directoryPath . '*.php') as $file) {
require_once $file;
}
}
foreach (scandir(BDP_LV_PLUGIN_DIR . 'modules/') as $curModule) {
if ($curModule != '.' && $curModule != '..' && is_dir(BDP_LV_PLUGIN_DIR . 'modules/' . $curModule))
{
if ($curModule == 'calendar') {
continue;
}
foreach ($subdirs as $dir) {
$directoryPath = BDP_LV_PLUGIN_DIR . 'modules/' . $curModule . '/' . $dir . '/';
foreach (glob($directoryPath . '*.php') as $file) {
require_once $file;
}
}
}
}

View File

@ -59,6 +59,13 @@ function kompass_print_gruppen_overview()
<?php
}
echo '</p>';
// Gutenberg-Editor einbinden
wp_editor( '', 'gutenberg_content', array(
'textarea_name' => 'gutenberg_content',
// 'media_buttons' => false, // Deaktivieren der Medien-Upload-Schaltfläche
) );
}
function kompass_get_group_actions(int $groupId, int $participantCount) : string

View File

@ -0,0 +1,10 @@
<?php
namespace Bdp\Modules\Mail\Controllers;
class MailCompose
{
function __construct()
{
kompass_print_mail_compose();
}
}

View File

@ -0,0 +1,153 @@
<?php
namespace Bdp\Modules\Mail\Controllers;
use Bdp\Libs\FileAccess;
use SearchMemberRequest;
class MailController
{
public function __construct()
{
add_menu_page(
__('E-Mail', BDP_LV_PLUGIN_SLUG),
__('E-Mail', BDP_LV_PLUGIN_SLUG),
'send_mails',
'kompass-mail',
[$this, 'router'],
'dashicons-email',
4
);
/*$mailCompose = new MailCompose();
add_submenu_page(
'kompass-mail',
__('Templates', BDP_LV_PLUGIN_SLUG),
__('Templates', BDP_LV_PLUGIN_SLUG),
'send_mails',
'kompass-mail-compose',
[$mailCompose, '__construct'],
1);*/
}
public function router()
{
if (isset($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
case 'send-email':
// SMTP-Konfiguration
$smtp_host = 'bdp.mein-verein.online'; // SMTP-Host
$smtp_port = 25; // SMTP-Port
$smtp_username = 'noreply@mareike.sachsen.pfadfinden.de'; // SMTP-Benutzername
$smtp_password = 'fwJ_wxbW9G45'; // SMTP-Passwort
$smtp_secure = 'tls'; // Verschlüsselung (tls oder ssl)
// Einstellungen für wp_mail ändern
add_action( 'phpmailer_init', function( $phpmailer ) use ( $smtp_host, $smtp_port, $smtp_username, $smtp_password, $smtp_secure ) {
$phpmailer->isSMTP();
$phpmailer->Host = $smtp_host;
$phpmailer->Port = $smtp_port;
$phpmailer->SMTPAuth = true;
$phpmailer->Username = $smtp_username;
$phpmailer->Password = $smtp_password;
$phpmailer->setFrom('info@pfadfinden-halle.de', 'Pfadfinden - Halle');
#$phpmailer->SMTPSecure = $smtp_secure;
} );
// Senden Sie die E-Mail
$sent = wp_mail($_REQUEST['mail-to'],$_REQUEST['mail-subject'],$_REQUEST['mail-text'],
['Reply-To: ' . $_REQUEST['mail-from'], 'Content-Type: text/html; charset=UTF-8']);
// Überprüfen, ob die E-Mail erfolgreich gesendet wurde
if ( $sent ) {
echo '<p>E-Mail wurde erfolgreich gesendet!</p>';
} else {
echo '<p>Fehler beim Senden der E-Mail!</p>';
}
echo $_REQUEST['mail-to'] . '<br />';
echo $_REQUEST['mail-text'];
echo 'mail gesendet';
break;
case 'create_group_form':
new \Bdp\Modules\Gruppen\Controllers\CreateGroupController();
break;
case 'update-group':
\UpdateGroupAction::execute(['gruppen_name' => $_REQUEST['kompass_groups_group_name']],
(int)$_REQUEST['group_id']);
new \Bdp\Modules\Gruppen\Controllers\PrintGroupsController();
break;
case 'create-group':
$data = ['gruppen_name' => $_REQUEST['kompass_groups_group_name']];
\CreateGroupAction::execute($data);
new \Bdp\Modules\Gruppen\Controllers\PrintGroupsController();
break;
case 'new-member':
new \Bdp\Modules\Gruppen\Controllers\CreateMemberController();
break;
case 'create-member':
$userData = \CreateGroupMemberDataAction::execute($_REQUEST);
if (count($userData['errors']) === 0) {
$memberId = \CreateGroupMemberAction::execute( $userData['data'] );
new \Bdp\Modules\Gruppen\Controllers\PrintMemberController($memberId);
} else {
kompass_print_message_box(implode('<br />', $userData['errors']), 'error');
new \Bdp\Modules\Gruppen\Controllers\CreateMemberController($userData['rawData']);
exit;
}
new \Bdp\Modules\Gruppen\Controllers\PrintGroupsController();
break;
case 'show-members':
$memberList = \ListMemberRequest::listForGroup((int)$_REQUEST['group-id']);
new \Bdp\Modules\Gruppen\Controllers\PrintMemberListController($memberList);
break;
case 'show-member':
new \Bdp\Modules\Gruppen\Controllers\PrintMemberController((int)$_REQUEST['member-id']);
break;
case 'compose-mail':
current_user_can('send_mails');
break;
case 'delete-group':
if (current_user_can('delete_groups')) {
}
break;
case 'edit-group':
if (current_user_can('edit_groups')) {
kompass_edit_group_form($_REQUEST['group-id']);
}
break;
default:
}
} else {
new MailCompose();
}
}
private function listMembers()
{
}
private function printMembers(array $memberList)
{
}
}

View File

@ -0,0 +1,34 @@
<?php
function kompass_print_mail_compose()
{
global $dbHandler;
?>
<form method="post" action="admin.php?page=kompass-mail" style="width: 80%; margin: auto">
<table style="width: 100%">
<input type="hidden" name="action" value="send-email" />
<tr>
<td><?= __('From: ', BDP_LV_PLUGIN_SLUG); ?></td>
<td><input type="text" name="mail-from" style="width: 100%"></td>
</tr>
<tr>
<td><?= __('To: ', BDP_LV_PLUGIN_SLUG); ?></td>
<td><input type="text" name="mail-to" style="width: 100%"></td>
</tr>
<tr>
<td><?= __('Subject: ', BDP_LV_PLUGIN_SLUG); ?></td>
<td><input type="text" name="mail-subject" style="width: 100%"></td>
</tr>
</table>
<?php
wp_editor( '', 'gutenberg_content', array(
'textarea_name' => 'mail-text',
// 'media_buttons' => false, // Deaktivieren der Medien-Upload-Schaltfläche
) );
submit_button(__('Send email', BDP_LV_PLUGIN_SLUG));
?>
</form>
<?php
}