-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.php
225 lines (214 loc) · 11.2 KB
/
index.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
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
217
218
219
220
221
222
223
224
225
<?php
session_start();
include('connect.php');
if(isset($_POST["ansubmit"])){
function valid($data){
$data = trim(stripslashes(htmlspecialchars($data)));
return $data;
}
$answer = valid($_POST["answer"]);
if($answer == NULL){
echo "<script>window.alert('Please Enter something.');</script>";
}
else{
$que = "";
if($_POST["nul"]==0){
if(strpos($_POST["preby"],$_SESSION["user"]) === false)
$que = "update quans set answer=CONCAT(answer,'<br>or<br>".$_POST["answer"]."'), answeredby=CONCAT(answeredby,', @ ".$_SESSION["user"]."') where question like '%".$_POST["question"]."%'";
else
$que = "update quans set answer=CONCAT(answer,'<br>or<br>".$_POST["answer"]."'), answeredby = '".$_SESSION["user"]."' where question like '%".$_POST["question"]."%'";
}
else
$que = "update quans set answer='".$_POST["answer"]."', answeredby = '".$_SESSION["user"]."' where question like '%".$_POST["question"]."%'";
if(mysqli_query($conn,$que)){
echo "<style>#searchbox{display: none;} #tb{display: block;}</style>";
}
else
echo mysqli_error($conn);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Interrogate </title>
<link type="text/css" rel="stylesheet" href="css/style.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="css/material.css">
<link type="text/css" rel="stylesheet" href="fonts/font.css">
<link rel="icon" href="images/icon1.png" >
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<style>
textarea{
display: none;
width: 300px;
height: 50px;
background: #333;
color: #ddd;
padding: 10px;
margin: 5px 0 -14px;
}
.ans_sub{
display: none;
padding: 0 10px;
height: 30px;
line-height: 30px;
}
.pop{
display: none;
text-align: center;
margin: 151.5px auto;
font-size: 12px;
}
</style>
</head>
<body id="_1">
<!-- navigation bar -->
<a href="index.php">
<div id="log">
<div id="i">i</div><div id="cir">i</div><div id="ntro">nterrogate</div>
</div>
</a>
<ul id="nav-bar">
<a href="index.php"><li id="home">Home</li></a>
<a href="categories.php"><li>Categories</li></a>
<a href="contacts.php"><li>Contact</li></a>
<a href="ask.php"><li>Ask Question</li></a>
<?php
if(! isset($_SESSION['user'])){
?>
<a href="login.php"><li>Log In</li></a>
<a href="signup.php"><li>Sign Up</li></a>
<?php
}
else{
?>
<a href="profile.php"><li>Hi, <?php echo $_SESSION["user"]; ?></li></a>
<a href="logout.php"><li>Log Out</li></a>
<?php
}
?>
</ul>
<!-- content -->
<div id="content">
<div id="searchbox">
<center>
<div class="heading">
<h1 class="logo"><div id="i">i</div><div id="cir">i</div><div id="ntro">nterrogate</div></h1>
<p id="tag-line">where questions are themselves the answers</p>
</div>
<form action="<?php echo htmlspecialchars( $_SERVER["PHP_SELF"] ); ?>" method="post" enctype="multipart/form-data" >
<input name="text" id="search" type="text" title="Question your Answers" placeholder="Looking for Answers to Some Question, simply just search here... ">
<i class="material-icons" id="sign">search</i>
<input name="submit" type="submit" value="Search" class="up-in" id="qsearch">
</form>
</center>
</div>
<div class="pop" id="ta">
<h1><b style="font-size: 1.5em; margin: -60px auto 10px; display: block;">:(</b>Sorry, Your search didn't match any documents.</h1>
</div>
<div class="pop" id="tb">
<center><h1><b style="font-size: 1.5em; margin: -60px auto 10px; display: block;">:)</b>Thank You For Your Answer.</h1></center>
</div>
<?php
if(isset($_POST["submit"])) {
function valid($data){
$data = trim(stripslashes(htmlspecialchars($data)));
return $data;
}
function check($data){
$data = strtolower($data);
if( $data != "what" && $data != "how" && $data != "who" && $data != "whom" && $data != "when" && $data != "why" && $data != "which" && $data != "where" && $data != "whose" && $data != "is" && $data != "am" && $data != "are" && $data != "do" && $data != "don't" && $data != "does" && $data != "did" && $data != "done" && $data != "was" && $data != "were" && $data != "has" && $data != "have" && $data != "will" && $data != "shall" && $data != "the" && $data != "i" && $data != "a" && $data != "an" && $data != "we" && $data != "he" && $data != "she" && $data != "")
return 1;
return 0;
}
$text = valid($_POST["text"]);
if($text == NULL){
echo "<script>window.alert('Please Enter something to search.');</script>";
}
else{
$text = preg_replace("/[^A-Za-z0-9]/"," ",$text);
$words = explode(" ",$text);
$format = "select * from quans where question like '%";
$query = "";
foreach($words as $word){
if(check($word)){
if($query == "")
$query = $format.$word."%'";
else
$query .= " union ".$format.$word."%'";
}
}
if(!$query){
echo "<script>window.alert('Search appropriate question.');</script>";
}
else{
$r = mysqli_query($conn, $query);
if(mysqli_error($conn))
echo "<script>window.alert('Some Error Occured. Try Again or Contact Us.');</script>";
else if(mysqli_num_rows($r)>0) {
?>
<style>.open{display: block;} </style>
<center>
<div class='open' style='height: auto; margin: 60px auto -135px;'>
<div id='topic'>
<h2 id='topic-head' style="font-weight: normal; border:none; font-size: 22px;">Your Search Results for '<?php echo $text; ?>' are :</h2>
</div>
<?php $n = 1; $nul=0; while( $row = mysqli_fetch_assoc($r) ) { ?>
<div id="qa-block">
<div class="question">
<div id="Q">Q.</div><?php echo $row["question"]."<small id='sml'>Asked By: @".$row['askedby']."</small>"; ?>
</div>
<div class="answer">
<?php
if($row["answer"]){
$nul=0;
echo $row["answer"]."<br><small>Answered By: @".$row['answeredby']."</small>";
}
else{
$nul=1;
echo "<em>*** Not Answered Yet ***</em>";
}
?>
<form id="f<?php echo $n; ?>" style="margin-bottom: -25px;" action="<?php echo htmlspecialchars( $_SERVER["PHP_SELF"] ); ?>" method="post" enctype="multipart/form-data">
<!-- <input type="button" value="Click here to answer." id="ans_b" >-->
<label style="margin-bottom: -25px;"><a id="ans_b<?php echo $n; ?>" href="#area<?php echo $no; ?>"><u>Submit your answer</u></a></label>
<br>
<script>
$(function(){
$('#ans_b<?php echo $n; ?>').click(function(e){
e.preventDefault();
$('#area<?php echo $n; ?>').css("display","block");
$('#ar<?php echo $n; ?>').css("display","block");
$('#f<?php echo $n; ?>').css("margin-bottom","0px");
});
});
</script>
<textarea id="area<?php echo $n; ?>" name="answer" placeholder="Your Answer..."></textarea>
<input style="display: none;" name="question" value="<?php echo $row['question'] ?>">
<input style="display: none;" name="nul" value="<?php echo $nul ?>">
<input style="display: none;" name="preby" value="<?php echo $row['answeredby'] ?>">
<br>
<input type="submit" name="ansubmit" value="Submit" class="up-in ans_sub" id="ar<?php echo $n; ?>">
</form>
</div>
</div>
<?php $n++; } ?>
</div>
</center>
<?php
} // if for no. of rows
else{
echo "<style>#searchbox{display: none;} #ta{display: block;}</style>";
}
}
} // a non null if
} // isset for submit
?>
</div>
<!-- Footer -->
<div id="footer">
© 2017 • Interrogate Inc.
</div>
</body>
</html>