Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Jan 3, 2020
1 parent ef73db7 commit fc54575
Show file tree
Hide file tree
Showing 19 changed files with 238 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
latest
1.1.2
1.1.4
1.1
1
79 changes: 79 additions & 0 deletions core/Mail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* KIMB-Forms-Project
* https://github.com/KIMB-technologies/KIMB-Forms-Project
*
* (c) 2018 - 2020 KIMB-technologies
* https://github.com/KIMB-technologies/
*
* released under the terms of GNU Public License Version 3
* https://www.gnu.org/licenses/gpl-3.0.txt
*/
defined( 'KIMB-FORMS-PROJECT' ) or die('Invalid Endpoint!');

/**
* System Mailer Class
* Uses PHP-Mail Function (to use SMTP use the Docker-Image, which uses internally https://hub.docker.com/r/kimbtechnologies/php_smtp_nginx)
*/
class Mail {

private static $templates = array(
'mailAdminNotif'
);

private $type, $template, $mailHeader;

/**
* Creates the Mail (also using a HTML Template)
*/
public function __construct( string $mailType ){
$this->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 <forms@' . $match[1] . '>'
)
);
}

/**
* 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
);
}
}

?>
17 changes: 17 additions & 0 deletions core/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<ul><li>' . implode( '</li><li>', $termine_text ) . '</li></ul>');
$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{
Expand Down
4 changes: 4 additions & 0 deletions core/PollAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions core/PollCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class PollCreator{
'pollname' => '',
'formtype' => '',
'description' => '',
'notifymails' => array(),
'termine' => array()
);
private $errormsg = '';
Expand Down
4 changes: 2 additions & 2 deletions core/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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){
Expand Down
23 changes: 23 additions & 0 deletions core/api/EditPoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

Expand Down Expand Up @@ -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');
}
}

?>
1 change: 1 addition & 0 deletions core/templates/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"%%EXPORTLINK%%" : "/export",
"%%PRINTLINK%%" : "/print",
"%%JSONDATA%%" : "[]",
"%%NOTIFMAILS%%" : "",
"multiples" : {
"Termin" : {
"%%NAME%%" : "Termin A",
Expand Down
11 changes: 11 additions & 0 deletions core/templates/admin_de.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ <h1>Administration</h1>
</a>
</div>
</div>
<div class="row">
<div class="col-sm" title="Liste (kommagetrennt) von E-Mail-Adressen, die bei neuen Eintragungen benachrichtigt werden.">
E-Mail Benachrichtigung
</div>
<div class="col-sm">
<input type="text" class="form-control" value="%%NOTIFMAILS%%" id="notifmailsList">
</div>
<div class="col form-group">
<button type="button" class="btn btn-light" id="notifmailsSave">E-Mail-Adressen speichern</button>
</div>
</div>
</div>
<div class="row">
<div class="col-sm">
Expand Down
11 changes: 11 additions & 0 deletions core/templates/admin_en.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ <h1>Admin</h1>
</a>
</div>
</div>
<div class="row">
<div class="col-sm" title="List (divided by comma) of mail addresses which receive an email on new submissions.">
E-Mail notification
</div>
<div class="col-sm">
<input type="text" class="form-control" value="%%NOTIFMAILS%%" id="notifmailsList">
</div>
<div class="col form-group">
<button type="button" class="btn btn-light" id="notifmailsSave">Save addresses</button>
</div>
</div>
</div>
<div class="row">
<div class="col-sm">
Expand Down
7 changes: 7 additions & 0 deletions core/templates/mailAdminNotif.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"%%POLLNAME%%": "",
"%%TERMINE%%": "",
"%%NAME%%": "",
"%%EMAIL%%": "",
"%%ADMINLINK%%": ""
}
21 changes: 21 additions & 0 deletions core/templates/mailAdminNotif_de.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<body>
<h1>Neue Teilnahme</h1>
<h2>%%POLLNAME%%</h2>
<ul>
<li>
Gewählte Termine<br />
%%TERMINE%%
</li>
<li>
%%NAME%%
</li>
<li>
%%EMAIL%%
</li>
</ul>
<a href="%%ADMINLINK%%">
Zum Adminbereich
</a>
</body>
</html>
21 changes: 21 additions & 0 deletions core/templates/mailAdminNotif_en.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<body>
<h1>New Submission</h1>
<h2>%%POLLNAME%%</h2>
<ul>
<li>
Choosen options<br />
%%TERMINE%%
</li>
<li>
%%NAME%%
</li>
<li>
%%EMAIL%%
</li>
</ul>
<a href="%%ADMINLINK%%">
Open admin section
</a>
</body>
</html>
3 changes: 2 additions & 1 deletion data/translation_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion data/translation_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
6 changes: 5 additions & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- CONF_cookiebanner=false
- SMTP_SERVER=
- SMTP_PORT=
- SMTP_USER=
- SMTP_PASS=
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
24 changes: 24 additions & 0 deletions load/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('&#x2714; ');
refreshView('notifmailsList');
}
else{
$("button#notifmailsSave").removeClass('btn-light');
$("button#notifmailsSave").addClass('btn-danger');
$("button#notifmailsSave").prepend('&#x2718; ');
$( "button#notifmailsSave" ).prop('false', true)
}
}
);
}
$("button#notifmailsSave").click( saveEMailList );
}

/**
Expand Down

0 comments on commit fc54575

Please sign in to comment.