-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
81 lines (68 loc) · 2.87 KB
/
Copy pathindex.php
File metadata and controls
81 lines (68 loc) · 2.87 KB
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
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
\UMLPoll\Database::connect($DB_SERVER, $DB_USER, $DB_PASS, $DB_DATABASE);
\UMLPoll\Database::charset("utf8");
$loader = new Twig_Loader_Filesystem(__DIR__ . '/res/twig/templates');
$twig = new Twig_Environment($loader, array(
'cache' => __DIR__ . '/compilation_cache',
'output_encoding' => 'UTF-8',
'auto_reload' => true
)
);
$twig_vars = array(
'page_title' => 'UML Poll',
'script_dir' => ""
);
switch (filter_input(INPUT_GET, 'p')) {
case 'newpoll':
$template_file = "newpoll/polldone.twig";
$get_id = filter_input(INPUT_GET, 'id');
$submit_token = filter_input(INPUT_POST, 'submit');
if ($get_id !== NULL && $submit_token !== NULL) {
$_exists_poll = \UMLPoll\Poll\Poll::existsPoll($get_id);
if ($_exists_poll === TRUE) {
$_is_valid_token = \UMLPoll\Poll\Token::isValid($get_id, $submit_token);
if ($_is_valid_token === TRUE) {
\UMLPoll\Poll\Token::delete($get_id, $submit_token);
$post_vars = filter_input_array(INPUT_POST);
$valid_values = [];
foreach ($post_vars as $key => $value) {
if (preg_match("/^q_(\d+)$/", $key, $result) === 1) {
$valid_values[$result[1]] = $value;
}
}
if (count($valid_values) > 0) {
$twig_vars['poll_id'] = $get_id;
\UMLPoll\Poll\Poll::insertResponses($get_id, $valid_values);
} else {
$twig_vars['poll_error'] = 4; // No hay datos a ingresar
}
} else {
$twig_vars['poll_error'] = 3; // El token es invalido
}
} else {
$twig_vars['poll_error'] = 2; // No existe la encuesta
}
} else {
$twig_vars['poll_error'] = 1; // Link invalido
}
break;
case 'results':
$template_file = "results/results.twig";
$poll_array = \UMLPoll\Poll\Poll::get((filter_input(INPUT_GET, 'id') !== NULL ? filter_input(INPUT_GET, 'id') : 1));
break;
case 'poll':
$template_file = "poll/poll.twig";
$poll_array = \UMLPoll\Poll\Poll::get((filter_input(INPUT_GET, 'id') !== NULL ? filter_input(INPUT_GET, 'id') : 1));
$poll_token = \UMLPoll\Poll\Token::generate();
\UMLPoll\Poll\Token::insert(filter_input(INPUT_GET, 'id'), $poll_token);
$twig_vars['poll_token'] = $poll_token;
break;
default:
$template_file = "home.twig";
break;
}
$twig_vars['poll_array'] = (isset($poll_array) ? $poll_array : NULL);
echo $twig->render($template_file, $twig_vars);
\UMLPoll\Database::close();