permission("log-viewer")) { $bind = array(); $sql = "SELECT b_log.*, b_utenti.cognome, b_utenti.nome "; if (empty($_SESSION["ente"])) { $sql .= ",b_enti.denominazione "; } $sql.= "FROM b_log LEFT JOIN b_utenti ON b_log.codoperatore = b_utenti.codice "; if (empty($_SESSION["ente"])) { $sql .= "LEFT JOIN b_enti ON b_log.codice_ente = b_enti.codice "; } $where = ""; if (!empty($_SESSION["log-filter"])) { if (isset($_SESSION["log-filter"]["nometab"]) && $_SESSION["log-filter"]["nometab"] !== "") { $bind[":nometab"] = $_SESSION["log-filter"]["nometab"]; $where .= (empty($where)) ? "WHERE " : "AND "; $where .= "b_log.nometab = :nometab "; } if (!empty($_SESSION["log-filter"]["operazione"])) { $bind[":operazione"] = $_SESSION["log-filter"]["operazione"]; $where .= (empty($where)) ? "WHERE " : "AND "; $where .= "b_log.operazione = :operazione "; } if (!empty($_SESSION["log-filter"]["id_record"])) { $bind[":id_record"] = $_SESSION["log-filter"]["id_record"]; $where .= (empty($where)) ? "WHERE " : "AND "; $where .= "b_log.id_record = :id_record "; } if (!empty($_SESSION["log-filter"]["ip"])) { $sud = suddivisione_pdo($_SESSION["log-filter"]["ip"],"ip"); $bind = array_merge($bind,$sud["bind"]); $where .= (empty($where)) ? "WHERE " : "AND "; $where .= $sud["sql"]; } if (!empty($_SESSION["log-filter"]["user"])) { $where .= (empty($where)) ? "WHERE (" : "AND ("; $sud = suddivisione_pdo($_SESSION["log-filter"]["user"],"b_utenti.cognome"); $bind = array_merge($bind,$sud["bind"]); $where .= $sud["sql"] . "OR "; $sud = suddivisione_pdo($_SESSION["log-filter"]["user"],"b_utenti.nome"); $bind = array_merge($bind,$sud["bind"]); $where .= $sud["sql"] . ")"; } if (isset($_SESSION["log-filter"]["codice_ente"]) && $_SESSION["log-filter"]["codice_ente"] !== "") { $bind[":codice_ente"] = $_SESSION["log-filter"]["codice_ente"]; $where .= (empty($where)) ? "WHERE " : "AND "; $where .= "b_log.codice_ente = :codice_ente "; } if (!empty($_SESSION["log-filter"]["from"])) { $bind[":dataop_from"] = datetime2mysql($_SESSION["log-filter"]["from"]); $where .= (empty($where)) ? "WHERE " : "AND "; $where .= "b_log.dataop >= :dataop_from "; } if (!empty($_SESSION["log-filter"]["to"])) { $bind[":dataop_to"] = datetime2mysql($_SESSION["log-filter"]["to"]); $where .= (empty($where)) ? "WHERE " : "AND "; $where .= "b_log.dataop <= :dataop_to "; } } $sql .= $where; if (!empty($_SESSION["ente"])) { $bind[":codice_ente"] = $_SESSION["ente"]->codice; $sql .= (empty($where)) ? "WHERE " : "AND "; $sql .= " b_log.codice_ente = :codice_ente "; } $sql .= "ORDER BY b_log.dataop DESC "; $ris = $pdo->go($sql,$bind); if ($ris->rowCount() > 0) { $return = array(); $row = array(); $row[] = "ID"; $row[] = "TAB"; $row[] = "OPERATION"; $row[] = "ROW"; $row[] = "IP"; $row[] = "USER"; if (empty($_SESSION["ente"])) { $row[] = strtoupper(__("ente")); } $row[] = "TIMESTAMP"; $row[] = "ISTRUZIONE"; $return[] = $row; while($record = $ris->fetch(PDO::FETCH_ASSOC)) { $row = array(); $row[] = $record["codice"]; $row[] = $record["nometab"]; $row[] = $record["operazione"]; $row[] = $record["id_record"]; $row[] = $record["ip"]; $row[] = $record["cognome"] . " " . $record["nome"]; if (empty($_SESSION["ente"])) { $row[] = (empty($record["denominazione"])) ? "" : $record["denominazione"]; } $row[] = mysql2datetime($record["dataop"]); $record["istruzione"] = base64_decode(@gzuncompress($record["istruzione"])); $row[] = $record["istruzione"]; $return[] = $row; } header("Content-Type:application/csv"); header("Content-Disposition:attachment;filename=log.csv"); foreach ($return as $row) { echo arrayToCsv($row)."\n"; } } } ?>