-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
167 lines (137 loc) · 4.13 KB
/
index.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
date_default_timezone_set('America/Argentina/Buenos_Aires');
$people = file_get_contents('people.json');
$peoplejson = stripslashes($people);
#echo $peoplejson;
$people = json_decode($people);
#print_r($people);
$results = file_get_contents('results.json');
$resultsjson = $results;
#echo $resultsjson;
$results = json_decode($results);
#print_r($results);
if ($_GET['audit']) {
file_put_contents("auditoria.htm",$_SERVER['REMOTE_ADDR']." - ".$_GET['audit']."\r\n",FILE_APPEND);
}
if ($_GET['taked']) {
#echo htmlentities($_GET['drawed']);
// Search
$pos = array_search(htmlentities($_GET['taked']), $people);
// Remove from array
#echo $results[$pos];
unset($people[$pos]);
$jsonData = json_encode(array_values($people));
file_put_contents('people.json', $jsonData);
die(htmlentities(" / ".$_GET['drawed'])." quitado de people.json");
}
if ($_GET['drawed']) {
#echo htmlentities($_GET['drawed']);
// Search
$pos = array_search(htmlentities($_GET['drawed']), $results);
// Remove from array
#echo $results[$pos];
unset($results[$pos]);
$jsonData = json_encode(array_values($results));
file_put_contents('results.json', $jsonData);
die(htmlentities(" / ".$_GET['drawed'])." quitado de results.json");
}
?>
<!DOCTYPE html>
<html lang="es" >
<head>
<meta charset="UTF-8">
<title>Amigo Invisible</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="wrapper" style="margin-top: 20vh;">
<h1>Amigo Invisible</h1>
<div class="select-wrap" id="peopleWrap">
<select id="people"></select>
<span class="arrow"></span>
</div>
<div><button id="choose">¿Quién me tocó?</button></div>
<div id="result"></div>
<div class="close"><span id="close"></span></div>
</div>
<script>window.onload = function()
{
drawList();
};
var nosorteados = <? echo $resultsjson;?> ;
var give = <? echo $peoplejson;?>;
var receive = nosorteados.concat();
var peopleWrap = document.getElementById('peopleWrap');
var people = document.getElementById('people');
var choose = document.getElementById('choose');
var result = document.getElementById('result');
var close = document.getElementById('close');
function drawList()
{
people.innerHTML = '<option value="">Quién sos vos?</option>';
for (var i = give.length - 1; i >= 0; i--) {
var option = document.createElement('option');
option.value = i;
option.innerHTML = give[i];
people.appendChild(option);
}
}
function selectPerson(person)
{
var name = give[person];
var nameIndex = receive.indexOf(name);
if(nameIndex >= 0)
{
receive.splice(nameIndex, 1);
}
var recipient = Math.floor((Math.random() * receive.length));
var recipientName = receive[recipient];
receive.splice(recipient, 1);
give.splice(person, 1);
if(nameIndex >= 0)
{
receive.push(name);
}
const Http2 = new XMLHttpRequest();
const url2='http://www.jeanphillippe.com/navidad/index.php?taked='+ name;
Http2.open("GET", url2);
Http2.send();
const Http3 = new XMLHttpRequest();
const url3='http://www.jeanphillippe.com/navidad/index.php?audit=<? echo date("d-m-Y H:i a");?> - ' + name + ", te toco " + recipientName + "!<br/>";
Http3.open("GET", url3);
Http3.send();
const Http = new XMLHttpRequest();
const url='http://www.jeanphillippe.com/navidad/index.php?drawed='+ recipientName;
Http.open("GET", url);
Http.send();
result.innerHTML = "<h2>" + name + ", te tocó " + recipientName + "!</h2>";
close.innerHTML = "Este resultado fue guardado.";
if(give.length > 0)
{
drawList();
}
}
choose.onclick = function()
{
if(people.value)
{
selectPerson(people.value);
}
};
close.onclick = function()
{
result.innerHTML = "";
close.innerHTML = "";
if(give.length == 0){
peopleWrap.parentNode.removeChild(peopleWrap);
choose.parentNode.removeChild(choose);
result.innerHTML = "<h2>Eso es todo!</h2>";
close.innerHTML = "";
}
};</script>
</body>
</html>