-
Notifications
You must be signed in to change notification settings - Fork 9
/
search.php
170 lines (143 loc) · 7.21 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
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
168
169
170
<?php
##########################################################################
# Copyright 2013, Philip Ewels ([email protected]) #
# #
# This file is part of Labrador. #
# #
# Labrador is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# Labrador is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with Labrador. If not, see <http://www.gnu.org/licenses/>. #
##########################################################################
include('includes/start.php');
include('includes/header.php');
function h ($string) {
global $regex_terms;
return preg_replace($regex_terms, '<span class="h">$0</span>', $string);
}
$search_raw = trim($_GET['s']);
preg_match_all('/"(?:\\\\.|[^\\\\"])*"|\S+/', $search_raw, $terms_raw);
$terms = $terms_raw[0];
if(count($terms) == 0){
header("Location: index.php");
}
// strip " marks from search entries
foreach($terms as $key => $term){
if(substr($terms[$key],0,1) == '"'){
$terms[$key] = substr($terms[$key],1);
}
if(substr($terms[$key],-1) == '"'){
$terms[$key]= substr($terms[$key],0,strlen($terms[$key])-1);
}
}
foreach($terms as $term){
$regex_terms[] = "/$term/i";
}
$project_fields = array('name', 'title', 'description', 'accession_geo', 'accession_sra', 'accession_ena', 'accession_ddjb', 'assigned_to', 'notes');
$sql = "SELECT * FROM `projects` WHERE ";
foreach ($project_fields as $field){
foreach ($terms as $term){
$sql .= "LOWER(`$field`) LIKE '%".strtolower($term)."%' OR ";
}
}
$sql = substr($sql, 0, strlen($sql) - 4);
$project_q = mysqli_query($dblink, $sql);
$num_project = mysqli_num_rows($project_q);
$publication_fields = array('year', 'journal', 'title', 'authors', 'pmid', 'doi');
$sql = "SELECT * FROM `papers` WHERE ";
foreach ($publication_fields as $field){
foreach ($terms as $term){
$sql .= "LOWER(`$field`) LIKE '%".strtolower($term)."%' OR ";
}
}
$sql = substr($sql, 0, strlen($sql) - 4);
$publications_q = mysqli_query($dblink, $sql);
$num_publications = mysqli_num_rows($publications_q);
$dataset_fields = array('name', 'species', 'cell_type', 'data_type', 'accession_geo', 'accession_sra', 'notes');
$sql = "SELECT * FROM `datasets` WHERE ";
foreach ($dataset_fields as $field){
foreach ($terms as $term){
$sql .= "LOWER(`$field`) LIKE '%".strtolower($term)."%' OR ";
}
}
$sql = substr($sql, 0, strlen($sql) - 4);
$dataset_q = mysqli_query($dblink, $sql);
$num_datasets = mysqli_num_rows($dataset_q);
?>
<a class="labrador_help_toggle pull-right" href="#labrador_help" title="Help"><i class="icon-question-sign"></i></a>
<h1>Search results for <span class="h"><?php echo implode('</span> <span class="h">', $terms); ?></span></h1>
<div class="labrador_help" style="display:none;">
<div class="well">
<h3>Searching</h3>
<p>The search looks for any project, publication or dataset containing any of your search keywords. You can search for a specific string using quotation marks, <em>eg.</em> <code>"example string"</code>.</p>
<p>You can read the full <a href="<?php echo $labrador_url; ?>/documentation/">Labrador documenation here</a>.</p>
</div>
</div>
<ul class="nav nav-tabs" id="myTab">
<li class="active"><a data-toggle="tab" href="#projects" <?php if($num_project == 0){ echo 'class="disabled"'; } ?>>Projects <span class="badge <?php if($num_project > 0){ echo 'badge-success'; } ?>"><?php echo $num_project; ?></span></a></li>
<li><a data-toggle="tab" href="#publications" <?php if($num_publications == 0){ echo 'class="disabled"'; } ?>>Publications <span class="badge <?php if($num_publications > 0){ echo 'badge-success'; } ?>"><?php echo $num_publications; ?></span></a></li>
<li><a data-toggle="tab" href="#datasets" <?php if($num_datasets == 0){ echo 'class="disabled"'; } ?>>Datasets <span class="badge <?php if($num_datasets > 0){ echo 'badge-success'; } ?>"><?php echo $num_datasets; ?></span></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="projects">
<?php if($num_project == 0){
echo '<p>No projects found.</p>';
} else {
while ($project = mysqli_fetch_array($project_q)){
echo '<h4><a href="project.php?id='.$project['id'].'">'.h($project['name']).'</a>   ';
if($project['accession_geo']) echo accession_badges ($project['accession_geo'], 'geo');
if($project['accession_sra']) echo accession_badges ($project['accession_sra'], 'sra');
if($project['accession_ena']) echo accession_badges ($project['accession_ena'], 'ena');
if($project['accession_ddjb']) echo accession_badges ($project['accession_ddjb'], 'ddjb');
echo '</h4>';
if($project['title']) echo '<p>'.h($project['title']).'</p>';
if($project['description']) echo '<p><small class="muted">'.h($project['description']).'</small></p>';
if($project['notes']) echo '<p><strong>Comments:</strong> <em>'.h($project['notes']).'</em></p>';
echo '<hr>';
}
} ?>
</div>
<div class="tab-pane" id="publications">
<?php if($num_publications == 0){
echo '<p>No publications found.</p>';
} else {
while ($pub = mysqli_fetch_array($publications_q)){
echo '<h4><a href="project.php?id='.$pub['project_id'].'">'.h($pub['title']).'</a></h4>';
echo '<p><strong>'.h($pub['journal']).'</strong> ('.h($pub['year']).')</p>';
echo '<p><small class="muted">'.h($pub['authors']).'</small></p>';
if($pub['pmid'] || $pub['doi']) echo '<p><small>';
if($pub['pmid']) echo 'PMID: <a href="http://www.ncbi.nlm.nih.gov/pubmed/'.$pub['pmid'].'" target="_blank">'.h($pub['pmid']).'</a> ';
if($pub['doi']) echo 'DOI <a href="http://dx.doi.org/'.$pub['doi'].'" target="_blank">'.h($pub['doi']).'</a>';
if($pub['pmid'] || $pub['doi']) echo '</small></p>';
echo '<hr>';
}
} ?>
</div>
<div class="tab-pane" id="datasets">
<?php if($num_datasets == 0){
echo '<p>No datasets found.</p>';
} else {
while ($ds = mysqli_fetch_array($dataset_q)){
echo '<h4><a href="datasets.php?id='.$ds['project_id'].'">'.h($ds['name']).'</a>   ';
if($project['accession_geo']) echo accession_badges ($project['accession_geo'], 'geo');
if($project['accession_sra']) echo accession_badges ($project['accession_sra'], 'sra');
echo '</h4>';
echo '<p>'.h($ds['species']).', '.h($ds['cell_type']).', '.h($ds['data_type']).'</p>';
if($ds['notes']) echo '<p><strong>Comments:</strong> <em>'.h($ds['notes']).'</em></p>';
echo '<hr>';
}
} ?>
</div>
</div>
<?php include('includes/javascript.php'); ?>
<script src="js/home.js" type="text/javascript"></script>
</body>
</html>