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