File: //var/www/html/qcr24/app/application/controllers/admin/Notifications.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Notifications extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('admin/mrentout');
$this->load->model('mcommon');
$this->load->library('pushnotifications');
}
public function send_notification()
{//echo 1;die;
$no_odometer_readings = $this->mrentout->get_no_odometer_readings();
//echo '<pre>';print_r($no_odometer_readings);die;
if (!empty($no_odometer_readings)) {
foreach ($no_odometer_readings as $no_odometer_reading) {
try {
$mail['name'] = $no_odometer_reading['first_name'] . ' ' . $no_odometer_reading['middle_name'] . ' ' . $no_odometer_reading['last_name'];
$mail['email'] = $no_odometer_reading['email']; //'arindamkbiswas@gmail.com';
$mail['subject'] = 'Odometer Reading Update Due';
$link = $direct_debit_response['AuthorisationLink']['Link'];
$mail_temp = file_get_contents('./global/mail/odometer_notification.html');
$mail_temp = str_replace("{web_url}", base_url(), $mail_temp);
$mail_temp = str_replace("{logo}", base_url('public/admin_assets/img/logo.png'), $mail_temp);
$mail_temp = str_replace("{name}", $mail['name'], $mail_temp);
$mail_temp = str_replace("{link}", $link, $mail_temp);
$mail_temp = str_replace("{current_year}", CURRENT_YEAR, $mail_temp);
$mail['message'] = $mail_temp;
// echo '<pre>';print_r($mail);die;
$this->sendMail($mail);
// Message payload
// $test_token_key = 'f60HBZ2bQouVC2_Wil-DxL:APA91bH5X-WULjfHUlG3FUNIzw43bGiO37F1kuvo7hKGRnWqN4xWdbosnq6HTIQtxXw_QfhZYS_Tfj1rH7tlxDiTzzeGG9y5dCQUFcTRMD_TXXilUal09hwMHHK8b4YIu5kVBgjgqxsQ';
$msg_payload = array (
'title' => 'Odometer Reading Update Due',
'message' => 'Please update odometer reading',
);
if($device_type == 1){
$this->pushnotifications->send_android_notification($no_odometer_reading['token_key'],$msg_payload);
} else {
$this->pushnotifications->send_ios_notification($no_odometer_reading['token_key'],$msg_payload);
}
$sql = "UPDATE rent_out_vehcile SET notification_counter = notification_counter + 1 WHERE rent_out_id = '".$no_odometer_reading['rent_out_id']."'";
$this->db->query($sql);
$odometer_notifications_data = array(
'rent_out_id'=>$no_odometer_reading['rent_out_id'],
'created_by'=>1,
'created_ts'=>date('Y-m-d H:i:s')
);
$this->db->insert('odometer_notifications',$odometer_notifications_data);
// if (isset($send_notification['success']) && $send_notification['success'] == 1) {
// echo $send_notification['multicast_id'];
// }
// if (isset($send_notification['failure']) && $send_notification['failure'] == 1) {
// //echo 'failed';
// }
//echo '<pre>';print_r($direct_debit_response_array);die;
} catch (Exception $e) {
// this will not catch DB related errors. But it will include them, because this is more general.
$return_data = array('status' => false, 'msg' => $e->getMessage());
echo json_encode($return_data);die;
}
}
echo 'All notification send successfully';
die;
}
}
private function sendMail($data){
//print_r($data);die;
$this->load->library('email');
$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.hostinger.com';
$config['smtp_port'] = '587';
// $config['smtp_user'] = 'quantum@syscentricdev.com';
// $config['smtp_pass'] = 'Syscentric@123';
$config['smtp_user'] = 'info@qcr24.com.au';
$config['smtp_pass'] = '3_6~40baX)';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->set_crlf("\r\n");
$this->email->from('info@qcr24.com.au', 'Quantum');
$this->email->to($data['email']);
$this->email->subject($data['subject']);
$this->email->message($data['message']);
if($this->email->send()){
return true;
}else{
// echo $this->email->print_debugger(); die;
return false;
}
}
}
?>