113 lines
3.7 KiB
PHP
Executable File
113 lines
3.7 KiB
PHP
Executable File
<?php
|
|
|
|
if (!defined('BASEPATH'))
|
|
exit('No direct script access allowed');
|
|
|
|
class Cronjob extends MX_Controller {
|
|
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->load->model("mail_settings/Mail_model");
|
|
$this->load->model('caregivers/Caregiver_model');
|
|
$this->load->helper('mail_frequency_helper');
|
|
}
|
|
|
|
/*
|
|
| cron job functionality
|
|
*/
|
|
public function cronEmail()
|
|
{
|
|
$caregiverDetails = $this->Caregiver_model->getCaregiverStatus();
|
|
foreach($caregiverDetails as $val)
|
|
{
|
|
$caregiver_id = $val['id'];
|
|
$ion_user_id = $val['ion_user_id'];
|
|
$to_email = $val['email'];
|
|
$submited_for_verification = $val['submited_for_verification'];
|
|
|
|
/*
|
|
| cronjob for uas-certificate
|
|
*/
|
|
if($val['employementHistory2'] !='')
|
|
{
|
|
$employementHistory2= json_decode($val['employementHistory2']);
|
|
if (!empty($employementHistory2->uas_certificate))
|
|
{
|
|
$uas_certificate = $employementHistory2->uas_certificate;
|
|
}
|
|
if(($uas_certificate == 0) && ($submited_for_verification == 'no'))
|
|
{
|
|
$type='uas-certification';
|
|
$this->cornMailUpdate($caregiver_id,$ion_user_id,$type);
|
|
}
|
|
}
|
|
|
|
/*
|
|
| cronjob for pending application
|
|
*/
|
|
$progress=$this->loadProgress($ion_user_id);
|
|
if(($submited_for_verification == 'no') && ($progress<100))
|
|
{
|
|
$type='pending-application';
|
|
$this->cornMailUpdate($caregiver_id,$ion_user_id,$type);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/*
|
|
| send Email
|
|
*/
|
|
public function sendEmail($type,$to_email)
|
|
{
|
|
$mailBody = $this->Caregiver_model->getMailBody($type);
|
|
$message = html_entity_decode($mailBody->message);
|
|
$from = array(
|
|
'name' => 'HMS Admin',
|
|
'email' => 'moli@sentientgeeks.com'
|
|
);
|
|
if($type=="uas-certification"){$subject ='UAS Certification';}
|
|
if($type=="pending-application"){$subject ='Pending Application';}
|
|
//$to_email="naransaha02@gmail.com";
|
|
$send=send_email($from,$to_email,$subject,$message);
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
| after sending Email by cronjob
|
|
| update the mail_log table
|
|
*/
|
|
public function cornMailUpdate($caregiver_id,$ion_user_id,$type)
|
|
{
|
|
$Maildata=$this->Caregiver_model->getFromMailLogTable($caregiver_id,$ion_user_id,$type);
|
|
$cdt=gmdate("Y-m-d H:i:s"); // in UTC, cdt = current date time
|
|
$strCdt=strtotime($cdt);
|
|
foreach($Maildata as $md){
|
|
$strNedt=strtotime($md->email_send_date); //Nedt = Next email date time
|
|
$mainId=$md->id;
|
|
$emst=$md->email_status; // email status
|
|
$sst=$md->send_status; // send status
|
|
if($strCdt>=$strNedt && $emst==1 && $sst==0){
|
|
$sendEmail=$this->sendEmail($type,$to_email);
|
|
if($sendEmail){
|
|
$update=$this->Caregiver_model->cronUpdateMailLogTable($mainId,$cdt);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
| load progress
|
|
*/
|
|
public function loadProgress($id)
|
|
{
|
|
$nurse_data=$this->Caregiver_model->getNurseByIonId($id);
|
|
$progressData=json_decode($nurse_data->from_tab_status_pctg);
|
|
$progress=$progressData->form1+$progressData->form2+$progressData->form3+$progressData->form4+$progressData->form5+$progressData->form6+$progressData->form7+$progressData->form8+$progressData->form9+$progressData->form10+$progressData->form11;
|
|
return $progress;
|
|
}
|
|
|
|
|
|
}
|
|
|