<?php
/******************************************************************************
 @Author:     Björn Brockmann, Paul Eppner (paul@twomoons.de)
                              Sven Bräutigam, Jürgen Brändle
 @Homepage    http://www.der-dirigent.de
 Last update : 2005-11-24                               
 Part of     : Update to Version 01.00.02  
******************************************************************************/
if (!is_object($perm)) die();
function con_edit_save_content ($idsidelang, $container, $number, $idtype, $typenumber, $value) {
        global $db, $auth, $dedi_db, $lang, $cfg_client, $cfg_client;

        $author = $auth->auth['uid'];
        set_magic_quotes_gpc($value);

        // Eintrag in die 'con_content'-Tabelle
        $sql = "SELECT value FROM $dedi_db[content] WHERE idsidelang='$idsidelang' AND container='$container' AND number='$number' AND idtype='$idtype' AND typenumber='$typenumber'";
        $db->query($sql);

        // Steht schon Content in der Datenbank?
        if ($db->next_record()) {

                // hat sich was geändert?
                if (addslashes($db->f('value')) != $value) {

                        // interne Bildpfade relativ machen
                        $in = array("!href=(\\\\)?[\"\']".$cfg_client['htmlpath']."([^\"\'\\\\]*)(\\\\)?[\"\']!i",
                                    "!src=(\\\\)?[\"\']".$cfg_client['htmlpath']."([^\"\'\\\\]*)(\\\\)?[\"\']!i");
                        $out = array("href=\\1\"\\2\\3\"",
                                     "src=\\1\"\\2\\3\"");
                        $value = preg_replace($in, $out, $value);

                        // wurde überhaupt was eingegeben?
                        if ($value != '') {
                                 $sql = "UPDATE $dedi_db[content] SET value='$value', author='$author', lastmodified='".time()."' WHERE idsidelang='$idsidelang' AND container='$container' AND number='$number' AND idtype='$idtype' AND typenumber='$typenumber'";
                                $db->query($sql);
                                $change = 'true';
                         } else {
                                $sql = "DELETE FROM ".$dedi_db['content']." WHERE idsidelang='$idsidelang' AND container='$container' AND number='$number' AND idtype='$idtype' AND typenumber='$typenumber'";
                                $db->query($sql);
                                $change = 'true';
                         }
                }
        } else {
                if ($value != '') {
                        // neuer Eintrag?
                         $sql = "INSERT INTO $dedi_db[content] (idsidelang, container, number, idtype, typenumber, value, author, created, lastmodified) VALUES('$idsidelang', '$container', '$number', '$idtype', '$typenumber', '$value', '$author', '".time()."', '".time()."')";
                        $db->query($sql);
                        $change = 'true';
                 }
         }

        if ($change) {
                // Änderungsdatum aktualisieren
                $sql = "UPDATE $dedi_db[side_lang] SET lastmodified='".time()."', author='$author' WHERE idsidelang='$idsidelang'";
                $db->query($sql);

                // Seitenkopien suchen
                $sql = "SELECT idcatside FROM $dedi_db[side_lang] A LEFT JOIN $dedi_db[cat_side] B USING(idside) WHERE A.idsidelang='$idsidelang'";
                $db->query($sql);
                while ($db->next_record()) $list[] = $db->f('idcatside');

                // Status der Seite auf geändert stellen
                change_code_status($list, '1', 'idcatside');
                unset($change);
        }
}

function con_edit_unset_sidelock ($idsidelang, $idtype, $typeid) {
        global $db, $dedi_db;

        $sql = "SELECT * FROM $dedi_db[content] WHERE idsidelang='$idsidelang' AND idtype='$idtype' AND typeid='$typeid'";
        $db->query($sql);
        if ($db->next_record()) {
                $sql = "UPDATE $dedi_db[content] SET edit_ttl = '0' WHERE idsidelang='$idsidelang' AND idtype='$idtype' AND typeid='$typeid'";
                $db->query($sql);
        }
}
?>