-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,58 +37,82 @@ | |
$subject = $header->subject; | ||
$date = date('Y-m-d H:i:s', strtotime($header->date)) . '.000'; | ||
|
||
// Determine the URS provider based on the email sender | ||
$providerAEmail = '[email protected]'; | ||
$providerBEmail = '[email protected]'; | ||
$providerCEmail = '[email protected]'; | ||
|
||
// Determine the URS provider based on the email sender | ||
if ($from == $providerAEmail) { | ||
$ursProvider = 'FORUM'; | ||
} elseif ($from == $providerBEmail) { | ||
$ursProvider = 'ADNDRC'; | ||
} elseif ($from == $providerCEmail) { | ||
$ursProvider = 'MFSD'; | ||
} else { | ||
$ursProvider = 'Unknown'; | ||
} | ||
// Determine the URS provider | ||
$provider = match ($from) { | ||
'[email protected]' => 'FORUM', | ||
'[email protected]' => 'ADNDRC', | ||
'[email protected]' => 'MFSD', | ||
default => 'Unknown', | ||
}; | ||
|
||
// Extract domain name or relevant info from the email (you'd need more specific code here based on the email content) | ||
$body = imap_fetchbody($inbox, $emailId, 1); | ||
$domain = extractDomainNameFromEmail($body); | ||
|
||
// Extract TLD from the domain and prepend a dot | ||
$parts = explode('.', $domain); | ||
$domainName = $parts[0]; | ||
$tld = "." . end($parts); | ||
if (!$domain) { | ||
error_log("No domain found in email body for email ID $emailId"); | ||
continue; | ||
} | ||
|
||
// Insert into the database | ||
$stmt = $dbh->prepare("SELECT sld, tld, client_id FROM service_domain WHERE sld = ?"); | ||
$stmt->execute([$domainName]); | ||
$stmt = $dbh->prepare("SELECT id, userid FROM tbldomains WHERE domain = ?"); | ||
$stmt->execute([$domain]); | ||
$domainResult = $stmt->fetch(PDO::FETCH_ASSOC); | ||
|
||
if ($domainResult) { | ||
$domainName = $domain; | ||
$clientId = $domainResult['client_id']; | ||
$userId = $domainResult['userid']; | ||
|
||
// Prepare the current date and time in the required format | ||
// Insert ticket in WHMCS tbltickets table | ||
$currentDateTime = date('Y-m-d H:i:s'); | ||
|
||
// Insert into the support_ticket table | ||
$stmt = $dbh->prepare("INSERT INTO support_ticket (support_helpdesk_id, client_id, priority, subject, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)"); | ||
$stmt->execute([1, $clientId, 100, 'New URS case for ' . $domainName, 'on_hold', $currentDateTime, $currentDateTime]); | ||
|
||
// Get the last inserted ID from the support_ticket table | ||
$supportTicketId = $dbh->lastInsertId(); | ||
|
||
// Get the client IP address, default to '127.0.0.1' if not available | ||
$clientIp = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1'; | ||
|
||
// Insert into the support_ticket_message table using the last inserted ID | ||
$stmt = $dbh->prepare("INSERT INTO support_ticket_message (support_ticket_id, client_id, admin_id, content, attachment, ip, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); | ||
$stmt->execute([$supportTicketId, null, 1, 'New URS case for ' . $domainName . ' submitted by ' . $ursProvider . ' on ' . $date . '. Please act accordingly', null, $clientIp, $currentDateTime, $currentDateTime]); | ||
// Generate a unique TID (Ticket ID) similar to WHMCS format, e.g., "SCT-441641" | ||
$tid = 'SCT-' . str_pad(mt_rand(1, 999999), 6, '0', STR_PAD_LEFT); | ||
// Generate a unique alphanumeric code for `c` (Ticket Hash), e.g., "tH7B0ple" | ||
$c = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 8); | ||
|
||
$stmt = $dbh->prepare(" | ||
INSERT INTO tbltickets ( | ||
tid, userid, did, cc, c, title, message, status, urgency, date, lastreply, ipaddress, | ||
flag, name, email, contactid, requestor_id, admin, attachment, attachments_removed, merged_ticket_id, clientunread, replyingadmin, adminunread, replyingtime, service, editor, updated_at | ||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) | ||
"); | ||
|
||
// Execute with appropriate values for each field | ||
$stmt->execute([ | ||
$tid, // tid: Unique Ticket ID | ||
$userId, // userid: User associated with the domain | ||
$config['whmcs_department_id'], // did: Department ID | ||
'', // cc: empty | ||
$c, // c: Unique Ticket Hash | ||
'New URS case for ' . $domain, // title: Subject line of the ticket | ||
'New URS case for ' . $domain . ' submitted by ' . $provider . ' on ' . $date . '. Please review and act accordingly.', // message: Ticket content | ||
'Open', // status: Ticket status | ||
'Medium', // urgency: Priority level | ||
$currentDateTime, // date: Ticket creation date | ||
$currentDateTime, // lastreply: Date of last reply (set to creation date initially) | ||
'127.0.0.1', // ipaddress: Default IP address if not available | ||
0, // flag: 0 | ||
'Automated URS System', // name: Requestor’s name (can use a generic identifier for automated tickets) | ||
$config['email']['sender'], // email: Default email if not available | ||
0, // contactid: Set to 0 if no specific contact is associated | ||
0, // requestor_id: Default to 0 if not specified | ||
'', // admin: empty | ||
'', // attachment: empty | ||
0, // attachments_removed: Set to 0, assuming no attachments are initially removed | ||
0, // merged_ticket_id: Default to 0 if this ticket is standalone | ||
1, // clientunread: 1 | ||
0, // replyingadmin: 0 | ||
'', // adminunread: empty | ||
'0000-00-00 00:00:00', // replyingtime: 0 | ||
'', // service: empty | ||
'plain', // editor: Default to 'plain' for message formatting | ||
$currentDateTime // updated_at: Set to current date/time | ||
]); | ||
|
||
// Log insertion and retrieve last inserted ticket ID | ||
$ticketId = $dbh->lastInsertId(); | ||
error_log("Created support ticket ID $ticketId for domain $domain."); | ||
} else { | ||
error_log('Domain ' . $domainName . ' does not exists in registry'); | ||
error_log('Domain ' . $domain . ' does not exists in registry'); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters