Visa Källkod

The following files exist in this folder. Click to view.

NamnTypStorlek
account.phpPHP Fil11.6 KB
admin.phpPHP Fil23.6 KB
authors.phpPHP Fil4.1 KB
book.phpPHP Fil5.9 KB
db_cnnt.phpPHP Fil407 B
header.phpPHP Fil1.7 KB
home.phpPHP Fil8.4 KB
index.phpPHP Fil5.3 KB
loan_handler.phpPHP Fil1.9 KB
manage_authors.phpPHP Fil4.7 KB
my_loans.phpPHP Fil6.9 KB
S.sqlSQL Fil3.3 KB
search.phpPHP Fil11 KB

index.php

133 lines UTF-8 Unix (LF) - Type: PHP Fil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php

session_start
();

// redirect om redan inloggad
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
    
header('Location: home.php');
    exit;
}
?>
<!DOCTYPE html>
<html lang="sv">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bibliotek Login</title>
    <link rel="stylesheet" href="style.css">
</head>
<body class="auth-page">
<div class="auth-container">
    <div class="auth-left">
        <div class="auth-branding">
            <h1>Biblioteket</h1>
            <p class="tagline">Din portal till kunskapen</p>
        </div>
    </div>
    
    <div class="auth-right">
        <?php
        
// success messages
        
if (isset($_GET['success']) && $_GET['success'] === 'deleted') {
            echo 
'<div class="notice error">Ditt konto har raderats.</div>';
        }
        if (isset(
$_GET['success']) && $_GET['success'] === 'registered') {
            echo 
'<div class="notice success">Konto skapat! Du kan logga in nu.</div>';
        }
        
// error msgs
        
if (isset($_GET['error'])): ?>
            <div class="notice error">
                <?php
                
if ($_GET['error'] === 'locked') {
                    echo 
"Kontot är låst på grund av för många misslyckade inloggningar. Kontakta admin.";
                } elseif (
$_GET['error'] === 'invalid') {
                    echo 
"Felaktigt användarnamn eller lösenord.";
                } elseif (
$_GET['error'] === 'exists') {
                    echo 
"Användarnamnet eller e-postadressen finns redan.";
                } elseif (
$_GET['error'] === 'email') {
                    echo 
"Ogiltig e-postadress.";
                } elseif (
$_GET['error'] === 'empty') {
                    echo 
"Fyll i alla fält.";
                } else {
                    echo 
"Ett fel uppstod. Försök igen.";
                }
                
?>
            </div>
        <?php endif;
        
// visa "ej behörighet" msg om URL har no-acces
        
if (isset($_GET['noaccess'])) {
            echo 
'<div class="notice warning">Du har inte behörighet att komma åt den sidan.</div>';
        }
        
?>
        
        <div class="auth-tabs">
            <button class="tab-btn active" data-tab="login">Logga in</button>
            <button class="tab-btn" data-tab="register">Registrera</button>
        </div>
        
        <div class="auth-forms">
            <!-- Login form -->
            <div class="tab-content active" id="login-tab">
                <form action="account.php" method="post">
                    <input type="hidden" name="action" value="login">
                    <h2>Välkommen tillbaka</h2>
                    <div class="input-group">
                        <label for="login-username">Användarnamn</label>
                        <input type="text" id="login-username" name="username" placeholder="Skriv ditt användarnamn" required>
                    </div>
                    <div class="input-group">
                        <label for="login-password">Lösenord</label>
                        <input type="password" id="login-password" name="password" placeholder="Skriv ditt lösenord" required>
                    </div>
                    <div class="form-footer">
                        <label class="checkbox-label">
                            <input type="checkbox" name="remember">
                            <span>Kom ihåg mig</span>
                        </label>
                    </div>
                    <button type="submit" class="auth-btn">Logga in</button>
                </form>
            </div>
            
            <!-- Registreringsformulär -->
            <div class="tab-content" id="register-tab">
                <form action="account.php" method="post">
                    <input type="hidden" name="action" value="register">
                    <h2>Skapa ditt konto</h2>
                    <div class="input-group">
                        <label for="reg-username">Användarnamn</label>
                        <input type="text" id="reg-username" name="username" placeholder="Välj ett användarnamn" required>
                    </div>
                    <div class="input-group">
                        <label for="reg-email">E-post</label>
                        <input type="email" id="reg-email" name="email" placeholder="din@email.se" required>
                    </div>
                    <div class="input-group">
                        <label for="reg-password">Lösenord</label>
                        <input type="password" id="reg-password" name="password" placeholder="Välj ett starkt lösenord" required>
                    </div>
                    <button type="submit" class="auth-btn">Skapa konto</button>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
document.querySelectorAll('.tab-btn').forEach(btn => {
    btn.addEventListener('click', () => {
        const tab = btn.dataset.tab;
        
        // Update buttons
        document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
        btn.classList.add('active');
        
        // Update content
        document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
        document.getElementById(tab + '-tab').classList.add('active');
    });
});
</script>
</body>
</html>