{extends file="admin-layout.tpl"}

{block name="no-return-functions"}
    {$admin_current_location = 'configuration'}
{/block}

{block name="page-title"}{intl l='System Logs'}{/block}

{block name="check-resource"}admin.configuration.variable{/block}
{block name="check-access"}update{/block}

{block name="main-content"}
<div class="variables edit-variable">

    <div id="wrapper" class="container">

        <ul class="breadcrumb">
			<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
            <li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
            <li>{intl l="System logs"}</li>
        </ul>

		<div class="row">
			<div class="col-md-12 general-block-decorator">
				<div class="row">

					<div class="col-md-12 title title-without-tabs">
					   {intl l="System Logs configuration"}
					</div>
                </div>

                <div class="form-container">
                    <div class="row">
                        <div class="col-md-12">
                            {form name='thelia.system-logs.configuration'}
	 						<form method="POST" action="{url path='/admin/configuration/system-logs/save'}">

                                {form_hidden_fields}

		                        {include
		                            file = "includes/inner-form-toolbar.html"
		                            hide_flags = true

		                            page_url  = "{url path='/admin/configuration/system-logs'}"
		                            close_url = "{url path='/admin/configuration'}"
		                        }

                                <div class="row">
                                    <div class="col-md-6">
                                        <p class="title title-without-tabs">{intl l='General configuration'}</p>

                                        {if $form_error}
							            <div class="alert alert-danger">{$form_error_message}</div>
							            {/if}

                                        <fieldset>

                                            {form_field field="level"}
					                        <div class="form-group {if $error}has-error{/if}">

					                            <label for="{$label_attr.for}" class="control-label">{$label}: </label>

				                                <select name="{$name}" id="{$label_attr.for}" class="form-control">
				                                    {foreach $choices as $choice}
				                                        <option value="{$choice->value}" {if $value == $choice->value}selected="selected"{/if}>{$choice->label}</option>
				                                    {/foreach}
				                                </select>

				                                <span class="help-block">
				                                {intl l='Messages which have a level greater or equal to the selected level will be added to the log destinations. '}
				                                </span>
                                            </div>
                                            {/form_field}

					                        {form_field field='format'}
					                           <div class="form-group {if $error}has-error{/if}">
					                               <label for="{$label_attr.for}" class="control-label">{$label}: </label>

					                               <div class="form-group">
					                                   <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Log lines format'}">
					                               </div>

	                                                <span class="help-block">
	                                                {intl l='Log lines header format. You may use the following variables: '}
	                                                <ul>
												        <li>#INDEX : {intl l='Sequential number of log line'}</li>
												        <li>#LEVEL : {intl l='Message level'}</li>
												        <li>#FILE : {intl l='Originating file name'}</li>
												        <li>#FUNCTION : {intl l='Originating function name '}</li>
												        <li>#LINE : {intl l='Originating file line number '}</li>
												        <li>#DATE : {intl l='date in yyyy-mm-dd format'}</li>
												        <li>#HOUR : {intl l='hour in hh:mm:ss format'}</li>
												    </ul>
	                                                </span>
					                           </div>
					                        {/form_field}

					                        {form_field field='show_redirections'}
					                           <div class="form-group {if $error}has-error{/if}">
					                               <label for="{$label_attr.for}" class="control-label">{$label}: </label>

                                                   <div>
	                                                   <label class="radio-inline">
	                                                      <input type="radio" name="{$name}" value="1" {if $value == 1}checked="checked"{/if}> {intl l='Yes'}
	                                                   </label>
	                                                   <label class="radio-inline">
	                                                       <input type="radio" name="{$name}" value="0" {if $value == 0}checked="checked"{/if}> {intl l='No'}
	                                                    </label>
                                                    </div>

                                                   <span class="help-block">{intl l='If yes, redirections through Redirect::exec() will be displayed as links'}</span>
					                           </div>
					                        {/form_field}

					                        {form_field field='files'}
					                           <div class="form-group {if $error}has-error{/if}">
					                               <label for="{$label_attr.for}" class="control-label">{$label}: </label>

					                               <div class="form-group">
					                                   <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='File names'}">
					                               </div>

					                               <span class="help-block">{intl l='Enter one or more file names without path separated by ";". Use "!" before a file name to exclude it. Use "*" to activate logs for all files.'}</span>
					                           </div>
					                        {/form_field}

                                            {form_field field='ip_addresses'}
                                               <div class="form-group {if $error}has-error{/if}">
                                                   <label for="{$label_attr.for}" class="control-label">{$label}: </label>

                                                   <div class="form-group">
                                                       <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='IP Addresses'}">
                                                   </div>

                                                   <span class="help-block">{intl l='Enter one or more IP V4 addresses separated by ";". Leave empty to display logs for all IP addresses'}</span>
                                                   <span class="help-block">{intl l='Your current IP address is %ip' ip={$ip_address}}</span>
                                               </div>
                                            {/form_field}

                                        </fieldset>

                                    </div>

                                    <div class="col-md-6">
                                        <p class="title title-without-tabs">{intl l='Destinations'}</p>

                                        <div class="alert alert-info">
                                            {intl l='The destinations processes logs to display, store or send them. You can select and configure zero, one or more destinations below.'}
                                        </div>

                                        <fieldset>
                                        {foreach $destinations as $classname => $destination}
	                                        {$active = in_array(get_class($destination), $active_destinations)}
	                                        <div class="well well-sm">
	                                            <input type="hidden" name="destinations[{$classname}][classname]" value="{get_class($destination)}" />

	                                            <p class="title title-without-tabs">{$destination->getTitle()}</p>
	                                            <p>{$destination->getDescription()}</p>

	                                            <div class="form-group">
	                                                <div>
	                                                    <label class="checkbox control-label">
	                                                       <input type="checkbox" class="activation-checkbox" name="destinations[{$classname}][active]" value="{$classname}" {if $active}checked="checked"{/if}> {intl l='Activate this log destination'}
	                                                    </label>
	                                                 </div>
	                                            </div>

                                                {if count($destination->getConfigs()) > 0}
		                                            <div class="config config-{$classname}" {if ! $active}style="display: none"{/if}>
			                                            {foreach $destination->getConfigs() as $config}
			                                                <div class="form-group">
			                                                    <label>{$config->getTitle()}</label>
				                                                {if $config->getType() == 2}
				                                                    <input  class="form-control" type="text" name="config[{$classname}][{$config->getName()}]" value="{$config->getValue()}" />
			                                                    {else if $config->getType() == 1}
			                                                        <textarea  class="form-control" name="config[{$classname}][{$config->getName()}]">{$config->getValue()}</textarea>
				                                                {/if}
			                                                   <span class="help-block">{$config->getLabel()}</span>
			                                                </div>
			                                            {/foreach}
		                                            </div>
	                                            {/if}

	                                        </div>
                                        {/foreach}
                                        </fieldset>

                                    </div>
	                            </div>
							</form>
							{/form}
						</div>
					</div>
				</div>
			</div>
		</div>
    </div>
</div>
{/block}

{block name="javascript-initialization"}
<script>
$(function() {
    $('.activation-checkbox').click(function(ev) {

        var classname = $(this).val();

        if ($(this).is(':checked')) {
            $('.config-'+classname).slideDown();
        }
        else {
            $('.config-'+classname).slideUp();
        }
    });
});
</script>
{/block}

{block name="javascript-last-call"}
    {hook name="system.logs-js" location="system-logs-js" }
{/block}