Based on the list of files and changes below, please help me create a title for the…
- User
Based on the list of files and changes below, please help me create a title for the commit message. Following the title, provide a short, easy-to-understand description of the changes along with inserting appropriate emojis to make the title and description more eye-catching and interesting: File: .htaccess Changes: diff --git a/.htaccess b/.htaccess index 6e49f60..f21c542 100644 --- a/.htaccess +++ b/.htaccess @@ -33,6 +33,7 @@ RewriteRule ^current-plant api_worksuite.php?map_infor=current_plant RewriteRule ^app-license/(.*) api_worksuite.php?map_infor=license&project_id=1 RewriteRule ^infor-user/(.*) api_worksuite.php?map_infor=user_chat&id=1 RewriteRule ^workchat/export-contacts api_worksuite.php?export=contacts [QSA,L] +RewriteRule ^workchat/export-chat/([0-9]+) api_worksuite.php?export=chats&id=$1 [QSA,L]
RewriteCond %{REQUEST_METHOD} POST RewriteRule ^store-template db_mess/wasend.php?act=create_template
File: api_worksuite.php Changes: diff --git a/api_worksuite.php b/api_worksuite.php index 344d43b..219e987 100644 --- a/api_worksuite.php +++ b/api_worksuite.php @@ -1918,6 +1918,7 @@ WHERE uc.
fromIN(SELECT DISTINCT u.id AS uid SELECT cc.name AS client_contact_name, cc.email AS whatsapp_id,-
u.id AS uid, u.uuid AS uuid, c.name AS client_name, c.image AS client_image,
@@ -1953,6 +1954,7 @@ WHERE uc.
fromIN(SELECT DISTINCT u.id AS uid SELECT f.client_contact_name, f.whatsapp_id,-
f.uid, f.uuid, f.client_name, f.client_image,
@@ -2023,6 +2025,143 @@ WHERE uc.
fromIN(SELECT DISTINCT u.id AS uid http_response_code(400); // Đặt mã lỗi HTTP tùy chọn echo json_encode(["error" => error_message]); } +} elseif (isset(_GET['export']) && _GET['export'] == 'chats' && isset(_GET['id'])) {- // Get the ID from the query parameter
- _GET['id'];
- $headers = apache_request_headers();
- headers, CASE_LOWER);
- $result_api = [];
- if (isset(headers['authorization']) && isset(headers['x-worksuite-company-token'])) {
-
$token = $headers['authorization']; -
$x_token = $headers['x-worksuite-company-token']; -
if ($token && $x_token) { -
$curl = curl_init(); -
curl_setopt_array($curl, array( -
CURLOPT_URL => $util->api_erp . "messages/chat-message/{$id}?per_page=300", -
CURLOPT_RETURNTRANSFER => true, -
CURLOPT_ENCODING => '', -
CURLOPT_MAXREDIRS => 10, -
CURLOPT_TIMEOUT => 30, -
CURLOPT_FOLLOWLOCATION => true, -
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, -
CURLOPT_CUSTOMREQUEST => 'GET', -
CURLOPT_HTTPHEADER => array( -
'X-WorkSuite-Company-Token: ' . $x_token, -
'Authorization: ' . $token -
), -
)); -
$response = curl_exec($curl); -
curl_close($curl); -
// Check for any cURL errors -
if (curl_errno($curl)) { -
// Handle the error -
echo json_encode(["error" => curl_error($curl)]); -
exit; -
} else { -
// Pass the response back to the client -
$data_mess = json_decode($response, true); -
if (count($data_mess['data']) > 0) { -
// Đảo ngược mảng để sắp xếp tin nhắn từ cũ đến mới -
$data_mess['data'] = array_reverse($data_mess['data']); -
$user_ids = array_unique(array_column($data_mess['data'], 'user_one')); -
$sql_user = "SELECT `id`,`name` FROM users WHERE `id` IN(" . implode(',', $user_ids) . ");"; -
$bindings_user = []; -
$data_user = $util->executeSQLQuery($sql_user, $bindings_user); -
$messages_by_date = []; -
foreach ($data_mess['data'] as $message) { -
$date = date('Y-m-d', strtotime($message['created_at'])); -
if (!isset($messages_by_date[$date])) { -
$messages_by_date[$date] = []; -
} -
// Find the sender name from the $data_user array -
$sender_name = ''; -
foreach ($data_user as $user) { -
if ($user['id'] == $message['user_one']) { -
$sender_name = $user['name']; -
break; -
} -
} -
// Create a new array with only the required attributes and the new sender_name attribute -
$new_message = [ -
'message' => $message['message'], -
'created_at' => $message['created_at'], -
'sender_name' => $sender_name -
]; -
$messages_by_date[$date][] = $new_message; -
} -
header("Content-type: application/vnd.ms-word"); -
header("Content-Disposition: attachment;Filename=chat_history.doc"); -
// Xuất HTML -
echo "<html><head><meta charset='UTF-8'><style> - body { font-family: Arial, sans-serif; }
- h1.header-chat-history {
-
font-size: 28px; -
text-align: center; -
font-weight: bold; -
color: #4A90E2; -
text-transform: uppercase; -
margin-bottom: 20px; -
border-bottom: 3px solid #4A90E2; -
padding-bottom: 10px; -
letter-spacing: 2px; - }
- .date-header { font-size: 16px; text-align: center; margin-top: 30px; margin-bottom: 15px; font-weight: bold; }
- .chat-box { margin-bottom: 15px; padding: 10px; border-radius: 6px; }
- .sender-name { font-weight: bold; font-size: 14px; margin-bottom: 5px; display: block; }
- .chat-message { font-size: 13px; margin-bottom: 5px; display: block; }
- .chat-time { font-size: 12px; color: #888888; margin-top: 5px; display: block; } +";
-
echo "<h1 class='header-chat-history'>Chat History</h1>"; -
foreach ($messages_by_date as $date => $messages) { -
$formatted_date = date('l, F j, Y', strtotime($date)); -
echo "<div class='date-header'>$formatted_date</div>"; -
foreach ($messages as $msg) { -
$sender_name = $msg['sender_name']; -
$hash = md5($sender_name); -
$color = substr($hash, 0, 6); -
$bgColor = '#' . $color; -
// Strip the hash at the beginning if it's there -
$hexColor = str_replace('#', '', $bgColor); -
$r = hexdec(substr($hexColor, 0, 2)); -
$g = hexdec(substr($hexColor, 2, 2)); -
$b = hexdec(substr($hexColor, 4, 2)); -
$yiq = (($r * 299) + ($g * 587) + ($b * 114)) / 1000; -
$textColor = ($yiq >= 128) ? '#000000' : '#FFFFFF'; -
$time = date('h:i A', strtotime($msg['created_at'])); -
$contrastTimeColor = ($textColor == '#000000') ? '#555555' : '#CCCCCC'; // Tạo màu thời gian tương phản nhẹ hơn -
// Tạo khoảng trắng không phá vỡ để tạo khoảng cách với lề trái -
$indent = str_repeat(' ', 5); -
echo "<div class='chat-box' style='background-color: $bgColor; color: $textColor;'>"; -
echo "<p> </p><span class='sender-name'>$indent{$sender_name}</span><br><br>"; -
echo "<span>$indent{$msg['message']}</span><br><br>"; -
echo "<span class='chat-time' style='color: $contrastTimeColor;'>$indent{$time}</span><p> </p>"; // Thời gian ở dưới cùng -
echo "</div>"; -
} -
} -
echo "</body>"; -
echo "</html>"; -
} else { -
echo $response; -
} -
exit; -
} -
} else { -
$error_message = "Missing token."; -
http_response_code(400); // Đặt mã lỗi HTTP tùy chọn -
echo json_encode(["error" => $error_message]); -
exit; -
} - } else {
-
$error_message = "Authorization headers missing."; -
http_response_code(400); -
echo json_encode(["error" => $error_message]); -
exit; - } } elseif (isset(_GET['export']) && _GET['export'] == 'contacts') { // Bao gồm thư viện SimpleXLSXWriter require_once 'xlsxwriter.class.php';
-
- Assistant
Commit Title: 🚀 Enhance Chat Export Functionality in .htaccess and API
Description:
- 📘 New Export Rule: Added a rewrite rule in
.htaccessto allow exporting chat messages viaworkchat/export-chat/{id}. - 💬 Chat Export Integration: Enhanced
api_worksuite.phpto support exporting chat histories. The chats are formatted and exported as a Word document with clear styling for date headers and message details. - 🔑 Authorization Checks: Implemented token-based authorization to ensure secure export operations.
- 🛠️ Code Cleanup: Made structural improvements in the PHP export logic, adding a new attribute for user ID in API responses and ensuring error handling for missing headers or tokens.
- 📘 New Export Rule: Added a rewrite rule in