Newer
Older
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* Header
*/
header('X-ATEndpoint: YES');
header('Access-Control-Allow-Origin: *');
include '../include/config.inc.php';
include '../include/tgSqliteDB.class.php';
include '../include/tgLdap.class.php';
include '../include/tgImap.class.php';
$db = new tgSqliteDB($conf);
$ldap = new tgLdap($conf);
$imap = new tgImap($conf);
// Work around magic_quotes_gpc
if (get_magic_quotes_gpc()) {
$data = stripslashes($_POST['data']);
} else {
$data = $_POST['data'];
}
/**
* Validation
*/
$in = json_decode($data, TRUE);
$out['status'] = 'Validating ...';
if($in['name'] == $in['surname']) {
$out['error']['surname'] = 'spamSuspicion';
}
if($ldap->uidExists($in['userid'])) {
$out['error']['userid'] = 'uidUsed';
}
if(empty($in['email'])) {
$out['error']['email'] = 'emailMissing';
}
if($ldap->emailExists($in['email'])) {
$out['error']['email'] = 'emailUsed';
}
if(isset($out['error'])) {
echo json_encode($out);
return;
}
/**
* Insert request
*/
// If no language given, default to English
if(!isset($in['lang'])) {
$in['lang'] = 'en';
}
$db->insertUserRequest($in);
/**
* Send e-mails
*/
function sendMails($conf, $imap, $db, $data) {
// User
$templateID = ($data['lang'] == 'de') ? 6 : 5;
$mail = $db->getMailTemplate($templateID);
$imap->mail($data['email'], $mail['subject'], $mail['body']);
// TextGrid team
$body = '';
foreach($data as $key => $value) {
$body .= $key . ': ' . $value . "\n";
}
$body .= "\nLink zum Backend: " . $conf['url'];
$imap->mail($conf['mail']['cc'], 'New request', $body);
}
sendMails($conf, $imap, $db, $in);
/**
* Return data
*/
echo json_encode(array('status' => 'done'));
?>