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

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>
      <?= \Html::input(
              array(
                      'label' => 'Nazwa',
                      'name'  => 'name',
                      'id'    => 'name',
                      'value' => $this -> banner['name'],
                      'class' => 'require'
      ) );
      ?>
      <?= \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'
              )
      );
      ?>
      <?= \Html::input(
              array(
                      'label' => 'Data zakończenia',
                      'name'  => 'date_end',
                      'id'    => 'date_end',
                      'value' => $this -> banner['date_end'],
                      'class' => 'date'
      ) );
      ?>
      <?= \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">
          <? 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>
                <?= \Html::input_icon(
                              array(
                                      'label'        => 'Obraz',
                                      'name'         => 'src',
                                      'id'           => 'src_' . $lg['id'],
                                      'value'        => $this -> banner['languages'][ $lg['id'] ]['src'],
                                      'icon_content' => 'przeglądaj',
                                      'icon_js'      => "window.open ( '/libraries/filemanager-9.14.1/dialog.php?type=1&popup=1&field_id=src_" . $lg['id'] . "&akey=c3cb2537d25c0efc9e573d059d79c3b8', 'mywindow', 'location=1,status=1,scrollbars=1, width=1100,height=700');"
                              )
                );
                ?>
                <?= \Html::input(
                            array(
                                    'label' => 'Url',
                                    'name'  => 'url',
                                    'id'    => 'url_' . $lg['id'],
                                    'value' => $this -> banner['languages'][ $lg['id'] ]['url']
                            )
                    );
                ?>
                <?= \Html::textarea(
                            array(
                                    'label'  => 'Kod html',
                                    'name'   => 'html',
                                    'id'     => 'html_' . $lg['id'],
                                    'value'  => $this -> banner['languages'][$lg['id']]['html']
                            )
                    );
                ?>
                <?= \Html::textarea(
                            array(
                                    'label'  => 'Treść',
                                    'name'   => 'text',
                                    '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();

$grid                  = new \gridEdit;
$grid -> id              = 'banner-edit';
$grid -> gdb_opt         = $gdb;
$grid -> include_plugins = true;
$grid -> title           = 'Edycja baneru';
$grid -> fields          = [
        [
                'db'    => 'id',
                'type'  => 'hidden',
                'value' => $this -> banner['id']
        ]
];
$grid -> external_code   = $out;
$grid -> actions         = [
        'save'   => [ 'url' => '/admin/banners/banner_save/', 'back_url' => '/admin/banners/view_list/' ],
        'cancel' => [ 'url' => '/admin/banners/view_list/' ]
];
$grid -> persist_edit    = true;
$grid -> id_param        = 'id';
echo $grid -> draw();
?>
<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>