{# **
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * #}
{% extends '@PrestaShop/Admin/layout.html.twig' %}
{% trans_default_domain 'Admin.Advparameters.Feature' %}

{% block content %}
<div class="row">
  <div class="col-lg-6">
    <div class="card" data-block="configuration_information">
      <h3 class="card-header">
        <i class="material-icons">info</i> {{ 'Configuration information'|trans }}
      </h3>
      <div class="card-body">
        <p class="mb-0">{{ 'You must provide this information when reporting an issue on GitHub or on the forum.'|trans }}</p>
      </div>
    </div>

    <div class="card" data-block="server_information">
      <h3 class="card-header">
        <i class="material-icons">info</i> {{ 'Server information'|trans }}
      </h3>
      <div class="card-body">
        {% if system.hostname is not empty %}
          <p class="mb-0">
            <strong>{{ 'Server Hostname:'|trans }}</strong> {{ system.hostname }}
          </p>
        {% endif %}
        {% if system.uname is not empty %}
          <p class="mb-0">
            <strong>{{ 'Server information:'|trans }}</strong> {{ system.uname }}
          </p>
        {% endif %}
        <p class="mb-0">
          <strong>{{ 'Server software version:'|trans }}</strong> {{ system.server.version }}
        </p>
        <p class="mb-0">
          <strong>{{ 'PHP version:'|trans }}</strong> {{ system.server.php.version }}
        </p>
        <p class="mb-0">
          <strong>{{ 'Memory limit:'|trans }}</strong> {{ system.server.php.memoryLimit }}
        </p>
        <p class="mb-0">
          <strong>{{ 'Max execution time:'|trans }}</strong> {{ system.server.php.maxExecutionTime }}
        </p>
        <p class="mb-0">
          <strong>{{ 'Upload Max File size:'|trans }}</strong> {{ system.server.php.maxFileSizeUpload }}
        </p>
        {% if system.instaWebInstalled %}
          <p class="mb-0">{{ 'PageSpeed module for Apache installed (mod_instaweb)'|trans }}</p>
        {% endif %}
      </div>
    </div>

    <div class="card" data-block="database_information">
      <h3 class="card-header">
        <i class="material-icons">info</i> {{ 'Database information'|trans({}, 'Admin.Advparameters.Feature') }}
      </h3>
      <div class="card-body">
        <p class="mb-0">
          <strong>{{ 'MySQL version:'|trans }}</strong> {{ system.database.version }}
        </p>
        <p class="mb-0">
          <strong>{{ 'MySQL server:'|trans }}</strong> {{ system.database.server }}
        </p>
        <p class="mb-0">
          <strong>{{ 'MySQL name:'|trans }}</strong> {{ system.database.name }}
        </p>
        <p class="mb-0">
          <strong>{{ 'MySQL user:'|trans }}</strong> {{ system.database.user }}
        </p>
        <p class="mb-0">
          <strong>{{ 'Tables prefix:'|trans }}</strong> {{ system.database.prefix }}
        </p>
        <p class="mb-0">
          <strong>{{ 'MySQL engine:'|trans }}</strong> {{ system.database.engine }}
        </p>
        <p class="mb-0">
          <strong>{{ 'MySQL driver:'|trans }}</strong> {{ system.database.driver }}
        </p>
      </div>
    </div>

    <div class="card" data-block="list_overrides">
      <h3 class="card-header">
        <i class="material-icons">info</i> {{ 'List of overrides'|trans({}, 'Admin.Advparameters.Feature') }}
      </h3>
      <div class="card-body">
        {% if system.overrides is empty %}
          <div class="alert alert-success mb-0" role="alert"><p class="alert-text">
            {{ 'No overrides have been found.'|trans({}, 'Admin.Advparameters.Feature') }}
          </p></div>
        {% else %}
          <ul>
            {% for override in system.overrides %}
              <li>{{ override }}</li>
            {% endfor %}
          </ul>
        {% endif %}
      </div>
    </div>
  </div>
  <div class="col-lg-6">
    <div class="card" data-block="store_information">
      <h3 class="card-header">
        <i class="material-icons">info</i> {{ 'Store information'|trans }}
      </h3>
      <div class="card-body">
        <p class="mb-0">
          <strong>{{ 'PrestaShop version:'|trans }}</strong> {{ system.shop.version }}
        </p>
        {{ renderhook('displayAdminStoreInformation') }}
        <p class="mb-0">
          <strong>{{ 'Shop URL:'|trans }}</strong> {{ system.shop.url }}
        </p>
        <p class="mb-0">
          <strong>{{ 'Shop path:'|trans }}</strong> {{ system.shop.path }}
        </p>
        <p class="mb-0">
          <strong>{{ 'Current theme in use:'|trans }}</strong> {{ system.shop.theme }}
        </p>
      </div>
    </div>

    <div class="card" data-block="mail_configuration">
      <h3 class="card-header">
        <i class="material-icons">info</i> {{ 'Mail configuration'|trans }}
      </h3>
      <div class="card-body">
        {% if system.isNativePHPmail %}
          <p class="mb-0">
            <strong>{{ 'Mail method:'|trans }}</strong> {{ 'You are using /usr/sbin/sendmail'|trans }}
          </p>
        {% else %}
          <p class="mb-0">
            <strong>{{ 'Mail method:'|trans }}</strong> {{ 'You are using your own SMTP parameters.'|trans }}
          </p>
          <p class="mb-0">
            <strong>{{ 'SMTP server:'|trans }}</strong> {{ system.smtp.server }}
          </p>
          <p class="mb-0">
            <strong>{{ 'SMTP username:'|trans }}</strong>
            {% if system.smtp.user is not empty %}
              {{ 'Defined'|trans }}
            {% else %}
              <span style="color:red;">{{ 'Not defined'|trans }}</span>
            {% endif %}
          </p>
          <p class="mb-0">
            <strong>{{ 'SMTP password:'|trans }}</strong>
            {% if system.smtp.password is not empty %}
              {{ 'Defined'|trans }}
            {% else %}
              <span style="color:red;">{{ 'Not defined'|trans }}</span>
            {% endif %}
          </p>
          <p class="mb-0">
            <strong>{{ 'Encryption:'|trans }}</strong> {{ system.smtp.encryption }}
          </p>
          <p class="mb-0">
            <strong>{{ 'SMTP port:'|trans }}</strong> {{ system.smtp.port }}
          </p>
        {% endif %}
      </div>
    </div>

    <div class="card" data-block="your_information">
      <h3 class="card-header">
        <i class="material-icons">info</i> {{ 'Your information'|trans }}
      </h3>
      <div class="card-body">
        <p class="mb-0">
          <strong>{{ 'Your web browser:'|trans }}</strong> {{ userAgent }}
        </p>
      </div>
    </div>

    <div class="card" id="checkConfiguration">
      <h3 class="card-header">
        <i class="material-icons">info</i> {{ 'Check your configuration'|trans }}
      </h3>
      <div class="card-body">
        {% if requirements.failRequired == false %}
          <p class="mb-0">
            <strong>{{ 'Required parameters:'|trans }}</strong>
            <span class="text-success">{{ 'OK'|trans({}, 'Admin.Advparameters.Notification') }}</span>
          </p>
        {% else %}
          <p class="mb-0">
            <strong>{{ 'Required parameters:'|trans }}</strong>
            <span class="text-danger">{{ 'Please fix the following error(s)'|trans({}, 'Admin.Advparameters.Notification') }}</span>
          </p>
          <ul>
            {% for key, value in requirements.testsRequired %}
              {% if 'fail' == value %}
                <li>{{ requirements.testsErrors[key] }}</li>
              {% endif %}
            {% endfor %}
          </ul>
        {% endif %}
        {% if requirements.failOptional is defined %}
          {% if requirements.failOptional == false %}
            <p class="mb-0">
              <strong>{{ 'Optional parameters:'|trans }}</strong>
              <span class="text-success">{{ 'OK'|trans({}, 'Admin.Advparameters.Notification') }}</span>
            </p>
          {% else %}
            <p class="mb-0">
              <strong>{{ 'Optional parameters:'|trans }}</strong>
              <span class="text-danger">{{ 'Please fix the following error(s)'|trans({}, 'Admin.Advparameters.Notification') }}</span>
            </p>
            <ul>
              {% for key, value in requirements.testsOptional %}
                {% if 'fail' == value %}
                  <li>{{ requirements.testsErrors[key] }}</li>
                {% endif %}
              {% endfor %}
            </ul>
          {% endif %}
        {% endif %}
      </div>
    </div>
  </div>
</div>

<div class="card" data-block="list_changed_files">
  <h3 class="card-header">
    <i class="material-icons">info</i> {{ 'List of changed files'|trans }}
  </h3>
  <div class="card-body" id="changedFiles">
    <i class="material-icons">loop</i> {{ 'Checking files...'|trans({}, 'Admin.Advparameters.Notification') }}
  </div>
</div>

<script>
  $(function()
  {
    var translations = {
      missing: '{{ 'Missing files'|trans({}, 'Admin.Advparameters.Notification')|e('js') }}',
      updated: '{{ 'Updated files'|trans({}, 'Admin.Advparameters.Notification')|e('js') }}',
      changesDetected: '{{ 'Changed/missing files have been detected.'|trans({}, 'Admin.Advparameters.Notification')|e('js') }}',
      noChangeDetected: '{{ 'No change has been detected in your files.'|trans({}, 'Admin.Advparameters.Notification')|e('js') }}'
    };

    $.ajax({
      type: 'POST',
      url: '{{ path('admin_system_information_check_files') }}',
      data: {},
      dataType: 'json',
      success: function(json)
      {
        var tab = {
          'missing': translations.missing,
          'updated': translations.updated,
        };

        if (json.missing.length || json.updated.length) {
          $('#changedFiles').html('<div class="alert alert-warning" role="alert"><p class="alert-text">' + translations.changesDetected + '</p></div>');
        } else {
          $('#changedFiles').html('<div class="alert alert-success mb-0" role="alert"><p class="alert-text">' + translations.noChangeDetected + '</p></div>');
        }

        $.each(tab, function(key, lang) {
          if (json[key].length) {
            var html = $('<ul>').attr('id', key+'_files');
            $(json[key]).each(function(key, file) {
              html.append($('<li>').html(file))
            });
            $('#changedFiles')
              .append($('<h4>').html(lang+' ('+json[key].length+')'))
              .append(html);
          }
        });
      }
    });
  });
</script>
{% endblock %}
