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

<head>
<title>Korisnici</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/bootstrap-multiselect/bootstrap-multiselect.css">
<link rel="stylesheet" href="assets/vendor/parsleyjs/css/parsley.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-md-5 col-sm-12">
                            <h1>Korisnici</h1>
                            <span></span>
                        </div>            
                        <div class="col-md-7 col-sm-12 text-md-right">
                            <div class="d-flex align-items-center justify-content-md-end mt-4 mt-md-0 flex-wrap vivify pullUp delay-550">
                                <div class="mb-3 mb-xl-0">
<?php if ($row_korisnik['level'] <= '2') { ?>
									<button type="button" class="btn btn-dark" data-toggle="modal" data-target=".add"><i class="fa fa-user-plus"></i> Dodaj korisnika</button>
<?php } ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row clearfix">
                    <div class="col-12">
                        <div class="card bg-clear">
                            <div class="header">
                                <ul class="nav nav-tabs3">
                                    <li class="nav-item"><a class="nav-link active show" data-toggle="tab" href="#All-Contacts">All</a></li>
                                </ul>
                            </div>
                            <div class="body">
                                <div class="tab-content mt-0">
                                    <div class="tab-pane show active" id="All-Contacts">
                                        <div class="row clearfix">
<?php
$success = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$lozinka=get_safe_value($leld,$_REQUEST['lozinka']);
$email=get_safe_value($leld,$_REQUEST['email']);
$ime=get_safe_value($leld,$_REQUEST['ime']);
$level =get_safe_value($leld,$_REQUEST['level']);

$ins_query="insert into le_users (`lozinka`, `email`, `ime`, `level`) values ('$lozinka', '$email', '$ime', '$level')";
mysqli_query($leld,$ins_query) or die ( mysqli_error());

$success = "
<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>Korisnik dodat!</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 = 'users.php';\",2000);</script>
		<div class='la-ball-fall'>
          <div></div>
          <div></div>
          <div></div>
        </div>
      </div>
    </div></div>
";
echo ''.$success.'';
}else {
?>
<?php
$count=1;
$query_boss = "SELECT * FROM le_users WHERE level > '1'";
$boss = mysqli_query($leld,$query_boss) or die(mysqli_error());
$totalRows_boss = mysqli_num_rows($boss);
?>
<?php while($row_boss = mysqli_fetch_assoc($boss)) { ?>
											<div class="col-lg-3 col-md-4 col-sm-6">
                                                <div class="card contact_card">
                                                    <div class="header">
<?php if ($row_korisnik['level'] <= '2') { ?>
														<ul class="header-dropdown dropdown">
                                                            <li class="dropdown">
                                                                <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"></a>
                                                                <ul class="dropdown-menu theme-bg gradient">
                                                                    <li><a data-toggle="modal" data-target=".edit<?php echo $row_boss['id']; ?>"><i class="fa fa-edit"></i> Izmena</a></li>
                                                                    <li><a data-toggle="modal" data-target="#delete<?php echo $row_boss['id']; ?>"><i class="fa fa-trash"></i> Brisanje</a></li>
                                                                </ul>
                                                            </li>
                                                        </ul>
														<div class="modal fade edit<?php echo $row_boss['id']; ?>" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
															<div class="modal-dialog" role="document">
																<div class="modal-content">
																	<div class="modal-header">
																		<h5 class="modal-title" id="exampleModalLabel"><i class="fa fa-edit"></i> <?php echo $row_boss['ime']; ?></h5>
																		<button type="button" class="close" data-dismiss="modal" aria-label="Close">
																			<span aria-hidden="true">&times;</span>
																		</button>
																	</div>
																	<form action="user_edit.php" method="post" id="advanced-form" data-parsley-validate novalidate>
																	<div class="modal-body">
																		<div class="form-group c_form_group">
																			<label>Email</label>
																			<div class="input-group">
																				<input type="text" name="email" value="<?php echo htmlentities($row_boss['email'], ENT_COMPAT, 'utf-8'); ?>" class="form-control" placeholder="" required data-parsley-maxlength="255">
																			</div>
																		</div>
																		<div class="form-group c_form_group">
																			<label>Ime</label>
																			<div class="input-group">
																				<input type="text" name="ime" value="<?php echo htmlentities($row_boss['ime'], ENT_COMPAT, 'utf-8'); ?>" class="form-control" placeholder="" required data-parsley-maxlength="40">
																			</div>
																		</div>
																		<div class="form-group c_form_group">
																			<label>Lozinka</label>
																			<div class="input-group">
																				<input type="text" name="lozinka" value="<?php echo htmlentities($row_boss['lozinka'], ENT_COMPAT, 'utf-8'); ?>" class="form-control" placeholder="" required data-parsley-maxlength="60">
																			</div>
																		</div>
<?php if ($row_korisnik['level'] == '1') { ?>
																		<div class="form-group c_form_group">
																			<label>Nivo</label>
																			<select name="level" class="custom-select" id="inputGroupSelect01">
																				<option value="1" <?php if (!(strcmp("1", htmlentities($row_boss['level'], ENT_COMPAT, 'utf-8')))) {echo "selected";} ?>>Webmaster</option>
																				<option value="2" <?php if (!(strcmp("2", htmlentities($row_boss['level'], ENT_COMPAT, 'utf-8')))) {echo "selected";} ?>>Administrator</option>
																			</select>
																		</div>
<?php } else if ($row_korisnik['level'] == '2') { ?>
																		<div class="form-group c_form_group">
																			<label>Nivo</label>
																			<select name="level" class="custom-select" id="inputGroupSelect01">
																				<option value="2" <?php if (!(strcmp("2", htmlentities($row_boss['level'], ENT_COMPAT, 'utf-8')))) {echo "selected";} ?>>Administrator</option>
																			</select>
																		</div>
<?php } ?>
																	</div>
																	<div class="modal-footer">
																		<button type="submit" class="btn btn-success">Izmeni</button>
																		<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
																	</div>
																	<input type="hidden" name="id" value="<?php echo $row_boss['id']; ?>" />
																	<input type="hidden" name="edit" value="1" />
																	</form>
																</div>
															</div>
														</div>
														<div class="modal fade" id="delete<?php echo $row_boss['id']; ?>" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
															<div class="modal-dialog modal-dialog-centered" role="document">
																<div class="modal-content">
																	<div class="modal-header">
																		<h5 class="modal-title" id="exampleModalCenterTitle">Upozorenje!</h5>
																		<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
																	</div>
																	<div class="modal-body">
																		<p>Da li ste sigurni da želite da obrišete korisnika?</p>
																	</div>
																	<div class="modal-footer">
																		<a href="user_delete.php?id=<?php echo $row_boss['id']; ?>" class="btn btn-primary theme-bg gradient">Da</a>
																		<button type="button" class="btn btn-default" data-dismiss="modal">Ne</button>
																	</div>
																</div>
															</div>
														</div>
<?php } ?>
                                                    </div>
                                                    <div class="body text-center">
                                                        <div class="circle">
                                                            <img class="rounded-circle" src="assets/images/sm/avatar2.jpg" alt="">
                                                        </div>
                                                        <h6 class="mt-3 mb-0"><?php echo $row_boss['ime']; ?></h6>
                                                        <span><?php echo $row_boss['email']; ?></span>
                                                    </div>
                                                </div>
                                            </div>
<?php $count++; } ?>
<?php } ?>
                                        </div>
                                    </div>
                                    
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
    </div>

</div>
<div class="modal fade add" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
	<div class="modal-dialog modal-dialog-centered" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="exampleModalLabel"><i class="fa fa-user-plus"></i> Dodaj korisnika</h5>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<form action="" method="post" id="advanced-form" data-parsley-validate novalidate>
			<div class="modal-body">
				<div class="form-group c_form_group">
				<div class="form-group c_form_group">
					<label>Lozinka</label>
					<input type="text" name="lozinka" class="form-control" placeholder="Lozinka" required data-parsley-maxlength="60">
				</div>
				<div class="form-group c_form_group">
					<label>Email</label>
					<input type="text" name="email" class="form-control" placeholder="Email" required data-parsley-maxlength="255">
				</div>
				<div class="form-group c_form_group">
					<label>Ime</label>
					<input type="text" name="ime" class="form-control" placeholder="Ime" required data-parsley-maxlength="40">
				</div>
<?php if ($row_korisnik['level'] == '1') { ?>
				<div class="form-group c_form_group">
					<label>Nivo</label>
					<select name="level" class="custom-select" data-parsley-required id="inputGroupSelect01">
						<option value="1">Webmaster</option>
						<option value="2">Administrator</option>
					</select>
				</div>
<?php } else if ($row_korisnik['level'] == '2') { ?>
				<div class="form-group c_form_group">
					<label>Nivo</label>
					<select name="level" class="custom-select" data-parsley-required id="inputGroupSelect01">
						<option value="2">Administrator</option>
					</select>
				</div>
<?php } ?>
			</div>
			<div class="modal-footer">
				<button type="submit" class="btn btn-success">Dodaj</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			</div>
			<input type="hidden" name="new" value="1" />
			</form>
		</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/bootstrap-multiselect/bootstrap-multiselect.js"></script>
<script src="assets/vendor/parsleyjs/js/parsley.min.js"></script>
<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/ui/dialogs.js"></script>
<script>
    $(function() {
        // validation needs name of the element
        $('#food').multiselect();

        // initialize after multiselect
        $('#advanced-form').parsley();
    });
</script>
</body>
</html>
