<?php
    
	if(!$dprotect) die ('Access Denied!');
	
	switch($link[2]) {
		
		case 'add':
			if($_POST['action'] == 'add' && $core->addGallery($_POST['name'])) {
				header('Location: '.$config['url'].'admin/galleries');
				exit();
			}
		break;
		
		case 'edit':
			if($_POST['action'] == 'edit' && $core->updateGallery($link[3], $_POST['name'])) {
				header('Location: '.$config['url'].'admin/galleries');
				exit();
			} elseif(!$_POST['action']) {
				$gallery = $core->galleryDetailsForId($link[3]);
				foreach($gallery as $k => $v) { $_POST[$k] = $v; }
			}
		break;
		
		case 'del':
			$images = $core->imagesForGallery($link[3]);
			if($images) {
				$smarty->assign('block', true);				
			} else {
				if($_POST['action']=='del') {
					if($_POST['confirm']) {
						$core->delGallery($link[3]);
						header('Location: '.$config['url'].'admin/galleries');
						exit();
					}
					$_SESSION['msg']['title'] = 'You have to confirm removal.';
					$_SESSION['msg']['err'] = true;	
				}
			}
		break;
		
		case 'swap':
			$core->swapGallery($link[3], $link[4]);
			header('Location: '.$config['url'].'admin/galleries');
			exit();
		break;		
		
		default:
			if($_POST['action'] =='search'){
				if($_POST['clear']) {
					unset($_SESSION['auth']['search']['gallery']);
				} else {
					$_SESSION['auth']['search']['gallery'] = $_POST['text'];
				}
			}
			is_numeric($link[2]) ? null : $link[2] = 1;
			$smarty->assign('list', $core->searchGalleries($_SESSION['auth']['search']['gallery'], $link[2], (int)$config['perpage']));
			
			
	}	
	
?>