*";
}
// Stampa la label con il nome interno del campo
private static function printCodeLabel(array $options) {
// Dividiamo la data reference
$split = explode(".", $options["attrs"]["data-reference"] ?? ".");
$index = array_key_last($split);
$label = $split[$index];
// Se la label trovata non è utile cerchiamone una utile
while($index > 0 && (in_array($label, ["codice", "*"]) || is_numeric($label))) {
$label = $split[--$index];
}
?>
= $label ?>
{"__{$method}"}($parameters[2] ?? "", $parameters[1]);
}
$parameters[0]["rel"] = $this->validation($parameters[0]);
return $this->{"__{$method}"}($parameters[0]);
}
}
/**
* Selezione codice istat
*
* @return void
*/
public function __codice_istat(array $options)
{
$options["attrs"]["class"][] = "not-chosen";
$options["field_id"] = uniqid("codice_istat_");
if (!empty($options["val"])) {
global $pdo;
$option = $pdo->go("SELECT * FROM b_istat_anac WHERE codice_istat = :codice_istat", [":codice_istat" => $options["val"]])->fetch(PDO::FETCH_ASSOC);
if($option)
$options["options"] = [$option["codice_istat"] => "{$option["etichetta"]}"];
}
ob_start();
echo $this->__select($options);
?>
return ob_get_clean();
}
/**
* Tiene traccia che il boilerplate venga salvato una sola volta
*
* @var boolean
*/
private $__centroCostoPrintBoilerplate = true;
/**
* Select per centri di costo con auto refresh dei componenti
*
* @param Array $options
* @return void
*/
public function __centroCosto(array $options)
{
// Inizializziamo cone not-chosen per avere un select2
$options["attrs"]["class"][] = "not-chosen";
$options["attrs"]["centroCosto"] = "";
$options["field_id"] = uniqid("centroCosto_");
$options["options"] = [$options["val"] => $options["val"]];
ob_start();
echo $this->__select($options);
?>
return ob_get_clean();
}
/**
* Print select
*
* @param Array $options
* @return void
*/
public function __select(array $options)
{
// Supporto per readonly
if (!empty($options["attrs"]) && !empty($options["attrs"]["readonly"])) {
if(isset($options["attrs"]["centroCosto"])) {
} else {
$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"]) && isset($options["options"][$options["val"]])) {
$dummy_options["val"] = $options["options"][$options["val"]];
} else {
$dummy_options["val"] = $options["val"];
}
$options["value"] = $options["val"];
return $this->__text($dummy_options) . $this->__hidden_but_better($options);
}
}
if (!empty($options["name"])) {
ob_start();
?>
">
= $this->label($options["name"], $options, $options["title"] ?? null); ?>
" name="= $options["name"] ?>" rel="= $options["rel"] ?? null ?>" data-rel="= $options["rel"] ?? null ?>"
$this->printAttributes($options["attrs"] ?? []) ?> id="= $options["field_id"] ?? $this->slugify($options["name"]) ?>" title="= $options["title"] ?>">
= __guue("Seleziona un valore...") ?>
foreach (($options["options"] ?? []) as $key => $title) {
?>
value="= $key ?>">
= $title?>
}
?>
if (!empty($options["help"])) {
?>-help" class="form-text text-muted">= $options["help"] ?>
}
?>
return ob_get_clean();
}
return null;
}
/**
* __number
*
* @param mixed $options
* @return void
*/
public function __number(array $options = [])
{
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "N";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* __decimal
*
* @param mixed $options
* @return void
*/
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"]) > 3) {
$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();
?>
">
if (empty($options["hidden-label"])) {
echo $this->label($options["name"], $options, $options["title"] ?? null);
}
?>
" class="form-control = $class ?> = (!empty($options["attrs"]["class"]) && is_array($options["attrs"]["class"])) ? implode(" ", $options["attrs"]["class"]) : null ?>" data-regex="= $options["pattern"] ?>" title="= __guue($options["title"] ?? $options["name"]) ?>" rel="= $options["rel"] ?? null ?>" data-rel="= $options["rel"] ?? null ?>" $this->printAttributes($options["attrs"] ?? []) ?> id="= $options["field_id"] ?? $this->slugify($options["name"]) ?>" name="= $options["name"] ?>" value="= $options["val"] ?? null ?>">
if (!empty($options["help"])) {
?>-help" class="form-text text-muted">= $options["help"] ?>
}
?>
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();
?>
">
= $this->label($options["name"], $options, $options["title"] ?? null); ?>
return ob_get_clean();
}
if (!empty($options["help"])) {
?>-help" class="form-text text-muted">= $options["help"] ?>
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();
?>
return 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 "";
}
return null;
}
/**
* Print CPV Selector
*
* @param mixed $options
* @return void
*/
public function __cpv(array $options)
{
global $pdo;
$id = $this->slugify(uniqid('', true));
ob_start();
?>
">
= $options["title"] . (($options["required"] ?? false) ? self::asterisk() : '') ?>:
= self::printCodeLabel($options) ?>
printAttributes($options["attrs"] ?? []) ?> placeholder="= __guue("Scrivi per ricercare una") ?> CPV" title="= __guue("Scrivi per ricercare una") ?> CPV" autocomplete="false" class="form-control">
mt-3">
if (!empty($options["val"])) {
$cpv = $pdo->go("SELECT * FROM b_cpv WHERE codice = :codice", [":codice" => $options["val"]])->fetch(PDO::FETCH_ASSOC);
if (!empty($cpv)) {
?>
" class="list-group-item d-flex align-items-center">
= $cpv["codice_completo"] ?>-= $cpv["IT"] ?>
= __guue("elimina") ?>
" id="= "input-{$id}" ?>" value="= $cpv["codice"] ?>" = !empty($options["rel"]) ? "rel={$options['rel']}" : '' ?>>
}
}
?>
return ob_get_clean();
}
/**
* Print checkbox input
*
* @param Array $options
* @return void
*/
public function __radio(array $options = [])
{
if (!empty($options["name"])) {
ob_start();
?>
= $options["size"] ?? 'col-sm-12' ?>">
= $this->label($options["name"], $options, $options["title"] ?? null); ?>
" name="= $options["name"] ?>" rel="= $options["rel"] ?? null ?>" data-rel="= $options["rel"] ?? null ?>"
$this->printAttributes($options["attrs"] ?? []) ?> id="= $options["field_id"] ?? $this->slugify($options["name"]) ?>" title="= $options["title"] ?>">
= __guue("Seleziona un valore...") ?>
foreach ($options["options"] as $key => $title) {
?>
value="= $key ?>">
= $title ?>
}
?>
if (!empty($options["help"])) {
?>-help" class="form-text text-muted">= $options["help"] ?>
}
?>
return ob_get_clean();
}
return null;
}
/**
* Print input attributes
*
* @param mixed $attributes
* @return void
*/
public function printAttributes(array $attributes): void
{
if (!empty($attributes) && is_array($attributes) && !array_is_list($attributes)) {
foreach ($attributes as $key => $value) {
if ($key !== "class") {
echo ' ' . $key . (isset($value) ? '="' . $value . '"' : 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";
$object = $options["object"] ?? "";
if ($object == "date_full") {
$options["input"]["class"][] = "datepick";
$options["rel"][3] = "D";
} else if ($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();
?>
" for="= $this->slugify($name) ?>">= __guue($title ?? $name) ?>:
= (!empty($options["required"]) || (!empty($options["rel"] && $options["rel"][0] == "S"))) ? self::asterisk() : null ?>
= self::printCodeLabel($options) ?>
return ob_get_clean();
}
return null;
}
public function __hidden_but_better(array $options = [])
{
ob_start();
?>
" value="= ($options["value"] ?? "") ?>" name="= $options["name"] ?>">
return ob_get_clean();
}
/**
* Print an hidden input
*
* @param mixed $options
* @return void
*/
public function __hidden(array $options = [])
{
ob_start();
?>
slugify($options["name"]) ?>" value="= ($options["val"] ?? "") ?>" name="= $options["name"] ?>">
return ob_get_clean();
}
/**
* Print a button
*
* @param mixed $options
* @return void
*/
public function __button(array $options = [])
{
ob_start();
?>
">
printAttributes($options["attrs"]) ?> class="= (!empty($options["attrs"]["class"]) && is_array($options["attrs"]["class"])) ? implode(" ", $options["attrs"]["class"]) : null ?>">= $options["title"] ?>
return ob_get_clean();
}
/**
* slugify
*
* @param mixed $text
* @return void
*/
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;
}
}