summaryrefslogtreecommitdiff
path: root/intern.gospeladlershof.de/code/erinnerung.php
blob: 89b2dcecc650b448c1e83310c3dcd18fee438c65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

require_once __DIR__ . '/db.php';
require_once __DIR__ . '/../vendor/autoload.php';

use Pheanstalk\Pheanstalk;

$db = get_db();
$error_msg = "";

if ( false === $db ) {
	$error_msg = "Kann keine Verbindung zur Datenbank herstellen.";
} else {
	try {
		$res = $db->query('SELECT count(*) FROM proben WHERE date(STR_TO_DATE(termin, "%d.%m.%Y")) > (SELECT CURDATE() ) ORDER BY date(STR_TO_DATE(termin, "%d.%m.%Y"));');
		$count_proben = $res->fetch(PDO::FETCH_NUM)[0];
	} catch(Exception $e) {
		$error_msg = $e->getMessage();
	}
}

if ( $error_msg != "" ) {
	// Fehlerbehandlung
	// schickt mir ne E-Mail mit der Fehlermeldung
	$pheanstalk = new Pheanstalk('192.168.122.1');

	$data = array(
		'To' => array('status@iamfabulous.de'),
		'Name' => 'Fehler | Gospelchor Adlershof',
		'From' => 'noreply@gospeladlershof.de',
		'ReplyTo' => 'status@iamfabulous.de',
		'Subject' => 'Gospelchor Adlershof | Error',
		'HTMLMessage' => null,
		'TextMessage' => $error_msg,
	);

	$pheanstalk
		->useTube('contactme_mail')
		->put(json_encode($data));	
} else {
	if ( $count_proben <= 3 ) {
		// email schicken, da wenige proben in der datenbank vorhanden sind
		$pheanstalk = new Pheanstalk('192.168.122.1');

		$data = array(
			'To' => array('status@iamfabulous.de'),
			'Name' => 'Gospelchor Adlershof',
			'From' => 'noreply@gospeladlershof.de',
			'ReplyTo' => 'status@iamfabulous.de',
			'Subject' => '[Chor-Admin] Wenige Proben',
			'HTMLMessage' => null,
			'TextMessage' => 'Hi Lotte\r\nes sind nur noch ' . $count_proben . ' eingetragen.\r\n\r\nViele Grüße\r\nMax',
		);

		$pheanstalk
			->useTube('contactme_mail')
			->put(json_encode($data));	
		}
}