1KA_F2F/admin/survey/modules/mod_KOLEKTOR/class.KolektorNotifications.php

128 lines
4.4 KiB
PHP

<?php
class KolektorNotifications {
private $response;
// Statusi responsa
private $statuses = array(
1 => 'proženo',
2 => 'opozorilo 1',
3 => 'opozorilo 3',
4 => 'neodgovorjeno',
5 => 'končano'
);
function __construct($respondent_id){
global $site_url;
global $lang;
if($respondent_id != '' && $respondent_id > 0){
$kr = new KolektorResponse($respondent_id);
$this->response = $kr->getResponse();
}
}
// Posljemo mail z obvestilom uredniku, da je bil spremenjen status responsa
public function sendNotification(){
$survey_title = SurveyInfo::getInstance()->getSurveyTitle();
$user_email = User::getInstance($this->response['usr_id'])->primaryEmail();
$subject = 'Kolektor ETRA 1KA - sprememba statusa respondenta';
$body = 'Status respondenta '.$this->response['respondent_email'].' ('.$this->response['respondent_funkcija'].') v anketi '.$survey_title.' je bil spremenjen na '.$this->response['status'].' - '.$this->statuses[$this->response['status']].'.';
// Posljemo mail
try{
$MA = new MailAdapter();
$MA->addRecipients($user_email);
echo $subject;
echo '<br>';
echo $body;
//$resultX = $MA->sendMail($body, $subject);
}
catch (Exception $e){
}
// Shranimo, da smo poslali notification in spremenili status
$sql_alert = sisplet_query("INSERT INTO kolektor_survey_response_alert
(respondent_id, alert_time, new_status)
VALUES
('".$response['usr_id']."', NOW(), '".$this->response['status']."')
");
}
// Posljemo mail respondentu z vabilom na anketo
public function sendRespondentNotification($respondent_message=''){
$subject = 'Kolektor ETRA - vabilo na anketo';
// Dobimo url povezave na anketo
$kr = new KolektorResponse($this->response['respondent_id']);
$url = $kr->getResponseURL();
$body = ($respondent_message != '') ? $respondent_message : $this->response['respondent_message'];
// Zamenjamo line breake in #URL#
//$body = nl2br(stripslashes($body));
$body = str_replace('\r\n', '<br>', $body);
$body = str_replace('\n', '<br>', $body);
$body = stripslashes($body);
$body = str_replace('#URL#', '<a href="'.$url.'">Kolektor anketa</a>', $body);
// Posljemo mail
try{
$MA = new MailAdapter();
$MA->addRecipients($this->response['respondent_email']);
echo $subject;
echo '<br>';
echo $body;
//$resultX = $MA->sendMail($body, $subject);
}
catch (Exception $e){
}
}
// Loop cez vse response in posljemo notificatione glede na statuse
public static function executeCronJob(){
// Loop po responsih s statusom 1, 2 ali 3 (prozeno, opozorilo 1, opozorilo 3)
$sql = sisplet_query("SELECT ksr.*, ksra.alert_time, ksra.new_status
FROM kolektor_survey_response ksr, kolektor_survey_response_alert ksra
WHERE ksr.respondent_id=ksra.respondent_id
AND ((ksr.status='1' AND ksr.insert_time <= NOW() - INTERVAL 7 DAY)
OR (ksr.status='2' AND ksr.insert_time <= NOW() - INTERVAL 21 DAY)
OR (ksr.status='3' AND ksr.insert_time <= NOW() - INTERVAL 42 DAY))
");
while($row = mysqli_fetch_array($sql)){
$kr = new KolektorResponse($row['respondent_id']);
// Status 1 - "prozeno" - preklopimo na status 2 "opozorilo 1"
if($this->response['status'] == '1'){
$kr->setStatus($status='2');
}
// Status 2 - "opozorilo 1" - preklopimo na status 3 "opozorilo 3"
elseif($this->response['status'] == '2'){
$kr->setStatus($status='3');
}
// Status 3 "opozorilo 3" - preklopimo na status 4 "neodgovorjeno"
elseif($this->response['status'] == '3'){
$kr->setStatus($status='4');
}
}
}
}
?>