This repository has been archived by the owner on Sep 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.php
174 lines (138 loc) · 5.56 KB
/
check.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
168
169
170
171
<!DOCTYPE HTML>
<html>
<head>
<title>answer</title>
<meta charset="utf-8">
<link href="stylesheet-dark.css" rel="stylesheet">
<link href="stylesheet-light.css" rel="stylesheet">
</head>
<body>
<?php
if (session_id()==="") session_start();
$start = microtime(true);
date_default_timezone_set("UTC");
$currentTime = time() + 3 * 3600;
$x = (float)$_GET["x"];
$yStr = (string)$_GET["y"];
$a = str_replace(",", ".", $yStr);
$y = (float)$a;
$switchTheme = $_GET["switch-1"];
$pr = ($switchTheme === "on");
if ((int)$pr === 1) {
echo "<script>
let head = document.head,
link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'stylesheet-dark.css';
document.getElementById('switch-1').setAttribute('checked', true);
head.appendChild(link);
</script>";
}
$rStr = (string)$_GET["r"];
$b = str_replace(",", ".", $rStr);
$r = (float)$b;
if ($_GET["y"] == "-0" || $_GET["y"] == "-0.0" || $_GET["y"] == "-0.00") $y = (float)0.0;
if ($_GET["r"] == "-0" || $_GET["r"] == "-0.0" || $_GET["r"] == "-0.00") $r = (float)0.0;
if (!($x ===-2.0 || $x === -1.5 || $x === -1.0 || $x === -0.5 || $x === 0.0 ||
$x === 0.5 || $x === 1.0|| $x === 1.5|| $x===2.0))
die("<p align='center'>Координата X указана неверно</p>");
if ($y < -5 || $y > 3)
die("<p align='center'> Координата Y указана неверно </p>");
if ($r < 1 || $r > 4)
die("<p align='center'> Радиус R указан неверно </p>");
if (!isset($_SESSION['responses'])) $_SESSION['responses']=array();
$response = new Response($x, $y, $r, $currentTime);
array_push($_SESSION['responses'],$response);
$time=(float)round(microtime(true)-$start,4);
if ($time==0) $time='Менее 0.0001';
echo "<p align='right' class='response-content' id='time'> Сейчас ".date("H:i:s", $currentTime)."</p>";
echo "<p align='left' class='response-content'> Точка ($x;$y) "; echo $response->check_area()? "":"не"; echo " входит в область с радиусом $r </p>";
echo "<p align='left' class='response-content'>Время проверки: ".$time." сек.</p>";
$response->setTime($time);
echo
"<table class='block' id='responsesTable'>
<thead>
<tr >
<th> <h2>Х</h2></th>
<th> <h2>Y</h2></th>
<th> <h2>R</h2></th>
<th> <h2>Текущее время</h2></th>
<th> <h2>Время проверки</h2></th>
<th> <h2>Результат</h2></th>
</tr>
</thead>";
foreach (array_reverse($_SESSION['responses']) as $i=>$response){
$t = date("H:i:s", $response->currentTime);
echo "<tr>
<td>$response->x</td>
<td>$response->y</td>
<td>$response->r</td>
<td>$t</td>
<td>$response->time</td> ";
echo $response->check_area()? "<td>yes </td> </tr>" : "<td>no</td> </tr>";
}
echo "</table>";
echo '<div id="responseFooter">
<div class="switch" align="right" onclick="aaaaa()">
<input type="checkbox" align="right" id="switch-1" class="switch-check">
<label for="switch-1">сделать красиво?</label>
</div>
<div style="clear: left"></div>
</div> ';
class Response{
public $x;
public $y;
public $r;
public $currentTime;
public $time;
function __construct($x,$y,$r, $currentTime)
{
$this->x=$x;
$this->y=$y;
$this->r=$r;
$this->currentTime=$currentTime;
}
function setTime($time) {
$this->time = $time;
}
function check_area(){
if ((($this->x <= 0) && ($this->y >= 0) && (($this->x * $this->x + $this->y * $this->y) <= 0.5 * $this->r)) || /*II четверть*/
(($this->x >= 0) && ($this->y <= 0) && ($this->y >= (0.5 * ($this->x - $this->r)))) || /*IV четверть*/
(($this->x <= 0) && ($this->x >= 0.5 * $this->r) && ($this->y <= 0) && ($this->y >= $this->r))) /*III четверть*/
return true;
else
return false;
}
}
?>
<script>
function aaaaa() {
let head = document.head,
link = document.createElement('link');
link.rel = 'stylesheet';
// проверяем значение из localStorage если dark то темная тема
if (localStorage.getItem('themeStyle') === 'dark') {
link.href = 'stylesheet-dark.css'; // ссылка на темный стиль
document.getElementById('switch-1').setAttribute('checked', true); // переключаем чекбокс в положение "темная тема"
}
// по умолчанию светлая тема
else {
link.href = 'stylesheet-light.css'; // ссылка на светлый стиль
}
head.appendChild(link); // вставляем <link rel="stylesheet" href="light|dark.css"> в шапку страницы между темаги head
// событие при переключении чекбокса
document.getElementById('switch-1').addEventListener('change', ev => {
let btn = ev.target;
// если чекбокс включен
if (btn.checked) {
link.href = 'stylesheet-dark.css'; // сключаем темную тему
localStorage.setItem('themeStyle', 'dark'); // записываем значение в localStorage
} else {
link.href = 'stylesheet-light.css'; // включаем светлую тему
localStorage.setItem('themeStyle', 'light'); // записываем значение в localStorage
}
});
}
</script>
</body>
</html>