-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
223 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
include_once "dbh.inc.php"; | ||
|
||
# Aggiungi goaway | ||
# vedi se c'è l'immagine, evenutalmente devi cancellarla | ||
# cancella dal database il post richesto | ||
|
||
$post = $_GET["idPost"]; | ||
|
||
$sql = "SELECT * FROM post WHERE id=?"; | ||
$stmt = mysqli_stmt_init($conn); | ||
mysqli_stmt_prepare($stmt, $sql); | ||
mysqli_stmt_bind_param($stmt, "i", $post); | ||
mysqli_stmt_execute($stmt); | ||
$result = mysqli_stmt_get_result($stmt); | ||
$image = mysqli_fetch_assoc($result); | ||
$dir = $image["post_dir"]; | ||
$author = $image["post_author"]; | ||
$fileName = $image["post_file_name"]; | ||
echo $fileName; | ||
|
||
if ($fileName == "") { | ||
# Cancel from database | ||
$sql = "DELETE FROM post WHERE id=?"; | ||
$stmt = mysqli_stmt_init($conn); | ||
mysqli_stmt_prepare($stmt, $sql); | ||
mysqli_stmt_bind_param($stmt, "i", $post); | ||
mysqli_stmt_execute($stmt); | ||
echo 'Cancellata solo dal database<br>'; | ||
header("Location: ../index.php?success=deletePost"); | ||
exit(); | ||
} else { | ||
$path = '../uploads/post/' . $dir . '/' . $author . '/' . $fileName; | ||
echo $path; | ||
if (!unlink($path)) { | ||
echo '>Error: file was not deleted.'; | ||
} else { | ||
# Cancel from database too | ||
$sql = "DELETE FROM post WHERE id=?"; | ||
$stmt = mysqli_stmt_init($conn); | ||
mysqli_stmt_prepare($stmt, $sql); | ||
mysqli_stmt_bind_param($stmt, "i", $post); | ||
mysqli_stmt_execute($stmt); | ||
mysqli_stmt_close($stmt); | ||
echo 'Cancellata sia dal database che dalla cartella<br>'; | ||
header("Location: ../index.php?success=deletePost"); | ||
exit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
include_once "dbh.inc.php"; | ||
|
||
$userId = $_SESSION["userId"]; | ||
|
||
$sql = "SELECT * FROM post ORDER BY post_date DESC"; | ||
$query = mysqli_query($conn, $sql); | ||
if (mysqli_num_rows($query) > 0) { | ||
while ($row = mysqli_fetch_assoc($query)) { | ||
echo '<div class="post"> | ||
<div class="header"> | ||
<div>' . $row["post_title"] . '</div> | ||
<div>' . $row["post_author"] . ' (' . $row["post_user_id"] . ')</div>'; | ||
if ($userId == $row["post_user_id"]) { | ||
echo '<div><button>Modify</button></div> | ||
<div><a href="includes/deletePost.inc.php?idPost=' . $row["id"] . '"><button>Cancel</button></a></div>'; | ||
} else { | ||
echo '<div></div> | ||
<div></div>'; | ||
} | ||
echo '</div>'; // close class header | ||
echo '<div class="content">'; | ||
if ($row["post_file_name"] == "") { | ||
} else { | ||
$imageAuthor = $row["post_author"]; | ||
$imageDir = $row["post_dir"]; | ||
$imageName = $row["post_file_name"]; | ||
$imagePath = "uploads/post/" . $imageDir . "/" . $imageAuthor . "/" . $imageName; | ||
echo '<img src="' . $imagePath . '" width="100px" height="100px">'; | ||
} | ||
echo $row["post_content"] . '<br><br>'; | ||
echo '<i>Posted on ' . $row["post_date"] . ' in /' . $row["post_dir"]; | ||
} // close if not set picture | ||
echo '</div>'; // close class content | ||
echo '</div>'; // close this post | ||
} // close while |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.