Reformat PHP code via php-cs-fixer

This commit is contained in:
coolneng 2020-06-22 23:00:43 +02:00
parent ea9f92d2df
commit befa3b116b
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
17 changed files with 217 additions and 171 deletions

View File

@ -1,14 +1,13 @@
<?php
include 'database.php';
if($_POST['id']) {
if ($_POST['id']) {
$pdo = connectDatabase();
$cities = fetchCities($pdo, $_POST['id']);
foreach($cities as $row){
foreach ($cities as $row) {
echo '"<option value="'.$row[0].'">'.$row[4].'</option>';
}
closeDatabase($pdo);
}
?>

View File

@ -34,7 +34,7 @@
$list = listHolidays($pdo);
foreach($list as $row) :
foreach ($list as $row) :
?>
<tr>
<td><?php echo $row[1]; ?></td>

View File

@ -1,38 +1,42 @@
<?php
include'database.php';
function holidayCreation(){
$data = $_POST;
$pdo = connectDatabase();
createHoliday($pdo, $data);
closeDatabase($pdo);
header('location: calendar.php');
function holidayCreation()
{
$data = $_POST;
$pdo = connectDatabase();
createHoliday($pdo, $data);
closeDatabase($pdo);
header('location: calendar.php');
}
function holidayModification(){
$data = $_POST;
$id = $_POST["id"];
$pdo = connectDatabase();
editHoliday($pdo, $data, $id);
closeDatabase($pdo);
header('location: calendar.php');
function holidayModification()
{
$data = $_POST;
$id = $_POST["id"];
$pdo = connectDatabase();
editHoliday($pdo, $data, $id);
closeDatabase($pdo);
header('location: calendar.php');
}
function holidayDeletion(){
$id = $_GET["delete"];
$pdo = connectDatabase();
deleteHoliday($pdo, $id);
closeDatabase($pdo);
header('location: calendar.php');
function holidayDeletion()
{
$id = $_GET["delete"];
$pdo = connectDatabase();
deleteHoliday($pdo, $id);
closeDatabase($pdo);
header('location: calendar.php');
}
function calendarConfig(){
$data = $_POST;
$pdo = connectDatabase();
configureCalendar($pdo, $data);
closeDatabase($pdo);
header('location: calendar.php');
function calendarConfig()
{
$data = $_POST;
$pdo = connectDatabase();
configureCalendar($pdo, $data);
closeDatabase($pdo);
header('location: calendar.php');
}
if (isset($_POST["create"])) {

View File

@ -18,7 +18,7 @@
?>
<form name="create_form" method="post" action="calendar_management.php">
<?php
if($_SESSION["user_type"] == 2):
if ($_SESSION["user_type"] == 2):
$pdo = connectDatabase();
$user = finduser($pdo, $_SESSION["user"]);
closeDatabase($pdo);
@ -28,7 +28,7 @@
<div class="input-group">
<select id="medico" name="medico">
<option>Seleccione un médico</option>
<?php foreach($doctors as $row) : ?>
<?php foreach ($doctors as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>

View File

@ -1,6 +1,7 @@
<?php
function connectDatabase() {
function connectDatabase()
{
$connection = 'unix_socket';
$host = '../.mysql/mysql.sock';
$charset = 'utf8mb4';
@ -10,17 +11,20 @@ function connectDatabase() {
return $pdo;
}
function closeDatabase($pdo) {
function closeDatabase($pdo)
{
$pdo = null;
}
function listRows($pdo, $table) {
function listRows($pdo, $table)
{
$query = "SELECT * FROM ?";
$result = $pdo->prepare($query)->execute([$table]);
return $result;
}
function createPatient($pdo, $data) {
function createPatient($pdo, $data)
{
$query = "INSERT INTO paciente
(nombre, apellido, fecha_de_nacimiento, documento_identificativo, tipo_documento, direccion, localidad, provincia, pais)
VALUES (?,?,?,?,?,?,?,?,?)";
@ -30,7 +34,8 @@ function createPatient($pdo, $data) {
return "Paciente creado con éxito";
}
function editPatient($pdo, $data, $id) {
function editPatient($pdo, $data, $id)
{
$query = "UPDATE paciente SET nombre=?, apellido=?, fecha_de_nacimiento=?, documento_identificativo=?,
tipo_documento=?, direccion=?, localidad=?, provincia=?, pais=? WHERE id=?";
$result = $pdo->prepare($query);
@ -40,11 +45,12 @@ function editPatient($pdo, $data, $id) {
return "Paciente modificado con éxito";
}
function deletePatient($pdo, string $id) {
function deletePatient($pdo, string $id)
{
$check = "SELECT * FROM informes where paciente = ?";
$result = $pdo->prepare($check);
$result->execute([$id]);
if($result->columnCount() == 0){
if ($result->columnCount() == 0) {
$statement = "DELETE FROM paciente where id=?";
$pdo->prepare($statement)->execute([$id]);
return "El paciente se ha eliminado correctamente";
@ -52,8 +58,9 @@ function deletePatient($pdo, string $id) {
return "No se puede eliminar el paciente dado que tiene citas";
}
function createHoliday($pdo, $data) {
if(empty($data["medico"])){
function createHoliday($pdo, $data)
{
if (empty($data["medico"])) {
$query = "INSERT INTO festivo (fecha_festivo, tipo_festivo, medico) VALUES (?,?,?)";
$pdo->prepare($query)->execute([$data["fecha_festivo"], $data["tipo_festivo"], $data["medico"]]);
} else {
@ -63,46 +70,53 @@ function createHoliday($pdo, $data) {
return "Festivo creado con éxito";
}
function editHoliday($pdo, $data, $id) {
function editHoliday($pdo, $data, $id)
{
$query = "UPDATE festivo SET fecha_festivo=?, tipo_festivo=?, medico=? WHERE id=?";
$pdo->prepare($query)->execute([$data["fecha_festivo"], $data["tipo_festivo"], $data["medico"], $id]);
return "Festivo modificado con éxito";
}
function deleteHoliday($pdo, $id) {
function deleteHoliday($pdo, $id)
{
$statement = "DELETE FROM festivo where id=?";
$pdo->prepare($statement)->execute([$id]);
return "Festivo borrado con éxito";
}
function createUser($pdo, $data) {
function createUser($pdo, $data)
{
$query = "INSERT INTO usuario (nombre, usuario, contraseña, rol, correo) VALUES (?,?,?,?,?)";
$pdo->prepare($query)->execute([$data["nombre"], $data["usuario"], $data["contraseña"], $data["rol"], $data["correo"]]);
return "Usuario creado con éxito";
}
function editUser($pdo, $data, $id) {
function editUser($pdo, $data, $id)
{
$query = "UPDATE usuario SET nombre=?, usuario=?, contraseña=?, rol=?, correo=? WHERE id=?";
$result = $pdo->prepare($query);
$result->execute([$data["nombre"], $data["usuario"], $data["contraseña"], $data["rol"], $data["correo"], $id]);
return "Usuario modificado con éxito";
}
function deactivateUser($pdo, $data, $id) {
function deactivateUser($pdo, $data, $id)
{
$query = "UPDATE usuario SET fecha_baja=now() WHERE id=?";
$result = $pdo->prepare($query);
$result->execute([$id]);
return "Usuario desactivado con éxito";
}
function listUsers($pdo) {
function listUsers($pdo)
{
$query = "SELECT usuario.nombre, usuario.usuario, rol.nombre, usuario.correo, usuario.id, fecha_baja FROM usuario
INNER JOIN rol ON usuario.rol = rol.codigo";
$result = $pdo->query($query)->fetchAll();
return $result;
}
function fetchUserData($pdo, string $id) {
function fetchUserData($pdo, string $id)
{
$query = "SELECT * FROM usuario WHERE id=?";
$result = $pdo->prepare($query);
$result->execute([$id]);
@ -110,7 +124,8 @@ function fetchUserData($pdo, string $id) {
return $data;
}
function findUser($pdo, $input) {
function findUser($pdo, $input)
{
$input = "%$input%";
$query = "SELECT usuario.nombre, usuario.usuario, rol.nombre, usuario.correo, usuario.id, fecha_baja
FROM usuario, rol WHERE usuario.rol=rol.codigo AND (usuario.nombre LIKE ? OR usuario.usuario LIKE ? OR usuario.correo LIKE ?)";
@ -120,7 +135,8 @@ function findUser($pdo, $input) {
return $data;
}
function listPatients($pdo) {
function listPatients($pdo)
{
$query = "SELECT paciente.id, paciente.nombre, paciente.apellido, paciente.fecha_de_nacimiento, paciente.documento_identificativo,
paciente.tipo_documento, paciente.direccion, municipios.nombre, provincias.provincia, paciente.pais, cita.id, informe.titulo
FROM paciente INNER JOIN municipios ON paciente.localidad = municipios.id_municipio
@ -134,7 +150,8 @@ function listPatients($pdo) {
}
function fetchPatientData($pdo, string $id) {
function fetchPatientData($pdo, string $id)
{
$query = "SELECT * FROM paciente WHERE id=?";
$result = $pdo->prepare($query);
$result->execute([$id]);
@ -142,7 +159,8 @@ function fetchPatientData($pdo, string $id) {
return $data;
}
function findPatient($pdo, $input) {
function findPatient($pdo, $input)
{
$input = "%$input%";
$query = "SELECT * FROM paciente WHERE nombre LIKE ? OR apellido LIKE ? OR documento_identificativo LIKE ?";
$result = $pdo->prepare($query);
@ -151,7 +169,8 @@ function findPatient($pdo, $input) {
return $data;
}
function fetchCities($pdo, $id){
function fetchCities($pdo, $id)
{
$query = "SELECT * FROM municipios WHERE id_provincia=?";
$result = $pdo->prepare($query);
$result->execute([$id]);
@ -159,7 +178,8 @@ function fetchCities($pdo, $id){
return $data;
}
function fetchRegions($pdo){
function fetchRegions($pdo)
{
$query = "SELECT * FROM provincias";
$result = $pdo->prepare($query);
$result->execute();
@ -167,7 +187,8 @@ function fetchRegions($pdo){
return $data;
}
function listHolidays($pdo){
function listHolidays($pdo)
{
$query = "SELECT * FROM festivo";
$result = $pdo->prepare($query);
$result->execute();
@ -175,7 +196,8 @@ function listHolidays($pdo){
return $data;
}
function listDoctors($pdo){
function listDoctors($pdo)
{
$query = "SELECT * FROM usuario where rol=2";
$result = $pdo->prepare($query);
$result->execute();
@ -183,7 +205,8 @@ function listDoctors($pdo){
return $data;
}
function fetchHolidayData($pdo, string $id) {
function fetchHolidayData($pdo, string $id)
{
$query = "SELECT * FROM festivo WHERE id=?";
$result = $pdo->prepare($query);
$result->execute([$id]);
@ -191,7 +214,8 @@ function fetchHolidayData($pdo, string $id) {
return $data;
}
function listReports($pdo){
function listReports($pdo)
{
$query = "SELECT informe.id, informe.titulo, informe.fecha, informe.hora, paciente.apellido,
usuario.nombre FROM informe INNER JOIN paciente ON paciente.id = informe.paciente
INNER JOIN usuario ON usuario.id = informe.medico";
@ -201,7 +225,8 @@ function listReports($pdo){
return $data;
}
function createReport($pdo, $data) {
function createReport($pdo, $data)
{
$query = "INSERT INTO informe
(fecha, hora, paciente, titulo, contenido, medico)
VALUES (?,?,?,?,?,?)";
@ -210,20 +235,23 @@ function createReport($pdo, $data) {
return "Informe creado con éxito";
}
function editReport($pdo, $data, $id){
function editReport($pdo, $data, $id)
{
$query = "UPDATE informe SET fecha=?, hora=?, paciente=?, titulo=?, contenido=?, medico=? WHERE id=?";
$pdo->prepare($query)->execute([$data["fecha"], $data["hora"], $data["paciente"],
$data["titulo"], $data["contenido"], $data["medico"], $id]);
return "Informe modificado con éxito";
}
function deleteReport($pdo, $id) {
function deleteReport($pdo, $id)
{
$statement = "DELETE FROM informe where id=?";
$pdo->prepare($statement)->execute([$id]);
return "Informe borrado con éxito";
}
function fetchPatients($pdo){
function fetchPatients($pdo)
{
$query = "SELECT id, apellido from paciente";
$result = $pdo->prepare($query);
$result->execute();
@ -231,7 +259,8 @@ function fetchPatients($pdo){
return $data;
}
function fetchReportData($pdo, string $id) {
function fetchReportData($pdo, string $id)
{
$query = "SELECT * FROM informe WHERE id=?";
$result = $pdo->prepare($query);
$result->execute([$id]);
@ -239,7 +268,8 @@ function fetchReportData($pdo, string $id) {
return $data;
}
function fetchLoginData($pdo, $data){
function fetchLoginData($pdo, $data)
{
$query = "SELECT usuario, contraseña, rol FROM usuario WHERE usuario=? AND fecha_baja IS NULL";
$result = $pdo->prepare($query);
$result->execute([$data["usuario"]]);
@ -247,7 +277,8 @@ function fetchLoginData($pdo, $data){
return $data;
}
function checkExistingCalendar($pdo, $data){
function checkExistingCalendar($pdo, $data)
{
$query = "SELECT * from calendario WHERE medico=?";
$result = $pdo->prepare($query);
$result->execute([$data["medico"]]);
@ -256,9 +287,10 @@ function checkExistingCalendar($pdo, $data){
}
function configureCalendar($pdo, $data){
function configureCalendar($pdo, $data)
{
$existing = checkExistingCalendar($pdo, $data);
if(!$existing){
if (!$existing) {
$query = "INSERT INTO calendario
(hora_inicio_mañana, hora_fin_mañana, hora_inicio_tarde, hora_fin_tarde,
horario, sabado_habil, domingo_habil, duracion_cita_por_defecto, medico)
@ -276,5 +308,3 @@ function configureCalendar($pdo, $data){
}
return "Calendario configurado con éxito";
}
?>

View File

@ -31,7 +31,7 @@
<div class="input-group">
<select id="medico" name="medico">
<option>Seleccione un médico</option>
<?php foreach($doctors as $row) : ?>
<?php foreach ($doctors as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>

View File

@ -31,7 +31,7 @@
<div class="input-group">
<select id="medico" name="medico">
<option>Seleccione un médico</option>
<?php foreach($doctors as $row) : ?>
<?php foreach ($doctors as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>

View File

@ -3,16 +3,16 @@
<nav>
<ul class="navbar-left">
<li class="list"><a href="index.php">Página principal</a></li>
<?php if(isset($_SESSION["user"])): ?>
<?php if (isset($_SESSION["user"])): ?>
<li class="list"><a href="user.php">Usuarios</a></li>
<li class="list"><a href="patient.php">Pacientes</a></li>
<li class="list"><a href="appointment.php">Citas</a></li>
<li class="list"><a href="calendar.php">Calendario</a></li>
<?php endif; ?>
<?php if($_SESSION["user_type"] == 2): ?>
<?php if ($_SESSION["user_type"] == 2): ?>
<li class="list"><a href="report.php">Informes</a></li>
<?php endif; ?>
<?php if(isset($_SESSION["user"])): ?>
<?php if (isset($_SESSION["user"])): ?>
<li class="list"><a href="user_management.php?logout=1">Log out</a></li>
<?php else: ?>
<li class="list"><a href="login.php">Login</a></li>

View File

@ -47,7 +47,7 @@
$list = listPatients($pdo);
}
foreach($list as $row) :
foreach ($list as $row) :
?>
<tr>
<td><?php echo $row[1]; ?></td>

View File

@ -49,7 +49,7 @@
<div class="input-group">
<label>provincia</label>
<select id="provincia" name="provincia">
<?php foreach($regions as $row) : ?>
<?php foreach ($regions as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>

View File

@ -1,38 +1,42 @@
<?php
include'database.php';
function patientCreation(){
$data = $_POST;
$pdo = connectDatabase();
createPatient($pdo, $data);
closeDatabase($pdo);
header('location: patient.php');
function patientCreation()
{
$data = $_POST;
$pdo = connectDatabase();
createPatient($pdo, $data);
closeDatabase($pdo);
header('location: patient.php');
}
function patientModification(){
$data = $_POST;
$id = $_POST["id"];
$pdo = connectDatabase();
editPatient($pdo, $data, $id);
closeDatabase($pdo);
header('location: patient.php');
function patientModification()
{
$data = $_POST;
$id = $_POST["id"];
$pdo = connectDatabase();
editPatient($pdo, $data, $id);
closeDatabase($pdo);
header('location: patient.php');
}
function patientDeletion(){
$id = $_GET["delete"];
$pdo = connectDatabase();
deletePatient($pdo, $id);
closeDatabase($pdo);
header('location: patient.php');
function patientDeletion()
{
$id = $_GET["delete"];
$pdo = connectDatabase();
deletePatient($pdo, $id);
closeDatabase($pdo);
header('location: patient.php');
}
function patientFind(){
$data = $_POST;
$pdo = connectDatabase();
findPatient($pdo, $data);
closeDatabase($pdo);
$search = $data["search_box"];
header("location: patient.php?search=$search");
function patientFind()
{
$data = $_POST;
$pdo = connectDatabase();
findPatient($pdo, $data);
closeDatabase($pdo);
$search = $data["search_box"];
header("location: patient.php?search=$search");
}
if (isset($_POST["create"])) {

View File

@ -35,7 +35,7 @@
$list = listReports($pdo);
foreach($list as $row) :
foreach ($list as $row) :
?>
<tr>
<td><?php echo $row[1]; ?></td>

View File

@ -33,7 +33,7 @@
<div class="input-group">
<select id="paciente" name="paciente">
<option>Seleccione un paciente</option>
<?php foreach($patients as $row) : ?>
<?php foreach ($patients as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>
@ -41,7 +41,7 @@
<div class="input-group">
<select id="medico" name="medico">
<option>Seleccione un médico</option>
<?php foreach($doctors as $row) : ?>
<?php foreach ($doctors as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>

View File

@ -31,7 +31,7 @@
<div class="input-group">
<select id="paciente" name="paciente">
<option>Seleccione un paciente</option>
<?php foreach($patients as $row) : ?>
<?php foreach ($patients as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>
@ -39,7 +39,7 @@
<div class="input-group">
<select id="medico" name="medico">
<option>Seleccione un médico</option>
<?php foreach($doctors as $row) : ?>
<?php foreach ($doctors as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>

View File

@ -1,29 +1,32 @@
<?php
include'database.php';
function reportCreation(){
$data = $_POST;
$pdo = connectDatabase();
createReport($pdo, $data);
closeDatabase($pdo);
header('location: report.php');
function reportCreation()
{
$data = $_POST;
$pdo = connectDatabase();
createReport($pdo, $data);
closeDatabase($pdo);
header('location: report.php');
}
function reportModification(){
$data = $_POST;
$id = $_POST["id"];
$pdo = connectDatabase();
editReport($pdo, $data, $id);
closeDatabase($pdo);
header('location: report.php');
function reportModification()
{
$data = $_POST;
$id = $_POST["id"];
$pdo = connectDatabase();
editReport($pdo, $data, $id);
closeDatabase($pdo);
header('location: report.php');
}
function reportDeletion(){
$id = $_GET["delete"];
$pdo = connectDatabase();
deleteReport($pdo, $id);
closeDatabase($pdo);
header('location: report.php');
function reportDeletion()
{
$id = $_GET["delete"];
$pdo = connectDatabase();
deleteReport($pdo, $id);
closeDatabase($pdo);
header('location: report.php');
}
if (isset($_POST["create"])) {

View File

@ -40,8 +40,8 @@
$list = listUsers($pdo);
}
foreach($list as $row) :
if(!$row[5]):
foreach ($list as $row) :
if (!$row[5]):
?>
<tr>
<td><?php echo $row[0]; ?></td>

View File

@ -3,61 +3,67 @@ include'database.php';
session_start();
function userCreation(){
$data = $_POST;
$pdo = connectDatabase();
createUser($pdo, $data);
closeDatabase($pdo);
header('location: user.php');
function userCreation()
{
$data = $_POST;
$pdo = connectDatabase();
createUser($pdo, $data);
closeDatabase($pdo);
header('location: user.php');
}
function userModification(){
$data = $_POST;
$id = $_POST["id"];
$pdo = connectDatabase();
editUser($pdo, $data, $id);
closeDatabase($pdo);
header('location: user.php');
function userModification()
{
$data = $_POST;
$id = $_POST["id"];
$pdo = connectDatabase();
editUser($pdo, $data, $id);
closeDatabase($pdo);
header('location: user.php');
}
function userDeletion(){
$id = $_GET["delete"];
$pdo = connectDatabase();
deactivateUser($pdo, $data, $id);
closeDatabase($pdo);
header('location: user.php');
function userDeletion()
{
$id = $_GET["delete"];
$pdo = connectDatabase();
deactivateUser($pdo, $data, $id);
closeDatabase($pdo);
header('location: user.php');
}
function userFind(){
$data = $_POST;
$pdo = connectDatabase();
findUser($pdo, $data);
closeDatabase($pdo);
$search = $data["search_box"];
header("location: user.php?search=$search");
function userFind()
{
$data = $_POST;
$pdo = connectDatabase();
findUser($pdo, $data);
closeDatabase($pdo);
$search = $data["search_box"];
header("location: user.php?search=$search");
}
function userLogin(){
$location = 'login.php';
$data = $_POST;
$pdo = connectDatabase();
$db_data = fetchLoginData($pdo, $data);
closeDatabase($pdo);
if($data["usuario"] == $db_data["usuario"] && $data["contraseña"] == $db_data["contraseña"]){
$_SESSION["user"] = $db_data["usuario"];
$_SESSION["user_type"] = $db_data["rol"];
$location = 'index.php';
}
header("location: $location");
function userLogin()
{
$location = 'login.php';
$data = $_POST;
$pdo = connectDatabase();
$db_data = fetchLoginData($pdo, $data);
closeDatabase($pdo);
if ($data["usuario"] == $db_data["usuario"] && $data["contraseña"] == $db_data["contraseña"]) {
$_SESSION["user"] = $db_data["usuario"];
$_SESSION["user_type"] = $db_data["rol"];
$location = 'index.php';
}
header("location: $location");
}
function userLogout(){
if(isset($_SESSION["user"])){
session_unset();
session_destroy();
}
header("location: index.php");
function userLogout()
{
if (isset($_SESSION["user"])) {
session_unset();
session_destroy();
}
header("location: index.php");
}
if (isset($_POST["create"])) {