Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start();
- include '../includes/db.php';
- if(isset($_SESSION['user']) && isset($_SESSION['password']) == true){
- $sel_sql = "SELECT * FROM users WHERE user_username = '$_SESSION[user]' AND user_password = '$_SESSION[password]'";
- if($run_sql = mysqli_query($conn, $sel_sql)){
- while($rows = mysqli_fetch_assoc($run_sql)){
- if(mysqli_num_rows($run_sql) == 1 ) {
- if($rows['role'] == 'admin'){
- }else{
- header('Location:../index.php');
- }
- }else{
- header('Location:../index.php');
- }
- }
- }
- }else{
- header('Location:../index.php');
- }
- if(isset($_POST['sumbit_post'])){
- $title = strip_tags($_POST['title']);
- $date = date('Y-m-d h:i:m');
- if(isset($_FILES['image'])){
- $image_name = $_FILES['image']['name'];
- $image_tmp = $_FILES['image']['temp_name'];
- $image_size = $_FILES['image']['size'];
- $image_ext = pathinfo($image_name, PATHINFO_EXTENSION);
- $image_path = '../images/'.$image_name;
- $image_db_path = 'images/'.$image_name;
- if($image_size < 1000000){
- if($image_ext == 'jpg' || $image_ext == 'png' || $image_ext == 'gif'){
- if(move_uploaded_file($image_tmp, $image_path)){
- $ins_sql = "INSERT INTO post (title, description, image, category, date , author) VALUES('$title','$_POST[description],'$image_db_path','$_POST[category]', '$date', '$_SESSION[user]')";
- if(){}
- }else{
- $image_err = 'Atsiprašome, netikėtai paveikslėlis buvo neįkeltas';
- }
- }else{
- $image_err = 'Paveikslėlio formatas netinkamas ! !';
- }
- }else {
- $image_err = 'Paveikslėlis užima per daug ! !';
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Administratoriaus aplinka</title>
- <link rel="stylesheet" href="../css/bootstrap.css">
- <script src="../js/jquery.js"></script>
- <script src="../js/bootstrap.js"></script>
- <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
- <script>tinymce.init({ selector:'textarea' });</script>
- </head>
- <body>
- <?php include 'includes/header.php' ?>
- <div style="width:50px;height:50px"></div>
- <?php include 'includes/sidebar.php' ?>
- <div class="col-lg-10">
- <div class="page-header"><h1>Naujienos kūrimas</h1></div>
- <div class="container-fluid">
- <form class="form-horizontal" action="new_post.php" method="post" enctype="multipart/form-data">
- <div class="form-group">
- <label for="image">Įkelti paveikslėlį</label>
- <input id="image" type="file" name="image" class="btn btn-primary"></input>
- </div>
- <div class="form-group">
- <label for="title">Naujienos pavadinimas</label>
- <input id="title" type="text" name="title" class="form-control" required></input>
- </div>
- <div class="form-group">
- <label for="category">Kategorija</label>
- <select id="category" name="category" class="form-control" required>
- <option value="">Pasirinkti kategorija</option>
- <?php
- $sel_sql = "SELECT * FROM category";
- $run_sql = mysqli_query($conn,$sel_sql);
- while ($rows = mysqli_fetch_assoc($run_sql)) {
- if($rows['category_name'] == 'Pagrindinis'){
- continue;
- }
- echo '<option value="'.$rows['category_name'].'">'.ucfirst($rows['category_name']).'</option>';
- }
- ?>
- </select>
- </div>
- <div class="form-group">
- <label for="title">Aprašymas</label>
- <textarea name="description" id="description" required></textarea>
- </div>
- <div class="form-group">
- <label for="category">Statusas</label>
- <select id="category" name="status" class="form-control">
- <option value="draft">Juodraštis</option>
- <option value="publish">Paskelbtas</option>
- </select>
- </div>
- <div class="form-group">
- <label for="title"></label>
- <input id="title" type="submit" name="submit_post" class="btn btn-primary btn-block"></input>
- </div>
- </form>
- </div>
- </div>
- <footer></footer>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement