<? 
define('ADMIN',true);
define('AJAX',true);
define('ROOT','../../..');
header('Content-Type: text/javascript; charset=utf-8');
require_once(ROOT.'/.config.php');
require_once(LIBS_PATH.'/system/sys_start.php');
require_once(LIBS_PATH.'/system/load_libs.php');
///////////////////////////

if(!empty($_GET['table'])) {
	if(is_numeric($_GET['parent_id']) && $_GET['parent_id']>-1) $cond.=' AND parent_id="'.(int)$_GET['parent_id'].'" ';

	if(count($_POST['R'])>0) foreach($_POST['R'] as $row) {
		$id=(int)@array_pop(explode('R:', $row));
		if(empty($id) || $id===0) continue;

		$X->DB->fast(' UPDATE '.$_GET['table'].' SET pozycja="'.++$i.'" WHERE id="'.$id.'" '.$cond.' ');
	}
}

$X->ADMIN->log_op(array('action'=>'ajax_sort', 'module_id'=>$_POST['module'], 'row_parent_id'=>$_GET['parent_id'], 'row_id'=>0, 'desc'=>$_GET['table']));
?>