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