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

157 lines
5.6 KiB
PHP
Raw Normal View History

<?php
class KolektorResponse {
private $response = array();
// 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;
// Dobimo podatke responsa
$sql = sisplet_query("SELECT * FROM kolektor_survey_response WHERE respondent_id='".$respondent_id."'");
if(mysqli_num_rows($sql) == 0){
echo 'Napaka! Odgovor ne obstaja.';
return false;
}
$row = mysqli_fetch_array($sql);
$this->response = $row;
}
// Vrnemo array response
public function getResponse(){ return $this->response; }
// Vrnemo URL za dostop respondenta do ankete
public function getResponseURL(){
$nice_url = SurveyInfo::getSurveyLink();
// Dobimo kodo za prepoznavo respondenta
$sql = sisplet_query("SELECT pass FROM srv_user WHERE id='".$this->response['respondent_id']."'");
if(mysqli_num_rows($sql) == 0){
return false;
}
$row = mysqli_fetch_array($sql);
$url = $nice_url.'&code='.$row['pass'];
$url .= '&kolemail='.$this->response['respondent_email'];
$url .= '&kolprojekt='.$this->response['respondent_projekt_id'];
$url .= '&kolfunkc='.$this->response['respondent_funkcija'];
if($this->response['respondent_remote_activation'] != '')
$url .= '&kolactivat='.$this->response['respondent_remote_activation'];
return $url;
}
// Shranjevanje novega statusa in posiljanje obvestila uredniku
public function setStatus($status){
// Shranimo nov status za response
$sql = sisplet_query("UPDATE kolektor_survey_response SET status='".$status."' WHERE respondent_id='".$this->response['respondent_id']."'");
// Posljemo obvestilo uredniku
$kn = new KolektorNotifications($this->response['respondent_id']);
$kn->sendNotification();
}
// Dodajanje responsa
public static function addResponse($response_data){
global $global_user_id;
// Najprej zgeneriramo kodo in cookie
$SI = new SurveyInvitationsNew($response_data['ank_id']);
list($code, $cookie) = $SI->generateCode();
// Ustvarimo respondenta v srv_user
$sql_user = sisplet_query("INSERT INTO srv_user
(ank_id, email, cookie, pass, last_status, time_insert)
VALUES
('".$response_data['ank_id']."', '".$response_data['respondent_email']."', '".$cookie."', '".$code."', '0', NOW())
");
$respondent_id = mysqli_insert_id($GLOBALS['connect_db']);
// Url za individualiziran dostop do ankete
$nice_url = SurveyInfo::getSurveyLink();
$url = $nice_url.'&code='.$code;
$url .= '&kolemail='.$response_data['respondent_email'];
$url .= '&kolprojekt='.$response_data['respondent_projekt_id'];
$url .= '&kolfunkc='.$response_data['respondent_funkcija'];
$url .= '&kolactivat='.$response_data['respondent_remote_activation'];
// Dodaj respondenta v kolektor bazo
$sql_kolektor = sisplet_query("INSERT INTO kolektor_survey_response
(ank_id,
usr_id,
insert_time,
status,
respondent_id,
respondent_email,
respondent_funkcija,
respondent_projekt_id,
respondent_remote_activation,
respondent_message)
VALUES
('".$response_data['ank_id']."',
'".$global_user_id."',
NOW(),
'1',
'".$respondent_id."',
'".$response_data['respondent_email']."',
'".$response_data['respondent_funkcija']."',
'".$response_data['respondent_projekt_id']."',
'".$response_data['respondent_remote_activation']."',
'".$response_data['respondent_message']."')
");
if (!$sql_kolektor){
echo mysqli_error($GLOBALS['connect_db']);
return false;
}
// Ce vse ok, nastavimo status na e-posta - neodgovor
$sql_user = sisplet_query("UPDATE srv_user SET last_status='1' WHERE id='".$respondent_id."'");
// Poslji email z vabilom na anketo
$kn = new KolektorNotifications($respondent_id);
$kn->sendRespondentNotification($response_data['respondent_message']);
// Uspesno prozenje
echo '<div class="popup_close"><a href="#" onclick="window.location.reload();">✕</a></div>';
echo '<h2>Dodajanje novega respondenta</h2>';
echo 'Anketa uspešno sprožena in email uspešno poslan respondentu ('.$response_data['respondent_email'].').';
// Gumb koncaj
echo '<div class="button_holder">';
echo ' <button class="medium white-blue" type="button" onClick="window.location.reload();">Zapri</button>';
echo '</div>';
}
}
?>