This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotes.php
87 lines (76 loc) · 2.12 KB
/
notes.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
<?php
include 'includes/header.php';
require 'includes/config.php';
?>
<body>
<?php
if($_SESSION['status'] == "admin" || $_SESSION['status'] == "user")
{
?>
<div class="container">
<?php
$page='notes';
include 'includes/navbar.php';
include 'includes/file-nav.php';
?>
<div class="sub-page-main">
<div class="display-menu">
<!-- Or delete just the button if no buttons on the page -->
</div>
<div class="main">
<?php
$userId = $_SESSION['id'];
$sqlGetUsersNote = "SELECT * FROM Users WHERE id='$userId'";
$resultsGetUsersNote = mysqli_query($conn, $sqlGetUsersNote);
$row = mysqli_fetch_assoc($resultsGetUsersNote);
?>
<div class="note">
<?php
echo "<form method='POST'>";
echo '<textarea rows="15" cols="50" name="note">';
echo $row['note'];
echo '</textarea>';
echo "<button name='update'>Update</button><br><br>";
echo "<button name='save'>Save note in directory</button>";
echo "<input name='fileName' value='note".date("Y-m-d")."' placeholder='Note file name'></input>";
echo "</form>";
?>
</div>
<?php
if(isset($_POST['update']))
{
$newNote = mysqli_real_escape_string($conn, $_POST['note']);
$updateNote = "UPDATE Users SET note='$newNote' WHERE id='$userId'";
if(mysqli_query($conn, $updateNote))
{
echo "Updated succesfully!<br>";
echo '<meta http-equiv="refresh" content="0;" />';
}
else
{
echo "ERROR."; //niekada neturetu buti
}
}
if(isset($_POST['save']))
{
$fileName = mysqli_real_escape_string($conn, $_POST['fileName']);
$myfile = fopen("./files/".$_SESSION['nick']."/".$fileName.".txt", "w");
$txt = mysqli_real_escape_string($conn, $_POST['note']);
fwrite($myfile, $txt);
fclose($myfile);
echo "File was created in your directory with the name ".$fileName.".txt !<br>";
}
?>
</div>
</div>
<?php
}
else
{
echo '<meta http-equiv="refresh" content="0; url=./errorAuthorization.shtml" />';
echo "You are not authorised to view this page!<br>";
}
?>
</div>
</body>
</html>