CHANGE_BUSINESS_MAIL_CONFIG_TEST : AADHAVAN
This commit is contained in:
parent
6798357556
commit
2fb8c3fd78
@ -6,6 +6,8 @@ use CodeIgniter\Router\RouteCollection;
|
|||||||
* @var RouteCollection $routes
|
* @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('/set_business_in_session/(:num)','StaffController::set_business_in_session/$1');
|
||||||
|
|
||||||
// $routes->get('/home','Home::index');
|
// $routes->get('/home','Home::index');
|
||||||
|
|||||||
@ -5,6 +5,7 @@ namespace App\Controllers;
|
|||||||
use App\Models\BusinessModel;
|
use App\Models\BusinessModel;
|
||||||
use App\Models\BranchModel;
|
use App\Models\BranchModel;
|
||||||
use App\Models\StaffModel;
|
use App\Models\StaffModel;
|
||||||
|
use App\Helpers\MailHelper;
|
||||||
|
|
||||||
use CodeIgniter\API\ResponseTrait;
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
|
||||||
@ -168,4 +169,17 @@ class BusinessController extends BaseController
|
|||||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -321,12 +321,17 @@ class StaffController extends BaseController
|
|||||||
}else{
|
}else{
|
||||||
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
|
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
|
||||||
$business_list = [];
|
$business_list = [];
|
||||||
|
if($staffdata->role == 'Admin'){
|
||||||
|
$business_list = $this->BusinessModel->findAll();
|
||||||
|
}else{
|
||||||
foreach (json_decode($staffdata->business_id) as $key => $value) {
|
foreach (json_decode($staffdata->business_id) as $key => $value) {
|
||||||
$business = $this->BusinessModel->where('business_id', $value)->first();
|
$business = $this->BusinessModel->where('business_id', $value)->first();
|
||||||
if ($business) {
|
if ($business) {
|
||||||
$business_list[] = $business;
|
$business_list[] = $business;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo view('layout/header', ['Data'=>$staffdata]);
|
echo view('layout/header', ['Data'=>$staffdata]);
|
||||||
echo view('staff_profile',['staff'=>$staffdata, 'business_list'=> $business_list]);
|
echo view('staff_profile',['staff'=>$staffdata, 'business_list'=> $business_list]);
|
||||||
echo view('layout/footer');
|
echo view('layout/footer');
|
||||||
|
|||||||
@ -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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -54,7 +54,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-bell mr-1"></i> Mail Settings</h5>
|
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-envelope mr-1"></i> Mail Settings</h5>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="subject-input">Email</label>
|
<label for="subject-input">Email</label>
|
||||||
@ -76,15 +76,33 @@
|
|||||||
<label for="subject-input">Port</label>
|
<label for="subject-input">Port</label>
|
||||||
<input type="text" id="port" class="form-control" value="<?= isset($business['smtp_port']) ? $business['smtp_port'] : '' ?>">
|
<input type="text" id="port" class="form-control" value="<?= isset($business['smtp_port']) ? $business['smtp_port'] : '' ?>">
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php if(!isset($business['business_id'])){ ?>
|
||||||
|
<h5 class="mb-3 text-uppercase bg-light p-2 client_notification_area"><i class="fas fa-bell mr-1"></i>Test Mail</h5>
|
||||||
|
<div class="form-row" id="test_mail_config_div">
|
||||||
|
<div class="form-group col-md-6">
|
||||||
|
<label for="">Test Config Mail</label>
|
||||||
|
<input type="mail" class="form-control" id="r_email">
|
||||||
|
</div>
|
||||||
|
<?php }else{ ?>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group col-md-6">
|
||||||
|
<!-- <label for="">Test Config Mail</label> -->
|
||||||
|
<!-- <input type="mail" class="form-control" id="r_email"> -->
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<input type="hidden" id="business_id" name="business_id" value="<?= isset($business['business_id']) ? $business['business_id'] : '' ?>">
|
<input type="hidden" id="business_id" name="business_id" value="<?= isset($business['business_id']) ? $business['business_id'] : '' ?>">
|
||||||
<input type="hidden" id="header_html" value='<?= isset($business['business_id']) ? $business['header_html'] : '' ?>'>
|
<input type="hidden" id="header_html" value='<?= isset($business['business_id']) ? $business['header_html'] : '' ?>'>
|
||||||
<input type="hidden" id="footer_html" value='<?= isset($business['business_id']) ? $business['footer_html'] : '' ?>'>
|
<input type="hidden" id="footer_html" value='<?= isset($business['business_id']) ? $business['footer_html'] : '' ?>'>
|
||||||
|
<?php if(isset($business['business_id'])){?>
|
||||||
<button type="submit" id="savedata" class="btn btn-primary">Submit</button>
|
<button type="submit" id="savedata" class="btn btn-primary">Submit</button>
|
||||||
|
<?php }else{ ?>
|
||||||
|
<button class="btn btn-primary" id="test-email-btn" type="button">Test Email</button>
|
||||||
|
<button type="submit" id="savedata" class="btn btn-primary" style="display:none;">Submit</button>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div> <!-- end card -->
|
</div> <!-- end card -->
|
||||||
@ -148,7 +166,42 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#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: '<?= base_url()."check_mail_config"; ?>',
|
||||||
|
type: 'POST',
|
||||||
|
data: formData,
|
||||||
|
json: true,
|
||||||
|
success: function(response) {
|
||||||
|
|
||||||
|
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 = '<?= base_url()."business_list"; ?>';
|
||||||
|
|
||||||
|
}else{
|
||||||
|
toastr.warning('Something went wrong', 'Warning');
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
// Handle errors here
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
$("#savedata").on("click", function()
|
$("#savedata").on("click", function()
|
||||||
{
|
{
|
||||||
@ -167,46 +220,27 @@ $("#savedata").on("click", function()
|
|||||||
smtp_port : $('#port').val(),
|
smtp_port : $('#port').val(),
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(formData);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '<?= base_url()."add_business"; ?>',
|
url: '<?= base_url()."add_business"; ?>',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: formData,
|
data: formData,
|
||||||
json: true,
|
json: true,
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
|
||||||
if(response.success){
|
if(response.success){
|
||||||
|
|
||||||
toastr.success('Data saved successfully ', 'Success');
|
toastr.success('Data saved successfully ', 'Success');
|
||||||
window.location.href = '<?= base_url()."business_list"; ?>';
|
window.location.href = '<?= base_url()."business_list"; ?>';
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
toastr.warning('Something went wrong', 'Warning');
|
toastr.warning('Something went wrong', 'Warning');
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
// Handle errors here
|
// Handle errors here
|
||||||
console.error(xhr.responseText);
|
console.error(xhr.responseText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user