diff --git a/archive/index-old.php b/archive/index-old.php new file mode 100644 index 0000000..71d55bc --- /dev/null +++ b/archive/index-old.php @@ -0,0 +1,215 @@ +query("SELECT +books.id AS id, +books.title AS title, +authors.name AS author +FROM books +INNER JOIN books_authors_link ON books.id = books_authors_link.book +INNER JOIN authors on authors.id = books_authors_link.author +ORDER BY books.id DESC +LIMIT 4"); + +$types = $db->query("SELECT +value +FROM custom_column_1 +ORDER BY value ASC"); + +?> + + + + + + + + + + + <?php echo $SiteName.': '.$SubName;?> + + ';?> + + + + + + + ';?> + + ';?> + + ';?> + + ';?> + + ';?> + + ';?> + + ';?> + + ';?> + + + + + + + + + + + + + + + + + + + + + + + + +
+ Close +
+
+ Infopump Avatar +
+

About the Project

+

Infopump

+

A bibliographic management and display system.
More info

+
+

A free, open source project from:
+ The L0WL1F3 Podcast
+ Neon Dystopia
+ Cyberpunk Librarian +

+
+

+ GitLab +

+ +
+ +
+
+

Recent Additions

+
    + fetchArray()) { + $row_value = $row['value']; + $row_titlecase = mb_convert_case($row_value, MB_CASE_TITLE, "UTF-8"); + echo '
  • '.$row_titlecase.'
  • '; + //echo '
  • '.$row_value.'
  • '; + + } + + ?> +
+ +
+
+

Search

+
+
+ +
+
+
+
+
+ +
+ +
+ +
+ +
    + +
+
+

Infopump - Cyberpunk Culture Database

+

Latest Additions

+
+ +
+ +
+ +
+ + + +
+
+ + fetchArray()) { + $row_id = $row['id']; + $row_title = $row['title']; + $row_author = $row['author']; + + echo '
'; + echo '
'; + echo ''; + echo '
'; + echo '

'.$row_title.'

'; + echo ''.$row_author.''; + echo '
'; + } + ?> +
+
+ + + + + + + + + + + + + + + + + + + + diff --git a/archive/itemrecord-old.php b/archive/itemrecord-old.php new file mode 100644 index 0000000..927a975 --- /dev/null +++ b/archive/itemrecord-old.php @@ -0,0 +1,502 @@ +query("SELECT id, title, date(timestamp), author_sort, strftime('%Y',pubdate) AS pubyear, date(last_modified) FROM books WHERE id = '$ItemID'"); + +while ($row = $book->fetchArray()) { + $row_id = $row['id']; + $row_title = $row['title']; + $row_created = $row['date(timestamp)']; + $row_author_sort = $row['author_sort']; + $row_pubdate = $row['pubyear']; + $row_modified = $row['date(last_modified)']; +} + +// ---------- Pull data from authors table ---------- +$author = $db->query("SELECT name FROM authors +INNER JOIN books_authors_link +ON books_authors_link.author = authors.id +WHERE books_authors_link.book = '$ItemID'"); + +while ($row = $author->fetchArray()) { + $row_creator = $row['name']; +} + +// ---------- Pull data from comments table ---------- +$summary = $db->query("SELECT text FROM comments WHERE book = '$ItemID'"); + +while ($row = $summary->fetchArray()) { + $row_summary = $row['text']; +} + +// ---------- Pull data from publishers table ---------- + +$publisher = $db->query("SELECT name from publishers +INNER JOIN books_publishers_link +ON books_publishers_link.publisher = publishers.id +WHERE books_publishers_link.book = '$ItemID'"); + +while ($row = $publisher->fetchArray()) { + $row_publisher = $row['name']; +} + +// ---------- Pull data from tags table ---------- + +$tags = $db->query("SELECT name FROM tags +INNER JOIN books_tags_link +ON books_tags_link.tag = tags.id +WHERE tags.name NOT LIKE 'infopump%' +AND books_tags_link.book = '$ItemID'"); + +// ---------- Pull data from tags table for Similar items ---------- + +// New similar tags query +$similartags = $db->query("SELECT name FROM tags +WHERE name IN (SELECT name FROM tags +INNER JOIN books_tags_link +ON books_tags_link.tag = tags.id +AND books_tags_link.book = '$ItemID' +ORDER BY RANDOM() LIMIT 2)"); + +$simtag = array(); + +while($row = $similartags->fetchArray()) { + $simtag[] = $row['name']; +} + +$getsimilar = $db->query("SELECT books.id, title, author_sort +FROM books +INNER JOIN books_tags_link +ON books_tags_link.book = books.id +INNER JOIN tags +ON tags.id = books_tags_link.tag +WHERE (tags.name LIKE '$simtag[0]' +OR tags.name LIKE '$simtag[1]') +AND books.id != '$ItemID' LIMIT 4"); + + +// ---------- Pull data from identifiers table ---------- + +$identifiers = $db->query("SELECT type, val FROM identifiers WHERE book = '$ItemID'"); + +// ---------- Pull data from languages table ---------- + +$languages = $db->query("SELECT languages.lang_code AS lang_code FROM languages +INNER JOIN books_languages_link +ON books_languages_link.lang_code = languages.id +WHERE book = '$ItemID' +ORDER BY books_languages_link.item_order"); + +// ---------- Pull data from tags table to dertermine type ---------- + +$type = $db->query("SELECT custom_column_1.value AS itemtype +FROM books_custom_column_1_link +INNER JOIN custom_column_1 +ON custom_column_1.id = books_custom_column_1_link.value +WHERE books_custom_column_1_link.book = '$ItemID'"); + +while ($row = $type->fetchArray()) { + $row_type = mb_convert_case($row['itemtype'], MB_CASE_TITLE, "UTF-8"); +} + +// ---------- Pull series information ---------- + +$series = $db->query("SELECT series.name AS series, books.series_index AS seriesindex +FROM series +INNER JOIN books_series_link +ON books_series_link.series = series.id +INNER JOIN books +ON books.id = books_series_link.book +WHERE books_series_link.book = '$ItemID'"); + +while ($row = $series->fetchArray()) { + $row_series = $row['series']; + $row_seriesindex = $row['seriesindex']; +} + +// ---------- Pull publisher location information ---------- + +$publisher_location = $db->query("SELECT custom_column_2.value AS publoc +FROM books +INNER JOIN +books_custom_column_2_link +ON books_custom_column_2_link.book = books.id +INNER JOIN +custom_column_2 +ON custom_column_2.id = books_custom_column_2_link.value +WHERE +books.id = '$ItemID'"); + +while ($row = $publisher_location->fetchArray()) { + $row_publocation = $row['publoc']; +} + +// ---------- Pull subtype information ---------- + +$subtype = $db->query("SELECT custom_column_3.value AS subtype +FROM books +INNER JOIN +books_custom_column_3_link +ON books_custom_column_3_link.book = books.id +INNER JOIN +custom_column_3 +ON custom_column_3.id = books_custom_column_3_link.value +WHERE +books.id = '$ItemID'"); + +while ($row = $subtype->fetchArray()) { + $row_subtype = $row['subtype']; +} + + + +// -------------------- END DATABASE QUERIES -------------------- + +?> + + + + + + '; ?> + + + + + ';?> + + '; ?> + + '; ?> + + '; ?> + + '; ?> + + '; ?> + + '; ?> + + '; ?> + + + + + + '; ?> + + '; ?> + + '; ?> + + fetchArray()) { + $row_id_type = $row['type']; + $row_id_val = $row['val']; + if ($row_id_type == 'isbn') { + echo ''; + } + } + ?> + + Item Record: '.$row_title.''; ?> + + + + + + + + + + + + + +
+
+
+
<?php echo $row_title; ?>
+
+
+

+
+ '; + echo 'Number '.$row_seriesindex.' in the '.$row_series.' series
'; + echo '
'; + } else { + echo '
'; + } + ?> +
+

+
+ +
+
+
+
+
+ +

Bibliographic Citations


+

Note: You may need to slightly edit citations for final use. Citations are based upon available data. Refer to your format guides for proper bibliographic citations.

+ + + + '.$row_author_sort.'. '.$row_title.'. '.$row_publocation.': '.$row_publisher.', '.$row_pubdate.'.
'; + echo ''; + } elseif ($row_type == 'Music') { + echo ''; + } else { + echo ''; + } + ?> + Copy Chicago citation

+ + + +
+ + + + '.$APA_author[0].', '.$APA_first.'. ('.$row_pubdate.'). '.$row_title.'. '.$row_publisher.'.

'; + echo ''; + } elseif ($row_type == 'Music') { + echo ''; + echo ''; + } else { + echo ''; + echo ''; + } + ?> + Copy APA citation

+ + + +
+ + + + '.$row_author_sort.'. '.$row_title.'. '.$row_publisher.', '.$row_pubdate.'.
'; + echo ''; + } elseif ($row_type == 'Music') { + echo ''; + } else { + echo ''; + } + + ?> + Copy MLA citation

+ + +
+ + +
+

Metadata

+ +
+ +
+
+
+ +
+
+

Similar items

+
+ fetchArray()) { + $row_simbookid = $row['id']; + $row_simtitle = $row['title']; + $row_simauthorsort = $row['author_sort']; + echo '
'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo '
'; + echo '
'; + echo ''; + echo '
'.$row_simtitle.'
'; + echo ''; + echo $row_simauthorsort; + echo '
'; + echo '
'; + echo ''; + echo ''; + echo '
'; + + + + echo '
'; + } + ?> +
+
+
+ + + + + + + + diff --git a/index.php b/index.php index 71d55bc..2a21333 100644 --- a/index.php +++ b/index.php @@ -1,28 +1,78 @@ query("SELECT -books.id AS id, -books.title AS title, -authors.name AS author -FROM books -INNER JOIN books_authors_link ON books.id = books_authors_link.book -INNER JOIN authors on authors.id = books_authors_link.author -ORDER BY books.id DESC -LIMIT 4"); +try { + // Set up Calibre database connection with error handling + if (!file_exists('metadata.sqlite')) { + throw new Exception('Database file not found'); + } + + $db = new SQLite3('metadata.sqlite'); + if (!$db) { + throw new Exception('Unable to open database'); + } + + // Set timeout to prevent locks + $db->busyTimeout(5000); + + // Get featured items (latest 4 by timestamp, not ID) + $feature = $db->query(" + SELECT + books.id AS id, + books.title AS title, + authors.name AS author + FROM books + INNER JOIN books_authors_link ON books.id = books_authors_link.book + INNER JOIN authors ON authors.id = books_authors_link.author + ORDER BY books.timestamp DESC + LIMIT 4 + "); + + if (!$feature) { + throw new Exception('Failed to fetch featured items'); + } + + // Get types for menu + $types = $db->query(" + SELECT value + FROM custom_column_1 + ORDER BY value ASC + "); + + if (!$types) { + throw new Exception('Failed to fetch types'); + } + +} catch (Exception $e) { + error_log('Database error in index.php: ' . $e->getMessage()); + // Display user-friendly error + $error_message = 'Unable to load content. Please try again later.'; +} -$types = $db->query("SELECT -value -FROM custom_column_1 -ORDER BY value ASC"); +/** + * Safely escape output for HTML + */ +function esc_html($text) { + return htmlspecialchars($text ?? '', ENT_QUOTES, 'UTF-8'); +} +/** + * Safely escape output for HTML attributes + */ +function esc_attr($text) { + return htmlspecialchars($text ?? '', ENT_QUOTES, 'UTF-8'); +} ?> - - @@ -31,68 +81,49 @@ ORDER BY value ASC"); - <?php echo $SiteName.': '.$SubName;?> + <?php echo esc_html($SiteName . ': ' . $SubName); ?> - ';?> - - + + + - - - - ';?> - - ';?> - - ';?> - - ';?> - - ';?> - - ';?> - - ';?> - - ';?> - - + + + + + + + + + + - - - + + + + + - - - - - - + + + + +
Close
@@ -101,22 +132,17 @@ ORDER BY value ASC");

About the Project

Infopump

-

A bibliographic management and display system.
More info

+

A bibliographic management and display system.
More info


-

A free, open source project from:
- The L0WL1F3 Podcast
- Neon Dystopia
+

A free, open source project from:
+ The L0WL1F3 Podcast
+ Neon Dystopia
Cyberpunk Librarian


GitLab

-
@@ -124,81 +150,85 @@ ORDER BY value ASC");

Recent Additions

-

Search

- +
+
-
-
-
    - -
-
-
-
- -
-
- - fetchArray()) { - $row_id = $row['id']; - $row_title = $row['title']; - $row_author = $row['author']; + +
+
+ fetchArray()) { + $row_id = (int)$row['id']; + $row_title = $row['title']; + $row_author = $row['author']; + + // Check if image exists, otherwise use placeholder + $image_path = "images/{$row_id}.jpg"; + if (!file_exists($image_path)) { + $image_path = "images/placeholder.jpg"; + } - echo '
'; - echo '
'; - echo ''; - echo '
'; - echo '

'.$row_title.'

'; - echo ''.$row_author.''; - echo '
'; - } - ?> -
-
- + echo ''; + } + } else { + echo '

No items found.

'; + } + ?> +
+
+ - - @@ -212,4 +242,9 @@ ORDER BY value ASC"); - +close(); +} +?> \ No newline at end of file diff --git a/itemrecord.php b/itemrecord.php index 927a975..a43b8c3 100644 --- a/itemrecord.php +++ b/itemrecord.php @@ -1,502 +1,612 @@ query("SELECT id, title, date(timestamp), author_sort, strftime('%Y',pubdate) AS pubyear, date(last_modified) FROM books WHERE id = '$ItemID'"); - -while ($row = $book->fetchArray()) { - $row_id = $row['id']; - $row_title = $row['title']; - $row_created = $row['date(timestamp)']; - $row_author_sort = $row['author_sort']; - $row_pubdate = $row['pubyear']; - $row_modified = $row['date(last_modified)']; +/** + * Safely escape output for HTML + */ +function esc_html($text) { + return htmlspecialchars($text ?? '', ENT_QUOTES, 'UTF-8'); } -// ---------- Pull data from authors table ---------- -$author = $db->query("SELECT name FROM authors -INNER JOIN books_authors_link -ON books_authors_link.author = authors.id -WHERE books_authors_link.book = '$ItemID'"); - -while ($row = $author->fetchArray()) { - $row_creator = $row['name']; +/** + * Safely escape output for HTML attributes + */ +function esc_attr($text) { + return htmlspecialchars($text ?? '', ENT_QUOTES, 'UTF-8'); } -// ---------- Pull data from comments table ---------- -$summary = $db->query("SELECT text FROM comments WHERE book = '$ItemID'"); - -while ($row = $summary->fetchArray()) { - $row_summary = $row['text']; +/** + * Generate Chicago citation + */ +function generate_chicago_citation($type, $author_sort, $title, $location, $publisher, $pubdate) { + if ($type == 'Text') { + return "{$author_sort}. {$title}. {$location}: {$publisher}, {$pubdate}."; + } elseif ($type == 'Music') { + return "{$author_sort}, {$title}. {$publisher}, {$pubdate}."; + } else { + return "{$author_sort}, director. {$title}. {$publisher}, {$pubdate}."; + } } -// ---------- Pull data from publishers table ---------- - -$publisher = $db->query("SELECT name from publishers -INNER JOIN books_publishers_link -ON books_publishers_link.publisher = publishers.id -WHERE books_publishers_link.book = '$ItemID'"); - -while ($row = $publisher->fetchArray()) { - $row_publisher = $row['name']; +/** + * Generate APA citation + */ +function generate_apa_citation($type, $author_sort, $title, $publisher, $pubdate, $creator) { + $name_parts = explode(', ', $author_sort); + $last_name = $name_parts[0] ?? ''; + $first_initial = isset($name_parts[1]) ? mb_substr($name_parts[1], 0, 1) : ''; + + if ($type == 'Text') { + return "{$last_name}, {$first_initial}. ({$pubdate}). {$title}. {$publisher}."; + } elseif ($type == 'Music') { + return "{$creator}. ({$pubdate}). {$title} [Album]. {$publisher}."; + } else { + return "{$last_name}, {$first_initial}. (Director). ({$pubdate}). {$title} [Film]. {$publisher}."; + } } -// ---------- Pull data from tags table ---------- - -$tags = $db->query("SELECT name FROM tags -INNER JOIN books_tags_link -ON books_tags_link.tag = tags.id -WHERE tags.name NOT LIKE 'infopump%' -AND books_tags_link.book = '$ItemID'"); - -// ---------- Pull data from tags table for Similar items ---------- - -// New similar tags query -$similartags = $db->query("SELECT name FROM tags -WHERE name IN (SELECT name FROM tags -INNER JOIN books_tags_link -ON books_tags_link.tag = tags.id -AND books_tags_link.book = '$ItemID' -ORDER BY RANDOM() LIMIT 2)"); - -$simtag = array(); - -while($row = $similartags->fetchArray()) { - $simtag[] = $row['name']; +/** + * Generate MLA citation + */ +function generate_mla_citation($type, $author_sort, $title, $publisher, $pubdate) { + if ($type == 'Text' || $type == 'Music') { + return "{$author_sort}. {$title}. {$publisher}, {$pubdate}."; + } else { + return "{$author_sort}, director. {$title}. {$publisher}, {$pubdate}."; + } } -$getsimilar = $db->query("SELECT books.id, title, author_sort -FROM books -INNER JOIN books_tags_link -ON books_tags_link.book = books.id -INNER JOIN tags -ON tags.id = books_tags_link.tag -WHERE (tags.name LIKE '$simtag[0]' -OR tags.name LIKE '$simtag[1]') -AND books.id != '$ItemID' LIMIT 4"); +// Initialize variables +$ItemID = null; +$db = null; +$error_message = null; +// Data arrays to store results +$book_data = []; +$identifiers = []; +$languages = []; +$tags = []; +$similar_items = []; -// ---------- Pull data from identifiers table ---------- - -$identifiers = $db->query("SELECT type, val FROM identifiers WHERE book = '$ItemID'"); - -// ---------- Pull data from languages table ---------- - -$languages = $db->query("SELECT languages.lang_code AS lang_code FROM languages -INNER JOIN books_languages_link -ON books_languages_link.lang_code = languages.id -WHERE book = '$ItemID' -ORDER BY books_languages_link.item_order"); - -// ---------- Pull data from tags table to dertermine type ---------- - -$type = $db->query("SELECT custom_column_1.value AS itemtype -FROM books_custom_column_1_link -INNER JOIN custom_column_1 -ON custom_column_1.id = books_custom_column_1_link.value -WHERE books_custom_column_1_link.book = '$ItemID'"); - -while ($row = $type->fetchArray()) { - $row_type = mb_convert_case($row['itemtype'], MB_CASE_TITLE, "UTF-8"); +try { + // Validate and sanitize ItemID - CRITICAL for SQL injection prevention + if (!isset($_GET["itemid"]) || !is_numeric($_GET["itemid"])) { + throw new Exception('Invalid item ID'); + } + + $ItemID = (int)$_GET["itemid"]; + + if ($ItemID <= 0) { + throw new Exception('Invalid item ID'); + } + + // Check if database exists + if (!file_exists('metadata.sqlite')) { + throw new Exception('Database file not found'); + } + + // Establish database connection + $db = new SQLite3('metadata.sqlite'); + if (!$db) { + throw new Exception('Unable to open database'); + } + + $db->busyTimeout(5000); + + // Pull data from books table - Using parameterized query for safety + $stmt = $db->prepare(" + SELECT + id, + title, + date(timestamp) as created, + author_sort, + strftime('%Y',pubdate) AS pubyear, + date(last_modified) as modified + FROM books + WHERE id = :itemid + "); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $book_data = $row; + } else { + throw new Exception('Item not found'); + } + + // Pull author data + $stmt = $db->prepare(" + SELECT name + FROM authors + INNER JOIN books_authors_link ON books_authors_link.author = authors.id + WHERE books_authors_link.book = :itemid + "); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $book_data['creator'] = $row['name']; + } + + // Pull summary/comments + $stmt = $db->prepare("SELECT text FROM comments WHERE book = :itemid"); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $book_data['summary'] = $row['text']; + } + + // Pull publisher + $stmt = $db->prepare(" + SELECT name + FROM publishers + INNER JOIN books_publishers_link ON books_publishers_link.publisher = publishers.id + WHERE books_publishers_link.book = :itemid + "); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $book_data['publisher'] = $row['name']; + } + + // Pull tags (excluding infopump internal tags) + $stmt = $db->prepare(" + SELECT name + FROM tags + INNER JOIN books_tags_link ON books_tags_link.tag = tags.id + WHERE tags.name NOT LIKE 'infopump%' + AND books_tags_link.book = :itemid + "); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + while ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $tags[] = $row['name']; + } + + // Pull identifiers + $stmt = $db->prepare("SELECT type, val FROM identifiers WHERE book = :itemid"); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + while ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $identifiers[] = $row; + } + + // Pull languages + $stmt = $db->prepare(" + SELECT languages.lang_code AS lang_code + FROM languages + INNER JOIN books_languages_link ON books_languages_link.lang_code = languages.id + WHERE book = :itemid + ORDER BY books_languages_link.item_order + "); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + while ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $languages[] = $row['lang_code']; + } + + // Pull type + $stmt = $db->prepare(" + SELECT custom_column_1.value AS itemtype + FROM books_custom_column_1_link + INNER JOIN custom_column_1 ON custom_column_1.id = books_custom_column_1_link.value + WHERE books_custom_column_1_link.book = :itemid + "); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $book_data['type'] = mb_convert_case($row['itemtype'], MB_CASE_TITLE, "UTF-8"); + } + + // Pull series information + $stmt = $db->prepare(" + SELECT series.name AS series, books.series_index AS seriesindex + FROM series + INNER JOIN books_series_link ON books_series_link.series = series.id + INNER JOIN books ON books.id = books_series_link.book + WHERE books_series_link.book = :itemid + "); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $book_data['series'] = $row['series']; + $book_data['series_index'] = $row['seriesindex']; + } + + // Pull publisher location + $stmt = $db->prepare(" + SELECT custom_column_2.value AS publoc + FROM books + INNER JOIN books_custom_column_2_link ON books_custom_column_2_link.book = books.id + INNER JOIN custom_column_2 ON custom_column_2.id = books_custom_column_2_link.value + WHERE books.id = :itemid + "); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $book_data['publisher_location'] = $row['publoc']; + } + + // Pull subtype + $stmt = $db->prepare(" + SELECT custom_column_3.value AS subtype + FROM books + INNER JOIN books_custom_column_3_link ON books_custom_column_3_link.book = books.id + INNER JOIN custom_column_3 ON custom_column_3.id = books_custom_column_3_link.value + WHERE books.id = :itemid + "); + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $book_data['subtype'] = $row['subtype']; + } + + // Get similar items based on tags + if (count($tags) >= 2) { + // Get two random tags for similarity + $random_tags = array_rand(array_flip($tags), min(2, count($tags))); + if (!is_array($random_tags)) { + $random_tags = [$random_tags]; + } + + $tag_placeholders = implode(',', array_fill(0, count($random_tags), '?')); + + $stmt = $db->prepare(" + SELECT DISTINCT books.id, title, author_sort + FROM books + INNER JOIN books_tags_link ON books_tags_link.book = books.id + INNER JOIN tags ON tags.id = books_tags_link.tag + WHERE tags.name IN ($tag_placeholders) + AND books.id != :itemid + LIMIT 4 + "); + + foreach ($random_tags as $index => $tag) { + $stmt->bindValue($index + 1, $tag, SQLITE3_TEXT); + } + $stmt->bindValue(':itemid', $ItemID, SQLITE3_INTEGER); + + $result = $stmt->execute(); + while ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) { + $similar_items[] = $row; + } + } + +} catch (Exception $e) { + error_log('Error in itemrecord.php: ' . $e->getMessage()); + $error_message = 'Unable to load item details. Please try again later.'; } -// ---------- Pull series information ---------- - -$series = $db->query("SELECT series.name AS series, books.series_index AS seriesindex -FROM series -INNER JOIN books_series_link -ON books_series_link.series = series.id -INNER JOIN books -ON books.id = books_series_link.book -WHERE books_series_link.book = '$ItemID'"); - -while ($row = $series->fetchArray()) { - $row_series = $row['series']; - $row_seriesindex = $row['seriesindex']; +// Helper function to get identifier URL +function get_identifier_url($type) { + $urls = [ + 'google' => 'https://books.google.com/books?id=', + 'isbn' => 'https://www.librarything.com/isbn/', + 'oclc' => 'https://worldcat.org/title/', + 'tmdb' => 'https://www.themoviedb.org/movie/' + ]; + return $urls[$type] ?? '#'; } -// ---------- Pull publisher location information ---------- - -$publisher_location = $db->query("SELECT custom_column_2.value AS publoc -FROM books -INNER JOIN -books_custom_column_2_link -ON books_custom_column_2_link.book = books.id -INNER JOIN -custom_column_2 -ON custom_column_2.id = books_custom_column_2_link.value -WHERE -books.id = '$ItemID'"); - -while ($row = $publisher_location->fetchArray()) { - $row_publocation = $row['publoc']; +// Check if image exists +$image_path = "images/{$ItemID}.jpg"; +if (!file_exists($image_path)) { + $image_path = "images/placeholder.jpg"; } - -// ---------- Pull subtype information ---------- - -$subtype = $db->query("SELECT custom_column_3.value AS subtype -FROM books -INNER JOIN -books_custom_column_3_link -ON books_custom_column_3_link.book = books.id -INNER JOIN -custom_column_3 -ON custom_column_3.id = books_custom_column_3_link.value -WHERE -books.id = '$ItemID'"); - -while ($row = $subtype->fetchArray()) { - $row_subtype = $row['subtype']; -} - - - -// -------------------- END DATABASE QUERIES -------------------- - ?> - - - '; ?> - - + + + + + - ';?> - - '; ?> - - '; ?> - - '; ?> - - '; ?> - - '; ?> - - '; ?> - - '; ?> - - + + + + + + + + + + + + + + + + + + + - '; ?> - - '; ?> - - '; ?> - - fetchArray()) { - $row_id_type = $row['type']; - $row_id_val = $row['val']; - if ($row_id_type == 'isbn') { - echo ''; - } - } - ?> - - Item Record: '.$row_title.''; ?> + <?php echo esc_html('Item Record: ' . ($book_data['title'] ?? 'Unknown')); ?> + - + + - + + - - + + + + + +
-
<?php echo $row_title; ?>
-
-

-
- '; - echo 'Number '.$row_seriesindex.' in the '.$row_series.' series
'; - echo '
'; - } else { - echo '
'; - } - ?> -
-

-
- -
+ <?php echo esc_attr($book_data['title'] ?? 'Unknown'); ?> +
+
+
Item Record
+

+ + +
+
+ + Number in the + + + series + +
+
+ +
+ + +

-
-
+ +
+ +
-

Bibliographic Citations


-

Note: You may need to slightly edit citations for final use. Citations are based upon available data. Refer to your format guides for proper bibliographic citations.

+

Bibliographic Citations


+

Note: You may need to slightly edit citations for final use. Citations are based upon available data. Refer to your format guides for proper bibliographic citations.

- - - '.$row_author_sort.'. '.$row_title.'. '.$row_publocation.': '.$row_publisher.', '.$row_pubdate.'.
'; - echo ''; - } elseif ($row_type == 'Music') { - echo ''; - } else { - echo ''; - } - ?> - Copy Chicago citation

- - - -
- - - - + + + + + Copy Chicago citation

- if ($row_type == 'Text') { - echo ''; - echo ''; - } elseif ($row_type == 'Music') { - echo ''; - echo ''; - } else { - echo ''; - echo ''; - } - ?> - Copy APA citation

- - +
+ + + + + + Copy APA citation

+ +
+ + + + + + Copy MLA citation

+ +
-
- - - - '.$row_author_sort.'. '.$row_title.'. '.$row_publisher.', '.$row_pubdate.'.
'; - echo ''; - } elseif ($row_type == 'Music') { - echo ''; - } else { - echo ''; - } - - ?> - Copy MLA citation

- - -
- - -
+ +

Metadata

- -
- +
+ + 0): ?>

Similar items

-
- fetchArray()) { - $row_simbookid = $row['id']; - $row_simtitle = $row['title']; - $row_simauthorsort = $row['author_sort']; - echo '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; - echo ''; - echo '
'.$row_simtitle.'
'; - echo ''; - echo $row_simauthorsort; - echo '
'; - echo '
'; - echo ''; - echo ''; - echo '
'; - - - - echo '
'; - } - ?> -
+
+ + +
+
+ + <?php echo esc_attr($item['title']); ?> + +
+
+
+ +
+
+ +
+
+ +
+ + + + + + + +close(); +} +?> \ No newline at end of file diff --git a/test.php b/test.php deleted file mode 100644 index bfe14e3..0000000 --- a/test.php +++ /dev/null @@ -1,9 +0,0 @@ -query('SELECT * FROM tags'); - -while ($row = $res->fetchArray()) { - echo "{$row['id']} {$row['name']}"."
"; -}