First functions

This commit is contained in:
genuineparts 2025-07-05 21:24:53 +02:00
parent c89f3a4171
commit 33d32256a3
7 changed files with 127 additions and 1 deletions

8
.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/OebbApiWeb.iml generated Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml generated Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/OebbApiWeb.iml" filepath="$PROJECT_DIR$/.idea/OebbApiWeb.iml" />
</modules>
</component>
</project>

19
.idea/php.xml generated Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCSFixerOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCodeSnifferOptionsConfiguration">
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" />
</component>
</project>

7
.idea/vcs.xml generated Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View file

@ -14,6 +14,28 @@ if (!isset($_SESSION['account_loggedin'])) {
<meta name="viewport" content="width=device-width,minimum-scale=1"> <meta name="viewport" content="width=device-width,minimum-scale=1">
<title>Home</title> <title>Home</title>
<link href="style.css" rel="stylesheet" type="text/css"> <link href="style.css" rel="stylesheet" type="text/css">
<script>
function suggest(val){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('suggest_container').innerHTML=this.responseText;
}
};
xhttp.open("GET", ("suggest.php?type=station&name="+ encodeURI(val)), true);
xhttp.send();
}
function suggestStation(val){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('suggest_stations').innerHTML=this.responseText;
}
};
xhttp.open("GET", ("suggest.php?type=stationName&name="+ encodeURI(val)), true);
xhttp.send();
}
</script>
</head> </head>
<body> <body>
@ -48,6 +70,24 @@ if (!isset($_SESSION['account_loggedin'])) {
<div class="block"> <div class="block">
<p>This is the home page. You are logged in!</p> <p>This is the home page. You are logged in!</p>
<form>
Bildschirm 2:<br>
Name: <input type="text" name="title">
Abfahrtszeit: <input type="text" name="time">
Zug (z.b. REX 3): <input type="text" name="train">
Station: <input type="text" name="station" list="listit" onkeyup="suggest(this.value)" id="station">
Endstation des Zugs: <input type="text" name="endstation" list="liststations" onkeyup="suggestStation(this.value)" id="endstation">
<div id="suggest_container" style="display:inline-block;">
<datalist id="listit">
<option ></option>
</datalist>
</div>
<div id="suggest_stations" style="display:inline-block;">
<datalist id="liststations">
<option ></option>
</datalist>
</div>
</form>
</div> </div>

36
suggest.php Normal file
View file

@ -0,0 +1,36 @@
<?php
if(!empty($_GET['name']) && strlen($_GET['name'])>2) {
$type = $_GET['type'];
//http://fahrplan.oebb.at/bin/ajax-getstop.exe/dn?REQ0JourneyStopsS0A=1&REQ0JourneyStopsB=12&S=""&js=true
$name = urldecode($_GET['name']);
$ch = curl_init();
$buffer = "";
curl_setopt($ch, CURLOPT_URL, 'https://fahrplan.oebb.at/bin/ajax-getstop.exe/dn?REQ0JourneyStopsS0A=1&REQ0JourneyStopsB=12&S='.$name.'&js=true');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_HEADER, false);
$fh=curl_exec($ch);
//var_dump(curl_getinfo($ch));
// schließe den cURL-Handle und gebe die Systemresourcen frei
curl_close($ch);
if ($fh) {
$buffer = trim($fh);
}
$data = json_decode(mb_convert_encoding(str_replace("SLs.sls={\"suggestions\":","",str_replace("};SLs.showSuggestion();","",$buffer)),'UTF-8','ISO-8859-1'));
if($type=="station") {
$output = '<datalist id="listit">';
foreach ($data as $value) {
$output .= '<option value="' . $value->{"extId"} . '">' . $value->{"value"} . '</option>';
}
$output .= '</datalist>';
echo $output;
}else{
$output = '<datalist id="liststations">';
foreach ($data as $value) {
$output .= '<option>' . $value->{"value"} . '</option>';
}
$output .= '</datalist>';
echo $output;
}
}