diff --git a/application/config/development/autoload.php b/application/config/development/autoload.php index 47a3ba2..367fa04 100644 --- a/application/config/development/autoload.php +++ b/application/config/development/autoload.php @@ -58,7 +58,7 @@ | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('email'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url'); +$autoload['helper'] = array('url', 'mail'); /* | ------------------------------------------------------------------- diff --git a/application/config/production/autoload.php b/application/config/production/autoload.php index 47a3ba2..367fa04 100644 --- a/application/config/production/autoload.php +++ b/application/config/production/autoload.php @@ -58,7 +58,7 @@ | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('email'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url'); +$autoload['helper'] = array('url', 'mail'); /* | ------------------------------------------------------------------- diff --git a/application/config/testing/autoload.php b/application/config/testing/autoload.php index 1eac0b5..6cafc14 100644 --- a/application/config/testing/autoload.php +++ b/application/config/testing/autoload.php @@ -58,7 +58,7 @@ | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array('session','database'); +$autoload['libraries'] = array('session','database','email'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url','custom'); +$autoload['helper'] = array('url','custom','mail', 'data'); /* | ------------------------------------------------------------------- diff --git a/application/config/testing/config.php b/application/config/testing/config.php index faf2337..1f213ef 100644 --- a/application/config/testing/config.php +++ b/application/config/testing/config.php @@ -102,7 +102,7 @@ | setting this variable to TRUE (boolean). See the user guide for details. | */ -$config['enable_hooks'] = FALSE; +$config['enable_hooks'] = TRUE; /* |-------------------------------------------------------------------------- diff --git a/application/config/testing/hooks.php b/application/config/testing/hooks.php index a8f38a5..9e912d6 100644 --- a/application/config/testing/hooks.php +++ b/application/config/testing/hooks.php @@ -11,3 +11,11 @@ | https://codeigniter.com/user_guide/general/hooks.html | */ + +$hook['pre_controller'] = array( + 'class' => 'MyHooks', + 'function' => 'initialize', + 'filename' => 'MyHooks.php', + 'filepath' => 'hooks', +); + diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 4ee740f..2047308 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -50,6 +50,7 @@ public function __construct() ### Syntax : $this->load->module('module_name', $params, $object_name); $this->load->module('Layout'); $this->load->module('Audit'); + $this->load->module('Notification'); } } diff --git a/application/helpers/custom_helper.php b/application/helpers/custom_helper.php index 76bda5f..0489ec8 100644 --- a/application/helpers/custom_helper.php +++ b/application/helpers/custom_helper.php @@ -78,6 +78,22 @@ function user() } } + if (!function_exists('business')) + { + function business() + { + $ci =& get_instance(); + $business = $ci->auth_model->get_logged_business(user()->business_id); + if (empty($business)) + { + $ci->auth_model->logout(); + } else { + return $business; + } + + } + } + if (!function_exists('employee')) { function employee() diff --git a/application/helpers/data_helper.php b/application/helpers/data_helper.php new file mode 100644 index 0000000..b3ac23c --- /dev/null +++ b/application/helpers/data_helper.php @@ -0,0 +1,58 @@ +Notification_model->get_leave_data_using_leave_id($id); +} + +} + +if (!function_exists('collectDelegationData')) { + + function collectDelegationData($id){ + + $ci =& get_instance(); + return $ci->Notification_model->get_delegation_data_using_delegation_id($id); + } + +} + +if (!function_exists('collectExpenceData')) { + + function collectExpenceData($id){ + + $ci =& get_instance(); + return $ci->Notification_model->get_expence_data_using_expence_id($id); + } + +} + + +if (!function_exists('getTempleteData')) { + + function getTempleteData($code, $type){ + + $ci =& get_instance(); + return $ci->Notification_model->get_template_data_using_code($code, $type); + } + +} + +if (!function_exists('replaceTemplateWithData')) { + + function replaceTemplateWithData($originalTemplate, $placeholders) { + $notificationContent = $originalTemplate; + foreach ($placeholders as $value) { + $notificationContent = str_replace($value['placeholder'], $value['strval'], $notificationContent); + } + return $notificationContent; + } + +} + + +?> \ No newline at end of file diff --git a/application/helpers/mail_helper.php b/application/helpers/mail_helper.php new file mode 100644 index 0000000..9cf17b4 --- /dev/null +++ b/application/helpers/mail_helper.php @@ -0,0 +1,156 @@ +sender_mail); + + + try { + $mailer = new PHPMailer(true); + log_message('info', 'phpmailer loaded'); + + $mailer->isSMTP(); + $mailer->CharSet = 'utf-8'; + $mailer->Host=business()->mail_hostname; + $mailer->SMTPSecure = business()->mail_security; + $mailer->SMTPAuth =true; + $mailer->SMTPDebug = 2; + $mailer->Username=business()->mail_username; + $mailer->Password=business()->mail_password; + $mailer->Port=business()->mail_port_no; + $mailer->setFrom(business()->sender_mail, $aliasName); + $mailer->addAddress($to); + + // Add CC recipients + if ($cc !== null) { + if (is_array($cc)) { + foreach ($cc as $ccRecipient) { + $mailer->addCC($ccRecipient); + } + } else { + $mailer->addCC($cc); + } + } + + // Add BCC recipients + if ($bcc !== null) { + if (is_array($bcc)) { + foreach ($bcc as $bccRecipient) { + $mailer->addBCC($bccRecipient); + } + } else { + $mailer->addBCC($bcc); + } + } + + $mailer->Subject=$subject; + $mailer->isHTML(true); + $mailer->Body=$body; + + $attachmentPath = '/path/to/your/attachment/' . $receipt; + + if (file_exists($attachmentPath)) { + $mailer->addAttachment($attachmentPath); + } + + $mailer->send(); + + return true; + log_message('info', 'success : mail sendsuccessfully'); + + } catch (Exception $e) { + + return 'Error: ' . $mailer->ErrorInfo; + log_message('info', 'Error : '.$mailer->ErrorInfo); + + } +} + + + +} + +if (!function_exists('send_emails_forgot_password')) { + + function send_emails_forgot_password($to, $subject, $body, $aliasName = '', $cc = null, $bcc = null, $receipt = null) + { + + log_message('info', 'send_mail_helper_loadded'); + log_message('info', 'Receiptent mail - '.$to.' - subject - '.$subject.' - body - '.$body); + log_message('info', 'Sender mail '.business()->sender_mail); + + + try { + $mailer = new PHPMailer(true); + log_message('info', 'phpmailer loaded'); + + $mailer->isSMTP(); + $mailer->CharSet = 'utf-8'; + $mailer->Host='smtp.sendgrid.net'; + $mailer->SMTPSecure = 'tls'; + $mailer->SMTPAuth =true; + $mailer->SMTPDebug = 2; + $mailer->Username='apikey'; + $mailer->Password='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'; + $mailer->Port='587'; + $mailer->setFrom('no-reply@tripapprovaltool.com'); + $mailer->addAddress($to); + + // Add CC recipients + if ($cc !== null) { + if (is_array($cc)) { + foreach ($cc as $ccRecipient) { + $mailer->addCC($ccRecipient); + } + } else { + $mailer->addCC($cc); + } + } + + // Add BCC recipients + if ($bcc !== null) { + if (is_array($bcc)) { + foreach ($bcc as $bccRecipient) { + $mailer->addBCC($bccRecipient); + } + } else { + $mailer->addBCC($bcc); + } + } + + $mailer->Subject=$subject; + $mailer->isHTML(true); + $mailer->Body=$body; + + $attachmentPath = '/path/to/your/attachment/' . $receipt; + + if (file_exists($attachmentPath)) { + $mailer->addAttachment($attachmentPath); + } + + $mailer->send(); + + return true; + log_message('info', 'success : mail sendsuccessfully'); + + } catch (Exception $e) { + + return 'Error: ' . $mailer->ErrorInfo; + log_message('info', 'Error : '.$mailer->ErrorInfo); + + } + } + + + + } + +?> \ No newline at end of file diff --git a/application/hooks/MyHooks.php b/application/hooks/MyHooks.php new file mode 100644 index 0000000..d9b080b --- /dev/null +++ b/application/hooks/MyHooks.php @@ -0,0 +1,15 @@ +load->database(); + $sql = "UPDATE `delegation` SET is_active = 0 WHERE to_date < CURDATE(); "; + $data = $CI->db->query($sql); + } + +} + diff --git a/application/modules/Auth/controllers/Auth.php b/application/modules/Auth/controllers/Auth.php index 46b2d1d..83b2558 100644 --- a/application/modules/Auth/controllers/Auth.php +++ b/application/modules/Auth/controllers/Auth.php @@ -166,6 +166,62 @@ public function sendMail(){ } } + public function sendOTP(){ + + $mail = $this->input->get('email'); + $otp = $this->input->get('otp'); + $where = 'email'; + $user = $this->auth_model->validateUserForOtp($mail, $where); + $id = $user->id; + $data['csrf_hash'] = $this->security->get_csrf_hash(); + $data['id'] = $id; + $data['email'] = $mail; + + + $body =` +
+ +Hello,
+Your One-Time Password (OTP) for verification is:
+This OTP is valid for a short period. Please do not share it with anyone.
+If you did not request this OTP, please ignore this email.
+Thank you!
+© 2023
+ +Time remaining: 90 seconds
+Time remaining: 90 seconds
Someone has contacted you!
+| Name | +
|---|
| Suseendhiran | +