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