isAdmin($_SESSION['user_id']); $services = $ticket->getServices($_SESSION['user_id'], $isAdmin); $attachmentSettings = $TicketSettings->get(array('attachments_enabled', 'attachment_save_dir', 'attachment_limit', 'attachment_max_size', 'attachment_extensions')); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $attachments = new Attachments( $db, $_FILES['ticket_file'], $attachmentSettings['attachment_save_dir'], $attachmentSettings['attachment_limit'], $attachmentSettings['attachment_max_size'], explode(', ', $attachmentSettings['attachment_extensions']) ); $_POST = array_map('trim', $_POST); $_SESSION['ticket']['ticket_subject'] = strip_real_escape_string($_POST['ticket_subject']); $_SESSION['ticket']['ticket_service'] = $_POST['ticket_service']; $_SESSION['ticket']['ticket_message'] = strip_real_escape_string($_POST['ticket_message']); $errors = array(); $fileErrors = array(); if (empty($_POST['ticket_subject'])) { $errors[] = get_lang('no_ticket_subject'); } elseif (strlen($_POST['ticket_subject']) > 64 || strlen($_POST['ticket_subject']) < 4) { $errors[] = get_lang('invalid_ticket_subject_length'); } if (array_search($_POST['ticket_service'], array_column($services, 'home_id')) === false) { $errors[] = get_lang('invalid_home_selected'); } if (empty($_POST['ticket_message'])) { $errors[] = get_lang('no_ticket_message'); } elseif (strlen($_POST['ticket_message']) < 4) { $errors[] = get_lang('invalid_ticket_message_length'); } if ($attachments->checkPath() === false && $attachmentSettings['attachments_enabled']) { $fileErrors[] = get_lang('attachment_directory_not_writable'); } if ($attachments->validAttachmentCount() === false && $attachmentSettings['attachments_enabled']) { $fileErrors[] = get_lang_f('attachment_invalid_file_count', $attachmentSettings['attachment_limit']); } if (empty($errors)) { $open = $ticket->open($_SESSION['user_id'], getClientIPAddress(), strip_real_escape_string($_POST['ticket_subject']), strip_real_escape_string($_POST['ticket_message']), $_POST['ticket_service'], $isAdmin); if (!$open) { echo ticketErrors(array(get_lang('failed_to_open'))); $view->refresh("?m=tickets&p=submitticket", 60); return; } if (isset($_SESSION['ticket'])) { unset($_SESSION['ticket']); } if ($attachmentSettings['attachments_enabled']) { // Validate the uploaded files if specified path exists and is writable. and if the amount of files is valid. // if any files fail to validate, then only save/move the ones which validated successfully and show an error for the ones which didn't. if (empty($fileErrors)) { $validator = $attachments->validate(); $fileErrors[] = $validator->getErrors(); $attachments->save($open['tid']); } setcookie('fileErrors', json_encode(array('uid' => $open['uid'], 'fileErrors' => $fileErrors)), time() + 86400, '/'); } //TICKET SUBMITTED, POST ON DISCORD and log //logger //$db->logger( "SUPPORT TICKET SUBMITTED "); $db->logger( "TICKET SUBMITTED by " . $_SESSION['user_id']); //WEBHOOK Discord======================================================================================= $webhook = "https://discord.com/api/webhooks/1087807080657854484/yYtW8q63xKj3rTFYrNfW2LJk_GeC_WtuI8eJOyELxWbqTQ-uMzOO2I9qofoJCoHXFhC1"; //$webhook = "https://discord.com/api/webhooks/710275918274363412/g5Tr-EUdEnLfFryOlscxJ6FuPiSJuE6EMKRYmh9UGMiqTUxU5-y9CQrBlDJW7znr0Tol"; $msg = "Server support ticket created:\n"."ServerID: " .$_POST['ticket_service'] ."\n". "Subject: " .$_POST['ticket_subject']; $json_data = array ('content'=>"$msg"); $make_json = json_encode($json_data); $ch = curl_init( $webhook ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec( $ch ); //If you need to debug, or find out why you can't send message uncomment line below, and execute script. //echo $response; //end WEBHOOK Discord $view->refresh("?m=tickets&p=viewticket&tid=".$open['tid']."&uid=".$open['uid'], 0); return; } else { echo ticketErrors($errors); $view->refresh("?m=tickets&p=submitticket", 60); return; } } echo '

'.get_lang('submit_ticket').'

'; echo '
'. ticketErrors() .'
'; echo '
'; if ($attachmentSettings['attachments_enabled']) { echo attachmentForm(); } echo '
'; require 'js/javascript_vars.php'; ?>