-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaddevent.php
112 lines (106 loc) · 3.48 KB
/
addevent.php
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
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
session_start();
function sanitize($string){
$string = strip_tags($string);
$string = str_replace("&", "&", $string);
$string = str_replace("\"", """, $string);
$string = str_replace("'", "'", $string);
$string = str_replace("<", "<", $string);
$string = str_replace(">", ">", $string);
return $string;
}
function leadZero($nmb){
if($nmb < 10){
$nmb = "0".(string)$nmb;
return $nmb;
}else{
$nmb = (string)$nmb;
return $nmb;
}
}
function dateArray($date, $time){
$datearray = explode(".", $date);
$timearray = explode(":", $time);
$dt = [
"day" => intval($datearray[0]),
"month" => intval($datearray[1]),
"year" => intval($datearray[2]),
"hour" => intval($timearray[0]),
"minute" => intval($timearray[1]),
];
$dt["day"] = leadZero($dt["day"]);
$dt["month"] = leadZero($dt["month"]);
$dt["year"] = (string)$dt["year"];
$dt["hour"] = leadZero($dt["hour"]);
$dt["minute"] = leadZero($dt["minute"]);
return $dt;
}
function dateString($date){
$datestr = $date["year"]."-".$date["month"]."-".$date["day"]."T".$date["hour"].":".$date["minute"].":00";
return $datestr;
}
function challengeString(){
$chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$chstr = "";
for($i = 0; $i < 8; $i++){
$chstr .= $chars[rand(0, strlen($chars) - 1)];
}
return $chstr;
}
function sendChallenge($address, $subject){
$subject .= " - Verifizierung";
$challenge = challengeString();
$body = "Zur Verifizierung Ihrer Email klicken sie bitte auf folgenden Link:\n http://jkliemann.de/offenesdresden.de/challenge.php?id=".session_id()."&code=".$challenge;
$header = "From: [email protected]\r\nX-Mailer: PHP/".phpversion();
if(mail($address, $subject, $body, $header)){
return $challenge;
}else{
echo "Es ist ein Fehler aufgetreten.\n";
}
}
$title = sanitize($_POST["title"]);
$startdate = sanitize($_POST["startdate"]);
$starttime = sanitize($_POST["starttime"]);
$enddate = sanitize($_POST["enddate"]);
$endtime = sanitize($_POST["endtime"]);
$location = sanitize($_POST["location"]);
$type = $_POST["type"];
$link = sanitize($_POST["link"]);
$mail = sanitize($_POST["mail"]);
$start = dateArray($startdate, $starttime);
$end = dateArray($enddate, $endtime);
if(!$start or !$end){
echo "<p>Es ist ein Eingabefehler aufgetreten.</p><a href='addevent.html'>Zurück</a>";
}else{
$startstring = dateString($start);
$endstring = dateString($end);
$varxml = "<event title=\"".$title."\">\n<start>".$startstring."</start>\n<end>".$endstring."</end>\n<location>".$location."</location>\n<link>".$link."</link>\n<mail>".$mail."</mail>\n</event>\n";
$challenge = sendChallenge($mail, $title);
$_SESSION["challenge"] = $challenge;
$_SESSION["title"] = $title;
$_SESSION["xml"] = $varxml;
$_SESSION["type"] = $type;
$_SESSION["mail"] = $mail;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Event einreichen</title>
<body>
<fieldset>
<legend>Eventdaten</legend>
<?php
echo "<p><label>Titel:<br/>".$title."</label></p>";
echo "<p><label>Start:<br/>".$start["day"].".".$start["month"].".".$start["year"]." ".$start["hour"].":".$start["minute"]."</label></p>";
echo "<p><label>Ende: <br/>".$end["day"].".".$end["month"].".".$end["year"]." ".$end["hour"].":".$end["minute"]."</label></p>";
echo "<p><label>Ort:<br/>".$location."</label></p>";
echo "<p><label>Link:<br/>".$link."</label></p>";
echo "<p><label>Kategorie: <br/>".$type."</label></p>";
echo "<p><label>E-Mail:<br/>".$mail."</label></p>";
?>
<p>E-Mail wurde versandt.</p>
</fieldset>
</body>
</html>