summaryrefslogtreecommitdiff
path: root/intern.gospeladlershof.de/code/erinnerung.php
blob: 27b9b4bf1c6c20cad7e234362bb4da59ecf6c59d (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
60
61
62
63
64
65
66
67
68
69
<?php
/**
 * Das Script wird per Cronjob aufgerufen und überprüft, ob noch genügend Proben eingetragen sind.
 * Wenn nicht, dann wird per E-Mail daran erinnert.
 */

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 <= 4 ) {

$text_msg = 'Hi Lotte,
es sind nur noch ' . $count_proben . ' Proben eingetragen.

Viele Grüße
Max';
		// 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' => $text_msg,
		);

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