<?php include('session.php'); ?>
<!doctype html>
<html lang="en">

<head>
<title>LaktusDev | Gallery</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="description" content="">
<meta name="author" content="LaktusDev, design by: laktusdev.com">

<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- VENDOR CSS -->
<link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/vendor/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/vendor/animate-css/vivify.min.css">
<link rel="stylesheet" href="assets/vendor/light-gallery/css/lightgallery.css">

<link rel="stylesheet" href="assets/vendor/sweetalert/sweetalert.css"/>

<!-- MAIN CSS -->
<link rel="stylesheet" href="assets/css/mooli.min.css">

</head>
<body>
    
<div id="body" class="theme-green">

<?php require 'includes/page-loader.php'; ?>

<?php require 'includes/themesetting.php'; ?>

    <!-- Overlay For Sidebars -->
    <div class="overlay"></div>

    <div id="wrapper">

<?php require 'includes/topbar.php'; ?>
<?php require 'includes/leftbar.php'; ?>
        <!-- Main body part  -->
        <div id="main-content">

            <div class="container-fluid">
                <!-- Page header section  -->
                <div class="block-header">
                    <div class="row clearfix">
                        <div class="col-lg-4 col-md-12 col-sm-12">
                            <h1>Galerija</h1>
                            <span>izmena slike</span>
                        </div>
                        <div class="col-lg-8 col-md-12 col-sm-12 text-lg-right">
                            
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-12">
                        <nav class="navbar navbar-expand-lg navbar-light bg-light page_menu">
                            <a class="navbar-brand" href="">Galerija</a>
                            
                            <div class="collapse navbar-collapse" id="navbarNavDropdown">
                                
                                <div class="ml-auto">
                                    
                                </div>
                            </div>
                        </nav>
                    </div>
                    <div class="col-12">
                        <div class="card">
                            <div class="body">
                                <div id="lightgallery" class="row clearfix lightGallery">
                                    
<?php
include("../../veza/le.php");
$images_dir = '../../uploads/portfolio/';

// collect and check the data sent by url is a number
$state_photoid = (int)($_GET['photo_id']);
// Check $photo_id is not empty
if(!empty($state_photoid) )
{
// Firstly Lets get the Photo ID

$result = mysqli_query($leld,"SELECT opis,slika FROM le_portfolio_photos WHERE 
photo_id='".addslashes($state_photoid)."'")
or die(mysqli_error());
$nr = mysqli_num_rows($result);
if( $nr < 1 )
{
	echo("Photo not found in DB!");
}
else
{           
$row = mysqli_fetch_array( $result );
mysqli_free_result( $result );
echo("<div class='col-lg-3 col-md-6 m-b-15'><a href='".$images_dir."".$row[1]."' class='light-link'>");
echo("<img src='".$images_dir."".$row[1]."' class='img-fluid' alt='".$row[0]."'>");
echo("</a></div>");
}
?>
<div class='col-lg-9 col-md-6 m-b-15'>
<form name="photo_move" action="portfolio_edit.php" method="post">
<b>Promeni naslov:</b><br />
<br /><br />
<div class="form-group">
<label for="caption">Naslov<span class="text-danger">*</span></label>
<input type="text" class="form-control" maxlength="150" name="caption" value="<?php echo($row['opis']); ?>" />
</div>
<input type="hidden" value="<?php echo($_GET['photo_id']); ?>" name="photo_id" />
<div class="form-group text-right m-b-0">
<input type="submit" class="btn btn-primary waves-light waves-effect" value="Submit" name="action" />
</div>
</form>
<br />
<form name="photo_delete" action="portfolio_edit.php" method="post">
<b>Obriši sliku:</b><br />
<input type="hidden" value="<?php echo($_GET['photo_id']); ?>" name="photo_id" />
<div class="form-group text-right m-b-0">
<input type="submit" class="btn btn-primary waves-effect waves-light" value="Obrisati" name="action" onclick="return confirm('Da li ste sigurni da želite da obrišete sliku?')" />
</div>
</form>
</div>

<?php
    }
    else
    {
        if( strcasecmp($_POST['action'], "Submit")==0 && !empty( $_POST['photo_id'] ) )
        {
            edit_photo($_POST['photo_id'], $_POST['caption']);
        }
        else if( strcasecmp($_POST['action'], "Obrisati")==0 && !empty( $_POST['photo_id'] ) )
        {
            delete_photo($_POST['photo_id']);
        }
        else
        {
            echo("Action not understood"); exit;
        }
        echo("<div class='sweet-overlay' tabindex='-1' style='opacity: 1.02; display: block;'></div>
<div class='sweet-alert showSweetAlert visible' data-custom-class='' data-has-cancel-button='false' data-has-confirm-button='true' data-allow-outside-click='false' data-has-done-function='false' data-animation='pop' data-timer='null' style='display: block; margin-top: -165px;'><div class='sa-icon sa-error' style='display: none;'>
      <span class='sa-x-mark'>
        <span class='sa-line sa-left'></span>
        <span class='sa-line sa-right'></span>
      </span>
    </div><div class='sa-icon sa-warning' style='display: none;'>
      <span class='sa-body'></span>
      <span class='sa-dot'></span>
    </div><div class='sa-icon sa-info' style='display: none;'></div><div class='sa-icon sa-success animate' style='display: block;'>
      <span class='sa-line sa-tip animateSuccessTip'></span>
      <span class='sa-line sa-long animateSuccessLong'></span>

      <div class='sa-placeholder'></div>
      <div class='sa-fix'></div>
    </div><div class='sa-icon sa-custom' style='display: none; background-image: url(&quot;assets/images/sm/avatar1.jpg&quot;); width: 80px; height: 80px;'></div><h4>Operacija uspešna!</h4>
    <p style='display: block;'></p>
    <fieldset>
      <input type='text' tabindex='3' placeholder=''>
      <div class='sa-input-error'></div>
    </fieldset><div class='sa-error-container'>
      <div class='icon'>!</div>
      <p>Not valid!</p>
    </div><div class='sa-button-container'>
      <button class='cancel' tabindex='2' style='display: none; box-shadow: none;'>Cancel</button>
      <div class='sa-confirm-button-container'>
        <script>setTimeout(\"location.href = 'portfolio.php';\",2000);</script>
		<div class='la-ball-fall'>
          <div></div>
          <div></div>
          <div></div>
        </div>
      </div>
    </div></div>");
    }
// the functions here
function edit_photo( $state_photoid, $new_caption )
{
global $leld;
mysqli_query($leld, "UPDATE le_portfolio_photos SET opis='".addslashes( $new_caption )."' WHERE photo_id='".addslashes( $state_photoid )."'"  );
}
function delete_photo($state_photoid)
{
global $leld;
global $images_dir;
$result = mysqli_query($leld, "
   SELECT slika
   FROM le_portfolio_photos
   WHERE photo_id = '" . addslashes($state_photoid) . "'
");
list($filename) = mysqli_fetch_array($result);
mysqli_free_result($result);
unlink($images_dir . '' . $filename);
unlink($images_dir . 'tb_' . $filename);
mysqli_query($leld,"
   DELETE FROM le_portfolio_photos
   WHERE photo_id='" . addslashes($state_photoid) . "'
");
}
?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

</div>
<!-- Javascript -->
<script src="assets/bundles/libscripts.bundle.js"></script>    
<script src="assets/bundles/vendorscripts.bundle.js"></script>

<!-- Vedor js file and create bundle with grunt  --> 
<script src="assets/vendor/light-gallery/js/lightgallery-all.min.js"></script><!-- Light Gallery Plugin Js --> 
<script src="assets/vendor/light-gallery/js/mousewheel.min.js"></script><!-- Light Gallery Plugin Js -->
<script src="assets/vendor/sweetalert/sweetalert.min.js"></script><!-- SweetAlert Plugin Js -->

<!-- Project core js file minify with grunt --> 
<script src="assets/bundles/mainscripts.bundle.js"></script>
<script src="../js/pages/medias/image-gallery.js"></script>
</body>
</html>