<? \System::setSessionVar( 'admin', true );?>
<div class="edit-row">
	<form method='POST' action='./' id='formularz' enctype="multipart/form-data" name="article_edit">
    <? if ( !$this -> _article['id'] ):?>
      <input type='hidden' name='rw' value='add_new' />
      <input type='hidden' name='check' value='<?= mktime();?>' />
      <input type='hidden' id="idk" name='id' value='' />
    <? else:?>
      <input type='hidden' name='rw' value='save' />
      <input type='hidden' id="idk" name='id' value='<?= $this -> _article['id'];?>' />
      <input type="hidden" id="version" name="version" value="<?= $this -> _version;?>" />
    <? endif;?>      
    <div id="slider-code">
      <ul class="pager">
        <li><a rel="0" class="pagenum" href="#"><span class="badge">1</span>Ustawienia podstawowe</a></li>
        <li><a rel="1" class="pagenum" href="#"><span class="badge">2</span>Ustawienia zaawansowane</a></li>
        <li><a rel="2" class="pagenum" href="#"><span class="badge">3</span>Wyświetlanie</a></li>
        <li><a rel="3" class="pagenum" href="#"><span class="badge">4</span>Galeria</a></li>
        <li><a rel="4" class="pagenum" href="#"><span class="badge">5</span>Pliki</a></li>
        <li><a rel="5" class="pagenum" href="#"><span class="badge">6</span>Inne</a></li>
      </ul>
      <a class="buttons prev tip" href="#" title="Wstecz">
        <img src="../../images/system/img-left.png" />
      </a>
      <div class="viewport">
        <ul class="overview">
          <li>
            <div class="slide-title">Ustawienia podstawowe</div>
            <div id="tabs" class="tabs-container">
              <ul class="tabs">
                <?
                if ( is_array( $this -> _language ) ) foreach ( $this -> _language as $language )
                {
                  ?>
                  <li><a href="lang_<?=$language['id'];?>" class="li-tabs <? if ( !$j++ ) echo 'active';?>"><?=$language['name'];?></a></li>
                  <?
                }
                ?>
              </ul>
              <?
              if ( is_array( $this -> _language ) ) foreach ( $this -> _language as $language )
              {
                ?>
                <script type="text/javascript">
                  $(document).ready(function(){
                    $( 'textarea#text_<?= $language['id'];?>' ).ckeditor( {
                      toolbar : 'MyToolbar',
                      language: 'pl',
                      height:'250',
                      width: '900px',
                      extraPlugins : 'youtube'
                    });
                  });
                </script>

                <div id="lang_<?= $language['id'];?>" class="tabs-content <? if ( $i++ ) echo 'nondisplay';?>">

                  <div class="group">
                    <label>Tytuł:</label>
                    <div class="content">
                      <input type='text' id="title_<?= $language['id'];?>" name='title_<?= $language['id'];?>' value='<?= $this -> secureHTML( $language['title'] );?>' />
                    </div>
                  </div>
                  <div class="group">
                    <label>Treść:</label>
                    <div class="content">
                      <textarea name='text_<?=$language['id'];?>' id='text_<?=$language['id'];?>' class='text' rows='10' cols='10'><?=$this -> eprint( $language['text'] );?></textarea>
                    </div>
                    <div class="clearfix"></div>
                  </div>
                  <div class="group">
                    <label>Link seo:</label>
                    <div class="content">
                      <input type='text' id="seo_link_<?= $language['id'];?>" name='seo_link_<?= $language['id'];?>' value='<?= $this -> secureHTML( $language['seo_link'] );?>' />
                      <a href="#" onclick="xajax_generateSeoLink( '<?= $language['id'];?>', $( title_<?= $language['id'];?> ).val() )">
                        <i class="icon refresh" style="position: relative; top: 3px; margin: 0;"></i>
                        generuj
                      </a>
                    </div>
                  </div>
                  <div class="group">
                    <label>Meta description:</label>
                    <div class="content">
                      <textarea id="meta_description_<?= $language['id'];?>" name='meta_description_<?= $language['id'];?>' cols='60' rows='5'><?= $language['meta_description'];?></textarea>
                    </div>
                    <div class="clearfix"></div>
                  </div>
                  <div class="group">
                    <label>Meta keywords:</label>
                    <div class="content">
                      <textarea id="meta_keywords_<?= $language['id'];?>" name='meta_keywords_<?= $language['id'];?>' cols='60' rows='5'><?= $language['meta_keywords'];?></textarea>
                    </div>
                    <div class="clearfix"></div>
                  </div>
                  <div style="clear: both;"></div>
                </div>
                <?
              }
              ?>
            </div>
          </li>
          <li>
            <div class="slide-title">Ustawienia zaawansowane</div>
            <div class="tabs-container">
              <div class="group">
                <label>Opublikowany:</label>
                <div class="content">
                  <input type="radio" name="enabled" class="enabled" id="enabled_0" value="0" <? if ( !$this -> _article['enabled'] ):?>checked='checked'<? endif;?> />
                  nie
                  <input type="radio" name='enabled' class="enabled" id="enabled_1" value='1' <? if ( $this -> _article['enabled'] || !$this -> _article ):?>checked='checked'<? endif;?> />
                  tak
                </div>
              </div>
              <div class="group">
                <label>Drukuj:</label>
                <div class="content">
                  <input type="radio" name="print" class="print" id="print_0" value="0" <? if ( !$this -> _article['print'] ):?>checked='checked'<? endif;?> />
                  nie
                  <input type="radio" name="print" class="print" id="print_1" value="1" <? if ( $this -> _article['print'] ):?>checked='checked'<? endif;?> />
                  tak
                </div>
              </div>
              <div class="group">
                <label>Pokaż tytuł:</label>
                <div class="content">
                  <input type="radio" name="show_title" class="show_title" id="show_title_0" value="0" <? if ( !$this -> _article['show_title'] ):?>checked='checked'<? endif;?> />
                  nie
                  <input type="radio" name="show_title" class="show_title" id="show_title_1" value="1" <? if ( $this -> _article['show_title'] || !$this -> _article ):?>checked='checked'<? endif;?> />
                  tak
                </div>
              </div>
              <div class="group">
                <label>Podmień tytuł z menu:</label>
                <div class="content">
                  <input type="radio" name="replace_menu_title" class="replace_menu_title" id="replace_menu_title_0" value="0" <? if ( !$this -> _article['replace_menu_title'] ):?>checked='checked'<? endif;?> />
                  nie
                  <input type="radio" name="replace_menu_title" class="replace_menu_title" id="replace_menu_title_1" value="1" <? if ( $this -> _article['replace_menu_title'] ):?>checked='checked'<? endif;?> />
                  tak
                </div>
              </div>
              <div class="group">
                <label>Pokaż datę:</label>
                <div class="content">
                  <input type="radio" name="show_date" class="show_date" id="show_date_0" value="0" <? if ( !$this -> _article['show_date'] ):?>checked='checked'<? endif?> />
                  nie
                  <input type="radio" name="show_date" class="show_date" id="show_date_1" value="1" <? if ( $this -> _article['show_date'] ):?>checked='checked'<? endif?> />
                  tak
                </div>
              </div>
              <div class="group">
                <label>Pokaż autora:</label>
                <div class="content">
                  <input type="radio" name="show_author" class="show_author" id="show_author_0" value="0" <? if ( !$this -> _article['show_author'] ):?>checked='checked'<? endif;?> />
                  nie
                  <input type="radio" name="show_author" class="show_author" id="show_author_1" value="1" <? if ( $this -> _article['show_author'] ):?>checked='checked'<? endif;?> />
                  tak
                </div>
              </div>
              <div class="group">
                <label>Wersjonowanie:</label>
                <div class="content">
                  <input type="radio" name="keep_archive" class="keep_archive" id="keep_archive_0" value="0" <? if ( !$this -> _article['keep_archive'] ):?>checked='checked'<? endif;?> />
                  nie
                  <input type="radio" name="keep_archive" class="keep_archive" id="keep_archive_1" value="1" <? if ( $this -> _article['keep_archive'] ):?>checked='checked'<? endif;?> />
                  tak
                </div>
              </div>      
              <div class="group">
                <label>Komenatrze:</label>
                <div class="content">
                  <input type="radio" name="comments_enabled" class="comments_enabled" id="comments_enabled_0" value="0" <? if ( !$this -> _article['comments_enabled'] ):?>checked='checked'<? endif;?> />
                  nie
                  <input type="radio" name="comments_enabled" class="comments_enabled" id="comments_enabled_1" value="1" <? if ( $this -> _article['comments_enabled'] ):?>checked='checked'<? endif;?> />
                  tak
                </div>
              </div>   
            </div>
          </li>
          <li>
            <div class="slide-title">Wyświetlanie</div>
            <div class="tabs-container">
              <div class="group">
                <select name="layout" id="layout" style="margin: 0 20px; width: 255px;">
                  <option value="">---- szablon domyślny ----</option>
                  <?
                  if ( is_array( $this -> _layouts ) ) foreach ( $this -> _layouts as $layout )
                  {
                    echo '<option value="' . $layout['id'] . '" ';
                      if ( $this -> _layout == $layout['id'] )
                        echo 'selected="selected"';
                    echo '>' . $layout['name'] . '</option>';
                  }
                  ?>
                </select>
              </div>
              <div class="group" style="padding: 10px 15px; line-height: 20px;">
                <?= \admin\view\Articles::drawArticleEditPages( $this -> _pages, 0 );?>
                <div class="clearfix"></div>
              </div>
            </div>
          </li>
      </form>
          <li>
            <div class="slide-title">Galeria</div>
            <div class="tabs-container">
              <div class="group">
                <?
                if ( !$this -> _article['id'] )
                  echo '<div style="padding: 20px;">Aby dodawać zdjęcia należy wcześniej zapisać artykuł.</div>';
                ?>
                <div id="article_galeries">
                  <ul id="image-list">
                    <?
                    $img_count = 0;
                    if ( is_array( $this -> _images ) ) foreach ( $this -> _images as $img )
                    {
                      echo '<li id="li_' . $img['id'] . '" style="background: url( \'/resources/thumber.php?img=/' . $img['src'] . '\' ) no-repeat center;">';
                        echo '<span class="sm2_delete" onClick="xajax_deleteArticleImg(' . $img['id'] . ');"></span>';
                      echo '</li>';
                      $img_count++;
                    }
                    ?>
                  </ul>
                </div>
                <div class="clearfix" style="margin-bottom: 20px;"></div>
                <? if ( $this -> _article['id'] ):?>
                  <div id="flash_uploader" style="height: 280px; margin: 10px;">You browser doesn't have Flash installed.</div>
                <? endif;?> 
              </div>
            </div>
          </li>
          <li>
            <div class="slide-title">Pliki</div>
            <div class="tabs-container">
              <div class="group">
                <?
                if ( !$this -> _article['id'] )
                  echo '<div style="padding: 20px;">Aby dodawać pliki należy wcześniej zapisać artykuł.</div>';
                ?>
                <ul id="files-list">
                  <?
                  $file_count = 0;
                  if ( is_array( $this -> _files ) ) foreach ( $this -> _files as $file )
                  {
                    echo '<li id="file_li_' . $file['id'] . '">';
                      echo '<div class="file" id="file_id_' . $file['id'] . '">';
                        echo '<span class="sm2_edit" onClick="manageFile( ' . $file['id'] . ' );"></span>';
                        if ( $file['name'] != '' )
                          echo $file['name'];
                        else
                          echo $file['file'];
                      echo '</div>';
                    echo '</li>';
                    $file_count++;
                  }
                  ?>
                </ul>
                <div class="clearfix" style="margin-bottom: 20px;"></div>

                <? if ( $this -> _article['id'] ):?>
                  <div id="flash_uploader_files" style="height: 280px;">You browser doesn't have Flash installed.</div>
                <? endif;?>
              </div>
            </div>
          </li>
          <li>
            <div class="slide-title">Inne</div>
            <div class="tabs-container">
              <div class="group">
                <label>Miniaturka:</label>
                <div class="content">
                  <? if ( $this -> _article['id'] ):?>
                    <form id="send-thumbnail" action="../resources/upload-thumbnails.php?hash=22292f4756dfed68e8397e356c28b32a" method="post" enctype="multipart/form-data">
                      <input type="file" name="thumbnails" accept="image/*" />
                      <input type="hidden" name="article_id" value="<?= $this -> _article['id'];?>" />
                      <input type="submit" value="Wyślij" class="button" style="padding: 3px 12px;" />
                    </form>
                    <div id="progress">
                      <div id="bar"></div>
                      <div id="percent">0%</div >
                    </div>
                    <div id="thumbnail-container">
                      <? if ( $this -> _article['thumbnail'] ):?>
                        <a class="delete_img_link thumbnail-delete" style="display: block;" onClick="$.prompt( 'Na pewno chcesz usunąć miniaturkę?', { title: 'Potwierdź?', submit: function(e,v,m,f) {  if ( v == true ) deleteArticleThumbnail(); }, buttons: { 'tak': true, 'nie': false }, focus: 1 } );">usuń</a>
                        <img src="../resources/thumber.php?img=<?= $this -> _article['thumbnail'];?>&h=150&w=150" class="thumbnail" style="border: 1px solid #E0E4E8;" />
                      <? endif;?>
                    </div>
                  <? else:?>
                    Aby dodać miniaturkę należy wcześniej zapisać artykuł.
                  <? endif;?>
                </div>
                <div class="clearfix"></div>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <a class="buttons next tip" href="#" title="Dalej">
        <img src="../../images/system/img-right.png" />
      </a>
    </div>

<div class="img_bg"></div>
<div class="img_big"></div>

<div class="plik_bg"></div>

<div class="plik_edycja">  
  <div class="group">
    <label style="width: 60px;">Nazwa:</label>
    <div class="content">
      <input type="text" id="name" style="width: 350px;" />
    </div>
  </div>  
  <div class="group">
    <label style="width: 60px;"></label>
    <div class="content">
      <a class="a-action" onClick="xajax_saveArticleFileInfo( jQuery( '#file_edit_id' ).val(), jQuery( '#name' ).val() )">zapisz</a>
      <a class="a-action" onClick="jQuery( '.plik_bg, .plik_edycja' ).hide();">anuluj</a>
    </div>
  </div>  
  <div class="group">
    <label style="width: 60px;"></label>
    <div class="content">
      <a class="delete_img_link" onClick="xajax_deleteArticleFile( jQuery( '#file_edit_id' ).val() )">usuń</a>
    </div>
  </div>  
  <input type="hidden" id="file_edit_id" />
</div>

<link rel="stylesheet" href="../resources/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" />

<script type="text/javascript" src="../resources/plupload/plupload.js"></script>
<script type="text/javascript" src="../resources/plupload/plupload.flash.js"></script>
<script type="text/javascript" src="../resources/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="../resources/plupload/i18n/pl.js"></script>
<script type="text/javascript" src="../resources/jquery/jquery.form.js"></script>

<script type="text/javascript">
  var img_count   = <?= $img_count;?>;
  var file_count  = <?= $file_count;?>;
  <?
  if ( $this -> _article['id'] )
  {
    ?>                  
    function deleteArticleThumbnail(){
      xajax_deleteArticleThumbnail( <?= $this -> _article['id'];?> )
    }
    
    $(function() {      
      
      var options = { 
        beforeSend: function() 
        {
          $( "#progress" ).show();
          $( "#bar" ).width( '0%' );
          $( "#message" ).html( "" );
          $( "#percent" ).html( "0%" );
        },
        uploadProgress: function(event, position, total, percentComplete) 
        {
          $( "#bar" ).width( percentComplete + '%' );
          $( "#percent" ).html( percentComplete + '%' );
        },
        success: function() 
        {
          $( "#bar" ).width( '100%' );
          $( "#percent" ).html( '100%' );
        },
        complete: function(response) 
        {
//          $("#message").html("<font color='green'>"+response.responseText+"</font>");
          $( '#thumbnail-container' ).html( '' );
          $( '#thumbnail-container' ).html( '<a class="delete_img_link thumbnail-delete" style="display: block;" onClick="$.prompt( \'Na pewno chcesz usunąć miniaturkę?\',{ callback: deleteArticleThumbnail, buttons: { tak: true, nie: false }, focus: 1 })">usuń</a><img src="../resources/thumber.php?img=' + response.responseText + '&h=150&w=150" class="thumbnail" style="border: 1px solid #E0E4E8;" />' );
                      
        }
      }; 
      $( "#send-thumbnail" ).ajaxForm( options );
      
      jQuery( '.plik_bg' ).click( function(){        
        jQuery( this ).hide();
        jQuery( '.plik_edycja' ).hide();
      })
      
      $("#flash_uploader").pluploadQueue({
        runtimes : 'flash',
        init : {
          Refresh: function(up) {
            $(".plupload_buttons").css("display", "inline");
            $(".plupload_upload_status").css("display", "inline");
            $(".plupload_start").addClass("plupload_disabled");
            $(".plupload_start").removeClass("plupload_disabled");        
          },

          FileUploaded: function(up, file, response) {        
            data = jQuery.parseJSON(response.response);
            jQuery('#image-list').append('<li id="li_' + data.id_img + '" style="background: url( \'/resources/thumber.php?img=' +  data.data_link + '\' ) no-repeat center;">'
              + '<span class="sm2_delete" onclick="xajax_deleteArticleImg(' + data.id_img + ');"></span>' 
              + '</li>');
            img_count++;
          }
        },
        url : '../resources/upload.php?article_id=<?= $this -> _article['id'];?>&hash=22292f4756dfed68e8397e356c28b32a',
        chunk_size : '1mb',
        unique_names : true,
        filters : [
          {title : "Obrazki", extensions : "jpg,gif,png,bmp,jpeg"}
        ],
        resize : {width : 1920, height : 1080, quality : 100},
        flash_swf_url : '../resources/plupload/plupload.flash.swf'
      });

      $("#flash_uploader_files").pluploadQueue({
        runtimes : 'flash',
        init : {
          Refresh: function(up) {
            $(".plupload_buttons").css("display", "inline");
            $(".plupload_upload_status").css("display", "inline");
            $(".plupload_start").addClass("plupload_disabled");
            $(".plupload_start").removeClass("plupload_disabled");        
          },

          FileUploaded: function(up, file, response) {           
            data = jQuery.parseJSON(response.response);
            jQuery('#files-list').append('<div class="file" id="file_li_' + data.id_file + '"><span class="sm2_edit" onClick="manageFile( ' + data.id_file + ' );"></span>' + data.data_link + '</div>' );
            file_count++;
          }
        },
        url : '../resources/upload_files.php?article_id=<?= $this -> _article['id'];?>&hash=22292f4756dfed68e8397e356c28b32a',
        chunk_size : '1mb',
        unique_names : false,
        filters : [
          {title : "Wszystkie pliki", extensions : "*"}
        ],
        flash_swf_url : '../resources/plupload/plupload.flash.swf'
      });
    });
    <?
  }
  ?>
    
  function manageFile( id ) 
  {
    jQuery( '.plik_edycja, .plik_bg' ).show();
    jQuery( '#file_edit_id' ).val( id );
    jQuery( '#name' ).val( '' );
    xajax_articleFileInfo( id );
  }
  ckeditor = true;

  $(document).ready(function()
  {    
    $( '#slider-code' ).tinycarousel({
      pager: true
    });
    
    $( ".tabs a" ).click( function () 
    {
			$( ".tabs .active" ).removeClass( "active" );
			$( this ).addClass( "active" );
			$( ".tabs-content" ).addClass( 'nondisplay' );
			var content_show = $( this ).attr( "href" );
			$( '#' + content_show ).removeClass( 'nondisplay' );
		  return false;
		});
    
    $( '.toggle-pages' ).click( function() {
      if ( $( this ).hasClass( 'show' ) )
      {
        $( this ).removeClass( 'show' ).addClass( 'hide' );
        $( '.' + $( this ).attr( 'id' ) ).show();
      }
      else
      {
        $( this ).removeClass( 'hide' ).addClass( 'show' );
        $( '.' + $( this ).attr( 'id' ) ).hide();
      }
    })

    $( '.select-page' ).click( function() {
      var id = $( this ).attr( 'idk' );
      
      if ( $( '#page_' + id ).prop( 'checked' ) )
        $( '#page_' + id ).prop( "checked", false );
      else
        $( '#page_' + id ).prop( "checked", true );
    })

    $( '.img_bg' ).click( function(){        
      $( this ).hide();
      $( '.img_big' ).hide();
    })

    $( '#image-list li' ).hover(
      function(){
        $( this ).children( 'div' ).css( { 'display' : 'block', 'margin-top' : '-26px' });
      },
      function(){
        $( this ).children( 'div' ).hide();
      }
    )
  });

  function saveArticle()
  {
    $.prompt( 'Trwa zapisywanie...' );
    var id                = $("#idk").val();
    var enabled           = $( ".enabled:checked" ).val();
    var comments_enabled  = $( ".comments_enabled:checked" ).val();
    var print             = $( ".print:checked" ).val();
    var show_title        = $( ".show_title:checked" ).val();
    var show_date         = $( ".show_date:checked" ).val();
    var show_author       = $( '.show_author:checked' ).val();
    var keep_archive      = $( '.keep_archive:checked' ).val();
    var replace_menu      = $( '.replace_menu_title:checked' ).val();
    var layout            = $( '#layout' ).val();
    var pages             = '';
    $('input.art_pages:checked').each(
      function() {
        if ( pages != '' )
          pages = pages + ':';
        pages = pages + $(this).val();
      }
    );
    xajax_saveArticle( id, enabled, comments_enabled, print, show_title, show_date, pages, show_author, keep_archive, layout, replace_menu );
  }

  function saveArticleTranslation( new_article ) 
  {
    var id            = $("#idk").val();
    var title         = new Object();
    var meta_o        = new Object();
    var meta_d        = new Object();
    var text          = new Object();
    var seo_link      = new Object();
    var keep_archive  = $( '.keep_archive:checked' ).val();
    var version       = $( '#version' ).val();
    <?
    if ( is_array( $this -> _language ) ) foreach ( $this -> _language as $language )
    {
      echo 'title["' . $language['id'] . '"] = $("#title_' . $language['id'] . '").val();' . chr( 13 ) . chr( 10 );
      echo 'meta_o["' . $language['id'] . '"] = $("#meta_description_' . $language['id'] . '").val();' . chr( 13 ) . chr( 10 );
      echo 'meta_d["' . $language['id'] . '"] = $("#meta_keywords_' . $language['id'] . '").val();' . chr( 13 ) . chr( 10 );
      echo 'text["' . $language['id'] . '"] = $("#text_' . $language['id'] . '").val();' . chr( 13 ) . chr( 10 );
      echo 'seo_link["' . $language['id'] . '"] = $("#seo_link_' . $language['id'] . '").val();' . chr( 13 ) . chr( 10 );
    }
    ?>
    var count = 0;
    for ( var klucz in title) count++;

    var i = 0;
    for ( var klucz in title) 
    {
      i++;
      message = false;
      if ( i == count )
        message = true;
      xajax_saveArticleTranslation( klucz , id , title[klucz] , meta_o[klucz] , meta_d[klucz] , text[klucz] , message , keep_archive , version, seo_link[klucz], new_article );
    }
  }
</script>
<style type="text/css">
  .ui-widget-content {
    background: none !important;
    border: none !important;
  }  
  .ui-widget-header {
    border: none !important;
    background: none !important;
  }
  .ui-widget {
    font-family: inherit !important;
  }
  .ui-tabs .ui-tabs-panel {
    padding: 0px !important;
  }
</style>