function loesche_posting()
{
    global $conn, $th_id, $po_id, $thread;
    global $arr_delete;
    global $farbe_tabellenrahmen, $farbe_tabelle_kopf2, $punkte_pro_posting, $t, $farbe_text;
    $arr_delete = array();
    //tabelle posting und thema locken
    $sql = "LOCK TABLES posting, thema WRITE";
    @mysql_query($sql, $conn);
    //rekursiv alle zu loeschenden postings in feld einlesen
    $arr_delete[] = $po_id;
    hole_alle_unter($po_id);
    //po_threadorder neu schreiben
    //nur relevant, wenn posting nicht erster im Thread
    //ansonsten wird es eh geloescht
    if ($po_id != $thread) {
        $sql = "select po_threadorder, po_ts from posting where po_id=" . intval($thread);
        $query = mysql_query($sql, $conn);
        $threadorder = mysql_result($query, 0, "po_threadorder");
        $new_ts = mysql_result($query, 0, "po_ts");
        //in array einlesen und zu loeschende rausschmeissen
        $arr_new_threadorder = explode(",", $threadorder);
        $arr_new_threadorder = array_diff($arr_new_threadorder, $arr_delete);
        if (count($arr_new_threadorder) == 0) {
            $arr_new_threadorder[0] = 0;
        } else {
            // beim löschen eines Postings wird hier die letzte änderung aller postings gesucht, damit
            // der thread_ts wieder stimmt
            $new_ts = '0000000000';
            $new_threadorder = implode(",", $arr_new_threadorder);
            $arr_new_threadorder = explode(",", $new_threadorder);
            for ($i = 0; $i < count($arr_new_threadorder); $i++) {
                $sql = "select po_ts from posting where po_id = " . intval($arr_new_threadorder[$i]);
                $query = mysql_query($sql, $conn);
                $ts = mysql_result($query, 0, "po_ts");
                if ($ts > $new_ts) {
                    $new_ts = $ts;
                }
            }
        }
        $new_threadorder = implode(",", $arr_new_threadorder);
        $sql = "update posting\n                        set po_threadorder = '{$new_threadorder}', po_threadts = {$new_ts}\n                        where po_id = {$thread}";
        mysql_query($sql, $conn);
        //eventuell letztes Posting auf ebene neu markieren
        $sql = "select po_vater_id, po_threadorder from posting where po_id = " . intval($po_id);
        $query = mysql_query($sql, $conn);
        $threadorder = mysql_result($query, 0, "po_threadorder");
        $vater_id = mysql_result($query, 0, "po_vater_id");
        //falls letztes posting, dann neu setzen
        if ($threadorder == "1") {
            $sql = "select po_id from posting\n                                where po_vater_id = {$vater_id}\n                                and po_id <> " . intval($po_id) . "\n                                order by po_ts desc\n                                limit 1";
            $query = mysql_query($sql, $conn);
            if (mysql_num_rows($query) > 0) {
                $po_id_update = mysql_result($query, 0, "po_id");
                $sql = "update posting\n                                        set po_threadorder = '1'\n                                        where po_id = {$po_id_update}";
                mysql_query($sql, $conn);
            }
        }
    }
    //eintragungen in Thema neu schreiben
    $sql = "select th_anzthreads, th_anzreplys, th_postings from thema where th_id=" . intval($th_id);
    $query = mysql_query($sql, $conn);
    $postings = mysql_result($query, 0, "th_postings");
    $anzthreads = mysql_result($query, 0, "th_anzthreads");
    $anzreplys = mysql_result($query, 0, "th_anzreplys");
    //in array einlesen und zu loeschende rausschmeissen
    $arr_new_postings = explode(",", $postings);
    $arr_new_postings = array_diff($arr_new_postings, $arr_delete);
    $new_postings = implode(",", $arr_new_postings);
    //th_anzthreads und th_anzreplys neu schreiben
    if ($po_id == $thread) {
        $anzthreads--;
        $anzreplys = $anzreplys - count($arr_delete) + 1;
    } else {
        $anzreplys = $anzreplys - count($arr_delete);
    }
    $sql = "update thema\n                set th_anzthreads = {$anzthreads},\n                th_anzreplys = {$anzreplys},\n                th_postings = '{$new_postings}'\n                where th_id = " . intval($th_id);
    mysql_query($sql, $conn);
    // Punkte abziehen
    echo "<table width=\"760\" cellspacing=\"0\" cellpadding=\"1\" border=\"0\" bgcolor=\"{$farbe_tabellenrahmen}\"><tr><td>\n" . "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\">" . "<tr bgcolor=\"{$farbe_tabelle_kopf2}\" valign=\"bottom\">\n<TD><DIV style=\"color:{$farbe_text}; font-weight:bold;\">";
    reset($arr_delete);
    while (list($k, $v) = @each($arr_delete)) {
        $sql = "select po_u_id from posting where po_id = " . intval($v);
        $result = mysql_query($sql, $conn);
        if ($result && mysql_num_rows($result) == 1) {
            $po_u_id = mysql_result($result, 0, 0);
            if ($po_u_id) {
                echo $t['forum_punkte2'] . punkte_offline($punkte_pro_posting * -1, $po_u_id) . "<BR>";
            }
        }
        @mysql_free_result($result);
    }
    echo "</DIV></TD></tr></table></td></tr></table><BR>\n";
    reset($arr_delete);
    while (list($k, $v) = @each($arr_delete)) {
        $sql = "delete from posting where po_id = " . intval($v);
        mysql_query($sql, $conn);
    }
    //Tabellen wieder freigeben
    $sql = "UNLOCK TABLES";
    @mysql_query($sql, $conn);
}
function verbuche_punkte($u_id)
{
    global $t, $punkte_pro_posting, $farbe_tabellenrahmen, $farbe_tabelle_kopf2, $farbe_text;
    global $punktefeatures;
    if ($punktefeatures) {
        echo "<table width=\"760\" cellspacing=\"0\" cellpadding=\"1\" border=\"0\" bgcolor=\"{$farbe_tabellenrahmen}\"><tr><td>\n";
        echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\">";
        echo "<tr bgcolor=\"{$farbe_tabelle_kopf2}\" valign=\"bottom\">\n<TD><DIV style=\"color:{$farbe_text}; font-weight:bold;\">" . $t['forum_punkte1'] . punkte_offline($punkte_pro_posting, $u_id) . "</DIV></TD></tr></table></td></tr></table><BR>\n";
    }
}