function print_gedcom_stats($block = true, $config = '', $side, $index)
{
    global $PGV_BLOCKS, $pgv_lang, $ALLOW_CHANGE_GEDCOM, $ctype, $COMMON_NAMES_THRESHOLD, $PGV_IMAGE_DIR, $PGV_IMAGES, $MULTI_MEDIA;
    global $top10_block_present;
    if (empty($config)) {
        $config = $PGV_BLOCKS['print_gedcom_stats']['config'];
    }
    if (!isset($config['stat_indi'])) {
        $config = $PGV_BLOCKS['print_gedcom_stats']['config'];
    }
    if (!isset($config['stat_first_death'])) {
        $config['stat_first_death'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_first_death'];
    }
    if (!isset($config['stat_last_death'])) {
        $config['stat_last_death'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_last_death'];
    }
    if (!isset($config['stat_media'])) {
        $config['stat_media'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_media'];
    }
    if (!isset($config['stat_link'])) {
        $config['stat_link'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_link'];
    }
    $id = 'gedcom_stats';
    $title = print_help_link('index_stats_help', 'qm', '', false, true);
    if ($PGV_BLOCKS['print_gedcom_stats']['canconfig']) {
        if ($ctype == 'gedcom' && PGV_USER_GEDCOM_ADMIN || $ctype == 'user' && PGV_USER_ID) {
            if ($ctype == 'gedcom') {
                $name = PGV_GEDCOM;
            } else {
                $name = PGV_USER_NAME;
            }
            $title .= "<a href=\"javascript: configure block\" onclick=\"window.open('" . encode_url("index_edit.php?name={$name}&ctype={$ctype}&action=configure&side={$side}&index={$index}") . "', '_blank', 'top=50,left=50,width=700,height=400,scrollbars=1,resizable=1'); return false;\">";
            $title .= "<img class=\"adminicon\" src=\"{$PGV_IMAGE_DIR}/" . $PGV_IMAGES['admin']['small'] . "\" width=\"15\" height=\"15\" border=\"0\" alt=\"" . $pgv_lang['config_block'] . "\" /></a>";
        }
    }
    $title .= $pgv_lang['gedcom_stats'];
    $stats = new stats(PGV_GEDCOM);
    $content = "<b><a href=\"index.php?ctype=gedcom\">" . PrintReady(strip_tags(get_gedcom_setting(PGV_GED_ID, 'title'))) . "</a></b><br />";
    $head = find_other_record('HEAD', PGV_GED_ID);
    $ct = preg_match('/1 SOUR (.*)/', $head, $match);
    if ($ct > 0) {
        $softrec = get_sub_record(1, '1 SOUR', $head);
        $tt = preg_match('/2 NAME (.*)/', $softrec, $tmatch);
        if ($tt > 0) {
            $software = printReady(trim($tmatch[1]));
        } else {
            $software = trim($match[1]);
        }
        if (!empty($software)) {
            $text = str_replace(array('#SOFTWARE#', '#CREATED_SOFTWARE#'), $software, $pgv_lang['gedcom_created_using']);
            $tt = preg_match('/2 VERS (.*)/', $softrec, $tmatch);
            if ($tt > 0) {
                $version = printReady(trim($tmatch[1]));
            } else {
                $version = '';
            }
            $text = str_replace(array('#VERSION#', '#CREATED_VERSION#'), $version, $text);
            $content .= $text;
        }
    }
    if (preg_match('/1 DATE (.+)/', $head, $match)) {
        if (empty($software)) {
            $content .= str_replace(array('#DATE#', '#CREATED_DATE#'), $stats->gedcomDate(), $pgv_lang['gedcom_created_on']);
        } else {
            $content .= str_replace(array('#DATE#', '#CREATED_DATE#'), $stats->gedcomDate(), $pgv_lang['gedcom_created_on2']);
        }
    }
    $content .= '<br /><table><tr><td valign="top" class="width20"><table cellspacing="1" cellpadding="0">';
    if ($config['stat_indi'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_individuals'] . '</td><td class="facts_value"><div dir="rtl"><a href="' . encode_url("indilist.php?surname_sublist=no&ged=" . PGV_GEDCOM) . '">' . $stats->totalIndividuals() . '</a></div></td></tr>';
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_males'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalSexMales() . '<br />' . $stats->totalSexMalesPercentage() . '%</div></td></tr>';
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_females'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalSexFemales() . '<br />' . $stats->totalSexFemalesPercentage() . '%</div></td></tr>';
    }
    if ($config['stat_surname'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_surnames'] . '</td><td class="facts_value"><div dir="rtl"><a href="' . encode_url("indilist.php?show_all=yes&surname_sublist=yes&ged=" . PGV_GEDCOM) . '">' . $stats->totalSurnames() . '</a></div></td></tr>';
    }
    if ($config['stat_fam'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_families'] . '</td><td class="facts_value"><div dir="rtl"><a href="famlist.php">' . $stats->totalFamilies() . '</a></div></td></tr>';
    }
    if ($config['stat_sour'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_sources'] . '</td><td class="facts_value"><div dir="rtl"><a href="sourcelist.php">' . $stats->totalSources() . '</a></div></td></tr>';
    }
    if ($config['stat_media'] == 'yes' && $MULTI_MEDIA == true) {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_media'] . '</td><td class="facts_value"><div dir="rtl"><a href="medialist.php">' . $stats->totalMedia() . '</a></div></td></tr>';
    }
    if ($config['stat_other'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_other'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalOtherRecords() . '</div></td></tr>';
    }
    if ($config['stat_events'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_events'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalEvents() . '</div></td></tr>';
    }
    if ($config['stat_users'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_users'] . '</td><td class="facts_value"><div dir="rtl">';
        if (PGV_USER_GEDCOM_ADMIN) {
            $content .= '<a href="useradmin.php">' . $stats->totalUsers() . '</a>';
        } else {
            $content .= $stats->totalUsers();
        }
        $content .= '</div>
</td>
</tr>';
    }
    if (!$block) {
        $content .= '</table></td><td><br /></td><td valign="top"><table cellspacing="1" cellpadding="1" border="0">';
    }
    if ($config['stat_first_birth'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_earliest_birth'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->firstBirthYear() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->firstBirth() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_last_birth'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_latest_birth'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->lastBirthYear() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->lastBirth() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_first_death'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_earliest_death'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->firstDeathYear() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->firstDeath() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_last_death'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_latest_death'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->lastDeathYear() . '</div>
</td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->lastDeath() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_long_life'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_longest_life'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->LongestLifeAge() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->LongestLife() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_avg_life'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_avg_age_at_death'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->averageLifespan() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $pgv_lang['stat_males'] . ':&nbsp;' . $stats->averageLifespanMale();
            $content .= '&nbsp;&nbsp;&nbsp;' . $pgv_lang['stat_females'] . ':&nbsp;' . $stats->averageLifespanFemale() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_most_chil'] == 'yes' && !$block) {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_most_children'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->largestFamilySize() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">' . $stats->largestFamily() . '</td>';
        }
        $content .= '</tr>';
    }
    if ($config['stat_avg_chil'] == 'yes') {
        $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_average_children'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->averageChildren() . '</div></td>';
        if (!$block) {
            $content .= '<td class="facts_value">&nbsp;</td>';
        }
        $content .= '</tr>';
    }
    $content .= '</table></td></tr></table>';
    if ($config['stat_link'] == 'yes') {
        $content .= '<a href="statistics.php"><b>' . $pgv_lang['stat_link'] . '</b></a><br />';
    }
    // NOTE: Print the most common surnames
    if ($config['show_common_surnames'] == 'yes') {
        $surnames = get_common_surnames($COMMON_NAMES_THRESHOLD);
        if (count($surnames) > 0) {
            $content .= '<br />';
            $content .= print_help_link('index_common_names_help', 'qm', '', false, true);
            $content .= '<b>' . $pgv_lang['common_surnames'] . '</b><br />';
            $i = 0;
            foreach ($surnames as $indexval => $surname) {
                if (stristr($surname['name'], '@N.N') === false) {
                    if ($i > 0) {
                        $content .= ', ';
                    }
                    $content .= '<a href="' . encode_url("indilist.php?ged=" . PGV_GEDCOM . "&surname=" . $surname['name']) . '">' . PrintReady($surname['name']) . '</a>';
                    $i++;
                }
            }
        }
    }
    global $THEME_DIR;
    if ($block) {
        require $THEME_DIR . 'templates/block_small_temp.php';
    } else {
        require $THEME_DIR . 'templates/block_main_temp.php';
    }
}
function print_htmlplus_block($block = true, $config = '', $side, $index)
{
    global $ctype, $factarray, $GEDCOM, $HTML_BLOCK_COUNT, $PGV_BLOCKS, $PGV_IMAGE_DIR, $PGV_IMAGES, $pgv_lang, $TEXT_DIRECTION, $MULTI_MEDIA, $SHOW_ID_NUMBERS;
    // config sanity check
    if (empty($config)) {
        $config = $PGV_BLOCKS['print_htmlplus_block']['config'];
    } else {
        foreach ($PGV_BLOCKS['print_htmlplus_block']['config'] as $k => $v) {
            if (!isset($config[$k])) {
                $config[$k] = $v;
            }
        }
    }
    if (!isset($HTML_BLOCK_COUNT)) {
        $HTML_BLOCK_COUNT = 0;
    }
    $HTML_BLOCK_COUNT++;
    /*
     * Select GEDCOM
     */
    switch ($config['gedcom']) {
        case '__current__':
            break;
        case '':
            break;
        case '__default__':
            $GEDCOM = get_site_setting('DEFAULT_GEDCOM');
            if (!$GEDCOM) {
                foreach (get_all_gedcoms() as $gedcom) {
                    $GEDCOM = $gedcom;
                    break;
                }
            }
            break;
        default:
            if (get_gedcom_setting(get_gedcom_from_id($config['gedcom']), 'imported')) {
                $GEDCOM = $config['gedcom'];
            }
            break;
    }
    /*
     * Initiate the stats object.
     */
    if ($config['compat'] == 1) {
        require_once PGV_ROOT . 'includes/classes/class_stats_compat.php';
        $stats = new stats_compat($GEDCOM);
    } elseif ($config['ui'] == 1) {
        require_once PGV_ROOT . 'includes/classes/class_stats_ui.php';
        $stats = new stats_ui($GEDCOM);
    } else {
        $stats = new stats($GEDCOM);
    }
    // Make some values from the GEDCOM's 0 HEAD record visible to the world
    global $CREATED_SOFTWARE, $CREATED_VERSION, $CREATED_DATE;
    $CREATED_SOFTWARE = $stats->gedcomCreatedSoftware();
    $CREATED_VERSION = $stats->gedcomCreatedVersion();
    $CREATED_DATE = $stats->gedcomDate();
    /*
     * First Pass.
     * Handle embedded language, fact, global, etc. references
     *   This needs to be done first because the language variables could themselves
     *   contain embedded keywords.
     */
    // Title
    $config['title'] = print_text($config['title'], 0, 2);
    // Content
    $config['html'] = print_text($config['html'], 0, 2);
    /*
     * Second Pass.
     */
    list($new_tags, $new_values) = $stats->getTags("{$config['title']} {$config['html']}");
    // Title
    if (strstr($config['title'], '#')) {
        $config['title'] = str_replace($new_tags, $new_values, $config['title']);
    }
    // Content
    $config['html'] = str_replace($new_tags, $new_values, $config['html']);
    /*
     * Restore Current GEDCOM
     */
    $GEDCOM = PGV_GEDCOM;
    /*
     * Start Of Output
     */
    $id = "html_block{$HTML_BLOCK_COUNT}";
    $title = "";
    if ($config['title'] != '') {
        if (PGV_USER_GEDCOM_ADMIN) {
            $title .= print_help_link('index_htmlplus_ahelp', 'qm_ah', '', false, true);
        } else {
            $title .= print_help_link('index_htmlplus_help', 'qm', '', false, true);
        }
        if ($PGV_BLOCKS['print_htmlplus_block']['canconfig']) {
            if ($ctype == "gedcom" && PGV_USER_GEDCOM_ADMIN || $ctype == "user" && PGV_USER_ID) {
                if ($ctype == "gedcom") {
                    $name = PGV_GEDCOM;
                } else {
                    $name = PGV_USER_NAME;
                }
                $title .= "<a href=\"javascript: configure block\" onclick=\"window.open('" . encode_url("index_edit.php?name={$name}&ctype={$ctype}&action=configure&side={$side}&index={$index}") . "', '_blank', 'top=50,left=50,width=600,height=350,scrollbars=1,resizable=1'); return false;\">" . "<img class=\"adminicon\" src=\"{$PGV_IMAGE_DIR}/{$PGV_IMAGES['admin']['small']}\" width=\"15\" height=\"15\" border=\"0\" alt=\"{$pgv_lang['config_block']}\" /></a>";
            }
        }
        $title .= $config['title'];
    }
    $content = $config['html'];
    if ($config['title'] == '' && $PGV_BLOCKS['print_htmlplus_block']['canconfig']) {
        if ($ctype == "gedcom" && PGV_USER_GEDCOM_ADMIN || $ctype == "user" && PGV_USER_ID) {
            if ($ctype == "gedcom") {
                $name = str_replace("'", "\\'", $GEDCOM);
            } else {
                $name = PGV_USER_NAME;
            }
            $content .= "<br />" . print_help_link('index_htmlplus_ahelp', 'qm_ah', '', false, true) . "<a href=\"javascript:;\" onclick=\"window.open('" . encode_url("index_edit.php?name={$name}&ctype={$ctype}&action=configure&side={$side}&index={$index}") . "', '_blank', 'top=50,left=50,width=600,height=500,scrollbars=1,resizable=1'); return false;\">" . "<img class=\"adminicon\" src=\"{$PGV_IMAGE_DIR}/{$PGV_IMAGES['admin']['small']}\" width=\"15\" height=\"15\" border=\"0\" alt=\"{$pgv_lang['config_block']}\" title=\"{$pgv_lang['config_block']}\" /></a>";
        }
    }
    global $THEME_DIR;
    if ($block) {
        require $THEME_DIR . 'templates/block_small_temp.php';
    } else {
        require $THEME_DIR . 'templates/block_main_temp.php';
    }
}