Download admin/manage.php from vergen-dev/deepsite-project-de4im: direct link, hf CLI and curl.
- Browser
- Download file 17.7 kB
-
https://huggingface.co/spaces/vergen-dev/deepsite-project-de4im/resolve/main/admin/manage.php
- Command line
-
hf download hf://spaces/vergen-dev/deepsite-project-de4im/admin/manage.php
-
curl -L -o manage.php https://huggingface.co/spaces/vergen-dev/deepsite-project-de4im/resolve/main/admin/manage.php
17.7 kB
| session_start(); | |
| if (!isset($_SESSION['admin_logged_in'])) { | |
| header('Location: login.php'); | |
| exit; | |
| } | |
| require '../db_connect.php'; | |
| $section = $_GET['section'] ?? 'config'; | |
| $valid_sections = ['config', 'stats', 'services', 'founders', 'cases', 'pricing', 'faq', 'solutions', 'goals', 'roadmap', 'bottom_stats', 'about_gallery']; | |
| if (!in_array($section, $valid_sections)) { | |
| die("Sezione non valida."); | |
| } | |
| // DELETE | |
| if (isset($_GET['delete']) && $section !== 'config') { | |
| $id = (int)$_GET['delete']; | |
| $db->prepare("DELETE FROM $section WHERE id = ?")->execute([$id]); | |
| header("Location: manage.php?section=$section"); | |
| exit; | |
| } | |
| // SAVE / UPDATE | |
| $success = false; | |
| if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
| if ($section === 'config') { | |
| foreach ($_POST as $k => $v) { | |
| if ($k === 'admin_password' || $k === 'id') continue; | |
| $stmt = $db->prepare("INSERT OR REPLACE INTO config (key_name, value_text) VALUES (?, ?)"); | |
| $stmt->execute([$k, $v]); | |
| } | |
| // Handle Config Images | |
| foreach ($_FILES as $key => $file) { | |
| if ($file['error'] === UPLOAD_ERR_OK) { | |
| $ext = pathinfo($file['name'], PATHINFO_EXTENSION); | |
| $filename = "uploads/" . $key . "_" . time() . "." . $ext; | |
| if (move_uploaded_file($file['tmp_name'], "../" . $filename)) { | |
| $db->prepare("INSERT OR REPLACE INTO config (key_name, value_text) VALUES (?, ?)")->execute([$key, $filename]); | |
| } | |
| } | |
| } | |
| $success = true; | |
| } else { | |
| // Add or Edit Item | |
| $is_edit = isset($_POST['id']); | |
| $fields = []; | |
| $values = []; | |
| // Define fields based on section (same logic as before) | |
| $expected_fields = []; | |
| if($section=='stats') $expected_fields=['label','value','unit','sort_order']; | |
| if($section=='services') $expected_fields=['title','icon','description','sort_order']; | |
| if($section=='founders') $expected_fields=['name','role','image_path','sort_order']; | |
| if($section=='cases') $expected_fields=['title','stats_text','role_text','tags','image_path','sort_order']; | |
| if($section=='pricing') $expected_fields=['name','price','features','is_recommended','sort_order']; | |
| if($section=='faq') $expected_fields=['question','answer','sort_order']; | |
| if($section=='solutions') $expected_fields=['title','description','sort_order']; | |
| if($section=='goals') $expected_fields=['title','description','sort_order']; | |
| if($section=='roadmap') $expected_fields=['phase','detail','sort_order']; | |
| if($section=='bottom_stats') $expected_fields=['value','label','sort_order']; | |
| if($section=='about_gallery') $expected_fields=['image_path','sort_order']; | |
| foreach ($expected_fields as $f) { | |
| if (isset($_POST[$f])) { | |
| $fields[] = $f; | |
| $values[] = $_POST[$f]; | |
| } | |
| } | |
| // Handle File Upload for Item | |
| if (in_array('image_path', $expected_fields) && isset($_FILES['image_path']) && $_FILES['image_path']['error'] === UPLOAD_ERR_OK) { | |
| $ext = pathinfo($_FILES['image_path']['name'], PATHINFO_EXTENSION); | |
| $filename = "uploads/" . $section . "_" . time() . "." . $ext; | |
| if (move_uploaded_file($_FILES['image_path']['tmp_name'], "../" . $filename)) { | |
| if(!in_array('image_path', $fields)) { | |
| $fields[] = 'image_path'; | |
| $values[] = $filename; | |
| } else { | |
| $key = array_search('image_path', $fields); | |
| $values[$key] = $filename; | |
| } | |
| } | |
| } | |
| if ($is_edit) { | |
| $id = $_POST['id']; | |
| $set = []; | |
| foreach ($fields as $index => $field) { | |
| $set[] = "$field = ?"; | |
| } | |
| $sql = "UPDATE $section SET " . implode(', ', $set) . " WHERE id = ?"; | |
| $values[] = $id; | |
| $db->prepare($sql)->execute($values); | |
| } else { | |
| $placeholders = array_fill(0, count($fields), '?'); | |
| $sql = "INSERT INTO $section (" . implode(', ', $fields) . ") VALUES (" . implode(', ', $placeholders) . ")"; | |
| $db->prepare($sql)->execute($values); | |
| } | |
| } | |
| if ($section !== 'config') { | |
| header("Location: manage.php?section=$section"); | |
| exit; | |
| } | |
| } | |
| // FETCH DATA | |
| if ($section === 'config') { | |
| $items = []; | |
| try { | |
| $rows = $db->query("SELECT key_name, value_text FROM config")->fetchAll(PDO::FETCH_KEY_PAIR); | |
| $items = $rows; | |
| } catch (Exception $e) { | |
| die("Errore database config: " . $e->getMessage()); | |
| } | |
| } else { | |
| try { | |
| $items = $db->query("SELECT * FROM $section ORDER BY sort_order ASC")->fetchAll(); | |
| } catch (Exception $e) { | |
| die("Errore database $section: " . $e->getMessage()); | |
| } | |
| } | |
| <!DOCTYPE html> | |
| <html lang="it"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Gestisci echo ucfirst($section); β OFT Admin</title> | |
| <link href="style.css" rel="stylesheet"> | |
| <link href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;600;700;800&family=Inter:wght@400;500;600&display=swap" rel="stylesheet"> | |
| </head> | |
| <body> | |
| <div class="app-layout"> | |
| <!-- Sidebar --> | |
| <aside class="sidebar"> | |
| <div class="brand"> | |
| <span>β‘</span> OFT Admin | |
| </div> | |
| <nav> | |
| <div class="nav-section">Contenuti</div> | |
| <a href="manage.php?section=config" class="nav-link <?php if($section=='config') echo 'active'; ?>">βοΈ Configurazione</a> | |
| <a href="manage.php?section=solutions" class="nav-link <?php if($section=='solutions') echo 'active'; ?>">π‘ Soluzioni</a> | |
| <a href="manage.php?section=goals" class="nav-link <?php if($section=='goals') echo 'active'; ?>">π Obiettivi</a> | |
| <a href="manage.php?section=roadmap" class="nav-link <?php if($section=='roadmap') echo 'active'; ?>">πΊοΈ Roadmap</a> | |
| <div class="nav-section">Liste</div> | |
| <a href="manage.php?section=services" class="nav-link <?php if($section=='services') echo 'active'; ?>">π οΈ Servizi</a> | |
| <a href="manage.php?section=cases" class="nav-link <?php if($section=='cases') echo 'active'; ?>">π Case Studies</a> | |
| <a href="manage.php?section=founders" class="nav-link <?php if($section=='founders') echo 'active'; ?>">π₯ Team</a> | |
| <a href="manage.php?section=about_gallery" class="nav-link <?php if($section=='about_gallery') echo 'active'; ?>">πΌοΈ Gallery Chi Siamo</a> | |
| <a href="manage.php?section=pricing" class="nav-link <?php if($section=='pricing') echo 'active'; ?>">π Pricing</a> | |
| <a href="manage.php?section=faq" class="nav-link <?php if($section=='faq') echo 'active'; ?>">β FAQ</a> | |
| <div class="nav-section">Altro</div> | |
| <a href="manage.php?section=stats" class="nav-link <?php if($section=='stats') echo 'active'; ?>">π Statistiche</a> | |
| <a href="manage.php?section=bottom_stats" class="nav-link <?php if($section=='bottom_stats') echo 'active'; ?>">π Big Stats</a> | |
| </nav> | |
| <div style="margin-top:auto"> | |
| <a href="index.php?logout=1" class="nav-link" style="color:var(--danger)">πͺ Logout</a> | |
| </div> | |
| </aside> | |
| <!-- Main Content --> | |
| <main class="main-content"> | |
| <div class="page-header"> | |
| <div> | |
| <a href="index.php" style="color:var(--muted); font-size:12px; font-weight:700; text-transform:uppercase;">β Dashboard</a> | |
| <h1 style="text-transform:capitalize">Gestisci <?php echo str_replace('_', ' ', $section); ?></h1> | |
| </div> | |
| </div> | |
| <?php if($section === 'config'): ?> | |
| <?php if($success): ?> | |
| <div style="background:rgba(16,185,129,0.1); color:var(--success); padding:16px; border-radius:8px; margin-bottom:24px; border:1px solid var(--success)"> | |
| β Configurazione salvata con successo! | |
| </div> | |
| <?php endif; ?> | |
| <div class="panel" style="padding:32px; max-width:800px"> | |
| <form method="POST" enctype="multipart/form-data"> | |
| <?php foreach($items as $key => $val): if($key=='admin_password' || $key=='id') continue; ?> | |
| <div class="form-group"> | |
| <label><?php echo str_replace('_', ' ', $key); ?></label> | |
| <?php if(strpos($key, 'image') !== false): ?> | |
| <div style="display:flex; align-items:center; gap:12px; margin-bottom:12px; background:var(--bg); padding:10px; border-radius:8px; border:1px solid var(--border)"> | |
| <img src="../<?php echo htmlspecialchars($val); ?>" style="height:60px; width:60px; object-fit:cover; border-radius:6px;"> | |
| <div style="font-size:13px; color:var(--muted); word-break:break-all"><?php echo htmlspecialchars($val); ?></div> | |
| </div> | |
| <input type="file" name="<?php echo $key; ?>" accept="image/*"> | |
| <input type="hidden" name="<?php echo $key; ?>" value="<?php echo htmlspecialchars($val); ?>"> | |
| <?php else: ?> | |
| <input type="text" name="<?php echo $key; ?>" value="<?php echo htmlspecialchars($val); ?>"> | |
| <?php endif; ?> | |
| </div> | |
| <?php endforeach; ?> | |
| <button type="submit" class="btn">Salva Modifiche</button> | |
| </form> | |
| </div> | |
| <?php else: ?> | |
| <!-- Add New --> | |
| <div style="margin-bottom:30px"> | |
| <details> | |
| <summary class="btn" style="display:inline-flex; list-style:none"> | |
| <span>+ Aggiungi Nuovo</span> | |
| </summary> | |
| <div class="panel" style="margin-top:20px; padding:32px; max-width:700px; animation: fadeIn 0.3s ease"> | |
| <h3 style="margin-top:0">Nuovo Elemento</h3> | |
| <form method="POST" enctype="multipart/form-data"> | |
| <!-- Fields based on section --> | |
| <?php | |
| $fields = []; | |
| if($section=='stats') $fields=['label','value','unit','sort_order']; | |
| if($section=='services') $fields=['title','icon','description','sort_order']; | |
| if($section=='founders') $fields=['name','role','image_path','sort_order']; | |
| if($section=='cases') $fields=['title','stats_text','role_text','tags','image_path','sort_order']; | |
| if($section=='pricing') $fields=['name','price','features','is_recommended','sort_order']; | |
| if($section=='faq') $fields=['question','answer','sort_order']; | |
| if($section=='solutions') $fields=['title','description','sort_order']; | |
| if($section=='goals') $fields=['title','description','sort_order']; | |
| if($section=='roadmap') $fields=['phase','detail','sort_order']; | |
| if($section=='bottom_stats') $fields=['value','label','sort_order']; | |
| if($section=='about_gallery') $fields=['image_path','sort_order']; | |
| foreach($fields as $f): ?> | |
| <div class="form-group"> | |
| <label><?php echo str_replace('_', ' ', $f); ?></label> | |
| <?php if($f == 'description' || $f == 'answer' || $f == 'features'): ?> | |
| <textarea name="<?php echo $f; ?>" rows="4"></textarea> | |
| <?php elseif($f == 'image_path'): ?> | |
| <input type="file" name="<?php echo $f; ?>" accept="image/*"> | |
| <?php else: ?> | |
| <input type="text" name="<?php echo $f; ?>" value="<?php echo ($f=='sort_order')?'0':''; ?>"> | |
| <?php endif; ?> | |
| </div> | |
| <?php endforeach; ?> | |
| <button type="submit" class="btn">Aggiungi Elemento</button> | |
| </form> | |
| </div> | |
| </details> | |
| </div> | |
| <!-- List Panel --> | |
| <div class="panel"> | |
| <?php foreach($items as $row): ?> | |
| <div class="list-item"> | |
| <?php if(isset($row['image_path'])): ?> | |
| <img src="../<?php echo htmlspecialchars($row['image_path']); ?>" class="item-image"> | |
| <?php endif; ?> | |
| <div class="item-content"> | |
| <span class="item-title"> | |
| <?php echo htmlspecialchars(reset($row)); // fallback ?> | |
| <?php echo isset($row['title']) ? $row['title'] : (isset($row['name']) ? $row['name'] : (isset($row['label']) ? $row['label'] : (isset($row['question']) ? $row['question'] : ''))); ?> | |
| </span> | |
| <div class="item-meta"> | |
| Ordine: <?php echo $row['sort_order']; ?> | |
| </div> | |
| </div> | |
| <div style="display:flex; gap:10px; align-items:center"> | |
| <details> | |
| <summary class="btn btn-outline" style="padding:6px 12px; font-size:12px">Modifica</summary> | |
| <div style="position:fixed; inset:0; background:rgba(0,0,0,0.8); z-index:999; display:flex; align-items:center; justify-content:center; padding:20px"> | |
| <div class="panel" style="width:100%; max-width:600px; padding:32px; position:relative; max-height:90vh; overflow-y:auto"> | |
| <div style="position:absolute; top:20px; right:20px; cursor:pointer" onclick="this.closest('details').removeAttribute('open')">β</div> | |
| <h3 style="margin-top:0">Modifica Elemento</h3> | |
| <form method="POST" enctype="multipart/form-data"> | |
| <input type="hidden" name="id" value="<?php echo $row['id']; ?>"> | |
| <?php foreach($fields as $f): ?> | |
| <div class="form-group"> | |
| <label><?php echo str_replace('_', ' ', $f); ?></label> | |
| <?php if($f == 'description' || $f == 'answer' || $f == 'features'): ?> | |
| <textarea name="<?php echo $f; ?>" rows="4"><?php echo htmlspecialchars($row[$f]); ?></textarea> | |
| <?php elseif($f == 'image_path'): ?> | |
| <div style="display:flex; align-items:center; gap:12px; margin-bottom:10px"> | |
| <img src="../<?php echo htmlspecialchars($row[$f]); ?>" style="height:40px; border-radius:4px"> | |
| </div> | |
| <input type="file" name="<?php echo $f; ?>" accept="image/*"> | |
| <?php else: ?> | |
| <input type="text" name="<?php echo $f; ?>" value="<?php echo htmlspecialchars($row[$f]); ?>"> | |
| <?php endif; ?> | |
| </div> | |
| <?php endforeach; ?> | |
| <button type="submit" class="btn">Salva Modifiche</button> | |
| </form> | |
| </div> | |
| </div> | |
| </details> | |
| <a href="?section=<?php echo $section; ?>&delete=<?php echo $row['id']; ?>" class="btn-danger" style="padding:8px 12px; border-radius:6px; font-size:12px; text-decoration:none" onclick="return confirm('Sicuro di voler eliminare?')">Elimina</a> | |
| </div> | |
| </div> | |
| <?php endforeach; ?> | |
| <?php if(empty($items)): ?> | |
| <div style="padding:40px; text-align:center; color:var(--muted)"> | |
| Nessun elemento presente. | |
| </div> | |
| <?php endif; ?> | |
| </div> | |
| <?php endif; ?> | |
| </main> | |
| </div> | |
| </body> | |
| </html> | |