function renderAchievementData($category, $guid, $faction)
{
    global $wDB, $lang;
    $baseptr = "?achievement";
    if ($guid) {
        $baseptr .= "&guid=" . $guid;
    } else {
        $baseptr .= "&faction=" . $faction;
    }
    echo '<br><script type="text/javascript" src="js/achievement.js"></script>';
    echo '<table class=achievement cellSpacing=0 cellPadding=0><tbody>';
    echo '<tr><td class="a_cat" id="a_category">';
    // Output player achievement statistic
    echo '<div class=a_topcat></div>';
    $category_list = $wDB->select("SELECT\n  `id` AS ARRAY_KEY,\n  `parent` AS PARENT_KEY,\n  `parent`,\n  `name`\n  FROM\n   `wowd_achievement_category`\n  ORDER BY `sortOrder`");
    // Show 1 category if no exist
    if ($category == 0 && !$guid) {
        reset($category_list);
        $category = key($category_list);
    }
    if ($guid) {
        echo '<div class=a_bodycat' . ($category == 0 ? '_sel' : '') . '><a id=ach_0 href=' . $baseptr . ' onclick=\'return selectCat(0);\'>' . $lang['achievment_total'] . '</a></div>';
    }
    foreach ($category_list as $id => $cat) {
        if ($id == 1) {
            continue;
        }
        $sel_cat = '';
        if ($id == $category) {
            $sel_cat = '_sel';
        } else {
            foreach ($cat['childNodes'] as $i => $sub) {
                if ($i == $category) {
                    $sel_cat = '_sel';
                }
            }
        }
        echo '<div class=a_bodycat' . $sel_cat . '>';
        echo "<a id='ach_" . $id . "' href=" . $baseptr . "&category=" . $id . " onclick='return selectCat(" . $id . ");'>" . $cat['name'] . "</a>";
        foreach ($cat['childNodes'] as $i => $sub) {
            echo "<a id='ach_" . $i . "' class=" . ($i == $category ? "sel" : "sub") . " href=" . $baseptr . "&category=" . $i . " onclick='return selectCat(" . $i . ");'>" . $sub['name'] . "</a>";
        }
        echo '</div>';
    }
    foreach ($category_list['1']['childNodes'] as $id => $cat) {
        $sel_cat = '';
        if ($id == $category) {
            $sel_cat = '_sel';
        } else {
            foreach ($cat['childNodes'] as $i => $sub) {
                if ($i == $category) {
                    $sel_cat = '_sel';
                }
            }
        }
        echo '<div class=a_bodycat' . $sel_cat . '>';
        echo "<a id='ach_" . $id . "' href=" . $baseptr . "&category=" . $id . " onclick='return selectCat(" . $id . ");'>" . $cat['name'] . "</a>";
        foreach ($cat['childNodes'] as $i => $sub) {
            echo "<a id='ach_" . $i . "' class=" . ($i == $category ? "sel" : "sub") . " href=" . $baseptr . "&category=" . $i . " onclick='return selectCat(" . $i . ");'>" . $sub['name'] . "</a>";
        }
        echo '</div>';
    }
    echo '</div>';
    echo '<div class=a_bottomcat></div>';
    echo '</td>';
    echo '<td class="a_data">';
    echo '<div class="a_topdata"></div>';
    echo '<div class="a_bdydata" id="a_data">';
    renderAchievementCategoryList($category, $faction, $guid);
    echo '</div>';
    echo '<div class="a_btmdata"></div>';
    echo '</td>';
    echo '</tr>';
    echo '</tbody></table>';
    echo '<script type="text/javascript">
  ChangeCssProperty(".ach_show .ach_req", "display", "none");
  ChangeCssProperty("div.a_bodycat a.sub", "display", "none");
  cacheCat("' . $baseptr . "&category=" . $category . '");
  </script>';
}
<?php

include_once "include/functions.php";
include_once "include/achievements.php";
$category = intval(@$_REQUEST['category']);
$faction = intval(@$_REQUEST['faction']);
$guid = intval(@$_REQUEST['guid']);
$faction = getAchievementFaction($guid, $faction);
if ($ajaxmode == 0) {
    renderAchievementData($category, $guid, $faction);
} else {
    renderAchievementCategoryList($category, $faction, $guid);
}