diff --git a/Notifications.php b/Notifications.php deleted file mode 100644 index 72fc4225..00000000 --- a/Notifications.php +++ /dev/null @@ -1,1048 +0,0 @@ -request->is('post')) { - session()->setFlashdata('reset', true); - $records = $this->request->getVar(); - if($records['mode'] == 'Email'){ - helper('notification'); - $notification = new NotificationHelper(); - $records['description'] = $records['maildescription']; - $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->error('Custom Notifications Email : historychildid = '.$history_child_id); - - }else{ - $records = $this->request->getVar(); - $doc_details = $this->request->getFile('media_doc'); - $params = (object) Null; - $parents_status = 0; - $receiving_status = 0; - $doc_path = APPPATH . '../public/uploads/'; - $doc_name = ''; - $errorMessages = []; - $this->logger->error("Whatsapp : sending message instance id = " . $_ENV['WAAI_INSTANCE'] . " - " . $_ENV['WAAI_TOKEN']); - 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; - // Step 1 Categories Check - if ($records['categories'] == 'SEND_WAAI_GROUP_URL') { - if ($records['group_id'] != "") { - $params->group_id = $records['group_id']; - } else { - session()->setFlashdata('error', 'Group Id Missing Please Try again..'); - $data['page_name'] = 'Custom Notifications'; - $this->render_page('notifications_form', $data); - return; - } - }else if ($records['categories'] == 'SEND_WAAI_URL') { - if ($records['mobile'] == "") { - session()->setFlashdata('error', 'Mobile Number Missing Please Try again..'); - $data['page_name'] = 'Custom Notifications'; - $this->render_page('notifications_form', $data); - return; - } - } else { - session()->setFlashdata('error', 'Please Choose your Category..'); - $data['page_name'] = 'Custom Notifications'; - $this->render_page('notifications_form', $data); - return; - } - - // Step 2 Media Check, Document Also Convert into Media Here. - if ($records['type'] == 'media') { - if ($records['media_url'] != "") { - $params->media_url = $records['media_url']; - $params->type = "media"; - } else { - session()->setFlashdata('error', 'Media Url Missing Please Try again..'); - $data['page_name'] = 'Custom Notifications'; - $this->render_page('notifications_form', $data); - return; - } - }elseif ($records['type'] == 'document') { - $doc_details = $this->request->getFile('media_doc'); - $doc_path = APPPATH . '../public/uploads/'; - - if (empty($doc_details)) { - session()->setFlashdata('error', 'Please select a file to upload.'); - $data['page_name'] = 'Custom Notifications'; - $this->render_page('notifications_form', $data); - return; - } - - if (!$doc_details->isValid() || $doc_details->getClientMimeType() !== 'image/jpeg') { - session()->setFlashdata('error', 'Please upload a valid JPEG image.'); - $data['page_name'] = 'Custom Notifications'; - $this->render_page('notifications_form', $data); - return; - } - - $doc_name = $doc_details->getName(); - - if ($doc_name === '') { - $this->logger->error("Err on upload: name not found"); - session()->setFlashdata('error', 'Document name not found. Please try again.'); - $data['page_name'] = 'Custom Notifications'; - $this->render_page('notifications_form', $data); - return; - } - - $doc_details->move($doc_path, $doc_name); - $params->media_url = base_url() . 'public/uploads/' . $doc_name; - $params->type = "media"; - $this->logger->error("Name After Upload: " . $doc_name); - }else{ - $params->type = "text" ; - } - - $NotificationModel = new NotificationModel(); - $history_parents_data = ['campaign_id' => 0,'status' => 0,'field_value' =>$records['mobile']]; - $history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data); - // print_r($mobile_no_arr); - if(!empty($mobile_no_arr)){ - foreach ($mobile_no_arr as $mobile) { - // try { - $exceptionOccurred = false; - // echo "----$mobile"; - if (trim(strlen($mobile)) == 10) { - if (ctype_digit($mobile)) { - if ($mobile != "") { - $params->number = (int)'91' . $mobile; - $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->error("Whatsapp : Request Type ==> Mobile Number = ".$mobile." - " . gettype($params)); - helper('notification'); - $notification = new NotificationHelper(); - $success = $notification->sendWhatsAppMessage($url, "POST", $params); - // echo "
";print_r($success);echo ""; - $receiving_status = $success['receiving_status']; - $parents_status = $success['receiving_status']; - $this->logger->error("Whatsapp : Reponse ==> Mobile Number = ".$mobile." Waai Reponse = ". 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']); - (int)$receiving_status === 1 ? $sended_number_count++ : $not_sended_number_count++; - } else { - $receiving_status = 0; - $parents_status = 0; - $history_msg = "Mobile Number = ".$mobile." is invalid."; - $this->logger->error("Whatsapp : Reponse ==> ".$history_msg); - $not_sended_number_count++; - $errorMessages[] = $history_msg; - } - }elseif (ctype_alpha($mobile)) { - $receiving_status = 0; - $parents_status = 0; - $history_msg = "Mobile Number = ".$mobile." is a character."; - $this->logger->error("Whatsapp : Reponse ==> ".$history_msg); - $not_sended_number_count++; - $errorMessages[] = $history_msg; - - }else { - $receiving_status = 0; - $parents_status = 0; - $history_msg = "Mobile Number = ".$mobile." is a combination of characters and numbers."; - $this->logger->error("Whatsapp : Reponse ==> ".$history_msg); - $not_sended_number_count++; - $errorMessages[] = $history_msg; - - } - }else { - $history_msg = "Mobile Number = ".$mobile." does not have 10 digits."; - $this->logger->error("Whatsapp : Reponse ==> ".$history_msg); - $not_sended_number_count++; - $errorMessages[] = $history_msg; - } - $history_child_data = [ 'fkid' => $history_parent_id, - 'customer_id' => 0, - 'receiving_entity' => $mobile, - 'receiving_status' => $receiving_status, - 'message' => $records['description'], - 'result'=>$history_msg]; - $NotificationModel = new NotificationModel(); - $history_child_id = $NotificationModel->save_custom_notification_history_child($history_child_data); - $this->logger->error('Custom Notifications Whatsapp : historychildid = '.$history_child_id); - } - if (!empty($errorMessages)) { - $this->logger->error(implode("\n", $errorMessages)); - session()->setFlashdata('error', implode('
"; - // print_r($details); - // echo ""; - // die; - $records = []; - $recipient_name = ""; - $recipient_email = ""; - $recipient_mobile = ""; - $subscription_name = ""; - $business_name = ""; - $to_subscription = ""; - if (isset($details)) { - $this->logger->error("Notification : Duedate notification Request data type = " . gettype($details)); - } - helper('notification'); - $notification = new NotificationHelper(); - foreach ($details as $rec) { - $recipient_name = $rec['customer_name']; - $recipient_email = $rec['customer_email']; - $recipient_mobile = $rec['customer_mobile']; - // $recipient_email = "sanjeev.p@venbainfotech.com"; - // $recipient_mobile = 6369084112; - $business_name = $rec['business_name']; - $subscription_name = $rec['title']; - $to_subscription = $rec['to_subscription']; - } - $records['template_name'] = ''; - $records['recipient_name'] = $recipient_name; - $records['recipient_email'] = $recipient_email ? $recipient_email : "sanjeev.p@venbainfotech.com"; - $records['subject'] = $business_name . " - Due Date Reminder"; - $records['description'] = " - -
Hello " . $recipient_name . ",
-This is a reminder that the following subscription is due soon:
-Subscription Name:" . $subscription_name . "
-Due Date: " . $to_subscription . "
-Please make sure to complete this subscription on time.
-Thank you.
- - "; - - $template = "Hello " . $recipient_name . ",\r\r\n\nThis is a reminder that the following subscription is due soon:\r\n- Subscription Name: " . $subscription_name . "\r\n Due Date: " . $to_subscription . "\r\n\nPlease make sure to complete this subscription on time.\n Thank you."; - - $params = (object) Null; - $params->number = (int)'91' . $recipient_mobile; - $params->type = "text"; - $params->message = $template; - $params->instance_id = $_ENV['WAAI_INSTANCE']; - $params->access_token = $_ENV['WAAI_TOKEN']; - $this->logger->error("Notification : Duedate notification Email Request data = " . json_encode($records)); - - $email_result = $notification->sendEmail($records); - $this->logger->error("Notification : Duedate notification Email Response = " . json_encode($email_result)); - $this->logger->error("Notification : Duedate notification Whatsapp Request data = " . json_encode($params)); - $whatsapp_result = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params); - $this->logger->error("Notification : Duedate notification Whatsapp Response = " . json_encode($whatsapp_result)); - } - - public function template_creation() - { - $data['page_name'] = 'Template Details'; - $model = new NotificationModel(); - $data['template'] = $model->getTemplateDetails(); - $this->render_page('template_creation', $data); - // echo "templates";die; - } - - ################################################################## - # Template Creation Insertion/updation Process ReferWith : Sanjeev - ################################################################## - public function template_creation_form($id) - { - - $data['group_details'] = $this->get_group_details(); - $model = new NotificationModel(); - if ($id === '0') { - $this->logger->error("Template Creation: In Add Page"); - $data['page_name'] = 'Add Template'; - $data['template_id'] = (int)$id; - $data['template_details'] = []; - } elseif ($id !== '0') { - $this->logger->error("Template Creation: In Edit Page ID =" . $id); - $data['page_name'] = 'Edit Template'; - $model->setTable('templates'); - $where = ['template_id' => (int)$id]; - $result = $model->where($where)->findAll(); - $data['template_id'] = (int)$id; - $data['template_details'] = !empty($result[0]) ? $result[0] : []; - } - // print_r($data['template_details']);die(); - $this->render_page('template_creation_form', $data); - } - - ############################################################################## - # Template Creation Delection which means inactive Process ReferWith : Sanjeev - ############################################################################## - public function template_creation_delete($id) - { - try { - helper('session'); - $session_uid = get_logged_user_id(); - $model = new NotificationModel(); - $model->setTable('templates'); - $where = ['template_id' => (int)$id]; - $result = $model->where($where)->findAll(); - if ($result) { - $this->logger->error("Template: Going to Inactive ID = " . $id); - $data = ['isactive' => 0, 'updated_by' => $session_uid, 'template_id' => (int)$id]; - $statement = $model->saveDetails($data, 'template_id', 'templates'); // just updating Inactive status only. - if ($statement['success']) { - session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : ""); - $this->logger->error($statement['log']); - } else if ($statement['error']) { - session()->setFlashdata('error', $statement['error']); - $this->logger->error($statement['log']); - } else { - throw new \Exception("Template: Err Occur on data the Template Inactive"); - } - } - } catch (\Exception $e) { - $this->logger->error("Template: Err Occur = " . $e->getMessage() . " File = " . $e->getFile() . " Line = " . $e->getLine()); - session()->setFlashdata('error', 'Message: ' . $e->getMessage()); - } - return redirect()->route('template_creation'); - } - - - public function get_group_details() - { - $model = new NotificationModel(); - $model->setTable('customer_groups'); - // $details = $model->where('isactive',1)->orderBy('group_id', 'ASC')->findAll(); - $where = ['isactive' => 1, 'group_name != ' => 'EXPIRYDATE']; - $details = $model->where($where)->orderBy('group_id', 'ASC')->findAll(); - return $details; - } - - public function get_template_details() - { - $model = new NotificationModel(); - $model->setTable('templates'); - $details = $model - ->where(['templates.isactive' => 1]) - ->whereNotIn('templates.template_name',array('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP')) - ->orderBy('templates.template_id', 'ASC')->findAll(); - return $details; - } - - public function template_creation_insert() - { - $this->logger->error("Template: Inserting/Updating Details"); - try { - ## Declarions - helper('session'); - $model = new NotificationModel(); - $session_uid = get_logged_user_id(); - $id = $this->request->getPost('template_id'); - $subject = $this->request->getPost('subject') ? $this->request->getPost('subject') : NULL; - $isactive = $id != "" ? $this->request->getPost('isactive') : 'on'; - $templatemessage = ""; - if($this->request->getPost('mode') === "Email"){ - $templatemessage = $this->request->getPost('templatemessage'); - }else if($this->request->getPost('mode') === "Whatsapp"){ - $templatemessage = $this->request->getPost('whatsapptemplatemessage'); - } - - $data = [ - 'template_id' => $id, - 'template_name' => $this->request->getPost('templatename'), - 'subject' => $subject, - 'message' => $templatemessage, - 'mode' => $this->request->getPost('mode'), - 'isactive' => (($isactive == 'on') ? 1 : 0), - 'created_by' => $session_uid, - 'updated_by' => $session_uid - ]; - $statement = $model->saveDetails($data, 'template_id', 'templates'); - if ($statement['success']) { - session()->setFlashdata('success', $statement['success']); - $this->logger->error($statement['log']); - } else if ($statement['error']) { - session()->setFlashdata('error', $statement['error']); - $this->logger->error($statement['log']); - } else { - throw new \Exception("Template: Err Occur"); - } - } catch (\Exception $e) { - $this->logger->error("Template: Err Occur =" . $e->getMessage()); - session()->setFlashdata('error', 'Message: ' . $e->getMessage()); - } - return redirect()->route('template_creation'); - } - - public function campaign_creation() - { - $data['page_name'] = 'Campaign Details'; - $model = new NotificationModel(); - $data['campaign'] = $model->getCampaignDetails(); - $this->render_page('campaign_creation', $data); - // echo "templates";die; - } - - public function campaign_creation_form($id) - { - - $data['group_details'] = $this->get_group_details(); - $data['template_details'] = $this->get_template_details(); - $model = new NotificationModel(); - if ($id === '0') { - $this->logger->error("Campaign Creation: In Add Page"); - $data['page_name'] = 'Add Campaign'; - $data['campaign_details'] = []; - } elseif ($id !== '0') { - $this->logger->error("Campaign Creation: In Edit Page ID =" . $id); - $data['page_name'] = 'Edit Campaign'; - $model->setTable('notification_campaign'); - $where = ['campaign_id' => (int)$id]; - $result = $model->where($where)->findAll(); - if (!empty($result)) { - foreach ($result as $i => $item) { - $result[$i]['group_id'] = unserialize($item['group_id']); - } - } - $data['campaign_details'] = !empty($result[0]) ? $result[0] : []; - } - $this->render_page('campaign_creation_form', $data); - } - - public function campaign_creation_delete($id) - { - try { - helper('session'); - $session_uid = get_logged_user_id(); - $model = new NotificationModel(); - $model->setTable('notification_campaign'); - $where = ['campaign_id' => (int)$id]; - $result = $model->where($where)->findAll(); - if ($result) { - $this->logger->error("Campaign: Going to Inactive ID = " . $id); - $data = ['isactive' => 0, 'updated_by' => $session_uid, 'campaign_id' => (int)$id]; - $statement = $model->saveDetails($data, 'campaign_id', 'notification_campaign'); // just updating Inactive status only. - if ($statement['success']) { - session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : ""); - $this->logger->error($statement['log']); - } else if ($statement['error']) { - session()->setFlashdata('error', $statement['error']); - $this->logger->error($statement['log']); - } else { - throw new \Exception("Campaign: Err Occur on data the Template Inactive"); - } - } - } catch (\Exception $e) { - $this->logger->error("Campaign: Err Occur = " . $e->getMessage() . " File = " . $e->getFile() . " Line = " . $e->getLine()); - session()->setFlashdata('error', 'Message: ' . $e->getMessage()); - } - return redirect()->route('campaign_creation'); - } - - public function campaign_creation_insert() - { - $this->logger->error("Campaign: Inserting/Updating Details"); - try { - ## Declarions - helper('session'); - $model = new NotificationModel(); - $session_uid = get_logged_user_id(); - $id = $this->request->getPost('campaign_id'); - $request_data = $this->request->getPost(); - $isactive = $id == "" ? 1 : (isset($request_data['isactive']) && $request_data['isactive'] == 'on' ? 1 : 0); - - $data = [ - 'campaign_id' => $id, - 'campaign_name' => $this->request->getPost('campaign_name'), - 'template_id' => $this->request->getPost('template_id'), - // 'scheduled_date' => $this->request->getPost('scheduled_date'), - // 'scheduled_time' => $this->request->getPost('scheduled_time') != "" ? $this->request->getPost('scheduled_time') : NULL, - 'mode' => $this->request->getPost('mode'), - 'group_id' => serialize($this->request->getPost('group_id')), - 'isactive' => $isactive, - 'created_by' => $session_uid, - 'updated_by' => $session_uid - ]; - if ($id != "") { - // id has value means updation process. - $notify_mod = new NotificationModel(); - $notify_mod->setTable('notification_campaign'); - $where = ['campaign_id' => (int)$id]; - $isactive_check = $notify_mod->where($where)->select('isactive')->first(); - if ((int)$isactive_check['isactive'] === 0 && $isactive === 0) { - $statement['success'] = ''; - $statement['error'] = 'Notification Campaign already In-Active. can`t able to update.'; - $statement['log'] = "Notification Campaign: already inactive status.Can`t able to update, Notification Campaign Group ID = " . $id; - } else { - $statement = $model->saveDetails($data, 'campaign_id', 'notification_campaign'); - } - } else { - // id has no value means insertion process. - $statement = $model->saveDetails($data, 'campaign_id', 'notification_campaign'); - } - - if ($statement['success']) { - $tid = $data['template_id']; - $cid = $data['campaign_id'] ? $data['campaign_id'] : $statement['insert_id']; - $this->scheduledNotifications($tid,$cid,1); - session()->setFlashdata('success', $statement['success']); - $this->logger->error($statement['log']); - } else if ($statement['error']) { - session()->setFlashdata('error', $statement['error']); - $this->logger->error($statement['log']); - } else { - throw new \Exception("Campaign: Err Occur"); - } - } catch (\Exception $e) { - $this->logger->error("Campaign: Err Occur =" . $e->getMessage()); - session()->setFlashdata('error', 'Message: ' . $e->getMessage()); - } - return redirect()->route('campaign_creation'); - } - - ################################################################ - # Expiry Notification ReferWith : Hema - ################################################################ - public function getExpCustomerDetail($window_time = null) - { - echo "Hi, "; - # Step 1: add the days to retrive the data// - $providedDate = date('Y-m-d'); - $newDate = date('Y-m-d', strtotime($providedDate . ' + ' . $window_time . ' days')); - $this->logger->error('EXPIRYDATE T-Date = '.$providedDate.', Given ' .$window_time.' Day, Calacuated Date based on Given day count = '.$newDate); - - # Step 2 :Get the customer detail// - $NotificationModel = new NotificationModel(); - $ExpCustomerDetail = $NotificationModel->getExpDate(); // Retrieve the stored query - - if (empty($ExpCustomerDetail)) { - $this->logger->error('No customer group found by the name of EXPIRYDATE'); - return; - } - - # Step 3: Replace the placeholder WINDOW_TIME with the user-provided value - $modifiedQuery = str_replace('WINDOW_TIME', $window_time, $ExpCustomerDetail); - // print_r($modifiedQuery);die; - if (empty($modifiedQuery)) { - $this->logger->error('There is no sub query'); - return; - } - $db = \Config\Database::connect(); - $queryResult = $db->query($modifiedQuery)->getResultArray(); - - $notification = new NotificationHelper(); - if (empty($queryResult)) { - $this->logger->error("There is no customer expiring on date:{$newDate}"); - echo " There is no customer expiring. till dated :{$newDate}"; - return; - } - - $emailTemplateName = $NotificationModel->getTempName(EXPIRAY_NOTIFY_TEMPLATE_EMAIL); - echo "Started.