service.php 2.53 KB
Newer Older
1
<?php
2
	require_once('runtime.php');
Clemens John's avatar
Clemens John committed
3 4 5
	require_once(ROOT_DIR.'/lib/core/Service.class.php');
	require_once(ROOT_DIR.'/lib/core/DnsRessourceRecordList.class.php');
	require_once(ROOT_DIR.'/lib/core/Routerlist.class.php');
6 7 8
	
	if(!isset($_GET['section']) AND isset($_GET['service_id'])) {
		$smarty->assign('message', Message::getMessage());
9
		
10 11 12
		$service = new Service((int)$_GET['service_id']);
		$service->fetch();
		$smarty->assign('service', $service);
13
		
14 15 16
		$smarty->display("header.tpl.html");
		$smarty->display("service.tpl.html");
		$smarty->display("footer.tpl.html");
17
	} elseif($_GET['section'] == 'add') {
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
		if(Permission::checkPermission(PERM_USER)) {
			//pass system messages to the template
			$smarty->assign('message', Message::getMessage());
			
			$dns_ressource_record_list = new DnsRessourceRecordList(false, (int)$_SESSION['user_id']);
			$smarty->assign('dns_ressource_record_list', $dns_ressource_record_list->getDnsRessourceRecordList());
			
			$routerlist = new Routerlist((int)$_SESSION['user_id']);
			$smarty->assign('routerlist', $routerlist->getRouterlist());
			
			//compile the template and sorround the main content by footer and header template
			$smarty->display("header.tpl.html");
			$smarty->display("service_add.tpl.html");
			$smarty->display("footer.tpl.html");
		} else {
			Permission::denyAccess(PERM_USER);
		}
35
	} elseif($_GET['section'] == 'insert_add') {
36 37 38 39 40 41 42 43 44 45 46
		if(Permission::checkPermission(PERM_USER)) {
			$service = new Service(false, (int)$_GET['user_id'], $_POST['title'], $_POST['description'], (int)$_POST['port'], 1,
								$_POST['iplist'], $_POST['dns_ressource_record_list']);
			if($service->store()) {
				$message[] = array('Der Service '.$service->getTitle().' wurde gespeichert.', 1);
			} else {
				$message[] = array('Der Service konnte nicht gespeichert werden.', 2);
			}
			
			Message::setMessage($message);
			header('Location: ./user.php?user_id='.$_GET['user_id']);
47
		} else {
48
			Permission::denyAccess(PERM_USER);
49 50 51 52
		}
	} elseif($_GET['section'] == 'delete') {
		$service = new Service((int)$_GET['service_id']);
		$service->fetch();
53 54 55 56 57 58 59 60
		if(permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $service->getUserId())) {
			if($service->delete()) {
				$message[] = array('Der Dienst '.$service->getTitle().' wurde gelöscht.', 1);
			} else {
				$message[] = array('Der Dienst '.$service->getTitle().' konnte nicht gelöscht werden.', 2);
			}
			Message::setMessage($message);
			header('Location: ./user.php?user_id='.$service->getUserId());
61
		} else {
62
			Permission::denyAccess(PERM_ROOT, $service->getUserId());
63
		}
64
	}
65
?>