diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a422ed1..aafa66c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -6,6 +6,8 @@ use CodeIgniter\Router\RouteCollection; * @var RouteCollection $routes */ + $routes->post('/check_mail_config','BusinessController::check_mail_config'); + $routes->get('/set_business_in_session/(:num)','StaffController::set_business_in_session/$1'); // $routes->get('/home','Home::index'); diff --git a/app/Controllers/BusinessController.php b/app/Controllers/BusinessController.php index f9114d6..1568721 100644 --- a/app/Controllers/BusinessController.php +++ b/app/Controllers/BusinessController.php @@ -5,6 +5,7 @@ namespace App\Controllers; use App\Models\BusinessModel; use App\Models\BranchModel; use App\Models\StaffModel; +use App\Helpers\MailHelper; use CodeIgniter\API\ResponseTrait; @@ -168,4 +169,17 @@ class BusinessController extends BaseController return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500); } } + + public function check_mail_config() + { + try { + $mail_config = $this->request->getPost(); + $r_mail = $this->request->getPost('r_email'); + $MailHelper = new MailHelper(); + print_r($MailHelper->check_mail_config($r_mail, $mail_config));die; + + } catch (\Exception $exception) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500); + } + } } diff --git a/app/Controllers/StaffController.php b/app/Controllers/StaffController.php index e9efab6..cd18ec1 100644 --- a/app/Controllers/StaffController.php +++ b/app/Controllers/StaffController.php @@ -319,17 +319,22 @@ class StaffController extends BaseController echo true; }else{ - $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); - $business_list = []; - foreach (json_decode($staffdata->business_id) as $key => $value) { - $business = $this->BusinessModel->where('business_id', $value)->first(); - if ($business) { - $business_list[] = $business; + $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); + $business_list = []; + if($staffdata->role == 'Admin'){ + $business_list = $this->BusinessModel->findAll(); + }else{ + foreach (json_decode($staffdata->business_id) as $key => $value) { + $business = $this->BusinessModel->where('business_id', $value)->first(); + if ($business) { + $business_list[] = $business; + } + } } - } - echo view('layout/header', ['Data'=>$staffdata]); - echo view('staff_profile',['staff'=>$staffdata, 'business_list'=> $business_list]); - echo view('layout/footer'); + + echo view('layout/header', ['Data'=>$staffdata]); + echo view('staff_profile',['staff'=>$staffdata, 'business_list'=> $business_list]); + echo view('layout/footer'); } } public function change_staff_password($staff_id) diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 7f28a0a..26615aa 100644 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -96,5 +96,46 @@ class MailHelper // } } + + public static function check_mail_config($r_email, $mail_config = []) + { + $default_config = [ + 'protocol' => 'smtp', + 'SMTPHost' => 'mail.venbait.in', + 'SMTPUser' => 'bbone@venbait.in', + 'SMTPPass' => 'xk!L(N_-R#};', + 'SMTPPort' => 465, + 'mailType' => 'html', + 'sender_email' => 'bbone@venbait.in', + 'sender_name' => 'BB-Sign' + ]; + + // Merge default config with provided config + $config = array_merge($default_config, $mail_config); + $email = \Config\Services::email(); + + $email->initialize([ + 'protocol' => $config['protocol'], + 'SMTPHost' => $config['SMTPHost'], + 'SMTPUser' => $config['SMTPUser'], + 'SMTPPass' => $config['SMTPPass'], + 'SMTPPort' => (int)$config['SMTPPort'], + 'mailType' => $config['mailType'] + ]); + + $email->setFrom($config['sender_email'], "Sender Name"); + $email->setTo($r_email); + $email->setSubject("Test Mail Configuration"); + $email->setMessage("Test Mail Configuration"); + + if ($email->send()) { + return json_encode(['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $r_email]); + } else { + log_message('error', 'Email sending failed: ' . $email->printDebugger(['headers'])); + return ['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $r_email]; + } + } + + } ?> diff --git a/app/Views/business_form.php b/app/Views/business_form.php index 326e8b2..f85aaaa 100644 --- a/app/Views/business_form.php +++ b/app/Views/business_form.php @@ -54,7 +54,7 @@ -
Mail Settings
+
Mail Settings
@@ -76,16 +76,34 @@
- +
+ +
Test Mail
+
+
+ + +
+ +
+
+ + +
+
'> - '> - - - + '> + + + + + + +
@@ -148,65 +166,81 @@ $(document).ready(function() { }); - - -$("#savedata").on("click", function() -{ - - var headerContent = $('#summernote-header').summernote('code'); - var footerContent = $('#summernote-footer').summernote('code'); - formData ={ - business_id : $('#business_id').val(), - business_name : $('#business_name').val(), - header_html : headerContent, - footer_html : footerContent, - email : $('#email').val(), - smtp_host : $('#host').val(), - smtp_user : $('#user_name').val(), - smtp_pass : $('#password').val(), - smtp_port : $('#port').val(), - }; - - console.log(formData); - - - - $.ajax({ - url: '', - type: 'POST', - data: formData, - json: true, - success: function(response) { - - if(response.success){ - - toastr.success('Data saved successfully ', 'Success'); - window.location.href = ''; + $("#test-email-btn").on("click", function() + { + formData ={ + sender_email : $('#email').val(), + r_email : $('#r_email').val(), + smtp_host : $('#host').val(), + smtp_user : $('#user_name').val(), + smtp_pass : $('#password').val(), + smtp_port : $('#port').val(), + }; + // console.log(formData); + $.ajax({ + url: '', + type: 'POST', + data: formData, + json: true, + success: function(response) { - }else{ - toastr.warning('Something went wrong', 'Warning'); - } - - }, - error: function(xhr, status, error) { - // Handle errors here - console.error(xhr.responseText); - } + console.log(JSON.parse(response)); + if(JSON.parse(response).status == 'success'){ + $('#savedata').css('display',''); + $('#test-email-btn').css('display','none'); + toastr.success('Data saved successfully ', 'Success'); + // window.location.href = ''; + + }else{ + toastr.warning('Something went wrong', 'Warning'); + } + + }, + error: function(xhr, status, error) { + // Handle errors here + console.error(xhr.responseText); + } + }); + }) + + $("#savedata").on("click", function() + { + + var headerContent = $('#summernote-header').summernote('code'); + var footerContent = $('#summernote-footer').summernote('code'); + formData ={ + business_id : $('#business_id').val(), + business_name : $('#business_name').val(), + header_html : headerContent, + footer_html : footerContent, + email : $('#email').val(), + smtp_host : $('#host').val(), + smtp_user : $('#user_name').val(), + smtp_pass : $('#password').val(), + smtp_port : $('#port').val(), + }; + + $.ajax({ + url: '', + type: 'POST', + data: formData, + json: true, + success: function(response) { + if(response.success){ + toastr.success('Data saved successfully ', 'Success'); + window.location.href = ''; + }else{ + toastr.warning('Something went wrong', 'Warning'); + } + }, + error: function(xhr, status, error) { + // Handle errors here + console.error(xhr.responseText); + } + }); }); - - - -}); - - - - - - - - - + diff --git a/app/Views/client_docs_preview.php b/app/Views/client_docs_preview.php index 2f0264d..05efa92 100644 --- a/app/Views/client_docs_preview.php +++ b/app/Views/client_docs_preview.php @@ -242,11 +242,11 @@ $.getJSON('https://api.ipify.org?format=json', function(data) { var clientIp = data.ip; var formData ={ - otp : $('#otp').val(), - doc_id : $('#doc_id').val(), - is_approved: 1, - clientIp : clientIp - } + otp : $('#otp').val(), + doc_id : $('#doc_id').val(), + is_approved: 1, + clientIp : clientIp + } $.ajax({ type: 'POST', url: '',