diff --git a/add_paper.php b/add_paper.php new file mode 100644 index 0000000..08e1626 --- /dev/null +++ b/add_paper.php @@ -0,0 +1,66 @@ + +prepare("INSERT INTO papers (title, authors, publication, year, notes) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$title, $authors, $publication, $year, $notes]); + header("Location: /?toast=" . urlencode('Paper added successfully!')); + exit; + } catch (PDOException $e) { + // In a real app, you'd log this error. + header("Location: /add_paper.php?toast=" . urlencode('Error adding paper.')); + exit; + } + } +} + +include 'partials/header.php'; +?> + +
+
+
+
+
+ Icon of a document or a book +

Add a New Paper

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+ + diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..f7dcb1c --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,61 @@ + +/* General Body Styles */ +body { + font-family: 'Inter', sans-serif; + background-color: #f8f9fa; + color: #343a40; +} + +/* Typography */ +h1, h2, h3, h4, h5, h6 { + font-family: 'Playfair Display', serif; + font-weight: 700; +} + +/* Buttons */ +.btn-primary { + background-image: linear-gradient(45deg, #007bff, #0056b3); + border: none; + transition: transform 0.2s; +} + +.btn-primary:hover { + transform: translateY(-2px); + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); +} + +/* Cards */ +.card { + border-radius: 0.5rem; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05); +} + +/* Header */ +.hero { + background: url('https://picsum.photos/1600/400') no-repeat center center; + background-size: cover; + color: white; + padding: 4rem 0; + text-align: center; +} + +.hero h1 { + font-size: 3.5rem; + text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); +} + +/* Form */ +.form-container { + background: white; + padding: 2rem; + border-radius: 0.5rem; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); +} + +/* Toast Notifications */ +.toast-container { + position: fixed; + top: 1rem; + right: 1rem; + z-index: 1050; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..a18f5f2 --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,45 @@ + +// Client-side validation for the add paper form +document.addEventListener('DOMContentLoaded', () => { + const form = document.querySelector('#add-paper-form'); + if (form) { + form.addEventListener('submit', (event) => { + let isValid = true; + const requiredFields = form.querySelectorAll('[required]'); + requiredFields.forEach(field => { + if (!field.value) { + isValid = false; + field.classList.add('is-invalid'); + } else { + field.classList.remove('is-invalid'); + } + }); + + if (!isValid) { + event.preventDefault(); + alert('Please fill out all required fields.'); + } + }); + } + + // Show toast from URL parameter + const urlParams = new URLSearchParams(window.location.search); + const toastMessage = urlParams.get('toast'); + if (toastMessage) { + const toastContainer = document.querySelector('.toast-container'); + if (toastContainer) { + const toast = ` + + `; + toastContainer.innerHTML = toast; + } + } +}); diff --git a/assets/vm-shot-2025-10-07T17-01-12-455Z.jpg b/assets/vm-shot-2025-10-07T17-01-12-455Z.jpg new file mode 100644 index 0000000..7cd944e Binary files /dev/null and b/assets/vm-shot-2025-10-07T17-01-12-455Z.jpg differ diff --git a/db/config.php b/db/config.php index bb98f7d..82f2f5e 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,35 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; + static $pdoconn = null; + if ($pdoconn === null) { + $host = '127.0.0.1'; + $db = 'lamp_app'; + $user = 'lamp_user'; + $pass = ''; + $charset = 'utf8mb4'; + + $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; + $options = [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]; + try { + $pdoconn = new PDO($dsn, $user, $pass, $options); + } catch (\PDOException $e) { + throw new \PDOException($e->getMessage(), (int)$e->getCode()); + } + } + return $pdoconn; } + +function run_migrations() { + $pdo = db(); + $migration_files = glob(__DIR__ . '/migrations/*.sql'); + foreach ($migration_files as $file) { + $sql = file_get_contents($file); + $pdo->exec($sql); + } +} + +run_migrations(); \ No newline at end of file diff --git a/db/migrations/001_create_papers_table.sql b/db/migrations/001_create_papers_table.sql new file mode 100644 index 0000000..2e59062 --- /dev/null +++ b/db/migrations/001_create_papers_table.sql @@ -0,0 +1,10 @@ + +CREATE TABLE IF NOT EXISTS papers ( + id INT AUTO_INCREMENT PRIMARY KEY, + title VARCHAR(255) NOT NULL, + authors VARCHAR(255) NOT NULL, + publication VARCHAR(255), + year INT, + notes TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/delete_paper.php b/delete_paper.php new file mode 100644 index 0000000..274d3ff --- /dev/null +++ b/delete_paper.php @@ -0,0 +1,31 @@ +prepare("SELECT id FROM papers WHERE id = ?"); +$stmt->execute([$paper_id]); +if ($stmt->rowCount() === 0) { + // Paper not found, maybe already deleted + header("Location: index.php?error=notfound"); + exit; +} + +// Delete the paper +try { + $stmt = $pdo->prepare("DELETE FROM papers WHERE id = ?"); + $stmt->execute([$paper_id]); + header("Location: index.php?success=deleted"); + exit; +} catch (PDOException $e) { + // Log error if you have a logging system + header("Location: index.php?error=deletfailed"); + exit; +} diff --git a/edit_paper.php b/edit_paper.php new file mode 100644 index 0000000..46b7d36 --- /dev/null +++ b/edit_paper.php @@ -0,0 +1,99 @@ +prepare("SELECT * FROM papers WHERE id = ?"); +$stmt->execute([$paper_id]); +$paper = $stmt->fetch(); + +if (!$paper) { + header("Location: index.php"); + exit; +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $title = trim($_POST['title'] ?? ''); + $authors = trim($_POST['authors'] ?? ''); + $publication = trim($_POST['publication'] ?? ''); + $year = filter_input(INPUT_POST, 'year', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1900, 'max_range' => date('Y') + 1]]); + $notes = trim($_POST['notes'] ?? ''); + + if (empty($title) || empty($authors)) { + $feedback = ['type' => 'danger', 'message' => 'Title and Authors are required.']; + } elseif ($year === false) { + $feedback = ['type' => 'danger', 'message' => 'Invalid year.']; + } else { + try { + $stmt = $pdo->prepare("UPDATE papers SET title = ?, authors = ?, publication = ?, year = ?, notes = ? WHERE id = ?"); + $stmt->execute([$title, $authors, $publication, $year, $notes, $paper_id]); + header("Location: index.php?success=updated"); + exit; + } catch (PDOException $e) { + $feedback = ['type' => 'danger', 'message' => 'Error updating paper: ' . $e->getMessage()]; + } + } + // To show feedback on the same page, we need to repopulate the paper variable with submitted data + $paper['title'] = $title; + $paper['authors'] = $authors; + $paper['publication'] = $publication; + $paper['year'] = $year; + $paper['notes'] = $notes; +} +?> + +
+
+
+
+
+

Edit Paper

+
+
+ +
+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + Cancel +
+
+
+
+
+
+ + diff --git a/index.php b/index.php index 7205f3d..d2dbe10 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,135 @@ prepare("SELECT COUNT(*) FROM papers WHERE title LIKE :search OR authors LIKE :search OR publication LIKE :search"); + $count_stmt->execute(['search' => "%$search%"]); +} else { + $count_stmt = $pdo->query("SELECT COUNT(*) FROM papers"); +} +$total_papers = $count_stmt->fetchColumn(); +$total_pages = ceil($total_papers / $papers_per_page); + +// Get papers for the current page +if ($search) { + $stmt = $pdo->prepare("SELECT * FROM papers WHERE title LIKE :search OR authors LIKE :search OR publication LIKE :search ORDER BY created_at DESC LIMIT :limit OFFSET :offset"); + $stmt->bindValue(':search', "%$search%", PDO::PARAM_STR); + $stmt->bindValue(':limit', $papers_per_page, PDO::PARAM_INT); + $stmt->bindValue(':offset', $offset, PDO::PARAM_INT); + $stmt->execute(); +} else { + $stmt = $pdo->prepare("SELECT * FROM papers ORDER BY created_at DESC LIMIT :limit OFFSET :offset"); + $stmt->bindValue(':limit', $papers_per_page, PDO::PARAM_INT); + $stmt->bindValue(':offset', $offset, PDO::PARAM_INT); + $stmt->execute(); +} + +$papers = $stmt->fetchAll(); ?> - - - - - - New Style - - - - - - - - - - - - - - - - - - - - - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ +
+
+

Your Paper Collection

+

A central place to manage all your academic papers.

+ Add a New Paper
-
- - - + + +
+ 'success', 'message' => 'Paper deleted successfully.']; + } + if ($_GET['success'] === 'updated') { + $feedback = ['type' => 'success', 'message' => 'Paper updated successfully.']; + } + } + if (isset($_GET['error'])) { + if ($_GET['error'] === 'notfound') { + $feedback = ['type' => 'danger', 'message' => 'Paper not found.']; + } + if ($_GET['error'] === 'deletfailed') { + $feedback = ['type' => 'danger', 'message' => 'Error deleting paper.']; + } + } + ?> + + + + +
+
+ + +
+
+ +

Recently Added

+
+ +
+

No papers added yet. Add your first one!

+
+ + +
+
+
+
+
+

+ + Publication:
+ + + Year:
+ + + Notes: 100 ? '...' : '') ?>
+ +

+
+ Edit + Delete +
+
+
+
+ + +
+ + + 1): ?> + + +
+ + \ No newline at end of file diff --git a/partials/footer.php b/partials/footer.php new file mode 100644 index 0000000..364fd6c --- /dev/null +++ b/partials/footer.php @@ -0,0 +1,12 @@ + + + + + + + diff --git a/partials/header.php b/partials/header.php new file mode 100644 index 0000000..52f55a8 --- /dev/null +++ b/partials/header.php @@ -0,0 +1,45 @@ + + + + + + + Paper CRM + + + + + + + + + + + + + + + +
+ +
diff --git a/privacy.php b/privacy.php new file mode 100644 index 0000000..1fe192c --- /dev/null +++ b/privacy.php @@ -0,0 +1,9 @@ + + + +
+

Privacy Policy

+

This is a placeholder for your privacy policy.

+
+ + diff --git a/sitemap.xml b/sitemap.xml new file mode 100644 index 0000000..02ee735 --- /dev/null +++ b/sitemap.xml @@ -0,0 +1,16 @@ + + + + + / + 1.0 + + + /add_paper.php + 0.8 + + + /privacy.php + 0.5 + +