<?php
    
	if(!$dprotect) die ('Access Denied!');	
        
	switch($link[2]) {
            
                case 'add':
			if($_POST['action'] == 'add' && $core->addPage($_POST['link'], $_POST['title'], $_POST['description'], $_POST['keywords'], $_POST['text'])) {
				header('Location: '.$config['url'].'admin/pages');
				exit();
			}
		break;
		
		case 'edit':
			if($_POST['action'] == 'edit' && $core->updatePage($link[3], $_POST['link'], $_POST['title'], $_POST['description'], $_POST['keywords'], $_POST['text'])) {
				header('Location: '.$config['url'].'admin/pages');
				exit();
			} elseif(!$_POST['action']) {
				$page = $core->pageDetailsForId($link[3]);
				foreach($page as $k => $v) { $_POST[$k] = $v; }
			}
		break;
		
		case 'del':
			if($_POST['action']=='del') {
				if($_POST['confirm']) {
					$core->delPage($link[3]);
					header('Location: '.$config['url'].'admin/pages');
					exit();
				}
				$_SESSION['msg']['title'] = 'You have to confirm delete operation.';
				$_SESSION['msg']['err'] = true;	
			}
		break;
		
		case 'swap':
			$core->swapPage($link[3], $link[4]);
			header('Location: '.$config['url'].'admin/pages');
			exit();
		break;
		
		default:
			if($_POST['action'] =='search'){
				if($_POST['clear']) {
					unset($_SESSION['auth']['search']['page']);
				} else {
					$_SESSION['auth']['search']['page'] = $_POST['text'];
				}
			}
			is_numeric($link[2]) ? null : $link[2] = 1;
			$smarty->assign('list', $core->searchPages($_SESSION['auth']['search']['page'], $link[2], (int)$config['perpage']));
			
	}	
	
?>