static function syncCatname2Artname($params)
 {
     global $REX, $I18N;
     $id = $params['id'];
     $clang = $params['clang'];
     $name = $params['data']['catname'];
     if ($name != '') {
         $sql = new rex_sql();
         $sql->setTable($REX['TABLE_PREFIX'] . 'article');
         $sql->setWhere('id=' . $id . ' AND clang=' . $clang);
         $sql->setValue('name', $name);
         $sql->addGlobalUpdateFields();
         $sql->update();
         rex_deleteCacheArticle($id, $clang);
     }
 }
             $UMOD->setValue('name', $mname);
             $UMOD->setValue('eingabe', $eingabe);
             $UMOD->setValue('ausgabe', $ausgabe);
             $UMOD->addGlobalUpdateFields();
             if ($UMOD->update()) {
                 $info = $I18N->msg('module_updated') . ' | ' . $I18N->msg('articel_updated');
             } else {
                 $warning = $UMOD->getError();
             }
             $new_ausgabe = stripslashes($ausgabe);
             if ($old_ausgabe != $new_ausgabe) {
                 // article updaten - nur wenn ausgabe sich veraendert hat
                 $gc = rex_sql::factory();
                 $gc->setQuery("SELECT DISTINCT(" . $REX['TABLE_PREFIX'] . "article.id) FROM " . $REX['TABLE_PREFIX'] . "article\r\n              LEFT JOIN " . $REX['TABLE_PREFIX'] . "article_slice ON " . $REX['TABLE_PREFIX'] . "article.id=" . $REX['TABLE_PREFIX'] . "article_slice.article_id\r\n              WHERE " . $REX['TABLE_PREFIX'] . "article_slice.modultyp_id='{$modul_id}'");
                 for ($i = 0; $i < $gc->getRows(); $i++) {
                     rex_deleteCacheArticle($gc->getValue($REX['TABLE_PREFIX'] . "article.id"));
                     $gc->next();
                 }
             }
         }
     }
     if ($goon != '') {
         $save = '0';
     } else {
         $function = '';
     }
 }
 if ($save != '1') {
     if ($function == 'edit') {
         $legend = $I18N->msg('module_edit') . ' [ID=' . $modul_id . ']';
         $hole = rex_sql::factory();
     }
 }
 // ------------------------------------------ END: MOVE CATEGORY
 // ------------------------------------------ START: SAVE METADATA
 if (rex_post('savemeta', 'boolean')) {
     $meta_article_name = rex_post('meta_article_name', 'string');
     $meta_sql = rex_sql::factory();
     $meta_sql->setTable($REX['TABLE_PREFIX'] . "article");
     // $meta_sql->debugsql = 1;
     $meta_sql->setWhere("id='{$article_id}' AND clang={$clang}");
     $meta_sql->setValue('name', $meta_article_name);
     $meta_sql->addGlobalUpdateFields();
     if ($meta_sql->update()) {
         $article->setQuery("SELECT * FROM " . $REX['TABLE_PREFIX'] . "article WHERE id='{$article_id}' AND clang='{$clang}'");
         $info = $I18N->msg("metadata_updated");
         rex_deleteCacheArticle($article_id, $clang);
         // ----- EXTENSION POINT
         $info = rex_register_extension_point('ART_META_UPDATED', $info, array('id' => $article_id, 'clang' => $clang, 'name' => $meta_article_name));
     } else {
         $warning = $meta_sql->getError();
     }
 }
 // ------------------------------------------ END: SAVE METADATA
 // ------------------------------------------ START: CONTENT HEAD MENUE
 $num_ctypes = count($REX['CTYPE']);
 $ctype_menu = '';
 if ($num_ctypes > 0) {
     $listElements = array();
     if ($num_ctypes > 1) {
         $listElements[] = $I18N->msg('content_types') . ': ';
     } else {
/**
 * Löscht einen Artikel
 *
 * @param $id ArtikelId des Artikels, der gelöscht werden soll
 *
 * @return TRUE wenn der Artikel gelöscht wurde, sonst eine Fehlermeldung
 */
function _rex_deleteArticle($id)
{
    global $REX, $I18N;
    // artikel loeschen
    //
    // kontrolle ob erlaubnis nicht hier.. muss vorher geschehen
    //
    // -> startpage = 0
    // --> artikelfiles löschen
    // ---> article
    // ---> content
    // ---> clist
    // ---> alist
    // -> startpage = 1
    // --> rekursiv aufrufen
    $return = array();
    $return['state'] = false;
    if ($id == $REX['START_ARTICLE_ID']) {
        $return['message'] = $I18N->msg('cant_delete_sitestartarticle');
        return $return;
    }
    if ($id == $REX['NOTFOUND_ARTICLE_ID']) {
        $return['message'] = $I18N->msg('cant_delete_notfoundarticle');
        return $return;
    }
    $ART = rex_sql::factory();
    $ART->setQuery('select * from ' . $REX['TABLE_PREFIX'] . 'article where id=' . $id . ' and clang=0');
    if ($ART->getRows() > 0) {
        $re_id = $ART->getValue('re_id');
        $return['state'] = true;
        $return = rex_register_extension_point('ART_PRE_DELETED', $return, array('id' => $id, 're_id' => $re_id, 'name' => $ART->getValue('name'), 'status' => $ART->getValue('status'), 'prior' => $ART->getValue('prior'), 'path' => $ART->getValue('path'), 'template_id' => $ART->getValue('template_id')));
        if (!$return['state']) {
            return $return;
        }
        if ($ART->getValue('startpage') == 1) {
            $return['message'] = $I18N->msg('category_deleted');
            $SART = rex_sql::factory();
            $SART->setQuery('select * from ' . $REX['TABLE_PREFIX'] . 'article where re_id=' . $id . ' and clang=0');
            for ($i = 0; $i < $SART->getRows(); $i++) {
                $return['state'] = _rex_deleteArticle($id);
                $SART->next();
            }
        } else {
            $return['message'] = $I18N->msg('article_deleted');
        }
        // Rekursion über alle Kindkategorien ergab keine Fehler
        // => löschen erlaubt
        if ($return['state'] === true) {
            rex_deleteCacheArticle($id);
            $ART->setQuery('delete from ' . $REX['TABLE_PREFIX'] . 'article where id=' . $id);
            $ART->setQuery('delete from ' . $REX['TABLE_PREFIX'] . 'article_slice where article_id=' . $id);
            // --------------------------------------------------- Listen generieren
            rex_generateLists($re_id);
        }
        return $return;
    } else {
        $return['message'] = $I18N->msg('category_doesnt_exist');
        return $return;
    }
}
/**
 * Löscht eine Clang
 *
 * @param $id Zu löschende ClangId
 */
function rex_deleteCLang($clang)
{
    global $REX;
    if ($clang == 0) {
        return "";
    }
    $content = "// --- DYN\n\r";
    foreach ($REX['CLANG'] as $cur => $val) {
        if ($cur != $clang) {
            $content .= "\n\r\$REX['CLANG']['{$cur}'] = \"{$val}\";";
        }
    }
    $content .= "\n\r// --- /DYN";
    $file = $REX['INCLUDE_PATH'] . "/clang.inc.php";
    $h = fopen($file, "r");
    $fcontent = fread($h, filesize($file));
    $fcontent = ereg_replace("(\\/\\/.---.DYN.*\\/\\/.---.\\/DYN)", $content, $fcontent);
    fclose($h);
    $h = fopen($file, "w+");
    fwrite($h, $fcontent, strlen($fcontent));
    fclose($h);
    @chmod($file, 0777);
    $del = new rex_sql();
    $del->setQuery("select * from " . $REX['TABLE_PREFIX'] . "article where clang='{$clang}'");
    for ($i = 0; $i < $del->getRows(); $i++) {
        $aid = $del->getValue("id");
        rex_deleteCacheArticle($aid, $clang);
        $del->next();
    }
    $del->setQuery("delete from " . $REX['TABLE_PREFIX'] . "article where clang='{$clang}'");
    $del->setQuery("delete from " . $REX['TABLE_PREFIX'] . "article_slice where clang='{$clang}'");
    unset($REX['CLANG'][$clang]);
    $del = new rex_sql();
    $del->setQuery("delete from " . $REX['TABLE_PREFIX'] . "clang where id='{$clang}'");
    // ----- EXTENSION POINT
    rex_register_extension_point('CLANG_DELETED', '', array('id' => $clang));
    rex_generateAll();
}
/**
 * Löscht eine Clang
 *
 * @param $id Zu löschende ClangId
 */
function rex_deleteCLang($clang)
{
    global $REX;
    if ($clang == 0) {
        return "";
    }
    $content = "";
    foreach ($REX['CLANG'] as $cur => $val) {
        if ($cur != $clang) {
            $content .= "\$REX['CLANG']['{$cur}'] = \"{$val}\";\n";
        }
    }
    $file = $REX['INCLUDE_PATH'] . "/clang.inc.php";
    rex_replace_dynamic_contents($file, $content);
    $del = new rex_sql();
    $del->setQuery("select * from " . $REX['TABLE_PREFIX'] . "article where clang='{$clang}'");
    for ($i = 0; $i < $del->getRows(); $i++) {
        $aid = $del->getValue("id");
        rex_deleteCacheArticle($aid, $clang);
        $del->next();
    }
    $del->setQuery("delete from " . $REX['TABLE_PREFIX'] . "article where clang='{$clang}'");
    $del->setQuery("delete from " . $REX['TABLE_PREFIX'] . "article_slice where clang='{$clang}'");
    unset($REX['CLANG'][$clang]);
    $del = new rex_sql();
    $del->setQuery("delete from " . $REX['TABLE_PREFIX'] . "clang where id='{$clang}'");
    // ----- EXTENSION POINT
    rex_register_extension_point('CLANG_DELETED', '', array('id' => $clang));
    rex_generateAll();
}
/**
 * Ändert den Status des Artikels
 *
 * @param int      $article_id Id des Artikels die gelöscht werden soll
 * @param int      $clang      Id der Sprache
 * @param int|null $status     Status auf den der Artikel gesetzt werden soll, oder NULL wenn zum nächsten Status weitergeschaltet werden soll
 *
 * @return array Ein Array welches den status sowie eine Fehlermeldung beinhaltet
 */
function rex_articleStatus($article_id, $clang, $status = null)
{
    global $REX, $I18N;
    if (!is_object($I18N)) {
        $I18N = rex_create_lang($REX['LANG']);
    }
    $success = false;
    $message = '';
    $artStatusTypes = rex_articleStatusTypes();
    $GA = rex_sql::factory();
    $GA->setQuery('select * from ' . $REX['TABLE_PREFIX'] . "article where id='{$article_id}' and clang={$clang}");
    if ($GA->getRows() == 1) {
        // Status wurde nicht von außen vorgegeben,
        // => zyklisch auf den nächsten Weiterschalten
        if (!$status) {
            $newstatus = ($GA->getValue('status') + 1) % count($artStatusTypes);
        } else {
            $newstatus = $status;
        }
        $EA = rex_sql::factory();
        $EA->setTable($REX['TABLE_PREFIX'] . 'article');
        $EA->setWhere("id='{$article_id}' and clang={$clang}");
        $EA->setValue('status', $newstatus);
        $EA->addGlobalUpdateFields($REX['REDAXO'] ? null : 'frontend');
        if (!$REX['REDAXO']) {
            include_once $REX['INCLUDE_PATH'] . '/functions/function_rex_generate.inc.php';
        }
        if ($EA->update()) {
            $message = $I18N->msg('article_status_updated');
            rex_deleteCacheArticle($article_id, $clang);
            // ----- EXTENSION POINT
            $message = rex_register_extension_point('ART_STATUS', $message, array('id' => $article_id, 'clang' => $clang, 'status' => $newstatus));
            $success = true;
        } else {
            $message = $EA->getError();
        }
    } else {
        $message = $I18N->msg('no_such_category');
    }
    return array($success, $message);
}
/**
 * Ändert den Status des Artikels
 * 
 * @param int       $article_id Id des Artikels die gelöscht werden soll
 * @param int       $clang      Id der Sprache
 * @param int|null  $status     Status auf den der Artikel gesetzt werden soll, oder NULL wenn zum nächsten Status weitergeschaltet werden soll
 * 
 * @return array Ein Array welches den status sowie eine Fehlermeldung beinhaltet
 */
function rex_articleStatus($article_id, $clang, $status = null)
{
    global $REX, $I18N;
    $success = false;
    $message = '';
    $artStatusTypes = rex_articleStatusTypes();
    $GA = new rex_sql();
    $GA->setQuery("select * from " . $REX['TABLE_PREFIX'] . "article where id='{$article_id}' and clang={$clang}");
    if ($GA->getRows() == 1) {
        // Status wurde nicht von außen vorgegeben,
        // => zyklisch auf den nächsten Weiterschalten
        if (!$status) {
            $newstatus = ($GA->getValue('status') + 1) % count($artStatusTypes);
        } else {
            $newstatus = $status;
        }
        $EA = new rex_sql();
        $EA->setTable($REX['TABLE_PREFIX'] . "article");
        $EA->setWhere("id='{$article_id}' and clang={$clang}");
        $EA->setValue('status', $newstatus);
        $EA->addGlobalUpdateFields();
        if ($EA->update()) {
            $message = $I18N->msg('article_status_updated');
            rex_deleteCacheArticle($article_id, $clang);
            // ----- EXTENSION POINT
            $message = rex_register_extension_point('ART_STATUS', $message, array('id' => $article_id, 'clang' => $clang, 'status' => $newstatus));
            $success = true;
        } else {
            $message = $EA->getError();
        }
    } else {
        $message = $I18N->msg("no_such_category");
    }
    return array($success, $message);
}
/**
 * Verschieben einer Kategorie in eine andere
 *
 * @param int $from_cat_id KategorieId der Kategorie, die verschoben werden soll (Quelle)
 * @param int $to_cat_id   KategorieId der Kategorie, IN die verschoben werden soll (Ziel)
 *
 * @return boolean TRUE bei Erfolg, sonst FALSE
 */
function rex_moveCategory($from_cat, $to_cat)
{
    global $REX;
    $from_cat = (int) $from_cat;
    $to_cat = (int) $to_cat;
    if ($from_cat == $to_cat) {
        // kann nicht in gleiche kategroie kopiert werden
        return false;
    } else {
        // kategorien vorhanden ?
        // ist die zielkategorie im pfad der quellkategeorie ?
        $fcat = rex_sql::factory();
        $fcat->setQuery('select * from ' . $REX['TABLE_PREFIX'] . "article where startpage=1 and id={$from_cat} and clang=0");
        $tcat = rex_sql::factory();
        $tcat->setQuery('select * from ' . $REX['TABLE_PREFIX'] . "article where startpage=1 and id={$to_cat} and clang=0");
        if ($fcat->getRows() != 1 or $tcat->getRows() != 1 && $to_cat != 0) {
            // eine der kategorien existiert nicht
            return false;
        } else {
            if ($to_cat > 0) {
                $tcats = explode('|', $tcat->getValue('path'));
                if (in_array($from_cat, $tcats)) {
                    // zielkategorie ist in quellkategorie -> nicht verschiebbar
                    return false;
                }
            }
            // ----- folgende cats regenerate
            $RC = array();
            $RC[$fcat->getValue('re_id')] = 1;
            $RC[$from_cat] = 1;
            $RC[$to_cat] = 1;
            if ($to_cat > 0) {
                $to_path = $tcat->getValue('path') . $to_cat . '|';
                $to_re_id = $tcat->getValue('re_id');
            } else {
                $to_path = '|';
                $to_re_id = 0;
            }
            $from_path = $fcat->getValue('path') . $from_cat . '|';
            $gcats = rex_sql::factory();
            // $gcats->debugsql = 1;
            $gcats->setQuery('select * from ' . $REX['TABLE_PREFIX'] . "article where path like '" . $from_path . "%' and clang=0");
            $up = rex_sql::factory();
            // $up->debugsql = 1;
            for ($i = 0; $i < $gcats->getRows(); $i++) {
                // make update
                $new_path = $to_path . $from_cat . '|' . str_replace($from_path, '', $gcats->getValue('path'));
                $icid = $gcats->getValue('id');
                $irecid = $gcats->getValue('re_id');
                // path aendern und speichern
                $up->setTable($REX['TABLE_PREFIX'] . 'article');
                $up->setWhere("id={$icid}");
                $up->setValue('path', $new_path);
                $up->update();
                // cat in gen eintragen
                $RC[$icid] = 1;
                $gcats->next();
            }
            // ----- clang holen, max catprio holen und entsprechen updaten
            $gmax = rex_sql::factory();
            $up = rex_sql::factory();
            // $up->debugsql = 1;
            foreach ($REX['CLANG'] as $clang => $clang_name) {
                $gmax->setQuery('select max(catprior) from ' . $REX['TABLE_PREFIX'] . "article where re_id={$to_cat} and clang=" . $clang);
                $catprior = (int) $gmax->getValue('max(catprior)');
                $up->setTable($REX['TABLE_PREFIX'] . 'article');
                $up->setWhere("id={$from_cat} and clang={$clang} ");
                $up->setValue('path', $to_path);
                $up->setValue('re_id', $to_cat);
                $up->setValue('catprior', $catprior + 1);
                $up->update();
            }
            // ----- generiere artikel neu - ohne neue inhaltsgenerierung
            foreach ($RC as $id => $key) {
                rex_deleteCacheArticle($id);
            }
            foreach ($REX['CLANG'] as $clang => $clang_name) {
                rex_newCatPrio($fcat->getValue('re_id'), $clang, 0, 1);
            }
        }
    }
    return true;
}