This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpoll.new.php
67 lines (55 loc) · 1.9 KB
/
poll.new.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
<?php
// FOR DEVELOPMENT: UN-COMMENT TO PRINT ERRORS AND WARNINGS
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
require_once "config/config.features.php";
if (isset($_POST["title"])
&& isset($_POST["dates"])
&& is_array($_POST["dates"])
&& sizeof($_POST["dates"]) > 0
&& sizeof($_POST["dates"]) <= SPR_MAX_POLL_DATES){
require_once "db.php";
$db = new DB();
// try to pass anti-spam (if enabled)
if (!$db->antiSpam($_SERVER['REMOTE_ADDR'])){
//BLOCKED
header("Location: index.php?blocked");
exit();
}
//prep data
$title = trim(htmlspecialchars($_POST["title"]));
$details = trim(preg_replace("/\s+/", " ", htmlspecialchars($_POST["details"])));
require_once "poll.model.php";
$poll = new Poll(
// id
hash("crc32", time() . htmlspecialchars($_POST["title"])),
// adminId
isset($_POST["adminLink"]) && strcmp("true", $_POST["adminLink"]) == 0
? hash("crc32", time() . $title . "admin")
: "NA",
// title
strlen($title) > 0 ? $title : "Sprudel",
// details
$details,
// changed (null - will be set when written to db)
null
);
// set poll dates
$poll->setDates(
$db->transformPollDates(
$poll->getId(),
$_POST["dates"]
)
);
//write data to polls table
$db->createPoll($poll);
//redirect to poll
$redir = "poll.php?poll=" . $poll->getId()
. (strcmp($poll->getAdminId(), "NA") != 0
? ("&adm=" . $poll->getAdminId())
: "");
header("Location: " . $redir);
exit();
}
?>