-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.php
More file actions
executable file
·167 lines (132 loc) · 4.35 KB
/
Copy pathdatabase.php
File metadata and controls
executable file
·167 lines (132 loc) · 4.35 KB
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
<?php
include('inc/common.inc.php');
echo '<div id="database">';
$img = array();
if (isset($_POST["send"])) {
// assign form values to an array
for ($i = 0; $i <= ($_POST["ysize"] - 1); $i++) {
for ($j = 1; $j <= $_POST["xsize"]; $j++) {
$value = ($i * $_POST["xsize"]) + $j;
// if $_POST[$value] exists it is clicked --> value = 1
if (isset($_POST[$value])) $img[$value] = 1;
}
}
// serialize for saving
$array_save = serialize($img);
global $db;
$sql_insert = "INSERT INTO radiartworks (id, user, title, array, x, y, time, up, down) VALUES " .
"(NULL, :user, :title, :array, :x, :y, datetime('now'), 0, 0);";
//test if entry already exists
$check = $db->prepare("SELECT id FROM radiartworks WHERE user = :user AND title = :title AND array = :array;");
$check->execute([
':user' => $_POST['user'],
':title' => $_POST['title'],
':array' => $array_save,
]);
$num = count($check->fetchAll(PDO::FETCH_ASSOC));
if ($num > 0)
echo '<p style="color: red;">Your radiartwork already exists!</p>';
else {
$insert = $db->prepare($sql_insert);
$insert->execute([
':user' => $_POST['user'],
':title' => $_POST['title'],
':array' => $array_save,
':x' => $_POST['xsize'],
':y' => $_POST['ysize'],
]);
$num = $insert->rowCount(); // check if saving was successful
if ($num > 0) {
echo "<p><font color='#00aa00'>";
echo "Your radiartwork was saved in our Database!";
echo "</font></p>";
}
else {
echo "<p><font color='#ff0000'>";
echo "An error occured. Please try again later!";
echo "</font></p>";
}
}
}
$sql = ("SELECT id FROM radiartworks");
$number = db_num_rows(db_query($sql));
$maximum_entrys = 20;
$sites = $number / $maximum_entrys; // calculate number of pages
if (!isset($_GET['sort'])) {
$identifier = "rand";
$sort = "RANDOM()";
} else { // sorting options
if ($_GET['sort'] == "up") {
$identifier = "up";
$sort = "up DESC, down DESC";
}
if ($_GET['sort'] == "x") {
$identifier = "x";
$sort = "x DESC, y DESC";
}
if ($_GET['sort'] == "time") {
$identifier = "time";
$sort = "time DESC";
}
}
// normal query when no page is given.
if (!isset($_GET['page'])) {
$sql = "SELECT id, user, title, array, x, y, ".
"strftime(' %d.%m.%Y at %H.%M h', time) as time, up, down ".
"FROM radiartworks ORDER BY " . $sort .
" LIMIT 0," . $maximum_entrys . ";";
} else {
// query when a page number is given.
$page = intval($_GET['page']);
$datas = ($page * $maximum_entrys) - $maximum_entrys;
$sql = "SELECT * FROM radiartworks ORDER BY " . $sort . " LIMIT " .
$datas . "," . $maximum_entrys * $page . ";";
}
// sorting functions
echo '<a class="sort" href="display.php?id_img=' . $random['id'] .
'">Random radiartwork</a>
<b> | </b>
<a class="sort" href="database.php?sort=x">Sort by Size</a>
<a class="sort" href="database.php?sort=time">Sort by Date</a>
<a class="sort" href="database.php?sort=up">Sort by Rating</a>';
// output table
echo "<table>";
echo "<tr>
<th>Number</th>
<th>Artist</th>
<th>Title</th>
<th>Size</th>
<th>Date of Publication</th>
<th>Rating</th>
</tr>";
$res = db_query($sql);
while ($data = db_fetch_assoc($res)) {
$width_up = 0.3 * $data["up"];
$width_down = 0.3 * $data["down"];
echo '
<tr>
<td>' . $data["id"] . '</td>
<td>' . escape($data["user"]) . '</td>
<td><a href="display.php?id_img=' . $data["id"] . '">' .
escape($data["title"]) . '</a></td>
<td>' . $data["x"] . ' x ' . $data["y"] . '</td>
<td>' . $data["time"] . '</td>
<td>
<div class="up" style="width: ' . $width_up . 'px"></div>
<span style="color:green">' . $data["up"] . '</span><br />
<div class="down" style="width: ' . $width_down . 'px"></div>
<span style="color:red">' . $data["down"] . '</span>
</td>
</tr>';
}
echo '</table>';
// output link list
for ($i = 2; $i - 1 < $sites; $i++) {
echo '<a class="num" href="database.php?page=' . $i . '&sort=' .
$identifier . '">' . $i . '</a>';
}
echo '</div>';
echo $footer;
?>
</body>
</html>