function trainer_block($category_id)
{
    global $base_instance, $userid, $now;
    if ($category_id) {
        $selected_category = ' AND category=' . $category_id;
    } else {
        $selected_category = '';
    }
    $data = $base_instance->get_data("SELECT *,({$now}-last_shown)*(value+1) AS abc FROM organizer_knowledge WHERE user={$userid} {$selected_category} ORDER BY abc DESC LIMIT 1");
    if (!$data) {
        $all_text = '<table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" class="pastel2"><tr><td width="100%" style="background-image: url(\'pics/gradient.jpg\');border-bottom:1px solid ' . _BLOCK_LINE_COLOR . '">&nbsp;<b>Random Knowledge</b></td></tr><tr><td width="100%" style="padding:10">No knowledge saved</td></tr></table>';
        return $all_text;
    }
    $knowledge_id = $data[1]->ID;
    $knowledge_title = $data[1]->title;
    $knowledge_text = $data[1]->text;
    $knowledge_category_id = $data[1]->category;
    $knowledge_value = $data[1]->value - 1;
    $knowledge_shown = $data[1]->shown + 1;
    $base_instance->query("UPDATE {$base_instance->entity['KNOWLEDGE']['MAIN']} SET shown={$knowledge_shown},value={$knowledge_value},last_shown={$now} WHERE ID={$knowledge_id}");
    $data = $base_instance->get_data("SELECT title FROM {$base_instance->entity['KNOWLEDGE']['CATEGORY']} WHERE ID={$knowledge_category_id}");
    $knowledge_category_text = $data[1]->title;
    $knowledge_text = convert_square_bracket($knowledge_text);
    $knowledge_text = nl2br($knowledge_text);
    if (!empty($knowledge_title)) {
        $knowledge_title = convert_square_bracket($knowledge_title);
        $knowledge_title = '<strong>' . $knowledge_title . ':</strong> ';
    }
    $all_text = '<table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" class="pastel2"><tr><td width="100%" style="background-image: url(\'pics/gradient.jpg\');border-bottom:1px solid ' . _BLOCK_LINE_COLOR . '"><font size="2">' . $knowledge_category_text . '</font> &nbsp; <font size="1">Shown: ' . $knowledge_shown . ' - Value: ' . $knowledge_value . ' &nbsp; <a href="increase-value.php?knowledge_id=' . $knowledge_id . '" target="status">[+5]</a> &nbsp; <a href="edit-knowledge.php?knowledge_id=' . $knowledge_id . '">[E]</a> &nbsp; <a href="javascript:DelKnow(\'' . $knowledge_id . '\')">[D]</a></font></td></tr><tr><td width="100%" style="padding:10"><div id="item' . $knowledge_id . '">' . $knowledge_title . $knowledge_text . '</div></td></tr></table>

<script language="JavaScript" type="text/javascript">function createRequestObject(){try {var requester=new XMLHttpRequest();}catch (error) {try{var requester=new ActiveXObject("Microsoft.XMLHTTP");}catch(error){return false;}}return requester;}var http=createRequestObject();function DelKnow(item){if(confirm("Delete Knowledge?")){http.open(\'get\',\'delete-knowledge.php?item=\'+item);http.onreadystatechange=handleResponse;http.send(null);}}function handleResponse(){if(http.readyState==4){var response=http.responseText;var update=new Array();if(response.indexOf(\'|\'!=-1)){res=response.split(\'|\');document.getElementById(res[0]).innerHTML=res[1];}}}</script>';
    return $all_text;
}
if (isset($_GET['text_search'])) {
    $text_search = sql_safe($_GET['text_search']);
    $where = " AND (text LIKE '%{$text_search}%' OR title LIKE '%{$text_search}%') ";
}
if (isset($_GET['category_id'])) {
    $category_id = (int) $_GET['category_id'];
    $where .= ' AND category=' . $category_id;
} else {
    if (isset($_GET['blog_id'])) {
        $blog_id = (int) $_GET['blog_id'];
        $where = ' AND ID=' . $blog_id;
    }
}
$data = $base_instance->get_data("SELECT * FROM {$base_instance->entity['BLOG']['MAIN']} WHERE user='******'{$where} ORDER BY datetime DESC");
echo '<head><meta http-equiv="content-type" content="text/html;charset=utf-8">
<style type="text/css">
td {font-family:Arial; font-size:10pt}
table.pastel,table.pastel td {border:1px solid #c5c5c5; border-collapse:collapse}
</style>
</head>

<table width="100%" border cellspacing=0 cellpadding=5 class="pastel">';
for ($index = 1; $index <= sizeof($data); $index++) {
    $title = $data[$index]->title;
    $text = $data[$index]->text;
    $title = convert_square_bracket($title);
    $text = convert_square_bracket($text);
    $text = nl2br($text);
    echo '<tr><td><strong>', $title, '</strong><br>', $text, '</td></tr>';
}
echo '</table>';
                    } else {
                        $visit_every = $number_of_days . ':' . $number_of_hours . ':' . $number_of_mins;
                    }
                }
            }
        }
        #
        if ($title) {
            $url_short = $title;
        } else {
            $url_short = 'http://' . substr($url, 0, 30);
        }
        if ($notes) {
            $notes_reminder = '<a href="javascript:void(window.open(\'edit-link.php?link_id=' . $ID . '\',\'\',\'width=550,height=650,top=100,left=100\'))">N</a>';
        } else {
            $notes_reminder = '&nbsp;';
        }
        if ($subtitle) {
            $subtitle = convert_square_bracket($subtitle);
            $subtitle2 = '<br><font size="1">' . $subtitle . '</font>';
        } else {
            $subtitle2 = '';
        }
        $speed = $base_instance->speed_array[$speed];
        $all_text .= '<tr bgcolor="#ffffff" onMouseOver=\'this.style.background="#e9e9e9"\' onMouseOut=\'this.style.background="#ffffff"\'><td onClick="window.open(\'visit-link.php?link_id=' . $ID . '\',\'_blank\'); this.style.fontWeight=\'bold\';" colspan=2><span class="fakelink">' . $url_short . '</span>' . $subtitle2 . '</td><td>' . $notes_reminder . '</td><td><a href="visit-link.php?link_id=' . $ID . '" target="_blank">V</a></td><td><a href="javascript:void(window.open(\'edit-link.php?link_id=' . $ID . '\',\'\',\'width=550,height=650,top=100,left=100\'))">E</a></td><td><a href="send-content.php?link_id=' . $ID . '">S</a></td><td><a href="javascript:void(window.open(\'delete-link.php?link_id=' . $ID . '\',\'\',\'width=450,height=300,top=100,left=100\'))">D</a></td><td>' . $public . '</td><td align="center">' . $visit_every . '</td><td align="center">' . $speed . '</td><td align="center">' . $lastvisit . ' (' . $time_in_BB . ')</td><td align="center">' . $sequence . '</td><td align="center">' . round($popularity) . ' </td><td align="center">' . $visits . '</td></tr>';
    }
    $all_text .= '</table>';
}
$content_array[1] = array('MAIN' => $all_text);
$html_instance->content = $content_array;
$html_instance->process();
            $all_text .= '<u>Fax:</u> ' . $fax . '<br>';
        }
        if ($mobile) {
            $mobile = convert_square_bracket($mobile);
            $all_text .= '<u>Mobile:</u> ' . $mobile . '<br>';
        }
        if ($address) {
            $address = convert_square_bracket($address);
            $all_text .= '<u>Address:</u> ' . $address . '<br>';
        }
        if ($notes) {
            $notes = convert_square_bracket($notes);
            $all_text .= '<u>Notes:</u> ' . $notes . '<br>';
        }
        if ($url) {
            $url = convert_square_bracket($url);
            $url_encoded = base64_encode($url);
            $all_text .= '<u>Website:</u> <a href="load-url.php?url_encoded=' . $url_encoded . '" target="_blank">' . $url . '</a><br>';
        }
        $all_text .= '</td>

<td width="25%" valign="top"><font size="1"><u>' . $category_text . '</u><br>
ID:' . $ID . ' &nbsp;&nbsp;&nbsp; Added: ' . $datetime_converted . '<p>

User: <a href="show-user.php?username='******'"><font size="1">' . $username . '</font></a>

</font>

</td></tr>';
    }
    $all_text .= '</table>';
$html_instance = new html();
$userid = $base_instance->get_userid();
if (isset($_GET['token'])) {
    $token = sql_safe($_GET['token']);
} else {
    if (isset($_GET['chat_id'])) {
        $chat_id = (int) $_GET['chat_id'];
        $data = $base_instance->get_data("SELECT token FROM {$base_instance->entity['LIVE_CHAT']['REQUEST']} WHERE ID='{$chat_id}'");
        $token = $data[1]->token;
    } else {
        exit;
    }
}
$html_instance->add_parameter(array('ACTION' => 'show_content', 'ENTITY' => 'LIVE_CHAT', 'MAXHITS' => 40, 'WHERE' => "WHERE token='{$token}'", 'HEADER' => 'Live Chat Transcript &nbsp;&nbsp; <a href="javascript:DelLiveChat()">[Delete]</a>', 'INNER_TABLE_WIDTH' => '80%', 'ORDER_COL' => 'ID', 'ORDER_TYPE' => 'ASC', 'URL_PARAMETER' => "token={$token}", 'HEAD' => '<script language="JavaScript" type="text/javascript">function DelLiveChat() {if (confirm("Delete Live Chat?")) {this.location.href="delete-live-chat.php?token=' . $token . '&back=1";} else {}}</script>'));
$data = $html_instance->get_items();
if (!$data) {
    $all_text = 'Live Chat not found';
} else {
    $all_text = '<table width="100%" border cellspacing=0 cellpadding=5 class="pastel">';
    for ($index = 1; $index <= sizeof($data); $index++) {
        $username = $data[$index]->username;
        $message = $data[$index]->message;
        $datetime = $data[$index]->datetime;
        $message = convert_square_bracket($message);
        $all_text .= '<tr><td valign="top">' . $datetime . ' <b>' . $username . ':</b> ' . $message . '</td></tr>';
    }
    $all_text .= '</table>';
}
$content_array[1] = array('MAIN' => $all_text);
$html_instance->content = $content_array;
$html_instance->process();
    function random_notes()
    {
        global $base_instance;
        $data = $base_instance->get_data("SELECT * FROM {$base_instance->entity['NOTE']['MAIN']} WHERE user={$this->user} ORDER BY RAND() LIMIT 1");
        if (!$data) {
            $all_text = '<table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" class="pastel2"><tr><td width="100%" style="background-image: url(\'pics/gradient.jpg\');border-bottom:1px solid ' . _BLOCK_LINE_COLOR . '">&nbsp;<b>Random Note</b></td></tr><tr><td width="100%" style="padding:10">No notes saved</td></tr></table>';
            return $all_text;
        }
        $note_id = $data[1]->ID;
        $note_title = $data[1]->title;
        $note_text = $data[1]->text;
        $note_category_id = $data[1]->category;
        $data = $base_instance->get_data("SELECT title FROM {$base_instance->entity['NOTE']['CATEGORY']} WHERE ID={$note_category_id}");
        $note_category_text = $data[1]->title;
        $note_text = convert_square_bracket($note_text);
        $note_text = $base_instance->insert_links($note_text);
        $note_text = nl2br($note_text);
        $all_text = '<table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" class="pastel2"><tr><td width="100%" style="background-image: url(\'pics/gradient.jpg\');border-bottom:1px solid ' . _BLOCK_LINE_COLOR . '">&nbsp;<b>Random Note</b> - ' . $note_category_text . ' - <a href="edit-note.php?note_id=' . $note_id . '">[Edit]</a> &nbsp; <a href="javascript:DelNote(\'' . $note_id . '\')">[Delete]</a></td></tr><tr><td style="padding:10"><div id="item' . $note_id . '"><b>' . $note_title . '</b><br>' . $note_text . '</div></td></tr></table>

<script language="JavaScript" type="text/javascript">function createRequestObject(){try {var requester=new XMLHttpRequest();}catch (error) {try{var requester=new ActiveXObject("Microsoft.XMLHTTP");}catch(error){return false;}}return requester;}var http=createRequestObject();function DelNote(item){if(confirm("Delete Note?")){http.open(\'get\',\'delete-note.php?item=\'+item);http.onreadystatechange=handleResponse;http.send(null);}}function handleResponse(){if(http.readyState==4){var response=http.responseText;var update=new Array();if(response.indexOf(\'|\'!=-1)){res=response.split(\'|\');document.getElementById(res[0]).innerHTML=res[1];}}}</script>';
        return $all_text;
    }
}
if (_SHORT_URLS == 1) {
    $url_blog = _HOMEPAGE . '/blog-' . $username;
} else {
    $url_blog = _HOMEPAGE . '/show-blog-public.php?username='******'<li><a href="' . $url_blog . '">Show all</a></li>';
#
$search_form = '<form action="show-blog-public.php" method="post">
<input type="hidden" name="username" value="' . $username . '">
<font size="1">Blog Search:</font><br>
<input type="text" name="text_search" size="10" onFocus="this.select()">
<input type="submit" value="Go"></form><br><br>';
$rss_feed = '<a href="show-blog-public-rss.php?user='******'"><img src="' . _HOMEPAGE . '/pics/rss.jpg" border="0" alt="RSS Feed"> RSS Feed</a><p>';
#
$about_me = convert_square_bracket($about_me);
$about_me = nl2br($about_me);
if (!empty($text_search)) {
    $text = preg_replace("/({$text_search})/i", "<b>\\1</b>", $text);
}
$about_me = $base_instance->insert_links($about_me);
$main = '<p>' . $about_me;
if (_SHORT_URLS == 1) {
    $about_me_link = _HOMEPAGE . '/user-' . $username;
} else {
    $about_me_link = _HOMEPAGE . '/show-about-me.php?username='******'<meta name="robots" content="index,follow">
<link rel="alternate" type="application/rss+xml" title="Blog of ' . $username . '" href="show-blog-public-rss.php?user='******'">';
$scrollbar = '';
$title = 'About me - Blog of ' . $username;