Esempio n. 1
0
 /**
  * 	Gathers results for a general search
  */
 function GeneralSearch()
 {
     global $GEDCOM, $GEDCOMS;
     $oldged = $GEDCOM;
     // Split search terms into an array
     $query_terms = array();
     $query = $this->query;
     // Words in double quotes stay together
     while (preg_match('/"([^"]+)"/', $query, $match)) {
         $query_terms[] = trim($match[1]);
         $query = str_replace($match[0], '', $query);
     }
     // Other words get treated separately
     while (preg_match('/[\\S]+/', $query, $match)) {
         $query_terms[] = trim($match[0]);
         $query = str_replace($match[0], '', $query);
     }
     // Get a list of gedcom IDs to search
     // TODO: don't we already have this somewhere?
     $ged_ids = array();
     foreach ($this->sgeds as $gedcom) {
         $ged_ids[] = get_id_from_gedcom($gedcom);
     }
     //-- perform the search
     if ($query_terms && $ged_ids) {
         // Write a log entry
         $logstring = "Type: General<br />Query: " . $this->query;
         AddToSearchlog($logstring, $this->sgeds);
         // Search the indi's
         if (isset($this->srindi)) {
             $this->myindilist = search_indis($query_terms, $ged_ids, 'AND', $this->tagfilter == 'on');
         } else {
             $this->myindilist = array();
         }
         // Search the fams
         if (isset($this->srfams)) {
             $this->myfamlist = array_merge(search_fams($query_terms, $ged_ids, 'AND', $this->tagfilter == 'on'), search_fams_names($query_terms, $ged_ids, 'AND'));
             $this->myfamlist = array_unique($this->myfamlist);
         } else {
             $this->myfamlist = array();
         }
         // Search the sources
         if (isset($this->srsour)) {
             if (!empty($this->query)) {
                 $this->mysourcelist = search_sources($query_terms, $ged_ids, 'AND', $this->tagfilter == 'on');
             }
         } else {
             $this->mysourcelist = array();
         }
         // Search the notes
         if (isset($this->srnote)) {
             if (!empty($this->query)) {
                 $this->mynotelist = search_notes($query_terms, $ged_ids, 'AND', $this->tagfilter == 'on');
             }
         } else {
             $this->mynotelist = array();
         }
         // If only 1 item is returned, automatically forward to that item
         // If ID cannot be displayed, continue to the search page.
         if (count($this->myindilist) == 1 && !$this->myfamlist && !$this->mysourcelist && !$this->mynotelist) {
             $indi = $this->myindilist[0];
             if (!count_linked_indi($indi->getXref(), 'ASSO', $indi->getGedId()) && !count_linked_fam($indi->getXref(), 'ASSO', $indi->getGedId()) && $indi->canDisplayName()) {
                 header("Location: " . encode_url($indi->getLinkUrl(), false));
                 exit;
             }
         }
         if (!$this->myindilist && count($this->myfamlist) == 1 && !$this->mysourcelist && !$this->mynotelist) {
             $fam = $this->myfamlist[0];
             if ($fam->canDisplayName()) {
                 header("Location: " . encode_url($fam->getLinkUrl(), false));
                 exit;
             }
         }
         if (!$this->myindilist && !$this->myfamlist && count($this->mysourcelist) == 1 && !$this->mynotelist) {
             $sour = $this->mysourcelist[0];
             if ($sour->canDisplayName()) {
                 header("Location: " . encode_url($sour->getLinkUrl(), false));
                 exit;
             }
         }
         if (!$this->myindilist && !$this->myfamlist && !$this->mysourcelist && count($this->mynotelist) == 1) {
             $note = $this->mynotelist[0];
             if ($note->canDisplayName()) {
                 header("Location: " . encode_url($note->getLinkUrl(), false));
                 exit;
             }
         }
     }
 }
 function countLinkedIndividuals()
 {
     return count_linked_indi($this->getXref(), $this->getType(), $this->ged_id);
 }