Notification : ps

This commit is contained in:
VE10-Sanjeev 2024-04-10 10:34:25 +00:00
parent a797c3eb6f
commit 3e17f60ed8
5 changed files with 398 additions and 375 deletions

View File

@ -151,8 +151,9 @@ $routes->match(['get','post'],'/book_publishwise_Report','Invoice::book_publishw
$routes->get("getExpCustomerDetail/(:num)",'Notifications::getExpCustomerDetail/$1');
$routes->get('send_whatsapp_message/', 'Notifications::send_whatsapp_message');
$routes->post('whatsapp_custom_notifications/', 'Notifications::whatsapp_custom_notifications');
$routes->match(['post', 'get'], 'mail_custom_notifications', 'Notifications::mail_custom_notifications');
// $routes->post('whatsapp_custom_notifications/', 'Notifications::whatsapp_custom_notifications');
// $routes->match(['post', 'get'], 'mail_custom_notifications', 'Notifications::mail_custom_notifications');
$routes->match(['post', 'get'], 'custom_notifications', 'Notifications::custom_notifications');
$routes->get('due_date_notifications', 'Notifications::due_date_notifications');
$routes->get('template_creation/', 'Notifications::template_creation');
$routes->get('template_creation_form/(:any)', 'Notifications::template_creation_form/$1');

View File

@ -9,12 +9,12 @@ class Notifications extends BaseController
{
################################################################
# Custom Email Notification
# Custom Notification
################################################################
public function mail_custom_notifications()
{
public function custom_notifications(){
if ($this->request->is('post')) {
$records = $this->request->getVar();
if($records['mode'] == 'Email'){
helper('notification');
$notification = new NotificationHelper();
$data = $notification->sendEmail($records);
@ -42,23 +42,15 @@ class Notifications extends BaseController
'result'=>strtolower(gettype($history_msg)) == "string" ? $history_msg : json_encode($history_msg)];
$history_child_id = $NotificationModel->save_notification_history_child($history_child_data);
$this->logger->info('Custom Notifications Email : historychildid = '.$history_child_id);
}
$records = [];
$data['page_name'] = 'Custom Notifications';
$this->render_page('notifications_form', $data);
}
# mail custom notifications closed
################################################################
# Custom Whatsapp Notification
################################################################
public function whatsapp_custom_notifications()
{
if ($this->request->is('post')) {
}else{
$records = $this->request->getVar();
$params = (object) Null;
$parents_status = 0;
$receiving_status = 0;
$doc_details = $this->request->getFile('media_doc');
$doc_path = APPPATH . '../public/uploads/';
$doc_name = '';
$this->logger->info("Whatsapp : sending message instance id = " . $_ENV['WAAI_INSTANCE'] . " - " . $_ENV['WAAI_TOKEN']);
try {
if ($records['categories'] == 'SEND_WAAI_GROUP_URL') {
@ -75,6 +67,7 @@ class Notifications extends BaseController
} else if ($records['categories'] == 'SEND_WAAI_URL') {
if ($records['mobile'] != "") {
$params->number = (int)'91' . $records['mobile'];
} else {
throw new \Exception("Mobile Number Missing Please Try again..");
}
@ -84,13 +77,35 @@ class Notifications extends BaseController
if ($records['type'] == 'media') {
if ($records['media_url'] != "") {
$params->media_url = $records['media_url'];
$params->type = "media";
} else {
throw new \Exception("Media Url Missing Please Try again..");
}
}
else if ($records['type'] == 'document') {
$doc_name = $doc_details->getName();
if($doc_name == ''){
$this->logger->error("Err on upload name not Founded ".$records['media_doc']);
throw new \Exception("Media Document Missing Please Try again..");
}else{
if ($doc_details->isValid()) {
$doc_details->move($doc_path, $doc_name);
$this->logger->info("Name After Upload".$doc_name);
$params->filename = $doc_name;
$params->media_url = base_url().'public/uploads/'.$doc_name;
$params->type = "media";
}else{
$params->filename = $doc_name;
$params->media_url = base_url().'public/uploads/'.$doc_name;
$params->type = "media";
}
}
}else{
$params->type = "text" ;
}
$url = constant($records['categories']);
$params->type = $records['type'] == "" ? "text" : $records['type'];
$params->instance_id = $_ENV['WAAI_INSTANCE'];
$params->access_token = $_ENV['WAAI_TOKEN'];
$params->message = strip_tags(ltrim($records['description']));
@ -120,13 +135,13 @@ class Notifications extends BaseController
'message' => $records['description'],
'result'=>$history_msg];
$history_child_id = $NotificationModel->save_notification_history_child($history_child_data);
$this->logger->info('Custom Notifications Whatsapp : historychildid = '.$history_child_id);
}
}
$records = [];
$data['page_name'] = 'Custom Notifications';
$this->render_page('notifications_form', $data);
$this->logger->info('Custom Notifications Whatsapp : historychildid = '.$history_child_id);
}
# whatsapp custom notifications closed
public function due_date_notifications()
{

View File

@ -129,9 +129,7 @@ class NotificationHelper
if ($result->status === "success") {
$final_result['message'] = isset($result->message) ? (
(strtolower(gettype($result->message)) === 'string') ?
$result->message : "Sended Success"
) : " Message Not Sent. ";
(strtolower(gettype($result->message)) === 'string') ? $result->message : "Sent Success") : " Not Sent.";
$final_result['receiving_status'] = isset($result->message) ? ((strtolower(gettype($result->message)) === 'string') ? 0 : 1 ) : 0 ;
}
} else {

View File

@ -1,46 +1,19 @@
<style>
/* Show the form section by default */
#mailFormDiv { display: none; }
#whatsappFormDiv { display: none; }
img {
max-width: 20px; /* Adjust as needed */
max-height: 20px; /* Adjust as needed */
}
#mailSection { display: none; }
#whatsappSection { display: none; }
#buttonSection { display: none; }
</style>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col">
<input type="radio" name="notificationType" id="showMailLink" value="mail" >
<label for="mailRadio">
<img src="<?= base_url() . "public/assets/images/brands/gmail.png" ?>" alt="mail">
<span>Mail Custom Notification</span>
</label>
</div>
<div class="col">
<input type="radio" name="notificationType" id="showWhatsappLink" value="whatsapp">
<label for="whatsappRadio">
<img src="<?= base_url() . "public/assets/images/brands/whatsapp.png" ?>" alt="whatsapp">
<span>Whatsapp Custom Notification</span>
</label>
</div>
<!-- <div class="col">
<a class="dropdown-icon-item" href="<?= base_url()."send_whatsapp_message"; ?>">
<img src="<?= base_url() . "public/assets/images/brands/whatsapp.png" ?>" alt="whatsapp">
<span>Whatsapp Static Notification</span>
</a>
</div> -->
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="col-lg-6">
<h4 class="header-title"><?= $page_name; ?></h4>
</br>
</div>
</div>
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
<?php if (session()->getFlashdata('success')) : ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
@ -49,7 +22,7 @@
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php unset($_SESSION['success']);unset($_SESSION['error']); endif; ?>
<?php endif; ?>
<?php if (session()->getFlashdata('error')) : ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?= session('error') ?>
@ -57,69 +30,53 @@
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php unset($_SESSION['success']);unset($_SESSION['error']); endif; ?>
<?php
unset($_SESSION['success']);unset($_SESSION['error']);
endif; ?>
<div id="textDiv">
<span class="widget-simple text-center">
<div class="media-body align-self-center font-24 avatar-title">
<p style="color: #0a0a0a!important;" class="mt-0" style><?= "Please Choose Message Mode....."; ?></p>
</div>
</span>
</div>
<!-- <div id="textDiv">
<span class="widget-simple text-center">
<div class="media-body align-self-center font-24 avatar-title">
<?php if (isset($validationErrors)) { ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?= $validationErrors ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php } elseif (isset($successMessage)) { ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?= $successMessage ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php } ?>
<p style="color: #0a0a0a!important;" class="mt-0" style><?= "Please Choose Your Choice....."; ?></p>
</div>
</span>
</div> -->
<div id="mailFormDiv">
<form role="form" class="parsley-examples" method="POST" enctype="multipart/form-data" action="<?= base_url() . "mail_custom_notifications"; ?>" id="myForm1">
<?php endif; ?>
<?php endif; ?>
<br>
<form role="form" class="parsley-examples" method="POST" enctype="multipart/form-data" action="<?= base_url() . "custom_notifications"; ?>" id="notifyCustomForm">
<div class="form-group row">
<label for="recipient" class="col-4 col-form-label" >Recipient Email<span class="text-danger"> *</span></label>
<div class="col-7">
<label class="col-3 col-form-label" for="mode">Mode</label>
<div class="col-9">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="mode" value="Email" onchange="get_notify_mode(this.value);">
<span class="form-check-label">Mail</span>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="mode" value="Whatsapp" onchange="get_notify_mode(this.value);">
<span class="form-check-label">Whatsapp</span>
</div>
</div>
</div>
<span id="mailSection">
<div class="form-group row">
<label for="recipient" class="col-3 col-form-label" >Recipient Email<span class="text-danger"> *</span></label>
<div class="col-9">
<input type="email" placeholder="Recipient Email" class="form-control" id="recipient" name="recipient_email" parsley-type="email" onkeyup="validateEmail(this.value)">
<span id="emailValidationMessage"></span>
</div>
</div>
<div class="form-group row">
<label for="CC" class="col-4 col-form-label">CC</label>
<div class="col-7">
<label for="CC" class="col-3 col-form-label">CC</label>
<div class="col-9">
<input type="text" placeholder="Enter multiple email addresses separated by commas" class="form-control" id="CC" name="carboncopy">
</div>
</div>
<div class="form-group row">
<label for="BCC" class="col-4 col-form-label">BCC</label>
<div class="col-7">
<label for="BCC" class="col-3 col-form-label">BCC</label>
<div class="col-9">
<input type="text" placeholder="Enter multiple email addresses separated by commas" class="form-control" id="BCC" name="blindcarboncopy">
</div>
</div>
<div class="form-group row">
<label for="subject" class="col-4 col-form-label">Subject<span class="text-danger"> *</span></label>
<div class="col-7">
<label for="subject" class="col-3 col-form-label">Subject<span class="text-danger"> *</span></label>
<div class="col-9">
<input type="text" placeholder="Subject" class="form-control" id="subject" name="subject">
</div>
</div>
<div class="form-group row">
<label for="body" class="col-4 col-form-label">Body<span class="text-danger"> *</span></label>
<div class="col-7">
<label for="body" class="col-3 col-form-label">Body<span class="text-danger"> *</span></label>
<div class="col-9">
<textarea id="summernote-basic" name="description" class="form-control" rows="7">
<h5>Hello {USER_NAME}, </h5>
<p>We create simple, flat & responsive custom mail template.</p>
@ -127,18 +84,13 @@
</textarea>
</div>
</div>
<div class="form-group text-right m-b-0">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="submitBtn1">
Send
</button>
</div>
</form>
</div>
<div id="whatsappFormDiv">
<form role="form" class="parsley-examples" method="POST" enctype="multipart/form-data" action="<?= base_url() . "whatsapp_custom_notifications"; ?>" id="myForm2">
</span>
<span id="whatsappSection">
<!-- <div class="form-group row">
<label for="group_id" class="col-4 col-form-label">Categories</label>
<div class="col-7">
<label for="group_id" class="col-3 col-form-label">Categories</label>
<div class="col-9">
<select class="form-control" id="categories" name="categories">
<option value="">Choose your Category Type</option>
<option value="SEND_WAAI_URL">Individual</option>
@ -149,16 +101,16 @@
<input type="hidden" id="categories" name="categories" value="SEND_WAAI_URL" />
<div id="fields-for-groupid" style="display: none;">
<div class="form-group row">
<label for="group_id" class="col-4 col-form-label">Group Id</label>
<div class="col-7">
<label for="group_id" class="col-3 col-form-label">Group Id</label>
<div class="col-9">
<input type="text" placeholder="Group ID" class="form-control" id="group_id" name="group_id">
</div>
</div>
</div>
<div id="fields-for-mobile">
<div class="form-group row">
<label for="mobile" class="col-4 col-form-label">Mobile Number<span class="text-danger"> *</span></label>
<div class="col-7">
<label for="mobile" class="col-3 col-form-label">Mobile Number<span class="text-danger"> *</span></label>
<div class="col-9">
<!-- <input type="number" placeholder="Mobile Number" class="form-control" id="mobile" name="mobile"> -->
<!-- <input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number" data-toggle="input-mask" data-mask-format="0000000000" <input type="text" class="form-control" id="cmobile" name="cmobile" value="<?= isset($customer['mobile_no']) ? $customer['mobile_no'] : '' ?>" placeholder="Mobile Number (Enter only numbers)" required maxlength="10" onkeypress="return restriction(event)" /> -->
<!-- <input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number" data-toggle="input-mask" data-mask-format="0000000000"> -->
@ -168,108 +120,136 @@
</div>
</div>
</div>
<div class="form-group row">
<label class="col-4 col-form-label">Message Type</label>
<div class="col-7">
<label class="col-3 col-form-label">Message Type</label>
<div class="col-9">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="type" id="textType" value="text" checked>
<label class="form-check-label" for="textType">Text</label>
<input class="form-check-input" type="radio" name="type" value="text" onchange="change_fields(this.value);" checked>
<span class="form-check-label">Text</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="type" id="mediaType" value="media">
<label class="form-check-label" for="mediaType">Media</label>
<input class="form-check-input" type="radio" name="type" value="media" onchange="change_fields(this.value);">
<span class="form-check-label">Media URL</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="type" value="document" onchange="change_fields(this.value);">
<span class="form-check-label">Document File</label>
</div>
</div>
</div>
<div id="fields-for-mediaurl" style="display: none;">
<div class="form-group row">
<label for="media_url" class="col-4 col-form-label">Media Link</label>
<div class="col-7">
<label for="media_url" class="col-3 col-form-label">Media Link</label>
<div class="col-9">
<input type="text" placeholder="Media Link" class="form-control" id="media_url" name="media_url">
</div>
</div>
</div>
<div id="fields-for-doc" style="display: none;">
<div class="form-group row">
<label for="message" class="col-4 col-form-label">Message <span class="text-danger"> *</span></label>
<div class="col-7">
<label for="media_doc" class="col-3 col-form-label">Document</label>
<div class="col-9">
<input type="file" id="media_doc" name="media_doc" />
</div>
</div>
</div>
<div class="form-group row">
<label for="message" class="col-3 col-form-label">Message <span class="text-danger"> *</span></label>
<div class="col-9">
<textarea id="message" name="description" class="form-control" rows="5">Message text here</textarea>
</div>
</div>
</span>
<span id="buttonSection">
<div class="form-group text-right m-b-0 ">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="submitBtn2">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="submitBtn">
Send
</button>
</div>
</form>
</div>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div><!-- end col -->
</div><!-- end row -->
</span>
</form>
<div id="textDiv">
<span class="widget-simple text-center">
<div class="media-body align-self-center font-24 avatar-title">
<!-- <p style="color: #0a0a0a!important;" class="mt-0" style><?= "Please Choose Message Mode....."; ?></p> -->
</div>
</span>
</div>
</div>
</div>
</div>
</div>
<script>
const textDiv = document.getElementById('textDiv');
const mailSection = document.getElementById('mailSection');
const whatsappSection = document.getElementById('whatsappSection');
const buttonSection = document.getElementById('buttonSection');
const showMailLink = document.getElementById('showMailLink');
const mailFormDiv = document.getElementById('mailFormDiv');
const showWhatsappLink = document.getElementById('showWhatsappLink');
const whatsappFormDiv = document.getElementById('whatsappFormDiv');
// Add a click event listener to the link
showMailLink.addEventListener('click', function() {
// Toggle the display of the div
// mailFormDiv.style.display = (mailFormDiv.style.display === 'none') ? 'block' : 'none';
mailFormDiv.style.display = 'block';
whatsappFormDiv.style.display = 'none';
function get_notify_mode(option) {
if (option == 'Email') {
mailSection.style.display = 'block';
whatsappSection.style.display = 'none';
textDiv.style.display = 'none';
const elements = document.getElementsByClassName("header-title");
for (let i = 0; i < elements.length; i++) {
elements[i].textContent = "Mail Custom Notification";
}
buttonSection.style.display = 'block';
document.getElementById("mobile").required = false;
document.getElementById("mobile").value = "";
document.getElementById("message").required = false;
document.getElementById("message").value="";
document.getElementById("recipient").required = true;
document.getElementById("subject").required = true;
document.getElementById("summernote-basic").required = true;
document.getElementById("mobile").required = false;
document.getElementById("message").required = false;
});
// Add a click event listener to the link
showWhatsappLink.addEventListener('click', function() {
// Toggle the display of the div
mailFormDiv.style.display = 'none';
} else {
whatsappSection.style.display = 'block';
mailSection.style.display = 'none';
textDiv.style.display = 'none';
// whatsappFormDiv.style.display = (whatsappFormDiv.style.display === 'none') ? 'block' : 'none';
whatsappFormDiv.style.display = 'block';
const elements = document.getElementsByClassName("header-title");
for (let i = 0; i < elements.length; i++) {
elements[i].textContent = "Whatsapp Custom Notification";
}
buttonSection.style.display = 'block';
// whatsappSection.style.display = (whatsappSection.style.display === 'none') ? 'block' : 'none';
document.getElementById("recipient").required = false;
document.getElementById("subject").required = false;
document.getElementById("summernote-basic").required = false;
document.getElementById("mobile").required = true;
document.getElementById("message").required = true;
});
document.getElementById("summernote-basic").required = true;
// document.getElementById("summernote-basic").value = "Hello {USER_NAME}, \n" +
// " We create simple, flat & responsive custom mail template\n" +
// " Please, write text here!";
// makeFormEmpty();
}
}
// Get references to the dropdown and field divs
const radioTextType = document.getElementById("textType");
const radioMediaType = document.getElementById("mediaType");
const fieldsForMediaURL = document.getElementById("fields-for-mediaurl");
// Add change event listeners to the radio buttons
radioTextType.addEventListener("change", function () {
// If "Text" is selected, hide the media URL field
const fieldsForDoc = document.getElementById("fields-for-doc");
function change_fields(option) {
if (option == 'document'){
fieldsForDoc.style.display = "block";
fieldsForMediaURL.style.display = "none";
document.getElementById("media_url").value = "";
});
radioMediaType.addEventListener("change", function () {
// If "Media" is selected, show the media URL field
}
if (option == 'media') {
fieldsForDoc.style.display = "none";
fieldsForMediaURL.style.display = "block";
});
document.getElementById("media_doc").value = "";
}
if (option == 'text') {
fieldsForDoc.style.display = "none";
fieldsForMediaURL.style.display = "none";
document.getElementById("media_url").value = "";
document.getElementById("media_doc").value = "";
}
}
const categories = document.getElementById("categories");
@ -298,45 +278,23 @@ radioMediaType.addEventListener("change", function () {
});
</script>
<script>
document.getElementById('myForm1').addEventListener('submit', function(event) {
var form = event.target;
// Get the rich text field element
var summernote = document.getElementById("summernote-basic");
if (form.checkValidity() === false) {
form.reportValidity(); // Display validation error messages
event.preventDefault(); // Prevent form submission if it's not valid
$('#submitBtn1').prop('disabled', false);
} else {
$('#submitBtn1').prop('disabled', true);
}
// Add an event listener for the input event
summernote.addEventListener("input", function() {
// This function will be called whenever the content of the rich text field changes
// You can perform your desired actions here
console.log("Content changed:", summernote.value);
// Call your onchange function here
yourOnChangeFunction();
});
document.getElementById('myForm2').addEventListener('submit', function(event) {
var form = event.target;
// Get the mobile input value
var mobileInput = document.getElementById('mobile');
var mobileValue = mobileInput.value;
// Check the validity of the mobile number
var isMobileValid = /^[0-9]{10}$/.test(mobileValue);
// alert(isMobileValid);
if (!isMobileValid) {
// alert(isMobileValid);
if (form.checkValidity() === false || !isMobileValid) {
// alert("if-if");
form.reportValidity(); // Display validation error messages
event.preventDefault(); // Prevent form submission if it's not valid
$('#submitBtn2').prop('disabled', false);
} else {
// alert("if-else");
$('#submitBtn2').prop('disabled', true);
// Define your onchange function
function yourOnChangeFunction() {
// Your logic here
console.log("Rich text field content changed!");
}
}else{
// alert("else");
$('#submitBtn2').prop('disabled', true);
}
});
</script>
<script>
function validateEmail(email) {
@ -356,6 +314,45 @@ radioMediaType.addEventListener("change", function () {
}
}
</script>
<script>
document.getElementById('notifyCustomForm').addEventListener('submit', function(event) {
var form = event.target;
var mode = document.getElementById('mode').value;
if(mode == 'Email'){
if (form.checkValidity() === false) {
form.reportValidity(); // Display validation error messages
event.preventDefault(); // Prevent form submission if it's not valid
$('#submitBtn').prop('disabled', false);
} else {
$('#submitBtn').prop('disabled', true);
}
}else{
// Get the mobile input value
var mobileInput = document.getElementById('mobile');
var mobileValue = mobileInput.value;
// Check the validity of the mobile number
var isMobileValid = /^[0-9]{10}$/.test(mobileValue);
// alert(isMobileValid);
if (!isMobileValid) {
// alert(isMobileValid);
if (form.checkValidity() === false || !isMobileValid) {
// alert("if-if");
form.reportValidity(); // Display validation error messages
event.preventDefault(); // Prevent form submission if it's not valid
$('#submitBtn').prop('disabled', false);
} else {
// alert("if-else");
$('#submitBtn').prop('disabled', true);
}
}else{
// alert("else");
$('#submitBtn').prop('disabled', true);
}
}
});
</script>
<script>
function restrictNonNumeric(event) {
var keyCode = event.which ? event.which : event.keyCode;
@ -381,3 +378,15 @@ radioMediaType.addEventListener("change", function () {
}
});
</script>
<script>
function makeFormEmpty() {
var form = document.getElementById('notifyCustomForm');
var inputs = form.querySelectorAll('input, textarea'); // Include textarea fields as well
inputs.forEach(function(input) {
input.value = ''; // Clear the value of each input field
});
return true; // Form is now empty
}
</script>

View File

@ -262,7 +262,7 @@
<a href="<?= base_url()."acknowlegdement"; ?>">Campaign Status</a>
</li>
<li>
<a href="<?= base_url()."mail_custom_notifications"; ?>">Ad-hoc Messages</a>
<a href="<?= base_url()."custom_notifications"; ?>">Ad-hoc Messages</a>
</li>
</ul>
</div>