diff --git a/README.md b/README.md index 495a451..b7013da 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Additionally, we extend our gratitude to: - **ChatGPT** for invaluable assistance with code and text writing. - [Slim Framework 4 Starter App](https://github.com/hezecom/slim-starter) which served as the foundation for our control panel. - [Tabler](https://tabler.io/), whose elegant and intuitive interface design has greatly influenced the user experience of Namingo. +- [leemunroe/responsive-html-email-template](https://github.com/leemunroe/responsive-html-email-template), for providing a great email template for our mailing system. ## Licensing diff --git a/automation/registrar.php b/automation/registrar.php index 4a7957c..ccb2146 100644 --- a/automation/registrar.php +++ b/automation/registrar.php @@ -43,6 +43,15 @@ if ($row) { $registryName = 'Example Registry LLC'; } +$stmt = $pdo->prepare("SELECT value FROM settings WHERE name = :name"); +$stmt->execute(['name' => 'currency']); +$row = $stmt->fetch(); +if ($row) { + $currency = $row['value']; +} else { + $currency = 'USD'; +} + // Define the query $sql = "SELECT id, clid, name, accountBalance, creditThreshold, creditLimit, email FROM registrar"; @@ -52,13 +61,13 @@ try { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { if ($row['accountBalance'] < $row['creditThreshold']) { // Case 1: accountBalance is less than creditThreshold - sendEmail($row, 'low_balance', $log, $supportEmail, $supportPhoneNumber, $registryName); + sendEmail($row, 'low_balance', $log, $supportEmail, $supportPhoneNumber, $registryName, $currency); } elseif ($row['accountBalance'] == 0) { // Case 2: accountBalance is 0 - sendEmail($row, 'zero_balance', $log, $supportEmail, $supportPhoneNumber, $registryName); + sendEmail($row, 'zero_balance', $log, $supportEmail, $supportPhoneNumber, $registryName, $currency); } elseif (($row['accountBalance'] + $row['creditLimit']) < 0) { // Case 3: accountBalance + creditLimit is less than 0 - sendEmail($row, 'over_limit', $log, $supportEmail, $supportPhoneNumber, $registryName); + sendEmail($row, 'over_limit', $log, $supportEmail, $supportPhoneNumber, $registryName, $currency); } } @@ -70,13 +79,13 @@ try { } // Function to send email -function sendEmail($data, $case, $log, $supportEmail, $supportPhoneNumber, $registryName) { +function sendEmail($data, $case, $log, $supportEmail, $supportPhoneNumber, $registryName, $currency) { $message = "Dear ".$data['name'].",\n\n"; switch ($case) { case 'low_balance': $subject = "Low balance alert for registrar: " . $data['clid']; - $message .= "We are writing to inform you that your account with us currently has a low balance. As of now, your account balance is {$data['accountBalance']}, which is below the minimum credit threshold of {$data['creditThreshold']}.\n\n"; + $message .= "We are writing to inform you that your account with us currently has a low balance. As of now, your account balance is $currency {$data['accountBalance']}, which is below the minimum credit threshold of $currency {$data['creditThreshold']}.\n\n"; break; case 'zero_balance': $subject = "Zero balance alert for registrar: " . $data['clid']; diff --git a/cp/app/Controllers/SupportController.php b/cp/app/Controllers/SupportController.php index 89f846f..13ff210 100644 --- a/cp/app/Controllers/SupportController.php +++ b/cp/app/Controllers/SupportController.php @@ -3,6 +3,7 @@ namespace App\Controllers; use App\Models\Tickets; +use App\Lib\Mail; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Container\ContainerInterface; @@ -65,6 +66,20 @@ class SupportController extends Controller $ticket_id = $db->getLastInsertId(); $db->commit(); + + $link = envi('APP_URL').'/ticket/'.$ticket_id; + $email = $db->selectValue('SELECT email FROM users WHERE id = ?', [$_SESSION['auth_user_id']]); + $registry = $db->selectValue('SELECT value FROM settings WHERE name = ?', ['company_name']); + $crdate = $currentDateTime->format('Y-m-d H:i:s.v'); + $message = file_get_contents(__DIR__.'/../../resources/views/mail/ticket.html'); + $placeholders = ['{registry}', '{link}', '{app_name}', '{app_url}', '{crdate}', '{ticket_id}', '{subject}']; + $replacements = [$registry, $link, envi('APP_NAME'), envi('APP_URL'), $crdate, $ticket_id, $subject]; + $message = str_replace($placeholders, $replacements, $message); + $mailsubject = '[' . envi('APP_NAME') . '] New Support Ticket Created'; + $from = ['email'=>envi('MAIL_FROM_ADDRESS'), 'name'=>envi('MAIL_FROM_NAME')]; + $to = ['email'=>$email, 'name'=>'']; + // send message + Mail::send($mailsubject, $message, $from, $to); } catch (Exception $e) { $db->rollBack(); return view($response, 'admin/support/newticket.twig', [ @@ -72,7 +87,7 @@ class SupportController extends Controller 'categories' => $categories ]); } - + $this->container->get('flash')->addMessage('success', 'Support ticket ' . $subject . ' has been created successfully!'); return $response->withHeader('Location', '/support')->withStatus(302); } @@ -158,6 +173,23 @@ class SupportController extends Controller ] ); + $link = envi('APP_URL').'/ticket/'.$ticket_id; + $email = $db->selectValue('SELECT email FROM users WHERE id = ?', [$_SESSION['auth_user_id']]); + $registry = $db->selectValue('SELECT value FROM settings WHERE name = ?', ['company_name']); + $responseBrief = mb_substr($responseText, 0, 100); + if (mb_strlen($responseText) > 100) { + $responseBrief .= "..."; + } + $message = file_get_contents(__DIR__.'/../../resources/views/mail/ticket-reply.html'); + $placeholders = ['{registry}', '{link}', '{app_name}', '{app_url}', '{latest}', '{ticket_id}']; + $replacements = [$registry, $link, envi('APP_NAME'), envi('APP_URL'), $responseBrief, $ticket_id]; + $message = str_replace($placeholders, $replacements, $message); + $mailsubject = '[' . envi('APP_NAME') . '] Update on Your Support Ticket'; + $from = ['email'=>envi('MAIL_FROM_ADDRESS'), 'name'=>envi('MAIL_FROM_NAME')]; + $to = ['email'=>$email, 'name'=>'']; + // send message + Mail::send($mailsubject, $message, $from, $to); + $this->container->get('flash')->addMessage('success', 'Reply has been created successfully on ' . $crdate); return $response->withHeader('Location', '/ticket/'.$ticket_id)->withStatus(302); } catch (Exception $e) { diff --git a/cp/resources/views/mail/ticket-reply.html b/cp/resources/views/mail/ticket-reply.html new file mode 100644 index 0000000..b677bfd --- /dev/null +++ b/cp/resources/views/mail/ticket-reply.html @@ -0,0 +1,332 @@ + + + + + + Update on Your Support Ticket + + + + + + + + + + + + \ No newline at end of file diff --git a/cp/resources/views/mail/ticket.html b/cp/resources/views/mail/ticket.html new file mode 100644 index 0000000..d60aff6 --- /dev/null +++ b/cp/resources/views/mail/ticket.html @@ -0,0 +1,331 @@ + + + + + + New Support Ticket Created + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/install.md b/docs/install.md index 9160bdd..80d740d 100644 --- a/docs/install.md +++ b/docs/install.md @@ -300,6 +300,22 @@ composer install This command will install the dependencies defined in your ```composer.json``` file, ensuring that your control panel has all the necessary components to operate effectively. +### Install Optional Dependencies: + +Execute one of the following commands to install the optional dependencies: + +```bash +composer require utopia-php/messaging +``` + +or + +```bash +composer require phpmailer/phpmailer +``` + +This command will install one of the packages which are essential for the mailing system of the control panel to function correctly. + ### Creating an Admin User: 1. Navigate to the 'bin' Directory: Change to the 'bin' subdirectory where the admin user creation script is located. (```create_admin_user.php```)