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) { ?>