Current File : /home/giriqfky/public_html/Barga/application/modules/notifications/controllers//Notifications.php
<?php
class Notifications extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('Notifications_model', 'Notifications');
$this->load->library('Fcmpushnotifications');
$this->controller_name = "notifications";
$this->folder = "notifications";
$this->per_page = PER_PAGE;
if(!$this->session->userdata('is_login')) { redirect('sessions','refresh'); } //Checked is logined in or not
}
public function index()
{
redirect($this->controller_name.'/notificationList');
}
public function deleteNotification($notification_id)
{
if(checkModuleAccessByUser(userInfo('user_role_id'), 41, "module_delete") == 0){ redirect('errors/noPermission');} // Check user access permission
if($notification_id > 0) {
$this->db->where('notification_id', $notification_id);
$this->db->delete(TABLE_FIREBASE_NOTIFICATION_RESPONSE);
$this->db->where('notification_id', $notification_id);
$this->db->delete(TABLE_NOTIFICATIONS);
$this->session->set_flashdata('msg_success', getMessage("record_delete", 3));
redirect($this->controller_name.'/notificationList');
} else {
$this->session->set_flashdata('msg_warning', getMessage("invalid_request", 3));
redirect($this->controller_name.'/notificationList');
}
}
/*** Notification List start ***/
public function notificationList()
{
if(checkModuleAccessByUser(userInfo('user_role_id'), 41, "module_view") == 0){ redirect('errors/noPermission');} // Check user access permission
$data = array();
//calc offset number
$page = $this->input->post('page');
if(!$page) $offset = 0;
else $offset = $page;
$total_record = count($this->Notifications->getNotificationList());
//pagination configuration
$config['target'] = '#data_list';
$config['base_url'] = base_url().$this->controller_name.'/ajaxnotificationList';
$config['total_rows'] = $total_record;
$config['per_page'] = $this->per_page;
$config['link_func'] = 'searchFilter';
$this->ajax_pagination->initialize($config);
$data['notifications'] = $this->Notifications->getNotificationList(array('limit'=>$this->per_page));
$data['title'] = "Notifications";
$data['total_record'] = $total_record;
$data['sl_no'] = $page;
$data['notification_html'] = $this->load->view('ajax_notification_lists', $data, true);
//load the view
$this->template->admin('notification_lists', $data);
}
public function ajaxnotificationList()
{
$conditions = array();
//calc offset number
$page = $this->input->post('page');
if(!$page) $offset = 0;
else $offset = $page;
//set conditions for search
$notification_message = $this->input->post('notification_message');
$notification_alert_type = $this->input->post('notification_alert_type');
$app_user_type = $this->input->post('app_user_type');
$date_from = $this->input->post('date_from');
$date_to = $this->input->post('date_to');
if(!empty($notification_message)) {
$conditions['search']['notification_message'] = $notification_message;
}
if(!empty($notification_alert_type)) {
$conditions['search']['notification_alert_type'] = $notification_alert_type;
}
if(!empty($app_user_type)) {
$conditions['search']['app_user_type'] = $app_user_type;
}
if(!empty($date_from)) {
$conditions['search']['date_from'] = $date_from;
}
if(!empty($date_to)) {
$conditions['search']['date_to'] = $date_to;
}
//total rows count
$total_record = count($this->Notifications->getNotificationList($conditions));
//pagination configuration
$config['target'] = '#data_list';
$config['base_url'] = base_url().$this->controller_name.'/ajaxnotificationList';
$config['total_rows'] = $total_record;
$config['per_page'] = $this->per_page;
$config['link_func'] = 'searchFilter';
$this->ajax_pagination->initialize($config);
//set start and limit
$conditions['start'] = $offset;
$conditions['limit'] = $this->per_page;
//get posts data
$data['notifications'] = $this->Notifications->getNotificationList($conditions);
$data['title'] = "Notifications";
$data['total_record'] = $total_record;
$data['sl_no'] = $page;
//load the view
$notification_html = $this->load->view('ajax_notification_lists', $data, true);
echo $notification_html;exit;
}
/*** Notification list end ***/
public function sendNotification()
{
if(checkModuleAccessByUser(userInfo('user_role_id'), 28, "module_view") == 0){ redirect('errors/noPermission');} // Check user access permission
$data['title'] = "Send Notification";
$this->template->admin('send_notification', $data);
}
public function ajaxSendNotification()
{
if ($this->input->is_ajax_request()) {
if(checkModuleAccessByUser(userInfo('user_role_id'), 28, "module_view") == 0){ redirect('errors/noPermission');} // Check user access permission
$app_user_ids = $this->input->post('app_user_ids');
$notification_alert_type = $this->input->post('notification_alert_type');
$notify_message = trim($this->input->post('notify_message'));
$notify_type_push = $this->input->post('notify_type_push');
$notify_type_sms = $this->input->post('notify_type_sms');
$notify_type_email = $this->input->post('notify_type_email');
$notify_message_title = trim($this->input->post('notification_title'));
if(count($app_user_ids) == 0 || $notify_message == '' || $notify_message_title == '') {
$response_data = array('msg' => getMessage("required_fields", 3), 'status' => 0);
} else {
/*** upload customer profile photo start ***/
if (isset($_FILES['push_image']) && ($_FILES['push_image']['name']) != '') {
$file_data = uploadFileCustom(IMG_PUSH_NOTIFY_PATH,"push_image",array("jpeg", "jpg", "png"), "push_notify_img");
if($file_data['upload_status'] == 1 && $file_data['res_msg'] == 'Success') {
$push_notify_img = base_url()."uploads/push_notifications/".$file_data['new_file_name'];//!empty($file_data['new_file_name']) ? base_url(IMG_PUSH_NOTIFY_PATH_ABS.$file_data['new_file_name']) : "";
} else {
$push_notify_img = array('status' => 0, 'msg' => getMessage("file_type_not_allowed", 3));
}
} else {
$push_notify_img = "";
}
/*** upload customer profile photo end ***/
$app_user_emails = $this->Notifications->getAppUserEmails($app_user_ids);
$deviceArr_A = $this->Notifications->getDeviceToken('A',$app_user_ids);
//$deviceArr_I = $this->Notifications->getDeviceToken('I',$app_user_ids);
$module_id = 0;
if($notify_type_push == 1) {
$notification_ids = $this->Notifications->saveNotification($module_id, $app_user_ids, $notify_message, $notify_message_title, $push_notify_img, 1, $notification_alert_type);
if(count($deviceArr_A) > 0) {
$this->fcmpushnotifications->send($deviceArr_A, $notify_message, SITE_NAME, $push_notify_img, 'A', $notification_ids);
}
/*if(count($deviceArr_I) > 0) {
$this->fcmpushnotifications->send($deviceArr_I, $notify_message, SITE_NAME, $push_notify_img, 'I', $notification_ids);
}*/
}
if($notify_type_sms == 2) {
$mobile = "";
$mobile_nos = $this->Notifications->getMobileNumbers($app_user_ids);
if(SMS_ON == 1) {
if(count($mobile_nos) > 0){
$module_id = 0;
$push_notify_img = "";
foreach($mobile_nos as $m_no){ $mobile .= $m_no . ",";}
$mobile_no = trim($mobile,",");
sendSMS($mobile_no, $notify_message);
//$notification_ids = $this->Notifications->saveNotification($module_id, $app_user_ids, $notify_message, $notify_message_title, $push_notify_img, 2, $notification_alert_type);
}
}
}
if($notify_type_email == 3) {
$email = "";
if(EMAIL_ON == 1) {
$mail_subject = "";
$company_name = getSettingValue('company_name');
$admin_email = getSettingValue('company_email');
if($app_user_emails){
foreach($app_user_emails as $user_email){
$this->load->library('supertronmailer', array(
'to' => convertToLowerCase($user_email),
'subject' => $mail_subject,
'body' => $notify_message,
'name' => convertToLowerCase($user_email),
'from_name' => $user_profile_name,
'from_email' => $user_email
));
$this->supertronmailer->send();
}
}
}
}
$response_data = array('msg' => getMessage("push_send_success", 3), 'status' => 1);
}
} else {
$response_data = array('msg' => getMessage("no_direct_script_access", 3), 'status' => 0);
}
echo json_encode($response_data);exit;
}
public function ajaxSendNotificationAppUserList()
{
if ($this->input->is_ajax_request()) {
$app_user_ids = $this->input->post('mem_ids');
$app_user_ids = substr($app_user_ids, 0, -1);
$app_user_ids = explode(",", $app_user_ids);
$notification_alert_type = $this->input->post('notification_alert_type');
$notify_message = trim($this->input->post('notify_message'));
$notify_type_push = $this->input->post('notify_type_push');
$notify_type_email = $this->input->post('notify_type_email');
$notify_type_sms = $this->input->post('notify_type_sms');
$notify_message_title = trim($this->input->post('notification_title'));
if(count($app_user_ids) == 0 || $notify_message == '') {
$response_data = array('msg' => getMessage("required_fields", 3), 'status' => 0);
} else {
/*** upload push image photo upload start ***/
if (isset($_FILES['push_image']) && ($_FILES['push_image']['name']) != '') {
$file_data = uploadFileCustom(IMG_PUSH_NOTIFY_PATH,"push_image",array("jpeg", "jpg", "png"), "push_notify_img");
if($file_data['upload_status'] == 1 && $file_data['res_msg'] == 'Success') {
$push_notify_img = base_url()."uploads/push_notifications/".$file_data['new_file_name'];//!empty($file_data['new_file_name']) ? base_url(IMG_PUSH_NOTIFY_PATH_ABS.$file_data['new_file_name']) : "";
} else {
$push_notify_img = array('status' => 0, 'msg' => getMessage("file_type_not_allowed", 3));
}
} else {
$push_notify_img = "";
}
/*** upload push image photo upload end ***/
$app_user_emails = $this->Notifications->getAppUserEmails($app_user_ids);
$deviceArr_A = $this->Notifications->getDeviceToken('A',$app_user_ids);
//$deviceArr_I = $this->Notifications->getDeviceToken('I',$app_user_ids);
$module_id = 0;
if($notify_type_push == 1) {
$notification_ids = $this->Notifications->saveNotification($module_id, $app_user_ids, $notify_message, $notify_message_title, $push_notify_img, 1, $notification_alert_type);
if(count($deviceArr_A) > 0) {
$this->fcmpushnotifications->send($deviceArr_A, $notify_message, SITE_NAME, $push_notify_img, 'A', $notification_ids);
}
/*if(count($deviceArr_I) > 0) {
$this->fcmpushnotifications->send($deviceArr_I, $notify_message, SITE_NAME, $push_notify_img, 'I', $notification_ids);
}*/
}
if($notify_type_sms == 2) {
$mobile = "";
$mobile_nos = $this->Notifications->getMobileNumbers($app_user_ids);
if(SMS_ON == 1) {
if(count($mobile_nos) > 0){
$module_id = 0;
$push_notify_img = "";
foreach($mobile_nos as $m_no){ $mobile .= $m_no . ",";}
$mobile_no = trim($mobile,",");
sendSMS($mobile_no, $notify_message);
//$notification_ids = $this->Notifications->saveNotification($module_id, $app_user_ids, $notify_message, $notify_message_title, $push_notify_img, 2, $notification_alert_type);
}
}
}
if($notify_type_email == 3) {
$email = "";
if(EMAIL_ON == 1) {
$mail_subject = "";
if($member_emails){
foreach($member_emails as $member_email){
$this->load->library('supertronmailer', array('to' => convertToLowerCase($member_email), 'subject' => $mail_subject, 'body' => $notify_message, 'name' => convertToLowerCase($member_email)));
$this->supertronmailer->send();
}
}
}
}
$response_data = array('msg' => getMessage("push_send_success", 3), 'status' => 1);
}
} else {
$response_data = array('msg' => getMessage("no_direct_script_access", 3), 'status' => 0);
}
echo json_encode($response_data);exit;
}
public function ajaxGetAppUsers()
{
if ($this->input->is_ajax_request()) {
if(checkModuleAccessByUser(userInfo('user_role_id'), 28, "module_view") == 0){ redirect('errors/noPermission');} // Check user access permission
$app_user_type = $this->input->post('app_user_type');
$user_mobile = $this->input->post('user_mobile');
$user_profile_name = $this->input->post('user_profile_name');
$app_users = $this->Notifications->getAppUsers($app_user_type, $user_mobile, $user_profile_name);
$data['app_users'] = $app_users;
$customer_html = $this->load->view('ajax_member_list', $data, true);
$response_data = array('msg' => getMessage("success", 3), 'status' => 1, 'customers' => $customer_html);
} else {
$response_data = array('msg' => getMessage("no_direct_script_access", 3), 'status' => 0, 'customers' => '');
}
echo json_encode($response_data);exit;
}
}