-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnew_chat.php
27 lines (21 loc) · 936 Bytes
/
new_chat.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
// Include the database connection file
require_once 'lib.required.php';
require_once 'db.php';
// Check if the user is authenticated (i.e. if the username is not empty)
if (empty($user)) {
// If the user is not authenticated, output an error message and exit the script
die("User not authenticated");
}
$_SESSION['searchr_term'] = '';
unset($_SESSION['search_term']);
$deployment = $config['azure']['default'];
$document_name = $_SESSION['document_name'] = '';
$document_text = $_SESSION['document_text'] = '';
// Check if the request method is POST
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Create a new chat in the database using the authenticated user's username as the chat's creator
$newChatId = create_chat($user, 'Chat', '', $deployment, $document_name, $document_text);
// Return the ID of the new chat as a JSON object to the client
echo json_encode(['chat_id' => $newChatId]);
}