Example #1
0
 /**
  * @param Route $route
  * @return $this
  */
 public function assignRoute(Route $route)
 {
     if (isset($this->_routes[$route->getRouteType()])) {
         if (isset($this->_routes[$route->getRouteType()][$route->getPath()])) {
             throw new \Exception("assigned route path was assigned before");
         }
     }
     // $this->_concatPath($this->_path, $route->getPath()) . PHP_EOL;
     $this->_routes[$route->getRouteType()][$route->getPath()] = $route;
     return $this;
 }
    /**
     * Show Search Result
     *
     * This function shows the search results
     */
    function showResult()
    {
        //result is empty
        if (!isset($this->result)) {
            //FIXME: translation
            ?>
			<div class="list-group-item alert alert-danger"><?php 
            echo Lang::l_("No data was found.");
            ?>
</div
			<?php 
            return;
        }
        // Obtain a list of columns
        foreach ($this->result as $key => $row) {
            //add missing variables
            if (!isset($row["ref"])) {
                $row["ref"] = "";
            }
            if (!isset($row["service"])) {
                $row["service"] = "";
            }
            if (!isset($row["from"])) {
                $row["from"] = "";
            }
            if (!isset($row["to"])) {
                $row["to"] = "";
            }
            if (!isset($row["via"])) {
                $row["via"] = "";
            }
            //set colour
            if (isset($row["color"])) {
                $row["colour"] = $row["color"];
            } elseif (!isset($row["colour"])) {
                $row["colour"] = "";
            }
            if (isset($row["text_color"])) {
                $row["text_colour"] = $row["text_color"];
            } elseif (isset($row["colour:text"])) {
                $row["text_colour"] = $row["colour:text"];
            } elseif (!isset($row["text_colour"])) {
                $row["text_colour"] = "";
            }
            //build html output
            $html = "<a href=\"?id=" . $row["id"] . "&train=" . urlencode(htmlentities($this->variables["train"])) . "\" class=\"list-group-item\">\n";
            $html .= "<h4>";
            $html .= Route::showRef($row["ref"], $row["route"], $row["service"], $row["colour"], $row["text_colour"]) . " ";
            $html .= Route::showfromviato($row["to"], $row["from"], $row["via"]);
            $html .= "</h4>\n";
            $html .= "<span>";
            $html .= Route::getRouteType($row["route"], $row["service"]);
            if (isset($row["network"])) {
                $html .= " / " . $row["network"];
            }
            if (isset($row["operator"])) {
                $html .= " / " . $row["operator"];
            }
            $html .= "</span>\n</a>";
            //write html
            echo $html;
        }
    }
    /**
     * This function produces the html output for the homepage
     */
    function output()
    {
        //calculate operatorstring
        if ($this->operator_distance > 0) {
            $operator_string = "";
            arsort($this->operator);
            foreach ($this->operator as $a => $b) {
                $operator_string .= $a . " (" . round($b / $this->relation_distance * 100, 1) . " %), ";
            }
            if ($this->operator_distance < $this->relation_distance) {
                $operator_string .= LANG::l_('N/A') . " (" . round(($this->relation_distance - $this->operator_distance) / $this->relation_distance * 100, 1) . " %)";
            } else {
                //delete comma
                $operator_string = substr($operator_string, 0, strlen($operator_string) - 2);
            }
        } else {
            $operator_string = LANG::l_('N/A') . " (100 %)";
        }
        // calculate trafficmodes string
        $trafficmode_string = LANG::l_('Unknown');
        //default
        if ($this->trafficmode_distance > 0) {
            arsort($this->trafficmode);
            $trafficmode_string = "";
            $trafficmode_name = array("mixed" => LANG::l_('mixed traffic'), "passenger" => LANG::l_('passenger traffic'), "freight" => LANG::l_('freight traffic'));
            foreach ($this->trafficmode as $a => $b) {
                if (isset($trafficmode_name[$a])) {
                    $trafficmode_string .= $trafficmode_name[$a] . " (" . round($b / $this->relation_distance * 100, 1) . " %), ";
                } else {
                    $this->trafficmode_distance -= $b;
                    //remove from trafficmode_distance
                }
            }
            if ($this->trafficmode_distance < $this->relation_distance) {
                $trafficmode_string .= LANG::l_('N/A') . " (" . round(($this->relation_distance - $this->trafficmode_distance) / $this->relation_distance * 100, 1) . " %)";
            } else {
                //delete comma
                $trafficmode_string = substr($trafficmode_string, 0, strlen($trafficmode_string) - 2);
            }
        } else {
            $trafficmode_string = LANG::l_('N/A') . " (100 %)";
        }
        // calculate electrified distances
        if ($this->electrified_distance > 0) {
            arsort($this->electrified);
            $electrified_string = "";
            foreach ($this->electrified as $a => $b) {
                if ($a == "no") {
                    $electrified_string .= LANG::l_('not electrified') . " (" . round($b / $this->relation_distance * 100, 1) . " %), ";
                } else {
                    $volfre = explode(";", $a);
                    if ($volfre[0] == LANG::l_('N/A')) {
                        $voltage = LANG::l_('N/A');
                    } else {
                        $voltage = $volfre[0];
                    }
                    if ($volfre[1] == LANG::l_('N/A')) {
                        $frequency = LANG::l_('N/A');
                    } elseif ($volfre[1] == "0") {
                        $frequency = LANG::l_('DC');
                    } else {
                        $frequency = $volfre[1] . " Hz " . LANG::l_('AC');
                    }
                    if ($voltage == LANG::l_('N/A') && $frequency == LANG::l_('N/A')) {
                        $electrified_string .= LANG::l_('electrified with unknown voltage') . " (" . round($b / $this->relation_distance * 100, 1) . " %), ";
                    } else {
                        $electrified_string .= $voltage . " V / " . $frequency . " (" . round($b / $this->relation_distance * 100, 1) . " %), ";
                    }
                }
            }
            if ($this->electrified_distance < $this->relation_distance) {
                $electrified_string .= LANG::l_('N/A') . " (" . round(($this->relation_distance - $this->electrified_distance) / $this->relation_distance * 100, 1) . " %)";
            } else {
                //delete comma
                $electrified_string = substr($electrified_string, 0, strlen($electrified_string) - 2);
            }
        } else {
            $electrified_string = LANG::l_('N/A') . " (100 %)";
        }
        // calculate structures
        if ($this->building_distance > 0) {
            $building_string = "";
            if ($this->tunnel_distance > 0) {
                $building_string .= round($this->tunnel_distance, 1) . " km " . LANG::l_('in tunnels') . " (" . round($this->tunnel_distance / $this->relation_distance * 100, 1) . " %), ";
            }
            if ($this->bridge_distance > 0) {
                $building_string .= round($this->bridge_distance, 1) . " km " . LANG::l_('on bridges') . " (" . round($this->bridge_distance / $this->relation_distance * 100, 1) . " %), ";
            }
            if ($this->embankment_distance > 0) {
                $building_string .= round($this->embankment_distance, 1) . " km " . LANG::l_('on embankments') . " (" . round($this->embankment_distance / $this->relation_distance * 100, 1) . " %), ";
            }
            if ($this->cutting_distance > 0) {
                $building_string .= round($this->cutting_distance, 1) . " km " . LANG::l_('in cuttings') . " (" . round($this->cutting_distance / $this->relation_distance * 100, 1) . " %), ";
            }
            //check whether there is a ground level part
            if ($this->relation_distance != $this->building_distance) {
                $building_string .= round($this->relation_distance - $this->building_distance, 1) . " km " . LANG::l_('on ground level') . " (" . round(($this->relation_distance - $this->building_distance) / $this->relation_distance * 100, 1) . " %)";
            } else {
                //delete comma
                $building_string = substr($building_string, 0, strlen($building_string) - 2);
            }
        } else {
            $building_string = round($this->relation_distance, 1) . " km " . LANG::l_('on ground level') . " (100 %)";
        }
        if (!isset($this->relation_tags["service"])) {
            $this->relation_tags["service"] = "";
        }
        //set ref to N/A, when not available
        if (!isset($this->relation_tags["ref"])) {
            $this->relation_tags["ref"] = "N/A";
        }
        //set colour
        if (isset($this->relation_tags["color"])) {
            $this->relation_tags["colour"] = $this->relation_tags["color"];
        } elseif (!isset($this->relation_tags["colour"])) {
            $this->relation_tags["colour"] = "";
        }
        if (isset($this->relation_tags["text_color"])) {
            $this->relation_tags["text_colour"] = $this->relation_tags["text_color"];
        } elseif (isset($this->relation_tags["colour:text"])) {
            $this->relation_tags["text_colour"] = $this->relation_tags["colour:text"];
        } elseif (!isset($this->relation_tags["text_colour"])) {
            $this->relation_tags["text_colour"] = "";
        }
        //get from and to values
        if (!isset($this->relation_tags["from"])) {
            $this->relation_tags["from"] = Lang::l_('Unknown');
        }
        if (!isset($this->relation_tags["to"])) {
            $this->relation_tags["to"] = Lang::l_('Unknown');
        }
        if (!isset($this->relation_tags["via"])) {
            $this->relation_tags["via"] = "";
        }
        //get route type:
        $route_type = Route::getRouteType($this->relation_tags["route"], $this->relation_tags["service"]);
        //title
        ?>
	<title><?php 
        echo LANG::l_("Train Analysis: ") . $this->relation_tags["ref"];
        ?>
 <?php 
        echo Route::showfromviato($this->relation_tags["to"], $this->relation_tags["from"], $this->relation_tags["via"]);
        ?>
</title>
		<?php 
        //javascript for speed profile
        ?>
<!-- flot implementation -->
<script type="text/javascript" src="flot/jquery.flot.js"></script>
<script type="text/javascript" src="flot/jquery.flot.dashes.js"></script>
<script type="text/javascript" src="flot/jquery.flot.selection.js"></script>
<script type="text/javascript" src="flot/jquery.flot.resize.js"></script>

  
<script type="text/javascript">

$(function() 
{
	// setup plot
	var options = 
	{
	 	series: 
		{
 			lines: 
 	 		{
	 	 		lineWidth: 1,
	 		},
	 		points: 
		 	{
	 	 		radius: 0.5,
	 		},
	 	shadowSize: 0.3
	},
	grid: 
	{
		hoverable: true,
	 	clickable: true,
	 	color: "#CCCCFF",
	 	lineWidth: 0.1
	},
	colors: ['#3333FF'],
	selection: 
	{
		mode: "x"
	}
};

var startData = [[0,0],<?php 
        //construct matrix for speed data
        $real_average_speed = 0;
        $this->maxspeed_point_array[-1] = $this->maxspeed_point_array[0];
        for ($i = 0; isset($this->maxspeed_point_array[$i]); $i++) {
            //calculate average speed
            $real_average_speed += ($this->maxspeed_point_array[$i][0] - $this->maxspeed_point_array[$i - 1][0]) * ($this->maxspeed_point_array[$i - 1][1] + $this->maxspeed_point_array[$i][1]) / 2;
            //add speed to javascript matrix
            echo "[" . $this->maxspeed_point_array[$i][0] . "," . $this->maxspeed_point_array[$i][1] . ", 'real']";
            if (isset($this->maxspeed_point_array[$i + 1])) {
                echo ",";
            }
        }
        ?>
];
    <?php 
        // add allowed maxspeed and distinguish between guessed and mapped values
        $k = 0;
        $l = 0;
        // only for first maxspeed value
        if ($this->maxspeed_array[0][2]) {
            ?>

	var maxspeed_<?php 
            echo $k;
            ?>
 = [<?php 
            $k++;
        } else {
            ?>

	var maxspeed_guessed_<?php 
            echo $l;
            ?>
 = [<?php 
            $l++;
        }
        // all other maxspeed values
        $this->maxspeed_array[-1] = $this->maxspeed_array[0];
        $maxspeed_distance = 0;
        $maxspeed_known = 0;
        for ($i = 0; isset($this->maxspeed_array[$i]); $i++) {
            // change between guessed and mapped -> new array
            if ($this->maxspeed_array[$i][2] != $this->maxspeed_array[$i - 1][2]) {
                if ($this->maxspeed_array[$i][1] < $this->maxspeed_array[$i - 1][1]) {
                    echo ",[" . $maxspeed_distance . "," . $this->maxspeed_array[$i][1] . ", 'allowed']";
                }
                if ($this->maxspeed_array[$i][2]) {
                    ?>
];

	var maxspeed_<?php 
                    echo $k;
                    ?>
 = [<?php 
                    $k++;
                } else {
                    ?>
];

	var maxspeed_guessed_<?php 
                    echo $l;
                    ?>
 = [<?php 
                    $l++;
                }
                if ($this->maxspeed_array[$i][1] > $this->maxspeed_array[$i - 1][1]) {
                    echo "[" . $maxspeed_distance . "," . $this->maxspeed_array[$i - 1][1] . ", 'allowed'],";
                }
            }
            //add speed to javascript matrix
            echo "[" . $maxspeed_distance . "," . $this->maxspeed_array[$i][1] . ", 'allowed'],";
            echo "[" . ($maxspeed_distance + $this->maxspeed_array[$i][0]) . "," . $this->maxspeed_array[$i][1] . ", 'allowed']";
            if (isset($this->maxspeed_array[$i + 1]) && $this->maxspeed_array[$i + 1][2] == $this->maxspeed_array[$i][2]) {
                echo ",";
            }
            $maxspeed_distance += $this->maxspeed_array[$i][0];
            // calculate how much of the maxspeed data is actually mapped and not guessed
            if ($this->maxspeed_array[$i][2]) {
                $maxspeed_known += $this->maxspeed_array[$i][0];
            }
        }
        ?>
];

    var stationData = [<?php 
        //construct matrix for stations
        $j = 0;
        if (isset($this->relation_stops[0])) {
            //go through all stops
            foreach ($this->relation_stops as $nr => $ref) {
                $stop_i = -1;
                //get id of stop in stop_position
                for ($i = 0; isset($this->stop_position[$i]["ref"]); $i++) {
                    if (isset($this->stop_position[$i]["ref"]) && $this->stop_position[$i]["ref"] == $ref) {
                        $stop_i = $i;
                    }
                }
                if ($stop_i >= 0) {
                    //get stop name
                    $stop_name[$nr] = "";
                    if ($this->relation_stops_type[$nr] == "n") {
                        if (isset($this->node[$ref]["ref_name"])) {
                            $stop_name[$nr] = $this->node[$ref]["ref_name"];
                        } elseif (isset($this->node[$ref]["name"])) {
                            $stop_name[$nr] = $this->node[$ref]["name"];
                        } elseif (isset($this->node[$ref]["description"])) {
                            $stop_name[$nr] = $this->node[$ref]["description"];
                        }
                        //mask '-sign:
                        $stop_name[$nr] = str_replace("'", "\\'", $stop_name[$nr]);
                        //write stop into matrix
                        echo "[" . $this->stop_position[$stop_i]["dis"] . ",0,'" . $stop_name[$nr] . "'],";
                        $j++;
                    }
                }
            }
        }
        ?>
[]];

	for ( var i = 0; stationData[i]; i++ )
	{
 		$("<div id='station" + i + "' class='hidden-xs'></div>").css({	
	 		position: "absolute",
	 		border: "none",
	 		padding: "2px",
	 		opacity: 0.80,
	 		width: 300,
	 		"border-radius": "2px",
		 	"transform": "rotate(-90deg)",
		 	"font-size": "0.6em",
		 	height:20,
		 	"z-index": "1"
 		}).appendTo("body");
	}
	var stations = new Array();
	
    function updateLabels(plot, stationData, stations)
    {	
		// add labels for stations
	 	var offset_left = $("#maxspeed").offset().left;
	 	var offset_top = $("#maxspeed").offset().top;
	 	
		for ( var i = 0; stationData[i]; i++ )
		{
			var xpos = stationData[i][0];
			var pO = plot.pointOffset({ x: xpos, y: 0 });
			$("#station" + i).html(stationData[i][2])
			.css({top: offset_top+$("#maxspeed").height()-200, left: (pO.left+offset_left-145)})
			
			if ( $('#maxspeed_labels:checked').length > 0 && ( pO.left + offset_left ) < $("#maxspeed").width() )
			{
				$("#station" + i).fadeIn(200);
			}
			else
			{
				$("#station" + i).hide();
			}
		}
		  
    }	      
    var plotdata = []; 
    var plotdata_nm = [];             
		<?php 
        for ($i = 0; $i < $k; $i++) {
            ?>
	var plotmaxspeed_<?php 
            echo $i;
            ?>
={
		data: maxspeed_<?php 
            echo $i;
            ?>
, 
		lines: 
		{
			show: true,
	        fill: true,
	        fillColor: "rgba(255, 168, 0, 0.1)",
	    },
		color: "#FF8800",
	};

	
		plotdata.push(plotmaxspeed_<?php 
            echo $i;
            ?>
);
		<?php 
        }
        for ($i = 0; $i < $l; $i++) {
            ?>
	var plotmaxspeed_guessed_<?php 
            echo $i;
            ?>
={
		data: maxspeed_guessed_<?php 
            echo $i;
            ?>
, 
		lines: 
		{
			show: true,
	        fill: true,
	        fillColor: "rgba(255, 168, 0, 0.06)",
	        lineWidth: 0,
	    },
	    dashes:
	    {
		    show: true,
 	 		lineWidth: 1,
 	 		dashLength: 2,
	    },
		color: "#FF8800"
		}
		plotdata.push(plotmaxspeed_guessed_<?php 
            echo $i;
            ?>
);

		<?php 
        }
        ?>
		var plotMaxspeed = {
		data: startData, 
		lines: 
		{
			show: true,
		}
		};
		var plotStationData = {
		data: stationData,
		lines: 
		{
			show: false,
		},
		points: 
		{
			show: true,
			radius: 1,
		}
		};

		plotdata.push(plotMaxspeed);
		plotdata.push(plotStationData);

		plotdata_nm.push(plotMaxspeed);
		plotdata_nm.push(plotStationData);
		
	    
		var plot = $.plot("#maxspeed", plotdata,
	 options);


	$("#maxspeed").bind("plothover", function (event, pos, item) 
	{
	 	if ( item) 
		{
	 		var x = item.datapoint[0].toFixed(3),
	 		y = item.datapoint[1].toFixed(0);
	 		var offset_left = $("#maxspeed").offset().left + $("#maxspeed").width();
	 		var offset_top = $("#maxspeed").offset().top;

	 		//default
	 		var postop = item.pageY - 33;
	 		var posleft = item.pageX - $("#tooltip_wrapper").width()/2;
			var className="top";
			var classNameArrow="";
	 		// right border
	 		if ( ( offset_left - posleft ) <  $("#tooltip_wrapper").width() )
	 		{
 				 posleft = item.pageX - $("#tooltip_wrapper").width()+7;
 				 var classNameArrow="right";	 
	 		}
	 		// left border
	 		if ( posleft <  $("#tooltip_wrapper").width()/2 )
	 		{
 				 posleft = item.pageX - 7;
 				 var classNameArrow="left";	 
	 		}
			// top border
			if ( ( postop - offset_top ) < 30 )
 			{
					var postop = item.pageY + 5;
					var className="bottom";
 			}
 			
	 		$("#tooltip").html("km " + x + ": " + y + " km/h");
	 		
 			$("#tooltip_wrapper")
 			.removeClass("top")
 			.removeClass("bottom")
 			.addClass("tooltip "+className)
 		 	.css({top: postop, left: posleft})
			.fadeIn(200);
 			$("#tooltip_arrow")
 			.removeClass("right")
 			.removeClass("left")
 			.addClass("tooltip-arrow "+classNameArrow)
 			if(item.series.data[item.dataIndex][2] == "allowed")
 			{
 	 			$("#tooltip").css("background-color","rgb(255, 168, 0)");
 	 			$("#tooltip").css("border-color","rgb(255, 168, 0)");
 	 			if ( className == "bottom" )
 	 			{
 	 				$("#tooltip_arrow").css("border-bottom-color","rgb(255, 168, 0)");
 	 			}
 	 			else
 	 			{
 	 				$("#tooltip_arrow").css("border-top-color","rgb(255, 168, 0)");
 	 			}
 			}
 			else
 			{
 	 			$("#tooltip").css("background-color","");
 	 			$("#tooltip").css("border-color","");
 	 			$("#tooltip_arrow").css("border-bottom-color","");
 	 			$("#tooltip_arrow").css("border-top-color","");
 			}
	 	} 
	 	else 
	  	{
	 		$("#tooltip_wrapper").hide();
	 	}
	});
	 
	// Create the overview plot
	var options_overview = 
	{
		series: 
		{
	 		lines: 
		 	{
	 	 		lineWidth:0.1,
	 		},
	 		points: {
	 			radius: 0.5,
 			},
	 		shadowSize:0
	 	},
	 	grid: {
	 		color: "#CCCCFF",
	 		lineWidth:0.1
	 	},
	 	colors: ['#3333FF'],
		selection: 
		{
			mode: "x"
		}
	}
	
	var overview = $.plot("#maxspeed_overview", 
	[{
		data: startData, 
		legend: 
		{
			show: false
		},
		lines: 
		{
			show: true,
			lineWidth: 0.5
		},
		shadowSize: 0
 	},
 	{
 		data: stationData,
 		lines: 
 	 	{
 			show: false,
 		},
 		points: 
 	 	{
 			show: true,
 			radius: 0.5,
		}		
 	}],options_overview
 	);

	// now connect the two
	var global_ranges;
	$("#maxspeed").bind("plotselected", function (event, ranges) 
	{

		// clamp the zooming to prevent eternal zoom

		if (ranges.xaxis.to - ranges.xaxis.from < 0.00001) 
		{
			ranges.xaxis.to = ranges.xaxis.from + 0.00001;
		}

		if (ranges.yaxis.to - ranges.yaxis.from < 0.00001) 
		{
			ranges.yaxis.to = ranges.yaxis.from + 0.00001;
		}

		//get the data
		if ( $('#show_maxspeed:checked').length > 0 )
		{
			data = plotdata;
		}
		else
		{
			data = plotdata_nm;
		}

		// do the zooming
		plot = $.plot("#maxspeed", data,
		$.extend(true, {}, options, 
		{
			xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to },
			yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to }
		})
		);
		global_ranges = ranges;


		// don't fire event on the overview to prevent eternal loop

		overview.setSelection(ranges, true);

		// update labels
		updateLabels(plot, stationData, stations);
	});

	$("#maxspeed_overview").bind("plotselected", function (event, ranges) 
	{
		plot.setSelection(ranges);
	});

	// add labels
	updateLabels(plot, stationData, stations);
	$('#maxspeed_labels').change(function() 
	{
		if ( $('#maxspeed_labels:checked').length > 0 )
		{
			for ( i = 0 ; i < <?php 
        echo $j;
        ?>
; i++ )
			{ 
				$('#station' + i).fadeIn(200);
			}
		}		
		else
		{	
			for ( i = 0; i < <?php 
        echo $j;
        ?>
; i++ )
			{ 
				$('#station' + i).hide();
			}
		}
			
	});

	// update labels when window is resized
	$( window ).resize(function(event,ranges) {
		updateLabels(plot, stationData, stations);
		});

	// update labels when alerts are closed
	if($('#alert'))
	{
		$('#alert').on('closed.bs.alert', function () {
			updateLabels(plot, stationData, stations);
		})
	}

	// show and hide maxspeed overview
	$('#show_overview').change(function() 
	{
		if ( $('#show_overview:checked').length > 0 )
		{
				$('#maxspeed_overview').show();
		}		
		else
		{	
			for ( i = 0; i < <?php 
        echo $j;
        ?>
; i++ )
			{ 
				$('#maxspeed_overview').hide();
			}
		}
	});

	// show and hide allowed maxspeeds
	$('#show_maxspeed').change(function() 
	{	
		if ( $('#show_maxspeed:checked').length > 0 )
		{
			data = plotdata;
		}					
		else
		{
			data = plotdata_nm;
		}
		if(global_ranges)
		{
			$.plot("#maxspeed", data, 
					$.extend(true, {}, options, 
							{
								xaxis: { min: global_ranges.xaxis.from, max: global_ranges.xaxis.to },
								yaxis: { min: global_ranges.yaxis.from, max: global_ranges.yaxis.to }
							})
					);
		}
		else
		{
			$.plot("#maxspeed", data, options);
		}
	});
	
	// Add the Flot version string 
	$("#flotversion").prepend('powered by <a href="http://www.flotcharts.org/">Flot ' + $.plot.version + '</a>');
});

</script>

</head>
<body>
<?php 
        top_nav();
        ?>
<div id="header" class="page-header">
	<div class="container">
		<header>
<h2> <?php 
        echo Route::showRef($this->relation_tags["ref"], $this->relation_tags["route"], $this->relation_tags["service"], $this->relation_tags["colour"], $this->relation_tags["text_colour"]) . " " . Route::showfromviato($this->relation_tags["to"], $this->relation_tags["from"], $this->relation_tags["via"]);
        ?>
</h2>
				</header>
	</div>
</div>
<div class="container-fluid panel-group">
<?php 
        if (isset($this->refresh_success) && $this->refresh_success == false) {
            ?>
	<div class="alert alert-danger alert-dismissable fade in" role="alert" id="alert">
		<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
		<span class="sr-only">Error:</span>
		<?php 
            echo Lang::l_("Route Data could not be updated from Overpass API.");
            ?>
		<button type="button" class="close" data-dismiss="alert" aria-label="Close">
  			<span aria-hidden="true">&times;</span>
		</button>
	</div>
	<?php 
        } elseif (isset($this->refresh_success) && $this->refresh_success == true) {
            ?>
	<div class="alert alert-success alert-dismissable fade in" role="alert" id="alert">
		<span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span>
		<span class="sr-only">Success:</span>
		<?php 
            echo Lang::l_("Route Data was successfully updated from Overpass API.");
            ?>
		<button type="button" class="close" data-dismiss="alert" aria-label="Close">
  			<span aria-hidden="true">&times;</span>
		</button>
	</div>
	<?php 
        }
        if ($this->relation_distance == 0) {
            ?>
	<div class="alert alert-warning alert-dismissable fade in" role="alert" id="alert_noways">
		<span class="glyphicon glyphicon-alert" aria-hidden="true"></span>
		<span class="sr-only">Warning:</span>
		<?php 
            echo Lang::l_("We couldn't find any ways for this route. Please check the OpenStreetMap data for errors.");
            ?>
		<button type="button" class="close" data-dismiss="alert" aria-label="Close">
  			<span aria-hidden="true">&times;</span>
		</button>
	</div>
	<?php 
        }
        ?>

	<div class="panel panel-primary">
		<div class="panel-heading">
			<h4 class="panel-title"><?php 
        echo Lang::l_('Route Details');
        ?>
:</h4>
		</div>
		<div class="panel-body">
		<?php 
        if (isset($this->relation_tags["operator"])) {
            ?>
	
			<div class="col-md-6"><b><?php 
            echo Lang::l_("Operator:");
            ?>
</b> <?php 
            echo $this->relation_tags["operator"];
            ?>
</div>
			<?php 
        } else {
            //set operator value for database input
            $this->relation_tags["operator"] = "";
        }
        if ($this->relation_distance > 10) {
            $relation_distance_show = round($this->relation_distance, 1);
        } else {
            $relation_distance_show = round($this->relation_distance, 2);
        }
        //calculate travel time
        $travel_time = 0;
        if ($this->real_average_speed > 0) {
            $travel_time = $this->relation_distance * $this->relation_distance / $this->real_average_speed * 60;
        }
        //calculate average speed
        $average_speed = 0;
        if ($this->relation_distance > 0) {
            $average_speed = $this->real_average_speed / $this->relation_distance;
        }
        //calculate speed_coverage
        $speed_coverage = 0;
        if ($this->relation_distance > 0) {
            $speed_coverage = $maxspeed_known / $this->relation_distance;
        }
        ?>
			<div class="col-md-6"><b><?php 
        echo Lang::l_('Train Type');
        ?>
:</b> <?php 
        echo $route_type;
        ?>
</div> 
			<div class="col-md-6"><b><?php 
        echo Lang::l_('Route Length');
        ?>
:</b> <?php 
        echo $relation_distance_show;
        ?>
 km</div> 
			<div class="col-md-6"><b><?php 
        echo Lang::l_('Travel Time');
        ?>
:</b> <?php 
        echo round($travel_time);
        ?>
 min</div> 
			<div class="col-md-6"><b><?php 
        echo Lang::l_('Average Speed');
        ?>
:</b> <?php 
        echo round($average_speed);
        ?>
 km/h</div>
			<div class="col-md-6"><b><?php 
        echo Lang::l_('Maximum Speed');
        ?>
:</b> <?php 
        echo $this->maxspeed_max;
        ?>
 km/h</div>
			<div class="col-md-6"><b><?php 
        echo Lang::l_('Known speed limits in OSM database');
        ?>
:</b> <?php 
        echo round($speed_coverage * 100, 1);
        ?>
 %</div>
		</div>
	</div>
	
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h4 class="panel-title"><?php 
        echo Lang::l_('Speed Profile');
        ?>
:</h4>
		</div>
		<div class="panel-body">
			<div style="position:relative" style="height:300px;width:100%;max-height:20%;">
				<div class="table-responsive">
					<div id="maxspeed" style="height:300px;width:100%;min-width:600px"></div>
				</div>
				<div id="maxspeed_overview"></div>
			</div>
			<small id="flotversion"></small>
			<div class="btn-group hidden-xs">
				<span class="input-group-addon">
				<input type="checkbox" id="maxspeed_labels" checked="checked" aria-label="..."/>
				</span>
				<label for="maxspeed_labels" class="input-group-addon"><?php 
        echo Lang::l_('Show Stop Names');
        ?>
</label>
			</div>
			<div class="btn-group hidden-xs">
				<span class="input-group-addon">
				<input type="checkbox" id="show_overview" checked="checked" aria-label="..."/>
				</span>
				<label for="show_overview" class="input-group-addon"><?php 
        echo Lang::l_('Show Overview');
        ?>
</label>
			</div>
			<div class="btn-group hidden-xs">
				<span class="input-group-addon">
				<input type="checkbox" id="show_maxspeed" checked="checked" aria-label="..."/>
				</span>
				<label for="show_maxspeed" class="input-group-addon"><?php 
        echo Lang::l_('Show Allowed Maxspeed');
        ?>
</label>
			</div>
			<div class="row"><small class="col-md-12"><b><?php 
        echo Lang::l_('Please note');
        ?>
:</b> <?php 
        echo Lang::l_('note_maxspeed');
        ?>
</small></div>
		</div>
	</div>
	
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h4 class="panel-title"><?php 
        echo Lang::l_('Railway details');
        ?>
:</h4>
		</div>
		<div class="panel-body">
			<div class="col-md-12"><b><?php 
        echo Lang::l_('Railway Operators');
        ?>
:</b> <?php 
        echo $operator_string;
        ?>
</div>
			<div class="col-md-12"><b><?php 
        echo Lang::l_('Railway Users');
        ?>
:</b> <?php 
        echo $trafficmode_string;
        ?>
</div>
			<div class="col-md-12"><b><?php 
        echo Lang::l_('Electrification');
        ?>
:</b> <?php 
        echo $electrified_string;
        ?>
</div>
			<div class="col-md-12"><b><?php 
        echo Lang::l_('Structures');
        ?>
:</b> <?php 
        echo $building_string;
        ?>
</div>
			<div class="col-md-12"><b><?php 
        echo Lang::l_('Gaps in Route');
        ?>
:</b> 
		<?php 
        if ($this->count_holes > 0) {
            ?>
			<span class="text-danger"><?php 
            echo $this->count_holes;
            ?>
</span> (<a href="http://ra.osmsurround.org/analyzeRelation?relationId=<?php 
            echo $this->id;
            ?>
&noCache=true&_noCache=on" title="<?php 
            echo Lang::l_('Analyze route with OSM Relation Analyzer');
            ?>
"><?php 
            echo Lang::l_('Analyze route');
            ?>
</a>)</span>
			<?php 
        } else {
            ?>
			<span class="text-success"><?php 
            echo $this->count_holes;
            ?>
</span>
			<?php 
        }
        ?>
	
			</div>
		</div>
	</div>
	
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h4 class="panel-title"><?php 
        echo Lang::l_('Map of Route and Stops');
        ?>
:</h4>
		</div>
		<div class="panel-body">
		<?php 
        $this->getStopNames();
        $this->showMap();
        ?>
			<div class="col-lg-6">
				<ul class="stations">
		<?php 
        if (isset($this->relation_stops[0])) {
            //go through all stations
            foreach ($this->relation_stops as $nr => $ref) {
                /* get class that should be used */
                $class = "default";
                if ($nr == 0) {
                    $class = "first";
                } elseif (!isset($this->relation_stops[$nr + 1])) {
                    $class = "last";
                }
                // show stops
                echo '<li class="' . $class . '"><span><a href="#map" onClick="railway_stops[' . $nr . '].openPopup();" onMouseOver="railway_stops[' . $nr . '].togglePopup();">' . $this->stop_name[$nr] . '</a></span></li>';
            }
        } else {
            ?>
					<li><?php 
            echo Lang::l_('N/A');
            ?>
</li>
			<?php 
        }
        ?>
	
				</ul>
			</div>
		</div>
	</div>
	
		<?php 
        //connect to database
        $con = connectToDB();
        // add route to database
        $query = "SELECT id FROM osm_train_details WHERE id=" . @$con->real_escape_string($this->id);
        $result = @$con->query($query) or log_error(@$con->error);
        while ($row = @$result->fetch_array()) {
            $mysql_id = $row["id"];
        }
        if (isset($mysql_id) && $mysql_id == $this->id) {
            if ($this->relation_distance > 0) {
                $query2 = "UPDATE osm_train_details SET id=" . @$con->real_escape_string($this->id) . ", ref='" . @$con->real_escape_string($this->relation_tags["ref"]) . "', ref_colour='" . @$con->real_escape_string($this->relation_tags["colour"]) . "', ref_textcolour='" . @$con->real_escape_string($this->relation_tags["text_colour"]) . "', `from`='" . @$con->real_escape_string($this->relation_tags["from"]) . "', `to`='" . @$con->real_escape_string($this->relation_tags["to"]) . "', operator='" . @$con->real_escape_string($this->relation_tags["operator"]) . "', route='" . @$con->real_escape_string($this->relation_tags["route"]) . "', service='" . @$con->real_escape_string($this->relation_tags["service"]) . "', length='" . @$con->real_escape_string($this->relation_distance) . "', time='" . @$con->real_escape_string($travel_time) . "', ave_speed='" . @$con->real_escape_string($average_speed) . "',max_speed='" . @$con->real_escape_string($this->maxspeed_max) . "', date='" . @$con->real_escape_string($this->filemtime) . "' WHERE id=" . @$con->real_escape_string($this->id) . ";";
            } else {
                $query2 = "DELETE FROM osm_train_details WHERE id=" . @$con->real_escape_string($this->id) . ";";
            }
            @$con->query($query2) or log_error(@$con->error);
        } else {
            if ($this->relation_distance > 0) {
                $query2 = "INSERT INTO osm_train_details VALUES( '" . @$con->real_escape_string($this->id) . "','" . @$con->real_escape_string($this->relation_tags["ref"]) . "','" . @$con->real_escape_string($this->relation_tags["colour"]) . "','" . @$con->real_escape_string($this->relation_tags["text_colour"]) . "','" . @$con->real_escape_string($this->relation_tags["from"]) . "','" . @$con->real_escape_string($this->relation_tags["to"]) . "', '" . @$con->real_escape_string($this->relation_tags["operator"]) . "', '" . @$con->real_escape_string($this->relation_tags["route"]) . "', '" . @$con->real_escape_string($this->relation_tags["service"]) . "','" . @$con->real_escape_string($this->relation_distance) . "','" . @$con->real_escape_string($travel_time) . "', '" . @$con->real_escape_string($average_speed) . "','" . @$con->real_escape_string($this->maxspeed_max) . "','" . @$con->real_escape_string($this->train->ref) . "','" . @$con->real_escape_string($this->filemtime) . "');";
                @$con->query($query2) or log_error(@$con->error);
                Train::setDefaultTrain($this->train->ref, $this->id, $this->relation_tags["service"], $this->relation_tags["route"], true);
            }
        }
        ?>
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h4 class="panel-title"><?php 
        echo Lang::l_('Train details');
        ?>
:</h4>
		</div>
		<div class="panel-body">
			<form action="index.php" method="get" class="form-inline" id="train_form">
				<input type="hidden" name="id" value="<?php 
        echo $this->id;
        ?>
">
				<input type="hidden" name="service" value="<?php 
        echo $this->relation_tags["service"];
        ?>
">
				<input type="hidden" name="route" value="<?php 
        echo $this->relation_tags["route"];
        ?>
">
		<?php 
        //show image for train if available
        if (isset($this->train->image)) {
            ?>
			<div class="col-md-12"><img src="img/trains/<?php 
            echo $this->train->image;
            ?>
" style="max-height: 50px;max-width: 100%" alt="<?php 
            echo Lang::l_("Train Image");
            ?>
"></div>
			<?php 
        }
        ?>
			<div class="col-md-4"><b><?php 
        echo Lang::l_('Train name');
        ?>
:</b> <?php 
        echo $this->train->name;
        ?>
</div>
			<div class="col-md-4"><b><?php 
        echo Lang::l_('Train type');
        ?>
:</b> <?php 
        echo Lang::l_(Train::$train_type[$this->train->type]);
        ?>
</div>
			<div class="col-md-4"><b><?php 
        echo Lang::l_('Maximum speed');
        ?>
: </b><?php 
        echo $this->train->maxspeed;
        ?>
 km/h</div>
			<div class="col-md-4"><b><?php 
        echo Lang::l_('Weight empty');
        ?>
:</b> <?php 
        echo $this->train->mass_empty / 12960;
        ?>
 t</div>
			<div class="col-md-4"><b><?php 
        echo Lang::l_('Power');
        ?>
:</b> <?php 
        echo $this->train->power / 12960;
        ?>
 kW</div>
			<div class="col-md-4"><b><?php 
        echo Lang::l_('Maximum torque');
        ?>
:</b> <?php 
        echo $this->train->torque / 12960;
        ?>
 Nm</div>
			<div class="col-md-4"><b><?php 
        echo Lang::l_('Maximum brake');
        ?>
:</b> <?php 
        echo $this->train->brake / 12960;
        ?>
 m/s²</div>
			<div class="col-md-4"><b><?php 
        echo Lang::l_('Length');
        ?>
:</b> <?php 
        echo $this->train->length * 1000;
        ?>
 m</div>
			<div class="col-md-4"><b><?php 
        echo Lang::l_('Seats');
        ?>
:</b> <?php 
        echo $this->train->seats;
        ?>
</div>

		<?php 
        $default_train = false;
        $train_def = Train::getDefaultTrain($this->id);
        if ($train_def == $this->train->ref) {
            $default_train = true;
        }
        if ($default_train == true) {
            $train_icon = "star";
            $train_text = Lang::l_('Set as Default');
            $btn = "btn-info disabled";
            $disabled = " disabled=\"disabled\"";
        } else {
            $train_icon = "star-empty";
            $btn = "btn-default";
            $train_text = Lang::l_('Set ') . $this->train->name . Lang::l_(' as Default');
            $disabled = "";
        }
        ?>
			
			<div class="col-md-12"> 
				<div class="form-group">
					<div>
						<label for="train"><?php 
        echo Lang::l_('Change train');
        ?>
:</label> 
						<?php 
        echo Train::changeTrain($this->train->ref, $train_def);
        ?>
					</div>
					<div>
						<input type="checkbox" id="train_default"<?php 
        echo $disabled;
        ?>
 class="sr-only">
    					<span id="text_default_train" class="hidden" aria-hidden="true"><?php 
        echo Lang::l_('Set as Default');
        ?>
</span>
    					<span id="text_not_default_change_train1" class="hidden" aria-hidden="true"><?php 
        echo Lang::l_('Change train and set ');
        ?>
</span>
    					<span id="text_not_default_train1" class="hidden" aria-hidden="true"><?php 
        echo Lang::l_('Set ');
        ?>
</span>
    					<span id="text_not_default_train2" class="hidden" aria-hidden="true"><?php 
        echo Lang::l_(' as Default');
        ?>
</span>
    					<span id="text_default_error" class="hidden" aria-hidden="true"><?php 
        echo Lang::l_('Can\'t set as Default');
        ?>
</span>
    					<span id="text_default_loading" class="hidden" aria-hidden="true"><?php 
        echo Lang::l_('Loading...');
        ?>
</span>
	    				
    					<div class="btn-group" role="group" id="train_default_group">
    						<div class="btn <?php 
        echo $btn;
        ?>
 btn-sm">
	    						<label for="train_default">
	    						<span id="train_icon" class="glyphicon glyphicon-<?php 
        echo $train_icon;
        ?>
" aria-hidden="true"></span>
	    						</label>
	    					</div>
	    					<div class="btn <?php 
        echo $btn;
        ?>
 btn-sm" title="<?php 
        echo Lang::l_('Click button to change.');
        ?>
">
	    						<label for="train_default" id="train_default_text">
	    						<?php 
        echo $train_text;
        ?>
	    						</label>
	    					</div>
	    					<button id="train_submit" class="btn btn-default btn-sm" type="submit" disabled="disabled"><?php 
        echo Lang::l_('Change train');
        ?>
</button>
    					</div>
    				</div>
    			</div>		
    		</div>
			</form>
		</div>
	</div>
</div>
</div>
    <nav class="navbar" id=footer>
		<div class="container">
			<small><strong><?php 
        echo Lang::l_('Data date');
        ?>
:</strong> <?php 
        echo date("F d Y H:i:s", $this->filemtime);
        ?>
 (<a href="?id=<?php 
        echo $this->id;
        ?>
&train=<?php 
        echo $this->train->ref;
        ?>
&rf=1" title="<?php 
        echo Lang::l_('Update data');
        ?>
"><?php 
        echo Lang::l_('Update data');
        ?>
</a>) | <?php 
        echo Lang::l_('Route Data');
        ?>
 © <a href="http://www.openstreetmap.org/copyright" title="OpenStreetMap <?php 
        echo Lang::l_('licence');
        ?>
">OpenStreetMap</a><?php 
        echo Lang::l_(' contributors');
        ?>
 | <a id="josmLink" href="http://127.0.0.1:8111/load_object?objects=r<?php 
        echo $this->id;
        ?>
&relation_members=true" data-editor="remote"><?php 
        echo Lang::l_('Load relation in JOSM');
        ?>
</a></small>
			<div class="navbar-right">
<?php 
        /** Flattr-Button, feel free to add your own flattr username or delete it **/
        ?>
<script id='fbcr6gj'>(function(i){var f,s=document.getElementById(i);f=document.createElement('iframe');f.src='//api.flattr.com/button/view/?uid=sb89&button=compact&url='+encodeURIComponent(document.URL);f.title='Flattr';f.height=20;f.width=110;f.style.borderWidth=0;s.parentNode.insertBefore(f,s);})('fbcr6gj');</script>

<?php 
        /** Github-Button, feel free to add your own github repository or delete it **/
        ?>
       
<!-- Place this tag where you want the button to render. -->
<a data-count-api="/repos/sb12/OSMTrainRouteAnalysis#stargazers_count" data-count-href="/sb12/OSMTrainRouteAnalysis/stargazers" data-icon="octicon-star" href="https://github.com/sb12/OSMTrainRouteAnalysis" class="github-button">Star</a> 
 
			</div>
		</div>
	</nav>
</div>
<div class="" role="tooltip" id="tooltip_wrapper" style="display:none;position:absolute">
	<div class="tooltip-arrow" id="tooltip_arrow"></div>
	<div id='tooltip' class='tooltip-inner'></div>
</div>

<div class="modal fade" id="josmErrorDialog" tabindex="-1" role="dialog" aria-labelledby="aboutLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-body">
				<p id="josmError" class="text-danger"><?php 
        echo Lang::l_('Loading relation to the editor failed - make sure JOSM or Merkaartor is loaded and the remote control option is enabled.');
        ?>
</p>
	        </div>
			<div class="modal-footer">
			    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
	        </div>
		</div>
	</div>
</div>
<!-- Place this tag right after the last button or just before your close body tag. -->
<script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
		<?php 
    }