{extends file="config.tpl"}

{block name="content"}
<form method="POST" action="{$modulelink}&amp;page=general" enctype='multipart/form-data' autocomplete="off">
    <div class="row">
        <div class="col-md-12">
            <h2><i class="fas fa-sliders-h"></i> General</h2>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <h4 class="mb-3">
                Invoices
                {if $invoice_active}
                    <span class="label label-success">Active</span>
                {else}
                    <span class="label label-danger">Not active</span>
                {/if}
            </h4>
            <div class="row">
                <div class="form-group col-md-12">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="invoicepdf_alert" value="true"{if $config.invoicepdf_alert eq 'true'} checked{/if}>
                            Send email notification to admins if not active
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="invoicepdf_autofix" value="true"{if $config.invoicepdf_autofix eq 'true'} checked{/if}>
                            Attempt to automatically fix the invoicepdf.tpl file
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <h4 class="mb-3">
                Quotes
                {if $quote_active}
                    <span class="label label-success">Active</span>
                {else}
                    <span class="label label-danger">Not active</span>
                {/if}
            </h4>
            <div class="row">
                <div class="form-group col-md-12">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="quotepdf_alert" value="true"{if $config.quotepdf_alert eq 'true'} checked{/if}>
                            Send email notification to admins if not active
                        </label>
                    </div>
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="quotepdf_autofix" value="true"{if $config.quotepdf_autofix eq 'true'} checked{/if}>
                            Attempt to automatically fix the quotepdf.tpl file
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <hr class="mb-4">
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <h4 class="mb-3">Date format</h4>
            <div class="row">
                <div class="form-group col-md-12">
                    <div class="radio">
                        <label>
                            <input type="radio" name="date_format_mode" value="auto"{if $config.date_format_mode eq 'auto'} checked{/if}>
                            Automatically format according to client language and country
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="radio" name="date_format_mode" value="whmcs"{if $config.date_format_mode eq 'whmcs'} checked{/if}>
                            Format according to <a href="configgeneral.php#tab=2">WHMCS system setting</a>: {$date_format}
                        </label>
                    </div>
                </div>
            </div>
            <div class="alert alert-info" role="alert">
                <i class="fas fa-info-circle"></i>
                Automatic formatting on linux servers requires the corresponding locales to be installed, otherwise it will revert to US formatting.
                Check the documentation for more details.
            </div>
        </div>
        <div class="col-md-6">
            <h4 class="mb-3">Preview thumbnails</h4>
            <div class="row">
                <div class="form-group col-md-12">
                    <div class="radio">
                        <label>
                            <input type="radio" name="thumb_mode" value="imagick"{if $config.thumb_mode eq 'imagick'} checked{/if}>
                            Use ImageMagick
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="radio" name="thumb_mode" value="magick"{if $config.thumb_mode eq 'magick'} checked{/if}>
                            Use GraphicsMagick
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="radio" name="thumb_mode" value="poppler"{if $config.thumb_mode eq 'poppler'} checked{/if}>
                            Use Poppler
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="radio" name="thumb_mode" value="disable"{if $config.thumb_mode eq 'disable'} checked{/if}>
                            Disable
                        </label>
                    </div>
                </div>
                <div class="form-group col-md-12">
                    <label for="thumb_bin">Path to binary</label>
                    <div class="input-group">
                        <span class="input-group-addon">
                            {if $config.thumb_mode eq 'disable'}
                                <span class="label label-default">Disabled</span>
                            {elseif $thumbs_executable}
                                <span class="label label-success">Executable</span>
                            {else}
                                <span class="label label-danger">Not executable</span>
                            {/if}
                        </span>
                        <input type="text" class="form-control" name="thumb_bin" value="{$config.thumb_bin}">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <hr class="mb-4">
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <h4 class="mb-3">Error handling</h4>
            <div class="row">
                <div class="form-group col-md-12">
                    <div class="radio">
                        <label>
                            <input type="radio" name="error_handling" value="fallback"{if $config.error_handling eq 'fallback'} checked{/if}>
                            Fallback to default WHMCS PDF generation, silently log the error and notify admins
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="radio" name="error_handling" value="throw"{if $config.error_handling eq 'throw'} checked{/if}>
                            Throw the error, also log it and send an email notification to admins
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <h4 class="mb-3">Data path</h4>
            <div class="row">
                <div class="form-group col-md-12">
                    <label for="thumb_bin">Full path for BestPDF data (leave empty for default)</label>

                    <div class="input-group">
                        <span class="input-group-addon">
                            {if $data_writable}
                                <span class="label label-success">Writable</span>
                            {else}
                                <span class="label label-danger">Not writable</span>
                            {/if}
                        </span>
                        <input type="text" class="form-control" name="data_path" value="{$config.data_path}">
                    </div>
                    <ul>
                        <li>
                            {if $templates_writable}
                                <span class="label label-success">Writable</span>
                            {else}
                                <span class="label label-danger">Not writable</span>
                            {/if}
                            pdf-templates/
                        </li>
                        <li>
                            {if $logos_writable}
                                <span class="label label-success">Writable</span>
                            {else}
                                <span class="label label-danger">Not writable</span>
                            {/if}
                            logos/
                        </li>
                        <li>
                            {if $fonts_writable}
                                <span class="label label-success">Writable</span>
                            {else}
                                <span class="label label-danger">Not writable</span>
                            {/if}
                            fonts/
                        </li>
                        <li>
                            {if $previews_writable}
                                <span class="label label-success">Writable</span>
                            {else}
                                <span class="label label-danger">Not writable</span>
                            {/if}
                            previews/
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <hr class="mb-4">
        </div>
    </div>

    <div class="btn-group" role="group" aria-label="...">
        <button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Save</button>
    </div>

</form>

<script>
    $(document).ready(function(){
        $('input[name=thumb_mode]').change(function() {
            switch(this.value) {
                case 'imagick':
                case 'magick':
                    $('input[name=thumb_bin]').val('convert');
                    break;
                case 'poppler':
                    $('input[name=thumb_bin]').val('pdftoppm');
                    break;
                default:
                    $('input[name=thumb_bin]').val('');
                    break;
            }
        });
    });
</script>
{/block}
