storeFormValues($_POST); $article->insert(); header("Location: admin.php?status=saved"); } elseif (isset($_POST['cancel'])) { header("Location: admin.php"); } else { $results['article'] = new Article; require("edit.php"); } } function edit() { $results = array(); $results['pageTitle'] = "Edit Article"; $result['form'] = "edit"; if (isset($_POST['save'])) { if (!$article = Article::getById((int)$_POST['id'])) { header( "Location: admin.php?error=notFound" ); return; } $article->storeFormValues($_POST); $article->update(); header("Location: admin.php?status=saved"); } elseif (isset($_POST['cancel'])) { header("Location: admin.php"); } else { $results['article'] = Article::getById((int)$_GET['article']); require("edit.php"); } } function delete() { if (!$article = Article::getById((int) $_GET['article'])) { header("Location: admin.php?error=notFound"); return; } $article->delete(); header("Location: admin.php?status=deleted"); } function listArticles() { $results = array(); $data = Article::getList(); // print_r($data); $results['articles'] = $data; // $results['totalRows'] = $data['totalRows']; $results['pageTitle'] = "All Articles"; if (isset($_GET['error'])) { if ($_GET['error'] == "notFound") { $results['error'] = "Error: Article not found."; } } if (isset( $_GET['status'])) { if ($_GET['status'] == "saved") $results['status'] = "Your changes have been saved."; if ($_GET['status'] == "deleted") $results['status'] = "Article deleted."; } require("list.php"); } ?>