2022-07-06 12:37:25 +02:00
< ? php
class KolektorNotifications {
2022-07-27 11:48:04 +02:00
private $response ;
// Statusi responsa
private $statuses = array (
1 => 'proženo' ,
2 => 'opozorilo 1' ,
3 => 'opozorilo 3' ,
4 => 'neodgovorjeno' ,
5 => 'končano'
);
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
function __construct ( $respondent_id ){
2022-07-06 12:37:25 +02:00
global $site_url ;
global $lang ;
2022-07-27 11:48:04 +02:00
if ( $respondent_id != '' && $respondent_id > 0 ){
$kr = new KolektorResponse ( $respondent_id );
$this -> response = $kr -> getResponse ();
}
}
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
// Posljemo mail z obvestilom uredniku, da je bil spremenjen status responsa
public function sendNotification (){
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
$survey_title = SurveyInfo :: getInstance () -> getSurveyTitle ();
$user_email = User :: getInstance ( $this -> response [ 'usr_id' ]) -> primaryEmail ();
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
$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' ]] . '.' ;
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
// Posljemo mail
try {
$MA = new MailAdapter ();
$MA -> addRecipients ( $user_email );
echo $subject ;
echo '<br>' ;
echo $body ;
//$resultX = $MA->sendMail($body, $subject);
}
catch ( Exception $e ){
}
2022-07-28 11:59:30 +02:00
// 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 ']."' )
" );
2022-07-06 12:37:25 +02:00
}
2022-07-27 11:48:04 +02:00
// Posljemo mail respondentu z vabilom na anketo
2022-07-28 11:59:30 +02:00
public function sendRespondentNotification ( $respondent_message = '' ){
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
$subject = 'Kolektor ETRA - vabilo na anketo' ;
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
// Dobimo url povezave na anketo
$kr = new KolektorResponse ( $this -> response [ 'respondent_id' ]);
$url = $kr -> getResponseURL ();
2022-07-06 12:37:25 +02:00
2022-07-28 11:59:30 +02:00
$body = ( $respondent_message != '' ) ? $respondent_message : $this -> response [ 'respondent_message' ];
// Zamenjamo line breake in #URL#
$body = nl2br ( stripslashes ( $body ));
$body = str_replace ( '#URL#' , '<a href="' . $url . '">Kolektor anketa</a>' , $body );
2022-07-27 11:48:04 +02:00
// Posljemo mail
try {
$MA = new MailAdapter ();
$MA -> addRecipients ( $this -> response [ 'respondent_email' ]);
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
echo $subject ;
echo '<br>' ;
echo $body ;
//$resultX = $MA->sendMail($body, $subject);
2022-07-06 12:37:25 +02:00
}
2022-07-27 11:48:04 +02:00
catch ( Exception $e ){
2022-07-06 12:37:25 +02:00
}
2022-07-27 11:48:04 +02:00
}
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
// Loop cez vse response in posljemo notificatione glede na statuse
public static function executeCronJob (){
2022-07-28 11:59:30 +02:00
// 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' );
}
2022-07-27 11:48:04 +02:00
}
2022-07-06 12:37:25 +02:00
}
}
?>