<?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	2006-04-11

 THIS IS A MODIFIED VERSION
 ALL MODIFICATIONS ARE INSERTIONS ONLY !!!
 INSERTIONS ARE MARKED WITH "// MODIFICATION START" & "// MODIFICATION END"
******************************************************************************/
if (!defined('IS_DEDI')) die();
include_once($dedi_path.'inc/fnc.type_common.php');

// MODIFICATION START
//
// tinymce include
$tinymce_flag=false;
$tinyinclude=$dedi_path.'inc/fnc.type_forms.tinymce.php';
if (file_exists($tinyinclude)) {
	include_once($tinyinclude);
	$tinymce_flag=true;
}
// treeview include
$treeview_flag=false;
$treeviewinclude=$dedi_path.'inc/fnc.type_forms.treeview.php';
if (file_exists($treeviewinclude)) {
	include_once($treeviewinclude);
	$treeview_flag=true;
}
//
// MODIFICATION END

/**
 * Returns a HTML-hiddenfield
 *
 * @Args: formname -> name of the inputfield
 *        content -> value of textfield
 * @Return String HTML hiddenfield
 * @Access private
 */
if (!is_object($perm)) die();
function _type_get_element_hidden($formname, $content)
{
        return '<input type="hidden" name="'. $formname .'" value="'. $content .'">';
}



/**
 * Returns a HTML-textfield
 *
 * @Args: formname -> name of the inputfield
 *        content -> value of textfield
 *        width
 *        maxlength
 * @Return String HTML textfield
 * @Access private
 */
function _type_get_element_text($formname, $content, $width, $maxlength) {
        $width = ( empty($width) ) ? '640px': $width;
        $maxlength = ( empty($maxlength) ) ? '': ' maxlength ="'. $maxlength .'" ';

        $out = '<input type="text" name="'. $formname .'" value="'. $content . '" size="90" style="width:' . $width . '" '. $maxlength .'>'."\n";
        return $out;
}



/**
 * Returns complete formatted HTML-textfield
 *
 * @Args: formname -> name of the inputfield
 *        content -> value of textfield
 *        type_config -> array with values from the DEDI:tag
 *        dedi_side['view'] -> the current view of the user, 'edit' or 'preview'
 *                 ['edit'] -> 'true' if user set the mod in templateconfig as active
 *                             if user set inactiv var is not set
 * @Return String HTML textfield
 * @Access public
 */
function type_form_text($formname, $content, $type_config, $dedi_side) {
        $content = type_form_dedilinks_to_templinks($content);
        if (! _type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'])) return _type_get_element_hidden($formname, $content);
        else {
                $width = $type_config['width'];
                $maxlength = $type_config['maxlength'];
                $out = '<td class="content">'."\n"._type_get_element_text($formname, $content, $width, $maxlength)."\n</td>\n";
        }
        return $out;
}


/**
 * Returns complete formatted HTML-textareafield
 *
 * @Args: formname -> name of the inputfield
 *        content -> value of textfield
 *        type_config -> array with values from the DEDI:tag
 *        dedi_side['view'] -> the current view of the user, 'edit' or 'preview'
 *                 ['edit'] -> 'true' if user set the mod in templateconfig as active
 *                             if user set inactiv var is not set
 * @Return String HTML textareafield
 * @Access public
 */
function type_form_textarea($formname, $content, $type_config, $dedi_side) {
        global  $cfg_dedi, $cfg_client, $sess, $bbcodehead_printed;

        $n = ''; $v = '';

        $content = type_form_dedilinks_to_templinks($content);
        if (!_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'])) return _type_get_element_hidden($formname, $content);
        $width = $type_config['width'];
        $width = ( empty($width) ) ? '640px': $width;
        $height = $type_config['height'];
        $height = ( empty($height) ) ? '200px': $height;

        $s = '<td class="content">';

        $features = array();
        if (!empty($type_config['features']) && $type_config['features'] != 'true') {
                $features = explode(',', $type_config['features']);
                $features = array_map('trim', $features);
        }

        $fonts = array();
        if (!empty($type_config['fonts'])) {
                $fontsstring = str_replace('  ', ' ', $type_config['fonts']);
                $fonts = explode(',', $fontsstring);
                $fonts = array_map('trim', $fonts);
        }

        $classes = array(); $classespre = array();
        if (!empty($type_config['classes'])) {
                $classesstring = str_replace('  ', ' ', $type_config['classes']);
                $classespre = explode(',', $classesstring);
                foreach($classespre as $v) {
                        list($n, $v) = explode('=', $v, 2);
                        $n = trim($n); $v = trim($v);
                        $classes[$n]= $v;
                }
        }
		if (!empty($type_config['classids'])) {
			//$style_array = _type_get_stylelist($type_config['classids']);
			$classidsstring = str_replace('  ', ' ', $type_config['classids']);
			$classidspre = explode(',', $classidsstring);
			foreach($classidspre as $v) {
				$classes[$v] = '.' . $v;
			}
		}

        $sizemin = (int)$type_config['sizemin'];
        $sizemin = (empty($sizemin)) ? 75 : $sizemin;
        $sizemax = (int)$type_config['sizemax'];
        $sizemax = (empty($sizemax)) ? 125 : $sizemax;

        // Wenn $type_config tatsächlich _garkein_ Element enthält (nochnichtmal id),
        // dann stimmt etwas nicht. Das passiert z.B. im DeDiFlex, da dort die IDs
        // dynamisch vergeben werden. In diesem Fall werden die Knöpfe mal
        // provisorisch ausgegeben, man weiß ja nie. Ist dies nicht erwünscht, einfach
        // die folgenden Zeile auskommentieren udn die drauf mit einem // versehen
        //if ($type_config['transform'] == 'bbcode') {
        if ($type_config['transform'] == 'bbcode' || count($type_config) == 0) {
                if(!$bbcodehead_printed) {
                        $bbcodehead_printed = true;
                        //print('$cfg_dedi: '); print_r($cfg_dedi);
                        //print('$cfg_client: '); print_r($cfg_client);

                        $s .= '
<script type="text/javascript" src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/bbcode.js') . '"></script>
<script type="text/javascript">
  var dedipath = \'' . $cfg_dedi['dedi_html_path'] . '\';
  var dedisess = \'' . $sess->id . '\';
  var frontendfile = \'' . $cfg_client['htmlpath'].$cfg_client['contentfile'] . '\';
  var allowclasses = ' . ((in_array('class', $features) || empty($type_config['features']) || $type_config['features'] == "true") ? 'true' : 'false') . ';
</script>
<style type="text/css">
.bbcodeform {
  margin: 0px;
}

.bbcodeform a {
  border: 1px outset #D0D7E3;
  background-color: #D0D7E3;
  display: block;
}

.bbcodeform a:hover {
  border-style: inset;
}

.bbcodeform a img {
  border-style: none;
}
</style>';
                }

$s .= '
<table class="bbcodeform"><tbody><tr>';
if(in_array('bold', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'b\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/bold.gif') . '" alt="Fett" title="Text Fett formatieren" />
  </a></td>';
if(in_array('italic', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'i\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/italic.gif') . '" alt="Kursiv" title="Text Kursiv formatieren" />
  </a></td>';
if(in_array('underline', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'u\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/underline.gif') . '" alt="Unterstrichen" title="Text Unterstrichen formatieren" />
  </a></td>';
if(in_array('strike', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'s\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/strike.gif') . '" alt="Durchgestrichen" title="Text Durchgestrichen formatieren" />
  </a></td>';
if(in_array('size', $features) || empty($type_config['features']) || $type_config['features'] == "true") {
  $s .= '
  <td><select style="font-weight: bold; font-size: 100%" name="size" id="size" onchange="bbcode(\'size\', \'' . $formname . '\', this);">
    <option style="font-style: italic;" value="">&gt; Gr&ouml;&szlig;e &lt;</option>' . "\n";
    for($n = $sizemin; $n <= $sizemax; $n=$n+5) {
      $s .= '    <option value="' . $n . '">' . $n . '%</option>' . "\n";
    }
  $s .= '  </select></td>';
}
if((in_array('font', $features) || empty($type_config['features']) || $type_config['features'] == "true") && count($fonts)) { $s .= '
  <td><select style="font-weight: bold; font-size: 100%" onchange="bbcode(\'font\', \'' . $formname . '\', this);">
    <option style="font-style: italic;" value="">&gt; Schriftart &lt;</option>' . "\n";
  foreach($fonts as $v) {
    $s .= '    <option style="font-family: \'' . htmlspecialchars($v) . '\';">' . htmlspecialchars($v) ."</option>\n";
  }
  $s .= '  </select></td>';
}
if((in_array('class', $features) || in_array('stylebox', $features) || empty($type_config['features']) || $type_config['features'] == "true") && count($classes)) { $s .= '
  <td><select id="classes" style="font-weight: bold; font-size: 100%" onchange="bbcode(\'class\', \'' . $formname . '\', this);">
    <option style="font-style: italic;" value="">&gt; Klasse &lt;</option>' . "\n";
  foreach($classes as $n => $v) {
    $s .= '    <option value="' . htmlspecialchars($n) . '">' . htmlspecialchars($v) . "</option>\n";
  }
  $s .= '  </select></td>';
}
if(((in_array('stylebox', $features) && in_array('class', $features)) || empty($type_config['features']) || $type_config['features'] == "true") && count($classes)) { $s .= '
  <td><input type="checkbox" id="stylebox" onclick="bbcode(\'stylebox\', \'' . $formname . '\', this);" /></td>';
}
if(in_array('sub', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'sub\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/sub.gif') . '" alt="Tiefgestellt" title="Text Tiefgestellt formatieren" />
  </a></td>';
if(in_array('sup', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'sup\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/sup.gif') . '" alt="Hochgestellt" title="Text Hochgestellt formatieren" />
  </a></td>';
if(in_array('forecol', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'forecol\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/forecol.gif') . '" alt="Textfarbe" title="Textfarbe w&auml;hlen" />
  </a></td>';
if(in_array('backcol', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'backcol\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/backcol.gif') . '" alt="Hintergrundfarbe" title="Hintergrundfarbe w&auml;hlen" />
  </a></td>';
if(in_array('email', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'email\', \'' . $formname . '\', \'notext=' . ($type_config['notext'] == 'true' ? '1' : '0') . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/mail.gif') . '" alt="EMail" title="EMail einf&uuml;gen" />
  </a></td>';
$feat_anchor = (in_array('anchor', $features) && in_array('link', $features)) || empty($type_config['features']) || $type_config['features'] == "true";
if($feat_anchor) $s .= '
  <td><a href="#" onclick="bbcode(\'anchor\', \'' . $formname . '\', \'notext=' . ($type_config['notext'] == 'true' ? '1' : '0') . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/anchor.gif') . '" alt="Anker" title="Anker einf&uuml;gen" />
  </a></td>';
if(in_array('link', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'link\', \'' . $formname . '\', \'notarget=' . ($type_config['notarget'] == 'true' ? '1' : '0') . '&anchor=' . ($feat_anchor ? '1' : '0') . '&notext=' . ($type_config['notext'] == 'true' ? '1' : '0') . '&external=' . ($type_config['external'] == 'false' ? '0' : '1') . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/link.gif') . '" alt="Link" title="Link einf&uuml;gen" />
  </a></td>';
if(in_array('filelink', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'filelink\', \'' . $formname . '\', \'notext=' . ($type_config['notext'] == 'true' ? '1' : '0') . '&filefolders=' . urlencode($type_config['filefolders']) . '&filesubfolders=' . ($type_config['filesubfolders'] == 'false' ? '0' : '1') . '&filefiletypes=' . urlencode($type_config['filefiletypes']) . '&filefiletypeids=' . urlencode($type_config['filefiletypeids']) . '&filefolderids=' . urlencode($type_config['filefolderids']) . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/filelink.gif') . '" alt="Dateilink" title="Dateilink einf&uuml;gen" />
  </a></td>';
if(in_array('list', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'list\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/list.gif') . '" alt="Liste" title="Liste einf&uuml;gen" />
  </a></td>';
if(in_array('code', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'code\', \'' . $formname . '\', \'php=' . ($type_config['phpformat'] == 'true' ? '1' : '0') . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/code.gif') . '" alt="Code" title="Code einf&uuml;gen" />
  </a></td>';
if((in_array('code', $features) && $type_config['phpformat'] == 'true') || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'phpcode\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/phpcode.gif') . '" alt="Code" title="PHP-Code einf&uuml;gen" />
  </a></td>';
if(in_array('img', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'img\', \'' . $formname . '\', \'imgfolders=' . urlencode($type_config['imgfolders']) . '&imgsubfolders=' . ($type_config['imgsubfolders'] == 'false' ? '0' : '1') . '&imgfiletypes=' . urlencode($type_config['imgfiletypes']) . '&imgfiletypeids=' . urlencode($type_config['imgfiletypeids']) . '&imgfolderids=' . urlencode($type_config['imgfolderids']) . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/img.gif') . '" alt="Bild" title="Bild einf&uuml;gen" />
  </a></td>';
if(in_array('hr', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'hr\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/hr.gif') . '" alt="Horizontale Linie" title="Eine Horizontale Linie einf&uuml;gen" />
  </a></td>';
if((in_array('br', $features) || empty($type_config['features']) || ($type_config['features'] == "true")) && ($type_config['paragraphs'] == 'p')) $s .= '
  <td><a href="#" onclick="bbcode(\'br\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/br.gif') . '" alt="Zeilenumbruch" title="Einen Zeilenumbruch einf&uuml;gen" />
  </a></td>';
if(in_array('abbr', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'abbr\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/abbr.gif') . '" alt="Abk&uuml;rzung" title="Eine Abk&uuml;rzung einf&uuml;gen" />
  </a></td>';
if(in_array('acronym', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'acronym\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/acronym.gif') . '" alt="Kurzwort" title="Ein Kurzwort (Akronym) einf&uuml;gen" />
  </a></td>';
if(in_array('footnote', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'footnote\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/footnote.gif') . '" alt="Fu&szlig;note" title="Eine Fu&szlig;note einf&uuml;gen" />
  </a></td>';
if(in_array('source', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'source\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/source.gif') . '" alt="Quellcode" title="HTML-Quellcode direkt eingeben" />
  </a></td>';
if(in_array('table', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'table\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/table.gif') . '" alt="Tabelle einf&uuml;gen" title="Tabelle einf&uuml;gen" />
  </a></td>';
if(in_array('striptags', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'striptags\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/striptags.gif') . '" alt="Tags entfernen" title="bbCode-Tags entfernen" />
  </a></td>';
if(in_array('charmap', $features) || empty($type_config['features']) || $type_config['features'] == "true") $s .= '
  <td><a href="#" onclick="bbcode(\'charmap\', \'' . $formname . '\');">
    <img src="' . $sess->url($cfg_dedi['dedi_html_path'] . 'external/bbcode/img/charmap.gif') . '" alt="Sonderzeichen" title="Sonderzeichen einf&uuml;gen" />
  </a></td>';
$s .= '
</table>';
        }
	$s .= '<textarea id="text" name="'. $formname . '" rows="14" cols="52" style="width:'.$width.';height:'.$height.'">'. $content ."</textarea>\n</td>\n";
        return $s;
}


/**
 * Returns complete WYSIWYG-field for IE or JAVA
 *
 * @Args: formname -> name of the inputfield
 *        content -> value of textfield
 *        type_config -> array with values from the DEDI:tag
 *        dedi_side['view'] -> the current view of the user, 'edit' or 'preview'
 *                 ['edit'] -> 'true' if user set the mod in templateconfig as active
 *                             if user set inactiv var is not set
 * @Return String HTML textareafield
 * @Access public
 */
function type_form_wysiwyg($formname, $content, $type_config) {
        global $db, $dedi_db, $dedi_lang, $client, $cfg_dedi, $cfg_client, $tmp_sniffer;

// MODIFICATION START
//
global $tinymce_flag;
if ($tinymce_flag==true && ($cfg_client['wysiwyg_applet']=='4' ||  $cfg_client['wysiwyg_applet']=='5'))
	$out=_type_form_tinymce($formname, $content, $type_config);
else {
//
// MODIFICATION END

        // Wenn kein ie > 5.5 oder applet ist immer sichtbar
        if (($tmp_sniffer['18'] != 'true' && $cfg_client['wysiwyg_applet'] == '1') || $cfg_client['wysiwyg_applet'] == '2') $out = _type_form_wysiwyg_java($formname, $content, $type_config);
        else $out = _type_form_wysiwyg_ie($formname, $content, $type_config);

// MODIFICATION START
//
}
//
// MODIFICATION END

        return $out;
}

function type_form_wysiwyg2($formname, $content, $type_config) {
        global $db, $dedi_db, $dedi_lang, $client, $cfg_dedi, $cfg_client, $tmp_sniffer;

// MODIFICATION START
//
global $tinymce_flag;
if ($tinymce_flag==true && ($cfg_client['wysiwyg_applet']=='4' ||  $cfg_client['wysiwyg_applet']=='5'))
	$out=_type_form_tinymce($formname, $content, $type_config);
else {
//
// MODIFICATION END

        // Wenn kein ie > 5.5 oder applet ist immer sichtbar
        if (($tmp_sniffer['18'] != 'true' && $cfg_client['wysiwyg_applet'] == '1') || $cfg_client['wysiwyg_applet'] == '2') $out = _type_form_wysiwyg_java($formname, $content, $type_config);
        elseif ($cfg_client['wysiwyg_applet'] == '3') $out = _type_form_wysiwyg_ie3($formname, $content, $type_config);
        else $out = _type_form_wysiwyg_ie2($formname, $content, $type_config);

// MODIFICATION START
//
}
//
// MODIFICATION END

        return $out;
}



function _type_form_wysiwyg_ie($formname, $content, $type_config) {
        global $dedi_lang, $client, $cfg_dedi, $cfg_client, $sess;

        $content = type_form_dedilinks_to_templinks($content);

        $out = '<script language="Javascript1.2" src="'.$sess->url($cfg_dedi['dedi_html_path'].'external/wysiwyg/wysiwyg.php').'"></script>'."\n";
        $out .= "    <td class=\"content\"><textarea name=\"$formname\" rows=\"20\" cols=\"52\" style=\"width:640\">$content</textarea></td>\n";
        //<a href="javascript:editor_insertHTML('box2','<font style=\'background-color: yellow\'>','</font>');">Highlight selected text</a> -
        $out .= '<script language="javascript1.2">'."\n";
        $out .= "if(document.all) fasteditor_generate('".$formname."');\n";
        $out .= '</script>'."\n";

        return $out;
}

function _type_form_wysiwyg_ie2($formname, $content, $type_config) {
        global $dedi_lang, $client, $lang, $dedi, $cfg_dedi, $cfg_client, $sess;

        $content = type_form_dedilinks_to_templinks($content);

        $out  = '<script language="Javascript1.2" src="'.$sess->url($cfg_dedi['dedi_html_path'].'external/wysiwyg/wysiwyg2.php').'"></script>'."\n";
        $out .= '<script>'."\n";

        // Konfigurationsarray schreiben
        $out .= $formname.'_conf = new Array();'."\n";

        // Toolbar
        if (!empty($type_config['features']) && $type_config['features'] != 'true') {
                $featurestring = str_replace(' ', '', strtolower($type_config['features']) );
                $features = explode(',', $featurestring );
                $out .= _type_form_wysiwyg_ie2_build_menu($formname.'_conf["toolbar"]', $features, $type_config['selectablestyles']);
        }

        // Mögliche Schriftarten
        if (!empty($type_config['selectablestyles'])) {
                $style_array = _type_get_stylelist($type_config['selectablestyles']);
                $c = count($style_array);
                if ($c > 0) {
                        for($i=0; $i<$c; $i++) $jsstyle .= '{ name: "'. $style_array[$i]['autodesc'] .'", className: "'. $style_array[$i]['name'] .'", classStyle: "'. $style_array[$i]['style'] .'" },' . "\n";
                        $jsstyle .= '{ name: "Styleangabe entfernen", className: "remove", classStyle: "" }';
                        $out .= $formname."_conf['fontstyles'] = [".$jsstyle."];";
                }
        }

        // Parameter für Bildimport
        $out .= ($type_config['imagefiletypes'] == 'true' || empty($type_config['imagefiletypes'])) ? $formname."_conf['imagefiletypes'] = 'jpg,gif,png,jpeg';\n" : $formname."_conf['imagefiletypes'] = '".$type_config['imagefiletypes']."';\n";
        $out .= ($type_config['imagefolders'] == 'true' || empty($type_config['imagefolders'])) ? $formname."_conf['imagefolders'] = 'true';\n" : $formname."_conf['imagefolders'] = '".$type_config['imagefolders']."';\n";
        $out .= ($type_config['imagesubfolders'] == 'true') ? $formname."_conf['imagesubfolders'] = 'true';\n" : $formname."_conf['imagesubfolders'] = 'false';\n";

        // Parameter für Dateilinks
        $out .= ($type_config['filefiletypes'] == 'true' || empty($type_config['filefiletypes'])) ? $formname."_conf['filefiletypes'] = 'true';\n" : $formname."_conf['filefiletypes'] = '".$type_config['filefiletypes']."';\n";
        $out .= ($type_config['filefolders'] == 'true' || empty($type_config['filefolders'])) ? $formname."_conf['filefolders'] = 'true';\n" : $formname."_conf['filefolders'] = '".$type_config['filefolders']."';\n";
        $out .= ($type_config['filesubfolders'] == 'true') ? $formname."_conf['filesubfolders'] = 'true';\n" : $formname."_conf['filesubfolders'] = 'false';\n";

        // Style für den Editor
        $stylesheet = _type_get_stylesheet();
        if ($stylesheet != '') $out .= $formname."_conf['stylesheet'] = '".str_replace("\'","'", dedi_addslashes($stylesheet))."';";//'
        $css = _type_get_style($type_config['styleclass'], $type_config['styleid'], $type_config['styledb']);
        if (!empty($css['type'])) $out .= $formname."_conf['style'] = '".$css['fullstyle']."';";
        $out .= '</script>'."\n";

        // Textfeld erstellen
        $out .= "    <td class=\"content\"><textarea name=\"$formname\" rows=\"20\" cols=\"52\" style=\"width:640\">$content</textarea></td>\n";

        // Editor generieren
        $out .= '<script language="javascript1.2">'."\n";
        $out .= "if(document.all) editor_generate('$formname');\n";
        $out .= '</script>'."\n";
        return $out;
}

function _type_form_wysiwyg_ie3($formname, $content, $type_config) {
        global $dedi_lang, $client, $lang, $dedi, $cfg_dedi, $cfg_client, $sess;
        $features = array();
        $content = type_form_dedilinks_to_templinks($content);

  $out = '<script>_editor_url = "'.$cfg_dedi['dedi_html_path'].'external/wysiwyg/";';
  $out .= '_editor_lang = "de";</script>';
  $out .= '<script language="Javascript1.2" src="'.$sess->url($cfg_dedi['dedi_html_path'].'external/wysiwyg/wysiwyg3.php').'"></script>'."\n";
        $out .= '<script>'."\n";
  $out .= 'if(typeof(HTMLArea.I18N) != "object") {location.reload(); };';
  $out .= 'HTMLArea.loadPlugin("ContextMenu");'."\n".'HTMLArea.loadPlugin("TableOperations");'."\n".'HTMLArea.loadPlugin("CSS");'."var testcount = 0;\n";
  $out .= 'function init_'.$formname."() {\n";
  $out .= 'if(typeof(ContextMenu) != "function" || typeof(TableOperations) != "function" || typeof(CSS) != "function" ){testcount++; setTimeout("init_'.$formname.'()",20); } else { '."\n";
  $out .= 'document.getElementById("'.$formname.'").style.visibility="visible";';
  $out .= 'var '.$formname.' = new HTMLArea("'.$formname.'");'."\n";

        // Toolbar
        if (!empty($type_config['features']) && $type_config['features'] != 'true') {
                $featurestring = str_replace(' ', '', strtolower($type_config['features']) );
                $features = explode(',', $featurestring );
                $out .= _type_form_wysiwyg_ie3_build_menu($formname.'.config.toolbar', $features, $type_config['selectablestyles']);
        }

        // Style für den Editor
        $stylesheet = _type_get_stylesheet();
        if ($stylesheet != '') {
                $stylesheet = preg_replace('/^.*?href=\\"(.*?)\\".*$/',"\\1",$stylesheet);
                $out .= "$formname.config.pageStyle = \"@import url('$stylesheet');\";\n";
        };
        // Parameter für Bildimport
        $out .= ($type_config['imagefiletypes'] == 'true' || empty($type_config['imagefiletypes'])) ? $formname.".config.imagefiletypes = 'jpg,gif,png,jpeg';\n" : $formname.".config.imagefiletypes = '".$type_config['imagefiletypes']."';\n";
        $out .= ($type_config['imagefolders'] == 'true' || empty($type_config['imagefolders'])) ? $formname.".config.imagefolders = 'true';\n" : $formname.".config.imagefolders = '".$type_config['imagefolders']."';\n";
        $out .= ($type_config['imagesubfolders'] == 'true') ? $formname.".config.imagesubfolders = 'true';\n" : $formname.".config.imagesubfolders = 'false';\n";

        // Parameter für Dateilinks
        $out .= ($type_config['filefiletypes'] == 'true' || empty($type_config['filefiletypes'])) ? $formname.".config.filefiletypes = 'true';\n" : $formname.".config.filefiletypes = '".$type_config['filefiletypes']."';\n";
        $out .= ($type_config['filefolders'] == 'true' || empty($type_config['filefolders'])) ? $formname.".config.filefolders = 'true';\n" : $formname.".config.filefolders = '".$type_config['filefolders']."';\n";
        $out .= ($type_config['filesubfolders'] == 'true') ? $formname.".config.filesubfolders = 'true';\n" : $formname.".config.filesubfolders = 'false';\n";

  // Context-Plugin
  $out .= "$formname.registerPlugin(ContextMenu);\n";
  // Table-Plugin
  if (in_array('table', $features) || empty($type_config['features']) || $type_config['features'] == "true") $out .= "$formname.registerPlugin(TableOperations);\n";
        // CSS-Plugin
        if (!empty($type_config['selectablestyles'])) {
                $style_array = _type_get_stylelist($type_config['selectablestyles']);
                $c = count($style_array);
                if ($c > 0) {
                        $jsstyle[] .= '"Styleangabe entfernen" : ""';
                        for($i=0; $i<$c; $i++) $jsstyle[] .= '"'.$style_array[$i]['autodesc'] .'" : "'. $style_array[$i]['name'] .'"';
                        $out .= "$formname.registerPlugin(CSS, {combos : [ { options: {\n\t";
                        $out .= implode(",\n\t",$jsstyle)."\n\t}\n}]\n});\n";
                }
        }

  $out .= "\n$formname.generate();}; };\nSafeAddOnload(init_$formname);";
        $out .= '</script>'."\n";

        // Textfeld erstellen
        $out .= "    <td class=\"content\" style=\"background:url('http://localhost/dedi1_0/backend/tpl/standard/img/wysiwyg3/loading.gif') no-repeat center #FFFFFF;\"><textarea id=\"$formname\" name=\"$formname\" rows=\"20\" cols=\"52\" style=\"width:640; visibility:hidden;\">$content</textarea></td>\n";
        return $out;
}

function _type_form_wysiwyg_ie3_build_menu($editor_conf_name, $features, $selectablestyles) {
        // 1. Zeile
        if (in_array('clipboardtools', $features)) $sub[] .= "'cut','copy','paste'";
        if (in_array('striptag', $features)) $sub[] .= "'remove'";
        if (in_array('undo', $features)) $sub[] .= "'undo','redo'";
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub).',"separator"';
        unset($sub);
        if (in_array('liveresize', $features)) $sub[] .= "'liveresize'";
        if (in_array('multipleselect', $features)) $sub[] .= "'multipleselect'";
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub).',"separator"';
        unset($sub);
        if (in_array('subscript', $features)) $sub[] .= "'subscript'";
        if (in_array('superscript', $features)) $sub[] .= "'superscript'";
        if (in_array('indent', $features)) $sub[] .= "'lefttoright','righttoleft'";
        if (in_array('changecase', $features)) $sub[] .= "'changecase'";
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub).',"separator"';
        unset($sub);
        if (in_array('search', $features)) $sub[] .= "'find'";
        if (in_array('changemode', $features)) $sub[] .= "'htmlmode'";
        if (in_array('popupeditor', $features)) $sub[] .= "'popupeditor'";
        //if (in_array('reset', $features)) $sub[] .= "'refresh'";
  // end of Line 1
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub);
        if (count($blocks) > 0) $row1 .= '['.implode(', ',$blocks)."],\n";
        unset($blocks); unset($sub);

        // 2. Zeile
        if (in_array('align', $features) ) $sub[] .= "'justifyleft','justifycenter','justifyright','justifyfull'";
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub).',"separator"';
        unset($sub);
        if (in_array('list', $features)) $sub[] .= "'insertorderedlist','insertunorderedlist'";
        if (in_array('indent', $features)) $sub[] .= "'outdent','indent'";
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub).',"separator"';
        unset($sub);
        if (in_array('bold', $features)) $sub[] .= "'bold'";
        if (in_array('italic', $features)) $sub[] .= "'italic'";
        if (in_array('underline', $features)) $sub[] .= "'underline'";
        if (in_array('strikethrough', $features)) $sub[] .= "'strikethrough'";
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub).',"separator"';
        unset($sub);
        if (in_array('image', $features)) $sub[] .= "'insertimage'";
        if (in_array('link', $features)) $sub[] .= "'createlink'";
        if (in_array('file', $features)) $sub[] .= "'insertfile'";
        if (in_array('link', $features) || in_array('file', $features)) $sub[] .= "'unlink'";
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub).',"separator"';
        unset($sub);
        if (in_array('hr', $features)) $sub[] .= "'inserthorizontalrule'";
        if (in_array('specialchars', $features)) $sub[] .= "'specchar'";
        if (in_array('date', $features)) $sub[] .= "'today'";
        if (in_array('marquee', $features)) $sub[] .= "'marquee'";
  // End of Line 2
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub);
        if (count($blocks) > 0) $row2 .= '['.implode(', ',$blocks)."],\n";
        unset($blocks); unset($sub);

        // 3. Zeile
        if (in_array('font', $features)) $sub[] .= "'fontname'";
        if (in_array('fontsize', $features)) $sub[] .= "'fontsize'";
        if (in_array('styles', $features)) $sub[] .= "'formatblock'";
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub).',"separator"';
        unset($sub);
        if (in_array('fontcolor', $features)) $sub[] .= "'forecolor'";
        if (in_array('backgroundcolor', $features)) $sub[] .= "'hilitecolor'";
  // End of Line 3
        if (count($sub) > 0) $blocks[] .= implode (', ', $sub);
        if (count($blocks) > 0) $row3 .= '['.implode(', ',$blocks)."],\n";
        unset($blocks); unset($sub);

        //Toolbar zurückgeben
        return "$editor_conf_name = [".$row1.$row2.$row3."];";
}


function _type_form_wysiwyg_ie2_build_menu($editor_conf_name, $features, $selectablestyles) {
        // 1. Zeile
        if (in_array('clipboardtools', $features)) $sub[] .= "'selectall','cut','copy','paste','delete'";
        if (in_array('striptag', $features)) $sub[] .= "'remove'";
        if (in_array('undo', $features)) $sub[] .= "'undo','redo'";
        if (in_array('search', $features)) $sub[] .= "'find'";
        if (in_array('changecase', $features)) $sub[] .= "'changecase'";
        if (count($sub) > 0) $row1 .= '['.implode (', ', $sub)."],\n";
        unset($sub);
        if (in_array('table', $features)) $sub[] .= "'InsertTable','showborder','TableProperties', 'RowProperties','InsertRowBefore','InsertRowAfter','DeleteRow','SplitRow', 'InsertColumnBefore','InsertColumnAfter','DeleteColumn', 'CellProperties','InsertCellBefore','InsertCellAfter','DeleteCell','SplitCell','MergeCells'";
        if (count($sub) > 0) $row1 .= '['.implode (', ', $sub)."],\n";
        unset($sub);
        if (!empty($row1)) $row1 = $row1."['linebreak'],\n";

        // 2. Zeile
        if (in_array('bold', $features)) $sub[] .= "'bold'";
        if (in_array('italic', $features)) $sub[] .= "'italic'";
        if (in_array('underline', $features)) $sub[] .= "'underline'";
        if (in_array('strikethrough', $features)) $sub[] .= "'strikethrough'";
        if (in_array('subscript', $features)) $sub[] .= "'subscript'";
        if (in_array('superscript', $features)) $sub[] .= "'superscript'";
        if (in_array('align', $features) ) $sub[] .= "'justifyleft','justifycenter','justifyright','justifyfull','justifynone'";
        if (count($sub) > 0) $row2 .= '['.implode (', ', $sub)."],\n";
        unset($sub);
        if (in_array('fontcolor', $features)) $sub[] .= "'forecolor'";
        if (in_array('backgroundcolor', $features)) $sub[] .= "'backcolor'";
        if (in_array('list', $features)) $sub[] .= "'OrderedList','UnOrderedList'";
        if (in_array('indent', $features)) $sub[] .= "'Outdent','Indent'";
        if (count($sub) > 0) $row2 .= '['.implode (', ', $sub)."],\n";
        unset($sub);
        if (in_array('link', $features)) $sub[] .= "'insertlink'";
        if (in_array('file', $features)) $sub[] .= "'insertfile'";
        if (in_array('link', $features) || in_array('file', $features)) $sub[] .= "'unlink'";
        if (in_array('image', $features)) $sub[] .= "'InsertImage'";
        if (in_array('liveresize', $features)) $sub[] .= "'liveresize'";
        if (in_array('multipleselect', $features)) $sub[] .= "'multipleselect'";
        if (count($sub) > 0) $row2 .= '['.implode (', ', $sub)."],\n";
        unset($sub);
        if (in_array('hr', $features)) $sub[] .= "'line'";
        if (in_array('specialchars', $features)) $sub[] .= "'specchar'";
        if (in_array('date', $features)) $sub[] .= "'today'";
        if (in_array('marquee', $features)) $sub[] .= "'marquee'";
        if (count($sub) > 0) $row2 .= '['.implode (', ', $sub)."],\n";
        unset($sub);
        if (!empty($row2)) $row2 = $row2."['linebreak'],\n";

        // 3. Zeile
        if (in_array('reset', $features)) $sub[] .= "'refresh'";
        if (in_array('preview', $features)) $sub[] .= "'preview'";
        if (in_array('print', $features)) $sub[] .= "'print'";
        if (count($sub) > 0) $row3 .= '['.implode (', ', $sub)."],\n";
        unset($sub);
//        if (in_array('styles', $features) && !empty($selectablestyles)) $sub[] .= "'fontstyle'";
        if (in_array('styles', $features)) $sub[] .= "'fontstyle'";
        if (in_array('font', $features)) $sub[] .= "'fontname'";
        if (in_array('fontsize', $features)) $sub[] .= "'fontsize'";
        if (count($sub) > 0) $row3 .= '['.implode (', ', $sub)."],\n";
        unset($sub);
        if (in_array('changemode', $features)) $sub[] .= "'htmlmode'";
        if (in_array('popupeditor', $features)) $sub[] .= "'popupeditor'";
        if (count($sub) > 0) $row3 .= '['.implode (', ', $sub)."],\n";
        unset($sub);
        return "$editor_conf_name = [".$row1.$row2.$row3."];";
}

function _type_form_wysiwyg_java($formname, $content, $type_config) {
        global $db, $dedi_db, $idlay, $dedi_lang, $client, $cfg_dedi, $cfg_client, $lang, $sess, $idcatside, $entry;

        // SET DEFAULTS FOR EDITOR APPLET...
        // get stylesheet-files for this page (code taken from project's inc/frontend.php)
        // have to use absolute urls, because stylesheets are not relative to codebase
        $sql = "SELECT C.filetype, D.dirname, B.filename FROM $dedi_db[lay_upl] AS A LEFT JOIN $dedi_db[upl] AS B USING(idupl) LEFT JOIN $dedi_db[filetype] C on B.idfiletype=C.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') == 'css') $stylefiles .= $cfg_client['htmlpath'].$db->f('dirname').$db->f('filename').",";

        // un-htmlify content, convert special chars to htmlentities and encode to base64 before passing content to the applet
        $content = strtr($content, array_flip(get_html_translation_table(HTML_ENTITIES)));
        $content = htmlentities($content);
        $b64content = base64_encode($content);

        // create "content" field for background saving of content from the applet.
        $contentfield = preg_replace("/(.*)_(\d+)_(\d+)_(\d+)_(\d+)/i", "\$2.\$3.\$4-\$5", $formname);

        // set server-side script that delivers image and file urls
        $servleturl = $sess->url($cfg_dedi['dedi_html_path'].'external/wysiwyg/applet.php?lang='.$lang.'&client='.$client);

        // turn on help menu by default.
        if (empty($type_config['features']) || $type_config['features'] == 'true') {
                // set default buttons for toolbar 1
                $buttons1 = "CUT,COPY,PASTE,SEPARATOR,BOLD,ITALIC,UNDERLINE,SEPARATOR,LEFT,CENTER,RIGHT,JUSTIFY,SEPARATOR,STYLESELECT,DETACHFRAME";

                // set default buttons for toolbar 2
                $buttons2 = "ULIST,OLIST,SEPARATOR,UNDO,REDO,SEPARATOR,DEINDENT,INDENT,SEPARATOR,ANCHOR,SEPARATOR,IMAGE,SEPARATOR,CLEARFORMATS,SEPARATOR,VIEWSOURCE,SEPARATOR,STRIKE,SUPERSCRIPT,SUBSCRIPT,INSERTCHARACTER,SEPARATOR,FIND,COLOR,TABLE,SEPARATOR,SAVECONTENT";

                // set default menuitems
                $menuitems = "EDIT,VIEW,FONT,FORMAT,INSERT,TABLE,SEARCH,TOOLS,HELP";

                // set view to start with
                $sourceview = 'false';
        } else {
                // is wysiwyg2, let the user choose what he wants to see!
                // add support for dedi-tags:
                $features = str_replace(' ', '', strtolower($type_config['features']) );
                $features = explode(',', $features);

                if (in_array('clipboardtools', $features) ) {
                        $menu_edit = 'true';
                        $components[] = 'CUT';
                        $components[] = 'COPY';
                        $components[] = 'PASTE';
                        $components[] = 'SEPARATOR';
                }

                $itemset = 'false';
                if (in_array('bold', $features)) {
                        $itemset = 'true';
                        $components[] = 'BOLD';
                }
                if (in_array('italic', $features)) {
                        $itemset = 'true';
                        $components[] = 'ITALIC';
                }
                if (in_array('underline', $features)) {
                        $itemset = 'true';
                        $components[] = 'UNDERLINE';
                }
                if ($itemset == 'true') $components[] = 'SEPARATOR';

                if (in_array('align', $features)) {
                        $menu_format = 'true';
                        $components[] = 'LEFT';
                        $components[] = 'CENTER';
                        $components[] = 'RIGHT';
                        $components[] = 'JUSTIFY';
                        $components[] = 'SEPARATOR';
                }
                if (in_array('font', $features)) $components[] = 'STYLESELECT';
                if (in_array('popupeditor', $features)) $detachframe = 'DETACHFRAME';
                if (in_array('list', $features)) {
                        $menu_format = 'true';
                        $components[] = 'ULIST';
                        $components[] = 'OLIST';
                        $components[] = 'SEPARATOR';
                }
                if (in_array('undo', $features)) {
                        $menu_edit = 'true';
                        $components[] = 'UNDO';
                        $components[] = 'REDO';
                        $components[] = 'SEPARATOR';
                }
                if( in_array('indent', $features) ) {
                        $components[] = 'DEINDENT';
                        $components[] = 'INDENT';
                        $components[] = 'SEPARATOR';
                }
                if(in_array('file', $features) || in_array('link', $features)) {
                        $menu_insert = 'true';
                        $components[] = 'ANCHOR';
                        $components[] = 'SEPARATOR';
                }
                if (in_array('image', $features)) {
                        $components[] = 'IMAGE';
                        $components[] = 'SEPARATOR';
                }
                if (in_array('striptag', $features)) {
                        $menu_format = 'true';
                        $components[] = 'CLEARFORMATS';
                        $components[] = 'SEPARATOR';
                }
                if (in_array('htmlmode', $features)) {
                        $menu_view = 'true';
                        $components[] = 'VIEWSOURCE';
                        $components[] = 'SEPARATOR';
                }

                $itemset = 'false';
                if (in_array('strikethrough', $features)) {
                        $itemset = 'true';
                        $components[] = 'STRIKE';
                }
                if (in_array('subscript', $features)) {
                        $itemset = 'true';
                        $components[] = 'SUBSCRIPT';
                }
                if (in_array('superscript', $features)) {
                        $itemset = 'true';
                        $components[] = 'SUPERSCRIPT';
                }
                if (in_array('specialchars', $features)) {
                        $itemset = 'true';
                        $components[] = 'INSERTCHARACTER';
                }
                if ($itemset == 'true') $components[] = 'SEPARATOR';

                $itemset = 'false';
                if (in_array('search', $features)) {
                        $itemset = 'true';
                        $menu_search = 'true';
                        $components[] = 'FIND';
                } else $menu_search = 'false';
                if (in_array('fontcolor', $features)) {
                        $itemset = 'true';
                        $components[] = 'COLOR';
                }
                if (in_array('table', $features)) {
                        $itemset = 'true';
                        $menu_table = 'true';
                        $components[] = 'TABLE';
                } else $menu_table = 'false';
                if ($itemset == 'true') $components[] = 'SEPARATOR';

                if (in_array('fontsize', $features)) $menu_font = 'true';
                if (in_array('hr', $features)) $menu_insert = 'true';

                $components[] = 'SAVECONTENT';

                // populate toolbars...
                $mycount = count($components);
                for ($myi = 0; $myi <= $mycount; $myi++) {
                        if ($myi >= 0 && $myi < 14 && ($myi == $mycount || $mycount == 1)) $buttons1 .= $components[$myi];
                        else if($myi >= 0 && $myi < 14 && $mycount > 1) $buttons1 .= $components[$myi].',';

                        else if ($myi >= 14 && $myi == $mycount) $buttons2 .= $components[$myi];
                        else if ($myi >= 14) $buttons2 .= $components[$myi].',';
                }
                $buttons1 .= $detachframe;

                // populate menubar
                if ($menu_edit == "true") $menuitems = "EDIT,";
                if ($menu_view == "true") $menuitems .= "VIEW,";
                if ($menu_font == "true") $menuitems .= "FONT,";
                if ($menu_format == "true") $menuitems .= "FORMAT,";
                if ($menu_insert == "true") $menuitems .= "INSERT,";
                if ($menu_table == "true") $menuitems .= "TABLE,";
                if ($menu_search == "true") $menuitems .= "SEARCH,";
                if ($menu_tools == "true") $menuitems .= "TOOLS,";
                $menuitems .= "HELP,";
                $menuitems = substr($menuitems, 0, strlen($menuitems)-1);

        }

        // SET OUTPUT FOR EDITOR APPLET...
        $out  = '    <input type="hidden" name="'.$formname.'">';
        $out .= '<td>';
//        foreach ($features as $key) {
//                $out .= "feature: $key<BR>";
//        }
        $out .= '<APPLET CODEBASE="'.$cfg_client['htmlpath'].'" CODE="de.xeinfach.kafenio.KafenioApplet.class" ARCHIVE="cms/wysiwyg/applet.jar,cms/wysiwyg/gnu-regexp-1.1.4.jar,cms/wysiwyg/config.jar,cms/wysiwyg/icons.jar" NAME="WYSIWYG_'.$formname.'" ID="WYSIWYG_'.$formname.'" WIDTH="644" HEIGHT="400" MAYSCRIPT>';
        $out .= '<PARAM NAME="codebase" VALUE="'.$cfg_client['htmlpath'].'">';
        $out .= '<PARAM NAME="code" VALUE="de.xeinfach.kafenio.KafenioApplet.class">';
        $out .= '<PARAM NAME="archive" VALUE="cms/wysiwyg/applet.jar,cms/wysiwyg/gnu-regexp-1.1.4.jar,cms/wysiwyg/config.jar,cms/wysiwyg/icons.jar">';
        $out .= '<PARAM NAME="name" VALUE="WYSIWYG_'.$formname.'">';
        $out .= '<PARAM NAME="type" VALUE="application/x-java-applet">';
        $out .= '<PARAM NAME="scriptable" VALUE="true">';
        $out .= '<PARAM NAME="BASE64" VALUE="true">';
        $out .= '<PARAM NAME="STYLESHEET" VALUE="'.$stylefiles.'">';
        $out .= '<PARAM NAME="BGCOLOR" VALUE="#DBE3EF">';
        $out .= '<PARAM NAME="LANGCODE" VALUE="de">';
        $out .= '<PARAM NAME="LANGCOUNTRY" VALUE="DE">';
        if ("$menuitems" != "") {
                $out .= '<PARAM NAME="MENUBAR" VALUE="true">';
                $out .= '<PARAM NAME="MENUITEMS" VALUE="'.$menuitems.'">';
        }
        $out .= '<PARAM NAME="SOURCEVIEW" VALUE="'.$sourceview.'">';
        $out .= '<PARAM NAME="MENUICONS" VALUE="true">';
        if ("$buttons1" != "") {
                $out .= '<PARAM NAME="TOOLBAR" VALUE="true">';
                $out .= '<PARAM NAME="BUTTONS" VALUE="'.$buttons1.'">';
        }
        if ("$buttons2" != "") {
                $out .= '<PARAM NAME="TOOLBAR2" VALUE="true">';
                $out .= '<PARAM NAME="BUTTONS2" VALUE="'.$buttons2.'">';
        }
        $out .= '<PARAM NAME="SERVLETURL" VALUE="'.$servleturl.'">';
        $out .= '<PARAM NAME="SERVLETMODE" VALUE="cgi">';
        $out .= '<PARAM NAME="SYSTEMID" VALUE="">';

        // z.b alle hidden-fields und die session-id beinhalten.
        $out .= '<PARAM NAME="POSTCONTENTURL" VALUE="';
        $out .= $cfg_client['htmlpath'].$sess->url($cfg_client['contentfile']."?lang=$lang&view=edit&action=save&entry=$entry&idcatside=$idcatside&content=$contentfield");
        $out .= '">';

        // contentparameter in dem der content übergeben werden soll.
        $out .= '<PARAM NAME="CONTENTPARAMETER" VALUE="'.$formname.'">';

        // outputmode kann normal oder base64 sein.
        $out .= '<PARAM NAME="OUTPUTMODE" VALUE="normal">';
        $out .= '<PARAM NAME="DEBUG" VALUE="false">';
        $out .= "<PARAM NAME=\"DOCUMENT\" VALUE=\"".$b64content."\">";
        $out .= "</APPLET>";
        $out .= "</td>";
        return $out;
}

function type_form_img($formname, $content, $type_config, $dedi_side) {
        global $db, $dedi_db, $dedi_lang, $client;

// MODIFICATION START
//
global $treeview_flag;
if ($treeview_flag==true)
	$out=type_form_img_treeview($formname, $content, $type_config, $dedi_side);
else {
//
// MODIFICATION END

        $content = type_form_dedilinks_to_templinks($content);
        //Standardfiletypes laden, wenn keine anderen angegeben, defaults laden
        $ft = strtolower(trim($type_config['filetypes']));
        $filetypes = ( empty($ft) || $ft == 'true' ) ? 'jpg,jpeg,gif,png': $ft;

        //get array of selectable images
        $image_array = _type_get_files($filetypes , $type_config['folders'], $type_config['subfolders']);
        $icount = count( $image_array );
        $optionfields= '<option value="">'.$dedi_lang['form_nothing'].'</option>' . "\n";
        for($temp_i = 0; $temp_i<$icount; $temp_i++) {
                $selected = ( $image_array[$temp_i]['id'] == $content ) ? ' selected ' : '';
                $optionfields .= '<option value="'. $image_array[$temp_i]['id'] .'"'. $selected . '>'. $image_array[$temp_i]['name'] .'</option>' ."\n";
        }
        $out = '<td class="content" width="640" nowrap><select name="'. $formname .'" size="1">'."\n";
        $out .= $optionfields;
        $out .= '</select></td>'. "\n";

// MODIFICATION START
//
}
//
// MODIFICATION END

        return $out;
}

function type_form_imgdescr($formname, $content, $type_config, $dedi_side) {
        global $db, $dedi_db, $dedi_lang, $client;

        $content = type_form_dedilinks_to_templinks($content);
        return "    <td class=\"content\"><textarea name=\"$formname\" rows=\"2\" cols=\"52\" style=\"width:640\">$content</textarea></td>\n";
}




function type_form_link($formname, $content, $type_config, $dedi_side) {
        global $db, $dedi_db, $dedi_lang, $mod_lang, $client, $lang, $catlist;

// MODIFICATION START
//
global $treeview_flag;
if ($treeview_flag==true)
	$out=type_form_link_treeview($formname, $content, $type_config, $dedi_side);
else {
//
// MODIFICATION END

        $content = type_form_dedilinks_to_templinks($content);

        $sql = "SELECT A.name, B.idcat, B.parent, B.sortindex FROM $dedi_db[cat_lang] AS A LEFT JOIN $dedi_db[cat] AS B USING(idcat) WHERE B.idclient='$client' AND A.idlang='$lang' ORDER BY B.parent, B.sortindex";
        $db->query($sql);
        while ($db->next_record()) {
                $ordner[$db->f('idcat')] = $db->f('name');
                $tlo_tree[$db->f('parent')][$db->f('sortindex')] = $db->f('idcat');
        }

        // tree_level_order_light();
        $sql = "SELECT D.idcatside, D.idcat, D.sortindex, D.is_start, F.title FROM $dedi_db[cat_side] AS D LEFT JOIN $dedi_db[side] AS E USING(idside) LEFT JOIN $dedi_db[side_lang] AS F USING(idside) WHERE E.idclient='$client' AND F.idlang='$lang' ORDER BY D.idcatside";
        $db->query($sql);
        while ($db->next_record()) {
                $seiten[$db->f('idcat')][$db->f('idcatside')]['name'] = $db->f('title');
                $seiten[$db->f('idcat')][$db->f('idcatside')]['idcatside'] = $db->f('idcatside');
                $seiten[$db->f('idcat')][$db->f('idcatside')]['is_start'] = $db->f('is_start');
                if ($db->f('is_start') == 1){ $seiten['start'][$db->f('idcat')] = $db->f('idcatside'); }
                if (!is_array($seiten['sortarray'][$db->f('idcat')])){$seiten['sortarray'][$db->f('idcat')] = array(); }
                array_push($seiten['sortarray'][$db->f('idcat')],$db->f('sortindex'));
        }
        $baum = array();
        foreach($catlist as $a){
                $temp['id'] = $seiten['start'][$a];
                $temp['name'] = $ordner[$a];
                $temp['level'] = $catlist_level[$a];
                array_push($baum, $temp);
                if(is_array($seiten[$a])) {
                        array_multisort($seiten['sortarray'][$a] , SORT_ASC , $seiten[$a] , SORT_ASC);
                        foreach(array_keys($seiten[$a]) as $b) {
                                //if($seiten['start'][$a] != $b) {
                                        $temp['id'] = $seiten[$a][$b]['idcatside'];
                                        $temp['name'] = $seiten[$a][$b]['name'];
                                        $temp['level'] = $catlist_level[$a] + 1;
                                        array_push($baum, $temp);
                                //}
                        }
                }
        }
        $out = "    <input type=\"hidden\" name=\"$formname\" value=\"$content\">\n";
        if (is_numeric($content)) {
                $con_link_intern = $content;
                $con_link_extern = '';
        } else {
                $con_link_intern = '0';
                $con_link_extern = $content;
        }
        $out .= "      <td width=\"640\" class=\"content\"><table cellspacing=\"1\" cellpadding=\"1\" border=\"0\" width='100%'>\n";
        $out .= "        <tr>\n";
        $out .= "          <td ><input type=\"text\" name=\"".$formname."extern\" value=\"".$con_link_extern."\" size=\"28\" style=\"width:219\" onchange=\"editcontent.".$formname.".value=this.value; editcontent.".$formname."intern.value='0';\">&nbsp;<small>(".$mod_lang['link_extern'].")</small>&nbsp;</td>\n";
        $out .= "        </tr><tr>";
        $out .= "          <td class=\"content\"><select name=\"".$formname."intern\" size=\"1\" onChange=\"editcontent.".$formname.".value=this.value; editcontent.".$formname."extern.value='';\">\n";
        if ($con_link_intern == '0') $out .= "<option value=\"0\" selected>&nbsp;".$dedi_lang['form_nothing']."</option>\n";
        else $out .= "<option value=\"0\">&nbsp;".$dedi_lang['form_nothing']."</option>\n";
        foreach($baum as $a) {
                if ($con_link_intern == $a['id']) $out .= "<option value=\"".$a['id']."\" selected>".(str_repeat('&nbsp;&nbsp;',$a['level'])).$a['name']."</option>\n";
                else $out .= "<option value=\"".$a['id']."\">".(str_repeat('&nbsp;&nbsp;',$a['level'])).$a['name']."</option>\n";
        }
        $out .= "          </select>&nbsp;<small>(".$mod_lang['link_intern'].")</small>&nbsp;</td>\n";
        $out .= "        </tr>\n";
        $out .= "      </table></td>\n";

// MODIFICATION START
//
}
//
// MODIFICATION END

        return $out;
}


function type_form_linkdescr($formname, $content, $type_config, $dedi_side) {
        return '<td class="content"><input type="text" name="'.$formname.'" style="width:400px" value="'.$content.'"></td>'."\n";
}


function type_form_linktarget($formname, $content, $type_config, $dedi_side) {
        global $mod_lang;

        $content = type_form_dedilinks_to_templinks($content);

        $out = "    <input type=\"hidden\" name=\"$formname\" value=\"$content\">\n";
        $out .= "      <td class=\"content\" width=\"640\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n";
        $out .= "        <tr>\n";
        $out .= "          <td class=\"content\"><input type=\"text\" name=\"".$formname."frame\" value=\"$content\" size=\"11\" style=\"width:100\" onchange=\"editcontent.".$formname.".value=this.value; editcontent.".$formname."selectframe.value='_self';\"></td>\n";
        $out .= "          <td class=\"content\"><select name=\"".$formname."selectframe\" size=\"1\" onChange=\"editcontent.".$formname.".value=this.value; editcontent.".$formname."frame.value=this.value;\">\n";
        if ($content == '_self') $out .= "            <option value=\"_self\" selected>&nbsp;".$mod_lang['link_self']."</option>\n";
        else $out .= "            <option value=\"_self\">&nbsp;".$mod_lang['link_self']."</option>\n";
        if ($content == '_blank') $out .= "            <option value=\"_blank\" selected>&nbsp;".$mod_lang['link_blank']."</option>\n";
        else $out .= "            <option value=\"_blank\">&nbsp;".$mod_lang['link_blank']."</option>\n";
        if ($content == '_parent') $out .= "            <option value=\"_parent\" selected>&nbsp;".$mod_lang['link_parent']."</option>\n";
        else $out .= "            <option value=\"_parent\">&nbsp;".$mod_lang['link_parent']."</option>\n";
        if ($content == '_top') $out .= "            <option value=\"_top\" selected>&nbsp;".$mod_lang['link_top']."</option>\n";
        else $out .= "            <option value=\"_top\">&nbsp;".$mod_lang['link_top']."</option>\n";
        $out .= "          </select></td>\n";
        $out .= "        </tr>\n";
        $out .= "      </table></td>\n";
         return $out;
}

function type_form_sourcecode($formname, $content, $type_config, $dedi_side) {
        global $js_pad, $cfg_dedi, $gb_conf;

        $content = type_form_dedilinks_to_templinks($content);

        include_once ($cfg_dedi['dedi_path'].'external/sourcepad/gb_source_pad.php');
        $js_pad = &new gb_source_pad('editcontent', $formname);

        $out = "    <td class=\"content\">\n";
        $js_pad -> set('handle_http_path', $cfg_dedi['dedi_html_path'].'external/sourcepad/');
        $js_pad -> set('language', 'german');
        $js_pad -> set('editorheight_css', '350px');
        $js_pad -> set('editorwidth_css', '640px');
        $js_pad -> set('content', $content);
        $out .= $js_pad -> make_pad();
        $out .= "    </td>\n";
        return $out;
}

/**
 * Returns complete formatted "select files from the filebrowser"- field
 *
 * @Args: formname -> name of the inputfield
 *        content -> value of textfield
 *        type_config -> array with values from the DEDI:tag
 *        dedi_side['view'] -> the current view of the user, 'edit' or 'preview'
 *                 ['edit'] -> 'true' if user set the mod in templateconfig as active
 *                             if user set inactiv var is not set
 * @Return String HTML textfield
 * @Access public
 */
function type_form_file($formname, $content, $type_config, $dedi_side) {
        global $db, $dedi_db, $dedi_lang, $client, $deditag_config;

// MODIFICATION START
//
global $treeview_flag;
if ($treeview_flag==true)
	$html_out=type_form_file_treeview($formname, $content, $type_config, $dedi_side);
else {
//
// MODIFICATION END

        $content = type_form_dedilinks_to_templinks($content);

        $filetypes = $type_config['filetypes'];
        $folders = $type_config['folders'];
        $subfolders = $type_config['subfolders'];

        //get files
        $file_list = _type_get_files($filetypes , $folders, $subfolders);

        $html_out = '
        <td class="content" width="640">
         <table cellspacing="0" cellpadding="0" border="0">';
        //zusätzliche beschreibung nur wenn ein title im tag angegeben wurde, sonst würde hier zwei mal das gleiche stehen
        if(! empty($deditag_config[$con_type[$con_contype]['type']][$con_typenumber]['title'])){
        $html_out .= '
          <tr>
           <td class="content">&nbsp;'. $con_type[$con_contype]['descr'] .':</td>
          </tr>';
        }

        $html_out .= '
          <tr>
           <td class="content">
                <select name="' . $formname . '" size="1">';

        //Keine Auswahl
        $html_out .= '<option value="">&nbsp;' . $dedi_lang['form_nothing'] .'</option>';

        $i = count($file_list);
        for($j=0; $j < $i; $j++)
        {
                if ($content == $file_list[$j]['id']){
                        $html_out .= '<option value="' . $file_list[$j]['id'] . '" selected>'. $file_list[$j]['name'] .'</option>'."\n";
                }
                else{
                        $html_out .= '<option value="' . $file_list[$j]['id'] . '">' . $file_list[$j]['name'] .'</option>'."\n";
                }
        }
        $html_out .= '</select>
           </td>
          </tr>
         </table>
        </td>';

        //Hidetarget auslesen und variable ins filetarget rüberretten, da die Werte der dedi:tags nur im Haupttag sichtbar sind
        global $filetarget_is_hidden;
        $filetarget_is_hidden = $type_config['hidetarget'];

// MODIFICATION START
//
}
//
// MODIFICATION END

        return $html_out;
}

function type_form_filedescr($formname, $content, $type_config, $dedi_side) {
        $content = type_form_dedilinks_to_templinks($content);
        return '<td class="content"><input type="text" name="'.$formname.'" style="width:400px" value="'.$content.'"></td>'."\n";
}

function type_form_filetarget($formname, $content, $type_config, $dedi_side) {
        global $mod_lang, $filetarget_is_hidden;

        $content = type_form_dedilinks_to_templinks($content);

        if($filetarget_is_hidden != 'true'){
                $out = "    <input type=\"hidden\" name=\"$formname\" value=\"$content\">\n";
                $out .= "      <td class=\"content\" width=\"640\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n";
                $out .= "        <tr>\n";
                $out .= "          <td class=\"content\"><input type=\"text\" name=\"".$formname."frame\" value=\"$content\" size=\"11\" style=\"width:100\" onchange=\"editcontent.".$formname.".value=this.value; editcontent.".$formname."selectframe.value='_self';\"></td>\n";
                $out .= "          <td class=\"content\"><select name=\"".$formname."selectframe\" size=\"1\" onChange=\"editcontent.".$formname.".value=this.value; editcontent.".$formname."frame.value=this.value;\">\n";
                if ($content == '_self') $out .= "            <option value=\"_self\" selected>&nbsp;".$mod_lang['link_self']."</option>\n";
                else $out .= "            <option value=\"_self\">&nbsp;".$mod_lang['link_self']."</option>\n";
                if ($content == '_blank') $out .= "            <option value=\"_blank\" selected>&nbsp;".$mod_lang['link_blank']."</option>\n";
                else $out .= "            <option value=\"_blank\">&nbsp;".$mod_lang['link_blank']."</option>\n";
                if ($content == '_parent') $out .= "            <option value=\"_parent\" selected>&nbsp;".$mod_lang['link_parent']."</option>\n";
                else $out .= "            <option value=\"_parent\">&nbsp;".$mod_lang['link_parent']."</option>\n";
                if ($content == '_top') $out .= "            <option value=\"_top\" selected>&nbsp;".$mod_lang['link_top']."</option>\n";
                else $out .= "            <option value=\"_top\">&nbsp;".$mod_lang['link_top']."</option>\n";
                $out .= "          </select></td>\n";
                $out .= "        </tr>\n";
                $out .= "      </table></td>\n";
        }
        unset($filetarget_is_hidden);
        return $out;
}

//
// PRIVATE HELPER FUNCTIONS
//
function type_form_dedilinks_to_templinks($content){

                //turn around inline- editing temp_links
                $in = array("!http://dedilink/fileid=(\d+)!",
                            "!http://dedilink/idcat=(\d+)!",
                            "!http://dedilink/idcatside=(\d+)!");
                $out = array("http://dedilink/temp_fileid=\\1",
                                 "http://dedilink/temp_idcat=\\1",
                                 "http://dedilink/temp_idcatside=\\1");
                return preg_replace($in, $out, $content);
}
?>