=== FIL: ./admin_manage.php ===
prepare("SELECT * FROM gallery_settings WHERE gallery_code = ?");
$settingsStmt->execute([$gallery_code]);
$gallery_settings = $settingsStmt->fetch();
$gallery_password = $gallery_settings['password'] ?? '';
// HENT VANNMERKER FRA DATABASEN FOR NEDTREKKSBOKS
$wmStmt = $pdo->query("SELECT * FROM watermarks ORDER BY name ASC");
$watermarks = $wmStmt->fetchAll(PDO::FETCH_ASSOC);
function applyWatermarkToImage($pdo, $filePath, $watermarkId) {
if ($watermarkId <= 0) return;
$stmt = $pdo->prepare("SELECT * FROM watermarks WHERE id = ?");
$stmt->execute([$watermarkId]);
$wmData = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$wmData || empty($wmData['image_path'])) return;
$wmFile = 'uploads/' . $wmData['image_path'];
if (!file_exists($wmFile)) return;
$ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
if (in_array($ext, ['jpg', 'jpeg'])) { $img = @imagecreatefromjpeg($filePath); }
elseif ($ext == 'png') { $img = @imagecreatefrompng($filePath); }
else { return; }
if (!$img) return;
$wmExt = strtolower(pathinfo($wmFile, PATHINFO_EXTENSION));
if (in_array($wmExt, ['jpg', 'jpeg'])) { $wmImg = @imagecreatefromjpeg($wmFile); }
elseif ($wmExt == 'png') { $wmImg = @imagecreatefrompng($wmFile); }
else { imagedestroy($img); return; }
if (!$wmImg) { imagedestroy($img); return; }
$img_w = imagesx($img);
$img_h = imagesy($img);
$wm_orig_w = imagesx($wmImg);
$wm_orig_h = imagesy($wmImg);
$scale_pct = $wmData['scale'] / 100;
// Tvinger bredde og høyde til å bli heltall (fikser ut-av-grenser feilen)
$new_wm_w = (int)max(1, $img_w * $scale_pct);
$new_wm_h = (int)max(1, $wm_orig_h * ($new_wm_w / $wm_orig_w));
$wmResized = imagecreatetruecolor($new_wm_w, $new_wm_h);
imagealphablending($wmResized, false);
imagesavealpha($wmResized, true);
$transparent = imagecolorallocatealpha($wmResized, 255, 255, 255, 127);
imagefilledrectangle($wmResized, 0, 0, $new_wm_w, $new_wm_h, $transparent);
imagecopyresampled($wmResized, $wmImg, 0, 0, 0, 0, $new_wm_w, $new_wm_h, $wm_orig_w, $wm_orig_h);
$opacity = (int)$wmData['opacity'];
if ($opacity < 100) {
$opacity_factor = $opacity / 100;
for ($x = 0; $x < $new_wm_w; ++$x) {
for ($y = 0; $y < $new_wm_h; ++$y) {
$color = imagecolorat($wmResized, $x, $y);
$alpha = ($color >> 24) & 0x7F;
$new_alpha = 127 - ((127 - $alpha) * $opacity_factor);
$new_color = imagecolorallocatealpha($wmResized, ($color >> 16) & 0xFF, ($color >> 8) & 0xFF, $color & 0xFF, $new_alpha);
imagesetpixel($wmResized, $x, $y, $new_color);
}
}
}
$pos = strtolower($wmData['position']);
// Tvinger padding til å bli heltall
$padding = (int)($img_w * 0.02);
$pos_y = $pos[0] ?? 'c';
$pos_x = $pos[1] ?? 'c';
$dst_x = 0; $dst_y = 0;
// Tvinger posisjons-utregningene til å bli heltall (fikser desimal-feilene)
if ($pos_x == 'l') $dst_x = $padding;
elseif ($pos_x == 'c') $dst_x = (int)(($img_w - $new_wm_w) / 2);
elseif ($pos_x == 'r') $dst_x = (int)($img_w - $new_wm_w - $padding);
if ($pos_y == 't') $dst_y = $padding;
elseif ($pos_y == 'c') $dst_y = (int)(($img_h - $new_wm_h) / 2);
elseif ($pos_y == 'b') $dst_y = (int)($img_h - $new_wm_h - $padding);
imagealphablending($img, true);
imagecopy($img, $wmResized, $dst_x, $dst_y, 0, 0, $new_wm_w, $new_wm_h);
if (in_array($ext, ['jpg', 'jpeg'])) { imagejpeg($img, $filePath, 90); }
elseif ($ext == 'png') { imagepng($img, $filePath); }
imagedestroy($img);
imagedestroy($wmImg);
imagedestroy($wmResized);
}
if (isset($_POST['action']) && $_POST['action'] === 'check_duplicates') {
header('Content-Type: application/json');
$check_set_id = (int)$_POST['set_id'];
$filenames = json_decode($_POST['filenames'], true);
if (empty($filenames)) { echo json_encode([]); exit; }
$in = str_repeat('?,', count($filenames) - 1) . '?';
$params = array_merge([$gallery_code, $check_set_id], $filenames);
$stmt = $pdo->prepare("SELECT title FROM photos WHERE gallery_code = ? AND set_id = ? AND title IN ($in)");
$stmt->execute($params);
$duplicates = $stmt->fetchAll(PDO::FETCH_COLUMN);
echo json_encode($duplicates);
exit;
}
if (isset($_POST['action']) && $_POST['action'] === 'upload_media_ajax') {
header('Content-Type: application/json');
$upload_set_id = (int)$_POST['set_id'];
$watermark_id = (int)($_POST['watermark_id'] ?? 0);
$replace_duplicate = isset($_POST['replace_duplicate']) && $_POST['replace_duplicate'] == '1';
if (!empty($_FILES['file']['name'])) {
$original_name = basename($_FILES['file']['name']);
$file_ext = pathinfo($original_name, PATHINFO_EXTENSION);
$unique_name = time() . '_' . rand(1000, 9999) . '.' . $file_ext;
$target_file = "uploads/" . $unique_name;
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file)) {
if ($watermark_id > 0) {
applyWatermarkToImage($pdo, $target_file, $watermark_id);
}
$existing = null;
if ($replace_duplicate) {
$s = $pdo->prepare("SELECT id, file_name FROM photos WHERE gallery_code = ? AND set_id = ? AND title = ?");
$s->execute([$gallery_code, $upload_set_id, $original_name]);
$existing = $s->fetch();
}
if ($existing) {
if (file_exists("uploads/" . $existing['file_name'])) {
unlink("uploads/" . $existing['file_name']);
}
$stmt = $pdo->prepare("UPDATE photos SET file_name = ? WHERE id = ?");
$stmt->execute([$unique_name, $existing['id']]);
$new_id = $existing['id'];
} else {
$stmt = $pdo->prepare("INSERT INTO photos (gallery_code, set_id, file_name, title) VALUES (?, ?, ?, ?)");
$stmt->execute([$gallery_code, $upload_set_id, $unique_name, $original_name]);
$new_id = $pdo->lastInsertId();
}
echo json_encode([
'success' => true,
'id' => $new_id,
'file_name' => $unique_name,
'original_name' => $original_name,
'set_id' => $upload_set_id,
'replaced' => !!$existing
]);
exit;
}
}
echo json_encode(['success' => false]);
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'send_email') {
$recipient = trim($_POST['recipient_email']);
$subject = trim($_POST['email_subject']);
$email_body = $_POST['email_body'];
$include_password = isset($_POST['include_password']);
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
$host = $_SERVER['HTTP_HOST'];
$gallery_link = "$protocol://$host/eva_gal/index.php?gallery=" . urlencode($gallery_code);
$email_body = str_replace('{gallery_link}', $gallery_link, $email_body);
$password_block = "";
if ($include_password && !empty($gallery_password)) {
$password_block = "Galleri passord: " . $gallery_password;
}
$email_body = str_replace('{password_block}', $password_block, $email_body);
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'din-epost@gmail.com';
$mail->Password = 'ditt-app-passord';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('din-epost@gmail.com', 'Fagfotograf Eva T. Belland');
$mail->addAddress($recipient);
$mail->isHTML(false);
$mail->Subject = $subject;
$mail->Body = $email_body;
$mail->send();
$message = "E-posten ble sendt vellykket til " . htmlspecialchars($recipient) . "!";
} catch (Exception $e) {
$error = "E-posten kunne ikke sendes. Feilmelding: {$mail->ErrorInfo}";
}
}
$templatesStmt = $pdo->query("SELECT * FROM email_templates ORDER BY id ASC");
$email_templates = $templatesStmt->fetchAll(PDO::FETCH_ASSOC);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'add_set') {
$set_name = trim($_POST['set_name']);
if (!empty($set_name)) {
$stmt = $pdo->prepare("INSERT INTO gallery_sets (gallery_code, set_name) VALUES (?, ?)");
$stmt->execute([$gallery_code, $set_name]);
$message = "Settet '$set_name' ble opprettet.";
}
}
if (in_array($action, ['delete', 'update_title'])) {
$photo_id = (int)$_POST['photo_id'];
$stmt = $pdo->prepare("SELECT * FROM photos WHERE id = ? AND gallery_code = ?");
$stmt->execute([$photo_id, $gallery_code]);
$photo = $stmt->fetch();
if ($photo) {
$old_filepath = "uploads/" . $photo['file_name'];
if ($action === 'delete') {
if (file_exists($old_filepath)) unlink($old_filepath);
$pdo->prepare("DELETE FROM photos WHERE id = ?")->execute([$photo_id]);
$message = "Bildet ble slettet.";
} elseif ($action === 'update_title') {
$new_title = trim($_POST['title']);
$new_set = (int)$_POST['new_set_id'];
$pdo->prepare("UPDATE photos SET title = ?, set_id = ? WHERE id = ?")->execute([$new_title, $new_set, $photo_id]);
$message = "Bildet ble oppdatert.";
}
}
}
if ($action === 'bulk_move' && !empty($_POST['selected_photos'])) {
$target_set = (int)$_POST['target_set_id'];
$photo_ids = explode(',', $_POST['selected_photos']);
$count = 0;
$stmt = $pdo->prepare("UPDATE photos SET set_id = ? WHERE id = ? AND gallery_code = ?");
foreach ($photo_ids as $pid) {
if ((int)$pid > 0) { $stmt->execute([$target_set, (int)$pid, $gallery_code]); $count++; }
}
$message = "$count bilder ble flyttet.";
}
// NY BULK DELETE FUNKSJON
if ($action === 'bulk_delete' && !empty($_POST['selected_photos'])) {
$photo_ids = explode(',', $_POST['selected_photos']);
$count = 0;
foreach ($photo_ids as $pid) {
if ((int)$pid > 0) {
$stmt = $pdo->prepare("SELECT * FROM photos WHERE id = ? AND gallery_code = ?");
$stmt->execute([(int)$pid, $gallery_code]);
$photo = $stmt->fetch();
if ($photo) {
$old_filepath = "uploads/" . $photo['file_name'];
if (file_exists($old_filepath)) unlink($old_filepath);
$pdo->prepare("DELETE FROM photos WHERE id = ?")->execute([(int)$pid]);
$count++;
}
}
}
$message = "$count bilder ble slettet.";
}
}
// HENT DATA FOR VISNING
$stmt = $pdo->prepare("SELECT * FROM gallery_sets WHERE gallery_code = ?");
$stmt->execute([$gallery_code]);
$sets = $stmt->fetchAll();
$set_counts = [];
$countStmt = $pdo->prepare("SELECT set_id, COUNT(*) as c FROM photos WHERE gallery_code = ? GROUP BY set_id");
$countStmt->execute([$gallery_code]);
foreach ($countStmt->fetchAll() as $row) { $set_counts[$row['set_id']] = $row['c']; }
if ($active_set > 0) {
$stmt = $pdo->prepare("SELECT * FROM photos WHERE gallery_code = ? AND set_id = ? ORDER BY id DESC");
$stmt->execute([$gallery_code, $active_set]);
$active_set_name = "Ukjent set";
foreach ($sets as $s) { if ($s['id'] == $active_set) $active_set_name = $s['set_name']; }
} else {
$stmt = $pdo->prepare("SELECT * FROM photos WHERE gallery_code = ? ORDER BY id DESC");
$stmt->execute([$gallery_code]);
$active_set_name = "Alle bilder";
}
$photos = $stmt->fetchAll();
$total_photos = array_sum($set_counts);
$setStmt = $pdo->prepare("SELECT cover_photo FROM gallery_settings WHERE gallery_code = ?");
$setStmt->execute([$gallery_code]);
$settings = $setStmt->fetch();
$db_cover = $settings['cover_photo'] ?? '';
$cover_image = !empty($db_cover) ? "uploads/" . $db_cover : (!empty($photos) ? "uploads/" . $photos[0]['file_name'] : "https://via.placeholder.com/600x400?text=Ingen+bilde");
?>
Album -
X DUPLICATES FOUND
The following files already exist in this photo set. Do you want to replace them with the ones you're uploading?
=== FIL: ./style_admin.css ===
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background-color: #f4f6f8;
color: #333;
margin: 0;
padding: 20px;
}
.admin-container {
max-width: 1200px;
margin: 0 auto;
}
h1 {
color: #1a1a1a;
margin-bottom: 20px;
}
.highlight {
color: #2e7d32;
}
.admin-card {
background: #fff;
border-radius: 8px;
padding: 24px;
margin-bottom: 25px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.upload-form {
display: flex;
flex-direction: column;
gap: 15px;
max-width: 500px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.form-group label {
font-weight: 600;
}
.form-group input[type="text"],
.form-group input[type="file"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
.btn {
padding: 10px 18px;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: 600;
text-decoration: none;
display: inline-block;
}
.btn-primary { background: #2e7d32; color: #fff; }
.btn-primary:hover { background: #256428; }
.btn-secondary { background: #1976d2; color: #fff; }
.btn-secondary:hover { background: #115293; }
.btn-small { padding: 5px 10px; font-size: 12px; background: #555; color: #fff; }
.data-table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
}
.data-table th, .data-table td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #eee;
}
.data-table th {
background-color: #fafafa;
}
.alert {
background-color: #e8f5e9;
color: #2e7d32;
padding: 12px 20px;
border-radius: 4px;
margin-bottom: 20px;
border: 1px solid #a5d6a7;
}
/* Kundeutvalg / Lister */
.client-header {
border-bottom: 2px solid #f0f0f0;
padding-bottom: 10px;
margin-bottom: 15px;
}
.lists-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
}
.list-column {
background: #fafafa;
padding: 15px;
border-radius: 6px;
border: 1px solid #eaeaea;
}
.mini-thumbs {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
gap: 8px;
margin-bottom: 12px;
}
.thumb-card img {
width: 100%;
height: 70px;
object-fit: cover;
border-radius: 4px;
}
.file-label {
font-size: 10px;
color: #666;
display: block;
word-break: break-all;
}
.export-box {
margin-top: 10px;
}
.export-box label {
font-size: 12px;
font-weight: bold;
display: block;
margin-bottom: 4px;
}
.export-box textarea {
width: 100%;
height: 60px;
font-size: 12px;
box-sizing: border-box;
margin-bottom: 6px;
border: 1px solid #ccc;
border-radius: 4px;
}
.empty-text {
color: #888;
font-style: italic;
font-size: 13px;
}
=== FIL: ./index.php ===
prepare("SELECT id FROM favorite_list_meta WHERE gallery_code = ? AND client_email = ? AND list_type = ?");
$check->execute([$gallery_code, $client_email_ajax, $list_type]);
if ($check->rowCount() == 0) {
$pdo->prepare("INSERT INTO favorite_list_meta (gallery_code, client_email, list_type, display_name) VALUES (?, ?, ?, ?)")
->execute([$gallery_code, $client_email_ajax, $list_type, $list_type]);
}
}
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
// 2. Toggle favoritt
if ($_POST['action'] === 'toggle_favorite') {
$photo_id = (int)$_POST['photo_id'];
$list_type = $_POST['list_type'] ?? 'My Favorites';
try {
// Sørg for at meta-rad finnes
$checkMeta = $pdo->prepare("SELECT id FROM favorite_list_meta WHERE gallery_code = ? AND client_email = ? AND list_type = ?");
$checkMeta->execute([$gallery_code, $client_email_ajax, $list_type]);
if ($checkMeta->rowCount() == 0) {
$pdo->prepare("INSERT INTO favorite_list_meta (gallery_code, client_email, list_type, display_name) VALUES (?, ?, ?, ?)")->execute([$gallery_code, $client_email_ajax, $list_type, $list_type]);
}
$check = $pdo->prepare("SELECT * FROM favorites WHERE gallery_code = ? AND photo_id = ? AND client_email = ? AND list_type = ?");
$check->execute([$gallery_code, $photo_id, $client_email_ajax, $list_type]);
if ($check->rowCount() > 0) {
$pdo->prepare("DELETE FROM favorites WHERE gallery_code = ? AND photo_id = ? AND client_email = ? AND list_type = ?")->execute([$gallery_code, $photo_id, $client_email_ajax, $list_type]);
$status = 'removed';
} else {
$pdo->prepare("INSERT INTO favorites (gallery_code, photo_id, client_email, list_type) VALUES (?, ?, ?, ?)")->execute([$gallery_code, $photo_id, $client_email_ajax, $list_type]);
$status = 'added';
}
$tot = $pdo->prepare("SELECT list_type, COUNT(*) as cnt FROM favorites WHERE gallery_code = ? AND client_email = ? GROUP BY list_type");
$tot->execute([$gallery_code, $client_email_ajax]);
$totals = [];
foreach($tot->fetchAll() as $row) { $totals[$row['list_type']] = $row['cnt']; }
echo json_encode(['success' => true, 'status' => $status, 'totals' => $totals]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
// 3. Lagre notat
if ($_POST['action'] === 'save_note') {
$photo_id = (int)$_POST['photo_id'];
$list_type = $_POST['list_type'] ?? 'My Favorites';
$note = trim($_POST['note'] ?? '');
try {
$stmt = $pdo->prepare("UPDATE favorites SET note = ? WHERE gallery_code = ? AND photo_id = ? AND client_email = ? AND list_type = ?");
$stmt->execute([$note, $gallery_code, $photo_id, $client_email_ajax, $list_type]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
}
// Hent innstillinger
$required_password = '';
if (!empty($gallery_code)) {
$setStmt = $pdo->prepare("SELECT * FROM gallery_settings WHERE gallery_code = ?");
$setStmt->execute([$gallery_code]);
$settings = $setStmt->fetch();
$required_password = $settings['password'] ?? '';
}
// Håndter innlogging
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login_submit'])) {
$input_gallery = trim($gallery_code ?: ($_POST['gallery_code'] ?? ''));
$input_email = trim($_POST['client_email']);
$input_password = $_POST['client_password'] ?? '';
if (empty($input_gallery)) {
$login_error = "Mangler gallerikode.";
} else {
$setStmt = $pdo->prepare("SELECT * FROM gallery_settings WHERE gallery_code = ?");
$setStmt->execute([$input_gallery]);
$settings = $setStmt->fetch();
$req_pass = $settings['password'] ?? '';
if (empty($input_email)) {
$login_error = "Vennligst oppgi din e-postadresse.";
} elseif (!empty($req_pass) && $input_password !== $req_pass) {
$login_error = "Feil passord. Vennligst prøv igjen.";
} else {
$_SESSION['auth_'.$input_gallery] = true;
$_SESSION['email_'.$input_gallery] = $input_email;
header("Location: index.php?gallery=" . urlencode($input_gallery));
exit;
}
}
}
$is_authenticated = false;
$client_email = '';
if (!empty($gallery_code)) {
$is_authenticated = isset($_SESSION['auth_'.$gallery_code]) && $_SESSION['auth_'.$gallery_code] === true;
$client_email = $_SESSION['email_'.$gallery_code] ?? '';
}
// Opprett meta-tabell og synkroniser gamle lister hvis de ikke finnes
if ($is_authenticated) {
$pdo->exec("CREATE TABLE IF NOT EXISTS favorite_list_meta (
id INT AUTO_INCREMENT PRIMARY KEY,
gallery_code VARCHAR(100),
client_email VARCHAR(100),
list_type VARCHAR(100),
display_name VARCHAR(100)
)");
$pdo->exec("
INSERT INTO favorite_list_meta (gallery_code, client_email, list_type, display_name)
SELECT DISTINCT gallery_code, client_email, list_type, list_type
FROM favorites f
WHERE NOT EXISTS (
SELECT 1 FROM favorite_list_meta m
WHERE m.gallery_code = f.gallery_code
AND m.client_email = f.client_email
AND m.list_type = f.list_type
)
");
}
if (empty($gallery_code) || !$is_authenticated || empty($client_email)) {
?>
Client Gallery
Eva
Password protected.
Vennligst oppgi e-post for å se galleriet.
prepare("SELECT p.*, f.note FROM photos p JOIN favorites f ON p.id = f.photo_id WHERE f.gallery_code = ? AND f.client_email = ? AND f.list_type = ? ORDER BY p.id ASC");
$stmt->execute([$gallery_code, $client_email, $view_list]);
} else {
$stmt = $pdo->prepare("SELECT * FROM photos WHERE gallery_code = ? ORDER BY id ASC");
$stmt->execute([$gallery_code]);
}
$photos = $stmt->fetchAll();
$setStmt = $pdo->prepare("SELECT * FROM gallery_sets WHERE gallery_code = ? ORDER BY id ASC");
$setStmt->execute([$gallery_code]);
$sets = $setStmt->fetchAll();
$favStmt = $pdo->prepare("SELECT photo_id, list_type, note FROM favorites WHERE gallery_code = ? AND client_email = ?");
$favStmt->execute([$gallery_code, $client_email]);
$user_favorites = $favStmt->fetchAll();
$fav_lookup = []; $fav_notes = []; $total_favs = 0;
foreach ($user_favorites as $fav) {
$fav_lookup[$fav['photo_id']][] = $fav['list_type'];
if(!empty($fav['note'])) { $fav_notes[$fav['photo_id']][$fav['list_type']] = $fav['note']; }
$total_favs++;
}
// Hent lister primært fra meta-tabellen (slik at tomme lister også vises)
$listStmt = $pdo->prepare("
SELECT
m.list_type,
m.display_name,
(SELECT COUNT(f.id) FROM favorites f WHERE f.gallery_code = m.gallery_code AND f.client_email = m.client_email AND f.list_type = m.list_type) as count,
(SELECT p.file_name FROM favorites f2 JOIN photos p ON f2.photo_id = p.id WHERE f2.gallery_code = m.gallery_code AND f2.client_email = m.client_email AND f2.list_type = m.list_type LIMIT 1) as thumb
FROM favorite_list_meta m
WHERE m.gallery_code = ? AND m.client_email = ?
");
$listStmt->execute([$gallery_code, $client_email]);
$db_lists = $listStmt->fetchAll();
$client_lists = [];
foreach($db_lists as $l) {
$client_lists[$l['list_type']] = ['id' => $l['list_type'], 'name' => $l['display_name'] ?: ucfirst($l['list_type']), 'count' => $l['count'], 'thumb' => $l['thumb']];
}
if (empty($client_lists)) {
$pdo->prepare("INSERT INTO favorite_list_meta (gallery_code, client_email, list_type, display_name) VALUES (?, ?, 'My Favorites', 'My Favorites')")->execute([$gallery_code, $client_email]);
$client_lists['My Favorites'] = ['id' => 'My Favorites', 'name' => 'My Favorites', 'count' => 0, 'thumb' => ''];
}
$layout = $settings['layout_style'] ?? 'center';
$typography = $settings['typography'] ?? 'sans';
$color_theme = $settings['color_theme'] ?? 'light';
$grid_thumb = $settings['grid_thumb_size'] ?? 'regular';
$colors = [
'light' => ['#ffffff', '#f4f4f4', '#222222'], 'gold' => ['#ffffff', '#fbf8f1', '#a68a61'], 'rose' => ['#ffffff', '#fcf6f7', '#a78284'],
'terracotta' => ['#ffffff', '#faf6f3', '#a7765c'], 'sand' => ['#ffffff', '#f7f6f4', '#a09383'], 'olive' => ['#ffffff', '#f6f7f4', '#8c9578'],
'agave' => ['#ffffff', '#f2f6f5', '#7d9e95'], 'sea' => ['#ffffff', '#f3f5f8', '#8690a2'], 'dark' => ['#111111', '#222222', '#ffffff']
];
$palette = $colors[$color_theme] ?? $colors['light'];
$bg_main = $palette[0];
$bg_grid = $palette[1];
$text_color = $palette[2];
function getFontCss($type) {
switch($type) {
case 'serif': return 'Georgia, "Times New Roman", serif';
case 'modern': return '"Helvetica Neue", Helvetica, sans-serif';
case 'timeless': return '"Playfair Display", Didot, serif';
case 'bold': return 'Impact, "Arial Black", sans-serif';
case 'subtle': return '"Avenir Next", "Segoe UI", sans-serif';
default: return '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
}
}
$font_family = getFontCss($typography);
$title_style = "";
if($typography === 'timeless') $title_style = 'font-weight: 300; letter-spacing: 4px;';
if($typography === 'bold') $title_style = 'font-weight: 900; letter-spacing: 1px;';
if($typography === 'subtle') $title_style = 'font-weight: 300; letter-spacing: 3px;';
$db_cover = $settings['cover_photo'] ?? '';
$cover_image = !empty($db_cover) ? "uploads/" . $db_cover : (!empty($photos) ? "uploads/" . $photos[0]['file_name'] : "");
$creation_date = strtoupper(date("jS F, Y"));
$is_favorites_overview = isset($_GET['favorites_overview']);
$column_count = ($grid_thumb === 'large') ? 2 : 3;
?>
Favorites
Curated by
$listData): $thumbUrl = $listData['thumb'] ? "uploads/" . htmlspecialchars($listData['thumb']) : "https://via.placeholder.com/140x90?text=Tom"; ?>
$photo):
$pid = $photo['id'];
$set_id = $photo['set_id'];
$active_lists = $fav_lookup[$pid] ?? [];
$is_fav = count($active_lists) > 0;
$current_note = ($view_list && isset($fav_notes[$pid][$view_list])) ? $fav_notes[$pid][$view_list] : '';
?>
Add to favorites
=== FIL: ./save_favorite.php ===
'error']);
exit;
}
// 1. Sjekk om dette bildet allerede ligger i denne spesifikke listen for kunden
$stmt = $pdo->prepare("SELECT id FROM favorites WHERE gallery_code = ? AND client_email = ? AND photo_id = ? AND list_type = ?");
$stmt->execute([$gallery_code, $client_email, $photo_id, $list_type]);
$exists = $stmt->fetch();
if ($exists) {
// Fjern fra listen
$del = $pdo->prepare("DELETE FROM favorites WHERE id = ?");
$del->execute([$exists['id']]);
$status = 'removed';
} else {
// Legg til i listen
$ins = $pdo->prepare("INSERT INTO favorites (gallery_code, client_email, photo_id, list_type) VALUES (?, ?, ?, ?)");
$ins->execute([$gallery_code, $client_email, $photo_id, $list_type]);
$status = 'added';
}
// 2. Hent oppdaterte totalsummer for ALLE lister for denne kunden
// (Slik at tellerne i toppmenyen blir oppdatert korrekt)
$list_types = ['favorites', 'wall_art', 'album'];
$totals = [];
foreach ($list_types as $type) {
$cStmt = $pdo->prepare("SELECT COUNT(*) FROM favorites WHERE gallery_code = ? AND client_email = ? AND list_type = ?");
$cStmt->execute([$gallery_code, $client_email, $type]);
$totals[$type] = $cStmt->fetchColumn();
}
echo json_encode([
'status' => $status,
'totals' => $totals
]);
?>
=== FIL: ./script.js ===
function toggleList(photoId, listType) {
const card = document.querySelector(`.photo-card[data-id="${photoId}"]`);
// Finn knappen som matcher denne liste-typen
const btn = Array.from(card.querySelectorAll('.list-toggle-btn'))
.find(b => b.getAttribute('onclick').includes(listType));
fetch('save_favorite.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
photo_id: photoId,
gallery_code: galleryCode,
client_email: clientEmail,
list_type: listType
})
})
.then(response => response.json())
.then(data => {
if (data.status === 'added') {
btn.classList.add('active');
} else if (data.status === 'removed') {
btn.classList.remove('active');
}
// Oppdater tellerne i toppmenyen basert på hva serveren returnerer
updateCounters(data.totals);
})
.catch(error => console.error('Feil:', error));
}
function updateCounters(totals) {
for (const [listType, count] of Object.entries(totals)) {
const counterSpan = document.getElementById(`count-${listType}`);
if (counterSpan) {
counterSpan.textContent = count;
}
}
}
// Kjør en opptelling ved oppstart hvis du vil
// (eller du kan la PHP fylle inn initial-tallene i HTML)
=== FIL: ./admin_design.php ===
exec("ALTER TABLE gallery_settings ADD COLUMN cover_photo VARCHAR(255) DEFAULT ''");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN layout_style VARCHAR(50) DEFAULT 'center'");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN typography VARCHAR(50) DEFAULT 'sans'");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN color_theme VARCHAR(50) DEFAULT 'light'");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN grid_style VARCHAR(50) DEFAULT 'vertical'");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN grid_thumb_size VARCHAR(50) DEFAULT 'regular'");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN grid_spacing VARCHAR(50) DEFAULT 'regular'");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN grid_nav_style VARCHAR(50) DEFAULT 'icon_text'");
} catch (PDOException $e) {
// Kolonnene finnes allerede
}
// 2. HÅNDTER AJAX-OPPDATERINGER
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
header('Content-Type: application/json');
$action = $_POST['action'] ?? '';
if ($action === 'update_design') {
$field = $_POST['field'] ?? '';
$value = $_POST['value'] ?? '';
$allowed = ['layout_style', 'typography', 'color_theme', 'grid_style', 'grid_thumb_size', 'grid_spacing', 'grid_nav_style'];
if (in_array($field, $allowed)) {
$stmt = $pdo->prepare("UPDATE gallery_settings SET $field = ? WHERE gallery_code = ?");
$stmt->execute([$value, $gallery_code]);
echo json_encode(['success' => true]);
exit;
}
}
if ($action === 'upload_cover' && !empty($_FILES['cover_file']['name'])) {
$file_name = basename($_FILES['cover_file']['name']);
$unique_name = time() . '_cover_' . pathinfo($file_name, PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES['cover_file']['tmp_name'], "uploads/" . $unique_name)) {
$stmt = $pdo->prepare("UPDATE gallery_settings SET cover_photo = ? WHERE gallery_code = ?");
$stmt->execute([$unique_name, $gallery_code]);
echo json_encode(['success' => true, 'file' => $unique_name]);
exit;
}
}
echo json_encode(['success' => false]);
exit;
}
// 3. HENT NÅVÆRENDE INNSTILLINGER FRA DATABASE
$stmt = $pdo->prepare("SELECT * FROM gallery_settings WHERE gallery_code = ?");
$stmt->execute([$gallery_code]);
$settings = $stmt->fetch();
$current_layout = $settings['layout_style'] ?? 'center';
$current_typography = $settings['typography'] ?? 'sans';
$current_color = $settings['color_theme'] ?? 'light';
$current_grid_style = $settings['grid_style'] ?? 'vertical';
$current_grid_thumb = $settings['grid_thumb_size'] ?? 'regular';
$current_grid_spacing = $settings['grid_spacing'] ?? 'regular';
$current_grid_nav = $settings['grid_nav_style'] ?? 'icon_text';
$db_cover = $settings['cover_photo'] ?? '';
if (empty($db_cover)) {
$photoStmt = $pdo->prepare("SELECT file_name FROM photos WHERE gallery_code = ? ORDER BY id ASC LIMIT 1");
$photoStmt->execute([$gallery_code]);
$first_photo = $photoStmt->fetchColumn();
$cover_url = $first_photo ? "uploads/" . $first_photo : "https://via.placeholder.com/600x400?text=Ingen+bilde";
} else {
$cover_url = "uploads/" . $db_cover;
}
$layouts = ['center'=>'Center', 'left'=>'Left', 'novel'=>'Novel', 'vintage'=>'Vintage', 'frame'=>'Frame', 'stripe'=>'Stripe', 'divider'=>'Divider', 'journal'=>'Journal', 'stamp'=>'Stamp', 'outline'=>'Outline', 'classic'=>'Classic', 'none'=>'None'];
$typography = ['sans' => ['Sans', 'A neutral font'], 'serif' => ['Serif', 'A classic font'], 'modern' => ['Modern', 'A sophisticated font'], 'timeless' => ['Timeless', 'A light and airy font'], 'bold' => ['BOLD', 'A punchy font'], 'subtle' => ['SUBTLE', 'A minimal font']];
$colors = [
'light' => ['#ffffff', '#f4f4f4', '#222222'], 'gold' => ['#ffffff', '#fbf8f1', '#a68a61'], 'rose' => ['#ffffff', '#fcf6f7', '#a78284'],
'terracotta' => ['#ffffff', '#faf6f3', '#a7765c'], 'sand' => ['#ffffff', '#f7f6f4', '#a09383'], 'olive' => ['#ffffff', '#f6f7f4', '#8c9578'],
'agave' => ['#ffffff', '#f2f6f5', '#7d9e95'], 'sea' => ['#ffffff', '#f3f5f8', '#8690a2'], 'dark' => ['#111111', '#222222', '#333333']
];
?>
Design -
=== FIL: ./db.php ===
PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
];
try {
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
?>
=== FIL: ./admin_gallery.php ===
exec("CREATE TABLE IF NOT EXISTS favorite_list_meta (
id INT AUTO_INCREMENT PRIMARY KEY,
gallery_code VARCHAR(100),
client_email VARCHAR(100),
list_type VARCHAR(100),
display_name VARCHAR(100)
)");
// Håndter eksport til CSV eller PDF
if (isset($_GET['export']) && isset($_GET['email'])) {
$exp_email = $_GET['email'];
$exp_list = $_GET['list'] ?? 'My Favorites';
$type = $_GET['export'];
$expStmt = $pdo->prepare("
SELECT p.file_name, p.title, s.set_name, f.created_at
FROM favorites f
LEFT JOIN photos p ON f.photo_id = p.id
LEFT JOIN gallery_sets s ON p.set_id = s.id
WHERE f.gallery_code = ? AND f.client_email = ? AND f.list_type = ?
");
$expStmt->execute([$gallery_code, $exp_email, $exp_list]);
$photos = $expStmt->fetchAll(PDO::FETCH_ASSOC);
if ($type === 'csv') {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=favorites_' . date('Y-m-d') . '.csv');
$output = fopen('php://output', 'w');
fputcsv($output, ['Collection: ' . $gallery_code, 'Favorite: ' . $exp_list, 'Email ' . $exp_email, '']);
fputcsv($output, ['Name', 'Note', 'Photo Set', 'Created at']);
foreach ($photos as $p) {
$date = $p['created_at'] ? date('j/n/Y', strtotime($p['created_at'])) : date('j/n/Y');
fputcsv($output, [$p['file_name'], '', $p['set_name'] ?? 'Farge bilder', $date]);
}
fclose($output);
exit;
} elseif ($type === 'pdf') {
?>
Favorite List
favlist-
| Collection: |
Favorite: |
Email |
|
|
|
|
|
prepare("UPDATE favorites SET client_email = ?, list_type = ? WHERE gallery_code = ? AND client_email = ? AND list_type = ?");
$stmt->execute([$new_email, $new_list, $gallery_code, $old_email, $old_list]);
$stmtMeta = $pdo->prepare("UPDATE favorite_list_meta SET client_email = ?, list_type = ?, display_name = ? WHERE gallery_code = ? AND client_email = ? AND list_type = ?");
$stmtMeta->execute([$new_email, $new_list, $new_list, $gallery_code, $old_email, $old_list]);
header("Location: admin_gallery.php?gallery=" . urlencode($gallery_code));
exit;
}
$dateCols = $pdo->query("SHOW COLUMNS FROM favorites LIKE 'created_at'")->fetchAll();
if (count($dateCols) === 0) {
$pdo->exec("ALTER TABLE favorites ADD COLUMN created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP");
}
$settingsStmt = $pdo->prepare("SELECT * FROM gallery_settings WHERE gallery_code = ?");
$settingsStmt->execute([$gallery_code]);
$gallery_settings = $settingsStmt->fetch();
$photoStmt = $pdo->prepare("SELECT file_name FROM photos WHERE gallery_code = ? ORDER BY id ASC LIMIT 1");
$photoStmt->execute([$gallery_code]);
$firstPhoto = $photoStmt->fetch();
$cover_image = !empty($gallery_settings['cover_photo']) ? "uploads/" . $gallery_settings['cover_photo'] : (!empty($firstPhoto) ? "uploads/" . $firstPhoto['file_name'] : "https://via.placeholder.com/600x400?text=Ingen+bilde");
// --- GRUPPERING AV LISTER (Løser problemet med usynlige, tomme lister) ---
// 1. Hent alle kjente lister for galleriet fra Meta-tabellen
$metaStmt = $pdo->prepare("SELECT client_email AS email, list_type, display_name FROM favorite_list_meta WHERE gallery_code = ? ORDER BY client_email ASC, list_type ASC");
$metaStmt->execute([$gallery_code]);
$meta_lists = $metaStmt->fetchAll(PDO::FETCH_ASSOC);
// 2. Hent alle favoritt-bilder fra Favorites
$favStmt = $pdo->prepare("
SELECT f.client_email AS email, f.list_type, p.file_name, p.title, f.created_at
FROM favorites f
LEFT JOIN photos p ON f.photo_id = p.id
WHERE f.gallery_code = ?
ORDER BY f.created_at DESC
");
$favStmt->execute([$gallery_code]);
$raw_favorites = $favStmt->fetchAll(PDO::FETCH_ASSOC);
$grouped_favorites = [];
// Bygg opp rammene for listene først
foreach ($meta_lists as $meta) {
$email = $meta['email'];
$list_name = $meta['list_type'];
if (!isset($grouped_favorites[$email])) { $grouped_favorites[$email] = []; }
$grouped_favorites[$email][$list_name] = [
'list_name' => $meta['display_name'] ?: $list_name,
'email' => $email,
'created' => '',
'photos' => []
];
}
// Fyll inn bildene der de hører hjemme
foreach ($raw_favorites as $row) {
$email = $row['email'];
$list_name = !empty($row['list_type']) ? $row['list_type'] : 'My Favorites';
if (!isset($grouped_favorites[$email])) { $grouped_favorites[$email] = []; }
if (!isset($grouped_favorites[$email][$list_name])) {
$grouped_favorites[$email][$list_name] = [
'list_name' => $list_name,
'email' => $email,
'created' => $row['created_at'],
'photos' => []
];
}
if (empty($grouped_favorites[$email][$list_name]['created'])) {
$grouped_favorites[$email][$list_name]['created'] = $row['created_at'];
}
if ($row['file_name']) {
$grouped_favorites[$email][$list_name]['photos'][] = [
'file' => $row['file_name'],
'title' => $row['title']
];
}
}
?>
Favorite Activity -
Favorite Activity
Ingen favoritter er valgt enda.
| EMAIL |
FAVORITE LIST |
PHOTOS |
DATE CREATED |
DATE UPDATED |
|
$lists): ?>
$list): ?>
|
📷
|
|
|
|
|
✏️ Edit List
⬇️ Download All
📄 Export
↓↑ Name: A-Z
=== FIL: ./style.css ===
.list-buttons {
display: flex;
flex-direction: column;
gap: 5px;
padding: 10px;
background: #1e1e1e;
}
.list-toggle-btn {
background: #2b2b2b;
border: 1px solid #444;
color: #ccc;
padding: 8px;
border-radius: 4px;
font-size: 13px;
cursor: pointer;
transition: all 0.2s;
text-align: left;
}
.list-toggle-btn:hover {
background: #3b3b3b;
color: #fff;
}
/* Fargekoder når en liste er aktiv */
.list-toggle-btn.active {
background: #1976d2; /* Blåfarge for aktiv liste */
color: white;
border-color: #1565c0;
font-weight: bold;
}
.list-tabs {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 15px;
}
.tab-btn {
background: #2b2b2b;
border: none;
color: #fff;
padding: 10px 18px;
border-radius: 20px;
cursor: pointer;
font-size: 14px;
}
.tab-btn.active {
background: #ff9800; /* Oransje fremheving for aktiv tab */
color: #000;
font-weight: bold;
}
=== FIL: ./admin_settings.php ===
exec("ALTER TABLE gallery_settings ADD COLUMN password VARCHAR(255) DEFAULT ''");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN show_homepage TINYINT(1) DEFAULT 0");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN client_exclusive TINYINT(1) DEFAULT 0");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN photo_download TINYINT(1) DEFAULT 0");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN video_download TINYINT(1) DEFAULT 0");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN favorite_enabled TINYINT(1) DEFAULT 1");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN store_enabled TINYINT(1) DEFAULT 0");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN email_registration TINYINT(1) DEFAULT 1");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN slideshow TINYINT(1) DEFAULT 1");
$pdo->exec("ALTER TABLE gallery_settings ADD COLUMN social_sharing TINYINT(1) DEFAULT 0");
} catch (PDOException $e) {
// Kolonnene finnes allerede
}
// 2. HÅNDTER LAGRING VIA AJAX
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
header('Content-Type: application/json');
$field = $_POST['field'] ?? '';
$value = $_POST['value'] ?? '';
// Tillatt 'password' her
$allowed = ['password', 'show_homepage', 'client_exclusive', 'photo_download', 'video_download', 'favorite_enabled', 'store_enabled', 'email_registration', 'slideshow', 'social_sharing'];
if (in_array($field, $allowed)) {
$stmt = $pdo->prepare("UPDATE gallery_settings SET $field = ? WHERE gallery_code = ?");
$stmt->execute([$value, $gallery_code]);
echo json_encode(['success' => true]);
exit;
}
echo json_encode(['success' => false]);
exit;
}
// 3. HENT INNSTILLINGER OG COVER
$stmt = $pdo->prepare("SELECT * FROM gallery_settings WHERE gallery_code = ?");
$stmt->execute([$gallery_code]);
$settings = $stmt->fetch();
$db_cover = $settings['cover_photo'] ?? '';
if (empty($db_cover)) {
$photoStmt = $pdo->prepare("SELECT file_name FROM photos WHERE gallery_code = ? ORDER BY id ASC LIMIT 1");
$photoStmt->execute([$gallery_code]);
$first_photo = $photoStmt->fetchColumn();
$cover_url = $first_photo ? "uploads/" . $first_photo : "https://via.placeholder.com/600x400?text=Ingen+bilde";
} else {
$cover_url = "uploads/" . $db_cover;
}
?>
Settings -
General Settings
Collection URL
Unique URL for visitors to access your collection.
Privacy Settings
Collection Password
Require visitors to enter this password in order to see the collection.
Download Settings
Favorite Settings
Store Settings
=== FIL: ./admin.php ===
exec("CREATE TABLE IF NOT EXISTS watermarks (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
image_path VARCHAR(255) DEFAULT '',
scale INT DEFAULT 30,
opacity INT DEFAULT 50,
position VARCHAR(10) DEFAULT 'cc'
)");
// ---------------------------------------------------------
$message = '';
$active_tab = $_GET['tab'] ?? 'collections';
// HÅNDTER LAGRING AV VANNMERKE
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_watermark'])) {
$w_id = (int)($_POST['watermark_id'] ?? 0);
$w_name = trim($_POST['watermark_name'] ?: 'Nytt vannmerke');
$w_scale = (int)$_POST['scale'];
$w_opacity = (int)$_POST['opacity'];
$w_pos = $_POST['position'];
$image_path = $_POST['existing_image'] ?? '';
// Last opp ny fil hvis valgt
if (!empty($_FILES['watermark_image']['name'])) {
$ext = pathinfo($_FILES['watermark_image']['name'], PATHINFO_EXTENSION);
$unique_name = 'wm_' . time() . '.' . $ext;
if (!file_exists('uploads/')) mkdir('uploads/', 0777, true);
if (move_uploaded_file($_FILES['watermark_image']['tmp_name'], 'uploads/' . $unique_name)) {
$image_path = $unique_name;
}
}
if ($w_id > 0) {
$stmt = $pdo->prepare("UPDATE watermarks SET name=?, image_path=?, scale=?, opacity=?, position=? WHERE id=?");
$stmt->execute([$w_name, $image_path, $w_scale, $w_opacity, $w_pos, $w_id]);
$message = "Vannmerket ble oppdatert!";
} else {
$stmt = $pdo->prepare("INSERT INTO watermarks (name, image_path, scale, opacity, position) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$w_name, $image_path, $w_scale, $w_opacity, $w_pos]);
$message = "Vannmerket ble opprettet!";
}
$active_tab = 'watermark';
}
// SLETT VANNMERKE
if (isset($_GET['delete_watermark'])) {
$del_id = (int)$_GET['delete_watermark'];
$pdo->prepare("DELETE FROM watermarks WHERE id = ?")->execute([$del_id]);
$message = "Vannmerket ble slettet.";
$active_tab = 'watermark';
}
// HÅNDTER LAGRING AV E-POSTMAL
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_template'])) {
$template_id = (int)($_POST['template_id'] ?? 0);
$template_name = trim($_POST['template_name']);
$subject = trim($_POST['subject']);
$body = trim($_POST['body']);
if ($template_id > 0) {
$stmt = $pdo->prepare("UPDATE email_templates SET template_name = ?, subject = ?, body = ? WHERE id = ?");
$stmt->execute([$template_name, $subject, $body, $template_id]);
$message = "E-postmalen ble oppdatert!";
} else {
$stmt = $pdo->prepare("INSERT INTO email_templates (template_name, subject, body) VALUES (?, ?, ?)");
$stmt->execute([$template_name, $subject, $body]);
$message = "Ny e-postmal ble opprettet!";
}
$active_tab = 'email_templates';
}
if (isset($_GET['delete_template'])) {
$del_id = (int)$_GET['delete_template'];
$pdo->prepare("DELETE FROM email_templates WHERE id = ?")->execute([$del_id]);
$message = "E-postmalen ble slettet.";
$active_tab = 'email_templates';
}
// Håndter opplasting av bilder (fra modalen)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['upload_photos'])) {
$gallery_code = trim($_POST['gallery_code']);
if (!empty($gallery_code) && !empty($_FILES['photos']['name'][0])) {
$target_dir = "uploads/";
if (!file_exists($target_dir)) mkdir($target_dir, 0777, true);
$uploaded_count = 0;
foreach ($_FILES['photos']['name'] as $key => $val) {
$original_name = basename($_FILES['photos']['name'][$key]);
$file_ext = pathinfo($original_name, PATHINFO_EXTENSION);
$unique_name = time() . '_' . $key . '.' . $file_ext;
if (move_uploaded_file($_FILES['photos']['tmp_name'][$key], $target_dir . $unique_name)) {
$stmt = $pdo->prepare("INSERT INTO photos (gallery_code, file_name, title) VALUES (?, ?, ?)");
$stmt->execute([$gallery_code, $unique_name, $original_name]);
$uploaded_count++;
}
}
$message = "Opprettet galleriet " . htmlspecialchars($gallery_code) . " med $uploaded_count bilder.";
}
}
// Hent data
$galleriesStmt = $pdo->query("SELECT p.gallery_code, COUNT(DISTINCT p.id) as total_photos, COUNT(DISTINCT f.id) as total_selections, (SELECT file_name FROM photos WHERE gallery_code = p.gallery_code ORDER BY id ASC LIMIT 1) as cover_image, MAX(p.id) as latest_id FROM photos p LEFT JOIN favorites f ON p.gallery_code = f.gallery_code GROUP BY p.gallery_code ORDER BY latest_id DESC");
$galleries = $galleriesStmt->fetchAll();
$templatesStmt = $pdo->query("SELECT * FROM email_templates ORDER BY id ASC");
$email_templates = $templatesStmt->fetchAll(PDO::FETCH_ASSOC);
$wmStmt = $pdo->query("SELECT * FROM watermarks ORDER BY id ASC");
$watermarks = $wmStmt->fetchAll(PDO::FETCH_ASSOC);
$edit_wm = null;
if (isset($_GET['edit_watermark'])) {
$active_tab = 'edit_watermark';
$w_id = (int)$_GET['edit_watermark'];
if ($w_id > 0) {
$s = $pdo->prepare("SELECT * FROM watermarks WHERE id = ?");
$s->execute([$w_id]);
$edit_wm = $s->fetch(PDO::FETCH_ASSOC);
}
}
?>
Fotograf - Collections & Settings
Watermark
Legg til og administrer dine vannmerker her. Du kan velge hvilket du vil bruke når du laster opp bilder.
Collection Sharing Email