verifyFormRequirements(); if (!$requirements["continue"]) { ?>
form["content"])) { $this->printSection($this->form["content"]); } if (!$requirements["continue"]) { ?>
embedJavascriptInDOMDocument(); } /** * Print Card HTML * * @param Array $element * @param ?String $object * @param Closure $function * @return void */ function printGroup(array $element, int $index, ?String $object, bool $is_repetition = false, bool $is_last_repetition = false, bool $print_del_button = true, Closure $function = null): void { // Titolo della card $title = $element["title"] ?? camelCaseToWords($element["id"]); // Identifica se il corrente è una ripetizione $repeatable = !empty($object); // ID univoco dell'elemento $identifier = str_replace('.', '_', uniqid("npa.", true)); // ID univoco del gruppo di ripetizioni $reference = $repeatable ? "repeatable_" . $element["repeatable_reference"] : ""; // Decide se la card va stampata o meno (viene stampata per i blocchi singoli o per il primo blcoco di una ripetizione) $open_card = !$repeatable || !$is_repetition; $close_card = !$repeatable || $is_last_repetition; // Evitiamo il card inutile if (!$repeatable && $element["id"] == "anacForm") { $open_card = false; $close_card = false; } if ($repeatable && !$is_repetition && !($this->locked_repetitions[$element["id"]] ?? false)) { $add_button = $this->makeAddButtonElement($reference, $object); } $is_section_header = ($element["depth"] ?? -1) == 1; ?>

button($add_button); ?>
" class="row "> makeDelButtonElement($identifier); echo $this->button($button); } if (!is_null($function)) { $function(); } ?>
getCardData(); $suggestions = $this->getSuggestions(); } foreach ($section as $element) { switch ($element["contentType"]) { case "reference": if (!empty($element["location"]) && file_exists("{$this->path}/{$element["location"]}")) { $elements = jsonToArray("{$this->path}/{$element["location"]}"); if (!empty($elements["content"])) { $this->printSection($elements["content"], $realName, false, $depth, $startIndex); } } break; case "group": // Verify that the element has content to print. if (!empty($element["content"])) { $element["depth"] = $depth; // Check if the element's id attribute needs to be inserted into the input field's name. if (!($element["_skip_id_name"] ?? false) && !$is_repetition) { array_push($realName, $element["id"]); } // Check if the element is repeatable and then print a group with a button to add the same element to the form; if ($element["_repeatable"]) { $title = $element["id"]; $object = $this->makeRepeatableObject(["element" => $element, "realName" => $realName, "codice" => $this->scheda["codice"] ?? $this->info["codice"]]); $repeats = 1; $sectionRealKey = implode(".", $realName); $values = DotPath::get($data, $sectionRealKey, null, false); if (!empty($values) && is_array($values) && array_is_list($values)) { $repeats = count($values); } // Carichiamo il numero di entry se presuggerito $forcedRepeats = 0; if (!$this->checkLock()) { $sectionSuggestions = DotPath::get($suggestions, $sectionRealKey); if (is_array($sectionSuggestions) && array_is_list($sectionSuggestions)) { $repeats = max($repeats, count($sectionSuggestions)); $forcedRepeats = count($sectionSuggestions); } } $repeats += $startIndex; for ($i = $startIndex; $i < $repeats; $i++) { $this->current_repetitions[$element["id"]] = $i; // Reset the repetition name $realRepetitionName = $realName; // Push the repetition name into the keys array array_push($realRepetitionName, $i); if ($element["_card"] ?? true) { $element["repeatable_reference"] = $this->establishIdAttributeForElement($realName, $element); $this->printGroup($element, $i, $object, $is_repetition || $i > 0, $i >= ($repeats - 1), $i + 1 > $forcedRepeats, function () use ($element, $realRepetitionName, $depth) { $this->printSection($element["content"], $realRepetitionName, false, $depth + 1); }); } else { $this->printSection($element["content"], $realRepetitionName); } if ($i >= $repeats - 1) { unset($this->current_repetitions[$element["id"]]); } } } else { if ($element["_card"] ?? true) { $this->printGroup($element, 0, null, $is_repetition, false, true, function () use ($element, $realName, $depth) { $this->printSection($element["content"], $realName, false, $depth + 1); }); } else { $this->printSection($element["content"], $realName, $depth + 1); } } array_pop($realName); } break; case "auto-filled": $element["type"] = "text"; $element["attrs"]["hidden"] = true; $element["class"][] = "d-none"; $element["val"] = "TO-BE-FILLED"; case "field": if ($element["hidden"] ?? false) { break; } // anacForm.lotti.0.campo $realKey = $this->establishKeyInDotNotation($realName, $element); // anacForm.lotti.*.campo $genericKey = preg_replace("/\.(\d+)/", ".*", $realKey); $element["name"] = $this->establishNameAttributeForElement($realName, $element); $element["attrs"]["data-reference"] = $this->establishIdAttributeForElement($realName, $element); if (empty($element["val"])) { $element["val"] = DotPath::get($data, $realKey); } if (!$this->checkLock()) { $suggestion = DotPath::get($suggestions, $realKey); if (!empty($suggestion)) { if ($suggestion["value"]["options"] ?? false) { $element["type"] = "select"; $element["options"] = $suggestion["value"]["options"]; } else { if (!empty($suggestion)) { $suggestion["value"] = htmlspecialchars($suggestion["value"], ENT_QUOTES|ENT_SUBSTITUTE, null, false); switch ($suggestion["forced"]) { case NPASuggestionType::FORCED: $element["val"] = $suggestion["value"]; $element["attrs"]["readonly"] = true; if (isset($element["title"])) { $element["title"] = "🪄 " . $element["title"]; } break; case NPASuggestionType::AUTOFILL: if (empty($element["val"])) { $element["val"] = $suggestion["value"]; } // La mancanza di break qui è volontaria case NPASuggestionType::OPTIONAL: $element["attrs"]["suggested_val"] = "{$suggestion["value"]}"; if (isset($element["title"])) { $element["title"] = "💡 " . $element["title"]; } break; } } } } } if ($element["type"] == "idScheda") { // Cerchiamo le schede pubblicate $filterSchede = [ "stato" => [">=", 50], "codice_npa" => $this->fascicolo["codice"], ]; // Se abbiamo un codice lotto, cerchiamole relative allo stesso codice lotto /*if(! empty($this->lot["codice_lotto_npa"])) { $filterSchede["codice_lotto"] = $this->lot["codice_lotto_npa"]; } */ // Se abbiamo un indicatore del tipo, usiamolo if (!empty($element["scheda_collegata"])) { $filterSchede["id_scheda"] = $element["scheda_collegata"]; } $schede = NuovaPiattaformaAppalti::fetchSchede(["id_scheda", "codice", "uuid", "timestamp_creazione"], $filterSchede); $element["type"] = "select"; $element["options"] = []; foreach ($schede as $id => $scheda) { $element["options"][$scheda["uuid"]] = __guue("Scheda ") . "$id #{$scheda['codice']} ({$scheda['uuid']})"; } } elseif ($element["type"] == "idContratto") { // Cerchiamo le schede pubblicate $filterSchede = [ "stato" => [">=", 50], "codice_npa" => $this->fascicolo["codice"], ]; if (!empty($element["scheda_collegata"])) { $filterSchede["id_scheda"] = $element["scheda_collegata"]; } $schede = NuovaPiattaformaAppalti::fetchSchede(["id_scheda", "codice", "info", "timestamp_creazione"], $filterSchede); // Filtriamo per quelle con idContratto foreach ($schede as $idx => $scheda) { $scheda["info"] = unserialize($scheda["info"]); if ($scheda["info"] && !empty($scheda["info"]->idContratto)) { $schede[$idx]["uuid"] = $scheda["info"]->idContratto; } } $element["type"] = "select"; $element["options"] = []; foreach ($schede as $scheda) { if (!empty($scheda["uuid"])) { $id = $scheda["id_scheda"]; $element["options"][$scheda["uuid"]] = __guue("ID contratto ottenuto da Scheda ") . "$id #{$scheda['codice']} ({$scheda['uuid']})"; } } } elseif ($element["type"] == "idPianificazione") { $element["type"] = "text"; //$element["options"] = []; //if (!empty($this->fascicolo["id_pianificazione"])) { // $element["options"][$this->fascicolo["id_pianificazione"]] = __guue("ID pianificazione del fascicolo") . " ({$this->fascicolo['id_pianificazione']})"; //} } foreach($this->locked_sections as $locked_section) { if(str_starts_with($genericKey, $locked_section)) { $element["attrs"]["readonly"] = true; $element["rel"] = []; } } if (in_array($genericKey, $this->locked_fields)) { $element["attrs"]["readonly"] = true; } if (!empty($element["name"])) { $hidden = $element["type"] === "hidden"; echo $hidden ? "" : '
'; echo $this->{$element["type"]}($element); echo $hidden ? "" : '
'; } break; default: if (DEVELOP_ENV) { dump($element); throw new Exception("Unmanaged element exception."); } break; } } } /** * Create the 'id' attribute for the element. * * @param mixed $names * @param mixed $element * @param mixed $withoutRepetitions * @return string */ function establishIdAttributeForElement(array $names, array $element): ?string { if (array_is_list($names)) { if (!($element["_skip_id_name"] ?? false)) { array_push($names, $element["id"]); } return implode(".", $names); } return null; } /** * Establish the key in dot notation * * @param Array $names * @param Array $element * @return string */ function establishKeyInDotNotation(array $names, array $element): ?string { if (array_is_list($names)) { if (!($element["_skip_id_name"] ?? false)) { array_push($names, $element["id"]); } return implode(".", $names); } return null; } /** * Create the 'name' attribute for the element. * * @param Array $names * @param Array $element * @return String */ function establishNameAttributeForElement(array $names, array $element): ?string { if (array_is_list($names)) { if (!($element["_skip_id_name"] ?? false)) { array_push($names, $element["id"]); } $name = "npa[" . implode("][", $names) . "]"; return $name; } return null; } /** * Make repeatable object for ajax request. * * @param Array $settings * @return String */ public static function makeRepeatableObject(array $settings): String { return base64_encode(gzdeflate(json_encode($settings))); } /** * Creates the remove repetition button * * @param string $unique_identifier * @return array */ protected function makeDelButtonElement(string $unique_identifier): array { return [ "name" => "button", "required" => false, "size" => "pr-2", "type" => "button", "title" => "", "attrs" => [ "class" => ["btn btn-xs btn-danger shadow-none ml-3 align-middle npa-delete-button"], "style" => " margin-top: 0.2em;", "onClick" => "elimina('#{$unique_identifier}', 'npa/box'); return false;" ] ]; } /** * Create the button to duplicate an element in the form * * @param String $unique_identifier * @param Array $object * @return array */ protected function makeAddButtonElement(String $unique_identifier, String $object): array { return [ "name" => "button", "required" => false, "size" => "pr-2", "type" => "button", "title" => " " . __guue("Aggiungi") . "", "attrs" => [ "onClick" => "npa.add2Form('{$unique_identifier}', '{$object}');", "class" => ["btn btn-sm btn-block btn-primary"] ] ]; } /** * Retrieves information about the types of form inputs * * @param mixed $form * @return array */ private function getFormInputsTypes(array $form): array { $inputs = []; foreach ($form as $element) { if (in_array($element["contentType"], ["field", "auto-filled"])) { $inputs[$element["id"]] = [ "type" => $element["type"], "format" => $element["format"] ?? "text" ]; } else { $inputs[$element["id"]] = $this->getFormInputsTypes($element["content"]); $inputs[$element["id"]]["_required"] = $element["_required"] ?? false; $inputs[$element["id"]]["_dataType"] = $element["_dataType"] ?? null; $inputs[$element["id"]]["_repeatable"] = $element["_repeatable"] ?? false; $inputs[$element["id"]]["contentType"] = $element["contentType"] ?? false; } } return $inputs; } /** * Generates and outputs the basic JavaScript boilerplate code within the npa component * * @return ?String */ public static function printJavascriptBoilerplate(): ?String { if (!$_SESSION["utente"]->readOnly) { ob_start(); ?> datiPubblicazioneEU) && isset($pubblicazione->datiPubblicazioneEU->noticeId)) : ?> datiPubblicazioneEU->stato->codice ?? "NA" ?>
border-datiPubblicazioneEU->stato->codice == "PUBB" ? 'success' : 'info' ?>">
">
mr-3">Pubblicazione Europa
datiPubblicazioneIT) && property_exists($pubblicazione->datiPubblicazioneIT, "idAvvisoPVL")) : ?>
datiPubblicazioneIT->stato->codice ?? "NA" ?>
border-">
">
mr-3">Pubblicazione Italia
form["rules"] ?? [])); ?>