-
Notifications
You must be signed in to change notification settings - Fork 1
/
add.php
227 lines (213 loc) · 9.17 KB
/
add.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
226
227
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add Puzzle</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<link rel="icon" href="puz.png">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.bg-4 {
background-color: #2f2f2f; /* Black Gray */
color: #fff;
}
.b{
background-color: #e6e6e6; /* light grey */
color: #000000;
}
</style>
</head>
<body class="b">
<?php
require 'connect.inc.php';
require 'core.inc.php';
if(loggedin())
{
?>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">PuzzlePedia</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="index.php">Home</a></li>
<li><a href="puzzlemine.php">Puzzle Mine</a></li>
<li><a href="practise.php">Practise</a></li>
<li><a href="leaderboard.php">Leaderboard</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php if(!loggedin())
{
?>
<li><a data-toggle="modal" data-target="#login"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
<li><a data-toggle="modal" data-target="#register"><span class="glyphicon glyphicon-edit"></span> Register</a></li>
<?php
}
else
{
?>
<li class="active"><a href="add.php">Add Puzzle</a></li>
<li><a href="profile.php?id=<?php echo $_SESSION['id'];?>"><span class="glyphicon glyphicon-user"></span> My Profile</a></li>
<li style="padding:5px"><button class="btn btn-primary" type="button">Score <span class="badge">
<?php
$query="select * from userinfo where id = '".$_SESSION['id']."' ";
if( $query_run = mysqli_query($con,$query) )
{
$result = $con->query($query);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo $row['score'];?></span></button>
</li>
<li><a href="logout.php"><span class="glyphicon glyphicon-off"></span>Logout</a></li>
<?php
}
}
}
}
?>
</ul>
</div>
</div>
</nav>
<div class='container'>
<h2>Enter Puzzle Title & Details:</h2>
<br><br>
<div id="small_form">
<form action="add.php" method="post" role="form" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label col-sm-2" >Puzzle Title:</label>
<div class="col-sm-10">
<input class='form-control' type="text" name="title" required placeholder="Enter Puzzle Title"><br><br>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" >Description & Questions:</label>
<div class="col-sm-10">
<textarea name="dq" class='form-control' rows="8" placeholder="Enter Description and Question"></textarea> <br><br>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" >Image(if necessary):</label>
<div class="col-sm-10">
<input class='form-control' type="file" name="img" ><br><br>
</div>
</div>
<br>
<br>
<div class="form-group">
<label class="control-label col-sm-2" >Answer:</label>
<div class="col-sm-10">
<textarea name="answer" class='form-control' rows="8" placeholder="Enter answer"></textarea> <br><br>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Submit" class="btn btn-primary">
</div>
</div>
</form>
</div>
</div>
<div class=" bg-4">
<hr>
<div class="text-center center-block">
<h3>PuzzlePedia</h3>
<h5>Think, Solve, Compete</h5>
<h5>-Designed & Developed by <a href="https://in.linkedin.com/in/rahul-bagad-b7810bb0"><strong>Rahul Bagad</strong></a></h5>
<a href="https://www.facebook.com/PuzzlePedia-933560270109874"><i id="social-fb" class="fa fa-facebook-square fa-3x social"></i></a>
<a href=""><i id="social-tw" class="fa fa-github fa-3x social"></i></a>
<a href="https://plus.google.com/u/0/114174056107999198883"><i id="social-gp" class="fa fa-google-plus-square fa-3x social"></i></a>
<a href="mailto:[email protected]"><i id="social-em" class="fa fa-envelope-square fa-3x social"></i></a>
</div>
<center>
<script type="text/javascript" src="http://widget.supercounters.com/hit.js"></script><script type="text/javascript">sc_hit(1353537,2,5);</script>
</center>
</div>
<?php
if(loggedin())
{
if(isset($_POST['title'])&&isset($_POST['dq'])&&isset($_POST['answer']))
{
$title=$_POST['title'];$dq=$_POST['dq'];$email=$_SESSION['eid'];$name=$_SESSION['name'];
$answer=$_POST['answer'];
if(isset($_FILES['img']))
{
echo "i2";
$fname = $_FILES['img']['name'];
$ext = @strtolower( end ( explode( '.', $fname) ) );
$ftmp = $_FILES['img']['tmp_name'];
echo $fname;
}
if(!empty($title)&&!empty($dq)&&!empty($answer)&&!empty($email))
{
if(!empty($fname))
{
echo "i3";
$tim = time();
$iname = $tim.".".$ext;
$query1 = "INSERT INTO `puzzle`(`title`, `dq`, `answer`, `author`, `email`, `img`,`score`,`level`) VALUES ( ' $title ',' $dq ',' $answer ',' $name','$email','$iname',0,'-')";
$path="img/pimg/".$iname;
if(move_uploaded_file($ftmp,$path));
}
else
{
echo "i4";
$tim = time();
$defimg="ni.jpg";
$query1 = $query1 = "INSERT INTO `puzzle`(`title`, `dq`, `answer`, `author`, `email`, `img`,`score`,`level`) VALUES ( ' $title ',' $dq ',' $answer ','$name','$email','$defimg',0,'-')";
}
if( $query_run = mysqli_query($con,$query1) )
{
echo "i5";
if(!empty($ftname)&&!empty($isize)) move_uploaded_file($ftname,"/img/pimg/".$iname); else mysql_error();
?>
<script type="text/javascript">
alert("Puzzle successfully added..");
</script>
<?php
$to=$email;
$headers="From: itspuzzlepedia.com";
$body="Thank you for contributing to puzzle community." ;
$subject="Puzzle Added";
mail($to,$subject,$body,$headers);
header( "refresh:0.3; url=practise.php" );
}
else
{echo "i6";
?>
<script type="text/javascript">
alert("Sorry an error Ocurred . Try again later");
</script>
<?php
echo mysqli_error($con);
header( "refresh:0.3; url=index.php" );
}
}
}
}
}
else
{
?>
<script type="text/javascript">
alert("You need to login first");
</script>
<?php
echo mysqli_error($con);
header( "refresh:0.3; url=index.php" );
}
?>
</body>
</html>