remove visible password

This commit is contained in:
schrom01 2023-08-17 21:38:35 +02:00
parent e8e39c6be4
commit c206ea3250
2 changed files with 131 additions and 42 deletions

View File

@ -1,7 +1,66 @@
<?php
include 'env_vars.php';
//echo "My Username is:" . getenv("username");
//echo "My API Key is:" . getenv("password");
//include 'env_vars.php';
//$username = getenv("username");
//$password = getenv("password");
$username = "username";
$password = "password";
// API endpoint
$apiUrl = 'https://www.zefix.admin.ch/ZefixPublicREST/apicompany/search';
// Request data
$data = array(
"name" => "Silias KLG",
"legalFormId" => 4,
"legalFormUid" => "0107",
"registryOfCommerceId" => 36,
"legalSeatId" => 623,
"canton" => "BE",
"activeOnly" => true
);
// Headers
$headers = array(
"apiKey: mykey"
);
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
// Close cURL session
curl_close($ch);
// Output the API response
echo $response;
?>
// Close cURL
curl_close($ch);
// Process the Zefix response and construct your own response
// ...
$constructed_response = $response;
// Send the response back to the client
header('Content-Type: application/json');
echo $constructed_response;
?>

108
index.php
View File

@ -8,7 +8,7 @@
<title>Silias Zefix Suche</title>
<style>
#myInput {
#sitzInput {
box-sizing: border-box;
background-position: 14px 12px;
background-repeat: no-repeat;
@ -18,7 +18,7 @@
border-bottom: 1px solid #ddd;
}
#myInput:focus {outline: 3px solid #ddd;}
#sitzInput:focus {outline: 3px solid #ddd;}
.dropdown {
@ -72,15 +72,15 @@
<input type="text" id="firmenname" name="firmenname"><br><br>
<label for="kanton">Kanton:</label>
<select id="kanton" name="kanton">
<!-- Hier kannst du die Optionen für die Kantone einfügen -->
</select><br><br>
<div id="kantonauswahl" class="scrollWindow">
</div><br><br>
<label for="sitz">Sitz (Postleitzahl / Gemeinde):</label><br>
<div class="dropdown">
<div id="myDropdown" class="dropdown-content">
<input type="text" placeholder="Postleitzahl / Ort" id="myInput" onkeyup="filterFunction()" name="sitz" autocomplete="off">
<div id="results" class="scrollWindow">
<div id="gemeindeDropdown" class="dropdown-content">
<input type="text" placeholder="Postleitzahl / Ort" id="sitzInput" onkeyup="filterFunction()" onchange="filterFunction()" name="sitzfilter" autocomplete="off">
<div id="sitzauswahl" class="scrollWindow">
</div>
@ -127,8 +127,6 @@
</form>
<script>
const kantonDropdown = document.getElementById('kanton');
const sitzInput = document.getElementById('sitz');
@ -154,43 +152,59 @@
const kantonIndex = headers.indexOf('Kanton');
const sitze = [];
const kantone = []
for (let i = 1; i < lines.length; i++) {
const cells = lines[i].split(',');
const plz = cells[plzIndex].trim();
const gemeindeName = cells[gemeindeNameIndex].trim();
const kanton = cells[kantonIndex].trim();
// Falls Kanton noch nicht vorhanden -> hinzufügen
if (!kantonDropdown.querySelector(`[value="${kanton}"]`)) {
const option = document.createElement('option');
option.value = kanton;
option.textContent = kanton;
kantonDropdown.appendChild(option);
if (!kantone.includes(kanton)) {
kantone.push(kanton)
const label = document.createElement('label');
const kantonsauswahl = document.getElementById("kantonauswahl")
kantonsauswahl.appendChild(label);
const input = document.createElement('input');
input.type = "checkbox";
input.name = "kantone[]";
input.value = kanton;
label.textContent = " " + kanton;
label.style.marginBottom = '0';
label.prepend(input);
kantonsauswahl.appendChild(document.createElement("br"))
}
// Sitz hinzufügen
sitze.push(cells)
const sitzString = plz + " " + gemeindeName
sitze.push(sitzString)
const anchorElement = document.createElement('a');
anchorElement.textContent = sitzString
anchorElement.href="#"
anchorElement.classList.add("result")
anchorElement.addEventListener('click', function(event) {
const index = i - 1; // Make sure 'i' is defined before using it here
chooseResult(index.toString());
});
document.getElementById("results").appendChild(anchorElement)
const gemeindeEintrag = document.createElement("div");
gemeindeEintrag.classList.add("gemeindeeintrag");
const label = document.createElement('label');
const sitzauswahl = document.getElementById("sitzauswahl")
sitzauswahl.appendChild(gemeindeEintrag);
gemeindeEintrag.appendChild(label);
const input = document.createElement('input');
input.type = "checkbox";
input.name = "sitze[]";
input.value = plz;
label.textContent = " " + sitzString;
label.style.marginBottom = '0';
label.prepend(input);
gemeindeEintrag.appendChild(document.createElement("br"))
}
function filterFunction() {
const numKantoneAusgewählt = kantoneAusgewählt()
var input, filter, ul, li, a, i;
input = document.getElementById("myInput");
input = document.getElementById("sitzInput");
filter = input.value.toUpperCase();
div = document.getElementById("myDropdown");
a = div.getElementsByTagName("a");
div = document.getElementById("gemeindeDropdown");
a = div.getElementsByClassName("gemeindeeintrag");
for (i = 0; i < a.length; i++) {
txtValue = a[i].textContent || a[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
if ((txtValue.toUpperCase().indexOf(filter) > -1 && (document.querySelector('input[name="kantone[]"][value=' + sitze[i][kantonIndex] + ']').checked || numKantoneAusgewählt === 0) ) || a[i].firstElementChild.firstElementChild.checked) {
a[i].style.display = "";
} else {
a[i].style.display = "none";
@ -198,24 +212,40 @@
}
}
function chooseResult(index) {
document.getElementById("myInput").value = sitze[index]
console.log("Choosen" + index)
function kantoneAusgewählt() {
const checkboxes = document.querySelectorAll('input[name="kantone[]"]');
let countChecked = 0;
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
countChecked = countChecked + 1;
}
}
return countChecked;
}
const myInput = document.getElementById('myInput');
const results = document.getElementById('results');
results.style.display = 'none';
myInput.addEventListener('focus', () => {
results.style.display = 'block';
const sitzInput = document.getElementById('sitzInput');
const sitzauswahl = document.getElementById('sitzauswahl');
sitzauswahl.style.display = 'none';
sitzInput.addEventListener('focus', () => {
sitzauswahl.style.display = 'block';
});
myInput.addEventListener('blur', () => {
sitzInput.addEventListener('blur', () => {
setTimeout(() => {
results.style.display = 'none';
sitzauswahl.style.display = 'none';
}, 100); // 1000 milliseconds = 1 second
});
// sitzauswahl.addEventListener('click', function(event) {
// setTimeout(() => {
// sitzInput.focus();
// sitzauswahl.style.display = 'block';
// console.log("exec")
// }, 150)
// })
</script>
</div>