-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_service.php
125 lines (104 loc) · 3.96 KB
/
file_service.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
<?php
require_once('appvars.php');
require_once('connectvars.php');
//get the q parameter from URL
$q = $_GET["q"];
function listArticles($dbc, $q) {
if (!strncmp($q, BIBLIO, strlen(BIBLIO))) {
$q = substr($q, strlen(BIBLIO));
}
$query = "SELECT * FROM resource where id = '$q' or title like '%$q%' or subject like '%$q%' ORDER BY title ASC LIMIT 0,10";
$data = mysqli_query($dbc, $query);
$hint = "";
while ($row = mysqli_fetch_array($data)) {
//echo $row['id'];
$paper = '[' . $row['id'] . ']' . $row['creator'] . '.' . $row['title'] . '.';
$text = '<label onClick="javascript:fileSelected(\'' . BIBLIO . $row ['id'] . '\');">' . $paper . '</label>';
if ($hint == "") {
/*
$hint = "<a href='" . type="button"
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" . style="width:200; height:20;"
$y->item(0)->childNodes->item(0)->nodeValue . "</a>"; */
//$hint = '<input class="btn btn-link" type="button" value="' . $paper . '" onClick="javascript:fileSelected(\'' . $row['id'] . '\');" />';
//$hint = '<label onClick="javascript:fileSelected(\'' . $row['id'] . '\');">'. $paper .'</label>';
$hint = $text;
} else {
/* $hint = $hint . "<br /><a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>"; */
//$hint = $hint . '<br /><input class="btn btn-link" type="button" value="' . $paper . '" onClick="javascript:fileSelected(\'' . $row['id'] . '\');" />';
$hint = $hint . $text;
}
}
return $hint;
}
function listConcepts($dbc, $q) {
$query = "SELECT * FROM def where name like '%$q%' ORDER BY name ASC LIMIT 0,10";
$data = mysqli_query($dbc, $query);
$hint = "";
while ($row = mysqli_fetch_array($data)) {
$paper = $row['name'] . '.' . $row['def'] ;
$text = '<label onClick="javascript:fileSelected(\'' . $row['name'] . '\');">' . $paper . '</label><br/>';
if ($hint == "") {
$hint = $text;
} else {
$hint = $hint . $text;
}
}
return $hint;
}
function listImages($dbc, $q) {
if (!strncmp($q, FIGURE, strlen(FIGURE))) {
$q = substr($q, strlen(FIGURE));
}
$query = "SELECT * FROM images where id like '%$q%' or name like '%$q%' or subject like '%$q%' or description like '%$q%' ORDER BY id ASC LIMIT 0,10";
$data = mysqli_query($dbc, $query);
$hint = "";
while ($row = mysqli_fetch_array($data)) {
//$link = '['. FIGURE . $row['id'] . ']' . $row['name'];
//$link = '['. FIGURE . $row['id'] . ']' . $row['name'];
$paper = '[' . FIGURE . $row['id'] . ']' . $row['name'] . '.' . $row['description'];
$text = '<label onClick="javascript:fileSelected(\'' . FIGURE . $row['id'] . '\');">' . $paper . '</label><br/>';
if ($hint == "") {
$hint = $text;
} else {
$hint = $hint . $text;
}
}
return $hint;
}
//lookup all links from the xml file if length of q>0
if (strlen($q) > 0) {
$hint = "";
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$text = listArticles($dbc, $q);
if ($hint == "") {
$hint = $text;
} else {
$hint = $hint . $text;
}
$text = listImages($dbc, $q);
if ($hint == "") {
$hint = $text;
} else {
$hint = $hint . $text;
}
$text = listConcepts($dbc, $q);
if ($hint == "") {
$hint = $text;
} else {
$hint = $hint . $text;
}
}
// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "") {
$response = "无相关资源";
} else {
$response = $hint;
}
//output the response
echo $response;
?>