Advertisement
Guest User

Untitled

a guest
Nov 24th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.83 KB | None | 0 0
  1. <?php session_start();
  2.  include '../includes/db.php';
  3.  if(isset($_SESSION['user']) && isset($_SESSION['password']) == true){
  4.     $sel_sql = "SELECT * FROM users WHERE user_username = '$_SESSION[user]' AND user_password = '$_SESSION[password]'";
  5.     if($run_sql = mysqli_query($conn, $sel_sql)){
  6.         while($rows = mysqli_fetch_assoc($run_sql)){
  7.         if(mysqli_num_rows($run_sql) == 1 ) {
  8.             if($rows['role'] == 'admin'){
  9.  
  10.             }else{
  11.                     header('Location:../index.php');
  12.             }
  13.             }else{
  14.                 header('Location:../index.php');
  15.             }
  16.         }
  17.     }
  18.  }else{
  19.     header('Location:../index.php');
  20.  }
  21.  if(isset($_POST['sumbit_post'])){
  22.     $title = strip_tags($_POST['title']);
  23.     $date = date('Y-m-d h:i:m');
  24.     if(isset($_FILES['image'])){
  25.         $image_name = $_FILES['image']['name'];
  26.         $image_tmp = $_FILES['image']['temp_name'];
  27.         $image_size = $_FILES['image']['size'];
  28.         $image_ext = pathinfo($image_name, PATHINFO_EXTENSION);
  29.         $image_path = '../images/'.$image_name;
  30.         $image_db_path = 'images/'.$image_name;
  31.         if($image_size < 1000000){
  32.             if($image_ext == 'jpg' || $image_ext == 'png' || $image_ext == 'gif'){
  33.                 if(move_uploaded_file($image_tmp, $image_path)){
  34.                     $ins_sql = "INSERT INTO post (title, description, image, category, date , author) VALUES('$title','$_POST[description],'$image_db_path','$_POST[category]', '$date', '$_SESSION[user]')";
  35.                     if(){}
  36.                 }else{
  37.                     $image_err = 'Atsiprašome, netikėtai paveikslėlis buvo neįkeltas';
  38.                 }
  39.             }else{
  40.                 $image_err = 'Paveikslėlio formatas netinkamas ! !';
  41.             }
  42.         }else {
  43.             $image_err = 'Paveikslėlis užima per daug ! !';
  44.         }
  45.     }
  46.  }
  47.  ?>
  48. <!DOCTYPE html>
  49. <html>
  50. <head>
  51. <title>Administratoriaus aplinka</title>
  52. <link rel="stylesheet" href="../css/bootstrap.css">
  53.         <script src="../js/jquery.js"></script>
  54.         <script src="../js/bootstrap.js"></script>
  55.         <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
  56.         <script>tinymce.init({ selector:'textarea' });</script>
  57. </head>
  58. <body>
  59.     <?php include 'includes/header.php' ?>
  60.     <div style="width:50px;height:50px"></div>
  61. <?php include 'includes/sidebar.php' ?>
  62. <div class="col-lg-10">
  63.     <div class="page-header"><h1>Naujienos kūrimas</h1></div>
  64.     <div class="container-fluid">  
  65.     <form class="form-horizontal" action="new_post.php" method="post" enctype="multipart/form-data">
  66.         <div class="form-group">
  67.             <label for="image">Įkelti paveikslėlį</label>
  68.             <input id="image" type="file" name="image" class="btn btn-primary"></input>
  69.         </div>
  70.         <div class="form-group">
  71.             <label for="title">Naujienos pavadinimas</label>
  72.             <input id="title" type="text" name="title" class="form-control" required></input>
  73.         </div>
  74.         <div class="form-group">
  75.             <label for="category">Kategorija</label>
  76.             <select id="category" name="category" class="form-control" required>
  77.             <option value="">Pasirinkti kategorija</option>
  78.                 <?php
  79.                 $sel_sql = "SELECT * FROM category";
  80.                 $run_sql = mysqli_query($conn,$sel_sql);
  81.                 while ($rows = mysqli_fetch_assoc($run_sql)) {
  82.                     if($rows['category_name'] == 'Pagrindinis'){
  83.                         continue;
  84.                     }
  85.                     echo '<option value="'.$rows['category_name'].'">'.ucfirst($rows['category_name']).'</option>';
  86.                  }
  87.  
  88.                 ?>
  89.             </select>
  90.         </div>
  91.         <div class="form-group">
  92.             <label for="title">Aprašymas</label>
  93.             <textarea name="description" id="description" required></textarea>
  94.         </div>
  95.         <div class="form-group">
  96.             <label for="category">Statusas</label>
  97.             <select id="category" name="status" class="form-control">
  98.                 <option value="draft">Juodraštis</option>
  99.                 <option value="publish">Paskelbtas</option>
  100.             </select>
  101.         </div>
  102.             <div class="form-group">
  103.             <label for="title"></label>
  104.             <input id="title" type="submit" name="submit_post" class="btn btn-primary btn-block"></input>
  105.         </div>
  106.     </form>
  107.     </div>
  108.  
  109. </div>
  110. <footer></footer>
  111. </body>
  112.  
  113.  
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement