$initials = get_indilist_salpha($SHOW_MARRIED_NAMES, true, PGV_GED_ID); // If there are no individuals in the database, do something sensible if (!$initials) { $initials[] = '@'; } // Make sure selections are consistent. // i.e. can't specify show_all and surname at the same time. if ($show_all == 'yes') { $alpha = ''; $surname = ''; $legend = $pgv_lang['all']; $url = 'famlist.php?show_all=yes'; } elseif ($surname) { $surname = UTF8_strtoupper($surname); $alpha = UTF8_substr($surname, 0, 1); foreach (db_collation_digraphs() as $from => $to) { if (strpos($surname, UTF8_strtoupper($to)) === 0) { $alpha = UTF8_strtoupper($from); } } $show_all = 'no'; $legend = $surname; switch ($falpha) { case '': break; case '@': $legend .= ', ' . $pgv_lang['NN']; break; default: $legend .= ', ' . $falpha; break;
function get_indilist_galpha($surn, $salpha, $marnm, $fams, $ged_id) { global $TBLPREFIX, $DB_UTF8_COLLATION, $DBCOLLATE, $gBitDb; if ($fams) { $tables = "{$TBLPREFIX}name, {$TBLPREFIX}individuals, {$TBLPREFIX}link"; $join = "n_file={$ged_id} AND i_file=n_file AND i_id=n_id AND l_file=n_file AND l_from=n_id AND l_type='FAMS'"; } else { $tables = "{$TBLPREFIX}name, {$TBLPREFIX}individuals"; $join = "n_file={$ged_id} AND i_file=n_file AND i_id=n_id"; } if ($marnm) { $join .= " AND n_type!='_MARNM'"; } if ($surn) { $join .= " AND n_sort LIKE {$surn}"; } elseif ($salpha) { $join .= " AND n_sort LIKE {$salpha}%"; } if ($DB_UTF8_COLLATION) { $column = "UPPER(SUBSTR(n_givn {$DBCOLLATE}, 1, 1))"; } else { $column = "UPPER(SUBSTR(n_givn {$DBCOLLATE}, 1, 3))"; } $exclude = ''; $include = ''; $digraphs = db_collation_digraphs(); foreach (array_unique($digraphs) as $digraph) { // Multi-character digraphs $exclude .= " AND n_sort NOT LIKE '{$digraph}%' {$DBCOLLATE}"; } foreach ($digraphs as $to => $from) { // Single-character digraphs $include .= " UNION SELECT UPPER('{$to}' {$DBCOLLATE}) AS alpha FROM {$tables} WHERE {$join} AND n_sort LIKE '{$from}%' {$DBCOLLATE} GROUP BY 1"; } $alphas = $gBitDb->getOne("SELECT {$column} AS alpha FROM {$tables} WHERE {$join} {$exclude} GROUP BY 1 {$include} ORDER BY 1"); $list = array(); foreach ($alphas as $alpha) { if ($DB_UTF8_COLLATION) { $letter = $alpha; } else { $letter = UTF8_strtoupper(UTF8_substr($alpha, 0, 1)); } $list[$letter] = $letter; } // If we didn't sort in the DB, sort ourselves if (!$DB_UTF8_COLLATION) { uasort($list, 'stringsort'); } // sorting puts "," and "@" first, so force them to the end if (in_array(',', $list)) { unset($list[',']); $list[','] = ','; } if (in_array('@', $list)) { unset($list['@']); $list['@'] = '@'; } return $list; }