public function withAuthors() { if ($this->id) { $this->authors = Source::getInstance()->getAllAuthors($this->id); } return $this; }
/** * @param $authorsArray * @param Book $book */ public function addAuthorsToBook($authorsArray, Book $book) { $authors = Source::getInstance()->getAllAuthors(NULL, $authorsArray); if ($authors) { $queryDelete = "DELETE FROM book_author WHERE id_book = " . $book->id; $res = mysqli_query(Source::$_connection, $queryDelete); $values = array(); foreach ($authors as $author) { $values[] = "(" . $book->id . ", " . $author->id . ")"; } $queryAdd = "INSERT INTO book_author (id_book, id_author) VALUES " . implode(",", $values); $res = mysqli_query(Source::$_connection, $queryAdd); if ($res) { $book->authors = $authors; } } }
case 'IFS': $data = array(); // Fetch all data, regardless of privacy $rows = get_INDI_rows($WT_TREE, $term); // Filter for privacy foreach ($rows as $row) { $person = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom); if ($person->canShowName()) { $data[] = array('value' => $person->getXref(), 'label' => str_replace(array('@N.N.', '@P.N.'), array(I18N::translateContext('Unknown surname', '…'), I18N::translateContext('Unknown given name', '…')), $row->n_full) . ', <i>' . $person->getLifeSpan() . '</i>'); } } // Fetch all data, regardless of privacy $rows = get_SOUR_rows($WT_TREE, $term); // Filter for privacy foreach ($rows as $row) { $source = Source::getInstance($row->xref, $WT_TREE, $row->gedcom); if ($source->canShowName()) { $data[] = array('value' => $source->getXref(), 'label' => $source->getFullName()); } } // Fetch all data, regardless of privacy $rows = get_FAM_rows($WT_TREE, $term); // Filter for privacy foreach ($rows as $row) { $family = Family::getInstance($row->xref, $WT_TREE, $row->gedcom); if ($family->canShowName()) { $marriage_year = $family->getMarriageYear(); if ($marriage_year) { $data[] = array('value' => $family->getXref(), 'label' => $family->getFullName() . ', <i>' . $marriage_year . '</i>'); } else { $data[] = array('value' => $family->getXref(), 'label' => $family->getFullName());
<?php /** * Created by PhpStorm. * User: Sergey Krivov (sergey@krivov.info) * Date: 09.02.2016 * Time: 14:59 */ $book = NULL; if (isset($_GET['id'])) { $book = Source::getInstance()->getBook($_GET['id']); } if ($book) { $book->withAuthors(); require "view/book.php"; } else { header("Location: /"); }
<?php /** * Created by PhpStorm. * User: Sergey Krivov (sergey@krivov.info) * Date: 10.02.2016 * Time: 01:43 */ if (isset($_GET['id'])) { $book = Source::getInstance()->getBook($_GET['id']); if ($book) { Source::getInstance()->deleteBook($book); } } header("Location: /");
<?php /** * Created by PhpStorm. * User: Sergey Krivov (sergey@krivov.info) * Date: 09.02.2016 * Time: 15:03 */ $book = new Book(); $authors = Source::getInstance()->getAllAuthors(); if (isset($_GET['id'])) { $book = Source::getInstance()->getBook($_GET['id']); if (!$book) { header("Location: /"); } $book->withAuthors(); } if (isset($_POST['book'])) { if (isset($_GET['id'])) { Source::getInstance()->editBook($book, $_POST['book']); } else { $book = new Book($_POST['book']); Source::getInstance()->addBook($book, $_POST['book']['authors']); } if (count($book->_errors) == 0) { header("Location: /?page=book&id=" . $book->id); } } require "view/form.php";
<?php /** * Created by PhpStorm. * User: Sergey Krivov (sergey@krivov.info) * Date: 09.02.2016 * Time: 15:00 */ $page = isset($_GET['p']) ? (int) $_GET['p'] : 1; $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5; $order = isset($_GET['order']) && $_GET['order'] === 'DESC' ? $_GET['order'] : 'ASC'; $orderField = isset($_GET['order_field']) && $_GET['order_field'] === 'date' ? $_GET['order_field'] : 'name'; $count = Source::getInstance()->getBookCount(); $allBooks = Source::getInstance()->getAllBooks($page, $limit, $order, $orderField); require "view/index.php";
/** * returns SOUR:TITL matching filter * @return Array of string */ function autocomplete_SOUR_TITL($FILTER) { $rows = get_autocomplete_SOUR_TITL($FILTER); $data = array(); foreach ($rows as $row) { $source = Source::getInstance($row); if ($source->canDisplayName()) { $data[] = $source->getFullName(); } } return $data; }
/** * returns SOUR:TITL matching filter * @return Array of string */ function autocomplete_SOUR_TITL($FILTER) { global $TBLPREFIX, $gBitDb; $sql = "SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM {$TBLPREFIX}sources WHERE s_name LIKE ? AND s_file=? ORDER BY s_name"; $rows = $gBitDb->query($sql, array("%{$FILTER}%", PGV_GED_ID), PGV_AUTOCOMPLETE_LIMIT); $data = array(); while ($row = $rows->fetchRows()) { $source = Source::getInstance($row); if ($source->canDisplayName()) { $data[] = $source->getFullName(); } } return $data; }
function search_sources($query, $geds, $match, $skip) { global $TBLPREFIX, $GEDCOM, $DB_UTF8_COLLATION, $gBitDb; // No query => no results if (!$query) { return array(); } // Convert the query into a SQL expression $querysql = array(); // Convert the query into a regular expression $queryregex = array(); foreach ($query as $q) { $queryregex[] = preg_quote(UTF8_strtoupper($q), '/'); if ($DB_UTF8_COLLATION || !has_utf8($q)) { $querysql[] = "s_gedcom LIKE '%{$q}%'"; } else { $querysql[] = "(s_gedcom LIKE '%{$q}%' OR s_gedcom LIKE '%" . UTF8_strtoupper($q) . "' OR s_gedcom LIKE '%" . UTF8_strtolower($q) . "%')"; } } $sql = "SELECT 'SOUR' AS type, s_id AS xref, s_file AS ged_id, s_gedcom AS gedrec FROM {$TBLPREFIX}sources WHERE (" . implode(" {$match} ", $querysql) . ') AND s_file IN (' . implode(',', $geds) . ')'; // Group results by gedcom, to minimise switching between privacy files $sql .= ' ORDER BY ged_id'; // Tags we might not want to search if (PGV_USER_IS_ADMIN) { $skipregex = '/^\\d (_UID|_PGVU|FILE|FORM|TYPE|CHAN|SUBM|REFN) .*(' . implode('|', $queryregex) . ')/im'; } else { $skipregex = '/^\\d (_UID|_PGVU|FILE|FORM|TYPE|CHAN|SUBM|REFN|RESN) .*(' . implode('|', $queryregex) . ')/im'; } $list = array(); $rows = $gBitDb->query($sql); $GED_ID = PGV_GED_ID; while ($row = $rows->fetchRow()) { // Switch privacy file if necessary if ($row['ged_id'] != $GED_ID) { $GEDCOM = get_gedcom_from_id($row['ged_id']); load_privacy_file($row['ged_id']); $GED_ID = $row['ged_id']; } $source = Source::getInstance($row); // SQL may have matched on private data or gedcom tags, so check again against privatized data. $gedrec = UTF8_strtoupper($source->getGedcomRecord()); foreach ($queryregex as $q) { if (!preg_match('/\\n\\d\\ ' . PGV_REGEX_TAG . ' .*' . $q . '/i', $gedrec)) { continue 2; } } if ($skip && preg_match($skipregex, $gedrec)) { continue; } $list[] = $source; } // Switch privacy file if necessary if ($GED_ID != PGV_GED_ID) { $GEDCOM = get_gedcom_from_id(PGV_GED_ID); load_privacy_file(PGV_GED_ID); } return $list; }
if (!isset($type)) { $type = ""; } $level0type = $type; if ($type == "INDI") { $record = Person::getInstance($pid); echo "<b>", PrintReady($record->getFullName()), "</b><br />"; } elseif ($type == "FAM") { if (!empty($pid)) { $record = Family::getInstance($pid); } else { $record = Family::getInstance($famid); } echo "<b>", PrintReady($record->getFullName()), "</b><br />"; } elseif ($type == "SOUR") { $record = Source::getInstance($pid); echo "<b>", PrintReady($record->getFullName()), " "; if ($TEXT_DIRECTION == "rtl") { echo getRLM(); } echo "(", $pid, ")"; if ($TEXT_DIRECTION == "rtl") { echo getRLM(); } echo "</b><br />"; } if (strstr($action, "addchild")) { if (empty($famid)) { print_help_link("edit_add_unlinked_person_help", "qm", "add_unlinked_person"); echo "<b>", $pgv_lang["add_unlinked_person"], "</b>\n"; } else {