<script type="text/javascript" src="/libraries/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/libraries/ckeditor/adapters/jquery.js"></script>
<?
\Shared\Helpers\Helpers::set_session( 'admin', true );
global $db;

$_SESSION['rfm_akey'] = bin2hex(random_bytes(16));
$_SESSION['rfm_akey_expires'] = time() + 20*60;
$_SESSION['can_use_rfm'] = true;
$rfmAkeyJS = $_SESSION['rfm_akey'];

ob_start();
?>

<div id="settings-tabs">
  <ul class="resp-tabs-list settings-tabs">
    <li><i class="fa fa-wrench"></i>Ustawienia</li>
    <li><i class="fa fa-file"></i>Zawartość</li>
  </ul>
  <div class="resp-tabs-container settings-tabs">
    <div>
      <?= \Shared\Html\Html::input(
              array(
                      'label' => 'Nazwa',
                      'name'  => 'name',
                      'id'    => 'name',
                      'value' => $this -> banner['name'],
                      'class' => 'require'
      ) );
      ?>
      <?= \Shared\Html\Html::input_switch(
              array(
                      'label'   => 'Aktywny',
                      'name'    => 'status',
                      'checked' => $this -> banner['status'] == 1 or ! $this -> banner['id'] ? true : false
              )
      );
      ?>
      <?= Html::input(
              array(
                      'label' => 'Data rozpoczęcia',
                      'name'  => 'date_start',
                      'id'    => 'date_start',
                      'value' => $this -> banner['date_start'],
                      'class' => 'date'
              )
      );
      ?>
      <?= \Shared\Html\Html::input(
              array(
                      'label' => 'Data zakończenia',
                      'name'  => 'date_end',
                      'id'    => 'date_end',
                      'value' => $this -> banner['date_end'],
                      'class' => 'date'
      ) );
      ?>
      <?= \Shared\Html\Html::input_switch(
                  array(
                          'label'   => 'Slajder / Strona główna',
                          'name'    => 'home_page',
                          'checked' => $this -> banner['home_page'] == 1 ? true : false
                  )
          );
      ?>
    </div>
    <div>
      <div id="languages-main">
        <ul class="resp-tabs-list languages-main htabs">
          <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <li><?= $lg['name'];?></a></li>
                <? endif;?>
              <? endforeach;
            endif;?>
        </ul>
        <div class="resp-tabs-container languages-main">
          <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
            <? if ( $lg['status'] ):?>
              <div>
                <?= \Shared\Html\Html::input_icon(
                              array(
                                      'label'        => 'Obraz',
                                      'name'         => 'src[' . $lg['id'] . ']',
                                      'id'           => 'src_' . $lg['id'],
                                      'value'        => $this -> banner['languages'][ $lg['id'] ]['src'],
                                      'icon_content' => 'przeglądaj',
                                      'icon_js'      => "window.open ( '/libraries/filemanager-9.14.2/dialog.php?type=1&popup=1&field_id=src_" . $lg['id'] . "&akey=" . $rfmAkeyJS . "', 'mywindow', 'location=1,status=1,scrollbars=1, width=1100,height=700');"
                              )
                );
                ?>
                <?= \Shared\Html\Html::input(
                            array(
                                    'label' => 'Url',
                                    'name'  => 'url[' . $lg['id'] . ']',
                                    'id'    => 'url_' . $lg['id'],
                                    'value' => $this -> banner['languages'][ $lg['id'] ]['url']
                            )
                    );
                ?>
                <?= \Shared\Html\Html::textarea(
                            array(
                                    'label'  => 'Kod html',
                                    'name'   => 'html[' . $lg['id'] . ']',
                                    'id'     => 'html_' . $lg['id'],
                                    'value'  => $this -> banner['languages'][$lg['id']]['html']
                            )
                    );
                ?>
                <?= \Shared\Html\Html::textarea(
                            array(
                                    'label'  => 'Treść',
                                    'name'   => 'text[' . $lg['id'] . ']',
                                    'id'     => 'text_' . $lg['id'],
                                    'value'  => $this -> banner['languages'][$lg['id']]['text']
                            )
                    );
                ?>
                <script type="text/javascript">
                  $(function () {
                    $('#text_<?= $lg['id'];?>').ckeditor({
                      toolbar: 'MyTool',
                      height: '300'
                    });
                  });
                </script>
              </div>
            <? endif;?>
          <? endforeach; endif;?>
        </div>
        <div class="clear"></div>
      </div>
    </div>
  </div>
</div>
<?
$out = ob_get_clean();

$gridId = 'banner-edit';
$gridTitle = 'Edycja baneru';
$gridSaveUrl = '/admin/banners/save/';
$gridBackUrl = '/admin/banners/list/';
$gridHidden = [['name' => 'id', 'value' => $this -> banner['id']]];
$gridContent = $out;
$gridPersist = true;
include __DIR__ . '/../components/grid-edit-replacement.php';
?>
<script type="text/javascript">
  $(function ()
  {
    disable_menu();

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

    $( '#settings-tabs' ).easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'settings-tabs',
      type: 'vertical'
    });

    $('#languages-main').easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'languages-main'
    });

  });
</script>
<script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>
