<? global $lang; ?>
<fieldset>
	<form method='POST' action='index.php?page_type=layout' id='formularz' enctype='multipart/form-data'>
	<input type='hidden' name='rw' value='<?=$this -> _rw;?>'>
  <?
  if ( $this -> _rw == 'save_new' )
  {
    ?><input type='hidden' name='<?=base64_encode("time");?>' value='<?=base64_encode(date("Y-m-d H:i:s"));?>'><?
  }
  else if ( $this -> _rw == 'save' )
  {
    ?><input type='hidden' id="idk" name='id' value='<?=$this -> _id;?>'><?
  }
  ?>
  <div class="edit_line">
    <label><?=ucfirst( $lang -> getTrans( 'T_NAZWA' ) );?>:</label>
    <div class="input">
      <input style='width:200px;' type='text' id='name' name='name' value='<? if ( isset( $this -> _name ) ) echo $this -> secureHTML( $this -> _name );?>'>
    </div>
  </div>
    
  <div class="edit_line">
    <label><?=ucfirst( $lang -> getTrans( 'T_AKTYWNY' ) );?>:</label>
    <div class="input">
      <input type="radio" name="enabled" class="enabled" id="enabled_0" value='0' <? if ( !isset( $this -> _enabled ) || $this -> _enabled == 0 ) echo 'checked="checked" '; ?>>
      <?=$lang -> getTrans( 'T_NIE' );?>
      <input type="radio" name="enabled" class="enabled" id="enabled_1" value='1' <? if ( isset( $this -> _enabled ) && $this -> _enabled == 1 ) echo 'checked="checked" '; ?>>
      <?=$lang -> getTrans( 'T_TAK' );?>
    </div>
  </div>
    
  <div class="edit_line">
    <label><?=ucfirst( $lang -> getTrans( 'T_STRONY' ) );?>:</label>
    <div class="input">
      <table class='t_category'>
			<?
				$i=0;
				if ( is_array( $this -> _pages ) ) foreach ( $this -> _pages as $page )
				{
					if ( $i%3 == 0 )
					{
						?><tr><?
					}
					?>
						<td style='width:33%;'>
							<input type='checkbox' name='pages[]' value='<?=$page -> get_id();?>' style='width:15px;'
								<?
								if ( $this -> _rw == 'save' && is_array( $this -> _pages_act ) && in_array( $page -> get_id() , $this -> _pages_act ) )
								{
									?>checked='checked'<?
								}
								?>
							><?=$page -> get_title();?>
						</td>
					<?
					if ( $i%3 == 2 )
					{
						?></tr><?
					}
					$i++;
				}
			?>
			</table>
    </div>
  </div>
    
  <div class="edit_line">
    <label><?=ucfirst( $lang -> getTrans( 'T_HTML' ) );?>:</label>
    <div class="input">
      <textarea name='html' class="text" id="html" cols="100" rows='50' style="width: 780px; height: 250px;"><? if ( isset( $this -> _html ) ) echo $this -> secureHTML( $this -> _html );?></textarea>
    </div>
  </div>
    
  <div class="edit_line">
    <label><?=ucfirst( $lang -> getTrans( 'T_CSS' ) );?>:</label>
    <div class="input">
      <textarea name='css' class="text" id="css" cols="100" rows='50' style="width: 780px; height: 250px;"><? if ( isset( $this -> _css ) ) echo $this -> secureHTML( $this -> _css );?></textarea>
    </div>
  </div>
    
  <div class="edit_line">
    <label><?=ucfirst( $lang -> getTrans( 'T_JAVASCRIPT' ) );?>:</label>
    <div class="input">
      <textarea name='js' class="text" id="js" cols="100" rows='50' style="width: 780px; height: 250px;"><? if ( isset( $this -> _js ) ) echo $this -> secureHTML( $this -> _js );?></textarea>
    </div>
  </div>
    
	</form>
</fieldset>
<script type="text/javascript">
function saveLayout()
{
	var id      = $("#idk").val();
	var name    = $("#name").val();
	var enabled = $(".enabled:checked").val();
	var html    = $("#html").val();
	var css     = $("#css").val();
	var js      = $("#js").val();
	var pages   = '';
	$('input:checkbox:checked').each(
	function() {
	  if ( pages != '' )
		pages = pages + ':';
	  pages = pages + $(this).val();
	}
	);
  $.prompt('<?=$lang -> getTrans( 'T_TRWA_ZAPISYWANIE' );?>');
  xajax_saveLayout( id , name , enabled , html , css , js , pages );
}
</script>