Update 34 files
- /nfc/README.md - /nfc/clean_old_logs.sh - /nfc/clockin.py - /nfc/emptycards.py - /nfc/sync_clocks.sh - /piservices/Dockerfile - /piservices/Portainer-lamp-stack.env - /piservices/Portainer-lamp-stack.yaml - /piservices/README.md - /piservices/avahi-alias.service - /piservices/clockpy.service - /piservices/emptycards.service - /piservices/nfc-sync.service - /piservices/test.sh - /www/404 - /www/get-table-data.php - /www/habiwan copy.png - /www/habiwan.png - /www/index.php - /www/log_swipe.php - /www/manage_data.php - /www/manifest.json - /www/names.csv - /www/network_audit.csv - /www/network-tracker.html - /www/nfc_debug.log - /www/scanner.html - /www/staff_names.php - /www/times.csv - /www/check_update.php - /www/dev.php - /www/favicon.png - /www/JsBarcode.all.min.js - /www/README.md
This commit is contained in:
1 parent
10824ab851
commit
a201d5d7ac
34 files changed
+9453
No files matched your search
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
$db = new PDO("mysql:host=db;dbname=PiClock", "root", "rootpassword");
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
// Ensure tables exist
|
||||
$db->exec("CREATE TABLE IF NOT EXISTS names (id INT AUTO_INCREMENT PRIMARY KEY, CardID VARCHAR(12) NOT NULL UNIQUE, name VARCHAR(100) DEFAULT NULL)");
|
||||
$db->exec("CREATE TABLE IF NOT EXISTS times (UID VARCHAR(12) NOT NULL, temp FLOAT, timestamp DATETIME)");
|
||||
|
||||
// --- BACKUP FUNCTION ---
|
||||
if (isset($_POST['backup'])) {
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="backup_' . date('Y-m-d') . '.csv"');
|
||||
$out = fopen('php://output', 'w');
|
||||
// Example: Exporting names
|
||||
$res = $db->query("SELECT * FROM names");
|
||||
while ($row = $res->fetch(PDO::FETCH_ASSOC)) { fputcsv($out, $row); }
|
||||
fclose($out);
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- IMPORT FUNCTION ---
|
||||
if (isset($_POST['import']) && isset($_FILES['csv_file'])) {
|
||||
$handle = fopen($_FILES['csv_file']['tmp_name'], 'r');
|
||||
while (($data = fgetcsv($handle)) !== false) {
|
||||
if (count($data) >= 2) {
|
||||
// Using INSERT IGNORE to prevent duplicate errors
|
||||
$stmt = $db->prepare("INSERT IGNORE INTO names (CardID, name) VALUES (?, ?)");
|
||||
$stmt->execute([$data[0], $data[1]]);
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
echo "<p>Import completed successfully.</p>";
|
||||
}
|
||||
?>
|
||||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="csv_file" accept=".csv" required>
|
||||
<button type="submit" name="import">Load & Merge CSV</button>
|
||||
<button type="submit" name="backup">Backup Current DB to CSV</button>
|
||||
</form>
|
||||
Reference in new issue
Block a user