PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/travel.php

https://bitbucket.org/bplsilva/t2r
PHP | 777 lines | 627 code | 149 blank | 1 comment | 114 complexity | 77e1f1565269b2651aaad275e192d5b9 MD5 | raw file
  1. <?php
  2. session_start();
  3. header('Content-Type: text/html; charset=utf-8');
  4. date_default_timezone_set('Europe/Paris');
  5. include_once("functions.php");
  6. ?>
  7. <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
  8. <html xmlns='http://www.w3.org/1999/xhtml'>
  9. <?php
  10. $settingsXml = new DOMDocument('1.0','UTF-8');
  11. $settingsXml->formatOutput = true;
  12. $settingsXml->preserveWhiteSpace = false;
  13. $settingsXml->load("settings.xml");
  14. $settingsXpath = new DOMXPath($settingsXml);
  15. if ($_SESSION['userConnected']) {
  16. $userConnected = $_SESSION['userConnected'];
  17. $userFile = $_SESSION['userFile'];
  18. $query = '//settings/accounts/user[@id="'.$userConnected.'"]';
  19. $entries = $settingsXpath->query($query);
  20. $userNumber = $entries->item(0)->getAttribute('number');
  21. $userFileXml = new DOMDocument('1.0','UTF-8');
  22. $userFileXml->formatOutput = true;
  23. $userFileXml->preserveWhiteSpace = false;
  24. $userFileXml->load("data/".$userFile);
  25. $userFileXpath = new DOMXPath($userFileXml);
  26. }
  27. if (!$userConnected) { $notLogged = true; }
  28. if ($userConnected) {
  29. $userData = array(
  30. 'id' => $userConnected,
  31. 'fullName' => getUserFullName($userFileXpath), 'firstName' => getUserFirstName($userFileXpath),
  32. 'email' => getUserEmail($userFileXpath), 'location' => getUserLocation($userFileXpath), 'img' => getUserImg($userFileXpath)
  33. );
  34. if (isset($_GET['id'])) {
  35. if ($_GET['id'] != null) {
  36. $travelID = $_GET['id'];
  37. $travelOwnerNumber = substr($travelID,1,1);
  38. if ($travelOwnerNumber == $userNumber) {
  39. $myTravel = true;
  40. $lookupUser = $userConnected;
  41. $lookupUserFile = $userFile;
  42. $lookupUserFileXml = $userFileXml;
  43. $lookupUserFileXpath = $userFileXpath;
  44. }
  45. else {
  46. $myTravel = false;
  47. $query = '//settings/accounts/user[@number="'.$travelOwnerNumber.'"]';
  48. $entries = $settingsXpath->query($query);
  49. $lookupUserFile = $entries->item(0)->getAttribute('file');
  50. $lookupUser = $entries->item(0)->getAttribute('id');
  51. $lookupUserFileXml = new DOMDocument('1.0','UTF-8');
  52. $lookupUserFileXml->formatOutput = true;
  53. $lookupUserFileXml->preserveWhiteSpace = false;
  54. $lookupUserFileXml->load("data/".$lookupUserFile);
  55. $lookupUserFileXpath = new DOMXPath($lookupUserFileXml);
  56. }
  57. $userLookupData = array(
  58. 'id' => $lookupUser,
  59. 'fullName' => getUserFullName($lookupUserFileXpath), 'firstName' => getUserFirstName($lookupUserFileXpath),
  60. 'email' => getUserEmail($lookupUserFileXpath), 'location' => getUserLocation($lookupUserFileXpath), 'img' => getUserImg($lookupUserFileXpath)
  61. );
  62. $query = '//travel-document/travel-data/travel[@id="'.$travelID.'"]';
  63. $entries = $lookupUserFileXpath->query($query);
  64. $travelNode = $entries->item(0);
  65. if (isset($_POST['insertDep']) && isset($_POST['insertArr']) && isset($_POST['depDate']) && isset($_POST['transport'])) {
  66. $insertDep = $_POST['insertDep'];
  67. if ($insertDep == 'true') { $inserDep = true; }
  68. else { $insertDep = false; }
  69. $insertArr = $_POST['insertArr'];
  70. if ($insertArr == 'true') { $inserArr = true; }
  71. else { $insertArr = false; }
  72. $resultDepID = $_POST['resultDepID'];
  73. $resultDepLocation = $_POST['resultDepLocation'];
  74. $resultDepCountry = $_POST['resultDepCountry'];
  75. $resultDepLatitude = $_POST['resultDepLatitude'];
  76. $resultDepLongitude = $_POST['resultDepLongitude'];
  77. $resultArrID = $_POST['resultArrID'];
  78. $resultArrLocation = $_POST['resultArrLocation'];
  79. $resultArrCountry = $_POST['resultArrCountry'];
  80. $resultArrLatitude = $_POST['resultArrLatitude'];
  81. $resultArrLongitude = $_POST['resultArrLongitude'];
  82. if ($insertDep) {
  83. if (isset($_POST['resultDepID']) && isset($_POST['resultDepLocation']) && isset($_POST['resultDepCountry']) && isset($_POST['resultDepLatitude']) && isset($_POST['resultDepLongitude'])) {
  84. $insertID = $resultDepID;
  85. $insertLocation = $resultDepLocation;
  86. $insertCountry = $resultDepCountry;
  87. $insertLatitude = $resultDepLatitude;
  88. $insertLongitude = $resultDepLongitude;
  89. $query = '//settings/location-data';
  90. $entries = $settingsXpath->query($query);
  91. $locationDataNode = $entries->item(0);
  92. $newLocationNode = $settingsXml->createElement("location");
  93. $newLocationNode->setAttribute('id',$insertID);
  94. $newLocationNode->setAttribute('name',$insertLocation);
  95. $newLocationNode->setAttribute('country',$insertCountry);
  96. $newLocationNode->setAttribute('lat',$insertLatitude);
  97. $newLocationNode->setAttribute('lng',$insertLongitude);
  98. $locationDataNode->appendChild($newLocationNode);
  99. $settingsXml->save("settings.xml");
  100. }
  101. else { $unknownError = true; }
  102. }
  103. if ($insertArr) {
  104. if (isset($_POST['resultArrID']) && isset($_POST['resultArrLocation']) && isset($_POST['resultArrCountry']) && isset($_POST['resultArrLatitude']) && isset($_POST['resultArrLongitude'])) {
  105. $insertID = $resultArrID;
  106. $insertLocation = $resultArrLocation;
  107. $insertCountry = $resultArrCountry;
  108. $insertLatitude = $resultArrLatitude;
  109. $insertLongitude = $resultArrLongitude;
  110. $query = '//settings/location-data';
  111. $entries = $settingsXpath->query($query);
  112. $locationDataNode = $entries->item(0);
  113. $newLocationNode = $settingsXml->createElement("location");
  114. $newLocationNode->setAttribute('id',$insertID);
  115. $newLocationNode->setAttribute('name',$insertLocation);
  116. $newLocationNode->setAttribute('country',$insertCountry);
  117. $newLocationNode->setAttribute('lat',$insertLatitude);
  118. $newLocationNode->setAttribute('lng',$insertLongitude);
  119. $locationDataNode->appendChild($newLocationNode);
  120. $settingsXml->save("settings.xml");
  121. }
  122. else { $unknownError = true; }
  123. }
  124. $depDate = $_POST['depDate'];
  125. $arrDate = $_POST['depDate'];
  126. $depLocation = $resultDepID;
  127. $depCountry = $resultDepCountry;
  128. $arrLocation = $resultArrID;
  129. $arrCountry = $resultArrCountry;
  130. $transport = $_POST['transport'];
  131. $systemDepDate = substr($enteredDepDate,6,4) . "-" . substr($enteredDepDate,3,2) . "-" . substr($enteredDepDate,0,2);
  132. $systemArrDate = substr($enteredDepDate,6,4) . "-" . substr($enteredDepDate,3,2) . "-" . substr($enteredDepDate,0,2);
  133. if ($depLocation != $arrLocation) {
  134. if (strtotime($systemDepDate) <= strtotime($systemArrDate)) {
  135. $newItineraryNode = $userFileXml->createElement("itinerary");
  136. $newItineraryNode->setAttribute('transport',$transport);
  137. $newItineraryNode->setAttribute('departure',$depLocation);
  138. $newItineraryNode->setAttribute('arrival',$arrLocation);
  139. $newItineraryNode->setAttribute('date',$depDate);
  140. $travelNode->appendChild($newItineraryNode);
  141. $userFileXml->save("data/".$userFile);
  142. $insertion = true;
  143. }
  144. }
  145. }
  146. if (isset($_POST['newTravelName']) && isset($_POST['travelType'])) {
  147. $newTravelName = $_POST['newTravelName'];
  148. $newTravelType = $_POST['travelType'];
  149. if ($newTravelName != null) {
  150. if ($newTravelName != $travelNode->getAttribute('name')) { $travelNode->setAttribute('name',$newTravelName); }
  151. if ($newTravelType != $travelNode->getAttribute('type')) { $travelNode->setAttribute('type',$newTravelType); }
  152. }
  153. $userFileXml->save("data/".$userFile);
  154. $nameChanged = true;
  155. }
  156. if (isset($_POST['remItineraryNumber']) && isset($_POST['remItineraryDepLocation']) && isset($_POST['remItineraryArrLocation'])
  157. && isset($_POST['remItineraryDepCountry'])&& isset($_POST['remItineraryArrCountry'])) {
  158. $remItineraryNumber = $_POST['remItineraryNumber'];
  159. $remItineraryDepLocation = $_POST['remItineraryDepLocation'];
  160. $remItineraryDepCountry = $_POST['remItineraryDepCountry'];
  161. $remItineraryArrLocation = $_POST['remItineraryArrLocation'];
  162. $remItineraryArrCountry = $_POST['remItineraryArrCountry'];
  163. if (!empty($remItineraryNumber) && !empty($remItineraryDepLocation) && !empty($remItineraryDepCountry)
  164. && !empty($remItineraryArrLocation) && !empty($remItineraryArrCountry)) {
  165. $query = '//travel-document/travel-data/travel[@id="'.$travelID.'"]/itinerary[position()=last()]';
  166. $entries = $userFileXpath->query($query);
  167. $itineraryNode = $entries->item(0);
  168. $travelNode->removeChild($itineraryNode);
  169. $userFileXml->save("data/".$userFile);
  170. $deletion = true;
  171. }
  172. }
  173. $travel = array(
  174. 'number' => substr(strrchr($travelID,'t'),1),
  175. 'id' => $travelNode->getAttribute('id'), 'name' => $travelNode->getAttribute('name'),
  176. 'type' => $travelNode->getAttribute('type'),
  177. 'typeName' => null, 'typeImg' => null,
  178. 'firstDay' => null, 'lastDay' => null, 'lastCity' => null,
  179. 'days' => 0, 'km' => 0, 'avgSpeed' => null, 'itineraries' => array(), 'lastItinerary' => array(),
  180. 'visitedCities' => array(), 'visitedCountries' => array(), 'transportTypes' => array()
  181. );
  182. $travel['typeName'] = getTravelTypeName($settingsXpath,$travel['type']);
  183. $travel['typeImg'] = getTravelTypeImg($settingsXpath,$travel['type']);
  184. $itineraryCount = 0;
  185. $itinerariesNode = $travelNode->childNodes;
  186. foreach ($itinerariesNode as $itinerary) {
  187. $itineraryCount++;
  188. $currentItinerary = array(
  189. 'number' => $itineraryCount,
  190. 'depLocation' => getItineraryDepartureLocation($lookupUserFileXpath,$itinerary),
  191. 'depDate' => getItineraryDepartureDate($lookupUserFileXpath,$itinerary),
  192. 'arrLocation' => getItineraryArrivalLocation($lookupUserFileXpath,$itinerary),
  193. 'arrDate' => getItineraryArrivalDate($lookupUserFileXpath,$itinerary),
  194. 'transport' => getItineraryTransport($lookupUserFileXpath,$itinerary),
  195. 'depLocationName' => null, 'depLocationCountry' => null, 'depLocationLat' => null, 'depLocationLng' => null,
  196. 'arrLocationName' => null, 'arrLocationCountry' => null, 'arrLocationLat' => null, 'arrLocationLng' => null,
  197. 'km' => null, 'days' => null
  198. );
  199. $currentItinerary['depLocationName'] = getLocationName($settingsXpath,$currentItinerary['depLocation']);
  200. $currentItinerary['depLocationCountry'] = getLocationCountry($settingsXpath,$currentItinerary['depLocation']);
  201. $depCoords = getLocationLatLng($settingsXpath,$currentItinerary['depLocation']);
  202. $currentItinerary['depLocationLat'] = $depCoords['lat'];
  203. $currentItinerary['depLocationLng'] = $depCoords['lng'];
  204. $currentItinerary['arrLocationName'] = getLocationName($settingsXpath,$currentItinerary['arrLocation']);
  205. $currentItinerary['arrLocationCountry'] = getLocationCountry($settingsXpath,$currentItinerary['arrLocation']);
  206. $arrCoords = getLocationLatLng($settingsXpath,$currentItinerary['arrLocation']);
  207. $currentItinerary['arrLocationLat'] = $arrCoords['lat'];
  208. $currentItinerary['arrLocationLng'] = $arrCoords['lng'];
  209. if (!in_array($currentItinerary['depLocation'],$travel['visitedCities'])) { $travel['visitedCities'][] = $currentItinerary['depLocation']; }
  210. if (!in_array($currentItinerary['depLocationCountry'],$travel['visitedCountries'])) { $travel['visitedCountries'][] = $currentItinerary['depLocationCountry']; }
  211. $systemDepDate = substr($currentItinerary['depDate'],6,4) . "-" . substr($currentItinerary['depDate'],3,2) . "-" . substr($currentItinerary['depDate'],0,2);
  212. if (!in_array($currentItinerary['arrLocation'],$travel['visitedCities'])) { $travel['visitedCities'][] = $currentItinerary['arrLocation']; }
  213. if (!in_array($currentItinerary['arrLocationCountry'],$travel['visitedCountries'])) { $travel['visitedCountries'][] = $currentItinerary['arrLocationCountry']; }
  214. $systemArrDate = substr($currentItinerary['arrDate'],6,4) . "-" . substr($currentItinerary['arrDate'],3,2) . "-" . substr($currentItinerary['arrDate'],0,2);
  215. if ($travel['firstDay'] == null) { $travel['firstDay'] = $systemDepDate; }
  216. if (strtotime($systemDepDate) < strtotime($travel['firstDay'])) { $travel['firstDay'] = $systemDepDate; }
  217. if ($travel['lastDay'] == null) { $travel['lastDay'] = $systemArrDate; }
  218. if (strtotime($systemArrDate) > strtotime($travel['lastDay'])) { $travel['lastDay'] = $systemArrDate; }
  219. $travel['lastCity'] = $currentItinerary['arrLocation'];
  220. $travel['lastCountry'] = $currentItinerary['arrLocationCountry'];
  221. if (!in_array($currentItinerary['transport'],$travel['transportTypes'])) {
  222. $travel['transportTypes'][] = $currentItinerary['transport'];
  223. }
  224. $currentItinerary['days'] = _date_diff(strtotime($systemDepDate),strtotime($systemArrDate));
  225. $currentItinerary['km'] = getDistance($currentItinerary['depLocationLat'],$currentItinerary['depLocationLng'],$currentItinerary['arrLocationLat'],$currentItinerary['arrLocationLng']);
  226. $travel['km'] = $travel['km'] + $currentItinerary['km'];
  227. $travel['lastItinerary'] = $currentItinerary;
  228. $travel['itineraries'][] = $currentItinerary;
  229. }
  230. $systemTravelDays = _date_diff(strtotime($travel['firstDay']),strtotime($travel['lastDay']));
  231. $travel['days'] = $systemTravelDays['days'];
  232. if (($travel['days'] == 0) && ($travel['km'] != 0)) { $travel['days'] = 1; }
  233. if ($travel['days'] == 0) { $travel['avgSpeed'] = 0; }
  234. else { $travel['avgSpeed'] = round($travel['km'] / ($travel['days'] * 24),2); }
  235. $query = '//settings/transports/transport';
  236. $entries = $settingsXpath->query($query);
  237. $transportsNode = $entries;
  238. $transportsTypes = array();
  239. foreach ($transportsNode as $transport) {
  240. $transportData = array('id' => $transport->getAttribute('id'), 'name' => $transport->getAttribute('name'), 'img' => $transport->getAttribute('img'));
  241. $transportsTypes[] = $transportData;
  242. }
  243. $query = '//settings/location-data/location';
  244. $entries = $settingsXpath->query($query);
  245. $locationsNode = $entries;
  246. $locations = array();
  247. foreach ($locationsNode as $location) {
  248. $locationCountry = getCountryName($settingsXpath,$location->getAttribute('country'));
  249. if (empty($locations[$locationCountry])) { $locations[$locationCountry] = array(); }
  250. $locations[$locationCountry][$location->getAttribute('id')] = array('id' => $location->getAttribute('id'), 'name' => $location->getAttribute('name'));
  251. }
  252. ksort($locations);
  253. $query = '//settings/travel-types/travel-type';
  254. $entries = $settingsXpath->query($query);
  255. $travelTypesNode = $entries;
  256. $travelTypes = array();
  257. foreach ($travelTypesNode as $type) {
  258. $typeData = array('id' => $type->getAttribute('id'), 'name' => $type->getAttribute('name'), 'img' => $type->getAttribute('img'));
  259. $travelTypes[] = $typeData;
  260. }
  261. }
  262. }
  263. else { $withoutID = true; }
  264. }
  265. openHeadTag();
  266. if ($notLogged) { title("Error"); }
  267. else { title("Travel: ".$travel['name']." [".$travel['id']."]"); }
  268. defaultMetaTag();
  269. echo "<script type='text/javascript'>
  270. function initialiser() { ";
  271. if (empty($travel['lastDay'])) { echo "datepickerSimple();"; }
  272. else { echo "datepickerLimit('".substr($travel['lastDay'],0,4).",". substr($travel['lastDay'],5,2) .",".substr($travel['lastDay'],8,2)."');"; }
  273. if (count($travel['itineraries']) > 0) {
  274. echo "var latlng = new google.maps.LatLng(".$travel['itineraries'][0]['depLocationLat'].",".$travel['itineraries'][0]['depLocationLng'].");";
  275. }
  276. else {
  277. echo "var latlng = new google.maps.LatLng(20,-20);";
  278. }
  279. echo "
  280. var bounds = new google.maps.LatLngBounds();
  281. var myPoints = [];";
  282. foreach ($travel['visitedCities'] as $city) {
  283. $cityCoords = getLocationLatLng($settingsXpath,$city);
  284. $cityLat = $cityCoords['lat'];
  285. $cityLng = $cityCoords['lng'];
  286. echo "myPoints.push(new google.maps.LatLng(".$cityLat.",".$cityLng."));";
  287. }
  288. echo "var options = { center: latlng, zoom: 2, mapTypeId: google.maps.MapTypeId.ROADMAP };
  289. var carte = new google.maps.Map(document.getElementById('map'),options);
  290. for(var i = 0; i < myPoints.length; i++) {
  291. bounds.extend(myPoints[i]);
  292. var thisMarker = addThisMarker(myPoints[i],i);
  293. thisMarker.setMap(carte);
  294. }
  295. var parcoursBus = [";
  296. $itineraryCount = 0;
  297. foreach ($travel['itineraries'] as $itinerary) {
  298. $itineraryCount++;
  299. if ($itineraryCount == 1) {
  300. $depLocationLat = $itinerary['depLocationLat']; $depLocationLng = $itinerary['depLocationLng'];
  301. echo "new google.maps.LatLng(".$depLocationLat.",".$depLocationLng."),";
  302. }
  303. $arrLocationLat = $itinerary['arrLocationLat']; $arrLocationLng = $itinerary['arrLocationLng'];
  304. echo "new google.maps.LatLng(".$arrLocationLat.",".$arrLocationLng."),";
  305. }
  306. echo "];
  307. var traceParcoursBus = new google.maps.Polyline({
  308. path: parcoursBus,
  309. strokeColor: '#000033',
  310. strokeOpacity: 1.0,
  311. strokeWeight: 2,
  312. geodesic: true
  313. });
  314. traceParcoursBus.setMap(carte);
  315. if (myPoints.length > 0) { carte.fitBounds(bounds); }
  316. function addThisMarker(point,m) {
  317. if (m == 0) { var marker = new google.maps.Marker({position: point, map: carte, icon: 'images/marker-finish.png'}); }
  318. else { var marker = new google.maps.Marker({position: point, map: carte, icon: 'images/marker-city.png'}); }
  319. return marker;
  320. }
  321. }
  322. </script>
  323. ";
  324. closeHeadTag();
  325. echo "<body class='bodygrey' onload='initialiser()'>
  326. <div class='headerspace'></div>
  327. <div class='header'>
  328. <!-- logo -->
  329. <a href=''><img src='images/logo2.png' alt='Logo' /></a>";
  330. displayNavbar("Travel");
  331. displayAccountInfo($userData);
  332. echo "</div><!-- header -->";
  333. displaySidebar("Travel");
  334. if ($notLogged) { displayNotLogged(); }
  335. else {
  336. if ($myTravel) {
  337. echo "<div class='maincontent'>
  338. <div class='breadcrumbs'>
  339. <a href='index.php'>Dashboard</a>
  340. <a href='travelinfo.php'>Travel Information</a>";
  341. if ($travel['km'] == 0) { echo "<a href='empty.php'>Empty Travels</a>"; }
  342. else if (strtotime($travel['firstDay']) > strtotime(date("Y-m-d")) || strtotime($travel['lastDay']) > strtotime(date("Y-m-d"))) { echo "<a href='upcoming.php'>Upcoming Travels</a>"; }
  343. else { echo "<a href='trips.php'>Completed Travels</a>"; }
  344. echo "<span>Travel: ".$travel['name']." [".$travel['id']."]</span>
  345. </div><!-- breadcrumbs -->
  346. <div class='two_third maincontent_inner '>
  347. <div class='left'>
  348. <h1 class='pageTitle'>Travel: ".$travel['name']." [".$travel['id']."]</h1>";
  349. if ($nameChanged) {
  350. echo "<div class='notification msgsuccess'>
  351. The travel details were successfully modified.
  352. </div><!-- notification info -->";
  353. }
  354. if ($deletion) {
  355. echo "<div class='notification msgerror'>
  356. Itinerary between <img src='images/flags/".$remItineraryDepCountry.".png' alt=''/> ".$remItineraryDepLocation."
  357. and <img src='images/flags/".$remItineraryArrCountry.".png' alt=''/> ".$remItineraryArrLocation." was successfully removed.
  358. </div><!-- notification info -->";
  359. }
  360. if ($insertion) {
  361. echo "<div class='notification msgsuccess'>
  362. Itinerary between <img src='images/flags/".$depCountry.".png' alt=''/> ".getLocationName($settingsXpath,$depLocation)."
  363. and <img src='images/flags/".$arrCountry.".png' alt=''/> ".getLocationName($settingsXpath,$arrLocation)." was successfully added to the travel.
  364. </div><!-- notification info -->";
  365. }
  366. echo "<div class='widgetbox'>
  367. <h3><span>Travel Map</span></h3>
  368. <div class='content'>
  369. <div id='map' style='width: 650px; height: 370px; margin: 0 auto 10px; border:1px solid #000000;'></div>
  370. </div><!-- content-->
  371. </div><!-- widgetbox -->
  372. <div class='widgetbox'>
  373. <h3><span>Itineraries</span></h3>
  374. <div class='content nopadding ohidden'>
  375. <table cellpadding='0' cellspacing='0' class='sTable3' width='100%'>
  376. <thead>
  377. <tr>
  378. <td align='center'>Number</td>
  379. <td align='center'>From</td>
  380. <td align='center'>To</td>
  381. <td align='center'>Transport Type</td>
  382. <td align='center'>Distance (km)</td>
  383. <td align='center'>Date</td>
  384. </tr>
  385. </thead>
  386. <tbody>";
  387. foreach ($travel['itineraries'] as $itinerary) {
  388. echo "<tr>
  389. <td align='center'>#".$itinerary['number']."</td>
  390. <td align='center'><img src='images/flags/".$itinerary['depLocationCountry'].".png' alt=''/> <a href='location.php?id=".$itinerary['depLocation']."'>".$itinerary['depLocationName']."</a></td>
  391. <td align='center'><img src='images/flags/".$itinerary['arrLocationCountry'].".png' alt=''/> <a href='location.php?id=".$itinerary['arrLocation']."'>".$itinerary['arrLocationName']."</a></td>
  392. <td align='center'><img src='images/".getTransportImg($settingsXpath,$itinerary['transport'])."' alt=''/> ".getTransportName($settingsXpath,$itinerary['transport'])."</td>
  393. <td align='center'>".$itinerary['km']." km</td>
  394. <td align='center'>".str_replace('-','/',$itinerary['depDate'])."</td>
  395. </tr>";
  396. }
  397. echo "</tbody>
  398. </table>
  399. </div><!-- content -->
  400. </div><!-- widgetbox2 -->
  401. <div id='tabs' class='tabs'>
  402. <ul>
  403. <li><a href='#tabs-1'>Add new itinerary</a></li>";
  404. if (!empty($travel['lastItinerary'])) {
  405. echo "<li><a href='#tabs-2'>Remove last itinerary</a></li>";
  406. }
  407. echo "</ul>
  408. <div id='tabs-1' style='text-align:center;'>
  409. <div class='form_default'>
  410. <form id='formAddItinerary' action='additinerary.php?id=".$travel['id']."' method='post'>";
  411. if (empty($travel['lastCity'])) { echo "<input type='hidden' name='itineraryFirst' value='true'/>"; }
  412. else { echo "<input type='hidden' name='itineraryFirst' value='false'/>"; }
  413. echo "<h2>Enter itinerary details</h2>
  414. <br/>
  415. <div class='three_fifth'>
  416. <label for='travelName' style='width:50px;'>From</label>";
  417. if (empty($travel['lastCity'])) {
  418. echo "<input type='text' id='depLocation' name='depLocation' value='' style='width:120px;' />";
  419. }
  420. else {
  421. echo "<input type='text' id='depLocation' name='depLocation' value='".getLocationName($settingsXpath,$travel['lastCity'])."' style='width:120px;padding:6px 5px;' />";
  422. }
  423. echo "<select style='width: 150px' id='depCountry' name='depCountry'><option value='null' selected='selected'>Select a country...</option>";
  424. $query = '//settings/countries/country';
  425. $entries = $settingsXpath->query($query);
  426. foreach ($entries as $country) {
  427. if ($country->getAttribute('code') == $travel['lastCountry']) { echo "<option selected value='".$country->getAttribute('code')."'>".$country->nodeValue."</option>"; }
  428. else { echo "<option value='".$country->getAttribute('code')."'>".$country->nodeValue."</option>"; }
  429. }
  430. echo "</select>";
  431. echo "<br/><br/>
  432. <label for='arrLocation' style='width:50px;'>To</label>
  433. <input type='text' id='arrLocation' name='arrLocation' value='' style='width:120px;padding:6px 5px;' />";
  434. //echo "<input id='arrCountry' />";
  435. echo "<select style='width: 150px' id='arrCountry' name='arrCountry'><option value='null' selected='selected'>Select a country...</option>";
  436. foreach ($entries as $country) { echo "<option value='".$country->getAttribute('code')."'>".$country->nodeValue."</option>"; }
  437. echo "</select>";
  438. echo "</div>
  439. <div class='two_fifth last'>
  440. <label for='datepickerDep' style='width:50px;'>Date</label>
  441. <input type='text' id='depDate' name='depDate' readonly='readonly' style='width:140px;padding:6px 5px;'/><br/></br>
  442. <table><tr>";
  443. $typeCount = 0;
  444. foreach ($transportsTypes as $transport) {
  445. $typeCount++;
  446. echo "<td width='68px' align='center'><img src='images/".$transport['img']."' alt=''/>";
  447. if ($typeCount == 1) { echo "<input type='radio' name='transport' style='margin:0 0 6px 2px;' value='".$transport['id']."' checked></input>"; }
  448. else { echo "<input type='radio' name='transport' style='margin:0 0 6px 2px;' value='".$transport['id']."'></input>"; }
  449. echo "<br/>".$transport['name']."</td>";
  450. }
  451. echo "</tr></table>
  452. </div>
  453. <div class='clear'></div>
  454. <button style='margin-left:0px;'>ADD ITINERARY</button>
  455. </form>
  456. </div>
  457. </div>";
  458. if (!empty($travel['lastItinerary'])) {
  459. echo "<div id='tabs-2' style='overflow:hidden;text-align:center;'>
  460. <form action='travel.php?id=".$travel['id']."' method='post'>
  461. <input type='hidden' name='remItineraryNumber' value='".$travel['lastItinerary']['number']."'/>
  462. <input type='hidden' name='remItineraryDepLocation' value='".$travel['lastItinerary']['depLocationName']."'/>
  463. <input type='hidden' name='remItineraryArrLocation' value='".$travel['lastItinerary']['arrLocationName']."'/>
  464. <input type='hidden' name='remItineraryDepCountry' value='".$travel['lastItinerary']['depLocationCountry']."'/>
  465. <input type='hidden' name='remItineraryArrCountry' value='".$travel['lastItinerary']['arrLocationCountry']."'/>
  466. <h2>Remove last itinerary</h2>
  467. <br/>
  468. <div class='three_fifth' style='text-align:center;'>
  469. <p>The last recorded itinerary in this travel is:</p><br/>
  470. <h2>#".$travel['lastItinerary']['number']."</h2>
  471. <p><img src='images/flags/".$travel['lastItinerary']['depLocationCountry'].".png' alt=''/> <b>".$travel['lastItinerary']['depLocationName']."</b> to <img src='images/flags/".$travel['lastItinerary']['arrLocationCountry'].".png' alt=''/> <b>".$travel['lastItinerary']['arrLocationName']."</b> (".$travel['lastItinerary']['km']." km)</p>
  472. </div>
  473. <div class='two_fifth last' style='text-align:center;'>
  474. <p style='margin: 3px 0 0 0;'>Are you sure you want to remove the itinerary between <b>".$travel['lastItinerary']['depLocationName']."</b> and <b>".$travel['lastItinerary']['arrLocationName']."</b>?</p>
  475. <br/>
  476. <input type='submit' value='Remove itinerary'/>
  477. </div>
  478. </form>
  479. </div>";
  480. }
  481. echo "</div><!-- tabs -->
  482. </div><!-- left -->
  483. </div><!-- two_third -->
  484. <div class='one_third last'>
  485. <div class='right'>
  486. <div class='widgetbox'>
  487. <h3><span>Travel details</span></h3>
  488. <div class='content'>
  489. <form id='formEdit' action='travel.php?id=".$travel['id']."' method='post'>
  490. <div class='form_default'>
  491. <label for='newTravelName' style='width:30px;'>Name</label>
  492. <input type='text' name='newTravelName' id='newTravelName' value='".$travel['name']."' style='width:200px;' />
  493. <p style='margin: 14px 0 0 !important;'><label for='travelType' class='nopadding' style='width:30px;'>Type</label>
  494. <table><tr>";
  495. $typeCount = 0;
  496. foreach ($travelTypes as $type) {
  497. echo "<td width='82px' align='center'><img src='images/".$type['img']."' alt=''/>";
  498. if ($travel['type'] == $type['id']) { echo "<input type='radio' style='margin: 0 0 6px 2px;' name='travelType' value='".$type['id']."' checked></input>"; }
  499. else { echo "<input type='radio' style='margin: 0 0 6px 2px;' name='travelType' value='".$type['id']."'></input>"; }
  500. echo "<br/>".$type['name']."</td>";
  501. }
  502. echo "</tr></table></p>
  503. <p style='margin: 14px 0 2px !important;'><button style='margin-left:52px;'>Edit details</button></p>
  504. </div><!--form-->
  505. </form>
  506. </div><!-- content -->
  507. </div><!-- widgetbox -->
  508. <div class='widgetbox'>
  509. <h3><span>Numbers</span></h3>
  510. <div class='content'>
  511. <h1 class='prize'>".$travel['km']." km</h1>
  512. <p>Number of days: <strong>".$travel['days']." ".qty('day','days',$travel['days'])."</strong></p>
  513. <br/>
  514. <div class='one_half bright'>
  515. <h2 class='prize'>".$travel['avgSpeed']." km/h</h2>
  516. <small>Average Speed</small>
  517. </div><!--one_half-->
  518. <div class='one_half last'>
  519. <h2 class='prize'>".count($travel['visitedCities'])." ".qty('city','cities',count($travel['visitedCities']))."</h2>
  520. <small>Cities visited</small>
  521. </div><!--one_half-->
  522. </div><!-- content -->
  523. </div><!-- widgetbox -->
  524. <div class='widgetbox'>
  525. <h3><span>Miscellaneous</span></h3>
  526. <div class='content'>
  527. <h2 class='prize'>".count($travel['visitedCountries'])." ".qty('country','countries',count($travel['visitedCountries']))."</h2>
  528. <p>Countries visited: ".displayCountryFlags($travel['visitedCountries'])."</p><br/>
  529. <h2 class='prize'>".count($travel['transportTypes'])." transport ".qty('type','types',count($travel['transportTypes']))."</h2>
  530. <p>Transport types used: ".displayTransportUsed($travel['transportTypes'])."</p>
  531. </div><!-- content -->
  532. </div><!-- widgetbox -->
  533. <div class='widgetbox'>
  534. <h3><span>Delete travel</span></h3>
  535. <div class='content'>
  536. <form id='form' action='travelinfo.php' method='post'>
  537. <input type='hidden' name='deletedID' value='".$travel['id']."'/>
  538. <input type='hidden' name='deletedName' value='".$travel['name']."'/>
  539. <div class='form_default' style='text-align:center;'>
  540. Delete <b>".$travel['name']."</b> travel?<br/>
  541. All itineraries contained in the travel will also be deleted.
  542. <p><button style='margin-left:0px;'>Delete travel</button></p>
  543. </div><!--form-->
  544. </form>
  545. </div><!-- content -->
  546. </div><!-- widgetbox -->
  547. </div><!--right-->
  548. </div><!--one_third last-->
  549. <br clear='all' />
  550. </div><!--maincontent-->
  551. <br />";
  552. }
  553. else {
  554. echo "<div class='maincontent'>
  555. <div class='breadcrumbs'>
  556. <a href='index.php'>Dashboard</a>
  557. <a href='userslist.php'>Users List</a>
  558. <a href='user.php?id=".$lookupUser."'>User: ".$lookupUser."</a>
  559. <span>Travel: ".$travel['name']." [".$travel['id']."]</span>
  560. </div><!-- breadcrumbs -->
  561. <div class='three_fifth'>
  562. <div class='left'>
  563. <h1 class='pageTitle'>Travel: ".$travel['name']." [".$travel['id']."]</h1>
  564. <div class='widgetbox'>
  565. <h3><span>Travel Info</span></h3>
  566. <div class='content'>
  567. <div class='one_fourth' style='text-align:center;'>
  568. <img src='".$userLookupData['img']."' alt='' style='border:1px solid black' width='64' height='64'/><br/>
  569. <a href='user.php?id=".$lookupUser."'>".$lookupUser."</a>
  570. </div>
  571. <div class='one_fourth' style='text-align:center;'><h2 class='prize'>".$travel['km']." km</h2><br/>
  572. Itineraries</div>
  573. <div class='one_fourth' style='text-align:center;'><h2 class='prize'>".$travel['days']." ".qty('day','days',$travel['days'])."</h2><br/>
  574. From<br/>to</div>
  575. <div class='one_fourth last' style='text-align:center;'><h2 class='prize'>".$travel['avgSpeed']." km/h</h2><br/>
  576. ".count($travel['visitedCities'])." ".qty('city','cities',count($travel['visitedCities']))."<br/>
  577. Countries</div>
  578. </div><!-- content-->
  579. </div><!-- widgetbox -->
  580. <div class='widgetbox'>
  581. <h3><span>Travel Map</span></h3>
  582. <div class='content'>
  583. <div id='map' style='width: 540px; height: 370px; margin: 0 auto 10px; border:1px solid #000000;'></div>
  584. </div><!-- content-->
  585. </div><!-- widgetbox -->
  586. </div><!-- left -->
  587. </div><!-- two_third -->
  588. <div class='two_fifth last'>
  589. <div class='right'>
  590. <div class='widgetbox'>
  591. <h3><span>Itineraries</span></h3>
  592. <div class='content nopadding ohidden'>
  593. <table cellpadding='0' cellspacing='0' class='sTable3' width='100%'>
  594. <thead>
  595. <tr>
  596. <td align='center' colspan='3'>List of itineraries</td>
  597. </tr>
  598. </thead>
  599. <tbody>";
  600. foreach ($travel['itineraries'] as $itinerary) {
  601. echo "<tr>
  602. <td align='center' width='24%'><b>#".$itinerary['number']."</b></td>
  603. <td align='center' width='38%'><img src='images/flags/".$itinerary['depLocationCountry'].".png' alt=''/> <a href='location.php?id=".$itinerary['depLocation']."'>".$itinerary['depLocationName']."</a></td>
  604. <td align='center' width='38%'><img src='images/flags/".$itinerary['arrLocationCountry'].".png' alt=''/> <a href='location.php?id=".$itinerary['arrLocation']."'>".$itinerary['arrLocationName']."</a></td>
  605. </tr>
  606. <tr>
  607. <td align='center' style='border-bottom:1px solid black;'>".$itinerary['km']." km</td>
  608. <td align='center' style='border-bottom:1px solid black;'><img src='images/".getTransportImg($settingsXpath,$itinerary['transport'])."' alt=''/> ".getTransportName($settingsXpath,$itinerary['transport'])."</td>
  609. <td align='center' style='border-bottom:1px solid black;'>".str_replace('-','/',$itinerary['depDate'])."</td>
  610. </tr>";
  611. }
  612. echo "<tr>
  613. <td align='center' colspan='3'>Total: ".count($travel['itineraries'])." ".qty('itinerary','itineraries',count($travel['itineraries']))."</td>
  614. </tr>";
  615. echo "</tbody>
  616. </table>
  617. </div><!-- content -->
  618. </div><!-- widgetbox2 -->
  619. </div><!--right-->
  620. </div><!--one_third last-->
  621. <br clear='all' />
  622. </div><!--maincontent-->
  623. <br />";
  624. }
  625. displayFooter();
  626. echo "</body>";
  627. }
  628. ?>