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