/**
 * Display TCExam Code EDITOR Tag Buttons
 * @author Nicola Asuni
 * @since 2006-03-07
 * @param $callingform (string) name of calling xhtml form
 * @param $callingfield (string) name of calling form field (textarea where output code will be sent)
 * @return XHTML string
 */
function tcecodeEditorTagButtons($callingform, $callingfield)
{
    global $l, $db;
    global $uploadedfile;
    require_once '../config/tce_config.php';
    // sanitize input parameters
    $callingform = preg_replace('/[^a-z0-9_]/', '', $callingform);
    $callingfield = preg_replace('/[^a-z0-9_]/', '', $callingfield);
    $buttons = '';
    // --- buttons
    $onclick = 'FJ_undo(document.getElementById(\'' . $callingform . '\').' . $callingfield . ')';
    $buttons .= getImageButton($l['w_undo'], '', K_PATH_IMAGES . 'buttons/undo.gif', $onclick, 'z');
    $onclick = 'FJ_redo(document.getElementById(\'' . $callingform . '\').' . $callingfield . ')';
    $buttons .= getImageButton($l['w_redo'], '', K_PATH_IMAGES . 'buttons/redo.gif', $onclick, 'y');
    $onclick = 'FJ_insert_tag(document.getElementById(\'' . $callingform . '\').' . $callingfield . '';
    $buttons .= getImageButton('bold', '[b]', K_PATH_IMAGES . 'buttons/bold.gif', $onclick, 'b');
    $buttons .= getImageButton('italic', '[i]', K_PATH_IMAGES . 'buttons/italic.gif', $onclick, 'i');
    $buttons .= getImageButton('underline', '[u]', K_PATH_IMAGES . 'buttons/under.gif', $onclick, 'u');
    $buttons .= getImageButton('strikethrough', '[s]', K_PATH_IMAGES . 'buttons/strike.gif', $onclick, 'd');
    $buttons .= getImageButton('small', '[small]', K_PATH_IMAGES . 'buttons/small.gif', $onclick, 's');
    $buttons .= getImageButton('subscript', '[sub]', K_PATH_IMAGES . 'buttons/subscr.gif', $onclick, 'v');
    $buttons .= getImageButton('superscript', '[sup]', K_PATH_IMAGES . 'buttons/superscr.gif', $onclick, 'a');
    $buttons .= getImageButton('link', '[url]', K_PATH_IMAGES . 'buttons/link.gif', $onclick, 'k');
    $buttons .= getImageButton('unordered list', '[ulist]', K_PATH_IMAGES . 'buttons/bullist.gif', $onclick, 'l');
    $buttons .= getImageButton('ordered list', '[olist]', K_PATH_IMAGES . 'buttons/numlist.gif', $onclick, 'o');
    $buttons .= getImageButton('list item', '[li]', K_PATH_IMAGES . 'buttons/li.gif', $onclick, 't');
    $buttons .= getImageButton('LRT', '[dir=ltr]', K_PATH_IMAGES . 'buttons/ltrdir.gif', $onclick, '');
    $buttons .= getImageButton('RTL', '[dir=rtl]', K_PATH_IMAGES . 'buttons/rtldir.gif', $onclick, '');
    $onclick = 'window.open(\'tce_colorpicker.php?frm=' . $callingform . '&fld=' . $callingfield . '&tag=bgcolor\',\'colorpicker\',\'height=550,width=330,resizable=yes,menubar=no,scrollbars=no,toolbar=no,directories=no,status=no,modal=yes\');';
    $buttons .= getImageButton('background-color', '', K_PATH_IMAGES . 'buttons/bgcolor.gif', $onclick, '');
    $onclick = 'window.open(\'tce_colorpicker.php?frm=' . $callingform . '&fld=' . $callingfield . '&tag=color\',\'colorpicker\',\'height=550,width=330,resizable=yes,menubar=no,scrollbars=no,toolbar=no,directories=no,status=no,modal=yes\');';
    $buttons .= getImageButton('color', '', K_PATH_IMAGES . 'buttons/color.gif', $onclick, '');
    $onclick = 'FJ_insert_tag(document.getElementById(\'' . $callingform . '\').' . $callingfield . '';
    $buttons .= getImageButton('code', '[code]', K_PATH_IMAGES . 'buttons/code.gif', $onclick, 'c');
    $buttons .= getImageButton('latex', '[tex]', K_PATH_IMAGES . 'buttons/latex.gif', $onclick, 'm');
    $buttons .= getImageButton('mathml', '[mathml]', K_PATH_IMAGES . 'buttons/mathml.gif', $onclick, 'h');
    $onclick = 'window.open(\'tce_select_mediafile.php?frm=' . $callingform . '&fld=' . $callingfield . '\',\'mediaselect\',\'height=600,width=680,resizable=yes,menubar=no,scrollbars=yes,toolbar=no,directories=no,status=no,modal=yes\');';
    $buttons .= getImageButton('object', '', K_PATH_IMAGES . 'buttons/image.gif', $onclick, '');
    $buttons .= '<br />' . K_NEWLINE;
    // font size
    $onselect = 'FJ_insert_tag(document.getElementById(\'' . $callingform . '\').' . $callingfield . ', ';
    $onselect .= 'document.getElementById(\'font_size_' . $callingfield . '\').options[document.getElementById(\'font_size_' . $callingfield . '\').selectedIndex].value';
    $onselect .= ')';
    $buttons .= '<select name="font_size_' . $callingfield . '" id="font_size_' . $callingfield . '" size="0" title="' . $l['w_font_size'] . '" style="margin:0;padding:0;" onchange="' . $onselect . '">';
    $buttons .= '<option value="" selected="selected" style="background-color:gray;color:white;">' . $l['w_font_size'] . '</option>';
    $buttons .= '<option value="[size=xx-small]">xx-small</option>';
    $buttons .= '<option value="[size=x-small]">x-small</option>';
    $buttons .= '<option value="[size=small]">small</option>';
    $buttons .= '<option value="[size=medium]">medium</option>';
    $buttons .= '<option value="[size=large]">large</option>';
    $buttons .= '<option value="[size=x-large]">x-large</option>';
    $buttons .= '<option value="[size=xx-large]">xx-large</option>';
    for ($i = 10; $i <= 400; $i += 10) {
        $buttons .= '<option value="[size=' . $i . '%]">' . $i . '%</option>';
    }
    $buttons .= '</select>' . K_NEWLINE;
    // font
    $tce_fonts = unserialize(K_AVAILABLE_FONTS);
    if (!empty($tce_fonts)) {
        $onselect = 'FJ_insert_tag(document.getElementById(\'' . $callingform . '\').' . $callingfield . ', ';
        $onselect .= 'document.getElementById(\'font_' . $callingfield . '\').options[document.getElementById(\'font_' . $callingfield . '\').selectedIndex].value';
        $onselect .= ')';
        $buttons .= '<select name="font_' . $callingfield . '" id="font_' . $callingfield . '" size="0" title="' . $l['w_font'] . '" style="margin:0;padding:0;" onchange="' . $onselect . '">';
        $buttons .= '<option value="" selected="selected" style="background-color:gray;color:white;">' . $l['w_font'] . '</option>';
        foreach ($tce_fonts as $fname => $font) {
            $buttons .= '<option value="[font=' . $font . ']">' . $fname . '</option>';
        }
        $buttons .= '</select>' . K_NEWLINE;
    }
    return $buttons;
}
/**
 * Display TCExam Code EDITOR Tag Buttons
 * @author Nicola Asuni
 * @since 2006-03-07
 * @param $callingform (string) name of calling xhtml form
 * @param $callingfield (string) name of calling form field (textarea where output code will be sent)
 * @param $id (int) DEPRECATED -- id appended to input fields names to differentiate from previous buttons.
 * @return XHTML string
 */
function tcecodeEditorTagButtons($callingform, $callingfield, $id = 0)
{
    global $l, $db;
    global $uploadedfile;
    require_once '../config/tce_config.php';
    // sanitize input parameters
    $callingform = preg_replace('/[^a-z0-9_]/', '', $callingform);
    $callingfield = preg_replace('/[^a-z0-9_]/', '', $callingfield);
    $id = intval($id);
    $buttons = '';
    $buttons .= '<script src="' . K_PATH_SHARED_JSCRIPTS . 'inserttag.js" type="text/javascript"></script>' . K_NEWLINE;
    // --- buttons
    $onclick = 'FJ_undo(document.getElementById(\'' . $callingform . '\').' . $callingfield . ')';
    $buttons .= getImageButton($l['w_undo'], '', K_PATH_IMAGES . 'buttons/undo.gif', $onclick, 'z');
    $onclick = 'FJ_redo(document.getElementById(\'' . $callingform . '\').' . $callingfield . ')';
    $buttons .= getImageButton($l['w_redo'], '', K_PATH_IMAGES . 'buttons/redo.gif', $onclick, 'y');
    $onclick = 'FJ_insert_tag(document.getElementById(\'' . $callingform . '\').' . $callingfield . '';
    $buttons .= getImageButton('bold', '[b]', K_PATH_IMAGES . 'buttons/bold.gif', $onclick, 'b');
    $buttons .= getImageButton('italic', '[i]', K_PATH_IMAGES . 'buttons/italic.gif', $onclick, 'i');
    $buttons .= getImageButton('underline', '[u]', K_PATH_IMAGES . 'buttons/under.gif', $onclick, 'u');
    $buttons .= getImageButton('strikethrough', '[s]', K_PATH_IMAGES . 'buttons/strike.gif', $onclick, 'd');
    $buttons .= getImageButton('small', '[small]', K_PATH_IMAGES . 'buttons/small.gif', $onclick, 's');
    $buttons .= getImageButton('subscript', '[sub]', K_PATH_IMAGES . 'buttons/subscr.gif', $onclick, 'v');
    $buttons .= getImageButton('superscript', '[sup]', K_PATH_IMAGES . 'buttons/superscr.gif', $onclick, 'a');
    $buttons .= getImageButton('link', '[url]', K_PATH_IMAGES . 'buttons/link.gif', $onclick, 'k');
    $buttons .= getImageButton('unordered list', '[ulist]', K_PATH_IMAGES . 'buttons/bullist.gif', $onclick, 'l');
    $buttons .= getImageButton('ordered list', '[olist]', K_PATH_IMAGES . 'buttons/numlist.gif', $onclick, 'o');
    $buttons .= getImageButton('list item', '[li]', K_PATH_IMAGES . 'buttons/li.gif', $onclick, 't');
    $buttons .= getImageButton('LRT', '[dir=ltr]', K_PATH_IMAGES . 'buttons/ltrdir.gif', $onclick, '');
    $buttons .= getImageButton('RTL', '[dir=rtl]', K_PATH_IMAGES . 'buttons/rtldir.gif', $onclick, '');
    $onclick = 'window.open(\'tce_colorpicker.php?frm=' . $callingform . '&amp;fld=' . $callingfield . '&amp;tag=bgcolor\',\'colorpicker\',\'height=550,width=330,resizable=yes,menubar=no,scrollbars=no,toolbar=no,directories=no,status=no,modal=yes\');';
    $buttons .= getImageButton('background-color', '', K_PATH_IMAGES . 'buttons/bgcolor.gif', $onclick, '');
    $onclick = 'window.open(\'tce_colorpicker.php?frm=' . $callingform . '&amp;fld=' . $callingfield . '&amp;tag=color\',\'colorpicker\',\'height=550,width=330,resizable=yes,menubar=no,scrollbars=no,toolbar=no,directories=no,status=no,modal=yes\');';
    $buttons .= getImageButton('color', '', K_PATH_IMAGES . 'buttons/color.gif', $onclick, '');
    $onclick = 'FJ_insert_tag(document.getElementById(\'' . $callingform . '\').' . $callingfield . '';
    $buttons .= getImageButton('code', '[code]', K_PATH_IMAGES . 'buttons/code.gif', $onclick, 'c');
    $buttons .= getImageButton('latex', '[tex]', K_PATH_IMAGES . 'buttons/latex.gif', $onclick, 'm');
    $onclick = 'window.open(\'tce_select_mediafile.php?frm=' . $callingform . '&amp;fld=' . $callingfield . '\',\'mediaselect\',\'height=600,width=680,resizable=yes,menubar=no,scrollbars=yes,toolbar=no,directories=no,status=no,modal=yes\');';
    $buttons .= getImageButton('object', '', K_PATH_IMAGES . 'buttons/image.gif', $onclick, '');
    return $buttons;
}