<?
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($_GET['action']=='sort') {
	for($i=1; $i<=8; $i++) {
		$pozycja=0;
		if(count($_POST['row_'.$i])>0) foreach($_POST['row_'.$i] as $id) {
			$X->DB->fast(' UPDATE _shortcuts SET row_id="'.$i.'", pozycja="'.++$pozycja.'" WHERE user_id="'.$_SESSION['backend']['user_id'].'" AND id="'.$id.'" ');
		}
	}
	exit;
}


if(is_numeric($_GET['shortcut_id'])) {
	$dane=$X->DB->fast(' SELECT * FROM _shortcuts WHERE user_id="'.$_SESSION['backend']['user_id'].'" AND id="'.$_GET['shortcut_id'].'" ');

	if(!empty($dane['id']) && $_GET['action']=='del') {
		$X->DB->q(' DELETE FROM _shortcuts WHERE user_id="'.$_SESSION['backend']['user_id'].'" AND id="'.$_GET['shortcut_id'].'" ');
		die('
			$("#shortcut_'.$_GET['shortcut_id'].'").hide(250);
			$.colorbox.close();
		');
	}

	$_GET['title']=$X->STR->outt($dane['title']);
	$_GET['url']=$X->STR->outt($dane['link']);
	$bold=$X->STR->outt($dane['bold']);
	$icon_sel=$X->STR->outt($dane['icon']);
	$icon_sel_src='images/icons/large/'.$icon_sel;
	$box_title='Edytuj skrót';
	$submit_title='Zapisz';
} else {
	$box_title='Dodaj nowy skrót';
	$submit_title='Dodaj';
}
$url=@array_pop(explode('/admin/',$_GET['url']));

foreach($X->FILE->read_dir('../../images/icons/large/') as $icon) {
	$icons.='<a href="#" onclick="shortcut_choose_icon(this,\'images/icons/large/\',\''.$icon.'\'); return false;" class="shortcut_icon_preview'.($icon_sel==$icon ? ' sel':'').'"><img src="images/icons/large_preview/'.str_replace('.png','.jpg',$icon).'" alt="" /></a>';
}


echo '
<script type="text/javascript">$.colorbox.setTitle("'.$box_title.'");</script>

<div style="width:756px; height:370px;">
	'.$X->FORM->get('shortcut', $REQ, '
		<div style="position:absolute; margin:2px 0px 0px 689px; width:48px; height:48px; border:1px solid #ddd; padding:5px; -moz-border-radius:6px; -webkit-border-radius:6px; border-radius:6px; text-align:center;" id="shortcut_icon_preview"><img src="'.$icon_sel_src.'" id="shortcut_icon_preview"'.(empty($icon_sel_src) ? ' style="display:none"':'').' alt="" /></div>

		<table class="form" cellpadding="3">
			<tr>
				<td>'.$X->FORM->label('link','Link',true).'</td>
				<td>'.$X->FORM->input('link',580,$url).'</td>
			</tr>
			<tr>
				<td>'.$X->FORM->label('title','Nazwa',true).'</td>
				<td>'.$X->FORM->input('title',580,$_GET['title']).'</td>
			</tr>
			<tr>
				<td>'.$X->FORM->label('bold','Pogrubienie').'</td>
				<td>'.$X->FORM->checkbox('bold',1,$bold).'</td>
			</tr>
			<tr><td width="82" style="padding-top:4px;">'.$X->FORM->label('icon','Ikona',true).'</td></tr>
		</table>

		<a id="icon_focus" name="icon_focus" style="display:block; width:756px;"></a>
		'.$X->FORM->hidden('icon',$icon_sel).'<div style="width:756px; padding:6px 0px 12px 0px">'.$icons.'</div>
		<div class="right">'.$X->FORM->submit($submit_title).'</div>

		'.$X->FORM->hidden('shortcut_id', $_GET['shortcut_id']).'
	', array('error_alt_pos'=>true)).'
</div>
';
?>