function pcp_output_flag($field_name, $view_userdata, $map_name = '')
{
    global $board_config, $phpbb_root_path, $phpEx, $lang, $images, $userdata;
    global $values_list, $tables_linked, $classes_fields, $user_maps, $user_fields, $template;
    $txt = '';
    $img = '';
    $res = '';
    if ($view_userdata['user_id'] != ANONYMOUS) {
        if (!empty($view_userdata['user_flag'])) {
            $img = '<img src="templates/' . substr($template->root, $template->tpldir_len) . '/images/flags/' . $view_userdata['user_flag'] . '" alt="' . ucfirst(substr($view_userdata['user_flag'], 0, strlen($view_userdata['user_flag']) - 4)) . '" title="' . ucfirst(substr($view_userdata['user_flag'], 0, strlen($view_userdata['user_flag']) - 4)) . '" border="0" width="20" height="13" />';
        } else {
            $img = '';
        }
        // result
        $res = pcp_output_format($field_name, $txt, $img, $map_name);
    }
    return $res;
}
function pcp_output($field_name, $view_userdata, $map_name = '', $legend_only = false)
{
    global $board_config, $phpbb_root_path, $phpEx, $lang, $images, $userdata;
    global $values_list, $tables_linked, $classes_fields, $user_maps, $user_fields;
    $res = '';
    // no field, exit
    if (empty($field_name)) {
        return '';
    }
    // fix user id
    $user_id = $userdata['user_id'];
    if (!$userdata['session_logged_in']) {
        $user_id = ANONYMOUS;
    }
    // values overwritten in maps
    if (!empty($user_maps[$map_name]['fields'][$field_name])) {
        @reset($user_maps[$map_name]['fields'][$field_name]);
        while (list($field_def, $field_def_value) = @each($user_maps[$map_name]['fields'][$field_name])) {
            $user_fields[$field_name][$field_def] = $field_def_value;
        }
    }
    // get field def
    $field_data = array();
    if (isset($user_fields[$field_name])) {
        $field_data = $user_fields[$field_name];
    }
    // default values
    if (empty($field_data['lang_key'])) {
        $field_data['lang_key'] = ucfirst($field_name);
    }
    if (empty($field_data['class'])) {
        $field_data['class'] = 'generic';
    }
    if (empty($field_data['type'])) {
        $field_data['type'] = 'VARCHAR';
    }
    // legend only
    if ($legend_only) {
        return mods_settings_get_lang($field_data['lang_key']);
    }
    // get class def
    $class_data = array();
    if (isset($classes_fields[$field_data['class']])) {
        $class_data = $classes_fields[$field_data['class']];
    }
    // check the data classes
    if (!pcp_get_class_check($field_data['class'], $view_userdata)) {
        return '';
    }
    // process special display
    if (!empty($field_data['dsp_func'])) {
        $func = $field_data['dsp_func'];
        $res = function_exists($func) ? $func($field_name, $view_userdata, $map_name) : $lang['PCP_err_field_dsp_func_unknown'];
    } else {
        // value
        $txt = '';
        $img = '';
        $lnk = $field_data['link'];
        $res = '';
        $constant_link = $field_data['lnk'] && !isset($view_userdata[$field_name]) && ($field_data['txt'] && !empty($field_data['title']) || $field_data['img'] && !empty($field_data['image']));
        if ($view_userdata['user_id'] != ANONYMOUS && (!empty($view_userdata[$field_name]) || $field_data['leg'] && !$field_data['txt'] && !$field_data['img'] || $constant_link)) {
            $title = isset($field_data['title']) ? mods_settings_get_lang($field_data['title']) : $view_userdata[$field_name];
            $alt = mods_settings_get_lang($field_data['lang_key']);
            switch ($field_data['type']) {
                case 'DATE':
                    $txt = !empty($view_userdata[$field_name]) ? create_date($lang['DATE_FORMAT'], $view_userdata[$field_name], $userdata['user_timezone']) : '';
                    $img .= isset($images[$field_data['image']]) ? '<img src="' . $images[$field_data['image']] . '" border="0" alt="' . $alt . '" title="' . $title . '" />' : '';
                    break;
                case 'DATETIME':
                    $txt = !empty($view_userdata[$field_name]) ? create_date($userdata['user_dateformat'], $view_userdata[$field_name], $userdata['user_timezone']) : '';
                    $img .= isset($images[$field_data['image']]) ? '<img src="' . $images[$field_data['image']] . '" border="0" alt="' . $alt . '" title="' . $title . '" />' : '';
                    break;
                case 'BIRTHDAY':
                    $pm_display = pcp_get_class_check('pm', $view_userdata);
                    if (!empty($view_userdata[$field_name])) {
                        $temp_url = $pm_display ? append_sid("./privmsg.{$phpEx}?mode=post&amp;" . POST_USERS_URL . '=' . $view_userdata['user_id']) : '';
                        $txt = create_birthday_date($lang['DATE_FORMAT'], $view_userdata[$field_name], $userdata['user_timezone']);
                        $img = intval(substr($view_userdata[$field_name], 4, 4)) == date('md', cal_date(time(), $board_config['board_timezone'])) ? $pm_display ? '<a href="' . $temp_url . '"><img src="' . $images['icon_birthday'] . '" border="0" align="absbottom" alt="' . $lang['Happy_birthday'] . '" title="' . $lang['Happy_birthday'] . '" /></a>' : '<img src="' . $images['icon_birthday'] . '" border="0" align="absbottom" alt="' . $lang['Happy_birthday'] . '" title="' . $lang['Happy_birthday'] . '" />' : '';
                    }
                    break;
                default:
                    $txt = $view_userdata[$field_name];
                    if ($field_data['lnk'] && !isset($view_userdata[$field_name])) {
                        $txt = $title;
                    }
                    $img .= isset($images[$field_data['image']]) ? '<img src="' . $images[$field_data['image']] . '" border="0" alt="' . $alt . '" title="' . $title . '" />' : '';
                    break;
            }
            // res
            $res = pcp_output_format($field_name, $txt, $img, $map_name, $lnk, $view_userdata);
        }
    }
    return $res;
}