-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
114 lines (93 loc) · 3.62 KB
/
search.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
<?php
ob_start(); session_start();
require_once('connectvars.php');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (isset($_GET['q']) && $_GET['q']!='' && $_GET['q']!=' ')
{
$term = mysqli_real_escape_string($dbc, strip_tags($_GET['q']));
/* now the entire codes throughout will search for the files according to parameter provided and then will display it to th user */
/* it is also taken care that only the files that have shared with you are displayed and that no ither sharing that happened between different users is displayed */
//Search user table
$query = "SELECT * FROM users WHERE nickname LIKE '%$term%' OR email LIKE '%$term%' OR naam LIKE '%$term%'";
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data)!=0)
{
while ($row=mysqli_fetch_array($data))
{
echo '<a href="shareview.php?id='.$row['id'] . '"><span id="resultitem">(User) ' . $row['naam'] . '</span></a>';
}
}
$myid = $_SESSION['userid'];
//Search File table
$query = "SELECT * FROM files WHERE filename LIKE '%$term%' AND shareid = '$myid'";
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data)!=0)
{
while ($row=mysqli_fetch_array($data))
{
echo '<span ';
if ($row['filetype']=='audio')
{
echo 'id="./server/php/files/' . $row['directory'] . '/' . $row['filename'] . '" class="audplay"';
}
else if ($row['filetype']=='video')
{
echo 'id="./server/php/files/' . $row['directory'] . '/' . $row['filename'] . '" class="vidplay"';
}
else if ($row['filetype']=='image')
{
echo 'id="resultitem"><img src="./server/php/files/' . $row['directory'] . '/thumbnail/' . $row['filename'] . '" height="50px" /';
}
else {
echo 'id="resultitem"';
}
echo '>(' . $row['filetype'] . ') ' . $row['filename'] . '</a><a href="./server/php/files/' . $row['directory'] . '/' . $row['filename'] . '"><button class="dwn"></button></a></span>';
}
}
$query = "SELECT * FROM sharedfiles WHERE shareid = '$myid' ORDER BY id DESC";
$data = mysqli_query($dbc, $query);
while ($row2=mysqli_fetch_array($data)) {
$fileid=$row2['fileid'];
$query2 = "SELECT * FROM files WHERE filename LIKE '%$term%' AND id = '$fileid'";
$data2 = mysqli_query($dbc, $query2);
while ($row=mysqli_fetch_array($data2)) {
echo '<span ';
if ($row['filetype']=='audio')
{
echo 'id="./server/php/files/' . $row['directory'] . '/' . $row['filename'] . '" class="audplay"';
}
else if ($row['filetype']=='video')
{
echo 'id="./server/php/files/' . $row['directory'] . '/' . $row['filename'] . '" class="vidplay"';
}
else if ($row['filetype']=='image')
{
echo 'id="resultitem"><img src="./server/php/files/' . $row['directory'] . '/thumbnail/' . $row['filename'] . '" height="50px" /';
}
else {
echo 'id="resultitem"';
}
echo '>(' . $row['filetype'] . ') ' . $row['filename'] . '</a><a href="./server/php/files/' . $row['directory'] . '/' . $row['filename'] . '"><button class="dwn"></button></a></span>';
}
}
/* search implementation using phototags */
//Search PhotoTags
$query = "SELECT * FROM tags WHERE tags LIKE '%$term%' AND userid='$myid'";
$data2 = mysqli_query($dbc, $query);
if (mysqli_num_rows($data2)!=0)
{
while ($row2=mysqli_fetch_array($data2))
{
$photoid = $row2['photoid'];
$q2 = "SELECT * FROM FILES WHERE id='$photoid' AND shareid='$myid'";
$data = mysqli_query($dbc, $q2);
while ($row=mysqli_fetch_array($data))
{
echo '<span ';
echo 'id="resultitem"><img src="./server/php/files/' . $row['directory'] . '/thumbnail/' . $row['filename'] . '" /';
echo '>(' . $row['filetype'] . ') ' . $row['filename'] . '</a><a href="./server/php/files/' . $row['directory'] . '/' . $row['filename'] . '"><button class="dwn"></button></a></span>';
}
}
}
}
?>