Advertisement
Guest User

f

a guest
Nov 30th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.53 KB | None | 0 0
  1. <?php
  2. include('inc/config.php');
  3. include('inc/functions.php');
  4. if(!isset($_SESSION['id'])) header('Location: index.php');
  5. ?>
  6. <!DOCTYPE html>
  7. <html lang="en">
  8.  
  9.     <head>
  10.         <?php include('inc/head.php'); ?>
  11.     </head>
  12.     <body>
  13.         <?php include('inc/navbar.php'); ?>
  14.             <div id="page-wrapper">
  15.                 <div class="container-fluid">
  16.                     <div class="row">
  17.                         <div class="col-lg-12">
  18.                             <h1 class="page-header">
  19.                                 Dashboard
  20.                             </h1>
  21.                             <ol class="breadcrumb">
  22.                                 <li class="active">
  23.                                     <i class="fa fa-dashboard"></i> Dashboard
  24.                                 </li>
  25.                             </ol>
  26.                         </div>
  27.                     </div>
  28.                     <center>
  29.             <?php
  30.                 if(isset($_POST['sendnews'])){
  31.                     $textnews = dbin($_POST['textnews']);
  32.                     $titlenews = dbin($_POST['titlenews']);
  33.                    
  34.                     $errorsnews = array();
  35.                    
  36.                     if(strlen($titlenews) < 1){
  37.                         $errorsnews[1] = 'Insert a title!';
  38.                     }          
  39.                     if(strlen($textnews) < 1){
  40.                         $errorsnews[1] = 'Enter any text for the news!';
  41.                     }      
  42.                    
  43.                     if(count($errorsnews) == 0){
  44.                         $username = dbin($_SESSION['realname']);
  45.                         mysqli_query($conn, "INSERT INTO $dbsite.news(id, title, text, author) VALUES(NULL, '$titlenews', '$textnews', '$username'");
  46.                        
  47.                         echo '<p class="alert alert-success">News inserted successfully!</p>';
  48.                         echo '<meta http-equiv="refresh" content="3;url=news.php" />';
  49.                     }else{
  50.                         foreach($errorsnews as $listnews){
  51.                             echo '<p class="alert alert-danger">',$listnews,'</p>';
  52.                         }
  53.                     }
  54.                 }      
  55.                 ?> 
  56.                 <script src="js/tiny/tinymce.min.js" language="javascript" type="text/javascript"></script>
  57.                     <script language="javascript" type="text/javascript">
  58.                     tinyMCE.init({
  59.                     mode : "specific_textareas",
  60.                     editor_selector : "mceEditor"
  61.                     });
  62.                     </script>
  63.                    
  64.                         <h2>News </h2>
  65.                             <div style="width: 50%;">
  66.                                 <form action='' method='POST'>
  67.                                     <b>
  68.                                         <p>Title: <input class="form-control" type="text" name="titlenews"/></p>
  69.                                         <br />
  70.                                         <p>Text: <textarea id="myarea1" class="mceEditor" name="textnews"> </textarea></p>
  71.                                         <br />
  72.                                         <button type="submit" class="btn btn-success" name="sendnews">Send</button>
  73.                                         <button type="reset" class="btn btn-danger">Reset</button>
  74.                                     </b>
  75.                                 </form>
  76.                             </div>
  77.                        
  78.                        
  79.                         <hr />
  80.                         <h2>List News</h2>
  81.                        
  82.                 <?php
  83.                     if(isset($_POST['id'])){
  84.                         $id = dbin($_POST['id']);
  85.                         mysqli_query($conn, "DELETE FROM $dbsite.news WHERE id='$id'");
  86.                        
  87.                         echo '<p class="alert alert-success">Deleted successfully!</p>';
  88.                         echo '<meta http-equiv="refresh" content="3;url=news.php" />';
  89.                     }
  90.                        
  91.                     $page = dbin(@$_GET['p']);
  92.                     $pag = dbin(($page + 0)*10);
  93.  
  94.                     $listnews = mysqli_query($conn, "SELECT * FROM $dbsite.news ORDER BY date LIMIT $pag,10");
  95.                     if($listnews && mysqli_num_rows($listnews) > 0){
  96.                 ?>
  97.                     <div class="mex">
  98.                         <table>
  99.                           <thead>
  100.                             <tr>
  101.                               <th>Title:</th>
  102.                               <th>Text:</th>
  103.                               <th>Author:</th>
  104.                               <th>Date:</th>
  105.                               <th></th>
  106.                             </tr>
  107.                           </thead>
  108.                           <tbody>
  109.                             <?php
  110.                                 while($listrow = mysqli_fetch_assoc($listnews)){
  111.                             ?>
  112.                             <form action="" method="POST">
  113.                                 <tr>
  114.                                   <td><textarea class="form-control" disabled><?php echo $listrow['title']; ?></textarea></td>
  115.                                   <td><textarea class="form-control" disabled><?php echo $listrow['text']; ?></textarea></td>
  116.                                   <td><input class="form-control" type="text" value="<?php echo $listrow['author']; ?>" disabled /></td>
  117.                                   <td><input class="form-control"type="text" value="<?php echo $listrow['date']; ?>" disabled /></td>
  118.                                   <td><button type="submit" name="id" class="btn btn-danger" value="<?php echo $listrow['id']; ?>">Delete</button></td>
  119.                                 </tr>
  120.                             </form>
  121.                             <?php } ?>
  122.                           </tbody>
  123.                         </table>
  124.                         <ul class="pagination">
  125.                         <?php
  126.                         if($page != 0)  echo '<li><a href="news.php?p=' .($page-1) .'">&laquo; Back</a></td></tr>';
  127.                         if($page < 50) echo '<li><a href="news.php?p=' .($page+1) .'">Forward &raquo;</a></td></tr>';
  128.                         ?>
  129.                         </ul>
  130.                     </div>
  131.                     <?php
  132.                         }else{
  133.                             echo '<p class="alert alert-danger">There are no news!</p>';
  134.                             echo'<ul class="pagination">';
  135.                                 if($page > 0)   echo '<li><a href="news.php?p=' .($page-1) .'">&laquo; Back</a></td></tr>';
  136.                             echo'</ul>';
  137.                         } ?>   
  138.                     </center>
  139.                 </div>
  140.  
  141.             </div>
  142.  
  143.         </div>
  144.         <?php include('inc/footer.php'); ?>
  145.     </body>
  146. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement