diff --git a/Dockerfile b/Dockerfile index e6e0038..89d9d6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM kimbtechnologies/php_nginx:latest +FROM kimbtechnologies/php_smtp_nginx:latest # add gd for captcha RUN apk add --update --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \ diff --git a/VERSION b/VERSION index 03b0ef5..2fbd1df 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ latest -1.1.2 +1.1.4 1.1 1 diff --git a/core/Mail.php b/core/Mail.php new file mode 100644 index 0000000..f0cdcbc --- /dev/null +++ b/core/Mail.php @@ -0,0 +1,79 @@ +type = 'mail' . $mailType; + if( !in_array( $this->type, self::$templates ) ){ + throw new Exception('Unknown Mail Template Type'); + } + $this->template = new Template( $this->type ); + + $this->setUpMailMeta(); + } + + /** + * Set a content key in the mail template + */ + public function setContent( $key, $value ){ + $this->template->setContent($key, $value); + } + + /** + * Sets up the meta data for the mail (header, ...) + */ + private function setUpMailMeta(){ + $c = new Config(); + preg_match( '/https?:\/\/([^\/\:]+).*/', $c->getValue(['site', 'hosturl']), $match ); + if( !isset($match[1])){ + $match[1] = 'example.com'; + } + + $this->mailHeader = implode("\r\n", + array( + 'MIME-Version: 1.0', + 'Content-type: text/html; charset=utf-8', + 'From: KIMB-Forms ' + ) + ); + } + + /** + * Sends the created Mail + * @param $to The destination mail address + */ + public function sendMail(string $to){ + mail( + $to, + LanguageManager::getTranslation($this->type), + $this->template->getOutputString(), + $this->mailHeader + ); + } +} + +?> \ No newline at end of file diff --git a/core/Poll.php b/core/Poll.php index 1eb5e12..894f05c 100644 --- a/core/Poll.php +++ b/core/Poll.php @@ -152,6 +152,23 @@ public function saveSendData( $template ){ //logfile file_put_contents( __DIR__ . '/../data/pollsubmissions.log', json_encode( array( $this->id, $name, $mail, $termine, time() ) ) . "\r\n" , FILE_APPEND | LOCK_EX ); + if( $this->polldata->isValue(['notifymails']) ){ + $tos = $this->polldata->getValue(['notifymails']); + if( !empty($tos)){ + $m = new Mail( 'AdminNotif' ); + + $m->setContent('POLLNAME', Utilities::optimizeOutputString($this->polldata->getValue( ['pollname'] ))); + $m->setContent('TERMINE', ''); + $m->setContent('NAME', Utilities::optimizeOutputString( $name )); + $m->setContent('EMAIL', Utilities::optimizeOutputString( $mail )); + $m->setContent('ADMINLINK', URL::generateLink('admin', '', $this->polldata->getValue(['code', 'admin']))); + + foreach( $tos as $to ){ + $m->sendMail( $to ); + } + } + } + return true; } else{ diff --git a/core/PollAdmin.php b/core/PollAdmin.php index 6debea9..7bb6811 100644 --- a/core/PollAdmin.php +++ b/core/PollAdmin.php @@ -108,6 +108,10 @@ private function showInfo(){ $this->template->setContent( 'EXPORTLINK', URL::generateAPILink('export', array( 'type' => 'csv', 'admin' => $this->polldata->getValue(['code', 'admin']) ) ) ); $this->template->setContent( 'PRINTLINK', URL::generateAPILink('export', array( 'type' => 'print', 'admin' => $this->polldata->getValue(['code', 'admin']) ) ) ); + if( $this->polldata->isValue(['notifymails']) ){ + $this->template->setContent( 'NOTIFMAILS', implode( ',', $this->polldata->getValue(['notifymails']) ) ); + } + $termine = array(); $terminmeta = array(); $submissempty = true; diff --git a/core/PollCreator.php b/core/PollCreator.php index 12be2b4..b640081 100644 --- a/core/PollCreator.php +++ b/core/PollCreator.php @@ -40,6 +40,7 @@ class PollCreator{ 'pollname' => '', 'formtype' => '', 'description' => '', + 'notifymails' => array(), 'termine' => array() ); private $errormsg = ''; diff --git a/core/Utilities.php b/core/Utilities.php index b7ef4d1..09c4964 100644 --- a/core/Utilities.php +++ b/core/Utilities.php @@ -16,7 +16,7 @@ class Utilities{ /** * The system's Version */ - const SYS_VERSION = 'v1.1.3'; + const SYS_VERSION = 'v1.1.4'; /** * Possible chars for: @@ -47,7 +47,7 @@ public static function optimizeOutputString($cont){ * **no boolean return** * @param $s the string to check * @param $reg the regular expressions (/[^a-z]/ to allow only small latin letters) - * @param $len the maximum lenght + * @param $len the maximum length * @return the clean string (empty, if other input than string or only dirty characters) */ public static function validateInput($s, $reg, $len){ diff --git a/core/api/EditPoll.php b/core/api/EditPoll.php index 260a88e..d4ce455 100644 --- a/core/api/EditPoll.php +++ b/core/api/EditPoll.php @@ -31,6 +31,10 @@ public function __construct(){ //poll meta aendern $this->changePoll( $_POST['name'], $_POST['desc'] ); } + else if( isset( $_POST['maillist'] ) ) { + //set poll notifications mails + $this->setMailList( $_POST['maillist'] ); + } die( 'nok' ); } @@ -76,6 +80,25 @@ private function changeDate( $n, $h, $a, $t ){ } } } + + private function setMailList( string $list ){ + $mails = Utilities::validateInput($list, Poll::PREG_MAIL, 500); + $mails = explode( ',', $list ); + $mails = array_map( + function ($m) { + return trim( $m ); + }, + $mails + ); + $savemails = array(); + foreach( $mails as $m ){ + if( filter_var( $m, FILTER_VALIDATE_EMAIL ) !== false ){ + $savemails[] = $m; + } + } + $this->polldata->setValue(['notifymails'], $savemails); + die('ok'); + } } ?> \ No newline at end of file diff --git a/core/templates/admin.json b/core/templates/admin.json index f9d0b65..b0add23 100644 --- a/core/templates/admin.json +++ b/core/templates/admin.json @@ -9,6 +9,7 @@ "%%EXPORTLINK%%" : "/export", "%%PRINTLINK%%" : "/print", "%%JSONDATA%%" : "[]", + "%%NOTIFMAILS%%" : "", "multiples" : { "Termin" : { "%%NAME%%" : "Termin A", diff --git a/core/templates/admin_de.html b/core/templates/admin_de.html index 6437172..e68ac5a 100644 --- a/core/templates/admin_de.html +++ b/core/templates/admin_de.html @@ -28,6 +28,17 @@

Administration

+
+
+ E-Mail Benachrichtigung +
+
+ +
+
+ +
+
diff --git a/core/templates/admin_en.html b/core/templates/admin_en.html index 59fabbb..e5bfa28 100644 --- a/core/templates/admin_en.html +++ b/core/templates/admin_en.html @@ -28,6 +28,17 @@

Admin

+
+
+ E-Mail notification +
+
+ +
+
+ +
+
diff --git a/core/templates/mailAdminNotif.json b/core/templates/mailAdminNotif.json new file mode 100644 index 0000000..2183796 --- /dev/null +++ b/core/templates/mailAdminNotif.json @@ -0,0 +1,7 @@ +{ + "%%POLLNAME%%": "", + "%%TERMINE%%": "", + "%%NAME%%": "", + "%%EMAIL%%": "", + "%%ADMINLINK%%": "" +} \ No newline at end of file diff --git a/core/templates/mailAdminNotif_de.html b/core/templates/mailAdminNotif_de.html new file mode 100644 index 0000000..cf17565 --- /dev/null +++ b/core/templates/mailAdminNotif_de.html @@ -0,0 +1,21 @@ + + +

Neue Teilnahme

+

%%POLLNAME%%

+
    +
  • + Gewählte Termine
    + %%TERMINE%% +
  • +
  • + %%NAME%% +
  • +
  • + %%EMAIL%% +
  • +
+ + Zum Adminbereich + + + \ No newline at end of file diff --git a/core/templates/mailAdminNotif_en.html b/core/templates/mailAdminNotif_en.html new file mode 100644 index 0000000..97b00e4 --- /dev/null +++ b/core/templates/mailAdminNotif_en.html @@ -0,0 +1,21 @@ + + +

New Submission

+

%%POLLNAME%%

+
    +
  • + Choosen options
    + %%TERMINE%% +
  • +
  • + %%NAME%% +
  • +
  • + %%EMAIL%% +
  • +
+ + Open admin section + + + \ No newline at end of file diff --git a/data/translation_de.json b/data/translation_de.json index 65609d5..c81d37b 100644 --- a/data/translation_de.json +++ b/data/translation_de.json @@ -20,5 +20,6 @@ "TooManySubmiss": "Diese Umfrage hat die maximale Anzahl an Antworten erreicht.", "HelfFin": "Helfer finden", "TermFin": "Termin finden", - "Teilnehm": "Teilnehmende" + "Teilnehm": "Teilnehmende", + "mailAdminNotif": "Neue Teilnahme" } \ No newline at end of file diff --git a/data/translation_en.json b/data/translation_en.json index 781cf2a..55a313a 100644 --- a/data/translation_en.json +++ b/data/translation_en.json @@ -20,5 +20,6 @@ "TooManySubmiss": "This poll has reached the limit of submissions.", "HelfFin": "Coordinate volunteers", "TermFin": "Schedule meetings", - "Teilnehm" : "attendees" + "Teilnehm": "Attendees", + "mailAdminNotif": "New Submission" } \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 4f37f6a..d9d29ac 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -23,4 +23,8 @@ services: - CONF_texts_enableNew=true - CONF_texts_textPoll=Ich bin mit den Datenschutzrichlinien ... einverstanden! - CONF_texts_textNew=Ich bin mit den AGB des Anbieters einverstanden! - - CONF_cookiebanner=false \ No newline at end of file + - CONF_cookiebanner=false + - SMTP_SERVER= + - SMTP_PORT= + - SMTP_USER= + - SMTP_PASS= \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index ec511f6..fad5180 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,4 +20,8 @@ services: - CONF_texts_enableNew=true - CONF_texts_textPoll=Ich bin mit den Datenschutzrichlinien ... einverstanden! - CONF_texts_textNew=Ich bin mit den AGB des Anbieters einverstanden! - - CONF_cookiebanner=false \ No newline at end of file + - CONF_cookiebanner=false + - SMTP_SERVER= # the mail server host (used for admin notification mails) + - SMTP_PORT= # the port to deliver mails (587 for starttls or 465 for tls) + - SMTP_USER= # the username for the mail server + - SMTP_PASS= # the password for the mail server \ No newline at end of file diff --git a/load/main.js b/load/main.js index 453c03b..3714d7f 100644 --- a/load/main.js +++ b/load/main.js @@ -448,6 +448,30 @@ function template_admin(){ if( !template_data.submissempty ){ $("button#swapbutton").prop('disabled', true); } + + function saveEMailList(){ + $( "button#notifmailsSave" ).prop('disabled', true); + $.post( template_data.editurl, + { + "maillist" : $("input#notifmailsList").val() + }, + function (data){ + if( data == 'ok' ){ + $("button#notifmailsSave").removeClass('btn-light'); + $("button#notifmailsSave").addClass('btn-success'); + $("button#notifmailsSave").prepend('✔ '); + refreshView('notifmailsList'); + } + else{ + $("button#notifmailsSave").removeClass('btn-light'); + $("button#notifmailsSave").addClass('btn-danger'); + $("button#notifmailsSave").prepend('✘ '); + $( "button#notifmailsSave" ).prop('false', true) + } + } + ); + } + $("button#notifmailsSave").click( saveEMailList ); } /**