Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Nov 3, 2023
1 parent 8f13166 commit caf1cdd
Show file tree
Hide file tree
Showing 10 changed files with 689 additions and 416 deletions.
2 changes: 1 addition & 1 deletion docker/docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
args:
env: devel
fqdn: motionui-dev.localhost
restart: unless-stopped
restart: always
ports:
- "8888:8080"
volumes:
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
args:
env: prod
fqdn: motionui.example.com
restart: unless-stopped
restart: always
ports:
- "8080:8080"
volumes:
Expand Down
2 changes: 1 addition & 1 deletion www/config/properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$config = array(
'project_name' => 'motion-UI',
'project_dir_name' => 'motionui',
'project_logo' => 'https://raw.githubusercontent.com/lbr38/motion-UI/main/www/public//assets/images/motion.png',
'project_logo' => 'https://raw.githubusercontent.com/lbr38/motion-UI/main/www/public/assets/images/motion.png',
'project_git_repo' => 'https://github.com/lbr38/motion-UI',
'project_git_repo_raw' => 'https://raw.githubusercontent.com/lbr38/motion-UI/main',
'project_update_doc_url' => 'https://github.com/lbr38/motion-UI/wiki/01.-Installation-and-update#update-motion-ui'
Expand Down
23 changes: 17 additions & 6 deletions www/controllers/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Mail
{
public function __construct(string|array $to, string $subject, string $content, string $link = null, string $linkName = 'Click here', string $attachmentFilePath = null)
public function __construct(string $to, string $subject, string $content, string $link = null, string $linkName = 'Click here', string $attachmentFilePath = null)
{
if (empty($to)) {
throw new \Exception('Error: mail recipient cannot be empty');
Expand All @@ -23,13 +23,16 @@ public function __construct(string|array $to, string $subject, string $content,
throw new \Exception('Error: mail message cannot be empty');
}

if (is_array($to)) {
$to = implode(',', $to);
/**
* if there is a , in the $to string, it means there are multiple recipients
*/
if (strpos($to, ',') !== false) {
$to = explode(',', $to);
}

/**
* HTML message template
* Powered by stripo.email
* Powered by MJML
*/
ob_start();
include(ROOT . '/templates/mail/mail.template.html.php');
Expand All @@ -43,7 +46,15 @@ public function __construct(string|array $to, string $subject, string $content,
try {
// Recipients
$mail->setFrom('noreply@' . WWW_HOSTNAME, PROJECT_NAME);
$mail->addAddress($to);

if (is_array($to)) {
foreach ($to as $recipient) {
$mail->addAddress($recipient);
}
} else {
$mail->addAddress($to);
}

$mail->addReplyTo('noreply@' . WWW_HOSTNAME, PROJECT_NAME);

// Attachments
Expand All @@ -58,7 +69,7 @@ public function __construct(string|array $to, string $subject, string $content,

$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
throw new Exception('Error: mail could not be sent. Mailer Error: ' . $mail->ErrorInfo);
}
}
}
13 changes: 13 additions & 0 deletions www/controllers/ajax/motion.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* Send a test email
*/
if ($_POST['action'] == "sendTestEmail" and !empty($_POST['mailRecipient'])) {
try {
$mymail = new \Controllers\Mail($_POST['mailRecipient'], 'Test email', 'This is a test email sent by motion-UI.');
} catch (Exception $e) {
response(HTTP_BAD_REQUEST, $e->getMessage());
}

response(HTTP_OK, 'Email sent');
}

/*
* Enable / disable alerts
*/
Expand Down
33 changes: 33 additions & 0 deletions www/public/resources/js/motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ $(document).on('click','#disable-alert-btn',function () {
enableAlert('disabled');
});

/**
* Event: send a test email
*/
$(document).on('click','#send-test-email-btn',function () {
var mailRecipient = $(this).attr('mail-recipient');
sendTestEmail(mailRecipient);
});

/**
* Event: select stats dates
*/
Expand Down Expand Up @@ -665,6 +673,31 @@ function enableAlert(status)
});
}

/**
* Ajax: send a test email
*/
function sendTestEmail(mailRecipient)
{
$.ajax({
type: "POST",
url: "/ajax/controller.php",
data: {
controller: "motion",
action: "sendTestEmail",
mailRecipient: mailRecipient
},
dataType: "json",
success: function (data, textStatus, jqXHR) {
jsonValue = jQuery.parseJSON(jqXHR.responseText);
printAlert(jsonValue.message, 'success');
},
error: function (jqXHR, textStatus, thrownError) {
jsonValue = jQuery.parseJSON(jqXHR.responseText);
printAlert(jsonValue.message, 'error');
},
});
}

/**
* Ajax: configure alerts
* @param {*} mondayStart
Expand Down
2 changes: 1 addition & 1 deletion www/public/resources/styles/common.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* v1.2
* v1.3
*/

/**
Expand Down
Loading

0 comments on commit caf1cdd

Please sign in to comment.