-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle.php
91 lines (72 loc) · 3.16 KB
/
article.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
<?
include_once 'libraries.php';
if ( !empty($_POST['submit']) ) {
if ( !empty($_POST['comment']) ) $comment = $_POST['comment'];
if ( !empty($_GET['id']) ) $article_id = $_GET['id'];
if ( !empty($arrUser['id'])) $user_id = $arrUser['id'];
if ( empty($comment) ) $error['comment'] = true;
if ( empty($article_id) ) $error['article_id'] = true;
if ( empty($user_id) ) $error['user_id'] = true;
if ( empty($error) ) {
$query = "INSERT INTO `comments` (comment, user_id, article_id) VALUES ('$comment','$user_id','$article_id')";
$result = mysql_query($query, $dbConn);
header ( 'Location: article.php?id='.$article_id);
die;
}
}
$query = "SELECT articles.id, articles.title, articles.extract, articles.text, articles.updated_at, categories.value as category, users.username FROM `articles`
INNER JOIN `categories` ON categories.id = articles.category_id
INNER JOIN `users` ON users.id = articles.user_id
WHERE articles.id = " . $_GET['id'] . " LIMIT 1";
$result = mysql_query ($query, $dbConn);
$article = mysql_fetch_assoc ($result);
$arrComments = array();
$query = "SELECT comments.id, comments.comment, users.username
FROM `comments`
INNER JOIN `users` ON comments.user_id = users.id
WHERE comments.status = 'valid' AND comments.article_id = " . $_GET['id'] . "
ORDER BY comments.id DESC";
$result = mysql_query ($query, $dbConn);
while ( $row = mysql_fetch_assoc ($result)) {
array_push( $arrComments,$row );
}
include_once 'header.php';
?>
<h1>Article</h1>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $article['title']; ?></h3>
</div>
<div class="panel-body">
<span class="label label-primary">Published</span> by <b><?php echo $article['username']; ?></b> in <i><?php echo $article['category']; ?></i> <b><?php echo date_format(date_create($article['fModificacion']), 'd/m/y h:m'); ?></b>
<hr/>
<?php echo $article['text']; ?>
</div>
</div>
<h2>Comments</h2>
<?php foreach ($arrComments as $comment) { ?>
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $comment['username']; ?> said</h3>
</div>
<div class="panel-body">
<?php echo $comment['comment']; ?>
</div>
</div>
<?php } ?>
<div>
<?php if ( !empty( $arrUser ) ) { ?>
<form action="article.php?id=<?php echo $_GET['id']; ?>" method="post">
<div class="form-group">
<label for="user">Post a comment</label>
<textarea class="form-control" rows="3" cols="50" name="comment" id="comment"></textarea>
</div>
<div class="form-group">
<input name="submit" type="submit" value="Send" class="btn btn-primary" />
</div>
</form>
<?php } else { ?>
<p>Please sign up to leave a comment on this article. <a href="signup.php">Sign up</a> or <a href="login.php">Log in</a></p>
<?php } ?>
</div>
<?php include_once 'footer.php'; ?>