-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle.php
82 lines (63 loc) · 2.5 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
<?
include_once 'libraries.php';
include_once 'Controller.php';
$controller = new Controller();
if ( !empty($_POST['submit']) ) {
// Validation
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) ) {
$controller->postComment($comment,$user_id,$article_id);
header ( 'Location: article.php?id='.$article_id);
die;
}
}
$article = $controller->getArticle($_GET['id']);
$comments = $controller->getArticleComments($_GET['id']);
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 ($comments 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'; ?>