<?
/* Afian is suspended */
if ($config->settings['suspend'] && $auth->currentUserInfo['username'] != "admin" && !$_GET['logout']) {
	header("Location: ?logout=1&msg=2");
	exit();
}


/* Setup redirects  */
if ($permissions['path'] == "") {
	if ($groupInfo['path'] == "") {
		if (($_GET['admin'] == "1" && $_GET['sub'] == "editgroup")) {
$_GET['msg']=1;
		} else {
			if ($_GET['logout'] != "1") {
				header("Location: ?admin=1&sub=editgroup&gid=".$auth->currentUserInfo['gid']."&msg=1");
				exit();
			}
		}
	} else {
		if (($_GET['admin'] == "1" || $_GET['sub'] == "edituser")) {
$_GET['msg']=1;
		} else {
			if ($_GET['logout'] != "1") {
				header("Location: ?admin=1&sub=edituser&uid=1&msg=1");
				exit();
			}
		}
	}
}


if ($_GET['file'] == "share") {
	require_once($sys['root']."/system/includes/myshares/share.inc");
} elseif ($_GET['file'] == "share.js") {
	$dontGzip = 1;
	require_once($sys['root']."/system/includes/myshares/share.js.inc");
} elseif ($_GET['file'] == "share_select_users") {
	require_once($sys['root']."/system/includes/myshares/selectusers.inc");
} elseif ($_GET['file'] == "share_select_users_list") {
	require_once($sys['root']."/system/includes/myshares/userlist.inc");
} elseif ($_GET['file'] == "jupload") {
	require_once($sys['root']."/system/includes/jupload.inc");
} elseif ($_GET['file'] == "jup") {
	require_once($sys['root']."/system/includes/jupload2.inc");
} elseif ($_GET['file'] == "tree_listing") {
	require_once($sys['root']."/system/includes/myfiles/treelisting.inc");
} elseif ($_GET['file'] == "myfilesacting") {
	require_once($sys['root']."/system/includes/myfiles/acting.inc");
} elseif ($_GET['file'] == "mysharesacting") {
	require_once($sys['root']."/system/includes/myshares/acting.inc");
} elseif ($_GET['file'] == "bshareacting") {
	require_once($sys['root']."/system/includes/browseshare/acting.inc");
} elseif ($_GET['file'] == "trashacting") {
	require_once($sys['root']."/system/includes/trash/acting.inc");
} elseif ($_GET['file'] == "listing") {
	require_once($sys['root']."/system/includes/myfiles/listing.inc");
}  elseif ($_GET['file'] == "comments") {
	require_once($sys['root']."/system/includes/comments.inc");
} elseif ($_GET['file'] == "workflow") {
	require_once($sys['root']."/system/includes/workflow.inc");
} elseif ($_GET['file'] == "thumb") {
	$dontGzip = 1;
	require_once($sys['root']."/system/includes/thumbmaker.inc");
} elseif ($_GET['file'] == "byemail") {
	require_once($sys['root']."/system/includes/byemail.inc");
} elseif ($_GET['file'] == "edittext") {
	require_once($sys['root']."/system/includes/edittext/index.inc");
} elseif ($_GET['file'] == "viewzip") {
	require_once($sys['root']."/system/includes/viewzip.inc");
} elseif ($_GET['file'] == "viewlog") {
	require_once($sys['root']."/system/includes/viewlog.inc");
} elseif ($_GET['file'] == "viewstats") {
	require_once($sys['root']."/system/includes/viewstats.inc");
} elseif ($_GET['file'] == "adm_user_summary") {
	require_once($sys['root']."/system/includes/adm_user_summary.inc");
} elseif ($_GET['file'] == "calendar") {
	require_once($sys['root']."/system/includes/calendar.inc");
} elseif ($_GET['folder_browser_data_feeder'] && ($auth->currentUserInfo['username'] == "admin")) {
	require_once($sys['root']."/system/includes/folder_browser_data_feeder.inc");
} else {
	
	/* Admin section */
	if ($_GET['admin']) {
		if ($auth->currentUserInfo['username'] == "admin") {
			$sys['admin'] = 1;
			if ($_GET['section'] == "users") { 
				if ($_GET['sub'] == "listing") {
				require_once($sys['root']."/system/includes/admin/users/listing.inc");
				} elseif ($_GET['sub'] == "acting") {
				require_once($sys['root']."/system/includes/admin/users/acting.inc");
				}
			} elseif ($_GET['section'] == "groups") {
				if ($_GET['sub'] == "listing") {
				require_once($sys['root']."/system/includes/admin/groups/listing.inc");
				} elseif ($_GET['sub'] == "acting") {
				require_once($sys['root']."/system/includes/admin/groups/acting.inc");
				}
			} elseif ($_GET['sub'] == "addgroup") { 
		require_once($sys['root']."/system/includes/admin/addgroup/index.inc");
			} elseif ($_GET['sub'] == "editgroup") { 
		require_once($sys['root']."/system/includes/admin/editgroup/index.inc");
			} elseif ($_GET['sub'] == "settings") { 
		require_once($sys['root']."/system/includes/admin/settings/index.inc");
			} elseif ($_GET['sub'] == "lastuploads") { 
		require_once($sys['root']."/system/includes/admin/lastuploads/index.inc");
			} elseif ($_GET['sub'] == "adduser") { 
		require_once($sys['root']."/system/includes/admin/adduser/index.inc");
			} elseif ($_GET['sub'] == "edituser") { 
		require_once($sys['root']."/system/includes/admin/edituser/index.inc");
			} elseif ($_GET['sub'] == "diagnostics") { 
		require_once($sys['root']."/system/includes/admin/diagnostics/index.inc");
			} elseif ($_GET['sub'] == "info") { 
		require_once($sys['root']."/system/includes/admin/info/index.inc");
			} elseif ($_GET['sub'] == "logsarchive") { 
		require_once($sys['root']."/system/includes/admin/logsarchive/index.inc");
			} elseif ($_GET['sub'] == "logs") { 
		require_once($sys['root']."/system/includes/admin/logs/index.inc");
			} elseif ($_GET['sub'] == "notifications") { 
		require_once($sys['root']."/system/includes/admin/notifications/index.inc");
			} else {
		require_once($sys['root']."/system/includes/admin/settings/index.inc");
			}
		} else {
			/* username != admin */
			header("Location: ?logout=1");
			exit();
		}
	} else {

		/* User section */
		if ($_GET['sharedfolders']) {
			$sys['sharedfolders'] = 1;
			require_once($sys['root']."/system/includes/sharedfolders/index.inc");
		} elseif ($_GET['myshares']) {
			$sys['myshares'] = 1;
			require_once($sys['root']."/system/includes/myshares/index.inc");
		} elseif ($_GET['mytasks']) {
			if ($permissions['sharing']) {
			$sys['myshares'] = 1;
			require_once($sys['root']."/system/includes/mytasks/index.inc");
			} else {
				header("Location: ?");
			}
		} elseif ($_GET['zipbrowser']) {
			$sys['zipbrowser'] = 1;
			require_once($sys['root']."/system/includes/zipbrowser/index.inc");
		} elseif ($_GET['slideshow']) { 
			require_once($sys['root']."/system/includes/slideshow/index.inc");
		} elseif ($_GET['components']) {
			require_once($sys['root']."/system/includes/components.inc");
		} elseif ($_GET['trash']) {
			$sys['trash'] = 1;
			require_once($sys['root']."/system/includes/trash/index.inc");
		} elseif ($_GET['search']) {
			require_once($sys['root']."/system/includes/search/index.inc");
		} elseif ($_GET['logout']) {
			//logout
			$auth->logout();
			$IP = getenv("REMOTE_ADDR");
			if (getenv("HTTP_X_FORWARDED_FOR")){
				$IP .= ";";
				$IP .= getenv("HTTP_X_FORWARDED_FOR"); 
			}
			$log->act("0", "logout", "IP ADDRESS: ".$IP);
			
			if ($settings->config['redirect_after_logout_url']) {
				header("Location: ".$settings->config['redirect_after_logout_url']."");
			} else {
				require_once($sys['root']."/system/templates/login/header.inc");
				require_once($sys['root']."/system/includes/login.inc");
				require_once($sys['root']."/system/templates/login/footer.inc");
			}
			
		} elseif ($_GET['listusers']) {
			$sys['othershares'] = 1;
			require_once($sys['root']."/system/includes/userslist/index.inc");
		} elseif ($_GET['browseshare']) {
			$sys['browseshare'] = 1;
			require_once($sys['root']."/system/includes/browseshare/index.inc");
		} else {
			/* Browsing home folder */
			$sys['myfiles'] = 1;
			//require_once($sys['root']."/system/includes/locationhistory.inc");
			if ($options['ui_type'] != "AFIAN_STANDARD" && $auth->currentUserInfo['username'] != "admin") {
				require_once($sys['root']."/system/includes/myfiles/index_simple.inc");
			} else {
				require_once($sys['root']."/system/includes/myfiles/index.inc");
			}
		}
	}
}
?>