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.
 
 
 
 
 

1282 righe
66 KiB

<?
class FormManager {
private $pdo;
private $token;
private $element_id;
private $element_type;
private $codice_form;
private $codice_ente;
public $info;
public $preview;
public $duplicateID;
public $stripEnte;
public $forcedData;
private $root;
public function __construct() {
global $pdo;
global $root;
$this->pdo = $pdo;
$this->root = $root;
$this->token = base64_encode(tokenGen());
$this->element_id = 0;
$this->element_type = "";
$this->duplicateID = null;
$this->preview = false;
}
public static function listFormEnte($codice_ente) {
global $pdo;
return $pdo->go("SELECT * FROM b_form WHERE codice_ente = :ente AND attivo = 'S' AND soft_delete = 'N'",[":ente"=>$codice_ente])->fetchAll(PDO::FETCH_ASSOC);
}
public function getInputInfo($codice_record) {
$bind = [":codice"=>$codice_record,":id"=>$this->element_id,":type"=>$this->element_type];
$record = $this->pdo->go("SELECT * FROM b_form_data WHERE codice = :codice AND id = :id AND type = :type ",$bind);
if ($record->rowCount() === 1) {
$record = $record->fetch(PDO::FETCH_ASSOC);
$group = $this->pdo->go("SELECT * FROM b_form_group WHERE codice = :codice",[":codice"=>$record["codice_gruppo"]]);
if ($group->rowCount() === 1) {
$return["gruppo"] = $group->fetch(PDO::FETCH_ASSOC);
$input = $this->pdo->go("SELECT * FROM b_form_input WHERE codice = :codice",[":codice"=>$record["codice_input"]]);
if ($input->rowCount() === 1) {
$return["input"] = $input->fetch(PDO::FETCH_ASSOC);
return $return;
}
}
}
return false;
}
public function init($codice_form,$element_type,$element_id=0) {
$return = false;
if (!empty($element_type) && !empty($codice_form)) {
$this->element_type = $element_type;
$this->codice_form = $codice_form;
$sql = "SELECT * FROM b_form WHERE codice = :id AND attivo = 'S' AND soft_delete = 'N'";
$ris = $this->pdo->go($sql,array(":id"=>$this->codice_form));
if ($ris->rowCount() === 1) {
$this->info = $ris->fetch(PDO::FETCH_ASSOC);
if (!empty($this->info)) {
$this->codice_ente = $this->info["codice_ente"];
}
$return = true;
}
}
$this->element_id = $element_id;
return $return;
}
public function getente() {
return $this->codice_ente;
}
private function getGroupID($group,$radice="") {
$return = array("codice"=>array(),"id"=>array());
if (!empty($group["id"])) { $radice .= $group["id"] . "/"; }
$sql = "SELECT * FROM b_form_group WHERE codice_gruppo = :codice_gruppo AND soft_delete = 'N' ORDER BY ordinamento ";
$ris = $this->pdo->go($sql,array(":codice_gruppo"=>$group["codice"]));
if ($ris->rowCount() > 0) {
while ($tmp_group = $ris->fetch(PDO::FETCH_ASSOC)) {
$tmp = $this->getGroupID($tmp_group,$radice);
$return["codice"] = array_merge($tmp["codice"],$return["codice"]);
$return["id"] = array_merge($tmp["id"],$return["id"]);
}
} else {
$sql = "SELECT * FROM b_form_input WHERE codice_gruppo = :codice_gruppo AND soft_delete = 'N' ORDER BY ordinamento ";
$ris_input = $this->pdo->go($sql,array(":codice_gruppo"=>$group["codice"]));
if ($ris_input->rowCount() > 0) {
while ($input = $ris_input->fetch(PDO::FETCH_ASSOC)) {
if (!empty($input["id"])) {
$input["id"] = $radice.$input["id"];
$return["id"][$input["id"]] = $input;
}
$return["codice"]["#".$input["codice"]] = $input;
}
}
}
return $return;
}
public static function getInfoFromID($id_form,$codice_ente) {
global $pdo;
if (!empty($codice_ente)) {
$sql = "SELECT * FROM b_form WHERE id = :id AND codice_ente = :codice_ente AND attivo = 'S' AND soft_delete = 'N'";
$ris = $pdo->go($sql,array(":id"=>$id_form,":codice_ente"=>$codice_ente));
if ($ris->rowCount() === 1) { return $ris->fetch(PDO::FETCH_ASSOC); }
}
$sql = "SELECT * FROM b_form WHERE id = :id AND attivo = 'S' AND soft_delete = 'N'";
$ris = $pdo->go($sql,array(":id"=>$id_form));
if ($ris->rowCount() === 1) { return $ris->fetch(PDO::FETCH_ASSOC); }
return false;
}
public static function getInfo($codice_form) {
global $pdo;
$sql = "SELECT * FROM b_form WHERE codice = :id AND attivo = 'S' AND soft_delete = 'N'";
$ris = $pdo->go($sql,array(":id"=>$codice_form));
if ($ris->rowCount() === 1) { return $ris->fetch(PDO::FETCH_ASSOC); }
return false;
}
public function getIDS() {
$return = false;
if (!empty($this->codice_form)) {
$return = array("codice"=>array(),"id"=>array());
$sql = "SELECT * FROM b_form WHERE codice = :id AND attivo = 'S' AND soft_delete = 'N'";
$ris = $this->pdo->go($sql,array(":id"=>$this->codice_form));
if ($ris->rowCount() === 1) {
$form = $ris->fetch(PDO::FETCH_ASSOC);
$sql = "SELECT * FROM b_form_group WHERE codice_form = :codice_form AND codice_gruppo = 0 AND soft_delete = 'N'";
$ris = $this->pdo->go($sql,array(":codice_form"=>$form["codice"]));
if ($ris->rowCount() > 0) {
while($group = $ris->fetch(PDO::FETCH_ASSOC)) {
$tmp = $this->getGroupID($group);
$return["codice"] = array_merge($tmp["codice"],$return["codice"]);
$return["id"] = array_merge($tmp["id"],$return["id"]);
}
}
}
}
return $return;
}
public function getValues($group=false,$duplicate = false) {
$return = false;
if (!empty($this->forcedData)) {
$return = [];
foreach($this->forcedData AS $gruppo_compilazione => $inputs) {
$input = reset($inputs);
if (!empty($group["codice"]) && $input["codice_gruppo"] == $group["codice"]) {
$return[$gruppo_compilazione] = $inputs;
}
}
if (empty($return)) {
$return = false;
}
} else {
if ((!empty($this->element_id) || !empty($this->duplicateID)) && !empty($this->element_type) && !empty($this->codice_form)) {
$bind = array();
$bind[":id"]=(!$duplicate) ? $this->element_id : $this->duplicateID;
$bind[":codice_form"]=$this->codice_form;
$bind[":type"]=$this->element_type;
$sql = "SELECT * FROM b_form_data WHERE codice_form = :codice_form AND id = :id AND type = :type AND soft_delete = 'N' ";
if (!empty($group)) {
$sql .= " AND codice_gruppo = :codice_gruppo ";
$bind[":codice_gruppo"]=$group["codice"];
}
$ris = $this->pdo->go($sql,$bind);
if ($ris->rowCount() > 0) {
$return = array();
while($row = $ris->fetch(PDO::FETCH_ASSOC)) {
if (!isset($return[$row["gruppo_compilazione"]])) { $return[$row["gruppo_compilazione"]] = array(); }
$return[$row["gruppo_compilazione"]][$row["codice_input"]] = array("codice"=>(!$duplicate) ? $row["codice"] : null,"value"=>$row["valore"], "codice_gruppo" => $row["codice_gruppo"]);
}
}
if (empty($return) && !empty($this->duplicateID) && !$duplicate) {
$return = $this->getValues($group,true);
}
}
}
return $return;
}
public function getValuesByID($id) {
$return = false;
if (!empty($id)) {
$ids = $this->getIDS();
if (!empty($ids["id"][$id])) {
$info = $ids["id"][$id];
$data = $this->getValues();
if (!empty($data)) {
if (!empty($info["codice_gruppo"]) && isset($data[$info["codice_gruppo"]][$info["codice"]]["value"])) {
$return = $data[$info["codice_gruppo"]][$info["codice"]]["value"];
} else if (isset($data[$info["codice"]]["value"])){
$return = $data[$info["codice"]]["value"];
}
}
}
}
return $return;
}
private function checkConditional($group) {
$return = NULL;
if (!empty($group["quesito_condizionale"])) {
$return = false;
$conditional = $this->pdo->prepare("SELECT valore FROM b_form_data WHERE codice_form = :codice_form AND codice_gruppo = :codice_gruppo AND gruppo_compilazione = -1 AND id = :id AND type = :type AND soft_delete = 'N'");
$conditional->bindValue(":codice_form",$this->codice_form);
$conditional->bindValue(":codice_gruppo",$group["codice"]);
$conditional->bindValue(":id",$this->element_id);
$conditional->bindValue(":type",$this->element_type);
$conditional->execute();
if ($conditional->rowCount() > 0) {
if ($tmpValore = $conditional->fetch(PDO::FETCH_ASSOC)) {
if (!empty($tmpValore)) {
if ($tmpValore["valore"] == "S") {
$return = true;
}
}
}
}
}
if (!empty($group["codice_gruppo"])) {
$padre = $this->pdo->go("SELECT * FROM b_form_group WHERE codice = :codice",[":codice"=>$group["codice_gruppo"]])->fetch(PDO::FETCH_ASSOC);
if (!empty($padre)) {
$tmp = $this->checkConditional($padre);
if ($tmp !== NULL) {
if ($tmp !== true) { $return = false; }
}
}
}
return $return;
}
public function validateData($values="",$language="") {
$return = array();
if (empty($language)) { $language = $_SESSION["language"]; }
if (empty($values)) {
$values = $this->getValues();
} else {
if (is_array($values)) {
$tmp = array();
foreach($values AS $group) {
foreach($group AS $group_id => $inputs) {
$tmp[$group_id] = $inputs;
}
}
$values = $tmp;
}
}
$inputInfo = $this->getIDS()["codice"] ?? "";
$obbligatori = array();
if (!empty($inputInfo)) {
$groupObb = $this->pdo->prepare("SELECT * FROM b_form_group WHERE codice = :codice AND ((obbligatorio = 'S' AND multi = 'S') OR multi = 'N')");
foreach($inputInfo AS $codice => $input) {
if ($input["obbligatorio"]=="S" && !in_array($input["tipo"],["soa","paragrafo"])) {
$groupObb->bindValue(":codice",$input["codice_gruppo"]);
$groupObb->execute();
if ($groupObb->rowCount() > 0) {
$checkGrp = $groupObb->fetch(PDO::FETCH_ASSOC);
$checkConditional = $this->checkConditional($checkGrp);
if ($checkConditional === NULL) {
$obbligatori[$codice] = false;
} else if ($checkConditional === true) {
$obbligatori[$codice] = false;
}
}
}
}
}
if ((empty($inputInfo) || empty($values)) && count($obbligatori) > 0) {
$return[] = __('errore validazione',$language);
} else {
if (!empty($values)) {
$obbligatori_keys = array_keys($obbligatori);
foreach($values AS $group_id => $inputs) {
foreach($inputs AS $codice => $input) {
$validateInfo = @$inputInfo["#".$codice];
if (!empty($validateInfo)) {
$validateInfo["titolo"] = json_decode($validateInfo["titolo"],true) ?? [];
if ($validateInfo["obbligatorio"] == "S" && in_array("#".$codice,$obbligatori_keys) !== false) {
if ($validateInfo["tipo"] == "address") {
if (!empty($input["value"])) {
$json = json_decode($input["value"]) ?? [];
$obbligatori["#".$codice] = true;
$prior = "";
$prior_value = "";
$continua = true;
foreach($json AS $key => $value) {
if (empty($value)) {
if (!empty($prior)) {
$data = getGeoData($prior,$prior_value,$key);
if (empty($data) && !empty($prior_value)) {
$continua = false;
}
}
if ($continua) {
if (isset($obbligatori["#".$codice])) { unset($obbligatori["#".$codice]); }
$return[] = ((!empty($validateInfo["titolo"][$language]) ? $validateInfo["titolo"][$language] : ($validateInfo["titolo"]["IT"] ?? "")) . " - " . __($key,$language) . " - " . __('obbligatorio',$language) ?? "");
}
}
$prior = $key;
$prior_value = $value;
}
} else {
$return[] = ((!empty($validateInfo["titolo"][$language]) ? $validateInfo["titolo"][$language] : ($validateInfo["titolo"]["IT"] ?? "")) . " " . __('obbligatorio',$language) ?? "");
}
} else if ($validateInfo["tipo"] == "file") {
if (!empty($input["value"])) {
$obbligatori["#".$codice] = true;
} else {
if (!empty($input["file"])) {
$obbligatori["#".$codice] = true;
} else {
$return[] = ((!empty($validateInfo["titolo"][$language]) ? $validateInfo["titolo"][$language] : ($validateInfo["titolo"]["IT"] ?? "")) . " " . __('obbligatorio',$language) ?? "");
}
}
} else if ($validateInfo["tipo"] == "deadline") {
if (strtotime(date2mysql($input["value"])) > time()) {
$obbligatori["#".$codice] = true;
} else {
$return[] = ((!empty($validateInfo["titolo"][$language]) ? $validateInfo["titolo"][$language] : ($validateInfo["titolo"]["IT"] ?? "")) . " " . __('è scaduto',$language) ?? "");
}
} else {
if (!empty($input["value"]) || $input["value"] === "0") {
$obbligatori["#".$codice] = true;
} else {
$return[] = ((!empty($validateInfo["titolo"][$language]) ? $validateInfo["titolo"][$language] : ($validateInfo["titolo"]["IT"] ?? "")) . " " . __('obbligatorio',$language) ?? "");
}
}
}
}
}
}
}
if (count($obbligatori) > 0) {
foreach($obbligatori AS $codice_obbligatorio => $check) {
if (!$check) {
$validateInfo = $inputInfo[$codice_obbligatorio];
$validateInfo["titolo"] = json_decode($validateInfo["titolo"],true) ?? [];
$return[] = (!empty($validateInfo["titolo"][$language]) ? $validateInfo["titolo"][$language] : ($validateInfo["titolo"]["IT"] ?? "") . " " . __('obbligatorio',$language) ?? "");
}
}
}
}
if (count($return) > 0) { $return = array_unique($return); }
return $return;
}
public static function setRequiredChecks($key,$filterID,$required_checks) {
global $pdo;
$codice_gruppo = $pdo->go("SELECT codice_gruppo FROM b_form_input WHERE codice = :codice",[":codice"=>$key])->fetch(PDO::FETCH_COLUMN) ?? null;
if (isset($codice_gruppo)) {
if (!isset($required_checks[$codice_gruppo])) {
$required_checks[$codice_gruppo] = [];
}
if (in_array($filterID,$required_checks[$codice_gruppo]) === false) {
$required_checks[$codice_gruppo][] = $filterID;
}
}
return $required_checks;
}
public static function setResultsForChecks($data,$filterID,$results) {
if (!isset($results[$data["id"]])) {
$results[$data["id"]] = [];
}
if (!isset($results[$data["id"]][$data["codice_gruppo"]])) {
$results[$data["id"]][$data["codice_gruppo"]] = [];
}
if (!isset($results[$data["id"]][$data["codice_gruppo"]][$data["gruppo_compilazione"]])) {
$results[$data["id"]][$data["codice_gruppo"]][$data["gruppo_compilazione"]] = [];
}
if (in_array($filterID,$results[$data["id"]][$data["codice_gruppo"]][$data["gruppo_compilazione"]])=== false) {
$results[$data["id"]][$data["codice_gruppo"]][$data["gruppo_compilazione"]][] = $filterID;
}
return $results;
}
public static function returnElementsFromFilters($inputs,$element_type,$andOperator = false) {
$return = false;
if (!empty($inputs)) {
global $pdo;
$required_checks = [];
$results = [];
$checkInputInForm = $pdo->prepare("SELECT b_form_input.codice FROM b_form_input
JOIN b_form_group ON b_form_input.codice_gruppo = b_form_group.codice
WHERE b_form_group.codice_form = :form AND b_form_input.codice = :key");
$sql = "SELECT b_form_data.id, b_form_data.codice_gruppo, b_form_data.gruppo_compilazione
FROM b_form_data WHERE b_form_data.soft_delete = 'N' AND b_form_data.type = :type AND b_form_data.codice_input = :key ";
$equal = $pdo->prepare($sql ." AND b_form_data.valore LIKE :valore ");
$greater = $pdo->prepare($sql ." AND b_form_data.valore >= :valore_min ");
$lesser = $pdo->prepare($sql ." AND b_form_data.valore <= :valore_max ");
$between = $pdo->prepare($sql ." AND b_form_data.valore <= :valore_max AND b_form_data.valore >= :valore_min ");
$equal->bindValue(":type",$element_type);
$greater->bindValue(":type",$element_type);
$lesser->bindValue(":type",$element_type);
$between->bindValue(":type",$element_type);
$multipleGeo = 0;
foreach($inputs AS $idForm => $groupFilters) {
foreach($groupFilters AS $key => $filters) {
$geoFilter = false;
if (isset($filters["value"])) {
$checkInputInForm->execute([":key"=>$key,":form"=>$idForm]);
if ($checkInputInForm->rowCount() > 0) {
$equal->bindValue(":key",$key);
$greater->bindValue(":key",$key);
$lesser->bindValue(":key",$key);
$between->bindValue(":key",$key);
if (!isset($filters["value"]["min"])) {
if (!empty($filters["value"]["geodata"])) {
$values = [];
$keys = ["stato","regione","provincia","citta","cap"];
$geoFilter = true;
foreach($keys AS $geo) {
if (!empty($filters["value"]["geodata"][$geo])) {
if (!is_array($filters["value"]["geodata"][$geo])) { $filters["value"]["geodata"][$geo] = [$filters["value"]["geodata"][$geo]]; }
$first = true;
foreach($filters["value"]["geodata"][$geo] AS $value) {
if (!empty($value)) {
if (!$first) {
$multipleGeo++;
} else {
$first = false;
}
$value = json_encode(array($value));
$value = str_replace('["',"",$value);
$value = str_replace('"]',"",$value);
$value = str_replace("\\","%",$value);
if ($geo != "citta" && $geo != "cap") {
$values[] = "\"{$geo}\":\"{$value}\"";
} else {
$values[] = "\"{$geo}\":\"%{$value}%\"";
}
}
}
}
}
} else {
$values = (!is_array($filters["value"])) ? [$filters["value"]] : $filters["value"];
}
if (!empty($values)) {
foreach($values AS $value) {
if (!empty($value) || $value === "0") {
$filterID = "equal_{$key}";
if ($andOperator) {
$filterID .= "_{$value}";
}
if ($geoFilter) {
$tag = explode(":",$value);
$tag = $tag["0"];
$tag = str_replace('"',"",$tag);
$filterID .= "_geo_{$tag}";
}
$required_checks = self::setRequiredChecks($key,$filterID,$required_checks);
$value = preg_replace('/[^A-Za-z0-9\-\.\_]/', '%', $value);
$equal->bindValue(":valore","%".$value."%");
$equal->execute();
if ($equal->rowCount() > 0) {
while($tmpId = $equal->fetch(PDO::FETCH_ASSOC)) {
if (!empty($tmpId["id"])) {
$results = self::setResultsForChecks($tmpId,$filterID,$results);
}
}
}
}
}
}
} else if (isset($filters["value"]["min"])) {
$min = $filters["value"]["min"];
$max = $filters["value"]["max"];
if (!empty($min) && !empty($max)) {
$filterID = "between_{$key}";
$required_checks = self::setRequiredChecks($key,$filterID,$required_checks);
$between->bindParam(":valore_min",$min,PDO::PARAM_INT);
$between->bindParam(":valore_max",$max,PDO::PARAM_INT);
$between->execute();
if ($between->rowCount() > 0) {
while($tmpId = $between->fetch(PDO::FETCH_ASSOC)) {
if (!empty($tmpId["id"])) {
$results = self::setResultsForChecks($tmpId,$filterID,$results);
}
}
}
} else if (!empty($max)) {
$filterID = "lesser_{$key}";
$required_checks = self::setRequiredChecks($key,$filterID,$required_checks);
$lesser->bindParam(":valore_max",$max,PDO::PARAM_INT);
$lesser->execute();
if ($lesser->rowCount() > 0) {
while($tmpId = $lesser->fetch(PDO::FETCH_ASSOC)) {
if (!empty($tmpId["id"])) {
$results = self::setResultsForChecks($tmpId,$filterID,$results);
}
}
}
} else if (!empty($min)) {
$filterID = "greater_{$key}";
$required_checks = self::setRequiredChecks($key,$filterID,$required_checks);
$greater->bindParam(":valore_min",$min,PDO::PARAM_INT);
$greater->execute();
if ($greater->rowCount() > 0) {
while($tmpId = $greater->fetch(PDO::FETCH_ASSOC)) {
if (!empty($tmpId["id"])) {
$results = self::setResultsForChecks($tmpId,$filterID,$results);
}
}
}
}
}
}
}
}
}
$return = [];
if (!empty($results)) {
if (!empty($required_checks)) {
foreach($results AS $id => $groups) {
$insert = 0;
foreach($groups AS $group_id => $compilazioni) {
if (!empty($required_checks[$group_id])) {
foreach($compilazioni AS $gruppo_compilazione) {
reset($required_checks[$group_id]);
$countChecks = 0;
foreach($required_checks[$group_id] AS $filterID) {
if (in_array($filterID,$gruppo_compilazione) !== false) {
$countChecks++;
}
}
if ($countChecks === count($required_checks[$group_id])) {
$insert++;
break;
}
}
}
}
if ($insert >= count($required_checks)) {
$return[] = $id;
}
}
} else {
$return = array_keys($results);
}
} else {
if (empty($required_checks)) {
$return = false;
}
}
}
return $return;
}
public function listVersions() {
return $this->pdo->go("SELECT codice, timestamp_modifica FROM b_form_history WHERE codice_form = :form AND type = :type AND id = :id ORDER BY codice DESC",[":form"=>$this->info["codice"],":type"=>$this->element_type,":id"=>$this->element_id])->fetchAll(PDO::FETCH_ASSOC);
}
public function getVersion($codice) {
$return = $this->pdo->go("SELECT * FROM b_form_history WHERE codice_form = :form AND type = :type AND id = :id AND codice = :codice",[":form"=>$this->info["codice"],":codice"=>$codice,":type"=>$this->element_type,":id"=>$this->element_id])->fetch(PDO::FETCH_ASSOC);
if (!empty($return["data"])) {
$return["data"] = json_decode($return["data"],true);
return $return;
}
}
public function saveVersion() {
$data = $this->getValues();
if (!empty($data)) {
$data = json_encode($data);
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = "b_form_history";
$salva->operazione = "INSERT";
$salva->oggetto = ["codice_form"=>$this->info["codice"],"type"=>$this->element_type,"id"=>$this->element_id,"data"=>$data];
$salva->save();
}
}
public function saveData($values) {
$return = true;
if (!empty($values) && !empty($this->element_id) && !empty($this->element_type) && !empty($this->codice_form)) {
$errors = array();
$sql_update = "UPDATE b_form_data SET codice_form = :codice_form, codice_gruppo = :codice_gruppo, codice_input = :codice_input, gruppo_compilazione = :gruppo, id = :id, type = :type, valore = :valore, utente_modifica = :utente_modifica WHERE codice = :codice ";
$sql_insert = "INSERT INTO b_form_data(codice_form, codice_gruppo,codice_input,gruppo_compilazione,id,type,valore,utente_modifica) VALUES (:codice_form, :codice_gruppo, :codice_input, :gruppo, :id, :type, :valore, :utente_modifica) ";
$ris_update = $this->pdo->prepare($sql_update);
$ris_insert = $this->pdo->prepare($sql_insert);
$ris_update->bindValue(":codice_form",$this->codice_form,PDO::PARAM_INT);
$ris_insert->bindValue(":codice_form",$this->codice_form,PDO::PARAM_INT);
$ris_update->bindValue(":id",$this->element_id,PDO::PARAM_INT);
$ris_insert->bindValue(":id",$this->element_id,PDO::PARAM_INT);
$ris_update->bindValue(":type",$this->element_type);
$ris_insert->bindValue(":type",$this->element_type);
$utente = (!empty($_SESSION["utente"]->codice)) ? $_SESSION["utente"]->codice : -1;
$ris_update->bindValue(":utente_modifica",$utente,PDO::PARAM_INT);
$ris_insert->bindValue(":utente_modifica",$utente,PDO::PARAM_INT);
$log_operazione = "";
foreach($values AS $codice_gruppo => $gruppi) {
$ris_update->bindValue(":codice_gruppo",$codice_gruppo,PDO::PARAM_INT);
$ris_insert->bindValue(":codice_gruppo",$codice_gruppo,PDO::PARAM_INT);
foreach($gruppi AS $gruppo_compilazione => $input) {
$error = false;
if (!is_numeric($gruppo_compilazione)) {
$sql = "SELECT MAX(gruppo_compilazione) AS id_gruppo FROM b_form_data";
$ris_gruppo = $this->pdo->go($sql);
if ($ris_gruppo->rowCount() > 0) {
$gruppo_compilazione = (int)$ris_gruppo->fetch(PDO::FETCH_ASSOC)["id_gruppo"] ?? 0;
$gruppo_compilazione++;
} else {
$gruppo_compilazione = 1;
}
}
$ris_update->bindValue(":gruppo",$gruppo_compilazione);
$ris_insert->bindValue(":gruppo",$gruppo_compilazione);
foreach($input AS $codice_input => $valore) {
if (!isset($valore["value"])) { $valore["value"] = ""; }
if (isset($valore["value"]) && is_array($valore["value"])) { $valore["value"] = json_encode($valore["value"]); }
if (!empty($valore["geodata"])) { $valore["value"] = json_encode($valore["geodata"]); }
if (!empty($valore["file"])) {
$file = array();
$file["filename"] = sanitize_string($valore["file"]);
$attachType = "form-". $this->element_type;
if ($this->stripEnte) {
$attachType = str_replace("-{$_SESSION["ente"]->codice}","",$attachType);
}
$file["codice"] = filesManager::saveFile($valore["file"],$this->element_id,$attachType);
if ($file["codice"] != false) {
$valore["value"] = json_encode($file);
}
}
$istruzione_log = "codice_form => " .$this->codice_form;
$istruzione_log .= " id => " .$this->element_id;
$istruzione_log .= " type => " .$this->element_type;
$istruzione_log .= " utente_modifica => " .$utente;
$istruzione_log .= " codice_gruppo => " .$codice_gruppo;
$istruzione_log .= " gruppo => " .$gruppo_compilazione;
$istruzione_log .= " codice_input => " .$codice_input;
$istruzione_log .= " valore => " .$valore["value"];
$valore["value"] = purify($valore["value"]);
$ris_update->bindValue(":codice_input",$codice_input,PDO::PARAM_INT);
$ris_insert->bindValue(":codice_input",$codice_input,PDO::PARAM_INT);
$ris_update->bindValue(":valore",$valore["value"]);
$ris_insert->bindValue(":valore",$valore["value"]);
if (empty($valore["codice"])) {
$ris_insert->execute();
$error = $ris_insert->errorInfo();
$operazione = "INSERT";
$codice = $this->pdo->lastInsertId();
if (!empty($error[1])) { $errors[] = $error; }
} else {
$ris_update->bindValue(":codice",$valore["codice"],PDO::PARAM_INT);
$ris_update->execute();
$codice = $valore["codice"];
$operazione = "UPDATE";
$error = $ris_update->errorInfo();
if (!empty($error[1])) { $errors[] = $error; }
}
$log_operazione .= " ###".$operazione."### ". $istruzione_log;
if (!empty($errors)) { $return = $errors; }
}
}
}
scriviLog("b_form_data","UPDATE",$log_operazione);
}
return $return;
}
public function printGroup($group,$language="",$edit,$bozza,$level=0,$ajax = false) {
$return = false;
if (empty($language)) { $language = $_SESSION["language"]; }
$sql = "SELECT * FROM b_form_group WHERE codice_gruppo = :codice_gruppo AND attivo = 'S' AND soft_delete = 'N' ORDER BY ordinamento ";
$ris = $this->pdo->go($sql,array(":codice_gruppo"=>$group["codice"]));
$sql = "SELECT * FROM b_form_input WHERE codice_gruppo = :codice_gruppo AND attivo = 'S' AND soft_delete = 'N' ORDER BY ordinamento ";
$ris_input = $this->pdo->go($sql,array(":codice_gruppo"=>$group["codice"]));
if ($ris->rowCount() > 0 || $ris_input->rowCount() > 0) {
if ((!empty($this->element_id) || !empty($this->duplicateID)) && !empty($this->element_type)) { $savedData = $this->getValues($group); }
$group["titolo"] = json_decode($group["titolo"],true) ?? [];
$group["titolo"] = (!empty($group["titolo"][$language])) ? $group["titolo"][$language] : ($group["titolo"]["IT"] ?? "");
$group["descrizione"] = json_decode($group["descrizione"],true) ?? [];
$group["descrizione"] = (!empty($group["descrizione"][$language])) ? $group["descrizione"][$language] : ($group["descrizione"]["IT"] ?? "");
if ($level==0) { ?>
<div class="card p-0 col-12 mb-2">
<div class="card-header" role="tab" id="Head-group-<?= $group["codice"] ?>">
<h3 class="card-title mb-0 font-weight-bold" data-target="#group-<?= $group["codice"] ?>">
<?= $group["titolo"] ?>
</h3>
</div>
<div id="group-<?= $group["codice"] ?>" class="card-body" aria-labelledby="Head-group-<?= $group["codice"] ?>">
<?
}
$return = true;
$collapse="";
$conditional = "";
if (!empty($group["quesito_condizionale"]) && $group["multi"] == "N") {
$value = "";
$codice = "";
if (isset($savedData[-1])) {
if (isset($savedData[-1][0]["value"])) { $value = $savedData[-1][0]["value"]; }
if (isset($savedData[-1][0]["codice"])) { $codice = $savedData[-1][0]["codice"]; }
unset($savedData[-1]);
}
$collapse = ($value == "S") ? "" : "collapse";
$conditional = "conditional";
?>
<div class="row mb-1">
<div class="col-12 col-lg-10">
<?= $group["quesito_condizionale"] ?>
</div>
<div class="col-12 col-lg-2">
<? if ($edit) {
$name = "dyn-form-input[".$group["codice_form"]."][". $group["codice"] ."][-1][0]";
?>
<div class="form-group">
<input type="hidden" name="<?= $name ?>[codice]" class="dyn-input" value="<?= $codice ?>">
<select rel="N;0;0;A" class="dyn-input form-control quesito-condizionale" title="<?= $group["quesito_condizionale"] ?>" name="<?= $name ?>[value]" onChange="if ($(this).val() == 'S') { $('#group-content-<?= $group["codice"] ?>').show(); } else { $('#group-content-<?= $group["codice"] ?>').hide(); } checkConditional('#group-content-<?= $group["codice"] ?>'); ">
<option value=""><?= __("Seleziona") ?>...</option>
<option <?= ($value == "S") ? "selected" : "" ?> value="S"><?= __("Si") ?></option>
<option <?= ($value == "N") ? "selected" : "" ?> value="N"><?= __("No") ?></option>
</select>
</div>
<?
} else {
echo ($value == "S") ? __("Si") : __("No");
}
?>
</div>
</div>
<?
}
?>
<div id="group-content-<?= $group["codice"] ?>" class="my-3 <?= $collapse ?> <?= $conditional ?>">
<?
if ($ris->rowCount() > 0) {
$sub_level = $level + 1;
while($sub_group = $ris->fetch(PDO::FETCH_ASSOC)) {
?>
<div id="group-body-<?= $sub_group["codice"] ?>">
<?
$sub_group["titolo"] = json_decode($sub_group["titolo"],true) ?? [];
$sub_group["titolo"] = (!empty($sub_group["titolo"][$language])) ? $sub_group["titolo"][$language] : ($sub_group["titolo"]["IT"] ?? "");
if ($sub_group["multi"] == "N") { ?><span class="d-block h5 font-weight-bold"><?= $sub_group["titolo"] ?></span><? }
$return = $this->printGroup($sub_group,$language,$edit,$bozza,$sub_level);
?>
</div><?
if ($sub_group["multi"]=="S" && $edit) {
?>
<button onclick="aggiungi('/backend/form/add-group.php?language=<?=$language ?>&bozza=<?= ($bozza) ? 1 : 0 ?>&level=<?= $sub_level ?>&token=<?= $this->token ?>&group=<?= base64_encode(json_encode($sub_group)) ?>','#group-body-<?= $sub_group["codice"] ?>'); return false" class="btn btn-lg btn-success btn-block"><span class="fa fa-plus-circle"></span> <?= __("Aggiungi nuovo",$language) ?></button>
<?
}
}
} else {
if ($ris_input->rowCount() > 0) {
$ris_input = $ris_input->fetchAll(PDO::FETCH_ASSOC);
if ($edit) {
if ($group["obbligatorio"]=="S" || $group["multi"] == "N" || $ajax) {
$rows = array("i_".rand()=>"");
}
}
if (!empty($savedData)) { $rows = $savedData; }
if (!empty($rows)) {
$first = true;
foreach($rows AS $group_id => $data) {
// if ($group["multi"]=="S") {
if (empty($group["col"])) { $group["col"] = "12"; }
?>
<div class="card p-0 border col-12 col-lg-<?= $group["col"] ?> <? if ($level > 0) { echo ($group["multi"]=="S") ? "mb-1" : "mb-5"; } ?>" id="group-panel-<?= $group_id ?>">
<div class="card-body">
<? if ($edit) {
if ((!$first || $group["obbligatorio"]=="N" || $ajax) && $group["multi"]=="S") {
$otherInfo = base64_encode(json_encode([
"id" => $this->element_id,
"type" => $this->element_type,
"codice_form" => $this->info["codice"] ?? 0,
"codice_gruppo" => $group["codice"]
]));
?>
<div class="text-right" style="margin-bottom:10px;">
<button class="btn-sm btn-danger" onclick="elimina('<?= $group_id ?>','form/data-group', 'other=<?= $otherInfo ?>'); return false;"><span class="fa fa-times"></span><span class="sr-only"><?= __('Elimina',$language) ?></span></button>
</div>
<? }
}
// }
if ($first) { $first = false; }
?><div class="row"><?
foreach ($ris_input AS $input) {
$input["titolo"] = json_decode($input["titolo"],true) ?? [];
$input["titolo"] = (!empty($input["titolo"][$language])) ? $input["titolo"][$language] : ($input["titolo"]["IT"] ?? "");
$input["descrizione"] = json_decode($input["descrizione"],true) ?? [];
$input["descrizione"] = (!empty($input["descrizione"][$language])) ? $input["descrizione"][$language] : ($input["descrizione"]["IT"] ?? "");
$name = "dyn-form-input[".$group["codice_form"]."][". $group["codice"] ."][".$group_id."][". $input["codice"] . "]";
$value = "";
$codice = "";
if (isset($data[$input["codice"]]["value"])) { $value = $data[$input["codice"]]["value"]; }
if (isset($data[$input["codice"]]["codice"])) { $codice = $data[$input["codice"]]["codice"]; }
if ($input["tipo"]=="address") {
if ($edit) {
include(__DIR__."/template/address.php");
} else {
include(__DIR__."/template/address-view.php");
}
} else if ($input["tipo"]=="city") {
if ($edit) {
include(__DIR__."/template/city.php");
} else {
include(__DIR__."/template/city-view.php");
}
} else if ($input["tipo"]=="soa") {
include(__DIR__."/template/soa.php");
} else {
if (empty($input["col"])) { $input["col"] = "12"; }
?>
<div class="col-12 col-lg-<?= $input["col"] ?>">
<label <?= (!$edit) ? 'class="value-label"' : "" ?> for="<?= $name ?>"><?= $input["titolo"] ?> <? if ($input["obbligatorio"]=="S") echo "*" ?></label>
<?
if ($bozza) { $input["obbligatorio"] = "N"; }
if (!$edit) {
?><span class="value-container"><?
switch ($input["tipo"]) {
case "file":
if (!empty($value)) {
$tmp = json_decode($value,true) ?? [];
$attachType = "form-". $this->element_type;
if ($this->stripEnte) {
$attachType = str_replace("-{$_SESSION["ente"]->codice}","",$attachType);
}
$file = filesManager::fileInfo($tmp["codice"],$tmp["filename"],$this->element_id,$attachType);
if (!empty($file)) {
$general_connection = false;
if (!empty(filesManager::availableTypes()[$attachType]["generalFolder"])) {
$general_connection = true;
}
$fileHref = filesManager::getAttachURL($file,$this->element_id,$attachType,$general_connection);;
?>
<a target="_blank" href="<?= $fileHref ?>">
<span class="fa fa-download"></span>
<?= $tmp["filename"] ?>
</a> - <?= human_filesize($file["size"]) ?>
<?
$input["obbligatorio"] = "N";
}
}
break;
case "select_json":
$sources = json_decode($input["opzioni"]) ?? [];
$options = array();
foreach($sources AS $source) {
$source = sanitize_string($source,[],"-",false);
if (file_exists(__DIR__."/json/".$source)) {
$tmp = json_decode(file_get_contents(__DIR__."/json/".$source),true) ?? [];
foreach ($tmp AS $op_value => $op_label) {
$options[$op_value] = (!empty($op_label[$language])) ? $op_label[$language] : ($op_label["IT"] ?? "");
$options[$op_value] = (!empty($options[$op_value])) ? $options[$op_value] : $op_label;
}
}
}
if (!empty($options[$value])) { echo $options[$value]; }
break;
case "valuta":
if (is_numeric($value)) {
echo number_format($value,2,",",".");
}
break;
case "paragrafo":
echo $input["descrizione"];
break;
default:
echo $value;
break;
}
?></span><?
} else { ?><div class="form-group"><input type="hidden" name="<?= $name ?>[codice]" class="dyn-input" value="<?= $codice ?>">
<?
$nameAppend = "";
switch ($input["tipo"]) {
case "paragrafo":
echo $input["descrizione"];
break;
case "blob":
?>
<textarea rows="5" rel="<?= $input["obbligatorio"] ?>;0;0;A" class="dyn-input <?= (empty($group["quesito_condizionale"])) ? "ckeditor_simple" : "ckeditor_condizionale" ?> form-control" title="<?= $input["titolo"] ?>" name="<?= $name ?>[value]"><?= $value ?></textarea>
<?
break;
case "multiple":
$nameAppend = "[]";
$value = json_decode(only_simple_chars(html_entity_decode($value)),true) ?? [];
case "select":
$options = json_decode($input["opzioni"]) ?? [];
if (!is_array($value)) { $value = [only_simple_chars(html_entity_decode($value))]; }
?>
<select rel="<?= $input["obbligatorio"] ?>;0;0;A" <?= !empty($nameAppend) ? "multiple" : "" ?> class="dyn-input form-control" title="<?= $input["titolo"] ?>" name="<?= $name ?>[value]<?= $nameAppend ?>">
<? if ($input["tipo"] != "multiple") { ?><option value="">Seleziona...</option><? } ?>
<?
foreach($options AS $option) {
$selected = "";
if (in_array(only_simple_chars(html_entity_decode($option)),$value) !== false) { $selected = "selected"; }
?><option <?= $selected ?>><?= $option ?></option><?
}
?>
</select>
<?
break;
case "multiple_json":
$nameAppend = "[]";
$value = json_decode(only_simple_chars($value),true) ?? [];
case "select_json":
$sources = json_decode($input["opzioni"]) ?? [];
$options = array();
foreach($sources AS $source) {
$source = sanitize_string($source,[],"-",false);
if (file_exists(__DIR__."/json/".$source)) {
$tmp = json_decode(file_get_contents(__DIR__."/json/".$source),true) ?? [];
foreach ($tmp AS $op_value => $op_label) {
$options[$op_value] = (!empty($op_label[$language])) ? $op_label[$language] : ($op_label["IT"] ?? "");
$options[$op_value] = (!empty($options[$op_value])) ? $options[$op_value] : $op_label;
}
}
}
if (!is_array($value)) { $value = [only_simple_chars(html_entity_decode($value))]; }
?>
<select rel="<?= $input["obbligatorio"] ?>;0;0;A" <?= !empty($nameAppend) ? "multiple" : "" ?> class="dyn-input form-control" title="<?= $input["titolo"] ?>" name="<?= $name ?>[value]<?= $nameAppend ?>">
<? if ($input["tipo"] != "multiple_json") { ?><option value="">Seleziona...</option><? } ?>
<?
foreach($options AS $op_value => $option) {
$selected = "";
if (in_array(only_simple_chars(html_entity_decode($op_value)),$value) !== false) { $selected = "selected"; }
?><option value="<?= $op_value ?>" <?= $selected ?>><?= $option ?></option><?
}
?>
</select>
<?
break;
case "file":
if (!empty($value)) {
$tmp = json_decode($value,true) ?? [];
$attachType = "form-". $this->element_type;
if ($this->stripEnte) {
$attachType = str_replace("-{$_SESSION["ente"]->codice}","",$attachType);
}
$file = filesManager::fileInfo($tmp["codice"],$tmp["filename"],$this->element_id,$attachType);
if (!empty($file)) {
$general_connection = false;
if (!empty(filesManager::availableTypes()[$attachType]["generalFolder"])) {
$general_connection = true;
}
$fileHref = filesManager::getAttachURL($file,$this->element_id,$attachType,$general_connection);;
?>
<div class="p-3 mb-3">
<input type="hidden" id="old-<?= $group_id ?>-<?= $input["codice"] ?>" class="dyn-input" name="<?= $name ?>[value]" value="<?= htmlentities($value) ?>">
<span id="old-label-<?= $group_id ?>-<?= $input["codice"] ?>">
<a target="_blank" href="<?= $fileHref ?>">
<span class="fa fa-download fa-2x" style="vertical-align:middle"></span>
&nbsp;<?= $tmp["filename"] ?>
</a> - <?= human_filesize($file["size"]) ?>
</span>
<button class="float-right btn btn-sm btn-danger" onclick='$("#old-<?= $group_id ?>-<?= $input["codice"] ?>").val("");$("#old-label-<?= $group_id ?>-<?= $input["codice"] ?>").remove(); <? if ($input["obbligatorio"] == "S") { ?>$("#file-<?= $group_id ?>-<?= $input["codice"] ?>").attr("rel","S;1;0;A");<?}?>return false;'><span class="fa fa-times"></span><span class="sr-only"><?= __('Elimina',$language) ?></span></button>
<div class="clearfix"></div>
</div>
<?
$input["obbligatorio"] = "N";
}
}
if (empty($this->preview)) {
filesManager::insertUploadForm('$("#file-'.$group_id.'-'.$input["codice"].'").val(file.name);',null,["maxNumberOfFiles"=>1]);
?>
<input type="hidden" rel="<?= $input["obbligatorio"] ?>;1;0;A" class="dyn-input" title="<?= $input["titolo"] ?>" name="<?= $name ?>[file]" value="" id="file-<?= $group_id ?>-<?= $input["codice"] ?>">
<?
}
break;
default:
$type = "A";
if (in_array($input["tipo"], array("number","valuta"))!==false) { $type = "N"; }
if ($input["tipo"]=="link") { $type = "L"; }
if ($input["tipo"]=="date" || $input["tipo"]=="deadline") { $type = "D"; }
if (!empty($input["tipoRel"])) { $type = $input["tipoRel"]; }
?>
<input type="hidden" id="today<?= $input["codice"] ?>" value="<?= date('d/m/Y') ?>">
<input type="text" rel="<?= $input["obbligatorio"] ?>;0;0;<?= $type ?><?= ($input["tipo"] == "deadline") ? ";today{$input["codice"]};>" : "" ?>" class="dyn-input form-control <?= ($input["tipo"]=="date" || $input["tipo"]=="deadline") ? "datepick" : "" ?>" title="<?= $input["titolo"] ?>" name="<?= $name ?>[value]" value="<?= $value ?>">
<?
break;
}
?>
</div>
<?
}
?>
<? if ($input["tipo"] == "deadline" && !empty($value) && strtotime(date2mysql($value)) < time()) { ?>
<div class="text-center alert alert-danger p-1"><small><span class="fa fa-exclamation-triangle"></span> <?= __("Scaduto") ?></small></div>
<? } ?>
</div>
<?
}
}
?>
</div>
<?
// if ($group["multi"]=="S") {
?>
</div>
</div>
<?
// }
}
}
}
}
?>
</div>
<?
if ($level==0) { ?>
</div></div>
<?
}
}
return $return;
}
public function printForm($edit=true,$bozza=false,$language = "") {
$return = false;
if (!empty($this->codice_form)) {
if (empty($language)) { $language = $_SESSION["language"]; }
$sql = "SELECT * FROM b_form WHERE codice = :codice AND attivo = 'S' AND soft_delete = 'N' ";
$ris = $this->pdo->go($sql,array(":codice"=>$this->codice_form));
if ($ris->rowCount() === 1) {
$form = $ris->fetch(PDO::FETCH_ASSOC);
$sql = "SELECT * FROM b_form_group WHERE codice_form = :codice_form AND codice_gruppo = 0 AND soft_delete = 'N' ORDER BY ordinamento ASC";
$ris = $this->pdo->go($sql,array(":codice_form"=>$form["codice"]));
if ($ris->rowCount() > 0) {
while($group = $ris->fetch(PDO::FETCH_ASSOC)) {
if ($this->printGroup($group,$language,$edit,$bozza) !== false) { $return = true; }
}
}
if ($return) {
?>
<script>
if (typeof checkConditional != "function") {
function checkConditional(groupId) {
if ($(groupId).length > 0) {
$(groupId).each(function() {
div = $(this);
inputs = div.find(":input");
if (div.is(":visible")) {
$(groupId).show();
if ($(".ckeditor_condizionale",groupId).length && !$(".cke",groupId).length) {
var editor = $(".ckeditor_condizionale",groupId);
Editor.create(editor, {
placeholder: 'Inserisci il testo',
removePlugins: [
"Autoformat", "BlockQuote", "CloudServices", "Link", "Image", "Heading", "ImageCaption", "ImageStyle", "ImageToolbar", "MediaEmbed", "PasteFromOffice", "Table", "TableToolbar", "TextTransformation", "AutoLink", "FontColor", "FontBackgroundColor", "FindAndReplace", "FontSize", "Highlight", "HorizontalLine", "IndentBlock", "ListProperties", "RemoveFormat", "TableCaption", "TableCellProperties", "TableColumnResize", "TableProperties", "WordCount", "Title"
],
toolbar: {
items: [
'undo', 'redo', 'link'
],
shouldNotGroupWhenFull: true
}
});
}
inputs.each(function() {
trueRel = $(this).attr('true-rel');
if (typeof trueRel !== typeof undefined && trueRel !== false) {
$(this).attr('rel',trueRel);
}
});
} else {
inputs.each(function() {
trueRel = $(this).attr('rel');
if (typeof trueRel !== typeof undefined && trueRel !== false) {
$(this).attr('true-rel',trueRel);
$(this).attr('rel',"N;0;0;A");
}
});
}
})
}
}
}
checkConditional(".conditional");
$(function () {
$('.quesito-condizionale').each(function (index, element) {
$(element).trigger('change').trigger('chosen:updated');
});
});
</script>
<?
}
}
}
return $return;
}
public function printFilters($language = "") {
$return = false;
if (!empty($this->codice_form)) {
if (empty($language)) { $language = $_SESSION["language"]; }
$sql = "SELECT * FROM b_form WHERE codice = :codice AND attivo = 'S' AND soft_delete = 'N' ";
$ris = $this->pdo->go($sql,array(":codice"=>$this->codice_form));
if ($ris->rowCount() === 1) {
$form = $ris->fetch(PDO::FETCH_ASSOC);
$sql = "SELECT * FROM b_form_group WHERE codice_form = :codice_form AND codice_gruppo = 0 AND soft_delete = 'N' ORDER BY ordinamento ASC";
$ris = $this->pdo->go($sql,array(":codice_form"=>$form["codice"]));
if ($ris->rowCount() > 0) {
while($group = $ris->fetch(PDO::FETCH_ASSOC)) {
if ($this->printGroupFilter($group,$language) !== false) { $return = true; }
}
}
}
}
return $return;
}
public function printGroupFilter($group,$language="") {
$return = false;
if (empty($language)) { $language = $_SESSION["language"]; }
$sql = "SELECT * FROM b_form_group WHERE codice_gruppo = :codice_gruppo AND attivo = 'S' AND soft_delete = 'N' ORDER BY ordinamento ";
$ris = $this->pdo->go($sql,array(":codice_gruppo"=>$group["codice"]));
$sql = "SELECT * FROM b_form_input WHERE codice_gruppo = :codice_gruppo AND filtra = 'S' AND attivo = 'S' AND soft_delete = 'N' ORDER BY ordinamento ";
$ris_input = $this->pdo->go($sql,array(":codice_gruppo"=>$group["codice"]));
if ($ris->rowCount() > 0 || $ris_input->rowCount() > 0) {
$group["titolo"] = json_decode($group["titolo"],true) ?? [];
$group["titolo"] = (!empty($group["titolo"][$language])) ? $group["titolo"][$language] : ($group["titolo"]["IT"] ?? "");
$group["descrizione"] = json_decode($group["descrizione"],true) ?? [];
$group["descrizione"] = (!empty($group["descrizione"][$language])) ? $group["descrizione"][$language] : ($group["descrizione"]["IT"] ?? "");
$return = true;
if ($ris->rowCount() > 0) {
while($sub_group = $ris->fetch(PDO::FETCH_ASSOC)) {
?>
<div id="group-body-<?= $sub_group["codice"] ?>">
<?
$return = $this->printGroupFilter($sub_group,$language);
?>
</div><?
}
} else {
if ($ris_input->rowCount() > 0) {
$ris_input = $ris_input->fetchAll(PDO::FETCH_ASSOC);
if (empty($group["col"])) { $group["col"] = "12"; }
?>
<div class="card p-0 mb-3">
<div class="card-header">
<h3 class="card-title" style="font-size:1em" data-target="#filterInputs<?= $group["codice"] ?>"><?= $group["titolo"] ?></h3>
</div>
<div class="card-body collapse" id="filterInputs<?= $group["codice"] ?>">
<div class="row">
<?
foreach ($ris_input AS $input) {
$input["titolo"] = json_decode($input["titolo"],true) ?? [];
$input["titolo"] = (!empty($input["titolo"][$language])) ? $input["titolo"][$language] : ($input["titolo"]["IT"] ?? "");
$input["descrizione"] = json_decode($input["descrizione"],true) ?? [];
$input["descrizione"] = (!empty($input["descrizione"][$language])) ? $input["descrizione"][$language] : ($input["descrizione"]["IT"] ?? "");
$name = "dyn-form-input[".$group["codice_form"]."][". $input["codice"] . "]";
if ($input["tipo"]=="address") {
include(__DIR__."/template/address-search.php");
} else if ($input["tipo"]=="city") {
include(__DIR__."/template/city-search.php");
} else {
if (empty($input["col"])) { $input["col"] = "12"; }
?>
<div class="col-12 col-lg-<?= $input["col"] ?>">
<div class="form-group">
<label for="<?= $name ?>"><?= $input["titolo"] ?> </label>
<?
switch ($input["tipo"]) {
case "paragrafo":
echo $input["descrizione"];
break;
case "multiple_json":
case "select_json":
$sources = json_decode($input["opzioni"]) ?? [];
$options = array();
foreach($sources AS $source) {
$source = sanitize_string($source,[],"-",false);
if (file_exists(__DIR__."/json/".$source)) {
$tmp = json_decode(file_get_contents(__DIR__."/json/".$source),true) ?? [];
foreach ($tmp AS $op_value => $op_label) {
$options[$op_value] = (!empty($op_label[$language])) ? $op_label[$language] : ($op_label["IT"] ?? "");
$options[$op_value] = (!empty($options[$op_value])) ? $options[$op_value] : $op_label;
}
}
}
?>
<select rel="N;0;0;A" class="dyn-input form-control" multiple title="<?= $input["titolo"] ?>" data-codice="<?= $input["codice"] ?>" name="<?= $name ?>[value][]">
<?
foreach($options AS $op_value => $option) {
$selected = "";
?><option value="<?= $op_value ?>" <?= $selected ?>><?= $option ?></option><?
}
?>
</select>
<?
break;
case "multiple":
case "select":
$options = json_decode($input["opzioni"]) ?? [];
?>
<select rel="N;0;0;A" class="dyn-input form-control" multiple title="<?= $input["titolo"] ?>" data-codice="<?= $input["codice"] ?>" name="<?= $name ?>[value][]">
<?
foreach($options AS $option) {
$selected = "";
?><option <?= $selected ?>><?= $option ?></option><?
}
?>
</select>
<?
break;
default:
$type = "A";
if (in_array($input["tipo"], array("number","valuta"))!==false) {
$rel = "N;0;0;N";
$class= "";
/* if ($input["tipo"] == "date") {
$rel= "N;0;0;D";
$class= "datepick";
} */
?>
<div class="form-group">
<small><strong>Min</strong></small>
<input type="text" rel="<?= $rel ?>" class="dyn-input <?= $class ?> form-control" title="<?= $input["titolo"] ?> - Min" data-codice="<?= $input["codice"] ?>-min" name="<?= $name ?>[value][min]" >
</div>
<div class="form-group">
<small><strong>Max</strong></small>
<input type="text" rel="<?= $rel ?>" class="dyn-input <?= $class ?> form-control" title="<?= $input["titolo"] ?> - Max" data-codice="<?= $input["codice"] ?>-max" name="<?= $name ?>[value][max]" >
</div>
<?
} else {
?>
<input type="text" rel="N;0;0;A" class="dyn-input form-control" title="<?= $input["titolo"] ?>" name="<?= $name ?>[value]" data-codice="<?= $input["codice"] ?>">
<?
}
break;
}
?>
</div>
</div>
<?
}
}
?>
</div>
</div>
</div>
<?
}
}
}
return $return;
}
public static function existValues($array) {
if (!empty($array)) {
foreach($array AS $key => $value) {
if ($key === "value") {
if (!empty($value) || $value === "0") {
return true;
}
} else {
if (is_array($value)) {
$return = static::existValues($value);
if ($return) {
return true;
}
}
}
}
}
return false;
}
}
?>