-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
173 lines (158 loc) · 7.09 KB
/
Copy pathdashboard.php
File metadata and controls
173 lines (158 loc) · 7.09 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
<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: admin_login.php');
exit();
}
include 'db.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$original_url = $_POST['original_url'];
$short_url = substr(md5(uniqid(rand(), true)), 0, 6); // Rastgele kısa URL oluştur
// Kısa linki veritabanına kaydet
$sql = "INSERT INTO links (original_url, short_url) VALUES ('$original_url', '$short_url')";
if ($conn->query($sql) === TRUE) {
$success = "Kısa link başarıyla oluşturuldu: <a href='http://bykz.org/$short_url' target='_blank'>bykz.org/$short_url</a>";
} else {
$error = "Bir hata oluştu: " . $conn->error;
}
}
// Veritabanından tüm kısa linkleri al (Yeniden eskiye sıralama)
$sql = "SELECT id, original_url, short_url, clicks, created_at FROM links ORDER BY created_at DESC";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Panel</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="page-wrapper">
<header class="dashboard-header">
<div class="container header-content">
<a href="dashboard.php" class="header-brand">Beykoz Üniversitesi Kısa Link Servisi</a>
<a href="admin_login.php" class="btn btn-outline" style="padding: 0.5rem 1rem; font-size: 0.85rem;">Çıkış Yap</a>
</div>
</header>
<div class="container">
<!-- Stats Summary -->
<?php
$total_links = $result->num_rows;
$total_clicks = 0;
$all_links = [];
if ($total_links > 0) {
while($row = $result->fetch_assoc()) {
$total_clicks += (int)$row['clicks'];
$all_links[] = $row;
}
}
?>
<div class="stats-grid">
<div class="stat-item">
<div class="stat-value"><?php echo $total_links; ?></div>
<div class="stat-label">Toplam Link</div>
</div>
<div class="stat-item">
<div class="stat-value"><?php echo $total_clicks; ?></div>
<div class="stat-label">Toplam Tıklama</div>
</div>
</div>
<div class="card mb-2">
<h3 class="mb-1">Yeni Kısa Link Oluştur</h3>
<form method="post">
<div class="form-group">
<label for="original_url">Orijinal URL</label>
<div style="display: flex; gap: 1rem;">
<input type="url" id="original_url" name="original_url" placeholder="https://örnek.com/uzun-link" required style="flex: 1;">
<button type="submit" class="btn btn-primary">Oluştur</button>
</div>
</div>
<?php if (isset($success)) { echo "<div class='alert alert-success'>$success</div>"; } ?>
<?php if (isset($error)) { echo "<div class='alert alert-danger'>$error</div>"; } ?>
</form>
</div>
<h3 class="mb-1">Önceki Kısa Linkler</h3>
<div class="table-container">
<table>
<thead>
<tr>
<th style="width: 50px;">#</th>
<th>Orijinal URL</th>
<th>Kısa URL</th>
<th style="width: 100px;">Tıklama</th>
<th style="width: 150px;">Tarih</th>
</tr>
</thead>
<tbody>
<?php
if (count($all_links) > 0) {
foreach($all_links as $row) {
$short_full = "http://bykz.org/" . $row['short_url'];
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td style='max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;' title='" . $row['original_url'] . "'>" . $row['original_url'] . "</td>";
echo "<td><a href='$short_full' id='link-{$row['short_url']}' target='_blank' style='color: var(--primary-color); font-weight: 600; text-decoration: none;'>bykz.org/" . $row['short_url'] . "</a>";
echo " <button onclick=\"copyToClipboard('$short_full', this)\" class='btn-outline' style='padding: 0.1rem 0.4rem; font-size: 0.7rem; margin-left: 0.5rem; cursor: pointer; border-radius: 4px;'>Kopyala</button></td>";
echo "<td><span style='background: #f1f5f9; padding: 0.25rem 0.5rem; border-radius: 4px; font-weight: 600;'>" . $row['clicks'] . "</span></td>";
echo "<td style='font-size: 0.85rem; color: var(--text-muted);'>" . date('d.m.Y H:i', strtotime($row['created_at'])) . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='5' class='text-center' style='padding: 2rem;'>Henüz herhangi bir kısa link oluşturulmamış.</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
<footer class="footer">
<p>Bu proje CC BY-NC-SA 4.0 Lisansı ile lisanslanmıştır — Beykoz Üniversitesi Bilgi İşlem Direktörlüğü</p>
</footer>
</div>
<script>
function copyToClipboard(text, btn) {
const originalText = btn.innerText;
// Modern Clipboard API
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(() => {
showSuccess(btn, originalText);
}).catch(err => {
fallbackCopy(text, btn, originalText);
});
} else {
// Fallback for non-https or older browsers
fallbackCopy(text, btn, originalText);
}
}
function fallbackCopy(text, btn, originalText) {
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
textArea.style.left = "-9999px";
textArea.style.top = "0";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
showSuccess(btn, originalText);
} catch (err) {
console.error('Fallback copy failed', err);
}
document.body.removeChild(textArea);
}
function showSuccess(btn, originalText) {
btn.innerText = 'Kopyalandı!';
btn.style.color = '#276749';
btn.style.borderColor = '#9ae6b4';
setTimeout(() => {
btn.innerText = originalText;
btn.style.color = '';
btn.style.borderColor = '';
}, 2000);
}
</script>
</body>
</html>