Commit 73bb6b29 by Tobin

dc

parent 6ead949a
......@@ -73,61 +73,5 @@ class CMS extends CI_Controller {
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url($url));
}
public function notification() {
$template['page'] = 'CMS/notification';
$template['menu'] = "Notification Templates";
$template['smenu'] = "Change Notification Templates";
$template['pTitle'] = "Notification Templates";
$template['page_head'] = "Notification Templates";
$template['pDescription'] = "Change Notification Templates";
$template['notificationData'] = $this->Cms_model->getNotifData();
$this->load->view('template',$template);
}
public function changeNotifData(){
$url = 'CMS/notification';
$flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'error');
if(!isset($_POST) || empty($_POST)){
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url($url));
}
if(!isset($_POST['forgot_mail']) || empty($_POST['forgot_mail'])){
unset($_POST['forgot_mail']);
}
if(!isset($_POST['forgot_sms']) || empty($_POST['forgot_sms'])){
unset($_POST['forgot_sms']);
}
if(!isset($_POST['verify_mail']) || empty($_POST['verify_mail'])){
unset($_POST['verify_mail']);
}
if(!isset($_POST['staff_reg_mail']) || empty($_POST['staff_reg_mail'])){
unset($_POST['staff_reg_mail']);
}
if(!isset($_POST['registration_mail']) || empty($_POST['registration_mail'])){
unset($_POST['registration_mail']);
}
if(!isset($_POST['registration_mail']) || empty($_POST['registration_mail'])){
unset($_POST['registration_mail']);
}
if(!isset($_POST['checker_activation_mail']) || empty($_POST['checker_activation_mail'])){
unset($_POST['checker_activation_mail']);
}
if(!isset($_POST['provider_activation_mail']) || empty($_POST['provider_activation_mail'])){
unset($_POST['provider_activation_mail']);
}
$status = $this->Cms_model->updateNotif($_POST);
if($status){
$flashMsg['class'] = 'success';
$flashMsg['message'] = 'Settings Successfully Updated..!';
}
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url($url));
}
}
?>
\ No newline at end of file
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Notification extends CI_Controller {
public function __construct() {
parent::__construct();
date_default_timezone_set("Asia/Riyadh");
$this->load->model('Notification_model');
if(!$this->session->userdata('logged_in')) {
redirect(base_url('Login'));
}
if($this->session->userdata['user_type'] != 1){
$flashMsg = array('message'=>'Access Denied You don\'t have permission to access this Page',
'class'=>'error');
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url());
}
}
public function notification() {
$template['page'] = 'Notification/notification';
$template['menu'] = "Notification Templates";
$template['smenu'] = "Change Notification Templates";
$template['pTitle'] = "Notification Templates";
$template['page_head'] = "Notification Templates";
$template['pDescription'] = "Change Notification Templates";
$template['notificationData'] = $this->Notification_model->getNotifData();
$this->load->view('template',$template);
}
public function changeNotifData(){
$url = 'Notification/notification';
$flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'error');
if(!isset($_POST) || empty($_POST)){
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url($url));
}
if(!isset($_POST['forgot_mail']) || empty($_POST['forgot_mail'])){
unset($_POST['forgot_mail']);
}
if(!isset($_POST['forgot_sms']) || empty($_POST['forgot_sms'])){
unset($_POST['forgot_sms']);
}
if(!isset($_POST['verify_mail']) || empty($_POST['verify_mail'])){
unset($_POST['verify_mail']);
}
if(!isset($_POST['staff_reg_mail']) || empty($_POST['staff_reg_mail'])){
unset($_POST['staff_reg_mail']);
}
if(!isset($_POST['registration_mail']) || empty($_POST['registration_mail'])){
unset($_POST['registration_mail']);
}
if(!isset($_POST['registration_mail']) || empty($_POST['registration_mail'])){
unset($_POST['registration_mail']);
}
if(!isset($_POST['checker_activation_mail']) || empty($_POST['checker_activation_mail'])){
unset($_POST['checker_activation_mail']);
}
if(!isset($_POST['provider_activation_mail']) || empty($_POST['provider_activation_mail'])){
unset($_POST['provider_activation_mail']);
}
$status = $this->Notification_model->updateNotif($_POST);
if($status){
$flashMsg['class'] = 'success';
$flashMsg['message'] = 'Settings Successfully Updated..!';
}
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url($url));
}
public function pushNotification() {
$this->load->model('Event_model');
$this->load->model('Region_model');
$template['page'] = 'Notification/pushNotification';
$template['menu'] = "Push Notification";
$template['smenu'] = "Manage Push Notification";
$template['pTitle'] = "Push Notification";
$template['page_head'] = "Push Notification";
$template['pDescription'] = "Manage Push Notification";
$template['regionData'] = $this->Region_model->getRegionData('','1');
$template['event_data'] = $this->Event_model->getEventData('','1','');
$this->load->view('template',$template);
}
function sendPushNotif(){
$flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'error');
if(!isset($_POST) || empty($_POST) ||
!isset($_POST['event_id']) || empty($event_id = $_POST['event_id']) ||
!isset($_POST['tags']) || empty($cities = $_POST['tags'])){
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Notification/pushNotification'));
}
$this->load->model('Event_model');
$event_data = $this->Event_model->getEventData($event_id,'');
$cities = "'".implode("','",$cities)."'";
$users = $this->Notification_model->getCityUsers($cities,'1');
if(empty($users)){
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Notification/pushNotification'));
}
foreach($users AS $user){
$userData = array('id'=>$event_data->event_id,
'title'=>$event_data->event_name,
'message'=>'New Event in your City');
$this->push_sent_cancel('1',$user['fcm_token'],$userData);
}
$flashMsg['class'] = 'success';
$flashMsg['message'] = 'Push Send Successfully';
$this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Notification/pushNotification'));
}
function reminderPush(){
$date = date('Y-m-d',strtotime(date("Y-m-d H:i:s")." +30 minutes"));
$sTime = date('H:i',strtotime(date("Y-m-d H:i:s")." +30 minutes"));
$eTime = date("H:i",strtotime(date("Y-m-d H:i:s")." +31 minutes"));
$sql = "SELECT CUST.customer_id,CUST.fcm_token,BOK.id AS booking_id,BOK.bookId,EVT.event_name
FROM booking AS BOK
INNER JOIN customer AS CUST ON (CUST.customer_id=BOK.customer_id)
INNER JOIN users AS USR ON (USR.id=CUST.customer_id)
INNER JOIN events AS EVT ON (EVT.event_id=BOK.event_id)
INNER JOIN event_date_time AS EDATE ON (EDATE.event_id=BOK.event_id)
WHERE BOK.status='1' AND USR.status='1' AND EDATE.status='1' AND
EDATE.date='$date' AND EDATE.time<='$eTime' AND EDATE.time>='$sTime'
GROUP BY BOK.id,CUST.customer_id";
$sql = "SELECT CUST.customer_id,CUST.fcm_token,BOK.id AS booking_id,BOK.bookId,EVT.event_name FROM booking AS BOK INNER JOIN customer AS CUST ON (CUST.customer_id=BOK.customer_id) INNER JOIN users AS USR ON (USR.id=CUST.customer_id) INNER JOIN events AS EVT ON (EVT.event_id=BOK.event_id) INNER JOIN event_date_time AS EDATE ON (EDATE.event_id=BOK.event_id) WHERE BOK.status='1' AND USR.status='1' AND EDATE.status='1' AND EDATE.date='2019-04-29' AND EDATE.time<='09:45' AND EDATE.time>='09:44' GROUP BY BOK.id,CUST.customer_id";
$bookData = $this->db->query($sql)->result_array();
foreach($bookData AS $bData){
$userData = array('id'=>$bData['bookId'],
'title'=>$bData['event_name'],
'message'=>'Booking Remainder');
$this->push_sent_cancel('2',$bData['fcm_token'],$userData);
break;
}
}
function push_sent_cancel($type='1', $fcm_token='', $fcm_data=array()) {
$settings = getSettings();
$key = $settings['app_id'];
if(empty($key) || empty($fcm_token) || empty($fcm_data)){
return;
}
switch ($type) {
case '1':
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"default\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"event_id\" : \"".$fcm_data['id']."\", \"trip_status\" : 0}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
break;
case '2':
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"default\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"booking_id\" : \"".$fcm_data['id']."\", \"trip_status\" : 0}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
break;
}
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json', 'Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$out = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
}
?>
\ No newline at end of file
......@@ -20,22 +20,5 @@ class Cms_model extends CI_Model {
$status = $this->db->update('privacy_policy',$cmsData);
return $status;
}
public function getNotifData(){
$notifData = $this->db->query("SELECT * FROM notification_templates");
if(!empty($notifData)){
return $notifData->row();
}
return 0;
}
public function updateNotif($notifData = array()){
if(empty($notifData)){
return 0;
}
$status = $this->db->update('notification_templates',$notifData);
return $status;
}
}
?>
\ No newline at end of file
<?php
class Notification_model extends CI_Model {
public function _consruct(){
parent::_construct();
}
public function getNotifData(){
$notifData = $this->db->query("SELECT * FROM notification_templates");
if(!empty($notifData)){
return $notifData->row();
}
return 0;
}
public function updateNotif($notifData = array()){
if(empty($notifData)){
return 0;
}
$status = $this->db->update('notification_templates',$notifData);
return $status;
}
public function getCityUsers($cities='',$view=''){
if(empty($cities)){
return 0;
}
$cond = ($view != '')?" USR.status IN ($view)":" USR.status!='2'";
$cond .= ($cities != '')?" AND CUST.profile_city IN ($cities)":"";
$cityData = $this->db->query("SELECT CUST.* FROM customer AS CUST
INNER JOIN users AS USR ON (USR.id=CUST.customer_id)
WHERE ".$cond);
if(!empty($cityData)){
return $cityData->result_array();
}
return 0;
}
}
?>
\ No newline at end of file
......@@ -24,7 +24,7 @@
<div class="col-md-12">
<div class="box box-warning">
<div class="box-body">
<form role="form" action="<?= base_url('CMS/changeNotifData') ?>" method="post"
<form role="form" action="<?= base_url('Notification/changeNotifData') ?>" method="post"
class="validate" data-parsley-validate="" enctype="multipart/form-data">
<div class="box-header with-border">
<h3 class="box-title padLeft10 padTop5">Email Template</h3>
......
<div class="content-wrapper">
<section class="content-header">
<h1>
<?= $pTitle ?>
<small><?= $pDescription ?></small>
</h1>
<ol class="breadcrumb">
<li><a href="<?= base_url() ?>"><i class="fa fa-star-o" aria-hidden="true"></i>Home</a></li>
<li><?= $menu ?></li>
<li class="active"><?= $smenu ?></li>
</ol>
</section>
<section class="content">
<div class="row">
<div class="col-md-12">
<?php if($this->session->flashdata('message')) {
$flashdata = $this->session->flashdata('message'); ?>
<div class="alert alert-<?= $flashdata['class'] ?>">
<button class="close" data-dismiss="alert" type="button">×</button>
<?= $flashdata['message'] ?>
</div>
<?php } ?>
</div>
<div class="col-md-12">
<div class="box box-warning">
<div class="box-body">
<form name="pushNotifForm" role="form" action="<?= base_url('Notification/sendPushNotif') ?>"
method="post" class="validate" data-parsley-validate="" enctype="multipart/form-data">
<div class="box-body">
<?php if(!empty($regionData)){ ?>
<div class="col-sm-4">
<div class="form-group">
<div class="box-header with-border">
<h3 class="box-title padLeft10 ">Event</h3>
</div>
<select name="event_id" class="form-control required" placeholder="Select Event" required>
<option selected disabled>Choose an Event</option>
<?php
foreach ($event_data as $event) {
echo '<option value="'.$event->event_id.'">'.$event->event_name.'</option>';
}
?>
</select>
</div>
</div>
<?php } ?>
<?php if(!empty($regionData)){ ?>
<div class="col-sm-8">
<div class="box-header with-border">
<h3 class="box-title padLeft10 ">Tags</h3>
</div>
<div type="parent" class="header-tag-box marginTop10">
<?php foreach($regionData AS $region){ ?>
<div id="tag_<?= $region->id ?>" class="header-tag cpoint"
tag_id="<?= $region->name ?>" select="0" onclick="manageTags(jQuery(this))">
<?= $region->name ?>
</div>
<?php } ?>
</div>
<div id="selected_tags" class="hide"></div>
</div>
<?php } ?>
</div>
<div class="col-md-12">
<div class="box-footer textCenterAlign">
<button id="pushNotification" type="submit" class="btn btn-primary">Push Notification</button>
<a href="<?= base_url() ?>" class="btn btn-primary">Cancel</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
</div>
\ No newline at end of file
......@@ -79,6 +79,10 @@
<label>Admin Email-ID</label>
<input type="email" name="admin_mail_id" class="form-control required" placeholder="Admin Email-ID" value="<?= $data['admin_mail_id'] ?>">
</div>
<div class="form-group col-xs-6">
<label>App-ID</label>
<input type="text" name="app_id" class="form-control required" placeholder="App-ID" value="<?= $data['app_id'] ?>">
</div>
</div>
<div class="form-group col-xs-5">
<div class="form-group">
......
......@@ -208,6 +208,28 @@
</li>
</ul>
</li>
<?php } if(in_array('Notification',$menus)){ ?>
<li class="treeview">
<a href="#">
<img src="<?=base_url("assets/images/m2.png") ?>">
<span>Notification Management</span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li>
<a href="<?= base_url('Notification/pushNotification') ?>">
<i class="fa fa-circle-o text-aqua"></i>
Push Notification
</a>
</li>
<li>
<a href="<?= base_url('Notification/notification') ?>">
<i class="fa fa-circle-o text-aqua"></i>
Notification Tempaltes
</a>
</li>
</ul>
</li>
<?php } if(in_array('CMS',$menus)){ ?>
<li>
<a href="<?= base_url('CMS') ?>">
......@@ -215,11 +237,6 @@
<span>CMS Management</span>
</a>
</li>
<?php } if(in_array('Notification',$menus)){ ?>
<li><a href="<?= base_url('CMS/notification') ?>">
<img src="<?=base_url("assets/images/m2.png") ?>">
<span>Notification Tempaltes</span></a>
</li>
<?php } if(in_array('Settings',$menus)){ ?>
<li>
<a href="<?= base_url('Settings') ?>">
......
......@@ -838,3 +838,18 @@ jQuery('#locPointerMap').locationpicker({
jQuery('#gooLocZoom').val('15');
}
});
jQuery('[id="pushNotification"]').on('click',function(event) {
event.preventDefault();
var validation = jQuery('[name="pushNotifForm"]').parsley().validate();
var error = 0;
if(jQuery('[id="selected_tags"]').children().length <= 0) {
error = 1;
jQuery('[type="parent"]').css("background-color",'#F2DEDE');
}
if(validation && error == 0){
jQuery('[name="pushNotifForm"]').submit();
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment