<?php
	include('includes/db.php'); 


	$type = trim($_GET['type']);
	$cat = trim($_GET['cat']);
	
	switch ($type): 						

		case 'category':
			$header="Kategorie";
			$sql="SELECT id, title FROM `$type`";  
		break;					
			
		case 'files':
			$header="Pliki";
			$a=explode('|',$cat);
			$sql="SELECT id, title, file FROM `$type` WHERE parent_id = '$a[0]' and parent = '$a[1]'";  
		break;	
				
													
		default:
			$header="error";
			$sql="error";  	
	endswitch;

	?>
    
       <div id="right_column">
        <!-- RIGHT -->
        <div id="right_top">
        	<div id="right_home"></div>
            <div id="right_right">            
            <a href="">Sortowanie</a>            
            <span><a href="#"><? echo $header; ?></a></span>            
            </div>
        </div>
        
        
        
        <div id="right_bg">
        
      	  <h3>Ustaw kolejność</h3>
          
          <!--table-->  
          <div id="table">          

		<script type="text/javascript">
          $(document).ready(function() {
            $("#test-list").sortable({
              handle : '.handle',
              update : function () {
                  var order = $('#test-list').sortable('serialize');
				  var url="<? echo $basehttp; ?>/admin/ajax/ajax.sort.php?type=<? echo $type; ?>&cat=<? echo $cat; ?>&"+order;
				  //alert(url);	
                  $("#info").load(url);
              }
            });
        });
        </script>


<div id="info"></div>

<ul id="test-list">
<?
	$sql.=" order by position ASC";
	$wynik =   mysql_query($sql)   or die('Błąd zapytania: '.mysql_error());	
	while($row = mysql_fetch_array($wynik)) {
?>

  <li id="listItem_<? echo $row[id]; ?>">
  <table width="100%" border="0">
  <tr>
    <td width="6%"><img src="<? echo $basehttp; ?>/admin/gfx/icons/arrow.png" alt="move" width="16" height="16" class="handle" /></td>
    <td>
    <?
	switch ($type): 						
		case 'category':
			echo "<strong>".$row['title']."</strong>";			
		break;	
		case 'oferty':
			echo "<strong>".$row['title']."</strong>";			
		break;			
		case 'pytania':
			echo "<strong>".$row['pytanie']."</strong>";			
		break;					
		case 'menu_tygodnia':
			echo "<strong>".$row['title']."</strong>";			
		break;			
		case 'links':
			echo "<strong>".$row['url']."</strong>";			
		break;		
		case 'gallery':
			echo "<strong>".$row['title']."</strong>";			
		break;		
		case 'pages':
			echo "<strong>".$row['title']."</strong>";			
		break;			
		case 'files':
			echo "<strong>"; if ($row['title']) { echo $row['title']; } else { echo $row['file'];} echo "</strong>";			
		break;			
		case 'pages_gallery':
			echo generateCMSitem('imageShowItem', $type,$_GET[id],$row['photo']); ;			
		break;	
		case 'images':
			echo generateCMSitem('imageShowItem', $type,$cat,$row['photo']); ;			
		break;	
		case 'slider':
			echo generateCMSitem('imageShowItem', $type,$row['id'],$row['photo']); ;			
		break;	
		case 'partners':
			echo generateCMSitem('imageShowItem', $type,$row['id'],$row['photo']); ;			
		break;			
				
	endswitch;	
	?>
    </td>
  </tr>
  </table>  
  </li>  
  <? }?>
</ul>

<table width="40%" border="0" style="margin-top:20px;">
  <tr>
    <td colspan="3"></td>
    </tr>
  <tr>
    <td width="4%"><a href="javascript:history.go(-1);"><img src="<? echo $basehttp; ?>/admin/gfx/icons/arrow_left.png" width="16" height="16" border="0" /></a></td>
    <td width="59%"><a href="javascript:history.go(-1);">wstecz</a> </td>
    <td width="37%">&nbsp;</td>
  </tr>
  </table>

        </div>        
        </div>        
        <div id="right_bottom"></div>
        </div>  
  </div>
</div>
<? include($basepath.'/admin/templates/footer.php'); ?>