-
Notifications
You must be signed in to change notification settings - Fork 0
/
pub.php
129 lines (106 loc) · 3.81 KB
/
pub.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
<?
require_once('utils/Autoload.php');
session_start();
if(empty($_SESSION) || !array_key_exists('Nome',$_SESSION) || !isset($_SESSION['Nome'])){
$_SESSION['error'] = array ('source' => 'contato.php','type' => 'No Permissions');
header('Location:formLogin');
die();
}else{
$myDbManager = new classes_DbManagerPDO();
$myUser = new classes_User($_SESSION,'SessionSet');
$typeUser = $myUser->getAdmin();
if(isset($_GET['id'])){
$id = $_GET['id'];
try{
$pub = new classes_PublicationManager($myDbManager);
$resultado = $pub->listOnePub($id);
}
catch(InvalidArgumentException $e){
echo '<div class="alert alert-danger" role="alert">'.$e->getMessage().'</div>';
}
}
if(!empty($_POST)){
try{
$myDbManager = new classes_DbManagerPDO();
$myValidator = new classes_ComentValidator();
$erros = null;
if(!is_array($errors = $myValidator->checkComent($_POST))){
$myComent = new classes_coment($myUser->getId(),$_POST['coment'],$_GET['id'],$_POST['avaliacao']);
$myComentManager = new classes_ComentManager($myDbManager);
$result = $myComentManager->insertComent($myComent, $_GET['id']);
}
}
catch(InvalidArgumentException $e){
echo '<div class="alert alert-danger" role="alert">'.$e->getMessage().'</div>';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?
include('head.php');
?>
<title>Publicação - Socialite</title>
<style>
img{
height:100px;
width:100px;
}
</style>
</head>
<body>
<?
include('navbar.php');
?>
<main>
<div class="container">
<?
echo "<img src= ".$resultado['imagem']." alt=".$resultado['descricao']."><br>".$resultado['descricao']."<br><br>";
if($typeUser == 'Admin'){
echo '<a class="btn btn-danger" href="deletePub?id='.$resultado['id_pub'].'" name="apagar">Apagar</a><br><br>';
}
?>
<form action="" method="POST">
<div class="form-group">
<label for="coment">Insira um comentário:</label>
<input type="text" class="form-control" name ="coment" id="coment">
</div>
<div class="form-group">
<label for="avaliacao">Dê uma avaliação:</label>
<select name="avaliacao" class="form-control" id="avaliacao">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</div>
</select><br>
<input type="submit" id="" class="btn btn-primary" value="Comente">
</form>
<br>
<br>
<?
try{
$myDbManager = new classes_DbManagerPDO();
$allComents = new classes_ComentManager($myDbManager);
$elesTodos = $allComents->getComents($_GET['id']);
}
catch(InvalidArgumentException $e){
echo '<div class="alert alert-danger" role="alert">'.$e->getMessage().'</div>';
}
for($i=count($elesTodos)-1;$i>=0;$i--){
$Nomes = $allComents->getNameComent($elesTodos[$i]['Id_util']);
echo $Nomes['Nome']. ' comentou: <br> ';
echo $elesTodos[$i]['Content'].'<br>';
echo $elesTodos[$i]['Avaliacao'].'/4 <br>';
}
?>
<a href="index" title="Ir para a página anterior">Voltar</a>
</div>
</main>
<?
include ("footer.php");
?>
</body>
</html>