Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //include config
- require_once('../includes/config.php');
- //if not logged in redirect to login page
- if(!$user->is_logged_in()){ header('Location: login.php'); }
- //show message from add / edit page
- if(isset($_GET['delpost'])){
- $stmt = $db->prepare('DELETE FROM blog_posts_seo WHERE postID = :postID') ;
- $stmt->execute(array(':postID' => $_GET['delpost']));
- //delete post categories.
- $stmt = $db->prepare('DELETE FROM blog_post_cats WHERE postID = :postID');
- $stmt->execute(array(':postID' => $_GET['delpost']));
- header('Location: index.php?action=eliminado');
- exit;
- }
- ?>
- <head>
- <script language="JavaScript" type="text/javascript">
- function delpost(id, title)
- {
- if (confirm("¿Realmente desea eliminar el artículo '" + title + "'?"))
- {
- window.location.href = 'index.php?delpost=' + id;
- }
- }
- </script>
- </head>
- <body>
- <?php include('menu.php');?>
- <?php
- //show message from add / edit page
- if(isset($_GET['action'])){
- echo '<div class="container"><h3>Articulo '.$_GET['action'].'.</h3></div>';
- }
- ?>
- <div class="container">
- <div class="col-md-12 text-right" style="margin: 15px 0 15px 0">
- <button class="btn btn-lg btn-primary" ><a href='add-post.php'>Agregar Articulo</a></button>
- </div>
- <table class="table">
- <tr>
- <th>Titulo</th>
- <th>Fecha</th>
- <th>Acción</th>
- </tr>
- <?php
- try {
- $stmt = $db->query('SELECT postID, postTitle, postDate FROM blog_posts_seo ORDER BY postID DESC');
- while($row = $stmt->fetch()){
- echo '<tr>';
- echo '<td>'.$row['postTitle'].'</td>';
- echo '<td>'.date('jS M Y', strtotime($row['postDate'])).'</td>';
- ?>
- <td>
- <a href="edit-post.php?id=<?php echo $row['postID'];?>">Editar</a> |
- <a href="javascript:delpost('<?php echo $row['postID'];?>','<?php echo $row['postTitle'];?>')">Eliminar</a>
- </td>
- <?php
- echo '</tr>';
- }
- } catch(PDOException $e) {
- echo $e->getMessage();
- }
- ?>
- </table>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement