PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/locations-view.php

https://github.com/mulka/empire
PHP | 116 lines | 76 code | 23 blank | 17 comment | 16 complexity | 197100777b138bbf70bd7e1d5da44c8f MD5 | raw file
  1<?php
  2
  3require_once "includes/func.getLocationById.php";
  4require_once "includes/func.getLocationRedirect.php";
  5require_once "includes/func.getNames.php";
  6require_once "includes/func.getFirstParentLocation.php";
  7require_once "includes/func.getChildrenLocations.php";
  8require_once "includes/func.getBreadcrumbs.php";
  9require_once "includes/func.getExternalLinks.php";
 10require_once "includes/func.getExternalUrls.php";
 11require_once "includes/func.getDefaultMap.php";
 12require_once "includes/func.getMapById.php";
 13require_once "includes/func.getLocationsOnMap.php";
 14require_once "includes/func.getLocationBoundsOnMap.php";
 15require_once "includes/func.getChildrenLocationBounds.php";
 16require_once "includes/func.convertToGmapsIfNeeded.php";
 17require_once "includes/func.getFirstBoundsOfParents.php";
 18
 19//the following are displayed:
 20//name
 21//connector
 22//parent location name with link to location-view.php of parent
 23
 24//lists direct children location names with links to location-view.php
 25
 26//link to location-edit.php with id of location
 27
 28//link to location-create.php to create a child of this location
 29
 30$locId = $_GET['locId'];
 31$map = $_GET['map'];
 32
 33if(!is_numeric($locId)){
 34	die("locId needs to be numeric");
 35}
 36
 37
 38if(is_numeric($map)){
 39	if(getLocationBoundsOnMap($locId, $map)){
 40		$mapId = $map;
 41	}else{
 42		$mapIdIgnored = true; //might want to show a warning to the user about this, or maybe not
 43	}
 44}else if($map == "gps"){
 45	$forceGps = true;
 46}else if($map == "none"){
 47	$hideMap = true;
 48}else if(isset($map)){
 49	die("valid map options: <mapId>, gps, none");
 50}
 51
 52if($redirectLocId = getLocationRedirect($locId)){
 53	header("Location: location-view.php?locId=$redirectLocId");
 54	exit();
 55}
 56
 57/*
 58the following is for location-view-map, and might be better off somewhere else besides here
 59*/
 60
 61$showBounds = true;
 62
 63//see if there is a default custom map for this location
 64//this function will choose the first map it can find if there is no default set
 65if(!$mapId && !$forceGps){
 66	$mapId = getDefaultMap($locId);
 67}
 68
 69//if custom map exists for this location
 70if($mapId){
 71	$mapInfo = getMapById($mapId);
 72	$locations = getLocationsOnMap($mapId);
 73	$bounds = getLocationBoundsOnMap($locId, $mapId);
 74	
 75	//TODO: I might be able to be write this function in javascript and push it to the browser
 76	convertToGmapsIfNeeded($mapInfo, $locations, $bounds);
 77	
 78	if(!isset($bounds)){
 79		$bounds = array('miny' => -85, 'minx' => -175, 'maxy' => 85, 'maxx' => 175);
 80		$showBounds = false;
 81	}
 82	$mapType = 'custom';
 83
 84//this location doesn't exist on a custom map, so show gps map
 85}else{
 86	
 87	//GPS STUFF
 88	$locations = getChildrenLocationBounds($locId);
 89	$bounds = getLocationBoundsOnMap($locId);
 90	
 91	$mapType = 'gps';
 92	
 93	//try to get parent GPS bounds
 94	if(!isset($bounds)){
 95		$bounds = getFirstBoundsOfParents($locId);
 96		
 97		$showBounds = false;
 98		if($bounds){
 99			$mapType = 'parent';
100		}
101	}
102	
103}
104
105require_once "includes/Smarty_Empire.class.php";
106$smarty =& new Smarty_Empire();
107$smarty->assign('location', getLocationById($locId));
108$smarty->assign('aka', getNames($locId));
109$smarty->assign('children', getChildrenLocations($locId));
110$smarty->assign('breadcrumbs', getBreadcrumbs($locId));
111$smarty->assign('externalLinks', getExternalLinks($locId));
112$smarty->assign('externalUrls', getExternalUrls($locId));
113if(!$hideMap){
114	$smarty->assign('map', array('type' => $mapType, 'info' => $mapInfo, 'locations' => $locations, 'bounds' => $bounds, 'showBounds' => $showBounds)); //for location-view-map
115}
116$smarty->display('locations-view.tpl.html');