This repository was archived by the owner on Jun 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
249 lines (228 loc) · 14.1 KB
/
Copy pathindex.php
File metadata and controls
249 lines (228 loc) · 14.1 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
require_once 'app/config.php';
require_once 'app/functions.php';
$college = null;
$college_slug = trim($_GET['college'] ?? '', '/');
// ── Detect college from URL slug ─────────────────────────────────────────────
if ($college_slug) {
$stmt = $conn->prepare("SELECT * FROM colleges WHERE short_name = ? AND status = 'active'");
$stmt->execute([$college_slug]);
$college = $stmt->fetch();
if (!$college) {
header("Location: " . BASE_URL . "/404.php");
exit();
}
}
// ── Handle login POST ────────────────────────────────────────────────────────
$error = $error ?? null;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $college) {
$email = sanitize($_POST['email']);
$password = $_POST['password'];
$stmt = $conn->prepare("SELECT * FROM users WHERE email = ? AND college_id = ?");
$stmt->execute([$email, $college['id']]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
// Track last login for college
$conn->prepare("UPDATE colleges SET last_login = NOW() WHERE id = ?")->execute([$college['id']]);
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_name'] = $user['name'];
$_SESSION['user_role'] = $user['role'];
$_SESSION['college_id'] = $college['id'];
$_SESSION['college_slug'] = $college_slug;
$_SESSION['college_name'] = $college['name'];
$_SESSION['college_logo'] = $college['logo'];
header("Location: " . BASE_URL . "/$college_slug/" . strtolower($user['role']) . "/dashboard.php");
exit;
} else {
$error = "Invalid email or password.";
}
}
// ── If no slug provided, show landing page ───────────────────────────────────
if (!$college_slug) {
// Fetch only demo college for the directory listing, hide others like ABIT
$colleges = $conn->query("SELECT name, short_name FROM colleges WHERE status='active' AND short_name = 'demo' ORDER BY name")->fetchAll();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $college ? htmlspecialchars($college['name']) . ' - Login' : 'SAMS - Smart Academic Management' ?></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="<?= BASE_URL ?>/assets/css/style.css">
<style>
body { font-family: 'Inter', sans-serif; background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e40af 100%); min-height: 100vh; }
.saas-card { background: rgba(255,255,255,0.97); border-radius: 20px; box-shadow: 0 25px 50px rgba(0,0,0,0.3); }
.brand-logo { width: 60px; height: 60px; background: linear-gradient(135deg, #4f46e5, #0ea5e9); border-radius: 15px; display: flex; align-items: center; justify-content: center; }
.college-pill { transition: all .2s; border: 2px solid transparent; }
.college-pill:hover { border-color: #4f46e5; background: #f0f0ff; transform: translateY(-1px); }
.btn-signin { background: linear-gradient(135deg, #4f46e5, #0ea5e9); border: none; padding: 12px; border-radius: 10px; font-weight: 600; }
.form-control-lg { border-radius: 10px; border: 1.5px solid #e2e8f0; }
.form-control-lg:focus { border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,0.15); }
.divider { position: relative; text-align: center; margin: 1.5rem 0; }
.divider::before { content:''; position: absolute; top:50%; left:0; right:0; height:1px; background:#e2e8f0; }
.divider span { background:#fff; padding:0 1rem; position:relative; color:#94a3b8; font-size:.85rem; }
.hero-badge { display: inline-block; background: rgba(79,70,229,0.1); color: #4f46e5; border-radius: 50px; padding: 6px 16px; font-size: 0.8rem; font-weight: 600; margin-bottom: 1rem; }
</style>
</head>
<body class="d-flex align-items-center justify-content-center py-5">
<div class="container">
<?php if ($college): ?>
<!-- ── COLLEGE LOGIN PAGE ─────────────────────────────────────────── -->
<div class="row justify-content-center">
<div class="col-md-5">
<div class="text-center mb-4">
<a href="<?= BASE_URL ?>" class="text-white text-decoration-none">
<i class="bi bi-arrow-left me-1"></i> Back to SAMS Platform
</a>
</div>
<div class="saas-card p-5">
<div class="text-center mb-4">
<div class="brand-logo mx-auto mb-3 overflow-hidden">
<?php if(!empty($college['logo'])): ?>
<img src="<?= htmlspecialchars($college['logo']) ?>" alt="Logo" class="w-100 h-100 object-fit-contain p-1 bg-white">
<?php else: ?>
<i class="bi bi-mortarboard-fill text-white fs-3"></i>
<?php endif; ?>
</div>
<h4 class="fw-bold mb-0 text-dark"><?= htmlspecialchars($college['name']) ?></h4>
<small class="text-muted">SAMS Portal • <?= strtoupper($college['short_name']) ?></small>
</div>
<?php if ($error): ?>
<div class="alert alert-danger border-0 rounded-3" role="alert">
<i class="bi bi-exclamation-circle me-1"></i> <?= $error ?>
</div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label class="form-label fw-medium">Email Address</label>
<div class="input-group">
<span class="input-group-text bg-light border-end-0"><i class="bi bi-envelope text-muted"></i></span>
<input type="email" name="email" class="form-control form-control-lg border-start-0 ps-0" placeholder="you@institute.edu" required>
</div>
</div>
<div class="mb-4">
<label class="form-label fw-medium">Password</label>
<div class="input-group">
<span class="input-group-text bg-light border-end-0"><i class="bi bi-lock text-muted"></i></span>
<input type="password" name="password" class="form-control form-control-lg border-start-0 ps-0" placeholder="••••••••" required>
</div>
</div>
<button type="submit" class="btn btn-signin text-white w-100 fs-6">
<i class="bi bi-box-arrow-in-right me-1"></i> Sign In
</button>
</form>
<?php if ($college_slug === 'demo'): ?>
<div class="mt-4 p-3 bg-light rounded-3 border">
<h6 class="fw-bold mb-2 text-primary small"><i class="bi bi-info-circle me-1"></i> Demo Credentials</h6>
<div class="text-xs text-muted mb-2">Password for all: <code>demo123</code></div>
<div class="d-flex flex-column gap-1">
<div class="d-flex justify-content-between">
<span class="small text-dark">Admin:</span>
<code>admin@demo.com</code>
</div>
<div class="d-flex justify-content-between">
<span class="small text-dark">Teacher:</span>
<code>teacher@demo.com</code>
</div>
<div class="d-flex justify-content-between">
<span class="small text-dark">Student:</span>
<code>student@demo.com</code>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php else: ?>
<!-- ── LANDING PAGE ───────────────────────────────────────────────── -->
<div class="row justify-content-center">
<div class="col-lg-10">
<div class="row align-items-center g-4">
<!-- Hero Text -->
<div class="col-lg-5 text-white">
<div class="hero-badge"><i class="bi bi-lightning-charge-fill me-1"></i> SaaS Platform</div>
<h1 class="display-5 fw-bold mb-3 lh-sm">Smart Academic<br>Management System</h1>
<p class="text-white-50 fs-6 mb-4">A powerful, centralized platform for institutions — manage students, teachers, fees, attendance, and more from one place.</p>
<div class="d-flex gap-3 mb-4 flex-wrap">
<div class="d-flex align-items-center gap-2 text-white-50">
<i class="bi bi-check2-circle text-success fs-5"></i><small>Multi-College Ready</small>
</div>
<div class="d-flex align-items-center gap-2 text-white-50">
<i class="bi bi-check2-circle text-success fs-5"></i><small>Secure & Private</small>
</div>
<div class="d-flex align-items-center gap-2 text-white-50">
<i class="bi bi-check2-circle text-success fs-5"></i><small>Indian ₹ Localized</small>
</div>
</div>
<a href="<?= BASE_URL ?>/signup.php" class="btn btn-light fw-bold px-4 py-2 rounded-pill">
<i class="bi bi-plus-circle me-1"></i> Register Your Institution
</a>
</div>
<!-- Login / College Selector -->
<div class="col-lg-7">
<div class="saas-card p-4 p-md-5">
<div class="d-flex align-items-center gap-3 mb-4">
<div class="brand-logo">
<i class="bi bi-mortarboard-fill text-white fs-4"></i>
</div>
<div>
<h5 class="fw-bold mb-0">Access Your Portal</h5>
<small class="text-muted">Select your institution to continue</small>
</div>
</div>
<?php if (isset($error)): ?>
<div class="alert alert-danger border-0 rounded-3 mb-4" role="alert">
<i class="bi bi-exclamation-circle me-1"></i> <?= $error ?>
</div>
<?php endif; ?>
<?php if (!empty($colleges)): ?>
<div class="mb-4">
<?php foreach ($colleges as $col): ?>
<a href="<?= BASE_URL ?>/<?= $col['short_name'] ?>/" class="d-flex align-items-center justify-content-between college-pill rounded-3 p-3 mb-2 text-decoration-none text-dark">
<div class="d-flex align-items-center gap-3">
<div style="width:40px;height:40px;background:linear-gradient(135deg,#4f46e5,#0ea5e9);border-radius:10px;display:flex;align-items:center;justify-content:center;">
<span class="text-white fw-bold small"><?= strtoupper(substr($col['short_name'], 0, 2)) ?></span>
</div>
<div>
<div class="fw-semibold"><?= htmlspecialchars($col['name']) ?></div>
<small class="text-muted"><?= htmlspecialchars($col['short_name']) ?>.sams</small>
</div>
</div>
<i class="bi bi-arrow-right text-muted"></i>
</a>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="text-center text-muted py-3">
<i class="bi bi-building fs-1 text-secondary d-block mb-2"></i>
No institutions registered yet.
</div>
<?php endif; ?>
<div class="divider"><span>or enter your portal link</span></div>
<form class="d-flex gap-2" onsubmit="goToCollege(event)">
<input type="text" id="slugInput" class="form-control" placeholder="e.g. abit" pattern="[a-zA-Z0-9_-]+">
<button class="btn btn-primary px-3" type="submit"><i class="bi bi-arrow-right"></i></button>
</form>
<small class="text-muted mt-2 d-block">Your portal: <?= BASE_URL ?>/<strong>{slug}</strong>/</small>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
<script>
function goToCollege(e) {
e.preventDefault();
const slug = document.getElementById('slugInput').value.trim().toLowerCase();
if (slug) window.location.href = '<?= BASE_URL ?>/' + slug + '/';
}
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>