-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
218 lines (195 loc) · 9.61 KB
/
search.php
File metadata and controls
218 lines (195 loc) · 9.61 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- link rel="shortcut icon" href="../../assets/ico/favicon.ico"-->
<title>IWTL · For Free</title>
<!-- Bootstrap core CSS -->
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- Theme-->
<link href="//netdna.bootstrapcdn.com/bootswatch/3.1.1/superhero/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="jumbotron-narrow.css" rel="stylesheet">
<script>
function showHiddenAV() {
document.getElementById('hiddenResults').style.display = "block";
document.getElementById('hiddenLink').style.display = "none";
}
</script>
<script>
function showHiddenBooks() {
document.getElementById('hiddenResults2').style.display = "block";
document.getElementById('hiddenLink2').style.display = "none";
}
</script>
<!-- Just for debugging purposes. Don't actually copy this line! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="header">
<ul class="nav nav-pills pull-right">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="blog.html">Blog</a></li>
</ul>
<h3 class="text-muted">IWTL · For Free (Alpha)</h3>
</div>
<div class="row">
<div class="well bs-component">
<form class="form-horizontal" action="search.php" method="post">
<fieldset>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label">What do you want to learn?</label>
<div class="col-lg-10">
<textarea class="form-control" rows="1" id="textArea" name="tags"></textarea>
<span class="help-block">Enter keywords related to the subject</span>
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label">How do you want to learn?</label>
<div class="col-lg-10">
<div class="checkbox">
<label>
<input type="checkbox" name="video" id="optionsRadios1" value="video" checked="">
Audio and video lectures
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="book" id="optionsRadios1" value="book" checked="">
Books
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
<h1>Results</h1>
<div class="well bs-component">
<?php
try{
$pdo = new PDO('mysql:dbname=xxxx;host=localhost;charset=utf8', 'xxxx', 'xxxx');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pre_tags = explode(" ",$_POST["tags"]);
$tags = implode(" +",$pre_tags);
$include_books = $_POST["book"];
$include_videos = $_POST["video"];
if(!is_null($_POST["tags"])){
if(!is_null($include_videos)){
$count = 0;
echo "\n\n<h2>Audio/Video Resources</h2>\n";
$stmt = $pdo->prepare("SELECT * FROM RESOURCES WHERE MATCH(TAGS) AGAINST(:tags IN NATURAL LANGUAGE MODE) AND CONTENT_TYPE LIKE 1;");
$stmt->execute(array(':tags' => $tags));
$count+=$stmt->rowCount();
if($count < 5){
foreach ($stmt as $row)
{
echo "<h3>".$row['NAME']."</h3> \n";
echo "<a target=\"_blank\" href = \"".$row['URL']."\">"."Check it out"."</a>";
}
}
else
{
$index = 0;
foreach($stmt as $row){
if($index < 5){
echo "<h3>".$row['NAME']."</h3> \n";
echo "<a target=\"_blank\" href = \"".$row['URL']."\">"."Check it out"."</a>";
}
if($index == 5){
echo "<div id=\"hiddenResults\" style=\"display:none;\">\n";
echo "<h3>".$row['NAME']."</h3> \n";
echo "<a target=\"_blank\" href = \"".$row['URL']."\">"."Check it out"."</a>";
}
if($index > 5){
echo "<h3>".$row['NAME']."</h3> \n";
echo "<a target=\"_blank\" href = \"".$row['URL']."\">"."Check it out"."</a>";
}
++$index;
}
echo "</div>";
echo "<br><br><a id=\"hiddenLink\" style=\"display:block;\" href=\"javascript:void(0)\" onclick=\"showHiddenAV();\">"."<h4>Didn't find what you wanted? Click to show all matching results!</h4>"."</a>\n\n";
}
if($count ==0){
echo "\nOh no! We didn't find any audio or video resources matching your search query! T_T\n";
}
}
echo "</div>";
echo "<br><br><div class=\"well bs-component\">";
if(!is_null($include_books)){
$count = 0;
echo "\n\n<h2>Books</h2>\n";
$stmt = $pdo->prepare("SELECT * FROM RESOURCES WHERE MATCH(TAGS) AGAINST(:tags IN NATURAL LANGUAGE MODE) AND CONTENT_TYPE LIKE 2;");
$stmt->execute(array(':tags' => "%".$tags."%"));
$count +=$stmt->rowCount();
if($count < 5){
foreach ($stmt as $row)
{
echo "<h3>".$row['NAME']."</h3> \n";
echo "<a target=\"_blank\" href = \"".$row['URL']."\">"."Check it out"."</a>";
}
}
else
{
$index = 0;
foreach($stmt as $row){
if($index < 5){
echo "<h3>".$row['NAME']."</h3> \n";
echo "<a target=\"_blank\" href = \"".$row['URL']."\">"."Check it out"."</a>";
}
if($index == 5){
echo "<div id=\"hiddenResults2\" style=\"display:none;\">\n";
echo "<h3>".$row['NAME']."</h3> \n";
echo "<a target=\"_blank\" href = \"".$row['URL']."\">"."Check it out"."</a>";
}
if($index > 5){
echo "<h3>".$row['NAME']."</h3> \n";
echo "<a target=\"_blank\" href = \"".$row['URL']."\">"."Check it out"."</a>";
}
++$index;
}
echo "</div>";
echo "<br><br><a id=\"hiddenLink2\" style=\"display:block;\" href=\"javascript:void(0)\" onclick=\"showHiddenBooks();\">"."<h4>Didn't find what you wanted? Click to show all matching results!</h4>"."</a>\n\n";
}
if($count ==0){
echo "\nOh no! We didn't find any book resources matching your search query! T_T\n";
}
}
}
else
{
echo "Try searching with at least one keyword.";
}
}
catch(PDOException $e){
echo "<p>There was an error! Please try your search again.<p>";
}
?>
</div>
</div>
<div class="footer">
<p>© IWTL · For Free 2014</p>
</div>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
</body>
</html>