- <?php
- require_once "db_config.php";
- $connection = @new mysqli($host, $db_user, $db_password, $db_name);
- if($connection->connect_errno!=0)
- {
- echo "DB-Error: " . $connection->connect_errno;
- }
- function showError($string)
- {
- echo "
- <div class=\"alert alert-danger\" role=\"alert\" style=\"width: 40%; margin-top: 5px; margin-left: 5px;\">
- $string
- </div>
- ";
- }
- function showInfo($string)
- {
- echo "
- <div class=\"alert alert-success\" role=\"alert\" style=\"width: 40%; margin-top: 5px; margin-left: 5px;\">
- $string
- </div>
- ";
- }
- function listProducts()
- {
- if($result = @$connection->query("SELECT * FROM products"))
- {
- $count = $result->num_rows;
- if($count > 0)
- {
- echo "test";
- }
- }
- else
- {
- echo "Wystąpił błąd podczas wczytywania produktów!";
- }
- $connection->close();
- echo "products here";
- }
- function showRegister()
- {
- echo "
- <div class=\"card\" style=\"margin-top: 13px; margin-left: 15px;\">
- <h4 class=\"card-title mb-4 mt-1\">Panel rejestracji</h4>
- <form action=\"register.php\" method=\"post\">
- <div class=\"form-group\" style=\"width: 20%;\">
- <label>Nazwa użytkownika</label>
- <input name=\"login\" class=\"form-control\" placeholder=\"Login\">
- </div>
- <div class=\"form-group\" style=\"width: 20%;\">
- <label>Hasło</label>
- <input name=\"password\" class=\"form-control\" placeholder=\"******\" type=\"password\">
- </div>
- <div class=\"form-group\" style=\"width: 20%;\">
- <label>Wpisz ponownie hasło</label>
- <input name=\"repeatpassword\" class=\"form-control\" placeholder=\"******\" type=\"password\">
- </div>
- Tutaj recaptcha
- <div class=\"form-group\">
- <button type=\"submit\" class=\"btn btn-success btn-block\" style=\"width: 20%;\">Zarejestruj się</button>
- </div>
- </form>
- </div>
- ";
- }
- function showLogin()
- {
- echo "
- <div class=\"card\" style=\"margin-top: 13px; margin-left: 15px;\">
- <h4 class=\"card-title mb-4 mt-1\">Panel logowania</h4>
- <form action=\"login.php\" method=\"post\">
- <div class=\"form-group\" style=\"width: 20%;\">
- <label>Nazwa użytkownika</label>
- <input name=\"login\" class=\"form-control\" placeholder=\"Login\">
- </div>
- <div class=\"form-group\" style=\"width: 20%;\">
- <label>Twoje hasło</label>
- <input name=\"password\" class=\"form-control\" placeholder=\"******\" type=\"password\">
- </div>
- <div class=\"form-group\">
- <button type=\"submit\" class=\"btn btn-primary btn-block\" style=\"width: 20%;\">Zaloguj się</button>
- </div>
- </form>
- </div>
- ";
- }
- if(isset($_SESSION['error']))
- {
- showError($_SESSION['error']);
- showLogin();
- unset($_SESSION['error']);
- exit();
- }
- if(isset($_SESSION['info']))
- {
- showInfo($_SESSION['info']);
- unset($_SESSION['info']);
- }
- if ((isset($_SESSION['user_logged'])) && ($_SESSION['user_logged']==true))
- {
- if($result = @$connection->query("SELECT * FROM products"))
- {
- $count = $result->num_rows;
- if($count > 0)
- {
- for($i = 0; $i < $count; $i++)
- {
- echo "e";
- }
- echo "poand 0";
- }
- else
- {
- showError("Nie znaleziono żadnych produktów w bazie danych.");
- }
- }
- else
- {
- echo "Wystąpił błąd podczas wczytywania produktów!";
- }
- }
- if(isset($_GET['do']))
- {
- if($_GET['do'] == "login")
- {
- showLogin();
- }
- elseif($_GET['do'] == "register")
- {
- showRegister();
- }
- elseif($_GET['do'] == "logout" && isset($_SESSION['user_logged']))
- {
- if($_SESSION['user_logged']==true)
- {
- session_unset();
- $_SESSION['user_logged'] = false;
- header('Location: index.php');
- }
- }
- else
- {
- showError("Nie możesz wyświetlić produktów bez zalogowania.");
- }
- }
- else
- {
- if($_SESSION['user_logged']==false)
- {
- showError("Nie możesz wyświetlić produktów bez zalogowania.");
- showLogin();
- }
- }
- $connection->close();
- ?>