gestione gare pubbliche
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

1121 righe
33 KiB

<?php
/**
* Bootstrap 4 form generator Trait
*/
trait BS4FormGenerator
{
public $read_only = false;
/*
* Print field options for debug
*/
private function debug_print(Array $options)
{
//return;
echo "<small class='p-2' style='background-color:#000000;color:#fff;'><b>{$options['name']}</b></small>";
}
/**
* Setup validation rules
*
* @param Array $options
* @return void
*/
private function validation(Array $options)
{
$rel = [];
$rel[] = "N";
$rel[] = "0";
$rel[] = "0";
$rel[] = "A";
if(! empty($options["required"])) {
$rel[0] = "S";
$rel[1] = "1";
}
if(! empty($options["rel"]) && is_array($options["rel"])) {
$rel = $options["rel"];
}
$field = substr($options["name"], (strrpos($options["name"], "[") + 1), ((strrpos($options["name"], "]") - 1) - (strrpos($options["name"], "["))));
if(! empty($this->settings["required_if_fields"][$field])) {
if(! empty($this->settings["required_if_fields"][$field]["field"])) {
$rel[3] = "required_if_empty";
$rel[4] = $this->slugify(str_replace("[[FORM]]", "[{$this->form_section}]", $this->settings["required_if_fields"][$field]["field"]));
}
}
return implode(";", $rel);
}
/**
* Check inaccessible methods
*
* @param String $method
* @param Array $parameters
* @return void
*/
public function __call($method, $parameters)
{
if(method_exists($this, "__{$method}")) {
if($method == "label") {
return $this->{"__{$method}"}($parameters[2] ?? "", $parameters[1]);
}
if(! empty($parameters[0]["rel"])) {
$parameters[0]["rel"] = $this->validation($parameters[0]);
}
return $this->{"__{$method}"}($parameters[0]);
}
}
/**
* Print select
*
* @param Array $options
* @return void
*/
public function __select(Array $options)
{
// Supporto per readonly
if(!empty($options["attrs"]) && !empty($options["attrs"]["readonly"])) {
$dummy_options = $options;
$dummy_options["attrs"]["disabled"] = 1;
// Previene che venga aggiornato il suo valore
$dummy_options["attrs"]["data-dummy"] = true;
$dummy_options["name"] = "dummy_" . $dummy_options["name"];
if(isset($options["options"][$options["val"]])) {
$dummy_options["val"] = $options["options"][$options["val"]];
}
$options["value"] = $options["val"];
return $this->__text($dummy_options) . $this->__hidden_but_better($options);
}
if(! empty($options["name"])) {
ob_start();
?>
<div class="form-group <?=!empty($options["assert_fail"]) ? 'text-danger' : null?> <?= $options["size"] ?? 'col-sm-12' ?>">
<?= $this->label($options["name"], $options, $options["title"] ?? null); ?>
<select class="custom-select "
name="<?= $options["name"] ?>"
rel="<?= $options["rel"] ?? null ?>"
<?
if(! empty($options["attrs"]) && is_array($options["attrs"])) {
foreach ($options["attrs"] as $key => $value) {
echo $key . (! empty($value) ? '="'.$value.'"' : null);
echo " ";
}
}
?>
id="<?= $this->slugify($options["name"]) ?>"
title="<?= $options["title"] ?>"
<?if ($this->read_only) {?>
disabled
<?}?>
>
<option value=""><?=__guue("Seleziona un valore...")?></option>
<?
foreach ($options["options"] as $key => $title) {
?><option <?= ($key == ($options["val"] ?? null)) ? 'selected="selected"' : null ?> value="<?= $key ?>"><?= $title ?></option><?
}
?>
</select>
<?
if(! empty($options["help"])) {
?><small id="<?= $this->slugify($options["name"]) ?>-help" class="form-text text-muted"><?= $options["help"] ?></small><?
}
?>
<?
if(! empty($options["assert_fail"])) {
?><div class="invalid-feedback d-block"><?=$options["assert_fail"]?></div><?
}
?>
</div>
<?
return $html = ob_get_clean();
}
return null;
}
public function __number(Array $options = [])
{
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "N";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
public function __decimal(Array $options = [])
{
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "2D";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print Select with Nuts Codes
*
* @param mixed $options
* @return void
*/
function __nuts(Array $options = []) {
global $pdo;
$bind = [];
$sql = "SELECT nuts, descrizione, data_fine_validita FROM b_nuts WHERE data_fine_validita = '' OR data_fine_validita IS NULL";
if(! empty($options["data_fine_validita"])) {
$sql .= "OR DATE(data_fine_validita) >= :data_fine_validita";
$bind[":data_fine_validita"] = $options["data_fine_validita"];
}
$nuts = $pdo->go($sql, $bind);
if($nuts->rowCount() > 0) {
while ($code = $nuts->fetch(PDO::FETCH_ASSOC)) {
if (strlen($code["nuts"]) > 4) {
$options["options"][$code["nuts"]] = $code["descrizione"];
if (! empty($code["data_fine_validita"])) {
$data_fine_validita = mysql2date($code["data_fine_validita"]);
$options["options"][$code["nuts"]] = "{$code["descrizione"]} (data fine validità {$data_fine_validita})";
}
}
}
}
$options["type"] = "select";
return $this->__select($options);
}
/**
* Print text input
*
* @param Array $options
* @return void
*/
public function __text(Array $options = [])
{
if(! empty($options["name"])) {
$class = null;
if(! empty($options["input"]["class"]) && is_array($options["input"]["class"])) {
$class = implode(" ", $options["input"]["class"]);
}
if(! empty($options["override"])) {
foreach ($options["override"] as $key => $value) {
if (array_key_exists($key, $options)) {
$options[$key] = $value;
}
}
}
ob_start();
?>
<div class="form-group <?=!empty($options["assert_fail"]) ? 'text-danger' : null?> <?= $options["size"] ?? null ?>">
<?
if (empty($options["hidden-label"])) {
echo $this->label($options["name"], $options, $options["title"] ?? null);
}
?>
<input type="text"
placeholder="<?= __guue($options["title"] ?? $options["name"]) ?>"
class="form-control <?= $class ?>"
title="<?= __guue($options["title"] ?? $options["name"]) ?>"
rel="<?= $options["rel"] ?? null ?>"
<?
if(! empty($options["attrs"]) && is_array($options["attrs"])) {
foreach ($options["attrs"] as $key => $value) {
echo " {$key}=\"{$value}\" ";
}
}
?>
id="<?= $this->slugify($options["name"]) ?>"
name="<?= $options["name"] ?>"
value="<?= htmlspecialchars($options["val"] ?? null) ?>"
<?if ($this->read_only) {?>
disabled
<?}?>
>
<?
if(! empty($options["help"])) {
?><small id="<?= $this->slugify($options["name"]) ?>-help" class="form-text text-muted"><?= $options["help"] ?></small><?
}
?>
<?
if(! empty($options["assert_fail"])) {
?><div class="invalid-feedback d-block"><?=$options["assert_fail"]?></div><?
}
?>
</div>
<?
if (isset($options["triggerOnChange"])) {
$this->suggestionTriggers[] = $this->slugify($options["name"]);
}
return ob_get_clean();
}
return null;
}
/**
* Print textarea input
*
* @param Array $options
* @return void
*/
public function __textarea(Array $options = [])
{
if(! empty($options["name"])) {
ob_start();
?>
<div class="form-group <?= $options["size"] ?? 'col-sm-12' ?>">
<?= $this->label($options["name"], $options, $options["title"] ?? null); ?>
<textarea class="form-control <?= empty($options["no-ckeditor"]) ? "ckeditor_guee" : null ?> <?= $options["attrs"]["class"] ?? "" ?>"
placeholder="<?= $options["title"] ?? $options["name"] ?>"
id="<?= $this->slugify($options["name"]) ?>"
rel="<?= $options["rel"] ?? null ?>"
name="<?= $options["name"] ?>"
title="<?= $options["title"] ?>"
<? if(! empty($options["attrs"])) { foreach ($options["attrs"] as $key => $value) { if($key !== "class") { echo "{$key}=\"{$value}\" "; } } } ?>
rows="3"><? if(! empty($options["val"])) { echo $options["val"]; } ?>
<?if ($this->read_only) {?>
disabled
<?}?>
</textarea>
<?
if(! empty($options["assert_fail"])) {
?><div class="invalid-feedback d-block"><?=$options["assert_fail"]?></div><?
}
?>
</div>
<?
if (isset($options["triggerOnChange"])) {
$this->suggestionTriggers[] = $this->slugify($options["name"]);
}
return $html = ob_get_clean();
}
return null;
}
/**
* Print value input
*
* @param Array $options
* @return void
*/
public function __value(Array $options) {
if (!empty($options["name"])) {
ob_start();
?>
<?php if(!isset($options["attrs"]["readonly"])) : ?>
<div class="form-group <?=!empty($options["assert_fail"]) ? 'text-danger' : null?> row px-3">
<div class="col-8 pl-0">
<?
if (empty($options["hidden-label"])) {
echo $this->label($options["name"], $options, $options["title"] ?? null);
}
?>
<input type="text"
placeholder="<?= __guue($options["title"] ?? $options["name"]) ?>"
class="form-control"
title="<?= __guue($options["title"] ?? $options["name"]) ?>"
rel="<?= $options["rel"] ?? null ?>"
<?
if(! empty($options["attrs"]) && is_array($options["attrs"])) {
foreach ($options["attrs"] as $key => $value) {
echo "{$key}=\"{$value}\"";
}
}
?>
id="<?= $this->slugify($options["name"]) ?>"
name="<?= $options["name"] ?>[value]"
value="<?= htmlspecialchars($options["val"]["value"] ?? null) ?>">
<?
?>
</div>
<div class="col-4 pr-0">
<?= $this->label($options["name"], $options, __guue("Valuta")); ?>
<?
if (!empty($options["rel"])) {
$options["rel"] = explode(";",$options["rel"]);
$options["rel"][3] = "A";
$options["rel"] = implode(";",$options["rel"]);
}
?>
<select class="custom-select "
name="<?= $options["name"] ?>[type]"
rel="<?= $options["rel"] ?? null ?>"
<?
if(! empty($options["attrs"]) && is_array($options["attrs"])) {
foreach ($options["attrs"] as $key => $value) {
echo $key . (! empty($value) ? '="'.$value.'"' : null);
}
}
?>
id="<?= $this->slugify($options["name"]) ?>"
title="<?= $options["title"] ?>">
<?php $selected_option = $options["val"]["type"] ?? "" ?>
<?php
// TODO Usare quelli della codelist direttamente
foreach(TedEsender::CURRENCIES as $value => $label) {
?>
<option <?=$selected_option == $value ? 'selected="selected"' : null ?> value="<?= htmlspecialchars($value) ?>"><?=__guue($label)?></option>
<?php
}
?>
</select>
<?
if(! empty($options["help"])) {
?><small id="<?= $this->slugify($options["name"]) ?>-help" class="form-text text-muted"><?= $options["help"] ?></small><?
}
?>
</div>
<?
if(! empty($options["assert_fail"])) {
?><div class="invalid-feedback d-block"><?=$options["assert_fail"]?></div><?
}
?>
</div>
<?php else:
// Supporto al readonly
$dummy_options = $options;
unset($dummy_options["rel"]);
$dummy_options["attrs"]["disabled"] = 1;
// Previene che venga aggiorntao il suo valore
$dummy_options["attrs"]["data-dummy"] = true;
$dummy_options["name"] = "dummy_" . $dummy_options["name"];
$dummy_options["val"] = number_format($options["val"]["value"], 2, ".", "") . " " . $options["val"]["type"];
//$dummy_options["rel"] = ["N", "0", "0", "N"]; // . " " . $options["val"]["type"];
//$options["value"] = $options["val"];
$value_options = $options;
unset($value_options["rel"]);
$value_options["value"] = $options["val"]["value"];
$value_options["name"] .= "[value]";
$type_options = $options;
unset($type_options["rel"]);
$type_options["name"] .= "[type]";
$type_options["value"] = $options["val"]["type"];
echo $this->__text($dummy_options);
echo $this->__hidden_but_better($value_options);
echo $this->__hidden_but_better($type_options);
endif; ?>
<?
return ob_get_clean();
}
return null;
}
/**
* Print duration input
*
* @param Array $options
* @return void
*/
public function __duration(Array $options) {
if (!empty($options["name"])) {
ob_start();
?>
<div class="form-group <?=!empty($options["assert_fail"]) ? 'text-danger' : null?> row px-3">
<div class="col-9 pl-0">
<?
if (empty($options["hidden-label"])) {
echo $this->label($options["name"], $options, $options["title"] ?? null);
}
?>
<input type="text"
placeholder="<?= __guue($options["title"] ?? $options["name"]) ?>"
class="form-control"
title="<?= __guue($options["title"] ?? $options["name"]) ?>"
rel="<?= $options["rel"] ?? null ?>"
<?
if(! empty($options["attrs"]) && is_array($options["attrs"])) {
foreach ($options["attrs"] as $key => $value) {
echo "{$key}=\"{$value}\"";
}
}
?>
id="<?= $this->slugify($options["name"]) ?>"
name="<?= $options["name"] ?>[value]"
value="<?= htmlspecialchars($options["val"]["value"] ?? null) ?>">
<?
?>
</div>
<div class="col-3 pr-0">
<?= $this->label($options["name"], $options, __guue("Tipologia")); ?>
<select class="custom-select "
name="<?= $options["name"] ?>[type]"
rel="<?= $options["rel"] ?? null ?>"
<?
if(! empty($options["attrs"]) && is_array($options["attrs"])) {
foreach ($options["attrs"] as $key => $value) {
echo $key . (! empty($value) ? '="'.$value.'"' : null);
}
}
?>
id="<?= $this->slugify($options["name"]) ?>"
title="<?= $options["title"] ?>">
<?php $selected_option = $options["val"]["type"] ?? "" ?>
<option <?=$selected_option == "DAY" ? 'selected="selected"' : null ?> value="DAY"><?=__guue('Giorni')?></option>
<option <?=$selected_option == "MONTH" ? 'selected="selected"' : null ?> value="MONTH"><?=__guue('Mesi')?></option>
<option <?=$selected_option == "WEEK" ? 'selected="selected"' : null ?> value="WEEK"><?=__guue('Settimane')?></option>
<option <?=$selected_option == "YEAR" ? 'selected="selected"' : null ?> value="YEAR"><?=__guue('Anni')?></option>
</select>
<?
if(! empty($options["help"])) {
?><small id="<?= $this->slugify($options["name"]) ?>-help" class="form-text text-muted"><?= $options["help"] ?></small><?
}
?>
</div>
<?
if(! empty($options["assert_fail"])) {
?><div class="invalid-feedback d-block"><?=$options["assert_fail"]?></div><?
}
?>
</div>
<?
return ob_get_clean();
}
return null;
}
/**
* Print checkbox input
*
* @param Array $options
* @return void
*/
public function __checkbox(Array $options = [])
{
if(! empty($options["name"])) {
$rel = explode(";",$options["rel"]);
if (count($rel) > 3 && $rel[3] != "Checked") {
$rel[3] = "Checked";
$options["rel"] = implode(";",$rel);
}
ob_start();
$checked = false;
?>
<div class="<?= $options["size"] ?? 'col-sm-12' ?>">
<div class="form-check mb-3">
<input class="form-check-input <?= $options["attrs"]["class"] ?? "" ?> <?=$options["required"] ? "valida" : ""?>"
type="checkbox"
value="__£__"
name="<?= $options["name"] ?>"
rel ="<?= $options["rel"] ?>"
title="<?= $options["title"] ?? ''?>"
id="<?= $this->slugify($options["name"]) ?>"
<? if(! empty($options["val"]) && $options["val"] == ($options["value"] ?? "__£__") ) {
$checked = true;
echo 'checked="checked"';
} ?>
<? if(! empty($options["attrs"])) { foreach ($options["attrs"] as $key => $value) { if($key !== "class") { echo "{$key}=\"{$value}\" "; } } } ?>>
<label class="form-check-label" for="<?= $this->slugify($options["name"]) ?>">
<?= $options["title"] ?? $options["name"] ?> <?=$options["required"] ? TedEsender::MANDATORY_ASTERISK : ""?>
</label>
</div>
</div>
<?
if ($checked && isset($options["triggerOnChange"])) {
$this->suggestionTriggers[] = $this->slugify($options["name"]);
}
return $html = ob_get_clean();
}
return null;
}
/**
* Print a text line
*
* @param array $options
* @return void
*/
public function __text_line(Array $options = [])
{
if(! empty($options["name"])) {
return "<div class='col-sm-12'><p>{$options["name"]}</p></div>";
}
return null;
}
/**
* Print a weight data
*
* @param array $options
* @return void
*/
public function __weight(Array $options = [])
{
if(! empty($options["name"])) {
$class = null;
if(! empty($options["input"]["class"]) && is_array($options["input"]["class"])) $class = implode(" ", $options["input"]["class"]);
if(! empty($options["override"])) {
foreach ($options["override"] as $key => $value) {
if (array_key_exists($key, $options)) {
$options[$key] = $value;
}
}
}
ob_start();
?>
<div class="form-group row <?= $options["size"] ?? null ?> <?=!empty($options["assert_fail"]) ? 'text-danger' : null?> m-0">
<div class="col-sm-12 col-md-2 d-flex">
<?= $this->label($options["name"], $options, $options["title"] ?? null); ?>
</div>
<input type="text"
placeholder="<?= __guue($options["title"] ?? $options["name"]) ?>"
class="col-sm-12 col-md-8 form-control <?= $class ?>"
title="<?= __guue($options["title"] ?? $options["name"]) ?>"
rel="<?= $options["rel"] ?? null ?>"
<?
if(! empty($options["attrs"]) && is_array($options["attrs"])) {
foreach ($options["attrs"] as $key => $value) {
echo "{$key}=\"{$value}\" ";
}
}
?>
id="<?= $this->slugify($options["name"]) ?>"
name="<?= $options["name"] ?>"
value="<?= htmlspecialchars($options["val"] ?? null) ?>">
<div class="col-sm-12 col-md-2 d-flex p-0">
<span class="mt-auto pb-2 mx-auto">/100</span>
</div>
<?
if(! empty($options["assert_fail"])) {
?><div class="invalid-feedback d-block"><?=$options["assert_fail"]?></div><?
}
?>
</div>
<?
if (isset($options["triggerOnChange"])) {
$this->suggestionTriggers[] = $this->slugify($options["name"]);
}
return $html = ob_get_clean();
}
return null;
}
public function __cpv(Array $options)
{
global $pdo;
$id = $this->slugify($options["name"]);
ob_start();
?>
<div class="form-group <?=!empty($options["assert_fail"]) ? 'text-danger' : null?> <?= $options["size"] ?? null ?>">
<label class="mb-0" for="<?= $id ?>"><?= $options["title"] . (($options["required"] ?? false) ? TedEsender::MANDATORY_ASTERISK : '') ?>: </label>
<div id="<?= $id ?>-search-cpv" class="<?= ! empty($options["val"]) ? 'd-none' : null ?>">
<input
id="<?= $id ?>"
<?
if(! empty($options["attrs"]) && is_array($options["attrs"])) {
foreach ($options["attrs"] as $key => $value) {
if($key == "class") continue;
echo "{$key}=\"{$value}\" ";
}
}
?>
type="text"
placeholder="<?= __guue("Scrivi per ricercare una") ?> CPV"
title="<?= __guue("Scrivi per ricercare una") ?> CPV"
autocomplete="false"
class="form-control"
>
<input type='hidden' name='<?= $options["name"] ?>' id='<?= "input-{$id}" ?>'>
<script>
$("#<?= $id ?>").typeahead({
hint: false,
highlight: true,
minLength: 2,
limit: 9999
}, {
name: 'cpv',
display: 'label',
source: function (query, syncResults, asyncResults) {
var selezionate = [];
$(".selected-cpv", "#<?= $id ?>").each(function () {
selezionate.push($(this).val());
});
$.ajax({
url: "/inc/cpv/autocomplete.php?minlength=<?= ! empty($options["minlength"]) ? $options["minlength"] : 2 ?>&macro=<?= ! empty($options["macro"]) ? $options["macro"] : '' ?>",
dataType: "json",
data: {
query: query,
selezionate: btoa(selezionate.join(","))
},
success: function (data) {
asyncResults(data);
}
});
},
limit: 9999
}).bind('typeahead:select', function (ev, suggestion) {
$.getJSON("/inc/cpv/info.php", {cpv: suggestion.value}, function (data, textStatus, jqXHR) {
if("codice" in data) {
var cpv = $("<div>", {class: "list-group-item d-flex align-items-center", id: "cpv-" + suggestion.value});
var title = $('<span>', {class: 'text-left flex-fill'}).text(data["codice_completo"] + " - " + data["IT"]);
var button = $('<button>', {class: 'btn btn-danger btn-sm', type: 'button', onClick: "deleteCPV('#cpv-" + suggestion.value +"','<?=$id?>');"}).html('<span class="fa fa-times"></span><span class="sr-only"><?= __guue("elimina") ?></span>');
cpv.append(title)
<?php if(!isset($options["attrs"]["readonly"])) : ?>
.append(button)
<?php endif; ?>;
$('#<?= $id ?>-search-cpv').addClass('d-none');
$('.list-group', "#<?= $id ?>-cpv-list").append(cpv);
$("#<?= $id ?>-cpv-list").removeClass('d-none');
const input = document.getElementById(`<?= "input-{$id}" ?>`);
input.value = suggestion.value;
$(input).trigger('change');
}
});
$('#<?= $id ?>').focus().typeahead('val', "");
$("#val" + suggestion.value).remove();
});
var deleteCPV = function(cpv, id) {
$(cpv).remove();
$(`#${id}-search-cpv`).removeClass('d-none');
$(`#${id}-cpv-list`).addClass('d-none');
const input = document.getElementById(`<?= "input-{$id}" ?>`);
input.value = null;
$(input).trigger('change');
}
</script>
</div>
<div id="<?= $id ?>-cpv-list" class="<?= empty($options["val"]) ? 'd-none' : null ?>">
<div class="list-group">
<?
if(! empty($options["val"])) {
$cpv = $pdo->go("SELECT * FROM b_cpv WHERE codice = :codice", [":codice" => $options["val"]])->fetch(PDO::FETCH_ASSOC);
if(! empty($cpv)) {
?>
<div id="cpv-<?= $cpv["codice_completo"] ?>" class="list-group-item py-2 d-flex align-items-center <?php if(isset($options["attrs"]["readonly"])) : ?> bg-secondary-muted <?php endif; ?>">
<span class="text-left flex-fill"><?=$cpv["codice_completo"]?>-<?= $cpv["IT"] ?></span>
<?php if(!isset($options["attrs"]["readonly"])) : ?>
<button class="btn btn-danger btn-sm" type="button" onclick="deleteCPV('#cpv-<?= $cpv['codice_completo'] ?>','<?=$id?>');"><span class="fa fa-times"></span><span class="sr-only"><?= __guue("elimina") ?></span></button>
<?php endif; ?>
<input type="hidden" name="<?= $options["name"] ?>" id="<?= "input-{$id}" ?>" value="<?= $cpv["codice"] ?>" <?=!empty($options["rel"]) ? "rel={$options['rel']}" : '' ?> >
</div>
<?
}
}
?>
</div>
</div>
</div>
<?
return ob_get_clean();
}
/**
* Print checkbox input
*
* @param Array $options
* @return void
*/
public function __radio(Array $options = [])
{
if(! empty($options["name"])) {
ob_start();
?>
<div class="form-group <?=!empty($options["assert_fail"]) ? 'text-danger' : null?> <?= $options["size"] ?? 'col-sm-12' ?>">
<?= $this->label($options["name"], $options, $options["title"] ?? null); ?>
<select class="custom-select "
name="<?= $options["name"] ?>"
rel="<?= $options["rel"] ?? null ?>"
<?
if(! empty($options["attrs"]) && is_array($options["attrs"])) {
foreach ($options["attrs"] as $key => $value) {
echo $key . (! empty($value) ? '="'.$value.'"' : null);
echo " ";
}
}
?>
id="<?= $this->slugify($options["name"]) ?>"
title="<?= $options["title"] ?>">
<option value=""><?=__guue("Seleziona un valore...")?></option>
<?
foreach ($options["options"] as $key => $title) {
?><option <?= ($key == ($options["val"] ?? null)) ? 'selected="selected"' : null ?> value="<?= $key ?>"><?= $title ?></option><?
}
?>
</select>
<?
if(! empty($options["help"])) {
?><small id="<?= $this->slugify($options["name"]) ?>-help" class="form-text text-muted"><?= $options["help"] ?></small><?
}
?>
</div>
<?
if(! empty($options["assert_fail"])) {
?><div class="invalid-feedback d-block"><?=$options["assert_fail"]?></div><?
}
?>
<?
return $html = ob_get_clean();
}
return null;
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __datetime(Array $options = [])
{
$options["input"]["class"] = ["datetimepick"];
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "DT";
if ($options["object"] == "date_full") {
$options["input"]["class"] = ["datepick"];
$options["rel"][3] = "D";
} else if ($options["object"] == "time") {
$options["input"]["class"] = ["timepick"];
$options["rel"][3] = "T";
}
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __date(Array $options = [])
{
$options["input"]["class"] = ["datepick"];
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "D";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __time(Array $options = [])
{
$options["input"]["class"] = ["time"];
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "T";
$options["rel"] = implode(";", $options["rel"]);
if (!empty($options["val"])) {
preg_match('/^\d{2}:\d{2}/',$options["val"],$m);
if (!empty($m)) {
$options["val"] = $m[0];
}
}
return $this->__text($options);
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __email(Array $options = [])
{
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "E";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __url(Array $options = [])
{
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "L";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print label
*
* @param String $name
* @param String $title
* @return void
*/
public function __label(String $name, Array $options, String $title = null)
{
if(! empty($name)) {
ob_start();
?><label class="mb-0 <?= ! empty($options["label-attrs"]["class"]) ? $options["label-attrs"]["class"] : null ?>" for="<?= $this->slugify($name) ?>"><?= __guue($title ?? $name) ?>: <?= ! empty($options["required"]) ? TedEsender::MANDATORY_ASTERISK : null ?></label><?
return $html = ob_get_clean();
}
return null;
}
/**
* Print a div
*
* @param array $options
* @return void
*/
public function __div(Array $options = [])
{
ob_start();
?>
<div class="<?=! empty($options["hidden"]) && $options["hidden"] ? 'd-none' : 'col-sm-12'?>">
<div <? if(! empty($options["attrs"])) { foreach ($options["attrs"] as $key => $value) { echo "{$key}=\"{$value}\" "; } } ?>>
<?
if(! empty($options["key"])) {
$values = self::get($this->info["valori"], $options["key"]);
$object = json_decode(@gzinflate(base64_decode($options["object"])), 1);
if(! empty($values) && ! empty($object) && (! empty($options["object"]) || $options["object"] !== "empty") || ! empty($object["force-show"])) {
$form = str_replace('.xsd', '', $object["xsd"]);
$ted = new TedEsender($form, $this->info["codice"], $this->settings);
$ted->setMode("bs4formgenerator");
$ted->debug = $this->debug;
if (isset($options["ignored_keys"])) $ted->ignored_keys = array_merge($ted->ignored_keys,$options["ignored_keys"]);
if(! empty($object["child"])) {
$child = new SimpleXMLIterator($object["child"]);
}
$title = end($object["settings"]["name"]);
if(! isset($object["multiple"]) || ! empty($object["multiple"])) {
if(! empty($object["key"])) {
$name = strtoupper($object["key"]);
if(! in_array($name, $object["settings"]["name"])) {
$object["settings"]["name"][] = $name;
}
}
$object["settings"]["name"][] = "£";
foreach ($values["£"] ?? $values as $id => $value) {
$s = $object["settings"];
$s["name"][] = $id;
$ted->fields = [];
$ted->getField($object["section"], $child, $s);
$ted->ignored_keys[] = $id;
?>
<div class="<?= empty($object["hidden-header"]) ? 'mb-3' : null ?>" id="<?= "container_{$id}" ?>">
<div class="card mb-3">
<?
if(empty($object["hidden-header"])) {
?>
<div class="card-header d-flex align-items-center">
<div class="col pl-0">
<?
$names = $s["name"];
do {
$name = array_pop($names);
} while (in_array($name, $ted->ignored_keys));
echo $ted->translate(str_replace("DYN_SECTION_", "", $title ?? $name));
?>
</div>
<button type="button" class="btn btn-sm btn-danger" title="Elimina" onclick="elimina('<?= '#container_' . $id ?>','guue/box'); return false;" placeholder="Elimina"><i class="fas fa-trash-alt"></i></button>
</div>
<?
}
?>
<div class="card-body">
<?
if((! isset($object["multiple"]) || $object["multiple"] == 1) && isset($object["hidden-header"]) && $object["hidden-header"]) {
?><div class="row"><div class="col-12 text-right"><a href="javascript:void(0)" class="text-muted" onclick="elimina('<?= '#container_' . $id ?>','guue/box');"><i class="fas fa-times"></i></a></div></div><?
}
?>
<div class="row">
<? $ted->printFields($object["section"]); ?>
</div>
</div>
</div>
</div>
<?
}
} else {
$ted->fields = [];
$ted->getField($object["section"], $child, $object["settings"]);
$title = end($object["settings"]["name"]);
#region[ShowToGaetano]
#OCCHIO CHE QUI SI POTREBBE PRESENTARE UN BUG INFIMO:
#In alcuni casi l'id non veniva valorizzato e rompeva l'interfaccia.
#Aggiungendolo come variabile qui e specificando l'id del container funziona
#Però non so per quale motivo questo errore si presenti solo nell'F14 e mai prima
$id = uniqid();
#endregion
?>
<div id="container_<?=$id?>" class="<?= empty($object["hidden-header"]) ? 'mb-3' : null ?>">
<div class="card mb-3">
<?
if(empty($object["hidden-header"])) {
?>
<div class="card-header d-flex align-items-center">
<div class="col pl-0">
<?
$names = $object["settings"]["name"];
do {
$name = array_pop($names);
} while (in_array($name, $ted->ignored_keys));
echo $ted->translate(str_replace("DYN_SECTION_", "", $title ?? $name));
?>
</div>
<button type="button" class="btn btn-sm btn-danger" title="Elimina" onclick="elimina('<?= '#container_' . $id ?>','guue/box'); return false;" placeholder="Elimina"><i class="fas fa-trash-alt"></i></button>
</div>
<?
}
?>
<div class="card-body">
<div class="row">
<? $ted->printFields($object["section"]); ?>
</div>
</div>
</div>
</div>
<?
}
}
}
?>
</div>
</div>
<?
return ob_get_clean();
}
public function __hidden_but_better(Array $options = [])
{
ob_start();
?>
<input type="hidden"
id="<?= $this->slugify($options["name"]) ?>"
value="<?= htmlspecialchars($options["value"] ?? "") ?>"
name="<?= $options["name"] ?>">
<?
return ob_get_clean();
}
public function __hidden(Array $options = [])
{
ob_start();
?>
<input type="hidden"
id="<?= $this->slugify($options["name"]) ?>"
value="<?= (($options["value"] ?? null) != null && $options["value"] != '') ? $options["value"] : "__£__" ?>"
name="<?= $options["name"] ?>">
<?
return ob_get_clean();
}
public function __button(Array $options = [])
{
ob_start();
?>
<div class="<?= $options["size"] ?? 'col-sm-12' ?>">
<button type="button" <? if(! empty($options["attrs"])) { foreach ($options["attrs"] as $key => $value) { echo "{$key}=\"{$value}\" "; } } ?>><?= $options["title"] ?></button>
</div>
<?
return ob_get_clean();
}
public static function slugify($text)
{
$text = preg_replace('~[^\pL\d]+~u', '-', $text); // replace non letter or digits by -
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); // transliterate
$text = preg_replace('~[^-\w]+~', '', $text); // remove unwanted characters
$text = trim($text, '-'); // trim
$text = preg_replace('~-+~', '-', $text); // remove duplicate -
$text = strtolower($text); // lowercase
if (empty($text)) return 'n-a';
return $text;
}
}