<?php
global $gdb, $config, $db;
ob_start();
$privileges = $this->privileges;
?>
<div class="form-group">
  <label class="col-lg-3 control-label">Uprawnienia użytkownika:</label>
  <div class="col-lg-9">
    <div class="row">
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="page_administration" id="page_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'page_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="page_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Strony</label>
      </div>
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline ps">

            <input type="checkbox" name="privileges" value="article_administration" id="article_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'article_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="article_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Artykuły</label>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="scontainers_administration" id="scontainers_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'scontainers_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="scontainers_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Zawartość statyczna</label>
      </div>
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="fileManager_administration" id="fileManager_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'fileManager_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="fileManager_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Menadżer plików</label>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="baners_administration" id="baners_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'baners_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="baners_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Banery</label>
      </div>
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="emails_administration" id="emails_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'emails_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="emails_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Skrzynka pocztowa</label>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="newsletter_administration" id="newsletter_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'newsletter_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="newsletter_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Newsletter</label>
      </div>
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="users_administration" id="users_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'users_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="users_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Użytkownicy</label>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="language_administration" id="language_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'language_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="language_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Języki</label>
      </div>
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="settings_administration" id="settings_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'settings_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="settings_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Ustawienia</label>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="template_administration" id="template_administration"
              <?
              foreach ($privileges as $pri)
              {
                if ($pri['name'] == 'template_administration')
                {
                  echo 'checked=checked';
                }
              }
              ?>>
            <label for="template_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Szablony strony</label>
      </div>
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="backups_administration" id="backups_administration" <? foreach ($privileges as $pri) if ($pri['name'] == 'backups_administration') echo 'checked=checked'; ?>>
            <label for="backups_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Kopia zapasowa</label>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-12 col-md-6">
        <div class="col-md-2 pt5">
          <div class="switch switch-primary round switch-inline">
            <input type="checkbox" name="privileges" value="seo_administration" id="seo_administration" <? foreach ($privileges as $pri) if ($pri['name'] == 'seo_administration') echo 'checked=checked'; ?>>
            <label for="seo_administration"></label>
          </div>
        </div>
        <label class="col-md-10 control-label text-left ps">Dodatkowe ustawienia SEO</label>
      </div>
      <div class="col-xs-12 col-md-6">

      </div>
    </div>
  </div>
</div>
<?
$this->user['id'] ? $password_param = 'optional' : $password_param = 'require';
$out = ob_get_clean();

$grid = new \gridEdit;
$grid->gdb_opt = $gdb;
$grid->include_plugins = true;
$grid->title = 'Zapisz użytkownika';
$grid->fields = [
  [
    'db'    => 'id',
    'type'  => 'hidden',
    'value' => $this->user['id']
  ], [
    'db'    => 'admin',
    'type'  => 'hidden',
    'value' => '1'
  ], [
    'name' => 'Login',
    'db' => 'login',
    'type' => 'text',
    'value' => $this->user['login'],
    'params' => ['class' => 'require', 'function' => 'check_login']
  ], [
    'name' => 'Aktywny',
    'db' => 'status',
    'type' => 'input_switch',
    'checked' => $this->user['status'] ? true : false
  ], [
    'db' => 'twofa_enabled',
    'name' => 'Dwustopniowe uwierzytelnianie (2FA)',
    'type' => 'input_switch',
    'checked' => $this -> user['twofa_enabled'] ? true : false,
  ], [
    'db' => 'twofa_email',
    'name' => 'E-mail do 2FA',
    'type' => 'text',
    'value' => $this -> user['twofa_email'],
  ], [
    'name' => 'Aktywny do',
    'db' => 'active_to',
    'type' => 'text',
    'id' => 'active_to',
    'value' => $this->user['active_to'] == '0000-00-00' ? '' : $this->user['active_to']
  ],
  [
    'name' => 'Hasło',
    'db' => 'password',
    'type' => 'password',
    'params' => ['class' => $password_param, 'min' => 5]
  ],
  [
    'name' => 'Hasło - powtórz',
    'db' => 'password_re',
    'type' => 'password',
    'params' => ['class' => $password_param, 'min' => 5, 'equal' => 'password', 'error_txt' => 'Podane hasła są różne']
  ]
];
$grid->actions = [
  'save' => ['url' => '/admin/users/user_save/', 'back_url' => '/admin/users/view_list/'],
  'cancel' => ['url' => '/admin/users/view_list/']
];
$grid->external_code = $out;
$grid->persist_edit = true;
echo $grid->draw();
?>

<script type="text/javascript">
  $(function() {
    disable_menu();
  });

  function check_login() {
    var response = null;

    $.ajax({
      type: 'POST',
      cache: false,
      async: false,
      url: '/admin/ajax.php',
      data: {
        a: 'check_login',
        login: $.trim($('#login').val()),
        user_id: <?= (int) $this->user['id']; ?>
      },
      success: function(data) {
        response = $.parseJSON(data);
      }
    });
    return response;
  };
  $(function() {
    $('#active_to').addClass('date');

    $('input[type="text"].date').datetimepicker({
      format: "YYYY-MM-DD",
      pickTime: false
    });
  });
</script>