function getImages(&$img, $eid = -1, $sid = -1) { global $tblprefix, $err_images; $iquery = "SELECT image_id, i.title, p.person_id as p_person_id, i.event_id, " . Event::getFields("e") . "," . PersonDetail::getFields() . "," . Source::getFields("s") . ", s.source_id as s_source_id" . " FROM " . $tblprefix . "images i " . " LEFT JOIN " . $tblprefix . "event e ON e.event_id = i.event_id " . " LEFT JOIN " . $tblprefix . "people p ON p.person_id = e.person_id " . " LEFT JOIN " . $tblprefix . "source s ON s.source_id = i.source_id " . PersonDetail::getJoins(); switch ($img->queryType) { case Q_RANDOM: $iquery .= $this->addPersonRestriction(" WHERE ") . $this->addRandom(); break; default: if ($sid > 0) { $iquery .= " WHERE s.source_id = " . quote_smart($sid); } else { if ($eid > 0) { $iquery .= " WHERE e.event_id = " . quote_smart($eid); } else { if (isset($img->person->person_id)) { $iquery .= " WHERE "; $iquery .= "p.person_id = " . quote_smart($img->person->person_id); $iquery .= $this->addPersonRestriction(" AND "); if (isset($img->image_id)) { $iquery .= " AND image_id=" . $img->image_id; } $iquery .= " ORDER BY e.date1"; } else { $bool = " WHERE "; if (isset($img->image_id)) { $iquery .= " WHERE image_id=" . $img->image_id; $bool = " AND "; } $iquery .= $this->addPersonRestriction($bool) . " ORDER BY b.date1"; } } } break; } $this->addLimit($img, $query); $iresult = $this->runQuery($iquery, $err_images); $res = array(); $img->numResults = 0; while ($row = $this->getNextRow($iresult)) { $image = new Image(); $image->person = new PersonDetail(); $image->person->loadFields($row, L_HEADER, "p_"); $image->person->name->loadFields($row, "n_"); $image->image_id = $row["image_id"]; $image->title = $row["title"]; $image->event = new Event(); $image->event->loadFields($row, "e_"); $image->source = new Source(); $image->source->loadFields($row, "s_"); $image->description = $image->event->descrip; $image->date = $image->event->date1; $res[] = $image; $img->numResults++; } $this->freeResultSet($iresult); $img->results = $res; }
function getEvents(&$events, $type, $attendees = false) { global $tblprefix; $events->numResults = 0; $query = "SELECT " . Event::getFields('e') . "," . Location::getFields('l') . " FROM " . $tblprefix . "event e" . " LEFT JOIN " . $tblprefix . "locations l ON l.location_id = e.location_id"; switch ($type) { case Q_BD: $query .= " WHERE etype < 4"; $query .= " AND e.person_id = " . $events->person->person_id; //birth and death events only if (!isset($events->person) || $events->person->person_id == '') { return; } break; case Q_REL: $query .= " WHERE (etype = " . BANNS_EVENT . " OR etype = " . MARRIAGE_EVENT . ")"; $query .= " AND e.event_id = " . $events->event_id; if (!isset($events->event_id) || $events->event_id == '') { return; } break; case Q_CEN: $query .= " WHERE etype = " . CENSUS_EVENT; $query .= " AND e.person_id = " . $events->person->person_id; if (!isset($events->person) || $events->person->person_id == '') { return; } break; case Q_OTHER: $query .= " WHERE etype = " . OTHER_EVENT; $query .= " AND e.person_id = " . $events->person->person_id; if (!isset($events->person) || $events->person->person_id == '') { return; } break; case Q_ALL: $query .= " WHERE e.event_id = " . $events->event_id; if (!isset($events->event_id) || $events->event_id == '') { return; } } //TODO error message $result = $this->runQuery($query, ''); $res = array(); while ($row = $this->getNextRow($result)) { $e = new Event(); $e->loadFields($row, "e_"); $e->location->loadFields($row, "l_"); if ($attendees) { $this->getAttendees($e); } $events->numResults++; $res[] = $e; } $this->freeResultSet($result); $events->results = $res; }
function getTranscripts(&$trans, $eid = -1, $sid = -1) { global $tblprefix, $err_trans, $currentRequest; $res = array(); $squery = "SELECT p.person_id, id, doc_title, file_name, e.event_id, e.descrip, e.date1," . Event::getFields("e") . "," . Source::getFields("s") . ", s.source_id as s_source_id," . PersonDetail::getFields() . " FROM " . $tblprefix . "documents doc" . " LEFT JOIN " . $tblprefix . "event e ON e.event_id = doc.event_id " . " LEFT JOIN " . $tblprefix . "people p ON p.person_id = e.person_id " . " LEFT JOIN " . $tblprefix . "source s ON s.source_id = doc.source_id " . PersonDetail::getJoins("LEFT"); if ($sid > 0) { $squery .= " WHERE s.source_id = " . quote_smart($sid); } else { if ($eid > 0) { $squery .= " WHERE e.event_id = " . quote_smart($eid); } else { if (isset($trans->person->person_id) && $trans->person->person_id > 0) { $squery .= " WHERE "; $squery .= "p.person_id = " . quote_smart($trans->person->person_id); $squery .= $this->addPersonRestriction(" AND "); if (isset($trans->transcript_id)) { $squery .= " AND id=" . $trans->transcript_id; } $squery .= " ORDER BY e.date1"; } else { $bool = " WHERE "; if (isset($trans->transcript_id)) { $squery .= " WHERE id=" . $trans->transcript_id; $bool = " AND "; } $squery .= $this->addPersonRestriction($bool) . " ORDER BY b.date1"; } } } $result = $this->runQuery($squery, $err_trans); $trans->numResults = 0; while ($row = $this->getNextRow($result)) { $t = new Transcript(); $t->person = new PersonDetail(); $t->person->loadFields($row, L_HEADER, "p_"); $t->person->name->loadFields($row, "n_"); $t->person->person_id = $row["person_id"]; $t->transcript_id = $row["id"]; $t->event = new Event(); $t->event->loadFields($row, "e_"); $t->event->event_id = $row["event_id"]; $t->source = new Source(); $t->source->loadFields($row, "s_"); $t->description = $t->event->descrip; $t->date = $t->event->date1; $t->title = $row["doc_title"]; $t->file_name = $row["file_name"]; $trans->numResults++; $res[] = $t; } $this->freeResultSet($result); $trans->results = $res; }
function getRelationshipDetails(&$search) { global $tblprefix, $err_spouse, $currentRequest; $partner = $search->relation->person_id; $res = array(); $search->numResults = 0; if (!($search->person->person_id > 0)) { return; } $query = "SELECT " . PersonDetail::getFields() . "," . PersonDetail::getFields("sp", "ns", "bs", "ds") . ", p.gender, DATE_ADD(b.date1, INTERVAL 40 YEAR) AS child_snatcher, " . " relation.event_id," . Event::getFields("e") . "," . Location::getFields("l") . ", relation.dissolve_date, relation.dissolve_reason," . " DATE_FORMAT(relation.dissolve_date, " . $currentRequest->datefmt . ") AS DOD " . "FROM " . $tblprefix . "people p "; $query .= " LEFT JOIN " . $tblprefix . "spouses relation ON "; if ($search->event->event_id > 0) { $query .= " relation.event_id = " . $search->event->event_id; } else { $query .= "((relation.groom_id = " . $search->person->person_id . ") OR (relation.bride_id = " . $search->person->person_id . "))"; } $query .= " LEFT JOIN " . $tblprefix . "people sp ON (relation.groom_id = sp.person_id OR relation.bride_id = sp.person_id)" . " AND sp.person_id <> p.person_id " . " LEFT JOIN " . $tblprefix . "event e ON e.event_id = relation.event_id" . " LEFT JOIN " . $tblprefix . "locations l ON l.location_id = e.location_id " . PersonDetail::getJoins("LEFT") . PersonDetail::getJoins("LEFT", "sp", "ns", "bs", "ds"); $query .= " AND sp.person_id <> p.person_id"; $query .= " WHERE p.person_id = " . $search->person->person_id; $query .= $this->addPersonRestriction(" AND "); $query .= $this->addPersonRestriction(" AND ", "bs", "ds"); $query .= " ORDER BY e.date1"; $result = $this->runQuery($query, $err_spouse); $search->numResults = 0; while ($row = $this->getNextRow($result)) { $rel = new Relationship(); $rel->person->loadFields($row, L_HEADER, "p_"); $rel->person->name->loadFields($row, "n_"); $rel->relation->loadFields($row, L_HEADER, "sp_"); $rel->relation->name->loadFields($row, "ns_"); $rel->loadFields($row); $rel->event = new Event(); $rel->event->loadFields($row, "e_"); $rel->event->location->loadFields($row, "l_"); $rel->marriage_date = $rel->event->date1; $rel->dom = $rel->event->fdate1; $rel->marriage_place = $rel->event->location; $rel->restrictDate = $row["child_snatcher"]; //Should sort out the SQL instead of this but for now... if ($rel->person->person_id != $rel->relation->person_id) { $search->numResults++; $res[] = $rel; } } $this->freeResultSet($result); $search->results = $res; }
function getSourceEvents(&$source) { global $tblprefix, $restrictdate, $strEvent, $datefmt; $pquery = "SELECT s.source_id, " . Source::getFields("s") . "," . Event::getFields("e") . "," . PersonDetail::getFields('p') . " FROM " . $tblprefix . "source s" . " JOIN " . $tblprefix . "source_event se ON s.source_id=se.source_id" . " JOIN " . $tblprefix . "event e ON se.event_id=e.event_id" . " JOIN " . $tblprefix . "people p ON e.person_id = p.person_id" . PersonDetail::getJoins(); if ($source->source_id > 0) { $pquery .= " WHERE s.source_id = " . $source->source_id; } $presult = $this->runQuery($pquery, ""); $source->numResults = 0; while ($row = $this->getNextRow($presult)) { $e = new Event(); $e->loadFields($row, "e_"); $e->person->loadFields($row, L_HEADER, "p_"); $e->person->name->loadFields($row, "n_"); $e->person->setPermissions(); $source->results[] = $e; $source->numResults++; } $this->freeResultSet($presult); }
function getCensusDetails(&$input) { global $tblprefix, $err_census_ret; $res = array(); $input->results = $res; $edquery = "SELECT cen.census_id, cen.census, schedule, year, census_date, cy.country, " . Event::getFields('e') . "," . PersonDetail::getFields() . "," . Attendee::getFields('a') . "," . Location::getFields('l') . "," . Location::getFields('al') . " FROM " . $tblprefix . "attendee a" . " JOIN " . $tblprefix . "event e ON a.event_id = e.event_id" . " JOIN " . $tblprefix . "census cen ON cen.event_id = e.event_id" . " JOIN " . $tblprefix . "people p ON a.person_id = p.person_id" . " LEFT JOIN " . $tblprefix . "locations l ON l.location_id = e.location_id" . " LEFT JOIN " . $tblprefix . "locations al ON al.location_id = a.location_id" . " LEFT JOIN " . $tblprefix . "census_years cy ON cen.census = cy.census_id" . PersonDetail::getJoins(); switch ($input->queryType) { case Q_TYPE: $where = ""; if (isset($input->schedule)) { $where = " WHERE e.reference =" . $input->schedule; } break; case Q_FAMILY: $where = " WHERE e.event_id = " . $input->event->event_id; if (!isset($input->event->event_id) || $input->event->event_id == '') { return; } break; default: $where = " WHERE p.person_id = " . $input->person->person_id; break; } $where .= $this->addPersonRestriction(" AND "); $orderby = " ORDER BY e.date1, b.date1"; $edquery .= $where . $orderby; if ($edresult = $this->runQuery($edquery, $err_census_ret)) { $input->numResults = 0; $events = array(); while ($edrow = $this->getNextRow($edresult)) { $cen = new CensusDetail(); $cen->loadFields($edrow); $e = new Event(); $e->loadFields($edrow, "e_"); $e->location->loadFields($edrow, "l_"); $new = false; if (isset($events[$e->event_id])) { $event = $events[$e->event_id]; } else { $new = true; $e->attendees = array(); $events[$e->event_id] = $e; $event = $e; } $a = new Attendee(); $a->person->loadFields($edrow, L_HEADER, "p_"); $a->person->name->loadFields($edrow, "n_"); if ($a->person->person_id == $event->person->person_id) { $event->person = $a->person; } $a->loadFields($edrow, "a_"); $a->location->loadFields($edrow, "al_"); $event->attendees[] = $a; //This is needed for php 4 $events[$event->event_id] = $event; if ($new) { $cen->event = $event; $input->numResults++; $res[] = $cen; } //This is also needed for php 4 for ($i = 0; $i < count($res); $i++) { if ($res[$i]->event->event_id == $event->event_id) { $c = $res[$i]; $c->event = $event; $res[$i] = $c; } } } $this->freeResultSet($edresult); } $input->results = $res; }
function getAttendeePlaces(&$locations, $person = null) { global $tblprefix, $strEvent, $datefmt; global $strBirthPlace, $strAddress; $query = "SELECT " . Attendee::getFields('a') . "," . PersonDetail::getFields('p') . ", " . Event::getFields("e") . "," . Location::getFields("l") . "," . Location::getFields("el") . " FROM " . $tblprefix . "attendee a" . " JOIN " . $tblprefix . "people p ON a.person_id = p.person_id" . " JOIN " . $tblprefix . "event e ON a.event_id = e.event_id" . " LEFT JOIN " . $tblprefix . "locations el ON el.location_id = e.location_id" . " LEFT JOIN " . $tblprefix . "locations l ON l.location_id = a.location_id" . PersonDetail::getJoins() . " WHERE (a.location_id is not null OR e.location_id is not null)" . " AND (NOT (e.etype = " . BANNS_EVENT . " OR e.etype=" . MARRIAGE_EVENT . "))"; $query .= $this->addPersonRestriction(" AND "); if ($locations->location_id > 0) { $query .= " AND (a.location_id = " . $locations->location_id . " OR e.location_id = " . $locations->location_id . ")"; } $presult = $this->runQuery($query, ""); while ($prow = $this->getNextRow($presult)) { $per = new PersonDetail(); $per->loadFields($prow, L_HEADER, 'p_'); $per->name->loadFields($prow, 'n_'); $per->setPermissions(); $e = new Event(); $e->loadFields($prow, "e_"); $loc = new Location(); $loc->loadFields($prow, "l_"); $loc->setPermissions(); if ($per->isViewable() && $loc->hasData()) { $text = $per->getLink() . ' '; switch ($e->type) { case CENSUS_EVENT: $text .= $strEvent[$e->type] . " " . $strBirthPlace; break; default: $text .= $strAddress; break; } $text .= ' ' . $e->getDate1(); if ($locations->location_id > 0 && $loc->location_id == $locations->location_id || $locations->location_id <= 0) { $p = $this->createPlace($locations, $loc, $text); } } $e->location->loadFields($prow, "el_"); $e->location->setPermissions(); if ($per->isViewable() && $e->location->hasData()) { $text = $per->getLink() . ' ' . $strEvent[$e->type] . ' ' . $e->getDate1(); if ($locations->location_id > 0 && $e->location->location_id == $locations->location_id || $locations->location_id <= 0) { $p = $this->createPlace($locations, $e->location, $text); } } } $this->freeResultSet($presult); }