<?php
/**
*
* @ This file is created by http://DeZender.Net
* @ deZender (PHP7 Decoder for SourceGuardian Encoder)
*
* @ Version			:	4.1.0.1
* @ Author			:	DeZender
* @ Release on		:	29.08.2020
* @ Official site	:	http://DeZender.Net
*
*/

require 'includes/check.php';
$ifofuser_check = $_SESSION['id'];
$jsondata_admin = file_get_contents('./includes/eggzie.json');
$data_admin = json_decode($jsondata_admin, true);
$json_admin = $data_admin['info'];
$col_admin = $json_admin['oo'];

if ($col_admin == '0') {
	header('Location: dashboard.php');
}

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$db = new SQLite3('./a/.eggziedb.db');
$res1 = $db->query('SELECT * FROM ibo');

if (isset($_GET['delete'])) {
	$db->exec('DELETE FROM ibo WHERE id=' . $_GET['delete']);
	$db->close();
	header('Location: users.php?succes');
}

if (isset($_GET['block'])) {
	$db->exec('UPDATE ibo SET is_blocked=\'1\' WHERE mac_address=\'' . $_GET['block'] . '\'');
	$db->close();
	header('Location: users.php?succes_block');
}

if (isset($_GET['unblock'])) {
	$db->exec('UPDATE ibo SET is_blocked=\'0\' WHERE mac_address=\'' . $_GET['unblock'] . '\'');
	$db->close();
	header('Location: users.php?succes_unblock');
}

include 'includes/header.php';
echo '<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' . "\n";
echo '    <div class="modal-dialog">' . "\n";
echo '        <div class="modal-content">' . "\n";
echo '            <div class="modal-header">' . "\n";
echo '                <h2>Confirm</h2>' . "\n";
echo '            </div>' . "\n";
echo '            <div class="modal-body">' . "\n";
echo '                Do you really want to delete?' . "\n";
echo '            </div>' . "\n";
echo '            <div class="modal-footer">' . "\n";
echo '                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>' . "\n";
echo '                <a class="btn btn-danger btn-ok">Delete</a>' . "\n";
echo '            </div>' . "\n";
echo '        </div>' . "\n";
echo '    </div>' . "\n";
echo '</div>' . "\n";
echo '        <div>';
echo '    <div class="container-fluid">' . "\n";

if (isset($_GET['succes'])) {
	echo $msg_delete;
}

if (isset($_GET['success'])) {
	echo $msg_success;
}

if (isset($_GET['succes_block'])) {
	echo $msg_succes_block;
}

if (isset($_GET['succes_unblock'])) {
	echo $msg_succes_unblock;
}

echo '          <h1 class=" h3 mb-1" style="color:' . $colour_head_16 . ';"> User Management</h1>' . "\n";
echo "\n";
echo '                <div class="card border-left-primary shadow h-100 card shadow mb-4">' . "\n";
echo '                <div class="card-header py-3">' . "\n";
echo '                <h6 class="m-0 font-weight-bold" style="color:' . $colour_head_11 . ';"><i class="fa fa-user"></i> Users</h6>' . "\n";
echo '                </div>' . "\n";
echo '                    <div class="card-body">';
echo '                            <a button class="btn btn-success btn-icon-split" style="background-color:' . $colour_head_btn . ';border-color:' . $colour_head_btn . ';color:' . $colour_head_10 . ';" href="./users_create.php">' . "\n";
echo '                            <span class="icon text-white-50"><i class="fas fa-plus" style="color:' . $colour_head_10 . ';"></i></span><span class="text"> ADD User</span>' . "\n";
echo '                            </button></a>' . "\n";
echo '    ' . "\t\t\t\t\t" . '<hr>';
echo "\t\t\t\t\t\t" . '<div class="table-responsive">';
echo "\t\t\t\t\t\t\t" . '<table id="Dtable" class="table" style="width:100%">';
echo "\t\t\t\t\t\t\t" . '<thead>';
echo "\t\t\t" . '<tr style = "color:' . $colour_head_12 . ';">';
echo "\t\t\t" . '<th style = "display:none" >Index</th>';
echo '                  <th>Title</th>' . "\n";
echo "\t\t\t\t" . '  <th>Mac Address</th>' . "\n";
echo '                  <th>Username</th>' . "\n";

if ($ifofuser_check != '2') {
	echo '                  <th>Server ID / Title</th>' . "\n";
}
else {
	echo '                  <th>DNS</th>' . "\n";
}

echo "\t\t\t\t" . '  <th>Blocked</th>' . "\n";
echo "\t\t\t\t" . '  <th>Edit</th>' . "\n";
echo "\t\t\t\t" . '  <th>Delete</th>';
echo "\t\t\t\t" . '</tr>';
echo "\t\t\t\t" . '</thead>';
echo "\t\t\t\t" . '<tbody style="background-color:' . $colour_head_3 . ';color:' . $colour_head_2 . ';">';

while ($row1 = $res1->fetchArray()) {
	$users_id = $row1['id'];
	$user_mac = $row1['mac_address'];
	$user_username = $row1['username'];
	$user_url = $row1['url'];
	$user_title = $row1['title'];
	$user_block = $row1['is_blocked'];
	$new_dns_name = '';
	$new_dns_url = '';
	$hostres = $db->query('SELECT * FROM portals WHERE id=\'' . $user_url . '\'');

	while ($hostrow = $hostres->fetchArray()) {
		$new_dns_name = $hostrow['name'];
		$new_dns_url = $hostrow['url'];
	}

	echo "\t\t\t\t\t" . ' <tr style="background-color:' . $colour_head_3 . ';color:' . $colour_head_2 . ';">';
	echo "\t\t\t\t\t" . ' <td style = "display:none">' . $users_id . '</td>';
	echo '                  <td>' . $user_title . '</td>' . "\n";
	echo '                  <td>' . $user_mac . '</td>' . "\n";
	echo '                  <td>' . $user_username . '</td>' . "\n";

	if ($ifofuser_check != '2') {
		echo '                  <td>' . $user_url . ' / ' . $new_dns_name . '</td>' . "\n";
	}
	else {
		echo '                  <td>' . $new_dns_url . '</td>' . "\n";
	}

	if ($user_block == '1') {
		echo "\t\t\t\t" . '  <td><a href="./users.php?unblock=' . $user_mac . '"><i class="fa fa-toggle-on" style="color:red"></i></a></td>' . "\n";
	}
	else {
		echo "\t\t\t\t" . '  <td><a href="./users.php?block=' . $user_mac . '"><i class="fa fa-toggle-off"  style="color:grey"></i></a></td>' . "\n";
	}

	echo "\t\t\t\t" . '  <td><a href="./users_update.php?update=' . $users_id . '"><i class="fa fa-pencil" style="font-size:15px;color:blue"></i></a></td>' . "\n";
	echo "\t\t\t" . ' <td><a class="btn btn-icon" href="#" data-href="./users.php?delete=' . $users_id . '" data-toggle="modal" data-target="#confirm-delete"><i class="fa fa-trash" style="font-size:15px;color:red"></i></a>';
	echo "\t\t\t\t\t" . '</td>';
	echo "\t\t\t\t\t" . '</tr>';
}

echo "\t\t\t\t\t\t\t" . '</tbody>';
echo "\t\t\t\t\t\t\t" . '</table>';
echo "\t\t\t\t\t\t" . '</div>';
echo "\t\t\t\t\t" . '</div>';
echo "\t\t\t\t" . '</div>';
echo "\t\t\t\t\t" . '</div>';
echo "\t\t\t\t" . '</div>';
include 'includes/footer.php';
echo '</body>';
echo '</html>';
require 'includes/egz.php';

?>