findById((int)$_GET['id']); header('Content-Type: application/json; charset=utf-8'); echo json_encode([ 'id' => $p->id, 'title' => $p->title, 'slug' => $p->slug, 'content' => $p->content, 'image_path' => $p->image_path, 'is_active' => $p->is_active, 'show_in_menu' => $p->show_in_menu, 'show_in_footer'=> $p->show_in_footer, ], JSON_UNESCAPED_UNICODE); exit; } // 4) Load model require __DIR__ . '/includes/cms/StaticPage.php'; $model = new StaticPage($conn); // 5) Handle deletion if (isset($_GET['del'])) { $id = (int)$_GET['del']; if ($id && $page = $model->findById($id)) { $page->delete(); } header('Location: static-pages.php'); exit; } // 6) Handle form submit if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = !empty($_POST['id']) ? (int)$_POST['id'] : null; $page = $id ? $model->findById($id) : new StaticPage($conn); if (!$page) { $page = new StaticPage($conn); } // Assign $page->title = trim($_POST['title']); $page->slug = trim($_POST['slug']); $page->content = $_POST['content']; $page->is_active = !empty($_POST['is_active']); $page->show_in_menu = !empty($_POST['show_in_menu']); $page->show_in_footer = !empty($_POST['show_in_footer']); // Image upload if (!empty($_FILES['image']['tmp_name'])) { $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION); $fn = 'page_' . time() . '.' . $ext; if (move_uploaded_file($_FILES['image']['tmp_name'], UPLOADS_DIR . $fn)) { $page->image_path = UPLOADS_URL . $fn; } } // Save $page->save(); header('Location: pages.php'); exit; } // 7) Fetch all pages $pages = $model->findAll(); ?>
| כותרת | פעיל | בתפריט | בפוטר | עריכה | מחיקה |
|---|---|---|---|---|---|
| = htmlspecialchars($p->title) ?> | = $p->is_active ? 'כן' : 'לא' ?> | = $p->show_in_menu ? 'כן' : 'לא' ?> | = $p->show_in_footer ? 'כן' : 'לא' ?> | X |