<?php
    // check the default settings
    // $forcerest to be set in calling page
    if (!isset($forcereset)) {
        $forcereset = false;
    }
    require_once "defaultsettings.php";
    tex_defaultsettings( $forcereset );

    // bit of a bodge - clear the tex cache area
    // so that any changes will display
    if (file_exists( "$CFG->dataroot/filter/tex" )) {
        remove_dir( "$CFG->dataroot/filter/tex", true ); 
    }

    // get strings
    $txt = new Object;
    $txt->latexsettings = get_string( 'latexsettings','admin' );
    $txt->latexpreamble = get_string( 'latexpreamble','admin' );
    $txt->backgroundcolour = get_string( 'backgroundcolour','admin' );
    $txt->density = get_string( 'density','admin' );
    $txt->pathlatex = get_string( 'pathlatex','admin' );
    $txt->pathdvips = get_string( 'pathdvips','admin' );
    $txt->pathconvert = get_string( 'pathconvert','admin' );
    $txt->tick = '&#x2714;';
    $txt->cross = '&#x2718;';

    // check file exists & display tick or cross 
    function texbinaryconfirm( $path ) {
        global $txt;
        if (is_file($path)) {
            echo "<span style=\"color:green;\">$txt->tick</span>";
        }
        else {
            echo "<span style=\"color:red;\">$txt->cross</span>";
        }        
    }
?>

<table cellpadding="9" cellspacing="0">
    <tr valign="top">
        <th align="right" scope="col"><?php echo $txt->latexsettings; ?></th>
        <th>&nbsp;</th>
    </tr>
    <tr valign="top">
        <td align="right"><?php echo $txt->latexpreamble; ?></td>
        <td><textarea type="text" name="filter_tex_latexpreamble" cols="60" rows="5"><?php p($CFG->filter_tex_latexpreamble); ?></textarea></td>
    </tr>
    <tr valign="top">
        <td align="right"><?php echo $txt->backgroundcolour; ?></td>
        <td><input type="text" name="filter_tex_latexbackground" 
            value="<?php p($CFG->filter_tex_latexbackground) ?>" /></td>
    </tr>
    <tr valign="top">
        <td align="right"><?php echo $txt->density; ?></td>
        <td><input type="text" name="filter_tex_density"
            value="<?php p($CFG->filter_tex_density); ?>" /></td>
    </tr>
    <tr valign="top">
        <td align="right"><?php echo $txt->pathlatex; ?></td>
        <td><input type="text" name="filter_tex_pathlatex" size="50"
            value="<?php p($CFG->filter_tex_pathlatex); ?>" />
            <?php texbinaryconfirm( $CFG->filter_tex_pathlatex ); ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><?php echo $txt->pathdvips; ?></td>
        <td><input type="text" name="filter_tex_pathdvips" size="50"
            value="<?php p($CFG->filter_tex_pathdvips); ?>" />
            <?php texbinaryconfirm( $CFG->filter_tex_pathdvips ); ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><?php echo $txt->pathconvert; ?></td>
        <td><input type="text" name="filter_tex_pathconvert" size="50"
            value="<?php p($CFG->filter_tex_pathconvert); ?>" />
            <?php texbinaryconfirm( $CFG->filter_tex_pathconvert ); ?>
        </td>
    </tr>
</table>
