<?php

session_start();
include 'assets/includes/db.php';
include 'assets/includes/config.php';

if ($_ERRORS) {
	error_reporting(E_ALL);
	ini_set('display_errors', 1);
}
if (!isset($_SESSION['loggedin']) && !$_SESSION['loggedin']) {
	header('location: logout.php');
}

$sql = 'SELECT * FROM profile ';
$sql .= 'WHERE id = \'1\';';
$result = $sqlite3->query($sql);
$profile_data = $result->fetchArray();
$sql = 'SELECT * FROM panel;';
$result = $sqlite3->query($sql);
$panel_data = $result->fetchArray();

if (isset($_POST['save_profile'])) {
	$sql = 'UPDATE profile SET ';
	$sql .= 'profile_name = \'' . $_POST['profile_first_name'] . '\', ';
	$sql .= 'username = \'' . $_POST['profile_user_name'] . '\', ';
	$sql .= 'password = \'' . $_POST['profile_password'] . '\', ';
	$sql .= 'avatar_url = \'' . $_POST['profile_avatar_url'] . '\' ';
	$sql .= 'WHERE id = \'1\';';
	$sqlite3->exec($sql);
	session_regenerate_id();
	$_SESSION['loggedin'] = true;
	$_SESSION['profile_name'] = $_POST['profile_first_name'];
	$_SESSION['username'] = $_POST['profile_user_name'];
	$_SESSION['avatar_url'] = $_POST['profile_avatar_url'];
	header('location: profile_edit.php');
}

if (isset($_POST['save_panel'])) {
	$sql = 'UPDATE panel SET ';
	$sql .= 'title = \'' . $_POST['panel_title'] . '\', ';
	$sql .= 'logo_light = \'' . $_POST['panel_light_logo'] . '\', ';
	$sql .= 'logo_dark = \'' . $_POST['panel_dark_logo'] . '\', ';
	$sql .= 'logo_light_sm = \'' . $_POST['panel_light_logo_small'] . '\', ';
	$sql .= 'logo_dark_sm = \'' . $_POST['panel_dark_logo_small'] . '\', ';
	$sql .= 'login_gif = \'' . $_POST['panel_login_gif'] . '\';';
	$sqlite3->exec($sql);
	header('location: profile_edit.php');
}

echo '<!doctype html>' . "\r\n" . '<html lang="en">' . "\r\n\r\n" . '<head>' . "\r\n\r\n" . '    ';
include 'assets/includes/title-meta.php';
echo "\r\n" . '    ';
include 'assets/includes/head-css.php';
echo "\r\n" . '</head>' . "\r\n\r\n" . '<body data-sidebar="dark">' . "\r\n\r\n" . '    <!-- Loader -->' . "\r\n" . '    <div id="preloader">' . "\r\n" . '        <div id="status">' . "\r\n" . '            <div class="spinner">' . "\r\n" . '                <i class="ri-loader-line spin-icon"></i>' . "\r\n" . '            </div>' . "\r\n" . '        </div>' . "\r\n" . '    </div>' . "\r\n\r\n" . '    <div id="layout-wrapper">' . "\r\n\r\n" . '        ';
include 'assets/includes/topbar.php';
echo "\r\n" . '        ';
include 'assets/includes/sidebar.php';
echo "\r\n" . '        <div class="main-content">' . "\r\n\r\n" . '            <div class="page-content">' . "\r\n" . '                <div class="container-fluid">' . "\r\n\r\n" . '                    <div class="row">' . "\r\n" . '                        <div class="col-12">' . "\r\n" . '                            <div class="page-title-box d-flex align-items-center justify-content-between">' . "\r\n" . '                                <h4 class="mb-0">Multipurpose Panel</h4>' . "\r\n\r\n" . '                                <div class="page-title-right">' . "\r\n" . '                                    <ol class="breadcrumb m-0">' . "\r\n" . '                                        <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>' . "\r\n" . '                                        <li class="breadcrumb-item active">Profile Edit</li>' . "\r\n" . '                                    </ol>' . "\r\n" . '                                </div>' . "\r\n\r\n" . '                            </div>' . "\r\n" . '                        </div>' . "\r\n" . '                    </div>' . "\r\n\r\n" . '                    <div class="row">' . "\r\n" . '                        <div class="col-xl-6">' . "\r\n" . '                            <div class="card h-100">' . "\r\n" . '                                <div class="card-body">' . "\r\n\r\n" . '                                    <h4 class="card-title">Profile Edit</h4>' . "\r\n" . '                                    <p class="card-title-desc">Update your profile information.</p>' . "\r\n\r\n" . '                                    <form method="POST">' . "\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="profile_first_name">Profile' . "\r\n" . '                                                Name</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input type="text" id="profile_first_name" name="profile_first_name" class="form-control" placeholder="Enter first name" value="';
echo $profile_data['profile_name'];
echo '">' . "\r\n" . '                                                <span class="text-muted">profile name displayed on menu</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="profile_user_name">Username</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input type="text" id="profile_user_name" name="profile_user_name" class="form-control" placeholder="Enter username" value="';
echo $profile_data['username'];
echo '">' . "\r\n" . '                                                <span class="text-muted">username to login to panel</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="profile_password">Password</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input type="password" id="profile_password" name="profile_password" class="form-control" placeholder="Enter password" value="';
echo $profile_data['password'];
echo '">' . "\r\n" . '                                                <span class="text-muted">password to login to panel</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="profile_avatar_url">Avatar' . "\r\n" . '                                                Image</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input type="url" id="profile_avatar_url" name="profile_avatar_url" class="form-control" placeholder="Enter avatar url" value="';
echo $profile_data['avatar_url'];
echo '">' . "\r\n" . '                                                <span class="text-muted">.jpg 128x128</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n" . '                                        <div class="text-center mt-4">' . "\r\n" . '                                            Remember to keep your username and password safe,<br>' . "\r\n" . '                                            The default username and password is <u>admin</u> & <u>admin</u>' . "\r\n" . '                                            if you need help contact your reseller.' . "\r\n" . '                                        </div>' . "\r\n" . '                                        <div class="text-center mt-4">' . "\r\n" . '                                            <button class="btn btn-primary waves-effect waves-light" type="submit" name="save_profile">Save Profile</button>' . "\r\n" . '                                        </div>' . "\r\n" . '                                    </form>' . "\r\n" . '                                </div>' . "\r\n" . '                            </div>' . "\r\n" . '                        </div> <!-- end col -->' . "\r\n\r\n" . '                        <div class="col-xl-6">' . "\r\n" . '                            <div class="card h-100">' . "\r\n" . '                                <div class="card-body">' . "\r\n\r\n" . '                                    <h4 class="card-title">Panel Edit</h4>' . "\r\n" . '                                    <p class="card-title-desc">Update your panel information.</p>' . "\r\n\r\n" . '                                    <form method="POST">' . "\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="panel_title">Panel Title</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input ';
echo $USER_PROFILE_PANEL_EDITS ? '' : 'disabled';
echo ' type="text" id="panel_title" name="panel_title" class="form-control" placeholder="Enter panel title" value="';
echo $panel_data['title'];
echo '">' . "\r\n" . '                                                <span class="text-muted">Title of Panel</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="panel_light_logo">Panel Logo' . "\r\n" . '                                                Light</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input ';
echo $USER_PROFILE_PANEL_EDITS ? '' : 'disabled';
echo ' type="url" id="panel_light_logo" name="panel_light_logo" class="form-control" placeholder="Enter panel logo light url" value="';
echo $panel_data['logo_light'];
echo '">' . "\r\n" . '                                                <span class="text-muted">.png 221x45</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="panel_dark_logo">Panel Logo' . "\r\n" . '                                                Dark</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input ';
echo $USER_PROFILE_PANEL_EDITS ? '' : 'disabled';
echo ' type="url" id="panel_dark_logo" name="panel_dark_logo" class="form-control" placeholder="Enter panel logo dark url" value="';
echo $panel_data['logo_dark'];
echo '">' . "\r\n" . '                                                <span class=" text-muted">.png 221x45</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="panel_light_logo_small">Panel' . "\r\n" . '                                                Logo Light (Small)</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input ';
echo $USER_PROFILE_PANEL_EDITS ? '' : 'disabled';
echo ' type="url" id="panel_light_logo_small" name="panel_light_logo_small" class="form-control" placeholder="Enter panel logo light small url" value="';
echo $panel_data['logo_light_sm'];
echo '">' . "\r\n" . '                                                <span class=" text-muted">.png 36x40</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="panel_dark_logo_small">Panel' . "\r\n" . '                                                Logo Dark (Small)</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input ';
echo $USER_PROFILE_PANEL_EDITS ? '' : 'disabled';
echo ' type="url" id="panel_dark_logo_small" name="panel_dark_logo_small" class="form-control" placeholder="Enter panel logo dark small url" value="';
echo $panel_data['logo_dark_sm'];
echo '">' . "\r\n" . '                                                <span class=" text-muted">.png 36x40</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n\r\n" . '                                        <div class="form-group row">' . "\r\n" . '                                            <label class="col-md-3 col-form-label" for="panel_login_gif">Panel Login' . "\r\n" . '                                                GIF</label>' . "\r\n" . '                                            <div class="col-md-9">' . "\r\n" . '                                                <input ';
echo $USER_PROFILE_PANEL_EDITS ? '' : 'disabled';
echo ' type="url" id="panel_login_gif" name="panel_login_gif" class="form-control" placeholder="Enter panel login gif url" value="';
echo $panel_data['login_gif'];
echo '">' . "\r\n" . '                                                <span class=" text-muted">.gif 2000x1333</span>' . "\r\n" . '                                            </div>' . "\r\n" . '                                        </div>' . "\r\n\r\n" . '                                        <div class="text-center mt-4">' . "\r\n" . '                                            <button class="btn btn-primary waves-effect waves-light" type="submit" name="save_panel">Save Panel</button>' . "\r\n" . '                                        </div>' . "\r\n" . '                                    </form>' . "\r\n" . '                                </div>' . "\r\n" . '                            </div>' . "\r\n" . '                        </div>' . "\r\n" . '                    </div>' . "\r\n" . '                </div>' . "\r\n" . '            </div>' . "\r\n\r\n" . '            ';
include 'assets/includes/footer.php';
echo "\r\n" . '        </div>' . "\r\n\r\n" . '    </div>' . "\r\n\r\n" . '    ';
include 'assets/includes/right-sidebar.php';
echo "\r\n" . '    ';
include 'assets/includes/vendor-scripts.php';
echo "\r\n" . '    <script src="./assets/js/app.js"></script>' . "\r\n\r\n" . '</body>' . "\r\n\r\n" . '</html>';

?>