diff --git a/src/database.php b/src/database.php index b77caad..7a25403 100644 --- a/src/database.php +++ b/src/database.php @@ -319,7 +319,9 @@ function fetchPatients($pdo) 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->execute([$id]); $data = $result->fetch(); diff --git a/src/print_html.js b/src/print_html.js new file mode 100644 index 0000000..4fe8ac7 --- /dev/null +++ b/src/print_html.js @@ -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); +} diff --git a/src/report.php b/src/report.php index 321c95e..505b05f 100644 --- a/src/report.php +++ b/src/report.php @@ -7,6 +7,7 @@ <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" /> + <script src="print_html.js"></script> </head> <body> <?php include 'navbar.php'; ?> @@ -25,14 +26,13 @@ <th>Hora</th> <th>Paciente</th> <th>Médico</th> - <th colspan="2">Acciones</th> + <th colspan="3">Acciones</th> </tr> </thead> <?php include 'database.php'; $pdo = connectDatabase(); - $list = listReports($pdo); foreach ($list as $row) : @@ -49,6 +49,12 @@ <td> <a href="report_management.php?delete=<?php echo $row[0]; ?>" class="del_btn">Borrar</a> </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> <?php endforeach ?> <?php closeDatabase($pdo); ?> diff --git a/src/report_content.php b/src/report_content.php new file mode 100644 index 0000000..0f6dc77 --- /dev/null +++ b/src/report_content.php @@ -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> diff --git a/src/report_create_form.php b/src/report_create_form.php index dd94622..0ebd7c2 100644 --- a/src/report_create_form.php +++ b/src/report_create_form.php @@ -14,8 +14,8 @@ include 'database.php'; $pdo = connectDatabase(); - $doctors = listDoctors($pdo); $patients = fetchPatients($pdo); + $user = finduser($pdo, $_SESSION["user"]); ?> <form name="create_form" method="post" action="report_management.php" onsubmit="return validateReport();"> <div class="input-group"> @@ -38,14 +38,6 @@ <?php endforeach ?> </select> </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"> <label>contenido</label> <input type="text" name="contenido" value=""> @@ -53,7 +45,7 @@ <div class="input-group"> <button class="btn" type="submit" name="create" >Guardar</button> </div> - <input type="button" value="Imprimir" onClick="window.print()"> + <input type="hidden" id="medico" name="medico" value="<?php echo $user[0][4]; ?>"> </form> <?php closeDatabase($pdo); ?> </body> diff --git a/src/report_management.php b/src/report_management.php index dd263d4..f8feae5 100644 --- a/src/report_management.php +++ b/src/report_management.php @@ -1,6 +1,7 @@ <?php include'database.php'; + function reportCreation() { $data = $_POST; @@ -10,6 +11,7 @@ function reportCreation() header('location: report.php'); } + function reportModification() { $data = $_POST; @@ -20,6 +22,7 @@ function reportModification() header('location: report.php'); } + function reportDeletion() { $id = $_GET["delete"]; @@ -29,6 +32,14 @@ function reportDeletion() header('location: report.php'); } + +function printPDF() +{ + $id = $_GET["print_pdf"]; + header('location: report.php'); +} + + if (isset($_POST["create"])) { reportCreation(); } @@ -38,6 +49,12 @@ if (isset($_POST["edit"])) { reportModification(); } + if (isset($_GET["delete"])) { reportDeletion(); } + + +if (isset($_GET["print_pdf"])) { + printPDF(); +}