· 8 years ago · Jun 06, 2018, 10:18 PM
1<?php
2
3 session_start();
4
5 if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])))
6 {
7 header('Location: ../index.php');
8 exit();
9 }
10
11 require("polacz.php");
12
13 $login = $_POST['login'];
14 $haslo = $_POST['haslo'];
15
16 $login = htmlentities($login, ENT_QUOTES, "UTF-8");
17
18 if ($rezultat = @$connection->query(
19 sprintf("SELECT * FROM users WHERE login='%s'",
20 mysqli_real_escape_string($connection,$login))))
21 {
22 $ilu_userow = $rezultat->num_rows;
23 if($ilu_userow>0)
24 {
25 $row = $rezultat->fetch_assoc();
26
27 if (password_verify($haslo, $row['haslo']))
28 {
29 $_SESSION['zalogowany'] = true;
30 $_SESSION['login'] = $row['login'];
31 $_SESSION['uprawnienia'] = $row['uprawnienia'];
32 unset($_SESSION['blad']);
33 $rezultat->free_result();
34 header('Location: ../php2/index2.php');
35 }
36 else
37 {
38 $_SESSION['blad'] = 'Zły login lub hasło!';
39 echo $_POST['haslo'];
40 header('Location: ../index.php');
41 }
42
43 } else {
44
45 $_SESSION['blad'] = 'Zły login lub hasło!';
46 header('Location: ../index.php');
47 }
48
49 }
50
51 $connection->close();
52
53?>
54
55
56SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
57SET AUTOCOMMIT = 0;
58START TRANSACTION;
59SET time_zone = "+00:00";
60
61
62CREATE DATABASE IF NOT EXISTS `Wynajem` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
63USE `Wynajem`;
64
65
66
67CREATE TABLE `klient` (
68 `Id_Klienta` int(11) NOT NULL,
69 `NazwaKlienta` text NOT NULL
70) ENGINE=InnoDB DEFAULT CHARSET=utf8;
71
72
73
74INSERT INTO `klient` (`Id_Klienta`, `NazwaKlienta`) VALUES
75(1, 'admin'),
76(2, 'user');
77
78
79
80CREATE TABLE `samochod` (
81 `Id` int(11) NOT NULL,
82 `Model` text COLLATE utf8_polish_ci NOT NULL,
83 `Marka` text COLLATE utf8_polish_ci NOT NULL,
84 `Cena` float NOT NULL,
85 `data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
86) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
87
88
89INSERT INTO `samochod` (`Id`, `Model`, `Marka`, `Cena`, `data`) VALUES
90(1, 'a1', 'audi', 1250.99, '2018-06-07 08:29:57'),
91(2, 'a2', 'audi', 2250.99, '2018-06-07 08:30:27'),
92(3, 'a3', 'audi', 3250.99, '2018-06-07 08:31:37'),
93(4, 'a4', 'audi', 4250.99, '2018-06-07 08:31:47'),
94(5, 'a5', 'audi', 5250.99, '2018-06-07 08:31:59'),
95(6, 'a6', 'audi', 6250.99, '2018-06-07 08:32:04'),
96(7, 'a7', 'audi', 7250.99, '2018-06-07 08:32:16'),
97(8, 'a8', 'audi', 8250.99, '2018-06-07 08:32:29'),
98(9,'a9', 'audi', 9250.99, '2018-06-07 08:32:43'),
99(10, 'a10', 'audi', 1250.99, '2018-06-07 08:32:54');
100
101
102
103CREATE TABLE `users` (
104 `user_id` int(11) NOT NULL,
105 `login` text NOT NULL,
106 `email` text NOT NULL,
107 `haslo` text NOT NULL,
108 `uprawnienia` text NOT NULL
109) ENGINE=InnoDB DEFAULT CHARSET=utf8;
110
111
112
113INSERT INTO `users` (`user_id`, `login`, `email`, `haslo`, `uprawnienia`) VALUES
114(0, 'admin', 'admin@interia.pl', '$2y$10$zzVLOlNOTyfoZBoGoHKdiOVGYr8qly3ga8CgE9YXPwWFmfmd0.nQ6', 'kierownik'),
115(4, 'pracownik', 'pracownik@interia.pl', '$2y$10$yF0ITtf9lLKbu0F.JY6PTOrBORfYNKCJwG0TNxvbLFNwW7q5K8THa', 'pracownik'),
116(5, 'Kierownik', 'kierownik@interia.pl', '$2y$10$TwdfSlN1munSqzggmJpcp.zy1h/7mZQIWrESBIKOKdsTtOqvivrxm', 'kierownik');
117
118
119ALTER TABLE `samochod`
120 ADD PRIMARY KEY (`Id`);
121
122
123ALTER TABLE `users`
124 ADD PRIMARY KEY (`user_id`);
125
126ALTER TABLE `klient`
127 ADD PRIMARY KEY (`Id_Klienta`);
128
129
130
131ALTER TABLE `klient`
132 MODIFY `Id_Klienta` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
133
134
135ALTER TABLE `samochod`
136 MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
137
138
139ALTER TABLE `users`
140 MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
141COMMIT;
142
143<?php
144
145 session_start();
146
147 if ((isset($_SESSION['zalogowany'])) && ($_SESSION['zalogowany']==true))
148 {
149 header('Location: index2.php');
150 exit();
151 }
152
153 if (isset($_POST['email']))
154 {
155 $walidacja=true;
156
157 $login = $_POST['login'];
158
159 if ((strlen($login)<3) || (strlen($login)>20))
160 {
161 $walidacja=false;
162 $_SESSION['e_login']="login od 3 do 20 znaków!";
163 }
164
165
166
167 $email = $_POST['email'];
168
169
170 $haslo1 = $_POST['haslo1'];
171 $haslo2 = $_POST['haslo2'];
172
173 if ((strlen($haslo1)<8) || (strlen($haslo1)>20))
174 {
175 $walidacja=false;
176 $_SESSION['e_haslo']="Hasło od 8 do 20 znaków!";
177 }
178
179 if ($haslo1!=$haslo2)
180 {
181 $walidacja=false;
182 $_SESSION['e_haslo']="Podane hasła nie identyczne!";
183 }
184
185 $haslo_hash = password_hash($haslo1, PASSWORD_DEFAULT);
186
187 if (!isset($_POST['regulamin']))
188 {
189 $walidacja=false;
190 $_SESSION['e_regulamin']="Potwierdź regulamin!";
191 }
192
193
194
195
196 require_once "php/polacz.php";
197 mysqli_report(MYSQLI_REPORT_STRICT);
198
199 try
200 {
201 if ($connection->connect_errno!=0)
202 {
203 throw new Exception(mysqli_connect_errno());
204 }
205 else
206 {
207 $result = $connection->query("SELECT user_id FROM users WHERE email='$email'");
208
209 if (!$result) throw new Exception($connection->error);
210
211 $mails_number = $result->num_rows;
212 if($mails_number>0)
213 {
214 $walidacja=false;
215 $_SESSION['e_email']="Istnieje już konto przypisane do tego adresu e-mail!";
216 }
217
218 $result = $connection->query("SELECT user_id FROM users WHERE login='$login'");
219
220 if (!$result) throw new Exception($connection->error);
221
222 $ile_takich_loginow = $result->num_rows;
223 if($ile_takich_loginow>0)
224 {
225 $walidacja=false;
226 $_SESSION['e_login']="Istnieje już gracz o takim loginu! Wybierz inny.";
227 }
228
229 if ($walidacja==true)
230 {
231
232 if ($connection->query("INSERT INTO users (login, haslo, email ) VALUES ('$login', '$haslo_hash', '$email')"))
233 {
234 $_SESSION['udanarejestracja']=true;
235 header('Location: index.php');
236 }
237 else
238 {
239 throw new Exception($connection->error);
240 }
241
242 }
243
244 $connection->close();
245 }
246
247 }
248 catch(Exception $e)
249 {
250 echo '<span style="color:red;">Błąd!</span>';
251 }
252
253 }
254
255
256?>
257
258<!DOCTYPE html>
259<html lang="en">
260
261<head>
262 <meta charset="utf-8">
263 <meta http-equiv="X-UA-Compatible" content="IE=edge">
264 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
265 <title>Wypożyczyalnia</title>
266 <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
267 <link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
268 <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
269</head>
270
271<body class="bg-dark">
272 <div class="container">
273 <div class="card card-register mx-auto mt-7">
274 <div class="card-header">Zarejestruj nowe konto</div>
275 <div class="card-body">
276
277
278 <form method="post">
279 <div class="form-group">
280 <label>Login</label>
281 <input class="form-control" type="text" placeholder="Podaj login" name="login" / >
282
283
284 </div>
285
286 <div class="form-group">
287 <label>Email</label>
288 <input class="form-control" type="email" placeholder="Podaj email" name="email">
289 </div>
290
291
292 <div class="form-group">
293 <div class="form-row">
294
295 <div class="col-md-4">
296 <label>Hasło</label>
297 <input class="form-control" type="password" placeholder="Hasło" name="haslo1" />
298 </div>
299
300 <div class="col-md-6">
301 <label>Powtórz Hasło</label>
302 <input class="form-control" type="password" placeholder="Powtórz Hasło" name="haslo2" />
303
304 </div>
305 </div>
306 </div>
307
308 <div class="form-group">
309 <label>
310 <input type="checkbox" name="regulamin" />
311 AkceptujÄ™ regulamin
312 </label>
313
314 </div>
315
316 <div class="sub">
317 <input class="btn btn-primary btn-block" type="submit" value="Zarejestruj siÄ™" />
318 </div>
319 </form>
320
321
322 <div class="text-center">
323 <a class="d-block small mt-3" href="index.php">Jeśli posiadasz konto to przejdź do panelu logowania</a> <br />
324 </div>
325 </div>
326 </div>
327 </div>
328</body>
329
330</html>
331
332 <?php
333
334 //Potrzebne dane do połączenia z bazą danych
335 $servername = "localhost";
336 $username = "root";
337 $password = "";
338 $dbname = "Wynajem";
339
340 $connection = new mysqli($servername, $username, $password, $dbname);
341
342 if ($connection->connect_error) {
343 die("Connection failed: " . $connection->connect_error);
344 }
345 ?>
346
347 <?php
348
349 //Potrzebne dane do połączenia z bazą danych
350 $servername = "localhost";
351 $username = "root";
352 $password = "";
353 $dbname = "Wynajem";
354
355 $connection = new mysqli($servername, $username, $password, $dbname);
356
357 if ($connection->connect_error) {
358 die("Connection failed: " . $connection->connect_error);
359 }
360 ?>
361
362 <?php
363//----------------------------------
364 session_start();
365
366
367
368 require("polacz.php");
369
370 $queryShow = 'SELECT * FROM samochod';
371?>
372<!DOCTYPE html>
373<html lang="en">
374 <head>
375 <meta charset="utf-8">
376 <meta http-equiv="X-UA-Compatible" content="IE=edge">
377 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
378 <title>Wypożyczyalnia</title>
379 <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
380 <link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
381 </head>
382 <body class="fixed-nav sticky-footer bg-dark" id="page-top">
383
384 <a href="logout.php">
385 <i class="fas fa-sign-out-alt"></i> Logout</a>
386
387 <?php
388 if(isset($_SESSION['komunikat'])){
389 echo '<div class="alert alert-danger error" role="alert"><strong>Komunikat!</strong> '. $_SESSION['komunikat'] . '</div>';
390 unset($_SESSION['komunikat']);
391 }
392 ?>
393
394 <table width="100%" cellspacing="0" , bgcolor="white">
395 <thead>
396 <tr>
397 <th>Id Samochodu</th>
398 <th>Model</th>
399 <th>Marka</th>
400 <th>Cena</th>
401 <th>Data dodania</th>
402 <th>Usuń</th>
403 </tr>
404 </thead>
405
406 <tbody>
407
408 <?php
409 $result = $connection->query($queryShow);
410 while ($row=$result->fetch_assoc()) {
411 $id = $row['Id'];
412 $marka = $row['Marka'];
413 $model = $row['Model'];
414 $cena = $row['Cena'];
415 $time = strtotime($row["data"]);
416 $rok = date('Y', $time);
417 $miesiac = date('m', $time);
418 $dzien = date('d', $time);
419 echo "<tr><td>$id</td> <td>$marka</td> <td>$model</td> <td>$cena</td> <td>$rok/$miesiac/$dzien</td>";
420 if($_SESSION['uprawnienia'] == "kierownik"){
421 echo "<td><form action=\"php/funkcje.php\" method=\"post\"><button type=\"submit\" name=\"delete\"class=\"btn btn-danger btn-sm\" value=\"" . htmlspecialchars($id) . "\">DEL</button></form></td></tr>";}
422 else echo "</tr>";
423 }
424 ?>
425 </tbody>
426 </table>
427
428
429 <?php if($_SESSION['uprawnienia'] == "pracownik"){ ?>
430 <div class="container-fluid">
431 <h3>Dodaj</h3>
432 <form class="klasa" action="php/funkcje.php" method="POST">
433 <div class="form-row">
434 <div class="col">
435 <input type="text" class="form-control" placeholder="Id" name="IdSamochodu" required>
436 </div>
437 <div class="col">
438 <input type="text" class="form-control" placeholder="Model" name="ModelSamochodu" required>
439 </div>
440 <div class="col">
441 <input type="text" class="form-control" placeholder="Marka" name="MarkaSamochodu" required>
442 </div>
443 <div class="col">
444 <input type="number" step="any" min="0" class="form-control" placeholder="cena" name="cenaWynajmu" required>
445 </div>
446 <button type="submit" class="btn btn-primary" name="dodaj">OK</button>
447 </div>
448 </form>
449 </div>
450 <br /><br />
451 <?php } ?>
452
453 <?php if($_SESSION['uprawnienia'] == "kierownik"){ ?>
454 <div class="container-fluid">
455 <h3>Dodaj</h3>
456 <form class="klasa" action="php/funkcje.php" method="POST">
457 <div class="form-row">
458 <div class="col">
459 <input type="text" class="form-control" placeholder="Id" name="IdSamochodu" required>
460 </div>
461 <div class="col">
462 <input type="text" class="form-control" placeholder="Model" name="ModelSamochodu" required>
463 </div>
464 <div class="col">
465 <input type="text" class="form-control" placeholder="Marka" name="MarkaSamochodu" required>
466 </div>
467 <div class="col">
468 <input type="number" step="any" min="0" class="form-control" placeholder="cena" name="cenaWynajmu" required>
469 </div>
470 <button type="submit" class="btn btn-primary" name="dodaj">OK</button>
471 </div>
472 </form>
473 </div>
474 <br /><br />
475 <?php } ?>
476 <?php if($_SESSION['uprawnienia'] == "kierownik"){ ?>
477 <!-- Formularz aktualizujÄ…cy rekord w bazie -->
478 <div class="container-fluid">
479 <h3>Edytuj</h3>
480 <form class="klasa" action="php/funkcje.php" method="POST">
481 <div class="form-row">
482 <div class="col">
483 <input type="text" class="form-control" placeholder="Id" name="IdS" required>
484 </div>
485 <div class="col">
486 <input type="text" class="form-control" placeholder="Model" name="Model" required>
487 </div>
488 <div class="col">
489 <input type="text" class="form-control" placeholder="Marka" name="Marka" required>
490 </div>
491 <div class="col">
492 <input type="number" step="any" min="0" class="form-control" placeholder="cena" name="cena">
493 </div>
494 <button type="submit" class="btn btn-primary" name="update">OK</button>
495 </div>
496 </form>
497 </div>
498 <br /><br />
499 </div>
500 <?php } ?>
501
502
503
504 </div>
505 </body>
506</html>
507
508<?php
509//----------------------------------
510 session_start();
511 if ((isset($_SESSION['zalogowany'])) && ($_SESSION['zalogowany']==true))
512 {
513 header('Location: index2.php');
514 exit();
515 }
516 require("polacz.php");
517 $queryShow = 'SELECT * FROM samochod';
518?>
519<!DOCTYPE html>
520<html lang="en">
521 <head>
522 <meta charset="utf-8">
523 <meta http-equiv="X-UA-Compatible" content="IE=edge">
524 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
525 <title>Wypożyczyalnia</title>
526 <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
527 <link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
528
529 </head>
530 <body class="fixed-nav sticky-footer bg-dark" id="page-top">
531
532
533 <form action="zaloguj.php" method="post">
534 <div class="form-group">
535 <label for="exampleInputLogin" color="white">Login pracownik lub kierownik</label>
536 <input class="form-control" id="exampleInputLogin" type="text" aria-describedby="loginHelp" name="login" placeholder="Podaj login" required>
537 </div>
538 <div class="form-group">
539 <label for="exampleInputPassword1">Hasło Pracownik123 lub Kierownik123 odpowiednio</label>
540 <input class="form-control" id="exampleInputPassword1" type="password" name="haslo" placeholder="Hasło" required>
541 </div>
542 <button class="btn btn-primary btn-block" type="submit">Login</button>
543 </form>
544
545 <div class="text-center">
546 <a class="d-block small mt-3" href="register.php">Zarejestruj siÄ™</a>
547 </div>
548
549
550 <table width="100%" cellspacing="0" , bgcolor="white">
551 <thead>
552 <tr>
553 <th>Id Samochodu</th>
554 <th>Model</th>
555 <th>Marka</th>
556 <th>Cena</th>
557 <th>Data dodania</th>
558
559 </tr>
560 </thead>
561
562 <tbody>
563
564 <?php
565 $result = $connection->query($queryShow);
566 while ($row=$result->fetch_assoc()) {
567 $id = $row['Id'];
568 $marka = $row['Marka'];
569 $model = $row['Model'];
570 $cena = $row['Cena'];
571 $time = strtotime($row["data"]);
572 $rok = date('Y', $time);
573 $miesiac = date('m', $time);
574 $dzien = date('d', $time);
575 echo "<tr><td>$id</td> <td>$marka</td> <td>$model</td> <td>$cena</td> <td>$rok/$miesiac/$dzien</td>";
576 }
577 ?>
578 </tbody>
579 </table>
580
581 </div>
582 </body>
583</html>
584
585<?php
586 //----------------------------------
587 session_start();
588 require("polacz.php");
589 //----------------------------------
590
591
592
593 /* ### DODAJ DO BAZY DANYCH ### */
594 function Dodaj($connection) {
595
596 // Escape user inputs for security
597 $Id = mysqli_real_escape_string($connection, $_REQUEST['Id']);
598 $Model = mysqli_real_escape_string($connection, $_REQUEST['Model']);
599 $Marka = mysqli_real_escape_string($connection, $_REQUEST['Marka']);
600 $Cena = mysqli_real_escape_string($connection, $_REQUEST['Cena']);
601
602 $sql = "INSERT INTO samochod (Id, Model, Marka, Cena) VALUES ('$Id', '$Model', '$Marka', '$Cena')";
603
604 if(mysqli_query($connection, $sql) == True){
605 $_SESSION['komunikat'] = "Dodano.";
606 } else {
607 $_SESSION['komunikat'] = "Nie dodano.";
608 }
609
610 mysqli_close($connection);
611 }
612
613 function Usun($connection) {
614
615 // Escape user inputs for security
616 $Id = mysqli_real_escape_string($connection, $_REQUEST['delete']);
617
618 $sql = "DELETE FROM samochod WHERE Id=$Id";
619
620 if(mysqli_query($connection, $sql) == True){
621 $_SESSION['komunikat'] = "Usunięto wiersz";
622 } else {
623 $_SESSION['komunikat'] = "Niepowodzenie usuwania";
624 }
625
626 mysqli_close($connection);
627 }
628
629 function Edytuj($connection) {
630
631 $Id = mysqli_real_escape_string($connection, $_REQUEST['Id']);
632
633 $query = "SELECT * FROM samochod where Id=$Id";
634 $result = mysqli_query($connection, $query);
635 while ($row=$result->fetch_assoc()) {
636 $id = $row['Id'];
637 $Model = $row['Model'];
638 $Marka = $row['Marka'];
639 $Cena = $row['Cena'];
640 }
641
642 if(!empty($_REQUEST['Model'])) { $Model = mysqli_real_escape_string($connection, $_REQUEST['Model']); } else { $Model = mysqli_real_escape_string($connection, $Model); }
643 if(!empty($_REQUEST['Marka'])) { $Marka = mysqli_real_escape_string($connection, $_REQUEST['Marka']); } else { $Marka = mysqli_real_escape_string($connection, $Marka); }
644 if(!empty($_REQUEST['Cena'])) { $Cena = mysqli_real_escape_string($connection, $_REQUEST['Cena']); } else { $Cena = mysqli_real_escape_string($connection, $Cena); }
645
646 $sql = "UPDATE samochod SET Model='$Model', Marka='$Marka', Cena='$Cena' WHERE Id=$Id";
647
648 if(mysqli_query($connection, $sql) == True){
649 $_SESSION['komunikat'] = "Pomyślna aktualizacja wierszu";
650 } else {
651 $_SESSION['komunikat'] = "Nie zaktualizowano wiersza.";
652 }
653
654 mysqli_close($connection);
655 }
656
657
658
659
660 /* ### W ZALEŻNOŚCI OD KLIKNIĘTEGO BUTTONA WYKONAJ DANĄ FUNKCJE ### */
661 if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['dodaj'])) {
662 Dodaj($connection);
663 }
664 else if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['delete'])) {
665 Usun($connection);
666 }
667 else if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['update'])) {
668 Edytuj($connection);
669 }
670
671 header('Location: ../index2.php');
672?>
673
674
675
676------ DRUGIE
677
678<?php
679
680 session_start();
681
682 if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])))
683 {
684 header('Location: ../index.php');
685 exit();
686 }
687
688 require("polacz.php");
689
690 $login = $_POST['login'];
691 $haslo = $_POST['haslo'];
692
693 $login = htmlentities($login, ENT_QUOTES, "UTF-8");
694
695 if ($rezultat = @$connection->query(
696 sprintf("SELECT * FROM users WHERE login='%s'",
697 mysqli_real_escape_string($connection,$login))))
698 {
699 $ilu_userow = $rezultat->num_rows;
700 if($ilu_userow>0)
701 {
702 $row = $rezultat->fetch_assoc();
703
704 if (password_verify($haslo, $row['haslo']))
705 {
706 $_SESSION['zalogowany'] = true;
707 $_SESSION['login'] = $row['login'];
708 $_SESSION['uprawnienia'] = $row['uprawnienia'];
709 unset($_SESSION['blad']);
710 $rezultat->free_result();
711 header('Location: ../php3/index2.php');
712 }
713 else
714 {
715 $_SESSION['blad'] = 'Zły login lub hasło!';
716 echo $_POST['haslo'];
717 header('Location: ../index.php');
718 }
719
720 } else {
721
722 $_SESSION['blad'] = 'Zły login lub hasło!';
723 header('Location: ../index.php');
724 }
725
726 }
727
728 $connection->close();
729
730?>
731
732<?php
733
734 session_start();
735
736 if ((isset($_SESSION['zalogowany'])) && ($_SESSION['zalogowany']==true))
737 {
738 header('Location: index2.php');
739 exit();
740 }
741
742 if (isset($_POST['email']))
743 {
744 $walidacja=true;
745
746 $login = $_POST['login'];
747
748 if ((strlen($login)<3) || (strlen($login)>20))
749 {
750 $walidacja=false;
751 $_SESSION['e_login']="login od 3 do 20 znaków!";
752 }
753
754
755
756 $email = $_POST['email'];
757
758
759 $haslo1 = $_POST['haslo1'];
760 $haslo2 = $_POST['haslo2'];
761
762 if ((strlen($haslo1)<8) || (strlen($haslo1)>20))
763 {
764 $walidacja=false;
765 $_SESSION['e_haslo']="Hasło od 8 do 20 znaków!";
766 }
767
768 if ($haslo1!=$haslo2)
769 {
770 $walidacja=false;
771 $_SESSION['e_haslo']="Podane hasła nie identyczne!";
772 }
773
774 $haslo_hash = password_hash($haslo1, PASSWORD_DEFAULT);
775
776 if (!isset($_POST['regulamin']))
777 {
778 $walidacja=false;
779 $_SESSION['e_regulamin']="Potwierdź regulamin!";
780 }
781
782
783
784
785 require_once "php/polacz.php";
786 mysqli_report(MYSQLI_REPORT_STRICT);
787
788 try
789 {
790 if ($connection->connect_errno!=0)
791 {
792 throw new Exception(mysqli_connect_errno());
793 }
794 else
795 {
796 $result = $connection->query("SELECT user_id FROM users WHERE email='$email'");
797
798 if (!$result) throw new Exception($connection->error);
799
800 $mails_number = $result->num_rows;
801 if($mails_number>0)
802 {
803 $walidacja=false;
804 $_SESSION['e_email']="Istnieje już konto przypisane do tego adresu e-mail!";
805 }
806
807 $result = $connection->query("SELECT user_id FROM users WHERE login='$login'");
808
809 if (!$result) throw new Exception($connection->error);
810
811 $ile_takich_loginow = $result->num_rows;
812 if($ile_takich_loginow>0)
813 {
814 $walidacja=false;
815 $_SESSION['e_login']="Istnieje już gracz o takim loginu! Wybierz inny.";
816 }
817
818 if ($walidacja==true)
819 {
820
821 if ($connection->query("INSERT INTO users (login, haslo, email ) VALUES ('$login', '$haslo_hash', '$email')"))
822 {
823 $_SESSION['udanarejestracja']=true;
824 header('Location: index.php');
825 }
826 else
827 {
828 throw new Exception($connection->error);
829 }
830
831 }
832
833 $connection->close();
834 }
835
836 }
837 catch(Exception $e)
838 {
839 echo '<span style="color:red;">Błąd!</span>';
840 }
841
842 }
843
844
845?>
846
847<!DOCTYPE html>
848<html lang="en">
849
850<head>
851 <meta charset="utf-8">
852 <meta http-equiv="X-UA-Compatible" content="IE=edge">
853 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
854 <title>Wypożyczyalnia</title>
855 <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
856 <link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
857 <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
858</head>
859
860<body class="bg-dark">
861 <div class="container">
862 <div class="card card-register mx-auto mt-7">
863 <div class="card-header">Zarejestruj nowe konto</div>
864 <div class="card-body">
865
866
867 <form method="post">
868 <div class="form-group">
869 <label>Login</label>
870 <input class="form-control" type="text" placeholder="Podaj login" name="login" / >
871
872
873 </div>
874
875 <div class="form-group">
876 <label>Email</label>
877 <input class="form-control" type="email" placeholder="Podaj email" name="email">
878 </div>
879
880
881 <div class="form-group">
882 <div class="form-row">
883
884 <div class="col-md-4">
885 <label>Hasło</label>
886 <input class="form-control" type="password" placeholder="Hasło" name="haslo1" />
887 </div>
888
889 <div class="col-md-6">
890 <label>Powtórz Hasło</label>
891 <input class="form-control" type="password" placeholder="Powtórz Hasło" name="haslo2" />
892
893 </div>
894 </div>
895 </div>
896
897 <div class="form-group">
898 <label>
899 <input type="checkbox" name="regulamin" />
900 AkceptujÄ™ regulamin
901 </label>
902
903 </div>
904
905 <div class="sub">
906 <input class="btn btn-primary btn-block" type="submit" value="Zarejestruj siÄ™" />
907 </div>
908 </form>
909
910
911 <div class="text-center">
912 <a class="d-block small mt-3" href="index.php">Jeśli posiadasz konto to przejdź do panelu logowania</a> <br />
913 </div>
914 </div>
915 </div>
916 </div>
917</body>
918
919</html>
920
921
922 <?php
923
924 //Potrzebne dane do połączenia z bazą danych
925 $servername = "localhost";
926 $username = "root";
927 $password = "";
928 $dbname = "Magazyn";
929
930 $connection = new mysqli($servername, $username, $password, $dbname);
931
932 if ($connection->connect_error) {
933 die("Connection failed: " . $connection->connect_error);
934 }
935 ?>
936
937
938 <?php
939
940 session_start();
941
942 session_unset();
943
944 header('Location: ../php3/index.php');
945
946?>
947
948
949
950SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
951SET AUTOCOMMIT = 0;
952START TRANSACTION;
953SET time_zone = "+00:00";
954
955
956CREATE DATABASE IF NOT EXISTS `Magazyn` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
957USE `Magazyn`;
958
959
960
961CREATE TABLE `Faktury` (
962 `Id_Faktury` int(11) NOT NULL,
963 `NazwaFaktury` text NOT NULL
964) ENGINE=InnoDB DEFAULT CHARSET=utf8;
965
966
967
968INSERT INTO `Faktury` (`Id_Faktury`, `NazwaFaktury`) VALUES
969(1, 'admin'),
970(2, 'user');
971
972
973
974CREATE TABLE `Towar` (
975 `Id` int(11) NOT NULL,
976 `Nazwa` text COLLATE utf8_polish_ci NOT NULL,
977 `Marka` text COLLATE utf8_polish_ci NOT NULL,
978 `Cena` float NOT NULL,
979 `data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
980) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
981
982
983INSERT INTO `Towar` (`Id`, `Nazwa`, `Marka`, `Cena`, `data`) VALUES
984(1, 'drabina', 'marka1', 1250.99, '2018-06-07 08:29:57'),
985(2, 'szpachla', 'marka2', 2250.99, '2018-06-07 08:30:27'),
986(3, 'koparka', 'marka3', 3250.99, '2018-06-07 08:31:37'),
987(4, 'dzwig', 'marka4', 4250.99, '2018-06-07 08:31:47'),
988(5, 'tapeta', 'marka1', 5250.99, '2018-06-07 08:31:59'),
989(6, 'gwozdzie', 'marka1', 6250.99, '2018-06-07 08:32:04'),
990(7, 'mlotek', 'marka1', 7250.99, '2018-06-07 08:32:16'),
991(8, 'siekiera', 'marka1', 8250.99, '2018-06-07 08:32:29'),
992(9,'lopata', 'marka1', 9250.99, '2018-06-07 08:32:43'),
993(10, 'kilof', 'marka1', 1250.99, '2018-06-07 08:32:54');
994
995
996
997CREATE TABLE `users` (
998 `user_id` int(11) NOT NULL,
999 `login` text NOT NULL,
1000 `email` text NOT NULL,
1001 `haslo` text NOT NULL,
1002 `uprawnienia` text NOT NULL
1003) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1004
1005
1006
1007INSERT INTO `users` (`user_id`, `login`, `email`, `haslo`, `uprawnienia`) VALUES
1008(0, 'admin', 'admin@interia.pl', '$2y$10$zzVLOlNOTyfoZBoGoHKdiOVGYr8qly3ga8CgE9YXPwWFmfmd0.nQ6', 'kierownik'),
1009(4, 'pracownik', 'pracownik@interia.pl', '$2y$10$yF0ITtf9lLKbu0F.JY6PTOrBORfYNKCJwG0TNxvbLFNwW7q5K8THa', 'pracownik'),
1010(5, 'Kierownik', 'kierownik@interia.pl', '$2y$10$TwdfSlN1munSqzggmJpcp.zy1h/7mZQIWrESBIKOKdsTtOqvivrxm', 'kierownik');
1011
1012
1013ALTER TABLE `Towar`
1014 ADD PRIMARY KEY (`Id`);
1015
1016
1017ALTER TABLE `users`
1018 ADD PRIMARY KEY (`user_id`);
1019
1020ALTER TABLE `Faktury`
1021 ADD PRIMARY KEY (`Id_Faktury`);
1022
1023
1024
1025ALTER TABLE `Faktury`
1026 MODIFY `Id_Faktury` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
1027
1028
1029ALTER TABLE `Towar`
1030 MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
1031
1032
1033ALTER TABLE `users`
1034 MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
1035COMMIT;
1036
1037
1038<?php
1039//----------------------------------
1040 session_start();
1041
1042
1043
1044 require("polacz.php");
1045
1046 $queryShow = 'SELECT * FROM Towar';
1047?>
1048<!DOCTYPE html>
1049<html lang="en">
1050 <head>
1051 <meta charset="utf-8">
1052 <meta http-equiv="X-UA-Compatible" content="IE=edge">
1053 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
1054 <title>Wypożyczyalnia</title>
1055 <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
1056 <link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
1057 </head>
1058 <body class="fixed-nav sticky-footer bg-dark" id="page-top">
1059
1060 <a href="logout.php">
1061 <i class="fas fa-sign-out-alt"></i> Logout</a>
1062
1063 <?php
1064 if(isset($_SESSION['komunikat'])){
1065 echo '<div class="alert alert-danger error" role="alert"><strong>Komunikat!</strong> '. $_SESSION['komunikat'] . '</div>';
1066 unset($_SESSION['komunikat']);
1067 }
1068 ?>
1069
1070 <table width="100%" cellspacing="0" , bgcolor="white">
1071 <thead>
1072 <tr>
1073 <th>Id Towaru</th>
1074 <th>Nazwa</th>
1075 <th>Marka</th>
1076 <th>Cena</th>
1077 <th>Data dodania</th>
1078 <th>Usuń</th>
1079 </tr>
1080 </thead>
1081
1082 <tbody>
1083
1084 <?php
1085 $result = $connection->query($queryShow);
1086 while ($row=$result->fetch_assoc()) {
1087 $id = $row['Id'];
1088 $nazwa = $row['Nazwa'];
1089 $marka = $row['Marka'];
1090 $cena = $row['Cena'];
1091 $time = strtotime($row["data"]);
1092 $rok = date('Y', $time);
1093 $miesiac = date('m', $time);
1094 $dzien = date('d', $time);
1095 echo "<tr><td>$id</td> <td>$nazwa</td> <td>$marka</td> <td>$cena</td> <td>$rok/$miesiac/$dzien</td>";
1096 if($_SESSION['uprawnienia'] == "kierownik"){
1097 echo "<td><form action=\"php/funkcje.php\" method=\"post\"><button type=\"submit\" name=\"delete\"class=\"btn btn-danger btn-sm\" value=\"" . htmlspecialchars($id) . "\">DEL</button></form></td></tr>";}
1098 else echo "</tr>";
1099 }
1100 ?>
1101 </tbody>
1102 </table>
1103
1104
1105 <?php if($_SESSION['uprawnienia'] == "pracownik"){ ?>
1106 <div class="container-fluid">
1107 <h3>Dodaj</h3>
1108 <form class="klasa" action="php/funkcje.php" method="POST">
1109 <div class="form-row">
1110 <div class="col">
1111 <input type="text" class="form-control" placeholder="Id" name="Id" required>
1112 </div>
1113 <div class="col">
1114 <input type="text" class="form-control" placeholder="Nazwa" name="Nazwa" required>
1115 </div>
1116 <div class="col">
1117 <input type="text" class="form-control" placeholder="Marka" name="Marka" required>
1118 </div>
1119 <div class="col">
1120 <input type="number" step="any" min="0" class="form-control" placeholder="cena" name="Cena" required>
1121 </div>
1122 <button type="submit" class="btn btn-primary" name="dodaj">OK</button>
1123 </div>
1124 </form>
1125 </div>
1126 <br /><br />
1127 <?php } ?>
1128
1129 <?php if($_SESSION['uprawnienia'] == "kierownik"){ ?>
1130 <div class="container-fluid">
1131 <h3>Dodaj</h3>
1132 <form class="klasa" action="php/funkcje.php" method="POST">
1133 <div class="form-row">
1134 <div class="col">
1135 <input type="text" class="form-control" placeholder="Id" name="Id" required>
1136 </div>
1137 <div class="col">
1138 <input type="text" class="form-control" placeholder="Nazwa" name="Nazwa" required>
1139 </div>
1140 <div class="col">
1141 <input type="text" class="form-control" placeholder="Marka" name="Marka" required>
1142 </div>
1143 <div class="col">
1144 <input type="number" step="any" min="0" class="form-control" placeholder="cena" name="Cena" required>
1145 </div>
1146 <button type="submit" class="btn btn-primary" name="dodaj">OK</button>
1147 </div>
1148 </form>
1149 </div>
1150 <br /><br />
1151 <?php } ?>
1152 <?php if($_SESSION['uprawnienia'] == "kierownik"){ ?>
1153 <!-- Formularz aktualizujÄ…cy rekord w bazie -->
1154 <div class="container-fluid">
1155 <h3>Edytuj</h3>
1156 <form class="klasa" action="php/funkcje.php" method="POST">
1157 <div class="form-row">
1158 <div class="col">
1159 <input type="text" class="form-control" placeholder="Id" name="Id" required>
1160 </div>
1161 <div class="col">
1162 <input type="text" class="form-control" placeholder="Nazwa" name="Nazwa" required>
1163 </div>
1164 <div class="col">
1165 <input type="text" class="form-control" placeholder="Marka" name="Marka" required>
1166 </div>
1167 <div class="col">
1168 <input type="number" step="any" min="0" class="form-control" placeholder="cena" name="Cena" required>
1169 </div>
1170 <button type="submit" class="btn btn-primary" name="update">OK</button>
1171 </div>
1172 </form>
1173 </div>
1174 <br /><br />
1175 </div>
1176 <?php } ?>
1177
1178
1179
1180 </div>
1181 </body>
1182</html>
1183
1184<?php
1185//----------------------------------
1186 session_start();
1187 if ((isset($_SESSION['zalogowany'])) && ($_SESSION['zalogowany']==true))
1188 {
1189 header('Location: index2.php');
1190 exit();
1191 }
1192 require("polacz.php");
1193 $queryShow = 'SELECT * FROM Towar';
1194?>
1195<!DOCTYPE html>
1196<html lang="en">
1197 <head>
1198 <meta charset="utf-8">
1199 <meta http-equiv="X-UA-Compatible" content="IE=edge">
1200 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
1201 <title>Wypożyczyalnia</title>
1202 <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
1203 <link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
1204
1205 </head>
1206 <body class="fixed-nav sticky-footer bg-dark" id="page-top">
1207
1208
1209 <form action="zaloguj.php" method="post">
1210 <div class="form-group">
1211 <label for="exampleInputLogin" color="white">Login pracownik lub kierownik</label>
1212 <input class="form-control" id="exampleInputLogin" type="text" aria-describedby="loginHelp" name="login" placeholder="Podaj login" required>
1213 </div>
1214 <div class="form-group">
1215 <label for="exampleInputPassword1">Hasło Pracownik123 lub Kierownik123 odpowiednio</label>
1216 <input class="form-control" id="exampleInputPassword1" type="password" name="haslo" placeholder="Hasło" required>
1217 </div>
1218 <button class="btn btn-primary btn-block" type="submit">Login</button>
1219 </form>
1220
1221 <div class="text-center">
1222 <a class="d-block small mt-3" href="register.php">Zarejestruj siÄ™</a>
1223 </div>
1224
1225
1226 <table width="100%" cellspacing="0" , bgcolor="white">
1227 <thead>
1228 <tr>
1229 <th>Id Towaru</th>
1230 <th>Nazwa</th>
1231 <th>Marka</th>
1232 <th>Cena</th>
1233 <th>Data dodania</th>
1234
1235 </tr>
1236 </thead>
1237
1238 <tbody>
1239
1240 <?php
1241 $result = $connection->query($queryShow);
1242 while ($row=$result->fetch_assoc()) {
1243 $id = $row['Id'];
1244 $nazwa = $row['Nazwa'];
1245 $marka = $row['Marka'];
1246 $cena = $row['Cena'];
1247 $time = strtotime($row["data"]);
1248 $rok = date('Y', $time);
1249 $miesiac = date('m', $time);
1250 $dzien = date('d', $time);
1251 echo "<tr><td>$id</td> <td>$nazwa</td> <td>$marka</td> <td>$cena</td> <td>$rok/$miesiac/$dzien</td>";
1252 }
1253 ?>
1254 </tbody>
1255 </table>
1256
1257 </div>
1258 </body>
1259</html>
1260
1261<?php
1262 //----------------------------------
1263 session_start();
1264 require("polacz.php");
1265 //----------------------------------
1266
1267
1268
1269 /* ### DODAJ DO BAZY DANYCH ### */
1270 function Dodaj($connection) {
1271
1272 // Escape user inputs for security
1273 $Id = mysqli_real_escape_string($connection, $_REQUEST['Id']);
1274 $Nazwa = mysqli_real_escape_string($connection, $_REQUEST['Nazwa']);
1275 $Marka = mysqli_real_escape_string($connection, $_REQUEST['Marka']);
1276 $Cena = mysqli_real_escape_string($connection, $_REQUEST['Cena']);
1277
1278 $sql = "INSERT INTO towar (Id, Nazwa, Marka, Cena) VALUES ('$Id', '$Nazwa', '$Marka', '$Cena')";
1279
1280 if(mysqli_query($connection, $sql) == True){
1281 $_SESSION['komunikat'] = "Dodano.";
1282 } else {
1283 $_SESSION['komunikat'] = "Nie dodano.";
1284 }
1285
1286 mysqli_close($connection);
1287 }
1288
1289 function Usun($connection) {
1290
1291 // Escape user inputs for security
1292 $Id = mysqli_real_escape_string($connection, $_REQUEST['delete']);
1293
1294 $sql = "DELETE FROM towar WHERE Id=$Id";
1295
1296 if(mysqli_query($connection, $sql) == True){
1297 $_SESSION['komunikat'] = "Usunięto wiersz";
1298 } else {
1299 $_SESSION['komunikat'] = "Niepowodzenie usuwania";
1300 }
1301
1302 mysqli_close($connection);
1303 }
1304
1305 function Edytuj($connection) {
1306
1307 $Id = mysqli_real_escape_string($connection, $_REQUEST['Id']);
1308
1309 $query = "SELECT * FROM towar where Id=$Id";
1310 $result = mysqli_query($connection, $query);
1311 while ($row=$result->fetch_assoc()) {
1312 $id = $row['Id'];
1313 $Nazwa = $row['Nazwa'];
1314 $Marka = $row['Marka'];
1315 $Cena = $row['Cena'];
1316 }
1317
1318 if(!empty($_REQUEST['Nazwa'])) { $Nazwa = mysqli_real_escape_string($connection, $_REQUEST['Nazwa']); } else { $Nazwa = mysqli_real_escape_string($connection, $Nazwa); }
1319 if(!empty($_REQUEST['Marka'])) { $Marka = mysqli_real_escape_string($connection, $_REQUEST['Marka']); } else { $Marka = mysqli_real_escape_string($connection, $Marka); }
1320 if(!empty($_REQUEST['Cena'])) { $Cena = mysqli_real_escape_string($connection, $_REQUEST['Cena']); } else { $Cena = mysqli_real_escape_string($connection, $Cena); }
1321
1322 $sql = "UPDATE towar SET Nazwa='$Nazwa', Marka='$Marka', Cena='$Cena' WHERE Id=$Id";
1323
1324 if(mysqli_query($connection, $sql) == True){
1325 $_SESSION['komunikat'] = "Pomyślna aktualizacja wierszu";
1326 } else {
1327 $_SESSION['komunikat'] = "Nie zaktualizowano wiersza.";
1328 }
1329
1330 mysqli_close($connection);
1331 }
1332
1333
1334
1335
1336 /* ### W ZALEŻNOŚCI OD KLIKNIĘTEGO BUTTONA WYKONAJ DANĄ FUNKCJE ### */
1337 if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['dodaj'])) {
1338 Dodaj($connection);
1339 }
1340 else if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['delete'])) {
1341 Usun($connection);
1342 }
1343 else if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['update'])) {
1344 Edytuj($connection);
1345 }
1346
1347 header('Location: ../index2.php');
1348?>
1349
1350 <?php
1351
1352 //Potrzebne dane do połączenia z bazą danych
1353 $servername = "localhost";
1354 $username = "root";
1355 $password = "";
1356 $dbname = "Magazyn";
1357
1358 $connection = new mysqli($servername, $username, $password, $dbname);
1359
1360 if ($connection->connect_error) {
1361 die("Connection failed: " . $connection->connect_error);
1362 }
1363 ?>