I make a ticket system which works for 3 states 1 = PENDING, 3 = FINISHED, 4 = CANCELED. My DB is modeled to be inserted by foreign keys.
What I intend you to do is if the ticket is with status 3 = FINISHED, do not allow me to edit that ticket . This in order to close the ticket and not modify.
I tried to do it through my UPDATE but the problem that throws me is that if I have tickets with the status 1 = PENDING and 4 = CANCELED everyone changes them with the status 3 = FINISHED and There, it no longer allows me to modify it (which is what I need to do, but do not change my status tickets). Also what I need you to do is send me a message saying that it can not be modified anymore because the ticket is closed.
Thank you.
Code
<?php
session_start();
if (empty($_POST['mod_id'])) {
$errors[] = "ID vacío";
} else if (empty($_POST['title'])){
$errors[] = "Descripción vacío";
} else if (
!empty($_POST['title'])
){
include "../config/config.php";//Contiene funcion que conecta a la base de datos
$title = $_POST["title"];
$process_1 = $_POST["process_1"];
$process_2 = $_POST["process_2"];
$category_id = $_POST["category_id"];
$priority_id = $_POST["priority_id"];
$turn_id = $_POST["turn_id"];
$area_id = $_POST["area_id"];
$user_id = $_SESSION["user_id"];
$status_id = $_POST["status_id"];
$final_id = $_POST["final_id"];
$kind_id = $_POST["kind_id"];
$id=$_POST['mod_id'];
$sql = "update ticket set title=\"$title\",category_id=\"$category_id\",priority_id=\"$priority_id\",turn_id=\"$turn_id\",area_id=\"$area_id\",process_1=\"$process_1\",process_2=\"$process_2\",status_id=\"$status_id\", final_id=\"$final_id\",kind_id=\"$kind_id\",updated_at=NOW() where status_id !=3";
$query_update = mysqli_query($con,$sql);
if ($query_update){
$messages[] = "El ticket ha sido actualizado satisfactoriamente.";
} else{
$errors []= "Lo siento algo ha salido mal intenta nuevamente.".mysqli_error($con);
}
} else {
$errors []= "Error desconocido.";
}
if (isset($errors)){
?>
<div class="alert alert-danger" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Error!</strong>
<?php
foreach ($errors as $error) {
echo $error;
}
?>
</div>
<?php
}
if (isset($messages)){
?>
<div class="alert alert-success" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>¡Bien hecho!</strong>
<?php
foreach ($messages as $message) {
echo $message;
}
?>
</div>
<?php
}
?>
Structure table status
status_id Primaria int(11)
name varchar(100)
Ticket table structure
id Primaria int(11)
title varchar(100)
process_1 varchar(100)
process_2 varchar(100)
category_id Índice int(11)
priority_id Índice int(11)
turn_id Índice int(11)
area_id Índice int(11)
user_id Índice int(11)
status_id Índice int(11)
final_id Índice int(11)
kind_id Índice int(11)