-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
51 lines (43 loc) · 1.44 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
<?php
require_once "/lib/Profile.php";
require_once "/lib/PDO.php";
require_once "/lib/StudentsMapper.php";
$mapper = new StudentsMapper($DBH);
if (isset($_COOKIE['studentscookie']['code'])) {
$code = $_COOKIE['studentscookie']['code'];
$head = "Ваши данные:";
$student = $mapper->getStudentsbyCode($code);
$new = 0;
$message = "вы можете их изменить";
} else {
$head = "Зарегистрируйтесь";
$student = new Profile;
$new = 1;
$message = '';
}
if (isset($_POST['submit'])) {
$student->setFields($_POST);
if ($mapper->isemailUsed($_POST['email'], $code)) {
$error = "emailused";
$message = "Такой email уже зарегистрирован!";
} else {
$error = $student->checkFields();
}
if (!$error) {
if ($new) {
$student->generateCode();
while ($mapper->iscodeUsed($student->getCode())) {
$student->generateCode();
}
$mapper->addStudent($student);
$code = $student->getCode();
setcookie("studentscookie[code]", $code, time() + (7 * 24 * 60 * 60 * 42), "/");
header("Location: index.php");
die();
} else {
$mapper->editProfile($student);
$message = "Данные успешно изменены!";
}
}
}
include "templates/profile.html";