$configPath = substr(__DIR__,0,strpos(__DIR__,"/public_html"))."/config.php"; include_once($configPath); if (! empty($_SESSION["utente"]) && $_SESSION["utente"]->permission($radice)) { $return = []; $return["draw"] = (int) $_POST["draw"]; $return["recordsTotal"] = (int) 0; $return["recordsFiltered"] = (int) 0; if (isset($_POST["draw"])) { $limit = ""; if(isset($_POST["start"]) && isset($_POST["length"]) && (int) $_POST["length"] > 0) { $start = (int) $_POST["start"]; $end = (int) $_POST["length"]; $limit = "LIMIT {$start}, {$end}"; } $select = "SELECT * "; $count = "SELECT COUNT(codice)"; $from = "FROM b_categorie_documentali"; $where = ["soft_delete = 'N'"]; $bind = []; if(! empty($_SESSION["ente"])) { $where[] = "(codice_ente IS NULL OR codice_ente = :codice_ente)"; $bind[":codice_ente"] = $_SESSION["ente"]->codice; } else { $where[] = "(codice_ente IS NULL)"; } $total = $pdo->go("{$count} {$from} WHERE {$where[0]}", $bind)->fetch(PDO::FETCH_COLUMN, 0); if($total > 0) { $return["recordsTotal"] = (int) $total; $return["recordsFiltered"] = (int) $total; $moduli = array_filter($config["moduli"], function(&$settings) { return $settings["completed"] == "S" && ! $settings["nascosto"]; }); $moduli = array_column($config["moduli"], "titolo", 'id'); $order = ["column" => "codice", "dir" => $_POST["order"][0]["dir"] ?? "DESC"]; switch($_POST["order"][0]["column"]) { case "0": $order["column"] = "codice"; break; case "2": $order["column"] = "modulo"; break; case "3": $order["column"] = "titolo"; break; } if(! empty($_POST["titolo"])) { $where = ["titolo LIKE :titolo"]; $bind[":titolo"] = "%{$_POST["titolo"]}%"; } if(! empty($_POST["modulo"])) { $where = ["modulo = :modulo"]; $bind[":modulo"] = $_POST["modulo"]; } $where = "WHERE " . implode(" AND ", $where); $result = $pdo->go("{$select} {$from} {$where} ORDER BY {$order["column"]} {$order["dir"]} {$limit}", $bind); $check = $pdo->prepare("SELECT codice FROM b_categorie_documentali_escluse WHERE codice_categoria = :codice_categoria AND codice_ente = :codice_ente"); $check->bindValue(":codice_ente", $_SESSION["ente"]->codice); while ($record = $result->fetch(PDO::FETCH_ASSOC)) { $row = []; $row[] = $record["codice"]; $row[] = $moduli[$record["modulo"]] ?? "Tutti i moduli"; $row[] = $record["titolo"]; ob_start(); ?>