-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
165 lines (149 loc) · 4.95 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
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
<?php
session_start();
if (!$_SESSION["verified"]) {
header("Location: /login.php?continue=" . $_SERVER["SCRIPT_NAME"]);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Photos</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/assets/main.css">
</head>
<body>
<div id="container">
<!-- Body start -->
<div id="body">
<ul class="nav">
<li class="navli"><a class="active" href="/">Home</a></li>
<li class="navli"><a href="/search.php">Search</a></li>
<li class="rightNavBtn"><button id="folderBtn"><img src = "/assets/newFolder.png"></button></li>
<li class="rightNavBtn"><button id="uploadBtn"><img src = "/assets/upload.png"></button></li>
</ul>
<div class='grid'>
<?php
$servername = "localhost";
$username = "root";
include 'assets/hidden.php';
$password = $mySQLPassword;
$database = "images";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$location = "home";
$folderID = 0;
$folderName = "";
$locErr = "";
$nameErr = "";
// GET real location
$GETLocation = clean_input($_GET["location"]);
if ($GETLocation != "") {
$folderID = (int)$GETLocation;
}
$res = mysqli_query($conn, "SELECT * FROM folders WHERE parent = '". $folderID . "'");
while($row = mysqli_fetch_assoc($res)) {
$link = "/index.php?location=" . $row['id'];
echo " <div draggable='true' class='gridBoxFolder' id='folder" . $row['id'] . "' data-id='" . $row['id'] . "'>";
echo " <a class='gridBoxLink' href=" . $link . ">";
echo " <div class='folderOuter'>";
echo " <div class='cls-context-menu-folder' data-id='" . $row['id'] . "' data-largest='y'>";
echo " <img draggable='false' class='cls-context-menu-folder' data-id='" . $row['id'] . "' src='/assets/folder.svg'>";
echo " <p class='cls-context-menu-folder' data-id='" . $row['id'] . "'>" . $row['name']. "</p>";
echo " </div>";
echo " </div>";
echo " </a>";
echo " </div>";
}
$res = mysqli_query($conn, "SELECT * FROM photos WHERE parent = '". $folderID . "'");
while($row = mysqli_fetch_assoc($res)) {
$thisId = $row['id'];
$viewLink = "/images/" . $thisId . "." . $row['fileType'];
echo " <div draggable='true' class='gridBoxImage' data-id='" . $row['id'] . "'>";
echo " <a href=" . $viewLink . ">";
echo " <div style='background: url(images/thumb" . $row['id']. "." . $row['fileType'] . ") 50% 50% no-repeat;
background-size: cover;'
class='cls-context-menu-image' id='$thisId'>";
echo " </div>";
echo " </a>";
echo " </div>";
}
function clean_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!-- Grid end -->
</div>
<!-- Body end -->
</div>
<!-- Footer start -->
<div id="footer">
<br>
<p class="fieldExplanation"><?php echo (100 - intval(file_get_contents("percent.txt"))); ?>% storage remaining</p>
<!-- Footer end -->
</div>
<!-- Container end -->
</div>
<!-- LEFT CLICK MENUS-->
<div id="div-context-menu" class="cls-context-menu">
<ul>
<li><a href="theLink">View Info</a></li>
<li><a href="editTagsLink">Edit Tags</a></li>
<li><a href="deletePhotoLink">Delete Photo</a></li>
</ul>
</div>
<div id="div-context-menu-folder" class="cls-context-menu">
<ul>
<li><a href="editFolderNameLink">Rename</a></li>
<li><a href="theLink">Delete Folder</a></li>
</ul>
</div>
<!-- New Folder Modal -->
<div id="newFolderModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span id="closeFolder" class="close">×</span>
<h2>Create Folder</h2>
</div>
<form method="post" action="createFolder.php">
<div class="modal-body">
<input type="text" placeholder="Folder Name" pattern="^[a-zA-Z0-9_]*$" title="Letters, numbers, and underscores, max 32 characters." name="folderName" maxlength="32" required>
<input type="hidden" name="parent" value=<?php echo $folderID; ?>>
</div>
<div class="modal-footer">
<input type="submit" value="Create">
</div>
</form>
</div>
</div>
<!-- New Image Modal -->
<div id="newImageModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span id="closeUpload" class="close">×</span>
<h2>Upload Image</h2>
</div>
<form method="post" action="upload.php" enctype="multipart/form-data">
<div class="modal-body">
<input type="file" id="imageUploadInput" name="fileToUpload" required hidden>
<input type="text" placeholder="Tags" pattern="^[a-z0-9]+(,[a-z0-9]+){4,31}$" title="Lower case letters and numbers only. Separated by comma." name="tags" minlength="9" required>
<input type="hidden" name="parent" value=<?php echo $folderID; ?>>
</div>
<div class="modal-footer">
<input type="submit" value="Create">
</div>
</form>
</div>
</div>
<script src="index.js"></script>
</body>
</html>