0
I created an email system. I now want to check the messages read (appear without Bold) and unread (appear Bold) by the user. I create the table with the emails this way:
<?php
while($row = mysqli_fetch_array($result))
{
?>
<section id="s1">
<div class="div1" id="minhaDiv" style="float: left;">
<table class="table table-bordered">
<tr>
<th width="20%">De</th>
<th width="60%">Assunto</th>
<th width="10%">Prioridade</th>
<th width="10%">Recebido</th>
</tr>
<tr>
<th width="10%" colspan=4>Recebido: <?php echo $row["Data"]; ?></th>
</tr>
<tr>
<td><?php echo $row["De"]; ?></td>
<td class="td-info view_data" id="<?php echo $row["Id"]; ?>" data-toggle="modal" href="#dataModal" width="20%" style="font-weight:bold" <?php echo $row["Status"] != '1'?' Normal ':' negrito '?>><?php echo $row["Assunto"]; ?></td>
<td><?php echo $row["Prioridade"]; ?></td>
<td><?php echo $row["Hora"]; ?></td>
</tr>
<tr>
<?php
}
?>
</table>
</div>
</section>
To read the contents of the message click on this td and open a modal:
<td class="td-info view_data" id="<?php echo $row["Id"]; ?>" data-toggle="modal" href="#dataModal" width="20%" <?php echo $row["Status"] == '1'?' style="font-weight:bold" ':' style="font-weight:normal" '?>><?php echo $row["Assunto"]; ?></td>
When opening the modal with the click I update in the column Status of the database table from 1 to 0, to stay as read and in the td above I do this check as follows:
width="20%" <?php echo $row["Status"] == '1'?' style="font-weight:bold" ':' style="font-weight:normal" '?>
Javascript to open modal and update:
$('.td-info').click(function(){
var item_id = $(this).attr("id");
var status = $(this).attr("Status");
$.ajax({
url:"./fetchRAD",
method: "POST",
data:{item_id:item_id, status:status},
success:function(data){
}
});
});
But the problem is that by changing the Status value to 0, if you are a different user you will also show how the message reads. So I intended to do this client-side check and not the database-side check.
Table to record messages:
CREATE TABLE `Alertas` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Tipo` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
`Prioridade` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`Email` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`Para` longtext COLLATE utf8_unicode_ci,
`Assunto` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Conteudo` longtext COLLATE utf8_unicode_ci,
`Recebido` datetime DEFAULT NULL,
`De` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Users that can receive in group or individually:
CREATE TABLE `testeCol` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Colaborador` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`Grupo` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=149 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Table to fill status as read:
CREATE TABLE `ValAlertas` (
`IdVal` int(11) NOT NULL AUTO_INCREMENT,
`IdSMS` int(11) DEFAULT NULL,
`Para` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Status` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`IdVal`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Yes, that way I had already done, the problem is that there are several users, the first when reading changes the status field to read and then all will receive the message as read, and actually only the first user read
– Bruno
Hold on? The message is shared?
– Vinicius De Jesus
Yes, the message is for multiple users, there may be situations where it does not depend on the users who select the upload. The ideal was to validate on the client side and not in a database
– Bruno
However in Client-side there is no "Save" ideal is that you save in the bank with a table. example: "read-user" table that would have 4 fields: id, user_id, messaging, status. If user 2 reads message 15 vc saves id=x; user_id=2; messaging=15; status="read".
– Vinicius De Jesus
Yes this is the way I am doing it, but another problem arises. The message can be sent to specific users or to a group. This group refers for example to 4 users, in this situation I will have the same problem. I ask, when selecting the group, then when I do the Insert it is possible to insert a line to home user who belongs to that group?
– Bruno
It would be interesting if you edited the question and explained more about your project as well as the structure of your bank.
– Vinicius De Jesus
edited the question with complete information
– Bruno
Let’s go continue this discussion in chat.
– Bruno