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
216
217
218
219
220
221
222
223
224
225
| <!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Классы это класc</title>
</head>
<body>
<br>
<form method="POST">
<p>Пункт назначения: <input type="text" name="place" /></p>
<p>Номер рейса: <input type="text" name="name" /></p>
<p>Тип самолета: <input type="text" name="type" /></p>
<p>Время вылета: <input type="text" name="time" /></p>
<p>День недели: <input type="text" name="date" /></p>
<input type="submit" name="button" value="Добавить" /><br>
<input type="submit" name="show" value="Показать список" /><br>
<b>а)Список рейсов для заданного пункта назначения;</b>
<br>Задайте пункт: <input type="text" name="pla"><br>
<input type="submit" name="setpla" value = "Задать"><br>
<b>б)Список рейсов для заданного дня недели;</b>
<br>Задайте день <input type="text" name="race"><br>
<input type="submit" name="setRace" value = "Задать"><br>
<b>в)Список рейсов для заданного дня недели, время вылета для которых больше
заданного </b>
<br>Задайте время: <input type="text" name="tim"><br>
<br>Задайте день: <input type="text" name="dat"><br>
<input type="submit" name="setraces" value = "Задать"><br>
<?php
if(isset($_POST['place'],$_POST['name'], $_POST['type'],$_POST['time'], $_POST['date'], $_POST["pla"],$_POST["race"], $_POST["tim"], $_POST["dat"])){
$place = $_POST['place'];
$name = $_POST['name'];
$type = $_POST['type'];
$time = $_POST['time'];
$date = $_POST['date'];}
$fp = fopen("dateofplanes.txt", "a+");
$f = file("dateofplanes.txt");
class Aeroflot
{
private $place;
private $name;
private $type;
private $time;
private $date;
public function getplace()
{
echo $this->place;
}
public function getname()
{
echo $this->name;
}
public function gettype()
{
echo $this->type;
}
public function getdate()
{
echo $this->date;
}
public function gettime()
{
echo $this->time;
}
function setauthor($place)
{
$this->place = $place;
$this->getplace();
}
function setname($name)
{
$this->name = $name;
$this->getname();
}
function setmaker($type)
{
$this->type = $type;
$this->gettype();
}
function setdate($date)
{
$this->date = $date;
$this->getdate();
}
function setnumofpag($time)
{
$this->time = $time;
$this->gettime();
}
function show($i)
{
echo ($i . ") <b>Пукнт назначения:</b>" . $this->place . "<b> Номер рейса:</b>" . $this->name . ",<b> Время вылета: </b>" . $this->time . ",<b> День: </b>" . $this->date . " ,<b> Тип самолета: </b>" . $this->type . " <br>");
}
public function __construct($place, $name, $time, $date, $type)
{
$this->place = $place;
$this->name = $name;
$this->time = $time;
$this->date = $date;
$this->type = $type;
}
}
function WriteOnFile($fp, $place, $name, $time, $date, $type)
{
$p = " | ";
$write = fwrite($fp, $place . $p . $name . $p . $time . $p . $date . $p . $type . "\r\n");
}
//Показать список
if (isset($_POST['show'])) {
$i = 0;
echo "<b> Список </b> <br>";
foreach ($f as $StringToShow) //берем файл как строку
{
$mas = explode(" | ", $StringToShow);
$tables[] = new Aeroflot($mas[0], $mas[1], $mas[2], $mas[3], $mas[4]);
}
foreach ($tables as $Table) {
$i++;
$Table->show($i);
}
}
//Добавление
if (isset($_POST['button'])) {
WriteOnFile($fp, $place, $name, $time, $date, $type);
$f = file("dateofplanes.txt");
$i = 0;
echo "<b> Список </b> <br>";
foreach ($f as $str) {
$mas = explode(" | ", $str);
$tables[] = new Aeroflot($mas[0], $mas[1], $mas[2], $mas[3], $mas[4]);
}
foreach ($tables as $table) {
$i++;
$table->show($i);
}
}
if (isset($_POST['setpla'],$_POST["pla"])) {
$newPlace = $_POST["pla"];
$j = 0;
foreach ($f as $string) {
$mas = explode(" | ", $string);
if (mb_strtolower($mas[0], 'UTF-8') == mb_strtolower($newPlace, 'UTF-8')) {
$MassOfTables[] = new Aeroflot($mas[0], $mas[1], $mas[2], $mas[3], $mas[4]);
}
}
echo "<b> Список рейсов для заданного пункта: </b> </br>";
foreach ($MassOfTables as $Table) {
$j++;
$Table->show($j);
}
}
//$newRace = $_POST["race"];
if (isset($_POST['setRace'],$_POST["race"])) {
$newRace = $_POST["race"];
$j = 0;
foreach ($f as $string) {
$mas = explode(" | ", $string);
$a = (mb_strtolower($newRace, 'UTF-8'));
$b = (mb_strtolower($mas[3], 'UTF-8'));
if ($a == $b) {
$MassOfTables[] = new Aeroflot($mas[0], $mas[1], $mas[2], $mas[3], $mas[4]);
}
}
echo "<b> Список рейсов для заданного дня недели: </b> </br>";
foreach ($MassOfTables as $Table) {
$j++;
$Table->show($j);
}
}
if (isset($_POST['setraces'],$_POST["tim"],$_POST["dat"])) {
$newTime = $_POST["tim"];
$newDate = $_POST["dat"];
$j = 0;
foreach ($f as $string) {
$mas = explode(" | ", $string);
$timeforcheck_1 = explode(":", $mas[2]);
$timeforcheck_2 = explode(":", $newTime);
if ((mb_strtolower($newDate, 'UTF-8') == mb_strtolower($mas[3], 'UTF-8')) and ($timeforcheck_2[0] <= $timeforcheck_1[0])) {
if ($timeforcheck_2[1] <= $timeforcheck_1[1]) {
$MassOfTables[] = new Aeroflot($mas[0], $mas[1], $mas[2], $mas[3], $mas[4]);
}
}
}
echo "<b> Список рейсов для заданного дня недели и времени: </b> </br>";
foreach ($MassOfTables as $Table) {
$j++;
$Table->show($j);
}
}
?>
</form>
</body>
</html> |