Print report content as HTML

This commit is contained in:
coolneng 2020-07-15 22:08:40 +02:00
parent 393a508136
commit 1993b0d27e
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
6 changed files with 83 additions and 13 deletions

View File

@ -319,7 +319,9 @@ function fetchPatients($pdo)
function fetchReportData($pdo, string $id) function fetchReportData($pdo, string $id)
{ {
$query = "SELECT * FROM informe WHERE id=?"; $query = "SELECT informe.id, titulo, fecha, hora, paciente , contenido, usuario FROM informe
INNER JOIN usuario ON informe.medico = usuario.id
WHERE informe.id=?";
$result = $pdo->prepare($query); $result = $pdo->prepare($query);
$result->execute([$id]); $result->execute([$id]);
$data = $result->fetch(); $data = $result->fetch();

15
src/print_html.js Normal file
View File

@ -0,0 +1,15 @@
function printExternal(url) {
var printWindow = window.open(url, 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');
printWindow.addEventListener('load', function() {
if (Boolean(printWindow.chrome)) {
printWindow.print();
setTimeout(function(){
printWindow.close();
}, 500);
} else {
printWindow.print();
printWindow.close();
}
}, true);
}

View File

@ -7,6 +7,7 @@
<meta name="description" content=""> <meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/style.css" type="text/css" media="screen" /> <link rel="stylesheet" href="static/style.css" type="text/css" media="screen" />
<script src="print_html.js"></script>
</head> </head>
<body> <body>
<?php include 'navbar.php'; ?> <?php include 'navbar.php'; ?>
@ -25,14 +26,13 @@
<th>Hora</th> <th>Hora</th>
<th>Paciente</th> <th>Paciente</th>
<th>Médico</th> <th>Médico</th>
<th colspan="2">Acciones</th> <th colspan="3">Acciones</th>
</tr> </tr>
</thead> </thead>
<?php <?php
include 'database.php'; include 'database.php';
$pdo = connectDatabase(); $pdo = connectDatabase();
$list = listReports($pdo); $list = listReports($pdo);
foreach ($list as $row) : foreach ($list as $row) :
@ -49,6 +49,12 @@
<td> <td>
<a href="report_management.php?delete=<?php echo $row[0]; ?>" class="del_btn">Borrar</a> <a href="report_management.php?delete=<?php echo $row[0]; ?>" class="del_btn">Borrar</a>
</td> </td>
<td>
<input type="button" value="HTML" class="create_btn" onClick="printExternal('report_content.php?id=<?php echo $row[0]; ?>')">
</td>
<td>
<a href="report_management.php?print_pdf=<?php echo $row[0]; ?>" class="create_btn">PDF</a>
</td>
</tr> </tr>
<?php endforeach ?> <?php endforeach ?>
<?php closeDatabase($pdo); ?> <?php closeDatabase($pdo); ?>

38
src/report_content.php Normal file
View File

@ -0,0 +1,38 @@
<html class="no-js" lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Gestión de informes</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/style.css" type="text/css" media="screen" />
</head>
<body>
<table>
<thead>
<tr>
<th>Titulo</th>
<th>Fecha</th>
<th>Hora</th>
<th>Paciente</th>
<th>Contenido</th>
<th>Médico</th>
</tr>
</thead>
<?php
include 'database.php';
$pdo = connectDatabase();
$data = fetchReportData($pdo, $_GET["id"]);
?>
<tr>
<td><?php echo $data[1]; ?></td>
<td><?php echo $data[2]; ?></td>
<td><?php echo $data[3]; ?></td>
<td><?php echo $data[4]; ?></td>
<td><?php echo $data[5]; ?></td>
<td><?php echo $data[6]; ?></td>
</tr>
<?php closeDatabase($pdo); ?>
</table>
</body>

View File

@ -14,8 +14,8 @@
include 'database.php'; include 'database.php';
$pdo = connectDatabase(); $pdo = connectDatabase();
$doctors = listDoctors($pdo);
$patients = fetchPatients($pdo); $patients = fetchPatients($pdo);
$user = finduser($pdo, $_SESSION["user"]);
?> ?>
<form name="create_form" method="post" action="report_management.php" onsubmit="return validateReport();"> <form name="create_form" method="post" action="report_management.php" onsubmit="return validateReport();">
<div class="input-group"> <div class="input-group">
@ -38,14 +38,6 @@
<?php endforeach ?> <?php endforeach ?>
</select> </select>
</div> </div>
<div class="input-group">
<select id="medico" name="medico">
<option>Seleccione un médico</option>
<?php foreach ($doctors as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>
</div>
<div class="input-group"> <div class="input-group">
<label>contenido</label> <label>contenido</label>
<input type="text" name="contenido" value=""> <input type="text" name="contenido" value="">
@ -53,7 +45,7 @@
<div class="input-group"> <div class="input-group">
<button class="btn" type="submit" name="create" >Guardar</button> <button class="btn" type="submit" name="create" >Guardar</button>
</div> </div>
<input type="button" value="Imprimir" onClick="window.print()"> <input type="hidden" id="medico" name="medico" value="<?php echo $user[0][4]; ?>">
</form> </form>
<?php closeDatabase($pdo); ?> <?php closeDatabase($pdo); ?>
</body> </body>

View File

@ -1,6 +1,7 @@
<?php <?php
include'database.php'; include'database.php';
function reportCreation() function reportCreation()
{ {
$data = $_POST; $data = $_POST;
@ -10,6 +11,7 @@ function reportCreation()
header('location: report.php'); header('location: report.php');
} }
function reportModification() function reportModification()
{ {
$data = $_POST; $data = $_POST;
@ -20,6 +22,7 @@ function reportModification()
header('location: report.php'); header('location: report.php');
} }
function reportDeletion() function reportDeletion()
{ {
$id = $_GET["delete"]; $id = $_GET["delete"];
@ -29,6 +32,14 @@ function reportDeletion()
header('location: report.php'); header('location: report.php');
} }
function printPDF()
{
$id = $_GET["print_pdf"];
header('location: report.php');
}
if (isset($_POST["create"])) { if (isset($_POST["create"])) {
reportCreation(); reportCreation();
} }
@ -38,6 +49,12 @@ if (isset($_POST["edit"])) {
reportModification(); reportModification();
} }
if (isset($_GET["delete"])) { if (isset($_GET["delete"])) {
reportDeletion(); reportDeletion();
} }
if (isset($_GET["print_pdf"])) {
printPDF();
}