<?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       - Bugfix for multibyte charsets
  Part of     : Update to Version 01.00.02
******************************************************************************/

//mehrere Elemente auf einmal speichern
if (!defined('IS_DEDI')) die();
if ($action == 'savex' && $data != '') {
	// Event
	fire_event('con_edit', array('path' => $dedi_path,'idcatside' => $idcatside));
    // Delete Content Cache
	$db->delete_cache('frontend_content');
	$array1 = explode('*x||*',substr($data,0,-5));
	foreach($array1 as $value)
	{
		$array2 = explode('*x|*',$value);
		con_edit_save_content($con_side[$idcatside]['idsidelang'], $array2[0], $array2[1], $array2[2], $array2[3], $array2[4]);
		$sql = "SELECT
					*
				FROM
					$dedi_db[content]
				WHERE
				idsidelang='".$con_side[$idcatside]['idsidelang']."'
				AND container='".$array2[0]."'
				AND number='".$array2[1]."'";
		$db->query($sql);
		if (!$db->affected_rows()) {
			$sql = "UPDATE
						$dedi_db[content]
					SET number=number-1
					WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."'
					AND container='".$array2[0]."'
					AND number>'".$array2[1]."'";
			$db->query($sql);
		}
	}
}

// Content speichern
if ($action == 'save') {
	// Event
	fire_event('con_edit', array('path' => $dedi_path, 'idcatside' => $idcatside, 'content' => $content));
    // Delete Content Cache
	$db->delete_cache('frontend_content');
	// Content-Array aufbauen
	$con_content = explode (';', $content);
	unset($content);
	foreach ($con_content as $value) {
		$con_config = explode ('.', $value);
		$con_container = $con_config['0'];

		// Modul verschieben
		if (is_numeric($entry)) {
			$sql = "UPDATE $dedi_db[content] SET number=number+1 WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number>'$entry'";
			$db->query($sql);
		}
		$con_contnbr = explode (',', $con_config[1]);
		$con_content_type = explode (',', $con_config[2]);
		foreach ($con_contnbr as $con_containernumber) {
			foreach ($con_content_type as $value3) {
				$value3 = explode ('-', $value3);
				$con_contype = $value3['0'];
				$con_typenumber = $value3['1'];
				$content = ${'content_'.$con_container.'_'.$con_containernumber.'_'.$con_contype.'_'.$con_typenumber};

				// neue Modul-ID vergeben
				if (is_numeric($entry)) $new_containernumber = $entry+1;
                                 else $new_containernumber = $con_containernumber;
				con_edit_save_content($con_side[$idcatside]['idsidelang'], $con_container, $new_containernumber, $con_contype, $con_typenumber, $content);
				unset($content);
			}

			// Modulverdopplung minimieren, wenn Content leer ist.
			$sql = "SELECT * FROM $dedi_db[content] WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number='$new_containernumber'";
			$db->query($sql);
			if (!$db->affected_rows()) {
                                	$sql = "UPDATE $dedi_db[content] SET number=number-1 WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number>'$new_containernumber'";
				$db->query($sql);
			}
		}

		// Falls nichts eingetragen wurde Eintrag zurückverschieben
		if (is_numeric($entry)) {
			$sql = "SELECT * FROM $dedi_db[content] WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number='".($entry+1)."'";
			$db->query($sql);
			if (!$db->affected_rows()) {
				$sql = "UPDATE $dedi_db[content] SET number=number-1 WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number>'$entry'";
				$db->query($sql);
			}
                 }
	}
}

// Content löschen
if ($action == 'delete') {
	$con_content = explode (';', $content);
	unset($content);
	// Delete Content Cache
	$db->delete_cache('frontend_content');
	foreach ($con_content as $value) {
		$con_config = explode ('.', $value);
		$con_container = $con_config['0'];
		$con_contnbr = $con_config['1'];

		// Einträge löschen
		$sql = "DELETE FROM $dedi_db[content] WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number='$con_contnbr'";
		$db->query($sql);

		// Modul verschieben
		$sql = "UPDATE $dedi_db[content] SET number=number-1 WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number>'$con_contnbr'";
		$db->query($sql);

		// Änderungsdatum aktualisieren
		$sql = "UPDATE $dedi_db[side_lang] SET lastmodified='".time()."', author='".$auth->auth['uid']."' WHERE idsidelang='".$con_side[$idcatside]['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='".$con_side[$idcatside]['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');
	}
}

// Modul nach oben verschieben
if ($action == 'move_up') {
	$con_content = explode (';', $content);
	// Delete Content Cache
	$db->delete_cache('frontend_content');
	unset($content);
	foreach ($con_content as $value) {
		$con_config = explode ('.', $value);
		$con_container = $con_config['0'];
		$entry = $con_config['1'];
		$sql = "UPDATE $dedi_db[content] SET number='-1' WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number='$entry'";
		$db->query($sql);
		$sql = "UPDATE $dedi_db[content] SET number=number+1 WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number='".($entry-1)."'";
		$db->query($sql);
		$sql = "UPDATE $dedi_db[content] SET number='".($entry-1)."' WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number='-1'";
		$db->query($sql);
	}
	// Änderungsdatum aktualisieren
	$sql = "UPDATE $dedi_db[side_lang] SET lastmodified='".time()."', author='".$auth->auth['uid']."' WHERE idsidelang='".$con_side[$idcatside]['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='".$con_side[$idcatside]['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');
}

// Modul nach unten verschieben
if ($action == 'move_down') {
	$con_content = explode (';', $content);
	// Delete Content Cache
	$db->delete_cache('frontend_content');
	unset($content);
	foreach ($con_content as $value) {
		$con_config = explode ('.', $value);
		$con_container = $con_config['0'];
		$entry = $con_config['1'];
		$sql = "UPDATE $dedi_db[content] SET number='-1' WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number='$entry'";
		$db->query($sql);
		$sql = "UPDATE $dedi_db[content] SET number=number-1 WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number='".($entry+1)."'";
		$db->query($sql);
		$sql = "UPDATE $dedi_db[content] SET number='".($entry+1)."' WHERE idsidelang='".$con_side[$idcatside]['idsidelang']."' AND container='$con_container' AND number='-1'";
		$db->query($sql);
	}
	// Änderungsdatum aktualisieren
	$sql = "UPDATE $dedi_db[side_lang] SET lastmodified='".time()."', author='".$auth->auth['uid']."' WHERE idsidelang='".$con_side[$idcatside]['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='".$con_side[$idcatside]['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');
}

//Content bearbeiten
if ($action == 'edit' || $action == 'new') {

	// Formularelemente includieren
	include_once($dedi_path.'inc/fnc.type_forms.php');
	$code = '<html>'."\n";
	$code .= '<head>'."\n";
	$code .= '<title>edit-Modus</title>'."\n";
	$code .= '<meta http-equiv="content-type" content="text/html; charset='.$lang_charset.'">'."\n";
	$code .= '<link rel="stylesheet" type="text/css" href="'.$cfg_dedi['dedi_html_path'].'tpl/'.$cfg_dedi['skin'].'/css/styles.css">'."\n";
	$code .= '</head>'."\n";
	$code .= '<body topmargin="0" leftmargin="0">'."\n";
	$code .= '<center>'."\n";
	$code .= '<table width="98%" cellspacing="0" cellpadding="0" border="0">'."\n";
	$code .= '  <tr>'."\n";
	$code .= '    <td>'."\n";
	$code .= "    <form name=\"editcontent\" method=\"post\" action=\"".$sess->url($cfg_client['contentfile'])."\">\n";
	$code .= "    <input type=\"hidden\" name=\"view\" value=\"edit\">\n";
	$code .= "    <input type=\"hidden\" name=\"lang\" value=\"$lang\">\n";
	$code .= "    <input type=\"hidden\" name=\"action\" value=\"save\">\n";
	$code .= "    <input type=\"hidden\" name=\"entry\" value=\"$entry\">\n";
	$code .= "    <input type=\"hidden\" name=\"idcatside\" value=\"$idcatside\">\n";
	$code .= "    <input type=\"hidden\" name=\"content\" value=\"$content\">\n";
	$code .= "    <table cellspacing=\"$cellspacing\" cellpadding=\"$cellpadding\" border=\"$border\">\n";

	$sql = "SELECT * FROM $dedi_db[type]";
	$db->query($sql);
	while ($db->next_record())
	{
		$con_type[$db->f('idtype')]['type'] = $db->f('type');
		$con_type[$db->f('idtype')]['input'] = $db->f('input');
		$con_type[$db->f('idtype')]['descr'] = $db->f('description');
	}

	// Content-Array erstellen
	$sql = "SELECT
				A.idcontent, container, number, idtype, typenumber, value
			FROM
				$dedi_db[content] A
				LEFT JOIN $dedi_db[side_lang] B USING(idsidelang)
			WHERE
				B.idside='$idside'
				AND B.idlang='$lang'";
	$db->query($sql);
	while ($db->next_record())
	{
	 	$content_array[$db->f('container')][$db->f('number')][$db->f('idtype')][$db->f('typenumber')] = array($db->f('idcontent'), htmlspecialchars($db->f('value')));
	}

	// Module finden
	if ($con_side[$idcatside]['idtplconf'] == '0') {
		$idtplconf = $con_tree[$con_side[$idcatside]['idcat']]['idtplconf'];
	} else {
		$idtplconf = $con_side[$idcatside]['idtplconf'];
	}

	$modlist = browse_template_for_module('0', $idtplconf);

	// Containernamen suchen
	$sql = "SELECT idlay FROM $dedi_db[tpl_conf] A LEFT JOIN $dedi_db[tpl] B USING(idtpl) WHERE A.idtplconf='$idtplconf'";
	$db->query($sql);
	$db->next_record();
	$idlay = $db->f('idlay');
	$list = browse_layout_for_containers($idlay);

	// Browserinformationen in Array schreiben
	$tmp_sniffer = explode(',', $sid_sniffer);

	// Bearbeitungsarray erstellen
	$con_content = explode (';', $content);
	unset($content);

	// Einzelne Container auflisten
	foreach ($con_content as $value) {

		// Konfiguration einlesen
		$con_config = explode ('.', $value);
		$con_container = $con_config['0'];
		$con_contnbr = explode (',', $con_config[1]);
		$con_content_type = explode (',', $con_config[2]);

		// Konfigurationsparameter mod_values extahieren und aufbereiten
		$sql = "SELECT container_conf.config FROM ".$dedi_db['container_conf']." container_conf LEFT JOIN ".$dedi_db['tpl_conf']." tpl_conf USING(idtplconf) LEFT JOIN ".$dedi_db['container']." container USING(idtpl) WHERE container_conf.idtplconf = $idtplconf AND container = $con_container AND container_conf.idcontainer = container.idcontainer";
		$db->query($sql);
		$db->next_record();
		$tpl_config_vars = $db->f('config');

		// mod_values aus Container ersetzen
		$container = $modlist[$con_container]['output'];
		$config = preg_split('/&/', $tpl_config_vars );
		foreach ($config as $key1 => $value1) {
			$tmp2 = explode('=', $value1);
			if ($tmp2['1'] != '') {
				// $mod_value Array schreiben
				$dedi_mod['value'][$tmp2['0']] = dedi_stripslashes(urldecode($tmp2['1']));
				// MOD_VALUE[x] ersetzen
				$container = str_replace('MOD_VALUE['.$tmp2['0'].']', str_replace("\'","'", urldecode($tmp2['1'])), $container);//'
			}
			unset($tmp2);
		}

		// nicht benutzte Variablen strippen
		$container = preg_replace('/MOD_VALUE\[\d*\]/', '', $container);
		if( stristr ($container, '<dedi:mod constant="tagmode" />') ){
			$container = str_replace('<dedi:mod constant="tagmode" />', '', $container);
			$container = dedi_stripslashes($container);
		}


		// Moduloutput simulieren, zum generieren der DeDi-Tag Informationen
		$deditag_config = extract_dedi_tags($container, 'type');

		// Rowspan für Containertabelle berechnen
		$rowspan = 0;
		foreach ($con_contnbr as $con_containernumber) {
			$rowspan++;
			foreach ($con_content_type as $value3) {
				$rowspan++;
				$rowspan++;
			}
		}

		$code .= "  <tr>\n";

		// Containername
		$code .= "    <td class=\"head\" valign=\"top\" width=\"110\" nowrap rowspan=\"$rowspan\">&nbsp;";
		if (!empty($list[$con_container]['title'])) $code .= $list[$con_container]['title'];
		else $code .= "$con_container. ".$dedi_lang['tpl_container'];
		$code .= "&nbsp;</td>\n";
		unset($rowspan);
		foreach ($con_contnbr as $con_containernumber) {

			// neues Modul erstellen?
			if ($con_containernumber == '-1') $print_containernumber = '';
			else $print_containernumber = $con_containernumber.'. ';

			// Modulname
			$modname = (($modlist[$con_container]['verbose']) != '' ? $modlist[$con_container]['verbose'] : $modlist[$con_container]['modname']) . ((empty($modlist[$con_container]['version'])) ? '' : ' (' . $modlist[$con_container]['version'] . ')');
			$code .= "    <td class=\"head\" width=\"640\">&nbsp;<!-- $print_containernumber -->".$modname."&nbsp;</td>\n";
			$code .= "  </tr>\n";
			foreach ($con_content_type as $value3) {
				$value3 = explode ('-', $value3);
				$con_contype = $value3['0'];
				$con_typenumber = $value3['1'];

				// Name für Eingabefeld
				// Nicht anzeigen bei Dateilink, wenn hidetarget auf true gesetzt ist
				if ($filetarget_is_hidden == 'true' && $con_contype == 12) {
					$code .= "    <td class=\"content\">&nbsp;&nbsp;</td>\n";
					$code .= "  </tr>\n";
					$code .= "  <tr>\n";

				} else {
					$code .= "    <td class=\"content\">&nbsp;";
					if (!empty($deditag_config[$con_type[$con_contype]['type']][$con_typenumber]['title'])) $code .= $deditag_config[$con_type[$con_contype]['type']][$con_typenumber]['title'];
					else $code .= $con_type[$con_contype]['descr'];
					$code .= ":&nbsp;</td>\n";
					$code .= "  </tr>\n";
					$code .= "  <tr>\n";
				}

				// Name des Formularfeldes
				$formname = 'content_'.$con_container.'_'.$con_containernumber.'_'.$con_contype.'_'.$con_typenumber;

				// benutzte WYSIWYG-Applets in Array schreiben
				if ((($tmp_sniffer['18'] != 'true' && $cfg_client['wysiwyg_applet'] == '1') || $cfg_client['wysiwyg_applet'] == '2') && $con_contype == '2' || $con_contype == '13') $used_applet[] = $formname;

				// Variable für den Content
				$content = $content_array[$con_container][$con_containernumber][$con_contype][$con_typenumber]['1'];
				eval ($con_type[$con_contype]['input']);
				unset($content);
				unset($formname);
				$code .= "  </tr>\n";

			}
		}
	}
	$code .= "      <tr>\n";
	$code .= "        <td>&nbsp;</td>\n";

	// Contentgrabberfunktion für die WYSIWYG-Applets
	if (($tmp_sniffer['18'] != 'true' && $cfg_client['wysiwyg_applet'] == '1') || $cfg_client['wysiwyg_applet'] == '2') {
		$code .= "    <script type=\"text/javascript\">\n";
		$code .= "    <!--\n";
		$code .= "      function sendContent() {\n";
		if (is_array($used_applet)) foreach ($used_applet as $formname) $code .= "        document.editcontent.$formname.value = document.WYSIWYG_$formname.getContents();\n";
		$code .= "        document.editcontent.submit();\n";
		$code .= "      }\n";
		$code .= "    //-->\n";
		$code .= "    </script>\n";
		unset($formname);
	}
	$code .= "        <td><a href=".$sess->url("".$cfg_client['contentfile']."?lang=$lang&action=abort&view=edit&idcatside=$idcatside")."><img src=\"".$cfg_dedi['dedi_html_path']."tpl/".$cfg_dedi['skin']."/img/but_cancel.gif\" border=0></a>\n";
	if (($tmp_sniffer['18'] != 'true' && $cfg_client['wysiwyg_applet'] == '1') || $cfg_client['wysiwyg_applet'] == '2') $code .= "        <input type=\"image\" name=\"submit\" onclick=\"sendContent();\" src=\"".$cfg_dedi['dedi_html_path']."tpl/".$cfg_dedi['skin']."/img/but_ok.gif\" border=\"0\"></td>\n";
	else $code .= "        <input type=\"image\" name=\"submit\" src=\"".$cfg_dedi['dedi_html_path']."tpl/".$cfg_dedi['skin']."/img/but_ok.gif\" border=\"0\"></td>\n";
	$code .= "      </tr>\n";
	$code .= "    </table>\n";
	$code .= "    </form>\n";
	unset ($con_type);
	unset ($con_content);
	$code .= '    </td>'."\n";
	$code .= '  </tr>'."\n";
	$code .= '</table>'."\n";
	$code .= '</center>'."\n";
	$code .= '</body>'."\n";
	$code .= '</html>'."\n";

// normale Anzeige
} else {

	// Template suchen
	$sql = "SELECT A.idtplconf, B.idtpl FROM $dedi_db[side_lang] A LEFT JOIN $dedi_db[tpl_conf] B USING(idtplconf) WHERE A.idside='$idside' AND A.idlang='$lang' AND A.idtplconf!='0'";
	$db->query($sql);
	if (!$db->affected_rows()) {
		$sql = "SELECT A.idtplconf, B.idtpl FROM $dedi_db[cat_lang] A LEFT JOIN $dedi_db[tpl_conf] B USING(idtplconf) WHERE A.idcat='$idcat' AND A.idlang='$lang' AND A.idtplconf!='0'";
		$db->query($sql);
	}
	if ($db->next_record()) {
		// Templatekonfiguration suchen
		$idtpl = $db->f('idtpl');
		$sql = "SELECT A.config, A.view, A.edit, B.container, C.name, C.output, C.idmod, C.verbose FROM $dedi_db[container_conf] A LEFT JOIN $dedi_db[container] B USING(idcontainer) LEFT JOIN $dedi_db[mod] C USING(idmod) WHERE A.idtplconf='".$db->f('idtplconf')."'";
		$db->query($sql);
		while ($db->next_record()) $container[$db->f('container')] = array ($db->f('config'), $db->f('view'), $db->f('edit'), $db->f('name'), $db->f('output'), $db->f('idmod'), $db->f('verbose'));

		// Content-Array erstellen
		$sql = "SELECT A.idcontent, container, number, idtype, typenumber, value FROM $dedi_db[content] A LEFT JOIN $dedi_db[side_lang] B USING(idsidelang) WHERE B.idside='$idside' AND B.idlang='$lang' ORDER BY number";
		$db->query($sql);
		while ($db->next_record()) $content[$db->f('container')][$db->f('number')][$db->f('idtype')][$db->f('typenumber')] = array($db->f('idcontent'), $db->f('value'));

		// Layout suchen
		$sql = "SELECT A.idlay, B.code FROM ".$dedi_db['tpl']." A LEFT JOIN ".$dedi_db['lay']." B USING(idlay) WHERE A.idtpl='$idtpl'";
		$db->query($sql);
		$db->next_record();
		$layout = $db->f('code');
		$idlay = $db->f('idlay');
		$layout = str_replace('<DEDIPHP:CACHE>', '<?PHP ', $layout);
		$layout = str_replace('</DEDIPHP:CACHE>', ' ?>', $layout);

		// Container generieren
		$list = extract_dedi_tags($layout);
		if (is_array($list)) {
			foreach ($list as $dedi_mod['container']) {
				// Head-Container?
				if ($dedi_mod['container']['type'] == 'head') {
					$code = "<!--START head//-->\n";
					$code .= "<meta name=\"generator\" content=\"Der Dirigent ".$cfg_dedi['version']." / www.der-dirigent.de\">\n";
					$code .= '<?PHP if ($con_side[$idcatside][\'meta_author\'] != \'\') echo \'<meta name="author" content="\'.$con_side[$idcatside][\'meta_author\'].\'">\'."\n"; ?>';
					$code .= '<?PHP if ($con_side[$idcatside][\'meta_description\'] != \'\') echo \'<meta name="description" content="\'.$con_side[$idcatside][\'meta_description\'].\'">\'."\n"; ?>';
					$code .= '<?PHP if ($con_side[$idcatside][\'meta_keywords\'] != \'\') echo \'<meta name="keywords" content="\'.$con_side[$idcatside][\'meta_keywords\'].\'">\'."\n"; ?>';
					$code .= '<?PHP if ($con_side[$idcatside][\'meta_robots\'] != \'\') echo \'<meta name="robots" content="\'.$con_side[$idcatside][\'meta_robots\'].\'">\'."\n"; ?>';
					$code .= '<meta http-equiv="content-type" content="text/html; charset='.$lang_charset.'">'."\n";
					$code .= "<meta http-equiv=\"expires\" content=\"0\">\n";
					$sql = "SELECT C.filetype, D.dirname, B.filename FROM $dedi_db[lay_upl] A LEFT JOIN $dedi_db[upl] B USING(idupl) LEFT JOIN $dedi_db[filetype] C USING(idfiletype) LEFT JOIN $dedi_db[directory] D ON B.iddirectory=D.iddirectory WHERE idlay='$idlay'";
					$db->query($sql);
					while ($db->next_record()) {
						if ($db->f('filetype') == 'js') $code .= "<script src=\"".$db->f('dirname').$db->f('filename')."\" type=\"text/javascript\"></script>\n";
						else if ($db->f('filetype') == 'css') $code .= "<link rel=\"StyleSheet\" href=\"".$db->f('dirname').$db->f('filename')."\" type=\"text/css\">\n";
					}
					$code .= "<style type=\"text/css\">\n";
					$code .= "  div.actEditFrame {border:1px solid #AF0F0F; -moz-user-focus: normal}\n";
					$code .= "  div.editFrame {border:1px dashed #BFBFBF; -moz-user-focus: normal}\n";
					$code .= "  #popmenu {position:absolute;width:140px;background-color:menu;font:normal 12px Verdana;line-height:18px;z-index:100;visibility:hidden;}\n";
					$code .= "  .menutitle {font-family : verdana, helvetica, arial, geneva, sans-serif; font-size : 11px; color: #FFFFFF; text-decoration : none;}\n";
					$code .= "  .menurow {font-family : verdana, helvetica, arial, geneva, sans-serif; font-size : 11px; color: #777777; text-decoration : none; padding-left : 10px; padding-right : 10px;}\n";
					$code .= "  .menurow a {color: #777777; text-decoration : none;}\n";
					$code .= "  #menurow_over {background-color: #DBE3EF;cursor:pointer;color: #000000;}\n";
					$code .= "  #menurow_over a {color: #000000; text-decoration : none; background-color: #DBE3EF;}\n";
					$code .= "</style>\n";
					//$code .= "<script language=\"JavaScript1.2\" src=\"cms/js/popupmenu.js\" type=\"text/javascript\"></script>\n";
					$code .= "<script language=\"JavaScript1.2\" src=\"". $cfg_dedi['dedi_html_path'].'tpl/'.$cfg_dedi['skin'].'/js/popupmenu.js' ."\" type=\"text/javascript\"></script>\n";
					$code .= "<script language=\"JavaScript\">\n";
					$code .= "<!--\n";
					$code .= "function dedi_status(message) {\n";
					$code .= "  window.status = message;\n";
					$code .= "  window.defaultStatus = window.status;\n";
					$code .= "}\n";
					$code .= "function on(message) {\n";
					$code .= '  window.setTimeout("dedi_status(\""+message+"\")",10);'."\n";
					$code .= "}\n";
					$code .= "function off() {\n";
					$code .= "  window.status = \"".str_replace('"', '\"', $con_side[$idcatside]['name'])."\";\n";
					$code .= "  window.defaultStatus = window.status;\n";
					$code .= "}\n";
					$code .= "function delete_confirm() {\n";
					$code .= "  if(confirm(\"".$dedi_lang['gen_deletealert']."\")) return true;\n";
					$code .= "  else return false;\n";
					$code .= "}\n";

					$code .= "function con_setcontent(container,number,type,typenumber) {\n";
					$code .= "  var thisID = 'content_'+container+'_'+number+'_'+type+'_'+typenumber;\n";
					$code .= "  eval(\"var a = document.getElementById('\" + thisID + \"');\");\n";
					$code .= "  var str = '';\n";
					$code .= "  var aContent = a.innerHTML;\n";
					$code .= "  var datas=a.id.split(\"_\");\n";
					$code .= "  str += datas[1] +'*x|*'+datas[2]+'*x|*'+datas[3]+'*x|*'+datas[4]+'*x|*' + aContent + '*x||*';\n";

					$code .= "  eval('document.editform_'+container+'_'+number+'_'+type+'_'+typenumber+'.data.value=str');\n";
					$code .= "  eval('document.editform_'+container+'_'+number+'_'+type+'_'+typenumber+'.submit()');\n";
					$code .= "}\n";
					$code .= "//-->\n";
					$code .= "</script>\n";
					$code .= "<div id=\"popmenu\" name=\"popmenu\" onMouseOver=\"clearhidemenu();highlightmenu(event,'on')\" onMouseOut=\"highlightmenu(event,'off');dynamichide(event)\"></div>\n";
					$code .= "<!--END head//-->\n";
					$search[] = $dedi_mod['container']['full_tag'];
					$replace[] = $code;

				// Seitenkonfigurationslayer?
				} elseif ($dedi_mod['container']['type'] == 'config') {
					$search[] = $dedi_mod['container']['full_tag'];
					$replace[] = '<?PHP if ($dedi_side[\'view\']) echo $con_side[$idcatside][\'config\']; ?>';
				} else {
					unset($code);
					unset($config);
					unset($output);

					// darf Modul bearbeitet werden? Seitencontent darf bearbeitet werden
					if ($container[$dedi_mod['container']['id']]['2'] == '0' && isset($idcatside) && $dedi_side['view'] == 'edit') $dedi_side['edit'] = 'true';
					else unset($dedi_side['edit']);

					// darf Modul gesehen werden? Modul ist aktiviert
					if ($container[$dedi_mod['container']['id']]['1'] == '0') {
						// Container konfigurieren
						$code = $container[$dedi_mod['container']['id']]['4'];
						$config = preg_split('/&/', $container[$dedi_mod['container']['id']]['0']);
						foreach ($config as $key1 => $value1) {
							$tmp2 = explode('=', $value1);
							if ($tmp2['1'] != '') {
								// $mod_value Array schreiben
								$dedi_mod['value'][$tmp2['0']] = dedi_stripslashes(urldecode($tmp2['1']));
								// MOD_VALUE[x] ersetzen
								$code = str_replace('MOD_VALUE['.$tmp2['0'].']', str_replace("\'","'", urldecode($tmp2['1'])), $code);
							}
							unset($tmp2);
						}

						// nicht benutzte Variablen strippen
						$code = preg_replace('/MOD_VALUE\[\d*\]/', '', $code);//'

						$code = str_replace('<DEDIPHP:CACHE>', '<?PHP ', $code);
						$code = str_replace('</DEDIPHP:CACHE>', ' ?>', $code);

						//Im tagmode stripslashes im modul ausführen
						if( stristr ($code, '<dedi:mod constant="tagmode" />') ){
							$code = str_replace('<dedi:mod constant="tagmode" />', '', $code);
							$code = dedi_stripslashes($code);
						}

						// Das Modul existiert noch nicht in der Datenbank
						if (!is_array($content[$dedi_mod['container']['id']])) $content[$dedi_mod['container']['id']]['1'] = 'neu';

						// Alle MOD_TAGS[] im Container ersetzen
						$used_type = extract_dedi_tags($code);

						// alle Module in einem Container generieren
						foreach ($content[$dedi_mod['container']['id']] as $key3 => $value3) {
							// letztes Modul in diesem Container?
							if (!$content[$dedi_mod['container']['id']][$key3+1]) {
								$dedi_mod['modul']['lastentry'] = 'true';
								$pre_container_code = '<?php $dedi_mod[\'modul\'][\'lastentry\']=\'true\'; ?>';
							} else {
								unset($dedi_mod['modul']['lastentry']);
								$pre_container_code = '<?php unset($dedi_mod[\'modul\'][\'lastentry\']); ?>';
							}

							// erstes Modul generieren?
							if ($key3 == '1') {
								$container_code = $code;
								if (is_array($used_type)) {
									// DEDI-TAG in Funktionsaufruf umwandeln
									foreach ($used_type as $value4) {
										// DEDI-TAG Konfiguration auslesen
										// Darf Modul erstellt werden?
										$dedi_type_config = '\'';

										// letztes Modul in diesem Container?
										foreach ($value4 as $key5=>$value5) if ($key5 != 'type' && $key5 != 'id' && $key5 != 'full_tag') $dedi_type_config .= '\''.$key5.'\'=>\''.str_replace('\"','"', dedi_addslashes($value5)).'\',';

										// letztes Komma entfernen
										$dedi_type_config = substr ($dedi_type_config,  1, -1);

										// Filemanagerklasse für Bildformatierung laden
										$to_eval ='$check_type_config = array('.$dedi_type_config.');';
										eval($to_eval);
										if($check_type_config['autoresize'] == 'true' && ! is_object($fm)){
											$this_dir = $dedi_path;
											include_once ($dedi_path.'inc/class.querybuilder_factory.php');
											include_once ($dedi_path.'inc/class.filemanager.php');
											include_once ($dedi_path.'inc/class.fileaccess.php');
											include_once ($dedi_path.'inc/class.fileaddon.php');
											$db_query = &new querybuilder_factory();
											$db_query = $db_query -> get_db($db, 'dedi_db', $this_dir.'inc/');
											$fm = &new filemanager();
										}
										if (!$value4['id']) $value4['id'] = '0';
										if (!is_integer($value4['id'])) {
											if (function_exists('type_output_'.strtolower($value4['type']))) {
												if ($value4['addslashes'] == 'true'){
													//bb testing please dont delete
													//$container_code = 'if(! function_exists(\'type_output_'.strtolower($value4['type']).'\'){'."\n";;
													//$container_code .=      'include_once(\''.$dedi_path.'inc/fnc.type.php\');'."\n";;
													//$container_code .= '}'."\n";
													$container_code = str_replace($value4['full_tag'], 'type_output_'.strtolower($value4['type']).'('.$dedi_mod['container']['id'].', $dedi_mod[\'modul\'][\'id\'], '.$value4['id'].', array('.$dedi_type_config.'))', $container_code);
												}
												else{
													$container_code = str_replace($value4['full_tag'], '<?PHP echo type_output_'.strtolower($value4['type']).'('.$dedi_mod['container']['id'].', $dedi_mod[\'modul\'][\'id\'], '.$value4['id'].', array('.$dedi_type_config.')); ?>', $container_code);
												}
											} else $container_code = $mod_lang['err_type'].$container_code;
										} else $container_code = $mod_lang['err_id'].$container_code;
									}
								}

								// Modul cachen
								eval('$dedi_mod[\'modul\'][\'id\'] = $key3;$dedi_mod[\'key\'] = \'mod\'.$dedi_mod[\'container\'][\'id\'].\'_\'.$key3.\'_\'; ?>'.$pre_container_code.$container_code);
								$container_code_final = ob_get_contents ();
								ob_end_clean ();
								ob_start();
								$output = '<?php $dedi_mod[\'modul\'][\'id\']=\''.$key3.'\';$dedi_mod[\'key\'] = \'mod\'.$dedi_mod[\'container\'][\'id\'].\'_\'.$key3.\'_\'; ?>'.$pre_container_code.$container_code_final;

							// alle weiteren Module dranhängen
							} else {
								// Modul cachen
								eval('$dedi_mod[\'modul\'][\'id\'] = $key3;$dedi_mod[\'key\'] = \'mod\'.$dedi_mod[\'container\'][\'id\'].\'_\'.$key3.\'_\'; ?>'.$pre_container_code.$container_code);
								$container_code_final = ob_get_contents ();
								ob_end_clean ();
								ob_start();
	                                                       	$output .= '<?php $dedi_mod[\'modul\'][\'id\']=\''.$key3.'\';$dedi_mod[\'key\'] = \'mod\'.$dedi_mod[\'container\'][\'id\'].\'_\'.$key3.\'_\'; ?>'.$pre_container_code.$container_code_final;
							}
						}

						// Container in Array schreiben
						$search[] = $dedi_mod['container']['full_tag'];
						if (!$dedi_side['edit']) $replace[] = '<!--START '.$dedi_mod['container']['id'].'//--><?php unset($dedi_side[\'edit\']); $dedi_mod[\'container\'][\'id\']=\''.$dedi_mod['container']['id'].'\'; ?>'.$output.'<!--END '.$dedi_mod['container']['id'].'//-->';
						else $replace[] = '<!--START '.$dedi_mod['container']['id'].'//--><?php $dedi_side[\'edit\']=\'true\'; $dedi_mod[\'container\'][\'id\']=\''.$dedi_mod['container']['id'].'\'; ?>'.$output.'<!--END '.$dedi_mod['container']['id'].'//-->';
						unset($output);
						unset($used_type, $dedi_mod['value']);
					} else {
						// Modul ist nicht sichtbar
						$search[] = $dedi_mod['container']['full_tag'];
						$replace[] = '';
					}
				}
			}

			// Seite erstellen
			$code = $layout;
			foreach ($search as $key=>$value) $code = str_replace($value, $replace[$key], $code);
		} else $code = $layout;
	} else $code = $dedi_lang['con_notemplate'];

	// Dynamisches PHP beibehalten
	$code = str_replace('<DEDIPHP>', '<?PHP ', $code);
	$code = str_replace('</DEDIPHP>', ' ?>', $code);
}
?>