<script type="text/javascript" src="/libraries/framework/vendor/plugins/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/libraries/framework/vendor/plugins/ckeditor/adapters/jquery.js"></script>
<?
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-file"></i>Ogólne</li>
      <li><i class="fa fa-file"></i>Opis</li>
      <li><i class="fa fa-globe"></i>SEO</li>
    </ul>
    <div class="resp-tabs-container settings-tabs">
      <div>
        <?= \Html::input( [
                      'label' => 'Nazwa',
                      'class' => 'require',
                      'name' => 'name',
                      'id' => 'name',
                      'value' => $this -> producer['name']
                    ] );?>
        <?= \Html::input_switch( [
                      'label' => 'Aktywny',
                      'name' => 'status',
                      'checked' => $this -> producer['status'] == 1 ? true : false
                    ] );?>
        <?= \Html::input_icon( [
                    'label' => 'Logo',
                    'name' => 'img',
                    'id' => 'img',
                    'value' => $this -> producer['img'],
                    'icon_content' => 'przeglądaj',
                    'icon_js' => "window.open ( 'http://" . $_SERVER['SERVER_NAME'] . "/libraries/filemanager-9.14.2/dialog.php?type=1&popup=1&field_id=img&akey=" . $rfmAkeyJS . "', 'mywindow', 'location=1,status=1,scrollbars=1, width=1100,height=700');"
                ] );
        ?>
      </div>
      <div>
        <div class="languages-main">
          <ul class="resp-tabs-list languages-main htabs">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg[ 'status' ] ):?>
                <li><? if ( $lg[ 'id' ] == \front\factory\Languages::default_language() ) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> ';?><?= $lg[ 'name' ];?></li>
              <? endif;?>
            <? endforeach; endif;?>
          </ul>
          <div class="resp-tabs-container languages-main">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
            <?
              $languages = array ();

              $languages[''] = '---- wersja językowa ----';
              if ( is_array( $this -> languages ) ) foreach ( $this -> languages as $lg_tmp )
              {
                if ( $lg_tmp[ 'id' ] != $lg[ 'id' ] )
                  $languages[ $lg_tmp[ 'id' ] ] = $lg_tmp[ 'name' ];
              }
              ?>
              <? if ( $lg[ 'status' ] ):?>
                <div>
                  <?= \Html::textarea( [
                        'label' => 'Opis',
                        'name' => 'description[' . $lg['id'] . ']',
                        'id' => 'description_' . $lg['id'],
                        'value' => $this -> producer['languages'][$lg[ 'id']]['description'],
                        'inline' => true
                    ] );?>
                  <?= \Html::textarea( [
                        'label' => 'Dane producenta',
                        'name' => 'data[' . $lg['id'] . ']',
                        'id' => 'data_' . $lg['id'],
                        'value' => $this -> producer['languages'][$lg[ 'id']]['data'],
                        'inline' => true
                    ] );?>
                  <script type="text/javascript">
                    $(function () {
                      $( '#data_<?= $lg[ 'id' ];?>').ckeditor({
                        toolbar: 'MyToolbar',
                        height: '250'
                      });

                      $( '#description_<?= $lg[ 'id' ];?>').ckeditor({
                        toolbar: 'MyToolbar',
                        height: '250'
                      });
                    });
                  </script>
                </div>
              <? endif;?>
            <? endforeach; endif;?>
          </div>
          <div class="clear"></div>
        </div>
      </div>
      <div>
        <div class="languages-main">
          <ul class="resp-tabs-list languages-main htabs">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg[ 'status' ] ):?>
                <li><? if ( $lg[ 'id' ] == \front\factory\Languages::default_language() ) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> ';?><?= $lg[ 'name' ];?></li>
              <? endif;?>
            <? endforeach; endif;?>
          </ul>
          <div class="resp-tabs-container languages-main">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
            <?
              $languages = array ();

              $languages[''] = '---- wersja językowa ----';
              if ( is_array( $this -> languages ) ) foreach ( $this -> languages as $lg_tmp )
              {
                if ( $lg_tmp[ 'id' ] != $lg[ 'id' ] )
                  $languages[ $lg_tmp[ 'id' ] ] = $lg_tmp[ 'name' ];
              }
              ?>
              <? if ( $lg[ 'status' ] ):?>
                <div>
                  <?= \Html::input( [
                        'label' => 'Meta title',
                        'name' => 'meta_title[' . $lg['id'] . ']',
                        'id' => 'meta_title_' . $lg[ 'id' ],
                        'value' => $this -> producer['languages'][$lg['id']]['meta_title']
                    ] );?>
                </div>
              <? endif;?>
            <? endforeach; endif;?>
          </div>
          <div class="clear"></div>
        </div>
      </div>
    </div>
  </div>
<?
$out = ob_get_clean();

$grid = new \gridEdit;
$grid -> id = 'producer-edit';
$grid -> gdb_opt = $gdb;
$grid -> include_plugins = true;
$grid -> title = 'Edycja producenta';
$grid -> fields = [
                    [
                      'db' => 'id',
                      'type' => 'hidden',
                      'value' => $this -> producer['id']
                    ]
                  ];
$grid -> actions = [
                      'save' => [ 'url' => '/admin/shop_producer/save/', 'back_url' => '/admin/shop_producer/list/' ],
                      'cancel' => [ 'url' => '/admin/shop_producer/list/' ]
                    ];
$grid -> external_code = $out;
$grid -> persist_edit = true;
$grid -> id_param = 'id';
echo $grid -> draw();
?>
<script type="text/javascript">
  $( function()
  {
    disable_menu();

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

    $('.languages-main').easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'languages-main'
    });
  });
</script>