2022-07-06 12:37:25 +02:00
< ? php
/*
VPRASANJA
- lahko razlicni userji aktivirajo razlicne faze iste stranke ? Potem vidjo vse ankete te stranke ?
- kaj povezuje ankete stranke - porjekt id ? potem se ga vnese samo pri prvi anketi
- je lahko vec faz istocasno aktivnih ( npr . anketa 1 in anketa 2 ) ?
- kdaj se poslje sporocilo ? ob 8 h zjutraj ?
- se lahko zacne sekvenca na npr . 2. anketi ( oz . se preskoci anketo 2. .. ? )
2022-07-27 11:48:04 +02:00
- besedilo opomnika , ki se posilja v mailu ?
- status " koncano " - mora respondent prikilkati do konca ankete ? Drugace ne moremo posiljati opomnika .
- smtp ? ?
2022-07-06 12:37:25 +02:00
*/
class Kolektor {
2022-07-27 11:48:04 +02:00
// 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
function __construct (){
global $site_url ;
global $lang ;
2022-07-25 12:21:16 +02:00
echo '<script src="' . $site_url . 'admin/survey/modules/mod_KOLEKTOR/script/script.js" type="text/javascript"></script>' ;
2022-07-06 12:37:25 +02:00
}
2022-07-25 12:21:16 +02:00
private function getResponses (){
2022-07-06 12:37:25 +02:00
global $global_user_id ;
global $admin_type ;
2022-07-25 12:21:16 +02:00
$data = array ();
// Admini vidijo vse reposnse
2022-07-06 12:37:25 +02:00
if ( $admin_type == '0' ){
2022-07-25 12:21:16 +02:00
$sql = sisplet_query ( " SELECT sr.*, s.survey_sequence
FROM kolektor_survey s , kolektor_survey_response sr
WHERE s . ank_id = sr . ank_id
2022-07-26 10:14:04 +02:00
ORDER BY sr . insert_time DESC
2022-07-25 12:21:16 +02:00
" );
2022-07-06 12:37:25 +02:00
while ( $row = mysqli_fetch_array ( $sql )){
2022-07-25 12:21:16 +02:00
$data [ $row [ 'id' ]] = $row ;
2022-07-06 12:37:25 +02:00
}
}
else {
2022-07-25 12:21:16 +02:00
// Uporabnik vidi samo svoje reponse
$sql = sisplet_query ( " SELECT sr.*, s.survey_sequence
FROM kolektor_survey s , kolektor_survey_response sr
WHERE sr . usr_id = '".$global_user_id."' AND s . ank_id = sr . ank_id
2022-07-26 10:14:04 +02:00
ORDER BY sr . insert_time DESC
2022-07-25 12:21:16 +02:00
" );
2022-07-06 12:37:25 +02:00
while ( $row = mysqli_fetch_array ( $sql )){
2022-07-25 12:21:16 +02:00
$data [ $row [ 'id' ]] = $row ;
2022-07-06 12:37:25 +02:00
}
}
2022-07-25 12:21:16 +02:00
return $data ;
}
private function getSurveys (){
$data = array ();
2022-07-26 10:14:04 +02:00
$sql = sisplet_query ( " SELECT ks.*, a.hash, a.naslov, a.akronim FROM kolektor_survey ks, srv_anketa a WHERE a.id=ks.ank_id ORDER BY ks.survey_sequence ASC " );
2022-07-25 12:21:16 +02:00
while ( $row = mysqli_fetch_array ( $sql )){
2022-07-26 10:14:04 +02:00
$data [ $row [ 'ank_id' ]] = $row ;
2022-07-25 12:21:16 +02:00
}
return $data ;
2022-07-06 12:37:25 +02:00
}
// Osnovni pogled
public function display (){
2022-07-25 12:21:16 +02:00
global $site_url ;
global $lang ;
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
echo '<button class="large blue kolektor_create_response" onClick="kolektorCreateResponsePopup();">Proži novo anketo</button>' ;
2022-07-25 12:21:16 +02:00
2022-07-26 10:14:04 +02:00
echo '<div id="kolektor_reponses_holder">' ;
2022-07-25 12:21:16 +02:00
$this -> displayResponses ();
2022-07-26 10:14:04 +02:00
echo '</div>' ;
2022-07-06 12:37:25 +02:00
}
2022-07-25 12:21:16 +02:00
public function displayResponses (){
2022-07-28 11:59:30 +02:00
global $site_url ;
2022-07-26 10:14:04 +02:00
echo ' <table class="kolektor_reponses">' ;
echo ' <tr>' ;
echo ' <th>Anketa</th>' ;
echo ' <th>ID projekta</th>' ;
echo ' <th>Email respondenta</th>' ;
echo ' <th>Funkcija respondenta</th>' ;
echo ' <th>Čas proženja</th>' ;
echo ' <th>Status</th>' ;
2022-07-28 11:59:30 +02:00
echo ' <th>Odgovori</th>' ;
echo ' <th>Opomnik</th>' ;
2022-07-26 10:14:04 +02:00
echo ' </tr>' ;
2022-07-13 10:40:19 +02:00
// Loop cez vse stranke
2022-07-25 12:21:16 +02:00
$responses = $this -> getResponses ();
2022-07-26 10:14:04 +02:00
$surveys = $this -> getSurveys ();
foreach ( $responses as $response_id => $response ){
2022-07-13 10:40:19 +02:00
2022-07-26 10:14:04 +02:00
echo ' <tr class="kolektor_response">' ;
echo ' <td>' . $surveys [ $response [ 'ank_id' ]][ 'naslov' ] . '</td>' ;
echo ' <td>' . $response [ 'respondent_projekt_id' ] . '</td>' ;
echo ' <td>' . $response [ 'respondent_email' ] . '</td>' ;
echo ' <td>' . $response [ 'respondent_funkcija' ] . '</td>' ;
echo ' <td>' . date ( 'j.n.Y H:i:s' , strtotime ( $response [ 'insert_time' ])) . '</td>' ;
2022-07-27 11:48:04 +02:00
echo ' <td>' . $this -> statuses [ $response [ 'status' ]] . '</td>' ;
2022-07-28 11:59:30 +02:00
echo ' <td><a href="' . $site_url . 'admin/survey/index.php?anketa=' . $response [ 'ank_id' ] . '&a=data">Preglej odgovore</a></td>' ;
2022-08-10 11:54:58 +02:00
echo ' <td><span onClick="kolektorSendRespondentNotificationPopup(\'' . $response [ 'respondent_id' ] . '\');">Pošlji opomnik</span></td>' ; // TODO
2022-07-26 10:14:04 +02:00
echo ' </tr>' ;
2022-07-13 10:40:19 +02:00
}
2022-07-26 10:14:04 +02:00
echo ' </table>' ;
2022-07-06 12:37:25 +02:00
}
2022-07-06 13:37:06 +02:00
// Prikaze formo za dodajanje novega responsa
2022-07-25 12:21:16 +02:00
public function displayAddResponse ( $data = array (), $error = array ()){
2022-07-27 11:48:04 +02:00
echo '<div class="popup_close"><a href="#" onclick="kolektorCreateResponseClose();">✕</a></div>' ;
2022-07-26 10:14:04 +02:00
echo '<h2>Dodajanje novega respondenta</h2>' ;
2022-07-25 12:21:16 +02:00
echo '<form id="kolektor_add_response_form" name="kolektor_add_response_form">' ;
// Izpisemo napake, ce kaksno polje manjka
if ( ! empty ( $error )){
echo '<div class="error_messages">' ;
echo 'Prosimo izpolnite vsa obvezna polja:' ;
2022-07-27 11:48:04 +02:00
echo '<ul>' ;
2022-07-25 12:21:16 +02:00
foreach ( $error as $error_msg ){
2022-07-27 11:48:04 +02:00
echo '<li class="error_message">' . $error_msg . '</li>' ;
2022-07-25 12:21:16 +02:00
}
2022-07-27 11:48:04 +02:00
echo '</ul>' ;
2022-07-25 12:21:16 +02:00
echo '</div>' ;
}
// Seznam 6 kolektor anket
echo '<div class="kolektor_setting ' . ( isset ( $error [ 'ank_id' ]) ? 'error' : '' ) . '">' ;
2022-07-28 11:59:30 +02:00
echo ' <div class="setting_line">Anketa:</div>' ;
2022-07-25 12:21:16 +02:00
$surveys = $this -> getSurveys ();
2022-07-27 11:48:04 +02:00
$sequence = 0 ;
2022-07-25 12:21:16 +02:00
foreach ( $surveys as $kolektor_survey ){
2022-07-28 11:59:30 +02:00
echo '<div class="setting_line">' ;
2022-07-27 11:48:04 +02:00
echo ' <input type="radio" id="kolektor_survey_' . $kolektor_survey [ 'survey_sequence' ] . '" name="kolektor_survey" sequence="' . $kolektor_survey [ 'survey_sequence' ] . '" value="' . $kolektor_survey [ 'ank_id' ] . '" ' . ( $data [ 'ank_id' ] == $kolektor_survey [ 'ank_id' ] ? 'checked="checked"' : '' ) . ' onChange="kolektorSelectSurvey();">' ;
2022-07-25 12:21:16 +02:00
echo ' <label for="kolektor_survey_' . $kolektor_survey [ 'survey_sequence' ] . '">' . $kolektor_survey [ 'survey_sequence' ] . ' - ' . $kolektor_survey [ 'naslov' ] . '</label>' ;
2022-07-28 11:59:30 +02:00
echo '</div>' ;
2022-07-27 11:48:04 +02:00
if ( $data [ 'ank_id' ] == $kolektor_survey [ 'ank_id' ])
$sequence = $kolektor_survey [ 'survey_sequence' ];
2022-07-25 12:21:16 +02:00
}
echo '</div>' ;
2022-07-06 12:37:25 +02:00
2022-07-27 11:48:04 +02:00
echo '<div id="kolektor_respondent_settings" ' . (( $sequence == 0 ) ? 'style="display:none;"' : '' ) . '>' ;
2022-07-25 12:21:16 +02:00
// ID projekta
echo '<div class="kolektor_setting ' . ( isset ( $error [ 'respondent_projekt_id' ]) ? 'error' : '' ) . '">' ;
2022-07-28 11:59:30 +02:00
echo ' <div class="setting_line">ID projekta:</div>' ;
2022-07-27 11:48:04 +02:00
echo ' <input type="text" class="medium" name="respondent_projekt_id" value="' . $data [ 'respondent_projekt_id' ] . '">' ;
2022-07-25 12:21:16 +02:00
echo '</div>' ;
// Email
echo '<div class="kolektor_setting ' . ( isset ( $error [ 'respondent_email' ]) ? 'error' : '' ) . '">' ;
2022-07-28 11:59:30 +02:00
echo ' <div class="setting_line">Email respondenta:</div>' ;
2022-07-27 11:48:04 +02:00
echo ' <input type="text" class="medium" name="respondent_email" value="' . $data [ 'respondent_email' ] . '">' ;
2022-07-25 12:21:16 +02:00
echo '</div>' ;
// Funkcija respondenta
2022-07-28 11:59:30 +02:00
$standard_functions = array ( 'Vodja nabave' , 'Vodja projekta' , 'Skrbnik pogodbe' , 'Nadzornik objekta' , 'Član inženirskega tima' );
$other_function = ( isset ( $data [ 'respondent_funkcija' ]) && $data [ 'respondent_funkcija' ] != '' && ! in_array ( $data [ 'respondent_funkcija' ], $standard_functions )) ? true : false ;
2022-07-25 12:21:16 +02:00
echo '<div class="kolektor_setting ' . ( isset ( $error [ 'respondent_funkcija' ]) ? 'error' : '' ) . '">' ;
2022-07-28 11:59:30 +02:00
echo ' <div class="setting_line">Funkcija respondenta v podjetju:</div>' ;
echo ' <select name="respondent_funkcija" id="respondent_funkcija_dropdown" class="dropdown medium" ' . ( $other_function ? 'disabled="disabled"' : '' ) . '>' ;
foreach ( $standard_functions as $standard_function ){
echo ' <option value="' . $standard_function . '" ' . ( $data [ 'respondent_funkcija' ] == $standard_function ? 'selected="selected"' : '' ) . '>' . $standard_function . '</option>' ;
}
2022-07-25 12:21:16 +02:00
echo ' </select>' ;
2022-07-28 11:59:30 +02:00
echo ' <div class="setting_line"><input type="checkbox" id="respondent_funkcija_other" onClick="kolektorOtherFunction();" ' . ( $other_function ? 'checked="checked"' : '' ) . '><label for="respondent_funkcija_other">Druga funkcija</label></div>' ;
echo ' <input type="text" class="medium" name="respondent_funkcija" id="respondent_funkcija_text" ' . ( $other_function ? 'value="' . $data [ 'respondent_funkcija' ] . '"' : 'style="display:none;" disabled="disabled"' ) . '>' ;
2022-07-25 12:21:16 +02:00
echo '</div>' ;
2022-07-28 11:59:30 +02:00
// Aktivacija na daljavo - samo za anketi 5 in 6
2022-08-31 10:23:52 +02:00
echo '<div id="kolektor_setting_activation" class="kolektor_setting ' . ( isset ( $error [ 'respondent_remote_activation' ]) ? 'error' : '' ) . '" ' . (( $sequence == '4' || $sequence == '5' ) ? '' : 'style="display:none;"' ) . '>' ;
2022-07-28 11:59:30 +02:00
echo ' <div class="setting_line">Aktivacija na daljavo:</div>' ;
2022-08-31 10:23:52 +02:00
echo ' <div class="setting_line"><input type="radio" id="respondent_remote_activation_0" name="respondent_remote_activation" value="0" ' . ( $data [ 'respondent_remote_activation' ] != '1' ? 'checked="checked"' : '' ) . ' ' . (( $sequence == '4' || $sequence == '5' ) ? '' : 'disabled="disabled"' ) . '><label for="respondent_remote_activation_0">Ne</label></div>' ;
echo ' <div class="setting_line"><input type="radio" id="respondent_remote_activation_1" name="respondent_remote_activation" value="1" ' . ( $data [ 'respondent_remote_activation' ] == '1' ? 'checked="checked"' : '' ) . ' ' . (( $sequence == '4' || $sequence == '5' ) ? '' : 'disabled="disabled"' ) . '><label for="respondent_remote_activation_1">Da</label></div>' ;
2022-07-27 11:48:04 +02:00
echo '</div>' ;
2022-07-25 12:21:16 +02:00
// Sporocilo respondentu
2022-08-10 11:54:58 +02:00
$text = ' Pozdravljeni ,
Prosimo vas , če lahko izpolnite anketo . Povezava do ankete : #URL#
Lep pozdrav ,
Kolektor ETRA ' ;
2022-07-28 11:59:30 +02:00
2022-07-25 12:21:16 +02:00
echo '<div class="kolektor_setting ' . ( isset ( $error [ 'respondent_message' ]) ? 'error' : '' ) . '">' ;
2022-07-28 11:59:30 +02:00
echo ' <div class="setting_line">Spremno besedilo:</div>' ;
echo ' <textarea name="respondent_message">' . ( isset ( $data [ 'respondent_message' ]) && $data [ 'respondent_message' ] != '' ? $data [ 'respondent_message' ] : $text ) . '</textarea>' ;
echo '</div>' ;
2022-07-25 12:21:16 +02:00
echo '</div>' ;
2022-07-26 10:14:04 +02:00
// Gumbi
echo '<div class="button_holder">' ;
2022-07-27 11:48:04 +02:00
echo ' <button class="medium white-blue" type="button" onClick="kolektorCreateResponseClose();">Zapri</button>' ;
echo ' <button class="medium blue" type="button" onClick="kolektorCreateResponse();">Sproži anketo in pošlji email respondentu</button>' ;
echo '</div>' ;
2022-07-06 12:37:25 +02:00
2022-07-25 12:21:16 +02:00
echo '</form>' ;
2022-07-06 12:37:25 +02:00
}
2022-08-10 11:54:58 +02:00
// Prikaze formo za posiljanje opomnika respondentu
public function displaySendRespondentNotification ( $respondent_id ){
echo '<div class="popup_close"><a href="#" onclick="kolektorCreateResponseClose();">✕</a></div>' ;
echo '<h2>Pošiljanje opomnika respondentu</h2>' ;
// Sporocilo respondentu - dobimo prvotnega
$sql = sisplet_query ( " SELECT respondent_message FROM kolektor_survey_response WHERE respondent_id=' " . $respondent_id . " ' " );
$row = mysqli_fetch_array ( $sql );
$text = $row [ 'respondent_message' ];
echo '<div class="kolektor_setting">' ;
echo ' <div class="setting_line">Besedilo opomnika:</div>' ;
echo ' <textarea name="respondent_message">' . $text . '</textarea>' ;
echo '</div>' ;
echo '<input type="hidden" name="respondent_id" value="' . $respondent_id . '">' ;
// Gumbi
echo '<div class="button_holder">' ;
echo ' <button class="medium white-blue" type="button" onClick="kolektorCreateResponseClose();">Zapri</button>' ;
echo ' <button class="medium blue" type="button" onClick="kolektorSendRespondentNotification();">Pošlji opomnik respondentu</button>' ;
echo '</div>' ;
}
2022-07-06 12:37:25 +02:00
2022-07-06 13:37:06 +02:00
public function displayResponseDetails (){
2022-07-06 12:37:25 +02:00
2022-07-25 12:21:16 +02:00
}
// Ajax klici
public function ajax (){
global $lang ;
global $site_path ;
global $global_user_id ;
2022-07-26 10:14:04 +02:00
if ( $_GET [ 'a' ] == 'add_repsonse_popup' ){
echo '<div id="kolektor_add_response">' ;
$this -> displayAddResponse ();
echo '</div>' ;
}
2022-08-10 11:54:58 +02:00
2022-07-26 10:14:04 +02:00
elseif ( $_GET [ 'a' ] == 'add_repsonse' ){
2022-07-25 12:21:16 +02:00
$response_data [ 'ank_id' ] = ( isset ( $_POST [ 'kolektor_survey' ])) ? $_POST [ 'kolektor_survey' ] : '' ;
$response_data [ 'respondent_email' ] = ( isset ( $_POST [ 'respondent_email' ])) ? $_POST [ 'respondent_email' ] : '' ;
$response_data [ 'respondent_funkcija' ] = ( isset ( $_POST [ 'respondent_funkcija' ])) ? $_POST [ 'respondent_funkcija' ] : '' ;
$response_data [ 'respondent_projekt_id' ] = ( isset ( $_POST [ 'respondent_projekt_id' ])) ? $_POST [ 'respondent_projekt_id' ] : '' ;
$response_data [ 'respondent_remote_activation' ] = ( isset ( $_POST [ 'respondent_remote_activation' ])) ? $_POST [ 'respondent_remote_activation' ] : '' ;
$response_data [ 'respondent_message' ] = ( isset ( $_POST [ 'respondent_message' ])) ? $_POST [ 'respondent_message' ] : '' ;
// Pohendlamo errorje
$error = array ();
if ( $response_data [ 'ank_id' ] == '' ){
2022-07-27 11:48:04 +02:00
$error [ 'ank_id' ] = 'izberite anketo' ;
2022-07-25 12:21:16 +02:00
}
if ( $response_data [ 'respondent_email' ] == '' ){
2022-07-27 11:48:04 +02:00
$error [ 'respondent_email' ] = 'vnesite email respondenta' ;
2022-07-25 12:21:16 +02:00
}
if ( $response_data [ 'respondent_funkcija' ] == '' ){
2022-07-27 11:48:04 +02:00
$error [ 'respondent_funkcija' ] = 'vnesite funkcijo respondenta' ;
2022-07-25 12:21:16 +02:00
}
if ( $response_data [ 'respondent_projekt_id' ] == '' ){
2022-07-27 11:48:04 +02:00
$error [ 'respondent_projekt_id' ] = 'vnesite ID projekta oz. krovnega projekta' ;
2022-07-25 12:21:16 +02:00
}
2022-07-27 11:48:04 +02:00
if ( $response_data [ 'respondent_remote_activation' ] == '' && isset ( $_POST [ 'respondent_remote_activation' ])){
$error [ 'respondent_remote_activation' ] = 'izberite, če gre za aktivacijo na daljavo' ;
2022-07-25 12:21:16 +02:00
}
if ( $response_data [ 'respondent_message' ] == '' ){
2022-07-27 11:48:04 +02:00
$error [ 'respondent_message' ] = 'vnesite spremno besedilo' ;
2022-07-25 12:21:16 +02:00
}
// Imamo napake
if ( ! empty ( $error )){
$this -> displayAddResponse ( $response_data , $error );
}
else {
// Dodamo nov response
KolektorResponse :: addResponse ( $response_data );
}
}
2022-08-10 11:54:58 +02:00
elseif ( $_GET [ 'a' ] == 'send_respondent_notification_popup' ){
$respondent_id = ( isset ( $_POST [ 'respondent_id' ])) ? $_POST [ 'respondent_id' ] : 0 ;
if ( $respondent_id > 0 ){
echo '<div id="kolektor_send_respondent_notification">' ;
$this -> displaySendRespondentNotification ( $respondent_id );
echo '</div>' ;
}
}
elseif ( $_GET [ 'a' ] == 'send_respondent_notification' ){
$respondent_id = ( isset ( $_POST [ 'respondent_id' ])) ? $_POST [ 'respondent_id' ] : '' ;
$notification = ( isset ( $_POST [ 'notification' ])) ? $_POST [ 'notification' ] : '' ;
$kn = new KolektorNotifications ( $respondent_id );
$kn -> sendRespondentNotification ( $notification );
// Uspesno prozenje
echo '<div class="popup_close"><a href="#" onclick="window.location.reload();">✕</a></div>' ;
echo '<h2>Pošiljanje opomnika respondentu</h2>' ;
echo 'Opomnik uspešno poslan.' ;
// Gumb koncaj
echo '<div class="button_holder">' ;
echo ' <button class="medium white-blue" type="button" onClick="window.location.reload();">Zapri</button>' ;
echo '</div>' ;
}
2022-07-06 12:37:25 +02:00
}
}
?>