-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.php
More file actions
215 lines (200 loc) · 6.03 KB
/
script.php
File metadata and controls
215 lines (200 loc) · 6.03 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
define("START_TIME",microtime(true));
?>
<!DOCTYPE html>
<html>
<head>
<title>Лаба 1</title>
<meta charset="utf-8">
<style>
body {
background: #5FC0CE;
}
header {
font-size: medium;
color: #FFAE00;
text-shadow: 1px 1px 2px #FF1300;
}
header > table {
background-color: #03899C;
width: 100%;
line-height: 0;
min-width: 450px;
}
table.rounded-corners {
border-radius: 50px;
border: 3px solid #03799D;
}
header h1 {
text-align: center
}
article div.error-div {
text-align: center;
color: #dd0c00;
text-shadow: 1px 1px 2px #FFAE00;
font-size: larger;
}
#back-page-button {
height: 60px;
width: 200px;
border-radius: 15px;
border: 3px solid #03799D;
background-color: #03899C;
text-shadow: 1px 1px 2px #FF1300;
color: #FFAE00;
padding: 0 2% 0 2%;
outline: none;
cursor: pointer;
}
#back-page-button:active {
background-color: #5FC0CE;
}
article table {
text-align: center;
width: 100%;
}
table.article-table {
border-collapse: collapse;
border: 3px solid #03799D;
}
table.article-table td {
border: 3px solid #03799D;
}
table.article-table th {
border: 3px solid #03799D;
}
article span#yes {
color: #009000;
font-weight: bold;
}
article span#no {
color: #aa2223;
font-weight: bold;
}
span.sort-symbol {
font-size: medium;
cursor: pointer;
}
</style>
<script src="sort_table.js" async></script>
</head>
<body>
<header>
<table class="rounded-corners">
<tr>
<td><h1>Результаты проверки</h1></td>
</tr>
</table>
</header>
<article>
<br>
<table class="article-table" rules="all">
<colgroup style="background-color: #21cfda">
<col>
<col>
<col>
</colgroup>
<colgroup style="background-color: #51c7da">
<col>
</colgroup>
<?php
$x = str_replace(",", ".", $_REQUEST['param-x']);
$y = str_replace(",", ".", $_REQUEST['param-y']);
$r = str_replace(",", ".", $_REQUEST['param-r']);
if (is_numeric($x) && is_numeric($y) && is_numeric($r) && floatval($r) >= 0) {
?>
<thead onclick="sort(event);">
<tr>
<th>X <span class="sort-symbol">⮃</span></th>
<th>Y <span class="sort-symbol">⮃</span></th>
<th>R <span class="sort-symbol">⮃</span></th>
<th data-type="reverse">Попадание <span class="sort-symbol">⮃</span></th>
</tr>
</thead>
<?php
$file = fopen("data.txt",'a');
$tmpString = round($x,16)." ".round($y,16)." ".round($r,16)." ".($x >= 0 && $x <= $r && $y <= $r/2 && $y >= 0
|| $x <= 0 && $y >= 0 && $y <= $x + $r
|| $x <= 0 && $y <= 0 && $y*$y <= $r*$r - $x*$x
? 'y' : 'n')."\n";
fwrite($file, $tmpString);
$file = fopen("data.txt",'r');
while (!feof($file)) {
$string = fgets($file);
$array = preg_split("/\s/", $string);
if ($array[3]) {
?>
<tr>
<td><?php echo $array[0]; ?></td>
<td><?php echo $array[1]; ?></td>
<td><?php echo $array[2]; ?></td>
<td><?php if ($array[3] == 'y')
echo '<span id="yes">да</span>';
else
echo '<span id="no">нет</span>'; ?>
</td>
</tr>
<?php
}
}
?>
</table>
<br>
<table>
<colgroup style="background-color: #36BBCE">
<col>
<col>
</colgroup>
<thead>
<tr>
<th>Текущее время</th>
<th>Время работы скрипта</th>
</tr>
</thead>
<td id="time-td">
<script>
function setTime() {
document.getElementById("time-td").innerHTML = new Date().toLocaleTimeString();
}
setInterval(setTime,1000);
setTime();
</script>
</td>
<td>
<?php printf("%.2f мкс", (microtime(true) - START_TIME)*1000000); ?>
</td>
<?php } else { ?>
<tr>
<td>
<br>
<div class="error-div">Введены неправильные данные!</div>
<br>
</td>
</tr>
<tr>
<td>
<?php
echo '<div style="font-size: large">'
. 'x = ' . ($x ?: 'неизвестно') . '<br>'
. 'y = ' . ($y ?: 'неизвестно') . '<br>'
. 'r = ' . ($r ?: 'неизвестно')
. '</div>';
?>
<br>
</td>
</tr>
<?php } ?>
</table>
<br>
<table>
<tr>
<td colspan="6">
<form action="index.html">
<button id="back-page-button" type="submit">Вернуться на страницу ввода параметров</button>
</form>
</td>
</tr>
</table>
</article>
</body>
</html>