- 15, May 2024
- #1
У меня возникла последняя проблема в системе, которую я создаю, поскольку я только что проводил тестирование, и я отправил тестовый ответ со стороны администратора внешнему пользователю и теперь хочу, чтобы внешний пользователь ответил сотрудникам службы поддержки из внешнего интерфейса, но по какой-то причине ответ не добавляется в таблицу базы данных Ticket_replies.
Я не получаю никаких ошибок, которые бы не помогли, ха-ха. Ниже приведен весь код, который у меня есть
Я не получаю никаких ошибок, которые бы не помогли, ха-ха. Ниже приведен весь код, который у меня есть
<?php
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login");
exit;
}
$username = $_SESSION['user_name'];
$customername = $_SESSION['customer_name'];
$customeremail = $_SESSION['customer_email'];
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
require_once "registerconfig.php";
if (isset($_POST['submit'])) {
// File upload configuration
$targetDir = "support-ticket-images/";
$allowTypes = array('pdf','doc','docx','jpg','png','jpeg','gif');
$statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
// Escape user inputs for security
$reply_text = strip_tags($_POST['reply_text'], ENT_QUOTES);
$ticket_id = htmlentities($_POST['ticket_id'], ENT_QUOTES);
$user_id = htmlentities($_SESSION["user_id"], ENT_QUOTES);
$fileNames = array_filter($_FILES['files']['name']);
if(!empty($fileNames)){
foreach($_FILES['files']['name'] as $key=>$val){
// File upload path
$fileName = basename($_FILES['files']['name'][$key]);
$targetFilePath = $targetDir . $fileName;
// Check whether file type is valid
$fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
if(in_array($fileType, $allowTypes)){
// Upload file to server
if(move_uploaded_file($_FILES["files"]["tmp_name"][$key], $targetFilePath)){
// Image db insert sql
$insertValuesSQL .= "('".$fileName."',LAST_INSERT_ID(),'".$username."','".$user_id."'),";
}else{
$errorUpload .= $_FILES['files']['name'][$key].' | ';
}
}else{
$errorUploadType .= $_FILES['files']['name'][$key].' | ';
}
}
if(!empty($insertValuesSQL)){
$insertValuesSQL = trim($insertValuesSQL, ',');
// Insert image file name into database
$sql = "INSERT INTO ticket_replies (ticket_id, reply_text,user_type, user_id) VALUES ('$ticket_id','$reply_text','customer', '$user_id');";
$sql .= "INSERT INTO support_ticket_files (file_name, ticket_id, user_name, user_id) VALUES $insertValuesSQL";
if(mysqli_multi_query($link, $sql)){
mysqli_multi_query($link,"UPDATE support_tickets set ticket_status = 'PENDING SUPPORT' where ticket_id ='$ticket_id'");
$errorUpload = !empty($errorUpload)?'Upload Error: '.trim($errorUpload, ' | '):'';
$errorUploadType = !empty($errorUploadType)?'File Type Error: '.trim($errorUploadType, ' | '):'';
$errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType;
echo "Replied Successfully.";
}else{
$statusMsg = "Sorry, there was an error uploading your file.";
}
}
}
// Display status message
echo $statusMsg;
}
<div class="col-md-9">
<?php
//$ticket_id = $_GET['ticket_id'];
//$user_name = $_SESSION['user_name'];
$username = $_SESSION['user_name'];
if($result = $link->query("SELECT ticket_id, ticket_subject, ticket_message, ticket_status, DATE_FORMAT(created_at,'%d/%m/%Y \at\ %H:%i:%s') AS created_at, DATE_FORMAT(ticket_timestamp,'%d/%m/%Y %H:%i:%s') AS ticket_timestamp FROM support_tickets WHERE ticket_id = ".$_GET['ticket_id']." and user_name = '".$_SESSION["user_name"]."'")){
//'". $ticket_id. "' AND user_name ='". $_SESSION["user_name"]. "'")){
//".$_GET['ticket_id']." and user_name = '".$_SESSION["user_name"]."'")){
if ($result->num_rows > 0) {
$ticket=$result->fetch_object();
?>
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-info panel-default-reply">
<div class="panel-heading-replybox" role="tab" id="headingReply">
<h4 class="panel-title-reply">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseReply" aria-expanded="true" aria-controls="collapseReply">
<i class="fa fa-pencil" aria-hidden="true"></i> Reply
</a>
</h4>
</div>
<div id="collapseReply" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingReply">
<div class="panel-body-reply-margin">
<form action="" method="post" class="form-block ticketform" enctype="multipart/form-data">
<input type="hidden" name="ticket_id" value="<?php echo $_GET['ticket_id']; ?>"/>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control input-lg" name="customer_name" value="<?php echo htmlspecialchars($_SESSION["customer_name"]); ?>" disabled>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Email</label>
<input type="text" class="form-control input-lg" name="customer_email" value="<?php echo htmlspecialchars($_SESSION["customer_email"]); ?>" disabled>
</div>
</div>
<?php if($ticket->ticket_status!='CLOSED'){ ?>
<div class="col-md-12 col-sm-12">
<div class="form-group">
<label>Message</label>
<textarea class="form-control" name="reply_text" id="reply_text" rows="10"></textarea>
</div>
</div>
<div class="col-md-12 col-sm-12">
<div class="form-group">
<label>Select Files To Upload</label>
<input type="file" name="files[]" multiple class="form-control"/>
</div>
</div>
<div class="col-md-12 col-sm-12">
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-sm">Submit</button>
</div>
</div>
<?php } else{ ?>
<div class="form-group text-center">
<label><h2><?php echo $ticket->ticket_status ?></h2></label>
<p>This support ticket is now closed, Please create new ticket for any issue</p>
</div>
<?php } ?>
</form>
</div>
</div>
<?php
}
}
?>
</div>
</div>
<div class="panel panel-default">
<?php
if($replyresult = $link->query("SELECT tr.ticket_id, tr.reply_text,tr.user_id, DATE_FORMAT(tr.reply_at,'%d/%m/%Y \at\ %H:%i:%s') AS reply_at, u.customer_name FROM ticket_replies tr left join users u on (u.user_id=tr.user_id and tr.user_type='customer' and tr.user_id='".$_SESSION["user_id"]."') WHERE ticket_id = '".$_GET["ticket_id"]."' order by reply_at desc")){
//DATE_FORMAT(tr.reply_at,'%d/%m/%Y \at\ %H:%i:%s') AS reply_at
if ($replyresult->num_rows > 0) {
while ($row = $replyresult->fetch_object()) {
?>
<?php echo ($row->user_id!=$_SESSION['user_id'])?'':''; ?>
<div class="panel-heading-replies"><i class="fa fa-user" aria-hidden="true"></i> <?php echo ($row->user_id==$_SESSION['user_id'])?$row->customer_name:'Support Team'; ?>
<span class="pull-right"><?php echo $row->reply_at?></span>
</div>
<div class="panel-body">
<?php echo html_entity_decode($row->reply_text) ?>
<?php
}
}
else {
echo "No Replies";
}
}
?>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
<strong>Original Message</strong>
<br>
<?php echo $ticket->ticket_message ?>
</div>
</div>
</div><!-- /col -->
PHP: Извините, это довольно длинный фрагмент кода.