////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// erlaubnis bei intrabvv speziell setzen
$database = $environment["parameter"][1];
if (is_array($_SESSION["katzugriff"])) {
    if (in_array("-1:" . $database . ":" . $environment["parameter"][2], $_SESSION["katzugriff"])) {
        $erlaubnis = -1;
    }
}
if (is_array($_SESSION["dbzugriff"])) {
    if (in_array($database, $_SESSION["dbzugriff"])) {
        $erlaubnis = -1;
    }
}
$db->selectDb($database, FALSE);
// spezial-check fuer artikel
$tname2path = tname2path($environment["parameter"][2]);
$erlaubnis = "";
if (is_array($cfg["bloged"]["blogs"][substr($tname2path, 0, strrpos($tname2path, "/"))]) && $cfg["bloged"]["blogs"][substr($tname2path, 0, strrpos($tname2path, "/"))]["category"] != "") {
    $kate = $cfg["bloged"]["blogs"][substr($tname2path, 0, strrpos($tname2path, "/"))]["category"];
    $laenge = strlen($kate) + 2;
    $art_version = "1";
    if ($environment["parameter"][6] != "") {
        $art_version = $environment["parameter"][6];
    }
    $sql = "SELECT SUBSTR(content,POSITION('[" . $kate . "]' IN content)+" . $laenge . ",POSITION('[/" . $kate . "]' IN content)-" . $laenge . "-POSITION('[" . $kate . "]' IN content) )as check_url from site_text where version=" . $art_version . " AND tname = '" . $environment["parameter"][2] . "'";
    $result = $db->query($sql);
    $data = $db->fetch_array($result, 1);
    $erlaubnis = priv_check($data["check_url"], $cfg["contented"]["right"]);
}
if (($cfg["contented"]["right"] == "" || priv_check($tname2path, $cfg["contented"]["right"], $specialvars["dyndb"]) || $erlaubnis == 1) && $tname2path != "") {
    // page basics
         }
         $ausgaben["ref_comp"] .= "<b>#" . $value["id"] . "</b>" . $group_content . "<br>";
     }
 } else {
     $ausgaben["ref_comp"] = "---";
 }
 $compilations_OnTheFly = compilation_list("", 25, 1);
 foreach ($compilations_OnTheFly as $ofl_id) {
     $ofl_array = explode(":", $ofl_id["id"]);
     if (in_array($environment["parameter"][1], $ofl_array)) {
         if (count($ofl_id["content"]) > 0) {
             foreach ($ofl_id["content"] as $content) {
                 if ($group_content != "") {
                     $group_content .= ", ";
                 }
                 $used_in = tname2path($content);
                 $group_content .= "<a href=\"" . $used_in . ".html\" title=\"/" . $used_in . ".html\">[" . $i . "]</a>";
                 $i++;
             }
         }
         if ($group_content != "") {
             $group_content = " (#(used_in) " . $group_content . ")";
         }
         $ausgaben["ref_comp"] .= "<b>OnTheFly#" . $ofl_id["name"] . "</b>" . $group_content . "<br>";
     }
 }
 // ersetzen-feld
 if ($_SESSION["uid"] == $form_values["fuid"] || count($intersect_groups) > 0) {
     # oder wenn man in berechtigter gruppe ist
     // dateien duerfen nur ersetzt werden, wenn sie nirgends verwendet werden
     if (count($used_in) == 0 && count($intersect) == 0 || $cfg["fileed"]["replace_used"] == true) {
function show_blog($url, $tags, $right = "", $limit = "", $kategorie = "", $future = "")
{
    global $db, $pathvars, $ausgaben, $mapping, $hidedata, $environment, $cfg, $specialvars;
    // parameter-erklaerung
    // 1: vorgesehen fuer inhalt_selector
    // 2: aufruf eines einzigen contents
    // 3: anzeige als faq
    // unzugaengliche #(marken) sichtbar machen
    if (isset($HTTP_GET_VARS["edit"])) {
        $ausgaben["inaccessible"] = "inaccessible values:<br />";
        $ausgaben["inaccessible"] .= "# (error1) #(error1)<br />";
    } else {
        $ausgaben["inaccessible"] = "";
    }
    // label bearbeitung aktivieren
    if (isset($_GET["edit"])) {
        $specialvars["editlock"] = 0;
    } else {
        $specialvars["editlock"] = -1;
    }
    // aus der url eine id machen
    $id = make_id($url);
    $new = $id["mid"];
    $where = "";
    // manipulation verhindern
    if ($environment["parameter"][2] != "" && !preg_match("/^[0-9]*\$/", $environment["parameter"][2])) {
        header('Location: /index.html');
        exit;
    }
    $sort_len = strlen($cfg["bloged"]["blogs"][$url]["sort"][0]) + 2;
    // hier erfolgt der rechte-check
    $check_url = $url;
    if ($kategorie != "") {
        $check_url = $kategorie;
    }
    $status = "status=1";
    $order = "";
    $wizard_right = "";
    // falls der der content bei dem der blog eingebunden ist, zur Freigabe angefordert ist, darf hier nichts mehr passieren
    if ($kategorie == tname2path($environment["parameter"][2]) && !priv_check($check_url, "publish")) {
        $sql = "SELECT status from site_text WHERE tname='" . $environment["parameter"][2] . "' AND label='" . $environment["parameter"][3] . "' ORDER by version DESC";
        $result = $db->query($sql);
        $data = $db->fetch_array($result, 1);
        if ($data["status"] == -2) {
            $wizard_right = "NO";
        }
    }
    if ($right == "" || priv_check($check_url, $right) && $wizard_right == "") {
        $hidedata["new"]["link"] = $url;
        $hidedata["new"]["kategorie"] = $kategorie;
        if ($environment["ebene"] == "/wizard") {
            $status = "(status=1 OR status = -1)";
            $order = " DESC ,changed";
        }
    }
    // erster test einer suchanfrage per kalender
    //
    if ($environment["parameter"][4] && $environment["kategorie"] != "delete") {
        $parameter = ",,," . $environment["parameter"][4] . "," . $environment["parameter"][5] . "," . $environment["parameter"][6];
        if ($cfg["bloged"]["blogs"][$url]["sort"][1] != -1) {
            $heute = getdate(mktime(0, 0, 0, $environment["parameter"][5] + 1, 0, $environment["parameter"][4]));
            if ($environment["parameter"][5] == "") {
                $month2 = "1";
                $month1 = "12";
            } else {
                $month1 = $environment["parameter"][5];
                $month2 = $environment["parameter"][5];
            }
            if (!$environment["parameter"][6]) {
                $day1 = $heute["mday"];
                $day2 = "1";
            } else {
                $day1 = $environment["parameter"][6];
                $day2 = $environment["parameter"][6];
            }
            // parameter - check
            $preg_error = "";
            if (!preg_match("/^[0-9]{4}\$/", $environment["parameter"][4])) {
                $preg_error = -1;
            }
            if ($environment["parameter"][5] != "" && !preg_match("/^[0-9]{1,2}\$/", $environment["parameter"][5])) {
                $preg_error = -1;
            }
            if ($environment["parameter"][6] != "" && !preg_match("/^[0-9]{1,2}\$/", $environment["parameter"][6])) {
                $preg_error = -1;
            }
            if ($preg_error == -1) {
                header('Location: /index.html');
                exit;
            }
            $environment["parameter"][4] = min($environment["parameter"][4], '2035');
            $environment["parameter"][4] = max($environment["parameter"][4], '1970');
            if ($cfg["bloged"]["blogs"][$url]["ext_sort"] == "") {
                $where .= " AND Cast(SUBSTRING(content,POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)+" . $sort_len . ",POSITION('[/" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-" . $sort_len . ") as DATETIME) < '" . $environment["parameter"][4] . "-" . $month1 . "-" . $day1 . " 23:59:59' AND Cast(SUBSTRING(content,POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)+" . $sort_len . ",POSITION('[/" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-" . $sort_len . ") as DATETIME) > '" . $environment["parameter"][4] . "-" . $month2 . "-" . $day2 . " 00:00:00'";
            } else {
                $where .= " AND (( Cast(SUBSTRING(content,POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)+" . $sort_len . ",POSITION('[/" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-" . $sort_len . ") as DATETIME) < '" . $environment["parameter"][4] . "-" . $month1 . "-" . $day1 . " 23:59:59' AND Cast(SUBSTRING(content,POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)+" . $sort_len . ",POSITION('[/" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-" . $sort_len . ") as DATETIME) >= '" . $environment["parameter"][4] . "-" . $month2 . "-" . $day2 . " 00:00:00')";
                $sort_len2 = strlen($cfg["bloged"]["blogs"][$url]["ext_sort"]) + 2;
                $where .= " OR ( Cast(SUBSTRING(content,POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)+" . $sort_len . ",POSITION('[/" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-" . $sort_len . ") as DATETIME) <= '" . $environment["parameter"][4] . "-" . $month1 . "-" . $day2 . " 00:00:00' AND  Cast(SUBSTRING(content,POSITION('[" . $cfg["bloged"]["blogs"][$url]["ext_sort"] . "]' IN content)+" . $sort_len2 . ",POSITION('[/" . $cfg["bloged"]["blogs"][$url]["ext_sort"] . "]' IN content)-POSITION('[" . $cfg["bloged"]["blogs"][$url]["ext_sort"] . "]' IN content)-" . $sort_len2 . ") as DATETIME) >= '" . $environment["parameter"][4] . "-" . $month2 . "-" . $day2 . " 00:00:00'))";
            }
        }
    }
    //
    // erster test einer suchanfrage per kalender
    // falls kategorie , werden nur diese angezeigt
    if ($kategorie != "") {
        $cat_len = strlen($cfg["bloged"]["blogs"][$url]["category"]) + 2;
        $where .= "  AND SUBSTRING(content,POSITION('[" . $cfg["bloged"]["blogs"][$url]["category"] . "]' IN content),POSITION('[/" . $cfg["bloged"]["blogs"][$url]["category"] . "]' IN content)-POSITION('[" . $cfg["bloged"]["blogs"][$url]["category"] . "]' IN content)) ='[" . $cfg["bloged"]["blogs"][$url]["category"] . "]" . $kategorie . "'";
    }
    if ($future == -1) {
        $where .= " AND Cast(SUBSTRING(content,POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)+" . $sort_len . ",POSITION('[/" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-" . $sort_len . ") as DATETIME) < '" . date('Y-m-d') . " 23:59:59'";
    }
    $tname = eCRC($url) . ".%";
    // falls parameter 2 gesetzt, wird nur dieser content geholt
    if ($environment["parameter"][2] != "" && $environment["ebene"] != "/wizard") {
        $tname = eCRC($url) . "." . $environment["parameter"][2];
    }
    // falls sort auf -1 wird anstatt ein datum ein integer als sortiermerkmal gesetzt um ein manuelles sortieren zu ermoeglichen
    if ($cfg["bloged"]["blogs"][$url]["sort"][1] == "-1") {
        $art = "SIGNED";
    } else {
        $art = "DATETIME";
    }
    // hier der endgueltige sql !!
    $sql = "SELECT Cast(SUBSTRING(content,POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)+" . $sort_len . ",POSITION('[/" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-POSITION('[" . $cfg["bloged"]["blogs"][$url]["sort"][0] . "]' IN content)-" . $sort_len . ") AS " . $art . ") AS date,status,content,tname from site_text WHERE " . $status . " AND tname like '" . $tname . "'" . $where . " order by date" . $order . " DESC";
    // damit kann man beliebig viele blogs manuell holen
    $ausgaben["inhalt_selector"] = "";
    if (strpos($limit, ",")) {
        $sql = $sql . " LIMIT " . $limit;
    } else {
        if ($limit != "") {
            $hidedata["inhalt_selector"]["on"] = "on";
            $p = $environment["parameter"][1] + 0;
            // seiten umschalter
            $inhalt_selector = inhalt_selector($sql, $p, $limit, $parameter, 1, 10, $getvalues);
            $ausgaben["inhalt_selector"] = $inhalt_selector[0] . "<br />";
            $sql = $inhalt_selector[1];
            $ausgaben["anzahl"] = $inhalt_selector[2];
            $ausgaben["sel_hit"] = $inhalt_selector[3];
        }
    }
    $counter = 0;
    $result = $db->query($sql);
    $preg1 = "\\.([0-9]*)\$";
    // evtl wizard einbinden
    if ($cfg["bloged"]["blogs"][$url]["wizard"] != "") {
        $editlink = "/wizard/show,";
    } else {
        $editlink = "/admin/contented/edit,";
    }
    while ($data = $db->fetch_array($result, 1)) {
        $tag_parameter = "";
        $counter++;
        // im wizard wird der content aus der SESSION-Variablen genommen
        if ($_SESSION["wizard_content"][DATABASE . "," . $data["tname"] . ",inhalt"] && $environment["ebene"] == "/wizard") {
            $test = preg_replace("|\r\n|", "\\r\\n", $_SESSION["wizard_content"][DATABASE . "," . $data["tname"] . ",inhalt"]);
        } else {
            $test = preg_replace("|\r\n|", "\\r\\n", $data["content"]);
        }
        foreach ($tags as $key => $value) {
            // finden der parameter sowie begin und endtag
            $invisible = "";
            if (is_array($value)) {
                $tag_parameter = $value["parameter"];
                $invisible = $value["invisible"];
                $show = $value["show"];
                $value = $value["tag"];
            }
            if (strpos($value, "=")) {
                $endtag = substr($value, 0, strpos($value, "="));
                if ($value == "IMG=") {
                    $value .= ".*";
                } else {
                    $value = $value . $tag_parameter;
                }
            } else {
                $endtag = $value;
            }
            // preg nach den tags in der config
            $preg = "(\\[" . addcslashes($value, "/") . "\\])(.*)\\[\\/" . $endtag . "\\]";
            if (preg_match("/{$preg}/Us", $test, $regs)) {
                $rep_tag = str_replace('\\r\\n', "<br />", $regs[0]);
                $org_tag = str_replace('\\r\\n', "<br />", $regs[2]);
            } else {
                $rep_tag = "";
                $org_tag = "";
            }
            // gefundene werte in array schreiben
            if ($invisible != -1) {
                $array[$counter][$key . "_wizard_edit_link"] = $pathvars["virtual"] . "/wizard/editor," . DATABASE . "," . $data["tname"] . ",inhalt," . $value . ":0,,,.html";
                $array[$counter][$key . "_org"] = str_replace("\"", "'", $org_tag);
                $array[$counter][$key . "_org_tag"] = $value;
                $array[$counter][$key] = tagreplace($rep_tag);
                if ($org_tag == "") {
                    $array[$counter][$key] = "";
                }
                if (preg_match("/^\\[IMG/", $rep_tag, $regs_img)) {
                    $image_para = explode("/", $rep_tag);
                    $array[$counter][$key . "_img_art"] = $image_para[2];
                    $array[$counter][$key . "_img_id"] = $image_para[3];
                    $array[$counter][$key . "_img_size"] = $image_para[4];
                    $sql_img = "SELECT * FROM site_file WHERE fid='" . $image_para[3] . "'";
                    $result_img = $db->query($sql_img);
                    $data_img = $db->fetch_array($result_img, 1);
                    $array[$counter][$key . "_img_desc"] = $data_img["fdesc"];
                    $array[$counter][$key . "_img_under"] = $data_img["funder"];
                    $array[$counter][$key . "_img_fname"] = $data_img["ffname"];
                    if ($show != "") {
                        $rep_tag = str_replace("/" . $image_para[4] . "/", "/" . $show . "/", $rep_tag);
                    }
                }
            } else {
                if (preg_match("/^\\[IMG/", $rep_tag, $reg_img)) {
                    $image_para = explode("/", $rep_tag);
                    $invisible_array[$counter][$key . "_img_art"] = $image_para[2];
                    $invisible_array[$counter][$key . "_img_id"] = $image_para[3];
                    $invisible_array[$counter][$key . "_img_size"] = $image_para[4];
                    if ($show != "") {
                        $rep_tag = str_replace("/" . $image_para[4] . "/", "/" . $show . "/", $rep_tag);
                    }
                }
                $invisible_array[$counter][$key . "_org"] = str_replace("\"", "'", $org_tag);
                $invisible_array[$counter][$key] = tagreplace($rep_tag);
                $array[$counter][$key . "_org"] = "";
                $array[$counter][$key] = "";
            }
        }
        preg_match("/{$preg1}/", $data["tname"], $regs);
        if ($environment["parameter"][2] != "" && $environment["ebene"] != "/wizard") {
            $array[$counter]["all"] = tagreplace($data["content"]);
            $array[$counter]["id"] = $regs[1];
        } else {
            $array[$counter]["datum"] = substr($data["date"], 8, 2) . "." . substr($data["date"], 5, 2) . "." . substr($data["date"], 0, 4);
            $array[$counter]["detaillink"] = $pathvars["virtual"] . $url . "/" . $regs[1] . ".html";
            if ($environment["ebene"] == "") {
                $faq_url = "/" . $environment["kategorie"];
            } else {
                $faq_url = $environment["ebene"] . "/" . $environment["kategorie"];
            }
            $array[$counter]["faqlink"] = $pathvars["virtual"] . $faq_url . ",,," . $regs[1] . ".html#faq_" . $regs[1];
            $array[$counter]["faqanker"] = "faq_" . $regs[1];
            $array[$counter]["allink"] = $pathvars["virtual"] . $faq_url . ",," . $regs[1] . ".html";
            $array[$counter]["id"] = $regs[1];
            $array[$counter]["status"] = $data["status"];
            // Sortierung ausgeben
            // ausgabe der aktions-buttons
            if ($right == "" || priv_check($check_url, $right) && $wizard_right == "") {
                if ($cfg["bloged"]["blogs"][$url]["sort"][1] == "-1") {
                    $sort_kat = "";
                    if ($kategorie != "") {
                        $id = make_id($kategorie);
                        $sort_kat = $id["mid"];
                    }
                    $array[$counter]["sort_up"] = $pathvars["virtual"] . "/admin/bloged/sort,up," . $regs[1] . "," . $sort_kat . "," . $new . ".html";
                    $array[$counter]["sort_down"] = $pathvars["virtual"] . "/admin/bloged/sort,down," . $regs[1] . "," . $sort_kat . "," . $new . ".html";
                } else {
                    $array[$counter]["sort_up"] = "";
                    $array[$counter]["sort_down"] = "";
                }
                $array[$counter]["wizard_delete_link"] = $pathvars["virtual"] . "/wizard/delete," . DATABASE . "," . $data["tname"] . ",inhalt.html\"";
                $array[$counter]["deletelink"] = "<a href=\"" . $pathvars["virtual"] . "/admin/bloged/delete,," . $regs[1] . "," . $sort_kat . "," . $new . ".html\">g(blog_delete)</a>";
                $array[$counter]["editlink"] = "<a href=\"" . $pathvars["virtual"] . $editlink . DATABASE . "," . $data["tname"] . ",inhalt.html\">g(blog_edit)</a>";
                $array[$counter]["tname"] = eCrc($url);
            } else {
                $array[$counter]["editlink"] = "";
                $array[$counter]["deletelink"] = "";
                $array[$counter]["sort"] = "";
            }
        }
        if ($environment["parameter"][3] == $regs[1]) {
            if (is_array($invisible_array)) {
                foreach ($invisible_array[$counter] as $key => $value) {
                    $array[$counter][$key] = $value;
                }
            }
        }
    }
    // was anzeigen
    if ($environment["ebene"] == "") {
        $templ = $environment["kategorie"];
    } else {
        $templ = eCRC($environment["ebene"]) . "." . $environment["kategorie"];
    }
    if (file_exists($pathvars["templates"] . $templ . ".tem.html")) {
        $mapping["main"] = $templ;
    } elseif ($cfg["bloged"]["blogs"][$url]["own_list_template"] != "") {
        $mapping["main"] = "-2051315182." . $cfg["bloged"]["blogs"][$url]["own_list_template"];
    } elseif ($cfg["bloged"]["blogs"][$url]["sort"][1] != "") {
        $mapping["main"] = "-2051315182.faq";
    } else {
        $mapping["main"] = "-2051315182.list";
    }
    return $array;
}
 foreach ($sliced_groups as $key => $value) {
     $id = $value["id"];
     $check = "";
     if (is_array($_SESSION["compilation_memo"][$id])) {
         $check = " checked=\"true\"";
     }
     $edit = "&nbsp;";
     if ($value["name"] == "---" || $cfg["fileed"]["compilation"]["blocked_used"] != true) {
         $edit = "<a href=\"" . $cfg["fileed"]["basis"] . "/collect," . $id . ".html\" title=\"g(edit)\"><img src=\"/images/default/edit.png\" alt=\"g(edit)\" /></a>";
         $edit .= "<a href=\"" . $cfg["fileed"]["basis"] . "/collect," . $id . ",delete.html\" title=\"g(delete)\"><img src=\"/images/default/delete.png\" alt=\"g(delete)\" /></a>";
     }
     $used_on = "";
     if (is_array($value["content"])) {
         $used_on = "<br />#(used_on)";
         foreach ($value["content"] as $tname) {
             $link = tname2path($tname) . ".html";
             $used_on .= "<br /><a href=\"" . $link . "\">" . $link . "</a>";
         }
     }
     $used_title_text = "";
     $used_title_show = "display:none;";
     if ($value["name"] != "---") {
         $used_title_text = str_replace(";;", "<br />", $value["name"]);
         $used_title_show = "";
     }
     $dataloop["compilation"][$id] = array("id" => $id, "count" => $num_pics, "used_on" => $used_on, "check" => $check, "edit" => $edit, "used_title_text" => $used_title_text, "used_title_show" => $used_title_show, "used_title" => "");
     // bilder der compilation finden
     $sql = "SELECT *\n                      FROM site_file\n                     WHERE fhit\n                      LIKE '%#p" . $id . ",%'\n                  ORDER BY fid";
     $list_item = "<li class=\"thumbs\">\n                                <a title=\"##title##\" class=\"pic\" rel=\"lightbox[##cid##]\" href=\"##src_lb##\"><img title=\"##title##\" alt=\"##title##\" src=\"##src##\"/></a>\n                                <input id=\"c##cid##p##pid##\" class=\"sel_pic_checkbox\" type=\"checkbox\" value=\"-1\" onclick=\"session_update(##cid##,##pid##);\"##check## />\n                          </li>";
     $search = array('##title##', '##cid##', '##pid##', '##src_lb##', '##src##', '##check##');
     $result = $db->query($sql);
function tagreplace($replace)
{
    global $db, $debugging, $cfg, $pathvars, $environment, $ausgaben, $defaults, $specialvars, $dataloop, $hidedata, $mapping;
    // cariage return + linefeed fix
    if ($specialvars["newbrmode"] != True) {
        $sear = array("\r\n[TA", "\r\n[RO", "\r\n[CO", "/H1]\r\n", "/H2]\r\n", "/H3]\r\n", "/H4]\r\n", "/H5]\r\n", "/H6]\r\n[", "/HR]\r\n", "AB]\r\n", "OW]\r\n", "OL]\r\n", "IV]\r\n");
        $repl = array("[TA", "[RO", "[CO", "/H1]", "/H2]", "/H3]", "/H4]", "/H5]", "/H6]", "/HR]", "AB]", "OW]", "OL]", "IV]");
        $replace = str_replace($sear, $repl, $replace);
    }
    $preg = "|\\[\\/[!A-Z0-9]{1,6}\\]|";
    $selection_counter = 0;
    $img_counter = 0;
    $imgb_counter = 0;
    while (preg_match($preg, $replace, $match)) {
        $closetag = $match[0];
        if (strstr($replace, $closetag)) {
            // wo beginnt der closetag
            $closetagbeg = strpos($replace, $closetag);
            // wie sieht der opentag aus
            $opentag = str_replace(array("/", "]"), array("", ""), $closetag);
            // wie lang ist der opentag
            $opentaglen = strlen($opentag);
            // nur hier kann der opentag sein
            $haystack = substr($replace, 0, $closetagbeg);
            // fehlenden open tag abfangen
            if (strpos($haystack, $opentag . "]") === false && strpos($haystack, $opentag . "=") === false) {
                if ($defaults["tag"]["error"] == "") {
                    $error = " <font color=\"#FF0000\">" . $opentag . "]?</font> ";
                } else {
                    $error = $defaults["tag"]["error"] . $opentag . "]" . $defaults["tag"]["/error"];
                }
                $replace = $haystack . $error . substr($replace, $closetagbeg + $opentaglen + 2);
                continue;
            }
            // wie lautet der tagwert
            $tagwertbeg = strlen($haystack) - (strpos(strrev($haystack), strrev($opentag)) + strlen($opentag)) + $opentaglen + 1;
            $tagoriginal = substr($replace, $tagwertbeg, $closetagbeg - $tagwertbeg);
            $tagwert = $tagoriginal;
            // parameter?
            $sign = substr($replace, $tagwertbeg - 1, 1);
            // opentag komplettieren
            $opentag = $opentag . $sign;
            // kompletten tag mit tagwert ersetzen
            switch ($closetag) {
                //
                // Block Elemente
                // H1-6 | P | PRE | DIV | LIST | HR | TAB, ROW, COL | CENTER
                //
                case "[/H1]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = nlreplace($tagwert);
                    }
                    if ($defaults["tag"]["h1"] == "") {
                        $defaults["tag"]["h1"] = "<h1>";
                        $defaults["tag"]["/h1"] = "</h1>";
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $defaults["tag"]["h1"] . $tagwert . $defaults["tag"]["/h1"], $replace);
                    break;
                case "[/H2]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = nlreplace($tagwert);
                    }
                    if ($defaults["tag"]["h2"] == "") {
                        $defaults["tag"]["h2"] = "<h2>";
                        $defaults["tag"]["/h2"] = "</h2>";
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $defaults["tag"]["h2"] . $tagwert . $defaults["tag"]["/h2"], $replace);
                    break;
                case "[/H3]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = nlreplace($tagwert);
                    }
                    if ($defaults["tag"]["h3"] == "") {
                        $defaults["tag"]["h3"] = "<h3>";
                        $defaults["tag"]["/h3"] = "</h3>";
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $defaults["tag"]["h3"] . $tagwert . $defaults["tag"]["/h3"], $replace);
                    break;
                case "[/H4]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = nlreplace($tagwert);
                    }
                    if ($defaults["tag"]["h4"] == "") {
                        $defaults["tag"]["h4"] = "<h4>";
                        $defaults["tag"]["/h4"] = "</h4>";
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $defaults["tag"]["h4"] . $tagwert . $defaults["tag"]["/h4"], $replace);
                    break;
                case "[/H5]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = nlreplace($tagwert);
                    }
                    if ($defaults["tag"]["h5"] == "") {
                        $defaults["tag"]["h5"] = "<h5>";
                        $defaults["tag"]["/h5"] = "</h5>";
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $defaults["tag"]["h5"] . $tagwert . $defaults["tag"]["/h5"], $replace);
                    break;
                case "[/H6]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = nlreplace($tagwert);
                    }
                    if ($defaults["tag"]["h6"] == "") {
                        $defaults["tag"]["h6"] = "<h6>";
                        $defaults["tag"]["/h6"] = "</h6>";
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $defaults["tag"]["h6"] . $tagwert . $defaults["tag"]["/h6"], $replace);
                    break;
                case "[/P]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = nlreplace($tagwert);
                    }
                    if ($sign == "]") {
                        $ausgabewert = "<p>" . $tagwert . "</p>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $pwerte = explode(";", $tagwerte[0]);
                        $extrawerte = explode(":", $pwerte[0]);
                        if ($extrawerte[1] != "") {
                            $pwerte[0] = $extrawerte[1];
                        }
                        if ($extrawerte[0] == "id") {
                            $art = "id";
                        } else {
                            $art = "class";
                        }
                        $attrib = "";
                        if ($pwerte[0] != "") {
                            $attrib = " " . $art . "=\"" . $pwerte[0] . "\"";
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "<p" . $attrib . ">" . $tagwerte[1] . "</p>", $replace);
                    }
                    break;
                case "[/PRE]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<pre>" . $tagwert . "</pre>", $replace);
                    break;
                case "[/DIV]":
                    if ($specialvars["newbrmode"] == True && strpos($specialvars["newbrblock"], "DIV") === false) {
                        $tagwert = nlreplace($tagwert);
                    }
                    if ($sign == "]") {
                        $ausgabewert = "<div>" . $tagwert . "</div>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $divwerte = explode(";", $tagwerte[0]);
                        $extrawerte = explode(":", $divwerte[0]);
                        if ($extrawerte[1] != "") {
                            $divwerte[0] = $extrawerte[1];
                        }
                        if ($extrawerte[0] == "id") {
                            $art = "id";
                        } else {
                            $art = "class";
                        }
                        $attrib = "";
                        if ($divwerte[0] != "") {
                            $attrib = " " . $art . "=\"" . $divwerte[0] . "\"";
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "<div" . $attrib . ">" . $tagwerte[1] . "</div>", $replace);
                    }
                    break;
                case "[/LIST]":
                    if ($sign == "]") {
                        $tagwerte = explode("[*]", $tagwert);
                        $ausgabewert = "<ul>";
                        while (list($key, $punkt) = each($tagwerte)) {
                            if ($specialvars["newbrmode"] == True) {
                                $punkt = nlreplace($punkt);
                            }
                            $ausgabewert .= "<li><span>" . $punkt . "</span></li>";
                        }
                        $ausgabewert .= "</ul>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    } else {
                        $tagrestbeg = strpos($tagwert, "]");
                        $listart = substr($tagwert, 0, $tagrestbeg);
                        $tagrest = substr($tagwert, $tagrestbeg + 1);
                        $tagwerte = explode("[*]", $tagrest);
                        if ($listart == 1) {
                            $ausgabewert = "<ol>";
                            while (list($key, $punkt) = each($tagwerte)) {
                                if ($specialvars["newbrmode"] == True) {
                                    $punkt = nlreplace($punkt);
                                }
                                $ausgabewert .= "<li><span>" . $punkt . "</span></li>";
                            }
                            $ausgabewert .= "</ol>";
                        } elseif ($listart == "DEF") {
                            $ausgabewert = "<dl>";
                            while (list($key, $punkt) = each($tagwerte)) {
                                if ($specialvars["newbrmode"] == True) {
                                    $punkt = nlreplace($punkt);
                                }
                                if ($key % 2 != 0) {
                                    $ausgabewert .= "<dd>" . $punkt . "</dd>";
                                } else {
                                    $ausgabewert .= "<dt>" . $punkt . "</dt>";
                                }
                            }
                            $ausgabewert .= "</dl>";
                        } else {
                            if (strlen($listart) > 1) {
                                $ausgabewert = "<ul type=\"" . $listart . "\">";
                            } else {
                                $ausgabewert = "<ol type=\"" . $listart . "\">";
                            }
                            while (list($key, $punkt) = each($tagwerte)) {
                                if ($specialvars["newbrmode"] == True) {
                                    $punkt = nlreplace($punkt);
                                }
                                $ausgabewert .= "<li><span>" . $punkt . "</span></li>";
                            }
                            if (strlen($listart) > 1) {
                                $ausgabewert .= "</ul>";
                            } else {
                                $ausgabewert .= "</ol>";
                            }
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    }
                    break;
                case "[/HR]":
                    if ($defaults["tag"]["hr"] == "") {
                        $defaults["tag"]["hr"] = "<hr />";
                        $defaults["tag"]["/hr"] = "";
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $defaults["tag"]["hr"] . $tagwert . $defaults["tag"]["/hr"], $replace);
                    break;
                case "[/TAB]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = str_replace("\r\n", "", $tagwert);
                    }
                    if ($sign == "]") {
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "<table cellspacing=\"0\" cellpadding=\"1\">" . $tagwert . "</table>", $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $tabwerte = explode(";", $tagwerte[0]);
                        if ($tabwerte[0] == "l") {
                            $align = " align=\"left\"";
                        } elseif ($tabwerte[0] == "m") {
                            $align = " align=\"center\"";
                        } elseif ($tabwerte[0] == "r") {
                            $align = " align=\"right\"";
                        } else {
                            $align = "";
                        }
                        if ($tabwerte[1] != "") {
                            $width = " width=\"" . $tabwerte[1] . "\"";
                        }
                        if ($tabwerte[2] != "") {
                            $border = " border=\"" . $tabwerte[2] . "\"";
                        }
                        if ($tabwerte[3] != "") {
                            $cellspacing = " cellspacing=\"" . $tabwerte[3] . "\"";
                        } else {
                            $cellspacing = " cellspacing=\"0\"";
                        }
                        if ($tabwerte[4] != "") {
                            $cellpadding = " cellpadding=\"" . $tabwerte[4] . "\"";
                        } else {
                            $cellpadding = " cellpadding=\"1\"";
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "<table" . $cellspacing . $cellpadding . $width . $align . $border . ">" . $tagwerte[1] . "</table>", $replace);
                        $replace = tagreplace($replace);
                    }
                    break;
                case "[/TABCSV]":
                    if ($sign != "]") {
                        $tagwerte = explode("]", $tagwert, 2);
                        $tabwerte = explode(";", $tagwerte[0]);
                        // csv-datei
                        if ($specialvars["subdir"] != "") {
                            $pfad = str_replace($specialvars["subdir"] . "/", "", $tabwerte[0]);
                        } else {
                            $pfad = $tabwerte[0];
                        }
                        $file_path = explode("/", $pfad);
                        $extension = $cfg["file"]["filetyp"][$file_path[2]];
                        $directory = $cfg["file"]["fileopt"][$extension]["path"];
                        $file_name = $extension . "_" . $file_path[3] . "." . $file_path[2];
                        if (file_exists($directory . $file_name)) {
                            $table = "";
                            $handle = fopen($directory . $file_name, "r");
                            // enthaelt die erste zeile spaltenueberschriften
                            if ($tabwerte[3] != "") {
                                $cell_tag1 = "<th scope=\"col\">";
                                $cell_tag2 = "</th>\n";
                                $row_tag1 = "<thead>\n<tr>";
                                $row_tag2 = "</tr>\n</thead>";
                            } else {
                                $cell_tag1 = "<td>";
                                $cell_tag2 = "</td>\n";
                                $row_tag1 = "<tr>";
                                $row_tag2 = "</tr>\n";
                            }
                            $thead = "";
                            while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
                                $row = "";
                                foreach ($data as $value) {
                                    $row .= $cell_tag1 . $value . $cell_tag2;
                                }
                                if ($row != "") {
                                    $table .= $row_tag1 . $row . $row_tag2;
                                }
                                if (strstr($cell_tag1, "<th")) {
                                    $thead = $table;
                                    $table = "";
                                    $cell_tag1 = "<td>";
                                    $cell_tag2 = "</td>\n";
                                    $row_tag1 = "<tr>";
                                    $row_tag2 = "</tr>\n";
                                }
                            }
                            // summary
                            if ($tagwerte[1] != "") {
                                $summary = " summary=\"" . $tagwerte[1] . "\"";
                            } else {
                                $summary = "";
                            }
                            // breite
                            if ($tabwerte[1] != "") {
                                $width = " width=\"" . $tabwerte[1] . "%\"";
                            } else {
                                $width = "";
                            }
                            // border
                            if ($tabwerte[2] != "") {
                                $border = " border=\"" . $tabwerte[2] . "\"";
                            } else {
                                $border = "";
                            }
                            if ($table != "") {
                                $table = "<table" . $border . $width . $summary . ">\n" . $thead . "<tbody>\n" . $table . "</tbody>\n</table>\n";
                            }
                        } else {
                            $table = "";
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $table, $replace);
                    } else {
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "", $replace);
                    }
                    break;
                case "[/ROW]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = str_replace("\r\n", "", $tagwert);
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<tr>" . $tagwert . "</tr>", $replace);
                    break;
                case "[/TH]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = nlreplace($tagwert);
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<th valign=\"top\">" . $tagwert . "</th>", $replace);
                    break;
                case "[/COL]":
                    if ($specialvars["newbrmode"] == True) {
                        $tagwert = nlreplace($tagwert);
                    }
                    if ($sign == "]") {
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "<td valign=\"top\">" . $tagwert . "</td>", $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $colwerte = explode(";", $tagwerte[0]);
                        if ($colwerte[0] == "l") {
                            $align = " align=\"left\"";
                        } elseif ($colwerte[0] == "m") {
                            $align = " align=\"center\"";
                        } elseif ($colwerte[0] == "r") {
                            $align = " align=\"right\"";
                        } else {
                            $align = "";
                        }
                        if ($colwerte[1] != "") {
                            $width = " width=\"" . $colwerte[1] . "\"";
                        }
                        if ($colwerte[2] == "o") {
                            $valign = " valign=\"top\"";
                        } elseif ($colwerte[2] == "m") {
                            $valign = " valign=\"middle\"";
                        } elseif ($colwerte[2] == "u") {
                            $valign = " valign=\"bottom\"";
                        } elseif ($colwerte[2] == "g") {
                            $valign = " valign=\"baseline\"";
                        } else {
                            $valign = " valign=\"top\"";
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "<td" . $align . $width . $valign . ">" . $tagwerte[1] . "</td>", $replace);
                    }
                    break;
                case "[/CENTER]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<center>" . $tagwert . "</center>", $replace);
                    break;
                    //
                    // Inline Elemente
                    // BR | IMG | LINK | -span-
                    //
                //
                // Inline Elemente
                // BR | IMG | LINK | -span-
                //
                case "[/BR]":
                    if ($sign == "]") {
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "<br />", $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $brwerte = explode(";", $tagwerte[0]);
                        if ($brwerte[0] == "a") {
                            $clear = "clear=\"all\"";
                            $style_clear = "style=\"clear:both;\"";
                        } elseif ($brwerte[0] == "l") {
                            $clear = "clear=\"left\"";
                            $style_clear = "style=\"clear:left;\"";
                        } elseif ($brwerte[0] == "r") {
                            $clear = "clear=\"right\"";
                            $style_clear = "style=\"clear:right;\"";
                        } else {
                            $clear = "";
                            $style_clear = "";
                        }
                        if ($specialvars["w3c"] == "strict") {
                            $replace = str_replace($opentag . $tagoriginal . $closetag, "<br " . $style_clear . "/>", $replace);
                        } else {
                            $replace = str_replace($opentag . $tagoriginal . $closetag, "<br " . $clear . "/>", $replace);
                        }
                    }
                    break;
                case "[/IMG]":
                    $img_counter++;
                    $imgsize = "";
                    $imgurl = "";
                    if ($sign == "]") {
                        if (!strstr($tagwert, "/")) {
                            $imgfile = $pathvars["fileroot"] . "images/" . $environment["design"] . "/" . $tagwert;
                            if (file_exists($imgfile)) {
                                $imgsize = getimagesize($imgfile);
                                $imgsize = " " . $imgsize[3];
                                $imgurl = $pathvars["images"] . $tagwert;
                            }
                        } else {
                            $imgurl = $tagwert;
                            if (!strstr($tagwert, "http")) {
                                if (strpos($tagwert, $cfg["file"]["base"]["pic"]["root"]) === false) {
                                    $opt = explode("/", $tagwert);
                                    $imgfile = $cfg["file"]["base"]["maindir"] . $cfg["file"]["base"]["pic"]["root"] . $cfg["file"]["base"]["pic"][$opt[4]] . "img_" . $opt[3] . "." . $opt[2];
                                } elseif (strstr($tagwert, $cfg["file"]["base"]["webdir"])) {
                                    $imgfile = str_replace($cfg["file"]["base"]["webdir"], "", $tagwert);
                                    $imgfile = $cfg["file"]["base"]["maindir"] . $imgfile;
                                } else {
                                    $imgfile = $pathvars["fileroot"] . $tagwert;
                                }
                                if (file_exists($imgfile)) {
                                    $imgsize = getimagesize($imgfile);
                                    $imgsize = " " . $imgsize[3];
                                } else {
                                    $imgsize = "";
                                }
                            }
                        }
                        $ausgabewert = "<img src=\"" . $imgurl . "\" title=\"" . $tagwert . "\" alt=\"" . $tagwert . "\"" . $imgsize . " />";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    } else {
                        if ($defaults["tag"]["img_w3c"] == "") {
                            $defaults["tag"]["img_w3c"] = "<img src=\"##imgurl##\" title=\"##beschriftung##\" alt=\"##beschriftung##\"##imgsize## style=\"##style_align####style_border####style_hspace####style_vspace##\"##attrib## />";
                        }
                        if ($defaults["tag"]["img"] == "") {
                            $defaults["tag"]["img"] = "<img src=\"##imgurl##\"##attrib####vspace####hspace## title=\"##beschriftung##\" alt=\"##beschriftung##\"##align####border####imgsize## />";
                        }
                        if ($defaults["tag"]["img_link"] == "") {
                            $defaults["tag"]["img_link"] = "<a href=\"##imglnk##\" title=\"##beschriftung##\">";
                        }
                        if ($defaults["tag"]["img_link_lb"] == "") {
                            $defaults["tag"]["img_link_lb"] = "<a href=\"##imglnk##\" title=\"##beschriftung##\" ##lightbox## >";
                        }
                        if ($defaults["tag"]["/img_link"] == "") {
                            $defaults["tag"]["/img_link"] = "</a>";
                        }
                        $repl = array("imgurl", "beschriftung", "funder", "fdesc", "imgsize", "attrib", "vspace", "hspace", "align", "border", "style_align", "style_border", "style_hspace", "style_vspace", "imglnk", "lightbox");
                        $tagwerte = explode("]", $tagwert, 2);
                        $imgwerte = explode(";", $tagwerte[0]);
                        $extrawerte = explode(":", $imgwerte[1]);
                        if ($extrawerte[1] != "") {
                            $imgwerte[1] = $extrawerte[1];
                        }
                        if ($extrawerte[0] == "id") {
                            $art = " id";
                        } else {
                            $art = " class";
                        }
                        $align = "";
                        $attrib = "";
                        $style_align = "";
                        if ($imgwerte[1] == "r") {
                            $align = " align=\"right\"";
                            $style_align = "float:right;";
                        } elseif ($imgwerte[1] == "l") {
                            $align = " align=\"left\"";
                            $style_align = "float:left;";
                        } elseif ($imgwerte[1] != "") {
                            $attrib = " " . $art . "=\"" . $imgwerte[1] . "\"";
                        }
                        if ($imgwerte[2] == "0") {
                            $border = " border=\"0\"";
                            $style_border = "border-width:0;";
                        } elseif ($imgwerte[2] > 0) {
                            $border = " border=\"" . $imgwerte[2] . "\"";
                            $style_border = "border-width:" . $imgwerte[2] . "px;";
                        } else {
                            $border = "";
                            $style_border = "";
                        }
                        if ($imgwerte[3] == "l") {
                            $lightbox = "rel=\"lightbox[" . $img_counter . "]\"";
                        }
                        if ($imgwerte[4] == "") {
                            $vspace = "";
                            $style_vspace = "";
                        } else {
                            $vspace = " vspace=\"" . $imgwerte[4] . "\"";
                            $style_vspace = "margin-top:" . $imgwerte[4] . "px;margin-bottom:" . $imgwerte[4] . "px;";
                        }
                        if ($imgwerte[6] == "") {
                            $hspace = "";
                            $style_hspace = "";
                        } else {
                            $hspace = " hspace=\"" . $imgwerte[6] . "\"";
                            if ($imgwerte[1] == "r") {
                                $style_hspace = "margin-left:" . $imgwerte[6] . "px;margin-right:0px;";
                            } elseif ($imgwerte[1] == "l") {
                                $style_hspace = "margin-left:0px;margin-right:" . $imgwerte[6] . "px;";
                            } else {
                                $style_hspace = "margin-left:" . $imgwerte[6] . "px;margin-right:" . $imgwerte[6] . "px;";
                            }
                        }
                        if ($tagwerte[1] == "") {
                            $beschriftung = $imgwerte[0];
                        } else {
                            $beschriftung = $tagwerte[1];
                        }
                        // weitere informationen aus datenbank holen
                        if (preg_match("/^\\//", $tagwerte[0])) {
                            $img_path = explode("/", str_replace($cfg["file"]["base"]["maindir"], "", $tagwerte[0]));
                            if (is_numeric($img_path[3])) {
                                $fid = $img_path[3];
                                //subdir quickfix
                            } elseif (is_numeric($img_path[4])) {
                                $fid = $img_path[4];
                            } else {
                                $fid = substr($tagwerte[0], 0, strpos($tagwerte[0], ";"));
                                $fid = strrchr($fid, "_");
                                $fid = substr($fid, 1, strpos($fid, ".") - 1);
                            }
                            $sql = "SELECT *\n                                            FROM site_file\n                                            WHERE fid=" . $fid;
                            $result = $db->query($sql);
                            $data = $db->fetch_array($result, 1);
                            $funder = $data["funder"];
                            $fdesc = $data["fdesc"];
                        } else {
                            $funder = $beschriftung;
                            $fdesc = $beschriftung;
                        }
                        $linka = "";
                        $linkb = "";
                        if (!strstr($imgwerte[0], "/")) {
                            $imgfile = $pathvars["fileroot"] . "images/" . $environment["design"] . "/" . $imgwerte[0];
                            if (file_exists($imgfile)) {
                                $imgsize = getimagesize($imgfile);
                                $imgsize = " " . $imgsize[3];
                                $imgurl = $pathvars["images"] . $imgwerte[0];
                            } else {
                                $imgsize = "";
                            }
                        } else {
                            $imgurl = $imgwerte[0];
                            if (!strstr($imgwerte[0], "http")) {
                                if (strpos($imgwerte[0], $cfg["file"]["base"]["pic"]["root"]) === false) {
                                    $opt = explode("/", str_replace($pathvars["subdir"], "", $imgwerte[0]));
                                    $imgfile = $cfg["file"]["base"]["maindir"] . $cfg["file"]["base"]["pic"]["root"] . $cfg["file"]["base"]["pic"][$opt[4]] . "img_" . $opt[3] . "." . $opt[2];
                                } elseif (strstr($imgwerte[0], $cfg["file"]["base"]["webdir"])) {
                                    $imgfile = str_replace($cfg["file"]["base"]["webdir"], "", $imgwerte[0]);
                                    $imgfile = $cfg["file"]["base"]["maindir"] . $imgfile;
                                } else {
                                    $imgfile = $pathvars["fileroot"] . $imgwerte[0];
                                }
                                if (file_exists($imgfile)) {
                                    $imgsize = getimagesize($imgfile);
                                    $imgsize = " " . $imgsize[3];
                                }
                                if ($imgwerte[3] != "") {
                                    $bilderstrecke = "," . $imgwerte[7];
                                } else {
                                    $bilderstrecke = "";
                                }
                                if ($imgwerte[3] != "") {
                                    if (strpos($imgurl, $cfg["file"]["base"]["pic"]["root"]) === false) {
                                        $opt = explode("/", str_replace($pathvars["subdir"], "", $imgurl));
                                        $imgid = $opt[3];
                                    } else {
                                        $opt = split("[_.]", $imgurl);
                                        $imgid = $opt[1];
                                    }
                                    $path = dirname($pathvars["requested"]);
                                    if (substr($path, -1) != '/') {
                                        $path = $path . "/";
                                    }
                                    $imglnk = $path . basename($pathvars["requested"], ".html") . "/view," . $imgwerte[3] . "," . $imgid . $bilderstrecke . ".html";
                                    if ($imgwerte[3] == "l") {
                                        $imglnk = preg_replace("/\\/(tn|s|m|b)\\//", "/o/", $imgurl);
                                        $linka = $defaults["tag"]["img_link_lb"];
                                    } else {
                                        $linka = $defaults["tag"]["img_link"];
                                    }
                                    $linkb = $defaults["tag"]["/img_link"];
                                }
                            } else {
                                $imgsize = "";
                            }
                        }
                        if ($specialvars["w3c"] == "strict") {
                            $ausgabewert = $linka . $defaults["tag"]["img_w3c"] . $linkb;
                        } else {
                            $ausgabewert = $linka . $defaults["tag"]["img"] . $linkb;
                        }
                        foreach ($repl as $value) {
                            $ausgabewert = str_replace("##" . $value . "##", ${$value}, $ausgabewert);
                            ${$value} = "";
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    }
                    break;
                case "[/LINK]":
                    if ($sign == "]") {
                        $ausgabewert = "<a href=\"" . $tagwert . "\" title=\"" . $tagwert . "\">" . $tagwert . "</a>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $linkwerte = explode(";", $tagwerte[0]);
                        $href = $linkwerte[0];
                        if ($tagwerte[1] == "") {
                            $beschriftung = $href;
                        } else {
                            $beschriftung = $tagwerte[1];
                        }
                        // ziel
                        if ($linkwerte[1] != "") {
                            $target = " target=\"" . $linkwerte[1] . "\"";
                        } else {
                            $target = "";
                        }
                        // title-tag
                        if ($linkwerte[2] != "") {
                            $title = $linkwerte[2];
                        } else {
                            if ($linkwerte[1] == "_blank") {
                                $title = "Link in neuem Fenster: " . str_replace("http://", "", $href);
                            } elseif (!strstr($beschriftung, "<")) {
                                $title = $beschriftung;
                            } else {
                                $title = "";
                            }
                        }
                        // css-klasse, je nachdem, welche art link vorliegt
                        $class = "";
                        if (preg_match("/^http/", $href)) {
                            $class = "link_extern";
                        } elseif (preg_match("/^" . str_replace("/", "\\/", $cfg["file"]["base"]["webdir"]) . ".*\\.([a-zA-Z]+)/", $href, $match)) {
                            if ($cfg["file"]["filetyp"][$match[1]] != "") {
                                $class = "link_" . $cfg["file"]["filetyp"][$match[1]];
                            }
                        }
                        // klasse manuell hinzufuegen
                        if ($linkwerte[3] != "") {
                            $class .= " " . $linkwerte[3];
                        }
                        // id
                        if ($linkwerte[4] != "") {
                            $id = " id=\"" . $linkwerte[4] . "\"";
                        } else {
                            $id = "";
                        }
                        $ausgabewert = $pic . "<a href=\"" . $href . "\"" . $id . $target . " title=\"" . $title . "\" class=\"" . $class . "\">" . $beschriftung . "</a>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    }
                    break;
                    //
                    // Inline Elemente - Logische Auszeichnungen
                    // AKR | EM | STRONG | CODE | CITE | -q-
                    //
                //
                // Inline Elemente - Logische Auszeichnungen
                // AKR | EM | STRONG | CODE | CITE | -q-
                //
                case "[/ACR]":
                    if ($sign == "]") {
                        $ausgabewert = "<acronym>" . $tagwert . "</acronym>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $acrwerte = explode(";", $tagwerte[0]);
                        $attrib = "";
                        if ($acrwerte[0] != "") {
                            $attrib = " title=\"" . $acrwerte[0] . "\"";
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "<acronym" . $attrib . ">" . $tagwerte[1] . "</acronym>", $replace);
                    }
                    break;
                case "[/EM]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<em>" . $tagwert . "</em>", $replace);
                    break;
                case "[/STRONG]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<strong>" . $tagwert . "</strong>", $replace);
                    break;
                case "[/CODE]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<code>" . $tagwert . "</code>", $replace);
                    break;
                case "[/CITE]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<blockquote>" . $tagwert . "</blockquote>", $replace);
                    break;
                    //
                    // Inline Elemente - Physische Auszeichnungen
                    // B | I | TT | U | S, ST | BIG | SMALL | SUB | SUP
                    //
                //
                // Inline Elemente - Physische Auszeichnungen
                // B | I | TT | U | S, ST | BIG | SMALL | SUB | SUP
                //
                case "[/B]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<b>" . $tagwert . "</b>", $replace);
                    break;
                case "[/I]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<i>" . $tagwert . "</i>", $replace);
                    break;
                case "[/TT]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<tt>" . $tagwert . "</tt>", $replace);
                    break;
                case "[/U]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<u>" . $tagwert . "</u>", $replace);
                    break;
                case "[/S]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<s>" . $tagwert . "</s>", $replace);
                    break;
                case "[/ST]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<strike>" . $tagwert . "</strike>", $replace);
                    break;
                case "[/BIG]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<big>" . $tagwert . "</big>", $replace);
                    break;
                case "[/SMALL]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<small>" . $tagwert . "</small>", $replace);
                    break;
                case "[/SUB]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<sub>" . $tagwert . "</sub>", $replace);
                    break;
                case "[/SUP]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<sup>" . $tagwert . "</sup>", $replace);
                    break;
                    //
                    // eWeBuKi Spezial
                    // E | ! | ANK | EMAIL | HS |HL | IMGB | IN | M0 | M1 | M2 | QUOTE | SP | UP | PREV | NEXT
                    //
                //
                // eWeBuKi Spezial
                // E | ! | ANK | EMAIL | HS |HL | IMGB | IN | M0 | M1 | M2 | QUOTE | SP | UP | PREV | NEXT
                //
                case "[/E]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<pre>" . $tagwert . "</pre>", $replace);
                    break;
                case "[/!]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<!--" . $tagwert . "-->", $replace);
                    break;
                case "[/ANK]":
                    if ($sign == "]") {
                        $ausgabewert = "<a name=\"" . $tagwert . "\"></a>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $ausgabewert = "<a name=\"" . $tagwerte[0] . "\">" . $tagwerte[1] . "</a>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    }
                    break;
                case "[/EMAIL]":
                    if ($sign == "]") {
                        $ausgabewert = "<a href=\"mailto:" . $tagwert . "\">" . $tagwert . "</a>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        if ($tagwerte[1] == "") {
                            $beschriftung = $tagwerte[0];
                        } else {
                            $beschriftung = $tagwerte[1];
                        }
                        $ausgabewert = "<a href=\"mailto:" . $tagwerte[0] . "\">" . $beschriftung . "</a>";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    }
                    break;
                case "[/HS]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $tagwert, $replace);
                    break;
                case "[/HL]":
                    if ($defaults["tag"]["hl"] == "") {
                        $defaults["tag"]["hl"] = "<hr />";
                        $defaults["tag"]["/hl"] = "";
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $defaults["tag"]["hl"] . $tagwert . $defaults["tag"]["/hl"], $replace);
                    break;
                case "[/IMGB]":
                    $imgb_counter++;
                    if ($defaults["tag"]["img_link"] == "") {
                        $defaults["tag"]["img_link"] = "<a href=\"##imglnk##\">";
                    }
                    if ($defaults["tag"]["img_link_lb"] == "") {
                        $defaults["tag"]["img_link_lb"] = "<a href=\"##imglnk##\" title=\"##beschriftung##\" ##lightbox## >";
                    }
                    if ($defaults["tag"]["/img_link"] == "") {
                        $defaults["tag"]["/img_link"] = "</a>";
                    }
                    $repl = array("imgurl", "imglnk", "beschriftung", "funder", "fdesc", "lightbox");
                    $tagwerte = explode("]", $tagwert, 2);
                    $imgwerte = explode(";", $tagwerte[0]);
                    $extrawerte = explode(":", $imgwerte[1]);
                    if ($extrawerte[1] != "") {
                        $imgwerte[1] = $extrawerte[1];
                    }
                    $ausgaben["align"] = "";
                    $lspace = "";
                    $rspace = "";
                    $ausgaben["imgstyle"] = "";
                    $ausgaben["float"] = "";
                    // "id" or "class" wird im template gesetzt (!#ausgaben_imgstyle)
                    if ($imgwerte[1] == "r") {
                        $ausgaben["align"] = "right";
                        $ausgaben["float"] = "float:right;";
                        if ($imgwerte[6] == "") {
                            $lspace = "10";
                        } else {
                            $lspace = $imgwerte[6];
                        }
                        $rspace = "0";
                    } elseif ($imgwerte[1] == "l") {
                        $ausgaben["align"] = "left";
                        $ausgaben["float"] = "float:left;";
                        $lspace = "0";
                        if ($imgwerte[6] == "") {
                            $rspace = "10";
                        } else {
                            $rspace = $imgwerte[6];
                        }
                    } elseif ($imgwerte[1] != "") {
                        $ausgaben["imgstyle"] = $imgwerte[1];
                    }
                    if ($imgwerte[2] == "0") {
                        $ausgaben["border"] = "border-width:0;";
                    } elseif ($imgwerte[2] > 0) {
                        $ausgaben["border"] = "border-width:" . $imgwerte[2] . ";";
                    } else {
                        $ausgaben["border"] = "";
                    }
                    if ($imgwerte[3] == "l") {
                        $lightbox = "rel=\"lightbox[b" . $imgb_counter . "]\"";
                    }
                    if ($imgwerte[4] == "") {
                        $tspace = "0";
                    } else {
                        $tspace = $imgwerte[4];
                    }
                    if ($imgwerte[5] == "") {
                        $bspace = "0";
                    } else {
                        $bspace = $imgwerte[5];
                    }
                    if ($tagwerte[1] == "") {
                        $beschriftung = $imgwerte[0];
                    } else {
                        $beschriftung = $tagwerte[1];
                    }
                    // weitere informationen aus datenbank holen
                    if (preg_match("/^\\//", $tagwerte[0])) {
                        $img_path = explode("/", str_replace($cfg["file"]["base"]["maindir"], "", $tagwerte[0]));
                        if (is_numeric($img_path[3])) {
                            $fid = $img_path[3];
                        } else {
                            $fid = substr($tagwerte[0], 0, strpos($tagwerte[0], ";"));
                            $fid = strrchr($fid, "_");
                            $fid = substr($fid, 1, strpos($fid, ".") - 1);
                        }
                        $sql = "SELECT *\n                                        FROM site_file\n                                        WHERE fid=" . $fid;
                        $result = $db->query($sql);
                        $data = $db->fetch_array($result, 1);
                        $funder = $data["funder"];
                        $fdesc = $data["fdesc"];
                    } else {
                        $funder = $beschriftung;
                        $fdesc = $beschriftung;
                    }
                    $ausgaben["linka"] = "";
                    $ausgaben["linkb"] = "";
                    if (strpos($imgwerte[0], "/") === false) {
                        $imgfile = $pathvars["fileroot"] . "images/" . $environment["design"] . "/" . $imgwerte[0];
                        if (file_exists($imgfile)) {
                            $imgsize = getimagesize($imgfile);
                            $ausgaben["imgsize"] = " " . $imgsize[3];
                            $ausgaben["imgurl"] = $pathvars["images"] . $imgwerte[0];
                        }
                    } else {
                        $imgurl = $imgwerte[0];
                        if (strpos($imgurl, "http") === false) {
                            if (strpos($imgwerte[0], $cfg["file"]["base"]["pic"]["root"]) === false) {
                                $opt = explode("/", str_replace($pathvars["subdir"], "", $imgurl));
                                $imgfile = $cfg["file"]["base"]["maindir"] . $cfg["file"]["base"]["pic"]["root"] . $cfg["file"]["base"]["pic"][$opt[4]] . "img_" . $opt[3] . "." . $opt[2];
                            } elseif (strpos($imgurl, $cfg["file"]["base"]["webdir"]) !== false) {
                                $imgfile = $cfg["file"]["base"]["maindir"] . str_replace($cfg["file"]["base"]["webdir"], "", $imgurl);
                            } else {
                                $imgfile = $pathvars["fileroot"] . $imgwerte[0];
                            }
                            if (file_exists($imgfile)) {
                                $imgsize = getimagesize($imgfile);
                                $ausgaben["tabwidth"] = $imgsize[0];
                                $ausgaben["imgsize"] = " " . $imgsize[3];
                            } else {
                                $ausgaben["tabwidth"] = "";
                                $ausgaben["imgsize"] = "";
                            }
                            if ($imgwerte[7] != "") {
                                $bilderstrecke = "," . $imgwerte[7];
                            } else {
                                $bilderstrecke = "";
                            }
                            if ($imgwerte[3] != "") {
                                if (strpos($imgurl, $cfg["file"]["base"]["pic"]["root"]) === false) {
                                    $opt = explode("/", str_replace($pathvars["subdir"], "", $imgurl));
                                    $imgid = $opt[3];
                                } else {
                                    $opt = split("[_.]", $imgurl);
                                    $imgid = $opt[1];
                                }
                                if (substr($pathvars["requested"], 0, 1) == '/') {
                                    $path = substr($pathvars["requested"], 1);
                                }
                                $path = dirname($pathvars["requested"]);
                                if (substr($path, -1) != '/') {
                                    $path = $path . "/";
                                }
                                $imglnk = $path . basename($pathvars["requested"], ".html") . "/view," . $imgwerte[3] . "," . $imgid . $bilderstrecke . ".html";
                                if ($imgwerte[3] == "l") {
                                    $imglnk = preg_replace("/\\/(tn|s|m)\\//", "/b/", $imgurl);
                                    $ausgaben["linka"] = $defaults["tag"]["img_link_lb"];
                                } else {
                                    $ausgaben["linka"] = $defaults["tag"]["img_link"];
                                }
                                foreach ($repl as $value) {
                                    $ausgaben["linka"] = str_replace("##" . $value . "##", ${$value}, $ausgaben["linka"]);
                                }
                                $ausgaben["linkb"] = $defaults["tag"]["/img_link"];
                            } else {
                                $ausgaben["linka"] = "";
                                $ausgaben["linkb"] = "";
                            }
                        }
                        $ausgaben["imgurl"] = $imgurl;
                    }
                    $ausgaben["alt"] = $beschriftung;
                    $ausgaben["beschriftung"] = $beschriftung;
                    $ausgaben["funder"] = $funder;
                    $ausgaben["fdesc"] = $fdesc;
                    $ausgaben["tspace"] = $tspace;
                    $ausgaben["lspace"] = $lspace;
                    $ausgaben["rspace"] = $rspace;
                    $ausgaben["bspace"] = $bspace;
                    $ausgabewert = str_replace(chr(13) . chr(10), "", parser("imgb", ""));
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgabewert, $replace);
                    break;
                case "[/SEL]":
                    $selection_counter++;
                    $tag_value = explode("]", $tagwert, 2);
                    $tag_param = explode(";", $tag_value[0]);
                    $tag_extra = explode(":", $tag_param[3]);
                    $tag_special = explode(":", $tag_param[0]);
                    if (!preg_match("/[0-9]+/", $tag_param[0])) {
                        $sel = "selection not ready";
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $sel, $replace);
                    } else {
                        $path = dirname($pathvars["requested"]);
                        if (substr($path, -1) != '/') {
                            $path = $path . "/";
                        }
                        $link = $path . basename($pathvars["requested"], ".html") . "/view," . $tag_param[1] . ",#," . $tag_param[0] . "," . $tag_param[2] . ".html";
                        #/view,groesse,bild,selektion,thumbs
                        if ($defaults["tag"]["sel"] == "") {
                            $defaults["tag"]["sel"] = "<div style=\"position:relative\" class=\"selection_teaser\">##no_image####youtube_div##\n<b>##title## ##youtube_link##</b>\n##no_image_end##<div>\n<ul>\n";
                        }
                        if ($defaults["tag"]["*sel"] == "") {
                            $defaults["tag"]["*sel"] = "<li class=\"thumbs\"##style##>\n<a href=\"##link##\" ##lb##class=\"pic\" title=\"##fdesc##\"><img src=\"##tn##\" alt=\"##funder##\" title=\"##funder##\"/></a>\n</li>\n";
                        }
                        if ($defaults["tag"]["/sel"] == "") {
                            $defaults["tag"]["/sel"] = "</ul>\n</div>\n<span##display##>g(compilation_info)(##count## g(compilation_pics))</span>\n</div>";
                        }
                        if (strstr($tag_param[0], ":")) {
                            $sel_pics = "";
                            foreach ($tag_special as $pics) {
                                if ($pics == "") {
                                    continue;
                                }
                                $sel_pics != "" ? $trenner = " ," : ($trenner = "");
                                $sel_pics .= $trenner . $pics;
                            }
                            if ($sel_pics == "") {
                                $sel_pics = 0;
                            }
                            $sql = "SELECT * FROM site_file WHERE fid in (" . $sel_pics . ")";
                            $sel_pics1 = explode(":", $tag_param[0]);
                            $i = 0;
                            foreach ($sel_pics1 as $key => $value) {
                                $i++;
                                $tmp_sort[$value] = $i;
                            }
                            $result = $db->query($sql);
                            $files = array();
                            $sortarray = array();
                            while ($data = $db->fetch_array($result, 1)) {
                                $sortarray[] = $tmp_sort[$data["fid"]];
                                $files[] = array("fid" => $data["fid"], "sort" => $counter, "ffart" => $data["ffart"], "ffname" => $data["ffname"], "funder" => $data["funder"], "fdesc" => $data["fdesc"]);
                            }
                            if (count($files) > 0) {
                                array_multisort($sortarray, $files);
                            }
                        } else {
                            $sql = "SELECT *\n                                          FROM site_file\n                                         WHERE fhit LIKE '%#p" . $tag_param[0] . "%'";
                            $result = $db->query($sql);
                            $files = array();
                            while ($data = $db->fetch_array($result, 1)) {
                                preg_match("/#p" . $tag_param[0] . "[,]*([0-9]*)#/i", $data["fhit"], $match);
                                $files[$match[1]] = array("fid" => $data["fid"], "sort" => $match[1], "ffart" => $data["ffart"], "ffname" => $data["ffname"], "funder" => $data["funder"], "fdesc" => $data["fdesc"]);
                            }
                            ksort($files);
                            $sort = array();
                            foreach ($files as $key => $row) {
                                $sort[$key] = $row['sort'];
                            }
                            array_multisort($sort, $files);
                        }
                        $sel = str_replace("##title##", $tag_value[1], $defaults["tag"]["sel"]);
                        // wenn video-parameter vorhanden dann marken ersetzen
                        if ($tag_param[5] != "") {
                            $sel = str_replace("##youtube_div##", "<div class=\"new_box new_space_inside\" style=\"background: #EEF3FB;height:212px;width:250px;display:none\" id=\"" . $tag_param[0] . "_video\">\n                                [OBJECT=http://www.youtube.com/v/" . $tag_param[5] . "&hl=de_DE&fs=1&;250;192;application/x-shockwave-flash]\n                                [PARAM=movie]http://www.youtube.com/v/" . $tag_param[5] . "&hl=de_DE&fs=1&[/PARAM]\n                                [PARAM=wmode]transparent[/PARAM]\n                                [/OBJECT]\n                                <span style=\"float:right\"><b><a onclick=\"Element.setStyle('" . $tag_param[0] . "_video', 'display:none');\">Schließen</a></b></span></div>", $sel);
                            $sel = str_replace("##youtube_link##", "<a onclick=\"Element.setStyle('" . $tag_param[0] . "_video', 'display:block;position:absolute;left:-1px;top:-228px');\">Video</a>", $sel);
                        } else {
                            $sel = str_replace("##youtube_div##", "", $sel);
                            $sel = str_replace("##youtube_link##", "", $sel);
                        }
                        $lb_helper = "";
                        $file_counter = 0;
                        foreach ($files as $row) {
                            $file_counter++;
                            if ($cfg["file"]["base"]["realname"] == True) {
                                $img = $cfg["file"]["base"]["webdir"] . $row["ffart"] . "/" . $row["fid"] . "/" . $tag_param[1] . "/" . $row["ffname"];
                                $tn = $cfg["file"]["base"]["webdir"] . $row["ffart"] . "/" . $row["fid"] . "/" . "tn/" . $row["ffname"];
                            } else {
                                $img = $cfg["file"]["base"]["webdir"] . $cfg["file"]["base"]["pic"]["root"] . $cfg["file"]["base"]["pic"][$tag_param[1]] . "img_" . $row["fid"] . "." . $row["ffart"];
                                $tn = $cfg["file"]["base"]["webdir"] . $cfg["file"]["base"]["pic"]["root"] . $cfg["file"]["base"]["pic"]["tn"] . "tn_" . $row["fid"] . "." . $row["ffart"];
                            }
                            $style = "";
                            if (!in_array($row["fid"], $tag_extra) && $tag_param[3] != "a") {
                                if ($tag_param[4] == "l") {
                                    $style = " style=\"display:none;\"";
                                } else {
                                    continue;
                                }
                            }
                            if ($tag_param[4] == "l") {
                                $changed = $img;
                                $lb = "rel=\"lightbox[group_" . $selection_counter . "]\" ";
                            } else {
                                $changed = str_replace("#", $row["fid"], $link);
                                $lb = "";
                            }
                            if ($tag_param[3] == "" && $tag_param[4] == "l" && $file_counter == 1) {
                                $tn1 = $img;
                                continue;
                            }
                            $s = array("##link##", "##lb##", "##tn##", "##funder##", "##fdesc##", "##style##");
                            $r = array($changed, $lb, $tn, $row["funder"], $row["fdesc"], $style);
                            $sel .= str_replace($s, $r, $defaults["tag"]["*sel"]);
                        }
                        if ($tag_param[3] == "" && $tag_param[4] == "l") {
                            $ArrayReplace = array(count($files), " style=\"display:none\"");
                        } else {
                            $ArrayReplace = array(count($files), "");
                        }
                        $sel .= str_replace(array("##count##", "##display##"), $ArrayReplace, $defaults["tag"]["/sel"]);
                        if ($tag_param[3] == "") {
                            if ($tag_param[4] == "l") {
                                $sel = str_replace("##no_image##", "<a href=\"" . $tn1 . "\" " . $lb . ">", $sel);
                                $sel = str_replace("##no_image_end##", "</a>", $sel);
                            } else {
                                $changed = str_replace("#", $files[0]["fid"], $link);
                                $sel = "<a href=\"" . $changed . "\">" . $tag_value[1] . "</a>";
                            }
                        } else {
                            $sel = str_replace("##no_image##", "", $sel);
                            $sel = str_replace("##no_image_end##", "", $sel);
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $sel, $replace);
                    }
                case "[/IN]":
                    if ($defaults["tag"]["in"] == "") {
                        $defaults["tag"]["in"] = "<em>";
                        $defaults["tag"]["/in"] = "</em>";
                    }
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $defaults["tag"]["in"] . $tagwert . $defaults["tag"]["/in"], $replace);
                case "[/M0]":
                    if ($sign == "]") {
                        $m0 = $ausgaben["M0"];
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $m0, $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $m0werte = explode(";", $tagwerte[0]);
                        if ($m0werte[0] == "l") {
                            $m0 = $ausgaben["L0"];
                        } else {
                            $m0 = $ausgaben["M0"];
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $m0, $replace);
                    }
                    break;
                case "[/M1]":
                    if ($sign == "]") {
                        if ($tagwert == "") {
                            $label = " .. ";
                        } else {
                            $label = $tagwert;
                        }
                        if ($ausgaben["M1"] != "") {
                            $trenner = $defaults["split"]["m1"];
                        } else {
                            $trenner = "";
                        }
                        $m1 = "<a class=\"menu_punkte\" href=\"" . $ausgaben["UP"] . "\">" . $label . "</a>" . $trenner . $ausgaben["M1"];
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $m1, $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $m1werte = explode(";", $tagwerte[0]);
                        if ($tagwerte[1] == "") {
                            $label = " .. ";
                        } else {
                            $label = $tagwerte[1];
                        }
                        if ($m1werte[0] == "l") {
                            $m1 = "";
                            if ($m1werte[1] == "b") {
                                $m1 = $defaults["split"]["l1"] . "<a class=\"menu_punkte\" href=\"" . $ausgaben["UP"] . "\">" . $label . "</a><br />";
                            }
                            $m1 .= $ausgaben["L1"];
                        } else {
                            $m1 = "";
                            if ($m1werte[1] == "b") {
                                if ($ausgaben["M1"] != "") {
                                    $trenner = $defaults["split"]["m1"];
                                } else {
                                    $trenner = "";
                                }
                                $m1 = "<a class=\"menu_punkte\" href=\"" . $ausgaben["UP"] . "\">" . $label . "</a>" . $trenner;
                            }
                            $m1 .= $ausgaben["M1"];
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $m1, $replace);
                    }
                    break;
                case "[/M2]":
                    if ($sign == "]") {
                        if ($tagwert == "") {
                            $label = " .. ";
                        } else {
                            $label = $tagwert;
                        }
                        if ($ausgaben["M2"] != "") {
                            $trenner = $defaults["split"]["m2"];
                        } else {
                            $trenner = "";
                        }
                        $m2 = "<a class=\"menu_punkte\" href=\"" . $ausgaben["UP"] . "\">" . $label . "</a>" . $trenner . $ausgaben["M2"];
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $m2, $replace);
                    } else {
                        $tagwerte = explode("]", $tagwert, 2);
                        $m2werte = explode(";", $tagwerte[0]);
                        if ($tagwerte[1] == "") {
                            $label = " .. ";
                        } else {
                            $label = $tagwerte[1];
                        }
                        if ($m2werte[0] == "l") {
                            $m2 = "";
                            if ($m2werte[1] == "b") {
                                $m2 = $defaults["split"]["l2"] . "<a class=\"menu_punkte\" href=\"" . $ausgaben["UP"] . "\">" . $label . "</a><br />";
                            }
                            $m2 .= $ausgaben["L2"];
                        } else {
                            $m2 = "";
                            if ($m2werte[1] == "b") {
                                if ($ausgaben["M2"] != "") {
                                    $trenner = $defaults["split"]["m2"];
                                } else {
                                    $trenner = "";
                                }
                                $m2 = "<a class=\"menu_punkte\" href=\"" . $ausgaben["UP"] . "\">" . $label . "</a>" . $trenner;
                            }
                            $m2 .= $ausgaben["M2"];
                        }
                        $replace = str_replace($opentag . $tagoriginal . $closetag, $m2, $replace);
                    }
                    break;
                case "[/M3]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgaben["M3"], $replace);
                    break;
                case "[/UP]":
                    if ($tagwert == "") {
                        $label = " .. ";
                    } else {
                        $label = $tagwert;
                    }
                    $up = "<a class=\"menu_punkte\" href=\"" . $ausgaben["UP"] . "\">" . $label . "</a>";
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $up, $replace);
                    break;
                case "[/PREV]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgaben["prev"], $replace);
                    break;
                case "[/NEXT]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $ausgaben["next"], $replace);
                    break;
                case "[/QUOTE]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "&quot;" . $tagwert . "&quot;", $replace);
                    break;
                case "[/SP]":
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "&nbsp;", $replace);
                    break;
                case "[/BLOG]":
                    if ($environment["ebene"] == "/wizard" && $environment["kategorie"] == "show") {
                        $kat = tname2path($environment["parameter"][2]);
                    } else {
                        if ($environment["ebene"] == "") {
                            $kat = "/" . $environment["kategorie"];
                        } else {
                            $kat = $environment["ebene"] . "/" . $environment["kategorie"];
                        }
                    }
                    $tagwerte = explode("]", $tagwert, 2);
                    $url = $tagwerte[0];
                    // erstellen der tags die angezeigt werden
                    if (is_array($cfg["bloged"]["blogs"][$url]["tags"])) {
                        foreach ($cfg["bloged"]["blogs"][$url]["tags"] as $key => $value) {
                            $tags[$key] = $value;
                        }
                    }
                    require_once $pathvars["moduleroot"] . "libraries/function_menu_convert.inc.php";
                    require_once $pathvars["moduleroot"] . "libraries/function_show_blog.inc.php";
                    if ($environment["parameter"][2] == "" || $environment["ebene"] == "/wizard") {
                        $dataloop["list"] = show_blog($url, $tags, $cfg["auth"]["ghost"]["contented"], $cfg["bloged"]["blogs"][$url]["rows"], $kat);
                    } else {
                        $all = show_blog($url, $tags, $cfg["auth"]["ghost"]["contented"], $cfg["bloged"]["blogs"][$url]["rows"], $kat);
                        unset($hidedata["new"]);
                        $hidedata["all"]["inhalt"] = $all[1]["all"];
                    }
                    if ($cfg["bloged"]["blogs"][$url]["category"] != "") {
                        $replace = str_replace($opentag . $tagoriginal . $closetag, parser($mapping["main"], ""), $replace);
                    } else {
                        $replace = str_replace($opentag . $tagoriginal . $closetag, "not allowed", $replace);
                    }
                    break;
                case "[/OBJECT]":
                    $tagwerte = explode("]", $tagwert, 2);
                    $objectwerte = explode(";", $tagwerte[0]);
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<object type=\"" . $objectwerte[3] . "\" data=\"" . $objectwerte[0] . "\" width=\"" . $objectwerte[1] . "\" height=\"" . $objectwerte[2] . "\">" . $tagwerte[1] . "</object>", $replace);
                    break;
                case "[/PARAM]":
                    $tagwerte = explode("]", $tagwert, 2);
                    $replace = str_replace($opentag . $tagoriginal . $closetag, "<param name=\"" . $tagwerte[0] . "\" value=\"" . $tagwerte[1] . "\"></param>", $replace);
                    break;
                case "[/YT]":
                    $tagwerte = explode("]", $tagwert, 2);
                    $ytwerte = explode(";", $tagwerte[0]);
                    $yt = "<object width=\"" . $ytwerte[0] . "\" height=\"" . $ytwerte[1] . "\">\n                                <param name=\"movie\" value=\"http://www.youtube.com/v/" . $tagwerte[1] . "&hl=de_DE&fs=1&\"></param>\n                                <param name=\"allowFullScreen\" value=\"true\"></param>\n                                <param name=\"allowscriptaccess\" value=\"always\"></param>\n                                <embed src=\"http://www.youtube.com/v/" . $tagwerte[1] . "&hl=de_DE&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"" . $ytwerte[0] . "\" height=\"" . $ytwerte[1] . "\"></embed>\n                                </object>";
                    $replace = str_replace($opentag . $tagoriginal . $closetag, $yt, $replace);
                    break;
                default:
                    $extra_tag = str_replace(array("/", "]", "["), array("", "", ""), $closetag);
                    if ($defaults["extra_tags"][$extra_tag] != "") {
                        if (file_exists($pathvars["moduleroot"] . $defaults["extra_tags"][$extra_tag])) {
                            include $pathvars["moduleroot"] . $defaults["extra_tags"][$extra_tag];
                            break;
                        }
                    }
                    // unbekannte tags verstecken
                    $replace = str_replace($closetag, "[##" . substr($closetag, 1), $replace);
            }
        }
    }
    // unbekannte tags wiederherstellen
    $replace = str_replace("[##/", "[/", $replace);
    return $replace;
}
 if ($environment["parameter"][1] == "") {
     $url = preg_replace(array("/^" . str_replace("/", "\\/", $pathvars["webroot"]) . "/", "/^" . str_replace("/", "\\/", $pathvars["virtual"]) . "/", "/\\.html\$/"), "", $_SERVER["HTTP_REFERER"]);
     $path = explode("/", $url);
     $kategorie = array_pop($path);
     if ($kategorie == "") {
         $kategorie = "index";
     }
     $ebene = implode("/", $path);
     if ($ebene == "") {
         $tname = $kategorie;
     } else {
         $tname = eCRC($ebene) . "." . $kategorie;
     }
     header("Location: " . $cfg["keyworded"]["basis"] . "/" . $environment["kategorie"] . "," . $tname . ".html");
 } else {
     $url = tname2path($environment["parameter"][1]);
     if ($url == "/") {
         if ($environment["parameter"][1] == "index") {
             $ausgaben["path"] .= "index";
         } else {
             $ausgaben["path"] = "";
             $ausgaben["form_error"] .= "#(error_url_na)";
         }
     } else {
         $ausgaben["path"] = $url . ".html";
     }
 }
 if ($ausgaben["path"] != "" && !priv_check($ausgaben["path"], $cfg["keyworded"]["right"]["content"])) {
     $ausgaben["form_error"] = "#(error_right)";
 }
 // schlagwoerter fuer die seite holen
     $ausgaben["form_referer"] = "/auth/login.html";
 } else {
     $ausgaben["form_referer"] = $_SERVER["HTTP_REFERER"];
 }
 // form elememte bauen
 $element = array_merge(form_elements("site_menu", $form_values), form_elements("site_menu_lang", $form_values));
 // freigabe-test
 if ($specialvars["content_release"] == -1) {
     $hidedata["add_menu"]["hide"] = -1;
 } else {
     $hidedata["add_menu"]["hide"] = "";
 }
 //wohin schicken
 $ausgaben["form_aktion"] = $pathvars["virtual"] . "/wizard/delete,devel0," . $environment["parameter"][2] . ",inhalt.html";
 $ausgaben["refid"] = $point["mid"];
 $url = $pathvars["virtual"] . tname2path($environment["parameter"][2]);
 $sql = "SELECT *\n                FROM " . SITETEXT . "\n                WHERE lang = '" . $environment["language"] . "'\n                AND label ='" . $environment["parameter"][3] . "'\n                AND tname ='" . $environment["parameter"][2] . "'\n            ORDER BY version ASC";
 $result = $db->query($sql);
 $security = "";
 while ($data = $db->fetch_array($result, 0)) {
     if ($data["status"] == -2) {
         $security = -1;
     }
     if ($data["status"] == 0) {
         $dataloop["allartikel"][$data["version"]]["color"] = "";
         $dataloop["allartikel"][$data["version"]]["text"] = "historisch";
     } elseif ($data["status"] == 1) {
         $dataloop["allartikel"][$data["version"]]["color"] = "";
         $dataloop["allartikel"][$data["version"]]["text"] = "aktuell";
     } else {
         $dataloop["allartikel"][$data["version"]]["color"] = "#FF9148";
 if ($HTTP_POST_VARS["tname"] != "") {
     $sql = "DELETE FROM " . $cfg["menued"]["db"]["text"]["entries"] . " WHERE tname = '" . $HTTP_POST_VARS["tname"] . "'";
     if ($debugging["sql_enable"]) {
         $debugging["ausgabe"] .= "sql: " . $sql . $debugging["char"];
     }
     $result = $db->query($sql);
     if (!$result) {
         $ausgaben["form_error"] = $db->error("#(text_error)<br />");
     }
 }
 // +++
 // content loeschen
 // neue Rechte loeschen
 // ***
 if ($specialvars["security"]["new"] == -1) {
     $sql = "DELETE FROM " . $cfg["menued"]["db"]["content"]["entries"] . " WHERE tname ='" . tname2path($HTTP_POST_VARS["tname"]) . "'";
     if ($debugging["sql_enable"]) {
         $debugging["ausgabe"] .= "sql: " . $sql . $debugging["char"];
     }
     $result = $db->query($sql);
     if (!$result) {
         $ausgaben["form_error"] = $db->error("#(text_error)<br />");
     }
 }
 // +++
 // neue Reche loeschen
 // ohne fehler bezeichnungen loeschen
 // ***
 if ($HTTP_POST_VARS["mlids"] != "" && $ausgaben["form_error"] == "") {
     $array = split(",", $HTTP_POST_VARS["mlids"]);
     foreach ($array as $value) {
if ($environment["parameter"][1]) {
    $ebe = make_ebene($environment["parameter"][1]);
    $tn = eCrc(substr($ebe, 0, strrpos($ebe, "/"))) . "." . substr($ebe, strrpos($ebe, "/") + 1);
    $sql = "Select * from site_text where tname = '" . $tn . "' and status = 1 and label = 'inhalt'";
    $result = $db->query($sql);
    $data = $db->fetch_array($result, 1);
    preg_match_all("/\\[LIST=DEF\\](.*)\\[\\/LIST\\]/Us", $data["content"], $match);
    foreach ($match[0] as $key => $value) {
        $buffer .= tagreplace($value);
    }
    $buffer = str_replace("<dl>", "", $buffer);
    $ausgaben["faq"] = str_replace("</dl>", "", $buffer);
}
// LISTE
$sql = "Select * from site_text where content like '%[LIST=DEF]%' and status = 1";
$result = $db->query($sql);
while ($data = $db->fetch_array($result, 1)) {
    $id = make_id(tname2path($data["tname"]));
    $name = "";
    foreach (url2Loop(tname2path($data["tname"])) as $value) {
        $name .= "|" . $value["label"];
    }
    $dataloop["faq_sites"][$id["mid"]]["id"] = $id["mid"];
    $dataloop["faq_sites"][$id["mid"]]["name"] = $name;
}
// was anzeigen
$mapping["main"] = "faq-library";
if ($debugging["html_enable"]) {
    $debugging["ausgabe"] .= "[ ++ " . $script["name"] . " ++ ]" . $debugging["char"];
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 }
 $change_a = "bysurname, byforename, byemail, byalias";
 if ($form_values["status"] == -2) {
     // 1. status der neuen version wird -2
     $status2 = ",-2";
     // 2. status -2 wird zu -1
     $sql = "UPDATE " . SITETEXT . "\n                                   SET status=-1\n                                 WHERE lang = '" . $environment["language"] . "'\n                                   AND label ='" . $environment["parameter"][3] . "'\n                                   AND tname ='" . $environment["parameter"][2] . "'\n                                   AND status=-2";
     $result = $db->query($sql);
     // 3. bearbeiter-daten wird belassen
     $change_b = "'" . $form_values["bysurname"] . "',\n                                     '" . $form_values["byforename"] . "',\n                                     '" . $form_values["byemail"] . "',\n                                     '" . $form_values["byalias"] . "'";
 } else {
     $change_b = "'" . $_SESSION["surname"] . "',\n                                     '" . $_SESSION["forename"] . "',\n                                     '" . $_SESSION["email"] . "',\n                                     '" . $_SESSION["alias"] . "'";
 }
 // alle dazugehoerigen blogs updaten
 if (is_array($tag_meat["BLOG"])) {
     $blog_sql = "SELECT tname FROM " . SITETEXT . " WHERE content ~ '\\\\[KATEGORIE\\]" . tname2path($environment["parameter"][2]) . "\\\\[\\/KATEGORIE\\]' group by tname";
     $blog_result = $db->query($blog_sql);
     while ($blog_data = $db->fetch_array($blog_result, 1)) {
         if ($_SESSION["wizard_content"][DATABASE . "," . $blog_data["tname"] . "," . $environment["parameter"][3]]) {
             // die naechste freie versionsnummer finden
             $sql = "SELECT max(version) as max_version, ebene, kategorie\n                                        FROM " . SITETEXT . "\n                                        WHERE lang = '" . $environment["language"] . "'\n                                        AND label ='" . $environment["parameter"][3] . "'\n                                        AND tname ='" . $blog_data["tname"] . "' group by ebene,kategorie";
             $result = $db->query($sql);
             $data = $db->fetch_array($result, 1);
             $next_blog_version = $data["max_version"] + 1;
             $sql = "INSERT INTO " . SITETEXT . "\n                                                    (lang, label, tname, version,\n                                                    ebene, kategorie,\n                                                    crc32, html, content,\n                                                    changed, bysurname, byforename, byemail, byalias" . $status1 . ")\n                                            VALUES (\n                                                    '" . $environment["language"] . "',\n                                                    '" . $environment["parameter"][3] . "',\n                                                    '" . $blog_data["tname"] . "',\n                                                    '" . $next_blog_version . "',\n                                                    '" . $data["ebene"] . "',\n                                                    '" . $data["kategorie"] . "',\n                                                    '" . $specialvars["crc32"] . "',\n                                                    '0',\n                                                    '" . addslashes($_SESSION["wizard_content"][DATABASE . "," . $blog_data["tname"] . "," . $environment["parameter"][3]]) . "',\n                                                    '" . date("Y-m-d H:i:s") . "',\n                                                    '" . $_SESSION["surname"] . "',\n                                                    '" . $_SESSION["forename"] . "',\n                                                    '" . $_SESSION["email"] . "',\n                                                    '" . $_SESSION["alias"] . "'\n                                                    ,-1)";
             $result = $db->query($sql);
         }
     }
 }
 $sql_content = "INSERT INTO " . SITETEXT . "\n                                                (lang, label, tname, version,\n                                                 ebene, kategorie,\n                                                 crc32, html,\n                                                 content,\n                                                 changed,\n                                                 " . $change_a . "\n                                                 " . $status1 . "\n                                                )\n                                         VALUES (\n                                                '" . $environment["language"] . "',\n                                                '" . $environment["parameter"][3] . "',\n                                                '" . $environment["parameter"][2] . "',\n                                                '" . $next_version . "',\n                                                '" . $ebene . "',\n                                                '" . $kategorie . "',\n                                                '" . $specialvars["crc32"] . "',\n                                                '0',\n                                                '" . addslashes($form_values["content"]) . "',\n                                                '" . date("Y-m-d H:i:s") . "',\n                                                " . $change_b . "\n                                                " . $status2 . ")";
 $release_version = $next_version;
    URL: http://www.chaos.de
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$position = $environment["parameter"][1] + 0;
// als tname werden die SESSIONS "ebene" u. "kategorie" verwendet
if ($environment["parameter"][2] == "") {
    if ($_SESSION["ebene"] != "") {
        $pfad = $_SESSION["ebene"] . "/" . $_SESSION["kategorie"];
        $tname = eCRC($_SESSION["ebene"]) . "." . $_SESSION["kategorie"];
    } else {
        $pfad = "/" . $_SESSION["kategorie"];
        $tname = $_SESSION["kategorie"];
    }
} else {
    $tname = $environment["parameter"][2];
    $pfad = tname2path($tname);
}
if (priv_check($pfad, $cfg["contented"]["right"]) || priv_check_old("", $cfg["contented"]["right"])) {
    // parameter-uebersicht
    //      1: selector-position                                2: tname
    //      3: label                                            4: old (versionsnr)
    //      5: new (versionsnr)                                 6: geparster Content? (->'html')
    //      7: diff-Typ (vgl $cfg[contented]["diff_engine"])
    // ueberschrift
    $ausgaben["url"] = $pfad;
    // label steuerung wenn kein para dann wird default-label aus cfg hergenommen
    if ($environment["parameter"][3] == "") {
        $label = $cfg["contented"]["default_label"];
    } else {
        $label = $environment["parameter"][3];
    }
         // naechste nicht versteckte versions-nummer finden
         $sql = "SELECT max(version) as max_version\n                          FROM " . SITETEXT . "\n                         WHERE lang = '" . $environment["language"] . "'\n                           AND label ='" . $environment["parameter"][3] . "'\n                           AND tname ='" . $environment["parameter"][2] . "'\n                           AND status>=0";
         $result = $db->query($sql);
         $data = $db->fetch_array($result, 1);
         $next_version = $data["max_version"] + 1;
         // alle "unnoetigen" versionen loeschen
         $sql = "DELETE\n                          FROM " . SITETEXT . "\n                         WHERE lang = '" . $environment["language"] . "'\n                           AND label ='" . $environment["parameter"][3] . "'\n                           AND tname ='" . $environment["parameter"][2] . "'\n                           AND status<0\n                           AND version<>" . $environment["parameter"][5];
         $result = $db->query($sql);
         // bisher aktuelle inhalte historisieren
         $sql = "UPDATE " . SITETEXT . " SET\n                                status=0\n                         WHERE lang = '" . $environment["language"] . "'\n                           AND label ='" . $environment["parameter"][3] . "'\n                           AND tname ='" . $environment["parameter"][2] . "'\n                           AND status>=0";
         $result = $db->query($sql);
         // freigegebenen Datensatz aktualisieren
         $sql = "UPDATE " . SITETEXT . "\n                           SET version=" . $next_version . ",\n                               status=1\n                         WHERE lang = '" . $environment["language"] . "'\n                           AND label ='" . $environment["parameter"][3] . "'\n                           AND tname ='" . $environment["parameter"][2] . "'\n                           AND version=" . $environment["parameter"][5];
         $result = $db->query($sql);
         // checken, ob menuepunkt aktivert ist
         $menu_entry = make_id(tname2path($environment["parameter"][2]));
         $sql = "UPDATE site_menu\n                           SET hide=NULL\n                         WHERE mid=" . $menu_entry["mid"];
         $result = $db->query($sql);
     } elseif ($environment["parameter"][4] == "unlock") {
         // version wird wieder entsperrt
         $sql = "UPDATE " . SITETEXT . "\n                           SET status=-1\n                         WHERE lang = '" . $environment["language"] . "'\n                           AND label ='" . $environment["parameter"][3] . "'\n                           AND tname ='" . $environment["parameter"][2] . "'\n                           AND version=" . $environment["parameter"][5];
         $result = $db->query($sql);
     }
     if ($_SESSION["form_referer"] != "") {
         $header = $_SESSION["form_referer"];
         unset($_SESSION["form_referer"]);
     } else {
         $header = $_SERVER["HTTP_REFERER"];
     }
     header("Location: " . $header);
 }
 function tname2path($tname, $refid = 0, $ebene = "")
 {
     global $db;
     $sql = "SELECT *\n                  FROM site_menu\n                 WHERE refid=" . $refid . "\n              ORDER BY mid";
     $result = $db->query($sql);
     while ($data = $db->fetch_array($result)) {
         if ($ebene == "") {
             $tmp_tname = $data["entry"];
         } else {
             $tmp_tname = eCRC($ebene) . "." . $data["entry"];
         }
         $path = $ebene . "/" . $data["entry"];
         $return_value = "";
         if ($tname == $tmp_tname) {
             return $path;
         } elseif (strstr($tname, eCRC($ebene . "/" . $data["entry"]) . ".")) {
             return $path . "/" . substr($tname, strpos($tname, ".") + 1);
         } else {
             $return_value = tname2path($tname, $data["mid"], $path);
         }
         if ($return_value != "") {
             return $return_value;
         }
     }
     if ($return_value == "" && $refid == 0) {
         $return_value = "/";
         if (!strstr($tname, ".")) {
             $return_value .= $tname;
         }
     }
     return $return_value;
 }
    $url = tname2path($environment["parameter"][2]);
    $point = make_id($url);
    $_SESSION["REFERER"] = $url;
    $_SESSION["form_referer"] = $pathvars["webroot"] . $pathvars["virtual"] . "/login.html";
} else {
    if ($_SESSION["REFERER"] != "" && preg_match("/wizard\$/", dirname($_SESSION["REFERER"]))) {
        $url = str_replace(array($pathvars["virtual"], ".html"), "", $_SESSION["REFERER"]);
    } else {
        $url = str_replace(array($pathvars["webroot"] . $pathvars["virtual"], ".html"), "", $_SERVER["HTTP_REFERER"]);
        $_SESSION["REFERER"] = $pathvars["virtual"] . $url;
    }
    $point = make_id($url);
    #$mid = $point["mid"];
}
$ausgaben["form_referer"] = $_SESSION["form_referer"];
if ($cfg["wizard"]["right"]["add"] == "" || priv_check($url, $cfg["wizard"]["right"]["add"]) || priv_check(tname2path($environment["parameter"][2]), $cfg["wizard"]["right"]["add"]) || priv_check_old("", $cfg["wizard"]["right"]) || $rechte["administration"] == -1 || $erlaubnis == -1) {
    // unzugaengliche #(marken) sichtbar machen
    // ***
    if (isset($_GET["edit"])) {
        $ausgaben["inaccessible"] = "inaccessible values:<br />";
        $ausgaben["inaccessible"] .= "# (error_result) #(error_result)<br />";
        $ausgaben["inaccessible"] .= "# (error_dupe) #(error_dupe)<br />";
    } else {
        $ausgaben["inaccessible"] = "";
    }
    if ($environment["parameter"][2] == "" || $environment["parameter"][3] == "") {
        $hidedata["add_menu"] = array();
        // auswahl fuer die unterschiedlichen Wizardtypen
        $mark = 0;
        $user_level = "wizards_default";
        if (priv_check("/" . $cfg["wizard"]["subdir"] . "/" . $cfg["wizard"]["name"], "admin")) {