Zefix_search/submit.php

91 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2023-08-17 19:08:24 +02:00
<?php
2023-08-21 20:37:59 +02:00
include 'zefixAPI.php';
2023-08-21 17:08:15 +02:00
2023-09-25 12:43:51 +02:00
$taskDir = 'tasks';
2023-09-25 11:55:08 +02:00
2023-08-21 20:37:59 +02:00
/*
* Request Types:
* Count
* List
* Export
*/
2023-08-17 21:38:35 +02:00
// Request data
2023-08-21 20:37:59 +02:00
$data = array();
$data["maxEntries"] = 50;
$data["offset"] = 0;
$data["languageKey"] = "de";
2023-08-21 20:37:59 +02:00
$results = array();
// Wenn Firmenname vorhanden
if(isset($_POST['firma']) && !empty($_POST['firma'])) {
$data["name"] = $_POST['firma'];
}
// Wenn gelöschte auch gesucht werden sollen
if(isset($_POST['geloeschteRechtseinheiten'])) {
$data["deletedFirms"] = true;
2023-08-21 20:37:59 +02:00
} else {
$data["deletedFirms"] = false;
2023-08-17 21:38:35 +02:00
}
//TODO get from Frontend
$data["searchType"] = "exact";
2023-08-21 20:37:59 +02:00
$rechtsformen = array();
2023-09-26 14:56:58 +02:00
if (isset($_POST['rechtsformen']) && is_array($_POST['rechtsformen']) && count($_POST['rechtsformen']) > 0) {
$rechtsformen = $_POST['rechtsformen'];
2023-08-21 20:37:59 +02:00
} else {
2023-09-25 11:13:53 +02:00
$legalFormArray = json_decode(sendAPILegalFormRequest($username, $password), true);
foreach ($legalFormArray as $rechtsform) {
$rechtsformen[] = $rechtsform["id"];
}
2023-08-21 20:37:59 +02:00
}
$sitze = array();
if (isset($_POST['sitze']) && is_array($_POST['sitze']) && count($_POST['sitze']) > 0) {
$sitze = $_POST['sitze'];
} else {
2023-09-25 11:13:53 +02:00
$communityArray = json_decode(sendAPICommunityRequest($username, $password), true);
foreach ($communityArray as $community) {
$sitze[] = $community["bfsId"];
}
2023-08-21 20:37:59 +02:00
}
2023-09-25 12:33:12 +02:00
$requests_to_do = Array();
2023-08-21 20:37:59 +02:00
// Loop through the selected values
foreach ($rechtsformen as $rechtsform) {
$data["legalForms"] = Array(intval($rechtsform));
2023-08-17 21:38:35 +02:00
2023-08-21 20:37:59 +02:00
// Loop through the selected values
foreach ($sitze as $sitz) {
$data["legalSeats"] = Array(intval($sitz));
2023-09-25 12:33:12 +02:00
$requests_to_do[] = $data;
2023-08-21 20:37:59 +02:00
}
}
2023-09-25 12:33:12 +02:00
$taskdata = Array();
$taskdata['requests'] = $requests_to_do;
2023-09-25 14:29:53 +02:00
$taskdata['email'] = $_POST['email'];
2023-09-25 12:33:12 +02:00
$taskString = json_encode($taskdata);
2023-09-25 12:43:51 +02:00
if(!is_dir($taskDir)){
mkdir($taskDir, 0755, true);
}
2023-09-25 15:45:26 +02:00
$taskfilename = $taskDir.'/'.time().'-'.bin2hex(random_bytes(4)).'.json';
2023-09-25 11:55:08 +02:00
$taskfile = fopen($taskfilename, 'w');
if($taskfile){
fwrite($taskfile, $taskString);
fclose($taskfile);
2023-09-25 14:36:51 +02:00
echo "Wir haben Ihren Auftrag erhalten. Sie erhalten von uns eine E-Mail, sobald die Daten zum Download bereit sind. Dies kann je nach Datenmenge lange dauern.";
2023-09-25 14:39:00 +02:00
echo '<br><a href="index.php">Zurück zur Startseite</a>';
2023-09-25 11:55:08 +02:00
} else {
2023-09-25 14:36:51 +02:00
echo "Ein Fehler ist aufgetreten.";
2023-09-25 11:55:08 +02:00
}
//$constructed_response = $response;
2023-08-17 21:38:35 +02:00
// Send the response back to the client
2023-08-21 20:37:59 +02:00
//header('Content-Type: application/json');
//echo $constructed_response;
2023-08-21 21:16:49 +02:00
2023-08-17 19:08:24 +02:00
?>