/
data.php
94 lines (67 loc) · 2.15 KB
/
data.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
<?php
require_once("functions.php");
require_once("InterestsManager.class.php");
//data.php
// siia pääseb ligi sisseloginud kasutaja
//kui kasutaja ei ole sisseloginud,
//siis suuunan data.php lehele
// muutujad väärtuste jaoks
$id = "";
$interest = "";
$name = "";
$add_name = "";
if(!isset($_SESSION["logged_in_user_id"])){
header("Location: login.php");
//see katkestab faili edasise lugemise
exit();
}
//kasutaja tahab välja logida
if(isset($_GET["logout"])){
//aadressireal on olemas muutuja logout
//kustutame kõik session muutujad ja peatame sessiooni
session_destroy();
header("Location: login.php");
}
//uus instants klassist
$InterestsManager = new InterestsManager($mysqli, $_SESSION["logged_in_user_id"]);
//aadressirealt muutuja
if(isset($_GET["new_interest"])){
$add_new_response = $InterestsManager->addInterest($_GET["new_interest"]);
}
//rippmenüü valiku kõrval vajutati nuppu
if(isset($_GET["new_dd_selection"])){
$add_new_userinterest_response = $InterestsManager->addUserInterest($_GET["new_dd_selection"]);
}
?>
<p>
Tere, <?=$_SESSION["logged_in_user_email"];?>
<a href="?logout=1"> Logi välja <a>
</p>
<h2>Lisa huviala</h2>
<?php if(isset($add_new_response->error)): ?>
<p style="color:red;">
<?=$add_new_response->error->message;?>
</p>
<?php elseif(isset($add_new_response->success)): ?>
<p style="color:green;" >
<?=$add_new_response->success->message;?>
</p>
<?php endif; ?>
<form>
<input name="new_interest" placeholder="Huviala"><input type="submit" name="login" value="Lisa">
</form>
<h2>Minu huvialad</h2>
<form>
<!--Siia järele tuleb rippmenüü -->
<?=$InterestsManager->createDropdown();?>
<input type="submit">
<?php if(isset($add_new_userinterest_response->error)): ?>
<p style="color:red;">
<?=$add_new_userinterest_response->error->message;?>
</p>
<?php elseif(isset($add_new_userinterest_response->success)): ?>
<p style="color:green;" >
<?=$add_new_userinterest_response->success->message;?>
</p>
<?php endif; ?>
</form>