<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>
<?php
global $db;
ob_start();

  if ( \S::is_array_fix( $this -> product -> permutations ) )
  {
    foreach ( $this -> product -> permutations as $permutation )
    {
      ?>
        <div class="form-group row">
        <label class="col-lg-4 control-label default-value">
        <?
          $data = explode( '_', $permutation );
          foreach ( $data as $row )
          {
            echo \shop\ProductAttribute::getAttributeNameByValue( $row, \front\factory\Languages::default_language()) . ': <span class="text-muted">' . \shop\ProductAttribute::getValueName( $row, \front\factory\Languages::default_language() ) . '</span>';
            if ( $row !== end( $data ) )
              echo ' | ';
          }
      echo '</label>';
      echo '<div class="col-lg-8">';
      echo '<input type="text" class="form-control" name="permutation_' . $permutation . '" value="' . \shop\Product::getPermutationQuantity( $this -> product -> id, $permutation ) . '">';
      echo '</div>';
      echo '</div>';
    }
  }
  else
  {
    echo '<div class="form-group row">';
    echo ' <label class="col-lg-4 control-label default-value">Produkt bez atrybutów (lub z 1 atrybutem i jedną wartością):</label>';
    echo '<div class="col-lg-8">';
    echo '<input type="text" class="form-control" name="permutation_0" value="' . \admin\factory\ShopProduct::permutation_quantity( $this -> product -> id, 0 ) . '">';
    echo '</div>';
    echo '</div>';
  }
?>

<?php
$out = ob_get_clean();

$grid = new \gridEdit();
$grid -> id = 'stock';
$grid -> gdb_opt = $gdb;
$grid -> include_plugins = true;
$grid -> title = 'Stany magazynowe: <u>'.$this -> product -> language['name'].'</u>';
$grid -> fields = [
  [
    'db' => 'id',
    'type' => 'hidden',
    'value' => $this -> product -> id,
  ],
];
$grid -> actions = [
  'save' => ['url' => '/admin/shop_product/stock_save/', 'back_url' => '/admin/shop_product/view_list/'],
  'cancel' => ['url' => '/admin/shop_product/view_list/'],
                            ];
$grid -> external_code = $out;
$grid -> persist_edit = true;
$grid -> id_param = 'id';

echo $grid -> draw();
?>
<script type="text/javascript">
  $( function()
  {
    disable_menu();
  });
</script>
