change custom notification Comma seperator mobile number : ps
This commit is contained in:
parent
a81ddaf6b7
commit
c73b186e71
@ -13,6 +13,7 @@ class Notifications extends BaseController
|
||||
################################################################
|
||||
public function custom_notifications(){
|
||||
if ($this->request->is('post')) {
|
||||
session()->setFlashdata('reset', true);
|
||||
$records = $this->request->getVar();
|
||||
if($records['mode'] == 'Email'){
|
||||
helper('notification');
|
||||
@ -45,95 +46,135 @@ class Notifications extends BaseController
|
||||
|
||||
}else{
|
||||
$records = $this->request->getVar();
|
||||
$doc_details = $this->request->getFile('media_doc');
|
||||
$params = (object) Null;
|
||||
$parents_status = 0;
|
||||
$receiving_status = 0;
|
||||
$doc_details = $this->request->getFile('media_doc');
|
||||
$receiving_status = 0;
|
||||
$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') {
|
||||
if ($records['group_id'] != "") {
|
||||
$params->group_id = $records['group_id'];
|
||||
} else {
|
||||
throw new \Exception("Group Id Missing Please Try again..");
|
||||
}
|
||||
if ($records['mobile'] != "") {
|
||||
$params->number = (int)'91' . $records['mobile'];
|
||||
} else {
|
||||
throw new \Exception("Mobile Number Missing Please Try again..");
|
||||
}
|
||||
} 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..");
|
||||
}
|
||||
} else {
|
||||
throw new \Exception("Please Choose your Category");
|
||||
}
|
||||
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->media_url = base_url().'public/uploads/'.$doc_name;
|
||||
$params->type = "media";
|
||||
}else{
|
||||
$params->media_url = base_url().'public/uploads/'.$doc_name;
|
||||
$params->type = "media";
|
||||
if($records['mobile'] != ""){
|
||||
$string = $records['mobile'];
|
||||
$mobile_no_arr = explode(',', $string);
|
||||
$total_number_count = count($mobile_no_arr);
|
||||
$sended_number_count = 0;
|
||||
$not_sended_number_count = 0;
|
||||
if ($records['type'] == 'document') {
|
||||
$doc_name = $doc_details->getName();
|
||||
if($doc_name !== '' && $doc_details->isValid()) {
|
||||
$doc_details->move($doc_path, $doc_name);
|
||||
$this->logger->info("Name After Upload".$doc_name);
|
||||
}
|
||||
}
|
||||
$NotificationModel = new NotificationModel();
|
||||
$history_parents_data = ['campaign_id' => 0,'status' => 0];
|
||||
$history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data);
|
||||
// print_r($mobile_no_arr);
|
||||
if(!empty($mobile_no_arr)){
|
||||
try {
|
||||
foreach ($mobile_no_arr as $mobile) {
|
||||
// echo "----$mobile";
|
||||
if (trim(strlen($mobile)) == 10) {
|
||||
if (ctype_digit($mobile)) {
|
||||
// ------------ Step 1
|
||||
if ($records['categories'] == 'SEND_WAAI_GROUP_URL') {
|
||||
if ($records['group_id'] != "") {
|
||||
$params->group_id = $records['group_id'];
|
||||
} else {
|
||||
throw new \Exception("Group Id Missing Please Try again..");
|
||||
}
|
||||
} else if ($records['categories'] == 'SEND_WAAI_URL') {
|
||||
if ($records['mobile'] != "") {
|
||||
$params->number = (int)'91' . $mobile;
|
||||
|
||||
} else {
|
||||
throw new \Exception("Mobile Number Missing Please Try again..");
|
||||
}
|
||||
} else {
|
||||
throw new \Exception("Please Choose your Category");
|
||||
}
|
||||
// echo "***".$params->number;
|
||||
//---------Step 2
|
||||
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{
|
||||
$params->media_url = base_url().'public/uploads/'.$doc_name;
|
||||
$params->type = "media";
|
||||
}
|
||||
}else{
|
||||
$params->type = "text" ;
|
||||
}
|
||||
$url = constant($records['categories']);
|
||||
$params->instance_id = $_ENV['WAAI_INSTANCE'];
|
||||
$params->access_token = $_ENV['WAAI_TOKEN'];
|
||||
$params->message = strip_tags(ltrim($records['description']));
|
||||
$this->logger->info("Whatsapp : sending message request = " . json_encode($params));
|
||||
$this->logger->info("Whatsapp : sending message request type b4 = " . gettype($params));
|
||||
|
||||
helper('notification');
|
||||
$notification = new NotificationHelper();
|
||||
$success = $notification->sendWhatsAppMessage($url, "POST", $params);
|
||||
// echo "<pre>";print_r($success);echo "</pre>";
|
||||
$receiving_status = $success['receiving_status'];
|
||||
$parents_status = $success['receiving_status'];
|
||||
$this->logger->info("Whatsapp : Reponse ==> Mobile Number = ".$mobile." Message = ". json_encode($success['reponse']));
|
||||
$history_msg = strtolower(gettype($success)) == "string" ? $success : json_encode($success['reponse']);
|
||||
// $tag = (int)$receiving_status === 1 ? 'success' : 'error' ;
|
||||
// session()->setFlashdata($tag, 'Message : ' . $success['message']);
|
||||
$this->logger->info("Whatsapp : Reponse = " . $success['message']);
|
||||
(int)$receiving_status === 1 ? $sended_number_count++ : $not_sended_number_count++;
|
||||
}elseif (ctype_alpha($mobile)) {
|
||||
$history_msg = "Mobile Number = ".$mobile." is a character.";
|
||||
$this->logger->info("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$not_sended_number_count++;
|
||||
throw new \Exception($history_msg);
|
||||
}else {
|
||||
$history_msg = "Mobile Number = ".$mobile." is a combination of characters and numbers.";
|
||||
$this->logger->info("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$not_sended_number_count++;
|
||||
throw new \Exception($history_msg);
|
||||
|
||||
}
|
||||
}else {
|
||||
$history_msg = "Mobile Number = ".$mobile." does not have 10 digits.";
|
||||
$this->logger->info("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$not_sended_number_count++;
|
||||
throw new \Exception($history_msg);
|
||||
}
|
||||
$NotificationModel = new NotificationModel();
|
||||
$history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,0);
|
||||
$this->logger->info($history_parent_statement);
|
||||
$history_child_data = [ 'fkid' => $history_parent_id,
|
||||
'customer_id' => 0,
|
||||
'receiving_entity' => $mobile." (original : ".$records['mobile'].")",
|
||||
'receiving_status' => $receiving_status,
|
||||
'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);
|
||||
}
|
||||
session()->setFlashdata("success","Message : Sent Success (". $sended_number_count." / ".$total_number_count." )");
|
||||
$this->logger->info("Whatsapp : Final ==> ".$sended_number_count." Sended out of ".$total_number_count." ( Not sended numbers count ".$not_sended_number_count." ) ");
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Whatsapp : Exception Message = " . $e->getMessage() . "<br> File: " . $e->getFile() . "<br> Line: " . $e->getLine() . "<br>");
|
||||
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
|
||||
}
|
||||
}else{
|
||||
session()->setFlashdata('error', 'Message : Mobile Not Founded');
|
||||
}
|
||||
}else{
|
||||
$params->type = "text" ;
|
||||
session()->setFlashdata('error', 'Message : Mobile Field Empty');
|
||||
}
|
||||
|
||||
$url = constant($records['categories']);
|
||||
$params->instance_id = $_ENV['WAAI_INSTANCE'];
|
||||
$params->access_token = $_ENV['WAAI_TOKEN'];
|
||||
$params->message = strip_tags(ltrim($records['description']));
|
||||
$this->logger->info("Whatsapp : sending message request = " . json_encode($params));
|
||||
$this->logger->info("Whatsapp : sending message request type b4 = " . gettype($params));
|
||||
helper('notification');
|
||||
$notification = new NotificationHelper();
|
||||
$success = $notification->sendWhatsAppMessage($url, "POST", $params);
|
||||
$receiving_status = $success['receiving_status'];
|
||||
$parents_status = $success['receiving_status'];
|
||||
$history_msg = strtolower(gettype($success)) == "string" ? $success : json_encode($success['reponse']);
|
||||
$tag = (int)$receiving_status === 1 ? 'success' : 'error' ;
|
||||
session()->setFlashdata($tag, 'Message : ' . $success['message']);
|
||||
$this->logger->info("Whatsapp : Reponse = " . $success['message']);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Whatsapp : Exception Message = " . $e->getMessage() . "<br> File: " . $e->getFile() . "<br> Line: " . $e->getLine() . "<br>");
|
||||
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
|
||||
$history_msg = $e->getMessage();
|
||||
}
|
||||
$NotificationModel = new NotificationModel();
|
||||
$history_parents_data = ['campaign_id' => 0,'status' => $parents_status];
|
||||
$history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data);
|
||||
$history_child_data = [ 'fkid' => $history_parent_id,
|
||||
'customer_id' => 0,
|
||||
'receiving_entity' => $records['mobile'],
|
||||
'receiving_status' => $receiving_status,
|
||||
'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 = [];
|
||||
|
||||
@ -296,6 +296,17 @@ public function customerGroupQueryExecution($queries){
|
||||
return $query->get()->getResultArray();
|
||||
}
|
||||
|
||||
public function getAllCustomerMobileNumber(){
|
||||
|
||||
$arr = $this->select('mobile_no')
|
||||
->where('mobile_no IS NOT NULL')
|
||||
->where('mobile_no !=', '')
|
||||
->groupBy('mobile_no')
|
||||
->having('COUNT(*) >', 1)
|
||||
->findAll();
|
||||
return count($arr)>0 ? $arr : [];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php session()->setFlashdata('reset', true); endif; ?>
|
||||
<?php if (session()->getFlashdata('error')) : ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<?= session('error') ?>
|
||||
@ -30,11 +30,10 @@
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php session()->setFlashdata('reset', true); 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 class="col-3 col-form-label" for="mode">Mode</label>
|
||||
<div class="col-9">
|
||||
@ -109,15 +108,21 @@
|
||||
</div>
|
||||
<div id="fields-for-mobile">
|
||||
<div class="form-group row">
|
||||
<label for="mobile" class="col-3 col-form-label">Mobile Number<span class="text-danger"> *</span></label>
|
||||
<div class="col-9">
|
||||
<label for="mobile" class="col-3 col-form-label">Mobile Number<span class="text-danger symbol"> *</span></label>
|
||||
<div class="col-7">
|
||||
<!-- <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"> -->
|
||||
<!-- Modified input with validation -->
|
||||
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number" maxlength="10" onkeypress="return restrictNonNumeric(event)">
|
||||
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number" onkeypress="return restrictNonNumeric(event)">
|
||||
<span id="mobileValidationMessage"></span>
|
||||
</div>
|
||||
<div class="col-2" style="display: none;">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="all_customers" name="all_customers">
|
||||
<label class="form-check-label" for="all_customers">All Customers</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -136,7 +141,7 @@
|
||||
</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>
|
||||
<span class="form-check-label">Upload Image</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -229,6 +234,31 @@
|
||||
// makeFormEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const checkbox = document.getElementById("all_customers");
|
||||
|
||||
|
||||
// When the checkbox is changed
|
||||
checkbox.addEventListener("change", function () {
|
||||
// Get the mobile input element
|
||||
const mobileInput = document.getElementById("mobile");
|
||||
document.getElementById('mobileValidationMessage').textContent = "";
|
||||
// If the checkbox is checked
|
||||
if (this.checked) {
|
||||
// Set mobile input field to readonly and clear its value
|
||||
mobileInput.readOnly = true;
|
||||
mobileInput.value = "";
|
||||
// Make the mobile input field not required
|
||||
mobileInput.removeAttribute("required");
|
||||
} else {
|
||||
// If the checkbox is not checked, remove readonly attribute
|
||||
mobileInput.readOnly = false;
|
||||
// Make the mobile input field required
|
||||
mobileInput.setAttribute("required", "required");
|
||||
}
|
||||
});
|
||||
|
||||
// Get references to the dropdown and field divs
|
||||
const fieldsForMediaURL = document.getElementById("fields-for-mediaurl");
|
||||
const fieldsForDoc = document.getElementById("fields-for-doc");
|
||||
@ -356,7 +386,9 @@
|
||||
<script>
|
||||
function restrictNonNumeric(event) {
|
||||
var keyCode = event.which ? event.which : event.keyCode;
|
||||
var isValid = (keyCode >= 48 && keyCode <= 57) || keyCode === 8; // Allow numeric input and backspace
|
||||
var isValid = (keyCode >= 48 && keyCode <= 57) || // Numeric keys
|
||||
keyCode === 8 || // Backspace
|
||||
keyCode === 44; // Comma
|
||||
if (!isValid) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
@ -364,19 +396,19 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
document.getElementById('mobile').addEventListener('input', function() {
|
||||
var mobileNumber = this.value;
|
||||
var isValid = /^[0-9]{10}$/.test(mobileNumber);
|
||||
var validationMessage = document.getElementById('mobileValidationMessage');
|
||||
// document.getElementById('mobile').addEventListener('input', function() {
|
||||
// var mobileNumber = this.value;
|
||||
// var isValid = /^[0-9]{10}$/.test(mobileNumber);
|
||||
// var validationMessage = document.getElementById('mobileValidationMessage');
|
||||
|
||||
if (isValid) {
|
||||
validationMessage.textContent = 'Valid mobile number';
|
||||
validationMessage.style.color = "green";
|
||||
} else {
|
||||
validationMessage.textContent = 'Invalid mobile number';
|
||||
validationMessage.style.color = "red";
|
||||
}
|
||||
});
|
||||
// if (isValid) {
|
||||
// validationMessage.textContent = 'Valid mobile number';
|
||||
// validationMessage.style.color = "green";
|
||||
// } else {
|
||||
// validationMessage.textContent = 'Invalid mobile number';
|
||||
// validationMessage.style.color = "red";
|
||||
// }
|
||||
// });
|
||||
</script>
|
||||
<script>
|
||||
function makeFormEmpty() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user