Facebook
From Gamboge Mousedeer, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 190
  1. <?php
  2.         require_once "db_config.php";
  3.  
  4.         $connection = @new mysqli($host, $db_user, $db_password, $db_name);
  5.        
  6.         if($connection->connect_errno!=0)
  7.         {
  8.                 echo "DB-Error: " . $connection->connect_errno;
  9.         }
  10.                
  11.         function showError($string)
  12.         {
  13.                 echo "
  14.                 <div class=\"alert alert-danger\" role=\"alert\" style=\"width: 40%; margin-top: 5px; margin-left: 5px;\">
  15.                         $string
  16.                 </div>
  17.                 ";
  18.         }
  19.        
  20.         function showInfo($string)
  21.         {
  22.                 echo "
  23.                 <div class=\"alert alert-success\" role=\"alert\" style=\"width: 40%; margin-top: 5px; margin-left: 5px;\">
  24.                         $string
  25.                 </div>
  26.                 ";
  27.         }
  28.        
  29.         function listProducts()
  30.         {
  31.                 if($result = @$connection->query("SELECT * FROM products"))
  32.                 {                      
  33.                         $count = $result->num_rows;
  34.                        
  35.                         if($count > 0)
  36.                         {
  37.                                 echo "test";
  38.                         }
  39.                 }
  40.                 else
  41.                 {
  42.                         echo "Wystąpił błąd podczas wczytywania produktów!";
  43.                 }
  44.  
  45.                 $connection->close();
  46.                
  47.                 echo "products here";
  48.         }
  49.        
  50.         function showRegister()
  51.         {
  52.                 echo "
  53.                 <div class=\"card\" style=\"margin-top: 13px; margin-left: 15px;\">
  54.                         <h4 class=\"card-title mb-4 mt-1\">Panel rejestracji</h4>
  55.                         <form action=\"register.php\" method=\"post\">
  56.                                 <div class=\"form-group\" style=\"width: 20%;\">
  57.                                         <label>Nazwa użytkownika</label>
  58.                                         <input name=\"login\" class=\"form-control\" placeholder=\"Login\">
  59.                                 </div>
  60.                                 <div class=\"form-group\" style=\"width: 20%;\">
  61.                                         <label>Hasło</label>
  62.                                         <input name=\"password\" class=\"form-control\" placeholder=\"******\" type=\"password\">
  63.                                 </div>
  64.                                 <div class=\"form-group\" style=\"width: 20%;\">
  65.                                         <label>Wpisz ponownie hasło</label>
  66.                                         <input name=\"repeatpassword\" class=\"form-control\" placeholder=\"******\" type=\"password\">
  67.                                 </div>
  68.                                 Tutaj recaptcha
  69.                                 <div class=\"form-group\">
  70.                                         <button type=\"submit\" class=\"btn btn-success btn-block\" style=\"width: 20%;\">Zarejestruj się</button>
  71.                                 </div>                                                        
  72.                         </form>
  73.                 </div>
  74.                 ";
  75.         }
  76.        
  77.         function showLogin()
  78.         {
  79.                 echo "
  80.                 <div class=\"card\" style=\"margin-top: 13px; margin-left: 15px;\">
  81.                         <h4 class=\"card-title mb-4 mt-1\">Panel logowania</h4>
  82.                         <form action=\"login.php\" method=\"post\">
  83.                                 <div class=\"form-group\" style=\"width: 20%;\">
  84.                                         <label>Nazwa użytkownika</label>
  85.                                         <input name=\"login\" class=\"form-control\" placeholder=\"Login\">
  86.                                 </div>
  87.                                 <div class=\"form-group\" style=\"width: 20%;\">
  88.                                         <label>Twoje hasło</label>
  89.                                         <input name=\"password\" class=\"form-control\" placeholder=\"******\" type=\"password\">
  90.                                 </div>
  91.                                 <div class=\"form-group\">
  92.                                         <button type=\"submit\" class=\"btn btn-primary btn-block\" style=\"width: 20%;\">Zaloguj się</button>
  93.                                 </div>                                                        
  94.                         </form>
  95.                 </div>
  96.                 ";
  97.         }
  98.        
  99.         if(isset($_SESSION['error']))
  100.         {
  101.                 showError($_SESSION['error']);
  102.                 showLogin();
  103.                 unset($_SESSION['error']);
  104.                 exit();
  105.         }
  106.        
  107.         if(isset($_SESSION['info']))
  108.         {
  109.                 showInfo($_SESSION['info']);
  110.                
  111.                 unset($_SESSION['info']);
  112.         }
  113.        
  114.         if ((isset($_SESSION['user_logged'])) && ($_SESSION['user_logged']==true))
  115.         {
  116.                 if($result = @$connection->query("SELECT * FROM products"))
  117.                 {
  118.                         $count = $result->num_rows;
  119.                        
  120.                         if($count > 0)
  121.                         {
  122.                                 for($i = 0; $i < $count; $i++)
  123.                                 {
  124.                                         echo "e";
  125.                                 }
  126.                                 echo "poand 0";
  127.                         }
  128.                         else
  129.                         {
  130.                                 showError("Nie znaleziono żadnych produktów w bazie danych.");
  131.                         }
  132.                 }
  133.                 else
  134.                 {
  135.                         echo "Wystąpił błąd podczas wczytywania produktów!";
  136.                 }
  137.         }
  138.        
  139.         if(isset($_GET['do']))
  140.         {
  141.                 if($_GET['do'] == "login")
  142.                 {
  143.                         showLogin();
  144.                 }
  145.                 elseif($_GET['do'] == "register")
  146.                 {
  147.                         showRegister();
  148.                 }
  149.                 elseif($_GET['do'] == "logout" && isset($_SESSION['user_logged']))
  150.                 {
  151.                         if($_SESSION['user_logged']==true)
  152.                         {
  153.                                 session_unset();
  154.                                 $_SESSION['user_logged'] = false;
  155.                                
  156.                                 header('Location: index.php');
  157.                         }
  158.                 }
  159.                 else
  160.                 {
  161.                         showError("Nie możesz wyświetlić produktów bez zalogowania.");
  162.                 }
  163.         }
  164.         else
  165.         {
  166.                 if($_SESSION['user_logged']==false)
  167.                 {
  168.                         showError("Nie możesz wyświetlić produktów bez zalogowania.");
  169.                         showLogin();
  170.                 }
  171.         }
  172.        
  173.         $connection->close();
  174. ?>