diff --git a/app/Config/Routes.php b/app/Config/Routes.php index edd66cb4..8b62d107 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -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'); diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index bf162f0e..9b441de7 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -9,58 +9,50 @@ 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(); - helper('notification'); - $notification = new NotificationHelper(); - $data = $notification->sendEmail($records); - $parents_status = 0; - $receiving_status = 0; - if (isset($data['error'])) { - session()->setFlashdata('error', 'Message: ' . $data['error']); - $history_msg = $data; - } - if (isset($data['success'])) { - session()->setFlashdata('success', 'Message: ' . $data['success']); - $parents_status = 1; - $receiving_status = 1; - $history_msg = 'Email sent successfully'; - } - $history_msg = (strtolower(gettype($history_msg)) == "string" ? $history_msg : json_encode($history_msg)) ; - $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['recipient_email'], - 'receiving_status' => $receiving_status, - 'message' => $records['description'], - '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')) { - $records = $this->request->getVar(); - $params = (object) Null; - $parents_status = 0; - $receiving_status = 0; - $this->logger->info("Whatsapp : sending message instance id = " . $_ENV['WAAI_INSTANCE'] . " - " . $_ENV['WAAI_TOKEN']); - try { + if($records['mode'] == 'Email'){ + helper('notification'); + $notification = new NotificationHelper(); + $data = $notification->sendEmail($records); + $parents_status = 0; + $receiving_status = 0; + if (isset($data['error'])) { + session()->setFlashdata('error', 'Message: ' . $data['error']); + $history_msg = $data; + } + if (isset($data['success'])) { + session()->setFlashdata('success', 'Message: ' . $data['success']); + $parents_status = 1; + $receiving_status = 1; + $history_msg = 'Email sent successfully'; + } + $history_msg = (strtolower(gettype($history_msg)) == "string" ? $history_msg : json_encode($history_msg)) ; + $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['recipient_email'], + 'receiving_status' => $receiving_status, + 'message' => $records['description'], + '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); + + }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') { if ($records['group_id'] != "") { $params->group_id = $records['group_id']; @@ -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,14 +135,14 @@ 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() { $date = $this->request->getGet('date'); diff --git a/app/Helpers/NotificationHelper.php b/app/Helpers/NotificationHelper.php index 9cecf2c1..6a4f8512 100644 --- a/app/Helpers/NotificationHelper.php +++ b/app/Helpers/NotificationHelper.php @@ -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 { diff --git a/app/Views/notifications_form.php b/app/Views/notifications_form.php index 349de733..4b2557b0 100644 --- a/app/Views/notifications_form.php +++ b/app/Views/notifications_form.php @@ -1,342 +1,300 @@ - -