1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
|
<?php
/***************************************
* Description:
* Autor: Robert Šmalc
* Created date: 04.02.2016
*****************************************/
namespace App\Controllers;
use App\Controllers\BodyController as Body;
use App\Controllers\CheckController as Check;
use App\Controllers\DisplayController as Display;
use App\Controllers\FindController as Find;
use App\Controllers\HeaderController as Header;
use App\Controllers\HelperController as Helper;
use App\Controllers\LanguageController as Language;
use App\Models\Model;
use App\Models\SaveSurvey;
use Common;
use SurveyInfo;
use SurveySetting;
use SurveySlideshow;
use GDPR;
use MAZA;
use UserAccess;
use SurveyCheck;
use KolektorResponse;
use SurveyPanel;
use SurveyEmailAccess;
class InitClass extends Controller
{
protected $get;
public function __construct()
{
parent::getGlobalVariables();
//inicializiramo $variable v $this, da jih lažje prikličemo
parent::getAllVariables();
if (!get('printPreview')) {
return $this->loadIfPrintPreviewFalse();
} else {
return $this->loadIfPrintPreviewTrue();
}
}
/************************************************
* Print preview je izključen
************************************************/
private function loadIfPrintPreviewFalse()
{
// cist na zacetku preverimo referer. Ce je prisel od kje drugje (napacno skopiran link itd...) ga preusmerimo na prvo stran ankete
if (!SurveyInfo::getInstance()->checkSurveyModule('panel') && isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], self::$site_url) === false && !isset($_GET['code']) && !isset($_GET['return']) && !isset($_GET['params'])) {
$anketa_hash = (isset($_GET['anketa'])) ? $_GET['anketa'] : ((isset($_POST['anketa'])) ? $_POST['anketa'] : die("Missing anketa id!"));
save('anketa_hash', $anketa_hash);
$anketa = getSurveyIdFromHash($anketa_hash);
save('anketa', $anketa);
// Pri ul evalvaciji tega ne pustimo, ker drugace narobe preusmeri
if (Common::checkModule('evalvacija') == '0') {
// to more bit, ker zgleda da pri redirectu browser ne nastavi novega refererja... (tudi websm anketa ne rabi tega - vedno mora skocit na ustrezno stran)
if ($_COOKIE['ref'] != get('anketa') && !(get('anketa') == get('webSMSurvey') && Common::checkModule('websmsurvey') == '1')) {
// prenesemo sistemske spremenljivke, ki so podane preko URLja
$sql1 = sisplet_query("SELECT s.id, s.variable FROM srv_spremenljivka s, srv_grupa g WHERE g.ank_id='" . get('anketa') . "' AND s.gru_id=g.id AND s.sistem='1' AND (s.tip='4' OR s.tip='21' OR s.tip='1')");
$g = '';
while ($row1 = mysqli_fetch_array($sql1))
if (isset($_GET[$row1['variable']])) $g .= '&' . $row1['variable'] . '=' . $_GET[$row1['variable']];
$g .= Header::getSurveyParams();
$redirect_url = SurveyInfo::getSurveyLink(false, false) . $g;
$request_url = 'http' . ($_SERVER['HTTPS'] ? 's' : null) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if ($redirect_url != $request_url) { // to je extra check, da pridejo skozi in se ne vrtijo v neskoncni zanki tudi ljudje (paranoiki :) ) brez cookiejev
setcookie('ref', get('anketa')); // cookie z referalom
header("Location: " . $redirect_url);
die();
}
}
}
}
// ce se je vrnil na anketo preko URLja
if (isset($_GET['return'])) {
Check::getInstance()->check_cookie_return();
}
if (isset($_GET['anketa']) || isset($_POST['anketa'])) {
$anketa_hash = (isset($_GET['anketa'])) ? $_GET['anketa'] : ((isset($_POST['anketa'])) ? $_POST['anketa'] : die("Missing anketa id!"));
save('anketa_hash', $anketa_hash);
$anketa = getSurveyIdFromHash($anketa_hash);
save('anketa', $anketa);
// Preverimo, ce gre za deaktivirano phishing anketo - vrnemo 404
global $mysql_database_name;
if($mysql_database_name == 'real1kasi' && in_array(get('anketa'), array('321069','328454','328864','329691')) ){
http_response_code(404);
die();
}
// Preverimo ce gre za POSEBNO webSM anketo (ki ne shranjuje nicesar - samo direktno preusmeri na ustrezno stran)
if (get('anketa') == get('webSMSurvey') && Common::checkModule('websmsurvey') == '1')
$this->jeWebSMSurvey();
// polovimo podatke o anketi
SurveyInfo::getInstance()->SurveyInit(get('anketa'));
$db_table = SurveyInfo::getInstance()->getSurveyArchiveDBString();
save('db_table', $db_table);
$rowa = SurveyInfo::getInstance()->getSurveyRow();
// Ce anketa sploh ne obstaja
if (!$rowa) {
Display::getInstance()->displayNapaka(self::$lang['no_survey']);
die();
}
// Ce nima dostopa do ankete
if (!((self::$admin_type <= $rowa['odgovarja'] && self::$admin_type >= 0) || ($rowa['odgovarja'] == 4))) {
Display::getInstance()->displayNapaka(self::$lang['no_access']);
die();
}
// pretecena anketa, kontroliramo datum na: starts in expire
$stringe = "SELECT id , CURDATE(), starts, expire FROM srv_anketa WHERE id='" . get('anketa') . "' AND starts <= CURDATE() AND expire >= CURDATE()";
$sqle = sisplet_query($stringe);
// Tudi ce je zakljucena pustimo prikaz pri nastavljenem glas_end -> preklop arhiva statistike pri glasovanju - drugace izpisemo obvestilo o zakljucku
if (!(isset($_GET['preview']) && $_GET['preview'] == 'on') && ($rowa['active'] < 1 or mysqli_num_rows($sqle) == 0) && (!isset($_GET['glas_end']) && (!isset($_GET['urejanje']))))
$this->anketaEnd($rowa);
// Preverimo ce je nastavljen staticen uvod (ki ne belezi nicesar) - da se pri embeddanih anketah ne shranjujejo vsi obiskovalci ampak se user ustvari sele na prvi strani po uvodu
if ($rowa['intro_static'] > 0 && $rowa['show_intro'] == 1 && count($_POST) == 0 && !isset($_GET['grupa'])) {
// inicializiramo jezik za multilang anketo
Language::getInstance()->multilang_init();
// konec ukvarjanja s cookieji, prikazemo header
Header::getInstance()->header();
Body::getInstance()->displayStaticIntroduction();
die();
}
// Ce imamo staticen uvod s captcho in smo kliknili na naslednjo stran, najprej preverimo captcho
elseif ($rowa['intro_static'] == 2 && $rowa['show_intro'] == 1 && count($_POST) != 0 && isset($_GET['grupa']) && $_GET['grupa'] == '0') {
Check::getInstance()->check_captcha_intro();
}
// Modul email dostop - prikazemo prvo stran za vnos emaila
if(SurveyInfo::getInstance()->checkSurveyModule('email_access') && (!isset($_GET['grupa']) || $_GET['grupa'] == '0')){
$sea = new SurveyEmailAccess(get('anketa'));
$response = array();
$code_check = false;
// Poslana je bila koda - preverimo, ce je ok in spustimo naprej
if(isset($_POST['code']) && $_POST['code'] != ''){
$code = $_POST['code'];
$code = str_replace(' ', '', $code);
// Preverimo kodo - ce je ok, spustimo naprej, drugace prikazemo error
$response = $sea->checkAccessCode($code);
// Koda je ok, pustimo na anketo
if($response === true)
$code_check = true;
}
// Poslan je bil email - posljemo kodo
elseif(isset($_POST['email'])){
// Preverimo captcho
if($sea->getEmailAccessSettings('captcha') == '1'){
Check::getInstance()->check_captcha_intro();
}
$email = $_POST['email'];
// Posljemo email s kodo
$response = $sea->sendAccessCode($email);
}
// Koda ni ok - izpisemo vsebino
if($code_check !== true){
// inicializiramo jezik za multilang anketo
Language::getInstance()->multilang_init();
// konec ukvarjanja s cookieji, prikazemo header
Header::getInstance()->header();
// Izpisemo uvod s kodo
Body::getInstance()->displayEmailAccessIntroduction($response);
die();
}
}
// ali je respondent avtor ankete (zaradi posebnih opcij prepoznave)
$sqlUserAutor = sisplet_query("SELECT ank_id, uid FROM srv_dostop WHERE ank_id='" . get('anketa') . "' AND uid='" . self::$global_user_id . "'");
if (mysqli_num_rows($sqlUserAutor) > 0)
save('userAutor', true);
// Ce imamo nastavljeno da vedno zahtevamo kodo
if (isset($_GET['code']) && $rowa['usercode_required'] == 1) {
unset($_GET['code']);
}
// pogledamo na kolk je nastavljen expire za cookie v nastavitvi ankete
$row = SurveyInfo::getInstance()->getSurveyRow();
save('cookie_expire', $row['cookie']);
if ($row['cookie'] == 0) {
$this->expire = 0;
}
elseif ($row['cookie'] == -1) {
if ($rowa['user_from_cms'] == 1) {
$this->expire = time() - 3600;
} else {
$this->expire = 0;
}
}
elseif ($row['cookie'] == 1) {
$this->expire = time() + 3600;
}
else {
$this->expire = time() + 2500000;
}
// Preberimo cookie stringiii
$this->cookie = null;
// da delata oba načina nastavljanja piškotkov, neglede na nastavitve
if (isset($_GET['survey-' . get('anketa')]))
$this->cookie = $_GET['survey-' . get('anketa')]; // Pri nastavitvi brez cookie-ja se cookie string prenaša preko URL-ja
// PANEL - preverimo, ce je respondent z istim panel id-jem in ga prepoznamo
if(SurveyInfo::getInstance()->checkSurveyModule('panel')){
if($this->cookie == null){
// Postavimo status panelista na default
$sp = new SurveyPanel(get('anketa'));
setcookie('panel_status', $sp->getPanelSettings('status_default'), 0, '/');
// Ustvarimo cookie panelista
$this->cookie = $this->panelNovRespondent();
}
}
// Obicajen cookie - pri panelu ga nikoli ne upostevamo
else{
if (isset($_COOKIE['survey-' . get('anketa')]))
$this->cookie = $_COOKIE['survey-' . get('anketa')];
}
// EVALVACIJA - Ce je nov respondent preverimo ce se je vrnil (zapis v tabeli eval_data_userCookie) in mu nastavimo ustrezen cookie da ga preusmerimo na ustrezno stran
if (Common::checkModule('evalvacija') == '1' && $this->cookie == null)
$this->cookie = $this->evlavacijaNovRespondent();
// HIERARHIJA - UČITELJ, preverimo, če je učitelj ponovno prišel nazaj
if (Common::checkModule('hierarhija') == '1' && SurveyInfo::checkSurveyModule('hierarhija') == 2 && is_null($this->cookie))
$this->cookie = $this->hierarhijaPreveriCeSeJeUciteljVrnilPonovnoResevatiAnketo();
// poskrbimo za user ID
// tuki je kookie ze nastavljen in ga samo preberemo
if ($this->cookie != null)
$this->cookieExist($this->cookie);
// kukija se ni, ga bomo pa nastavil
if ($this->cookie == null)
$this->cookieIsNull();
// tukaj bomo dodatno preverjali, ce slucajno kje&kdaj pride do napake da usr_id ni postavljen
if (get('usr_id') == 0) {
$get = '';
foreach ($_GET AS $key => $val) {
if ($get != '')
$get .= ', ';
$get .= $key . ': "' . $val . '"';
}
$post = '';
foreach ($_POST AS $key => $val) {
if ($post != '')
$post .= ', ';
$post .= $key . ': "' . $val . '"';
}
$kuki = '';
foreach ($_COOKIE AS $key => $val) {
if ($kuki != '')
$kuki .= ', ';
$kuki .= $key . ': "' . $val . '"';
}
$text = 'GET: ' . $get . '; POST: ' . $post . '; COOKIE: ' . $kuki;
$sql_log = sisplet_query("SELECT value FROM srv_survey_misc WHERE sid = '" . get('anketa') . "' AND what = 'usr_id_error'");
$row_log = mysqli_fetch_array($sql_log);
$text = $row_log['value'] . "\n" . $text;
sisplet_query("REPLACE INTO srv_survey_misc (sid, what, value) VALUES ('" . get('anketa') . "', 'usr_id_error', '" . $text . "')");
}
// inicializiramo jezik za multilang anketo
Language::getInstance()->multilang_init();
// konec ukvarjanja s cookieji, prikazemo header
Header::getInstance()->header();
//prikaz konca ankete - posebej statistika pri glasovanju
if (isset($_GET['glas_end'])) {
Body::getInstance()->displayKonecGlasovanje();
} else {
if (isset($_GET['loop_id'])) save('loop_id', $_GET['loop_id']);
// nismo se poslali kaksno stran z odgovori
if (count($_POST) == 0) {
// Preverimo kvoto pri Evoli Team Meter
if (SurveyInfo::getInstance()->checkSurveyModule('evoli_teammeter')
|| SurveyInfo::getInstance()->checkSurveyModule('evoli_quality_climate')
|| SurveyInfo::getInstance()->checkSurveyModule('evoli_teamship_meter')
|| SurveyInfo::getInstance()->checkSurveyModule('evoli_organizational_employeeship_meter')
) {
// Ce imamo nastavljeno skupino
if (isset($_GET['skupina'])) {
$skupina_id = $_GET['skupina'];
$sqlGroupTM = sisplet_query("SELECT kvota_val, kvota_max, date_to FROM srv_evoli_teammeter WHERE ank_id='" . get('anketa') . "' AND skupina_id='" . $skupina_id . "'");
$rowGroupTM = mysqli_fetch_array($sqlGroupTM);
// Ce je kvota ze dosezena
if ($rowGroupTM['kvota_val'] >= $rowGroupTM['kvota_max']) {
Body::getInstance()->displayKonecEvoliTM();
die();
}
// Ce je datum ze presezen
if (strtotime($rowGroupTM['date_to']) < time() - (60 * 60 * 24)) {
$date_to = date('d.m.Y', strtotime($rowGroupTM['date_to']));
Body::getInstance()->displayKonecEvoliTM($date_to);
die();
}
}
}
if (isset($_GET['grupa']))
save('grupa', $_GET['grupa']);
if ($rowa['show_intro'] == 0 && !isset($_GET['grupa'])) {
$this->set_userstatus(3);
SaveSurvey::saveSistemske();
save('grupa', Find::getInstance()->findNextGrupa());
}
if (get('grupa') == 'end') {
$this->set_userstatus(6);
Body::getInstance()->displayKonec();
}
elseif (get('displayAllPages')) {
Body::getInstance()->displayAllPages();
}
// prikazemo ustrezno stran / grupo
elseif (get('grupa') > 0) {
$preskok = false;
// pogledamo ce preskocimo kaksno stran zaradi branchinga
while (get('grupa') > 0 && (!isset($_GET['disableif']) || $_GET['disableif'] != 1) && !Check::getInstance()->checkGrupa()) {
SaveSurvey::getInstance()->posted(1);
save('grupa', Find::getInstance()->findNextGrupa());
$preskok = true;
}
if ($preskok) SaveSurvey::getInstance()->posted_commit(); // pri preskokih se ne shranjuje sproti v bazo, ampak na koncu, vse naenkrat
if (get('grupa') > 0) {
Body::getInstance()->displayAnketa();
} else {
$this->set_userstatus(6);
Body::getInstance()->displayKonec();
}
// prikazemo uvodni nagovor - introduction
} else {
// nastavimo status -- kliknil je na anketo
$this->set_userstatus(3);
Body::getInstance()->displayIntroduction();
}
}
// poslani so bili odgovori
else {
save('grupa', $_GET['grupa']);
// Preverimo ce gre za gdpr anketo in ce je sprejel pogoje za sodelovanje
if(GDPR::isGDPRSurveyTemplate(get('anketa'))){
// Ni sprejel pogojev za sodelovanje - vrzemo na zakljucek
if(isset($_POST['gdpr']) && $_POST['gdpr_accept'] == '0'){
Body::getInstance()->displayKonec();
die();
}
// Ni oznacil ali sprejema pogoje
elseif(isset($_POST['gdpr']) && !isset($_POST['gdpr_accept'])){
Body::getInstance()->displayIntroduction();
die();
}
}
if (get('grupa') == 'end') {
$this->set_userstatus(6);
Body::getInstance()->displayKonec();
}
else {
// ce je nastavljena grupa (se pravi ni prva stran) in ce nismo v predogledu ankete
if (get('grupa') > 0 || get('displayAllPages')) {
// nastavimo status -- izpolnjuje anketo
$this->set_userstatus(5);
// shrani poslano stran v bazo
SaveSurvey::getInstance()->posted();
} else { // prva stran z vprasanji
$s = sisplet_query("REPLACE INTO srv_user_grupa" . get('db_table') . " (gru_id, usr_id, time_edit) VALUES ('0', '" . get('usr_id') . "', NOW())");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
// Ce imamo napredni modul za belezenje casovc po straneh
if(SurveyInfo::getInstance()->checkSurveyModule('advanced_timestamps')){
sisplet_query("INSERT INTO srv_advanced_timestamps
(gru_id, usr_id, time_edit)
VALUES
('0', '".get('usr_id')."', NOW())
");
}
$this->set_userstatus(4);
}
if (get('loop_AW') == 0 && get('loop_id') == null) {
$grupa = Find::getInstance()->findNextGrupa();
}
elseif (get('loop_AW') == 1) {
$grupa = get('grupa');
}
elseif (get('loop_id') != null) {
$grupa = get('grupa');
save('loop_id', Find::getInstance()->findNextLoopId(), 1);
if (get('loop_id') == null)
$grupa = Find::getInstance()->findNextGrupa();
}
if (get('displayAllPages')) {
echo ' <script>' . "\n";
echo ' window.close();' . "\n";
if(Common::checkModule('gorenje'))
echo ' document.location.href=\'https://surveys.gorenje.com/\';' . "\n";
else
echo ' document.location.href=\'https://www.1ka.si/\';' . "\n";
echo ' </script>' . "\n";
}
elseif ($grupa > 0) {
save('grupa', $grupa);
if (get('loop_AW') == 0 && get('loop_id') == null)
header('Location: ' . SurveyInfo::getSurveyLink(false, false) . '&grupa=' . get('grupa') . Header::getSurveyParams() . get('cookie_url') . '');
elseif (get('loop_AW') == 1)
header('Location: ' . SurveyInfo::getSurveyLink(false, false) . '&grupa=' . get('grupa') . '&ime=' . get('ime_AW') . Header::getSurveyParams() . get('cookie_url') . '');
elseif (get('loop_id') != null)
header('Location: ' . SurveyInfo::getSurveyLink(false, false) . '&grupa=' . get('grupa') . '&loop_id=' . get('loop_id') . Header::getSurveyParams() . get('cookie_url') . '');
}
else {
// nastavimo status -- anketo je izpolnil do konca
$this->set_userstatus(6);
//prikaz konca ankete - pri glasovanju izpisujemo posebej zakljucek in statistiko
if ($rowa['survey_type'] == 0) {
Body::getInstance()->displayKonecGlasovanje();
} else {
Body::getInstance()->displayKonec();
}
}
}
}
}
}
// prisli smo cez vse silne procedure in redirecte, lahko pobrisemo cookie za referer, ker ga (upam) ne rabimo vec
setcookie('ref', '', time() - 5000); // pobrisemo cookie
}
/**
* Preverimo, če učitelj rešuje anketo in če že ima usr_id shranjen v bazi ali ga še ni
*
* @return mixed $cookie
*/
private function hierarhijaPreveriCeSeJeUciteljVrnilPonovnoResevatiAnketo()
{
$url = base64_decode(urldecode($this->get->enc));
$cookie = sisplet_query("SELECT su.cookie AS cookie FROM srv_hierarhija_koda AS shk LEFT JOIN srv_user AS su ON (shk.srv_user_id = su.id) WHERE url='" . $url . "'", "obj")->cookie;
return $cookie;
}
/************************************************
* Naložimo v kolikor imamo vkloplje print preview TRUE
************************************************/
private function loadIfPrintPreviewTrue()
{
$anketa = (isset($_GET['anketa'])) ? $_GET['anketa'] : ((isset($_POST['anketa'])) ? $_POST['anketa'] : die("Missing anketa id!"));
if (get('anketa') != $anketa)
save('anketa', $anketa);
// polovimo podatke o anketi
\SurveyInfo::getInstance()->SurveyInit(get('anketa'));
$db_table = \SurveyInfo::getInstance()->getSurveyArchiveDBString();
save('db_table', $db_table);
\SurveySetting::getInstance()->Init(get('anketa'));
if(isset($_REQUEST['usr_id']))
save('usr_id', $_REQUEST['usr_id']);
Language::getInstance()->multilang_init();
}
/************************************************
* Če gre za posebno testno anketo WebSMSruvey
************************************************/
private function jeWebSMSurvey()
{
// inicializiramo jezik za multilang anketo
$row = SurveyInfo::getInstance()->getSurveyRow();
if (isset($_GET['language'])) { // jezik podan preko GETa (podan je ze v linku ali spremenimo v previewu)
$sqll = sisplet_query("SELECT lang_id FROM srv_language WHERE ank_id='" . get('anketa') . "' AND lang_id='$_GET[language]'");
$rowl = mysqli_fetch_array($sqll);
save('lang_id', $rowl['lang_id']);
} elseif (isset($_POST['language'])) { // jezik podan v POSTu (ce si ga user spremeni na prvi strani)
save('lang_id', $_POST['language']);
}
if (get('lang_id') == null) { // ni bil podan preko GETa in ni shranjen v bazi -- priredimo default jezik
$_GET['language'] = self::$lang['id']; // to damo samo zato, da se shrani ID default jezika v bazo, namesto -1 (ker pri default jeziku ne podamo nič preko URLja)
// get('lang_id') mora se vedno ostati null !
} else { // zamenjamo jezik
$file = lang_path(get('lang_id'));
if (@include($file))
$_SESSION['langX'] = lang_path(get('lang_id'), 1);
}
// prikazemo header
Header::getInstance()->header();
if (!isset($_GET['grupa'])) {
if ($row['show_intro'] == 1) {
Body::getInstance()->displayIntroduction();
} else {
$grupa = save('grupa', Find::getInstance()->findNextGrupa(), 1);
if ($grupa > 0) {
if (isset($_GET['language']))
header('Location: ' . SurveyInfo::getSurveyLink(false, false) . '&grupa=' . get('grupa') . '&language=' . $_GET['language'] . '');
else
header('Location: ' . SurveyInfo::getSurveyLink(false, false) . '&grupa=' . get('grupa') . '');
} else {
Body::getInstance()->displayKonec();
}
}
} else {
save('grupa', $_GET['grupa']);
// pogledamo ce preskocimo kaksno stran zaradi branchinga
while (get('grupa') > 0 && $_GET['disableif'] != 1 && !Check::getInstance()->checkGrupa()) {
save('grupa', Find::getInstance()->findNextGrupa());
}
// nismo se poslali kaksno stran z odgovori
if (count($_POST) == 0) {
if (get('grupa') > 0)
Body::getInstance()->displayAnketa();
else
Body::getInstance()->displayKonec();
} // poslani so bili odgovori
else {
$grupa = Find::getInstance()->findNextGrupa();
save('grupa', $grupa, 1);
if ($grupa > 0) {
if (isset($_GET['language']))
header('Location: ' . SurveyInfo::getSurveyLink(false, false) . '&grupa=' . get('grupa') . '&language=' . $_GET['language'] . '');
else
header('Location: ' . SurveyInfo::getSurveyLink(false, false) . '&grupa=' . get('grupa') . '');
} else {
Body::getInstance()->displayKonec();
}
}
}
die();
}
/************************************************
* Tudi ce je zakljucena pustimo prikaz pri nastavljenem glas_end -> preklop arhiva statistike pri glasovanju - drugače izpišemo obvestilo o zaključku
************************************************/
private function anketaEnd($rowa)
{
if (get('lang_id') != null) $_lang = '_' . get('lang_id'); else $_lang = '';
SurveySetting::getInstance()->init(get('anketa'));
if ($rowa['active'] > 0) {
// preverimo začetek in konec
$sqlDates = sisplet_query("SELECT id, starts, expire, (IF(CURDATE() >= starts, true, false)) as boolStarts, (IF(CURDATE() <= expire, true, false)) as boolExpire FROM srv_anketa WHERE id='" . get('anketa') . "'");
$rowDates = mysqli_fetch_assoc($sqlDates);
if (!$rowDates['boolStarts']) {
$srv_survey_non_active_notStarted = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_survey_non_active_notStarted' . $_lang);
if ($srv_survey_non_active_notStarted == '') $srv_survey_non_active_notStarted = self::$lang['srv_survey_non_active_notStarted'];
Display::getInstance()->displayNapaka($srv_survey_non_active_notStarted . $rowDates['starts']);
}
if (!$rowDates['boolExpire']) {
$srv_survey_non_active_expired = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_survey_non_active_expired' . $_lang);
if ($srv_survey_non_active_expired == '') $srv_survey_non_active_expired = self::$lang['srv_survey_non_active_expired'];
Display::getInstance()->displayNapaka(self::$lang['srv_survey_non_active_expired'] . $rowDates['expire']);
}
} elseif ($rowa['active'] == 0) {
# anketa ni aktivna, preverimo ali je bila sploh aktivirana
$str = "SELECT count(*) FROM srv_activity WHERE sid = '" . get('anketa') . "'";
$qry = sisplet_query($str);
list($count_activity) = mysqli_fetch_row($qry);
if ($count_activity > 0) {
$srv_survey_non_active = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_survey_non_active' . $_lang);
if ($srv_survey_non_active == '') $srv_survey_non_active = self::$lang['srv_survey_non_active'];
Display::getInstance()->displayNapaka($srv_survey_non_active);
} else {
$srv_survey_non_active_notActivated = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_survey_non_active_notActivated' . $_lang);
if ($srv_survey_non_active_notActivated == '') $srv_survey_non_active_notActivated = self::$lang['srv_survey_non_active_notActivated'];
Display::getInstance()->displayNapaka($srv_survey_non_active_notActivated);
}
} else {
$srv_survey_deleted = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_survey_deleted' . $_lang);
if ($srv_survey_deleted == '') $srv_survey_deleted = self::$lang['srv_survey_deleted'];
Display::getInstance()->displayNapaka($srv_survey_deleted);
}
die();
}
// PANEL - Ce je nov respondent preverimo ce se je vrnil (ima isti SID) in mu nastavimo ustrezen cookie da ga preusmerimo na ustrezno stran
private function panelNovRespondent(){
$sp = new SurveyPanel(get('anketa'));
$panel_id_name = $sp->getPanelSettings('user_id_name');
$panel_id = ($panel_id_name != '' && isset($_GET[$panel_id_name])) ? $_GET[$panel_id_name] : 0;
if ($panel_id != '' && $panel_id != '0') {
$sqlPanel = sisplet_query("SELECT u.cookie
FROM srv_spremenljivka s, srv_grupa g, srv_data_text".get('db_table')." d, srv_user u
WHERE s.variable='".$panel_id_name."' AND s.gru_id=g.id AND g.ank_id='".get('anketa')."'
AND s.id=d.spr_id AND d.text='".$panel_id."'
AND u.id=d.usr_id AND u.deleted!='1'
");
if (mysqli_num_rows($sqlPanel) > 0) {
$rowPanel = mysqli_fetch_array($sqlPanel);
$cookie = $rowPanel['cookie'];
return $cookie;
}
}
}
// MODUL EMAIL DOSTOP - preverimo kodo mu nastavimo ustrezen cookie
private function emailDostopNovRespondent(){
$sp = new SurveyPanel(get('anketa'));
$panel_id_name = $sp->getPanelSettings('user_id_name');
$panel_id = ($panel_id_name != '' && isset($_GET[$panel_id_name])) ? $_GET[$panel_id_name] : 0;
if ($panel_id != '' && $panel_id != '0') {
$sqlPanel = sisplet_query("SELECT u.cookie
FROM srv_spremenljivka s, srv_grupa g, srv_data_text".get('db_table')." d, srv_user u
WHERE s.variable='".$panel_id_name."' AND s.gru_id=g.id AND g.ank_id='".get('anketa')."'
AND s.id=d.spr_id AND d.text='".$panel_id."'
AND u.id=d.usr_id AND u.deleted!='1'
");
if (mysqli_num_rows($sqlPanel) > 0) {
$rowPanel = mysqli_fetch_array($sqlPanel);
$cookie = $rowPanel['cookie'];
return $cookie;
}
}
}
// EVALVACIJA - Ce je nov respondent preverimo ce se je vrnil (zapis v tabeli eval_data_userCookie) in mu nastavimo ustrezen cookie da ga preusmerimo na ustrezno stran
private function evlavacijaNovRespondent(){
$student = (isset($_GET['sifstud'])) ? $_GET['sifstud'] : 0;
$predmet = (isset($_GET['sifpredm'])) ? $_GET['sifpredm'] : -1; // Ce resuje splosno anketo ni predmeta -> predmet = -1
if ($student > 0) {
$sqlE = sisplet_query("SELECT u.cookie AS cookie FROM eval_data_userCookie adu, srv_user u
WHERE adu.ank_id='" . get('anketa') . "' AND adu.student='" . $student . "' AND adu.predmet='" . $predmet . "'
AND u.ank_id='" . get('anketa') . "' AND u.id=adu.usr_id");
if (mysqli_num_rows($sqlE) > 0) {
$rowE = mysqli_fetch_array($sqlE);
$cookie = $rowE['cookie'];
return $cookie;
}
}
}
/************************************************
* Če cookie obstaja ga samo preberemo
************************************************/
protected $cookie;
private function cookieExist($cookie)
{
$rowa = SurveyInfo::getInstance()->getSurveyRow();
$sql = sisplet_query("SELECT id, user_id FROM srv_user WHERE cookie='$cookie' AND deleted='0' LIMIT 1");
$row = mysqli_fetch_array($sql);
if ($row['id'] > 0) {
save('usr_id', $row['id']);
// cookie se enkrat nastavmo, ce se je kaj spreminjal nastavitve expire-ja
$this->set_cookie('survey-' . get('anketa'), $cookie, $this->expire);
// v primeru da je cookie ze bil postavljen, pa da se ni bilo povezave s sisplet userjem, ga 'povezemo'
if ($rowa['user_from_cms'] >= 1)
if ($row['user_id'] == 0 && self::$global_user_id > 0)
$sql = sisplet_query("UPDATE srv_user SET user_id = '" . self::$global_user_id . "' WHERE cookie = '$cookie'");
// Preverimo, ce je ze koncal anketo (in se kasneje vrnil), ce lahko se ureja svoje odgovore
// Dodano v pogoj da se to izvede samo ce nima nastavljene grupe (drugace dela narobe klik nazaj na zakljucku, preklop med bloki...)
if ($rowa['return_finished'] == 0 && !isset($_GET['grupa']) && !isset($_GET['urejanje']) && !isset($_GET['return']) && !SurveyInfo::getInstance()->checkSurveyModule('panel')) {
$sqls = sisplet_query("SELECT MAX(status) AS status FROM srv_userstatus WHERE usr_id='" . get('usr_id') . "'");
$rows = mysqli_fetch_array($sqls);
if ($rows['status'] == 6) { // Koncal anketo
Header::getInstance()->header();
Body::getInstance()->displayKonec();
die();
}
}
// ce ze ima kuki in ni poslana grupa pomeni, da se je vrnil se enkrat resevat anketo
if (!isset($_GET['grupa'])) {
Check::getInstance()->check_cookie_return();
}
} else { // dodatno preverjanje, ce se slucajno kaj sfizi, pa da ni tega cookieja v bazi, ga moramo se enkrat nastavit
$this->cookie = null;
}
}
/************************************************
* Cookie ni nastavljen is null
************************************************/
private function cookieIsNull()
{
if (get('lang_id') != null) $_lang = '_' . get('lang_id'); else $_lang = '';
$rowa = SurveyInfo::getInstance()->getSurveyRow();
//preverjamo limit stevila glasov
if ((!isset($_GET['preview']) || $_GET['preview'] != 'on') && ($rowa['vote_limit'] == 1 || $rowa['vote_limit'] == 2)) {
// preverimo ce smo presegli limit
// Stetje samo ustreznih odgovorov
if ($rowa['vote_limit'] == 2)
$sqlVotes = sisplet_query("SELECT COUNT(id) FROM srv_user WHERE ank_id='" . get('anketa') . "' AND (last_status='5' OR last_status='6') AND lurker='0' AND deleted='0'");
// Stetje vseh odgovorov
else
$sqlVotes = sisplet_query("SELECT COUNT(id) FROM srv_user WHERE ank_id='" . get('anketa') . "' AND deleted='0'");
$rowVotes = mysqli_fetch_assoc($sqlVotes);
if ($rowa['vote_count'] <= $rowVotes['COUNT(id)']) {
//$this->display->displayNapaka(self::$lang['srv_survey_non_active_voteLimit'].' ('.$rowa['vote_count'].')');
$srv_survey_non_active_voteLimit = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_survey_non_active_voteLimit' . $_lang);
if ($srv_survey_non_active_voteLimit == '') $srv_survey_non_active_voteLimit = self::$lang['srv_survey_non_active_voteLimit'];
Display::getInstance()->displayNapaka($srv_survey_non_active_voteLimit);
die();
}
}
// splosna koda za dostop do ankete (brez prepoznave userja) - dodatno preverimo ce je ta funkcionalnost na voljo v paketu
$userAccess = UserAccess::getInstance(self::$global_user_id);
$sqlp = sisplet_query("SELECT password FROM srv_password WHERE ank_id='" . get('anketa') . "'");
if (mysqli_num_rows($sqlp) > 0 && $userAccess->checkUserAccess($what='password')) {
$ok = false;
while ($rowp = mysqli_fetch_array($sqlp)) {
if (isset($_POST['password']) && $rowp['password'] == $_POST['password'] /*|| $_COOKIE['password_' .get('anketa')] == $rowp['password']*/) {
setcookie('password_' . get('anketa'), $rowp['password']);
$ok = true;
}
}
if (!$ok) {
Header::getInstance()->header();
Body::getInstance()->displayIntroduction();
die();
}
}
// preverimo, ce blokiramo IP (to nardimo, samo ce se ni kukija - drugac bi ga takoj zablokiral (ce pa je kuki se ga pa itak prepoza pa potem shendla))
if ($rowa['block_ip'] > 0) {
$sqlip = sisplet_query("SELECT id FROM srv_user WHERE ank_id='" . get('anketa') . "' AND ip='" . Helper::remote_address() . "' AND time_edit >= NOW() - INTERVAL $rowa[block_ip] MINUTE");
if (mysqli_num_rows($sqlip) > 0) { // je ze dostopal iz tega IPja
Header::getInstance()->header();
Body::getInstance()->displayKonec();
die();
}
}
if (self::$global_user_id == 0) {
$row1['id'] = 0;
}
else {
$sql1 = sisplet_query("SELECT id, cookie FROM srv_user WHERE user_id = '" . self::$global_user_id . "' AND user_id > 0 AND ank_id = '" . get('anketa') . "'");
if(mysqli_num_rows($sql1) > 0)
$row1 = mysqli_fetch_array($sql1);
else
$row1['id'] = 0;
}
// ce je izbrana povezava s sisplet userjem in da smo najdl cookie za trenutnega userja, potem nastavimo ta cookie
if ($row1['id'] > 0 && $rowa['user_from_cms'] == 1) {
$rand = $row1['cookie'];
$this->set_cookie('survey-' . get('anketa'), $rand, $this->expire);
save('usr_id', $row1['id']);
// Preverimo, ce je ze koncal anketo (in se kasneje vrnil), ce lahko se ureja svoje odgovore
if ($rowa['return_finished'] == 0) {
$sqls = sisplet_query("SELECT MAX(status) AS status FROM srv_userstatus WHERE usr_id='" . get('usr_id') . "'");
$rows = mysqli_fetch_array($sqls);
if ($rows['status'] == 6) { // Koncal anketo
Header::getInstance()->header();
Body::getInstance()->displayKonec();
die();
}
}
// ce ze ima kuki in ni poslana grupa pomeni, da se je vrnil se enkrat resevat anketo
if (!isset($_GET['grupa'])) {
Check::getInstance()->check_cookie_return();
}
}
// userji iz baze
elseif (
($rowa['user_base'] == 1) &&
#če imamo neindividualizirana vabila - poslana preko vabil, vendar bez kode in zato brez sledenja (uporabnik se pri pošiljanju NE prenese iz srv_invitations_recipients v srv_user)
$rowa['individual_invitation'] != 0 &&
( // Omogoči anketo tudi respodentom, ki niso v bazi
($rowa['usercode_skip'] == 0) // Ne (vsi grejo sem not, ker morajo nujno vnesti kodo)
|| ($rowa['usercode_skip'] == 1 /*&& (isset($_POST['usercode']) or isset($_GET['code']))*/) // Da (sem not grejo samo, ce so vnesli kodo, da jih prepoznamo, sicer grejo na else in dobijo nov cookie)
|| ($rowa['usercode_skip'] == 2 && (!get('userAutor') || (isset($_POST['usercode']) or isset($_GET['code'])))) // Samo avtor (ce ni avtor ankete, gre sem noter in mora vnesti kodo. Avtor ankete pa gre sem notr samo ce je podana koda, sicer gre na else in dobi nov cookie)
// Respondenti naj vedno vnesejo kodo: Da
|| ($rowa['usercode_required'] == 1 && $rowa['usercode_skip'] != 1 &&
( // Omogoči anketo tudi respodentom, ki niso v bazi
$rowa['usercode_skip'] == 0 // Ne (vsi grejo sem not, ker morajo nujno vnesti kodo)
|| ($rowa['usercode_skip'] == 2 && !get('userAutor') /*&& ( !$userAutor || $userAutor || (isset($_POST['usercode']) or isset($_GET['code'])) )*/) // Samo avtor (ce ni avtor ankete, gre sem noter in mora vnesti kodo. Avtor ankete pa gre sem notr samo ce je podana koda, sicer gre na else in dobi nov cookie)
) // ^ tale pogoj zgoraj se ni cist ok, ker mora tudi avtor vnesti kodo - AVTORJU NI TREBA VNEST KODE CE JE TO VKLOPLJENO - dodan && !get('userAutor')
)
)
) {
if (isset($_POST['usercode']) or isset($_GET['code'])) {
if (isset($_POST['usercode']))
$usercode = strtolower($_POST['usercode']);
elseif (isset($_GET['code']))
$usercode = strtolower($_GET['code']);
else
die();
$sql2 = sisplet_query("SELECT id, recnum, cookie FROM srv_user WHERE TRIM(pass) = '$usercode' AND ank_id='".get('anketa')."' AND deleted='0'");
if (!$sql2) echo mysqli_error($GLOBALS['connect_db']);
$row2 = mysqli_fetch_array($sql2);
// Pravilna koda
if (mysqli_num_rows($sql2) > 0) {
// Ce imamo vklopljen modul za volitve preskocimo kar nekaj korakov (anonimizacija)
if(!SurveyInfo::checkSurveyModule('voting')){
// Dodatno preverimo ce koda se ni potekla
$sqlC = sisplet_query("SELECT * FROM srv_invitations_recipients WHERE ank_id='".get('anketa')."' AND TRIM(password)='".$usercode."' AND DATE(NOW())>DATE(date_expired) AND date_expired!='0000-00-00 00:00:00'");
if(mysqli_num_rows($sqlC) > 0){
Display::getInstance()->displayNapaka(self::$lang['srv_expiredcode']);
die();
}
# nastavimo še da je uporabnik odgovoril na anketo za nov način e-mail vabil
sisplet_query("UPDATE srv_invitations_recipients SET responded = '1', date_responded = NOW() WHERE ank_id='" . get('anketa') . "' AND TRIM(password) ='$usercode' AND responded = '0'");
sisplet_query("COMMIT");
}
$rand = $row2['cookie'];
$this->set_cookie('survey-' . get('anketa'), $rand, $this->expire);
save('usr_id', $row2['id']);
// Preverimo ce imamo vklopljeno da uporabnik nadaljuje kjer je ostal - potem ga preusmerimo na pravo stran
Check::getInstance()->check_cookie_return();
if ($row2['recnum'] == 0) {
if (isset($_POST['referer']))
$referer = $_POST['referer'];
elseif (isset($_SERVER['HTTP_REFERER']))
$referer = $_SERVER['HTTP_REFERER'];
else
$referer = 0;
SurveySetting::getInstance()->Init(get('anketa'));
$ip = SurveySetting::getInstance()->getSurveyMiscSetting('survey_ip');
$browser = SurveySetting::getInstance()->getSurveyMiscSetting('survey_browser');
$referal = SurveySetting::getInstance()->getSurveyMiscSetting('survey_referal');
$date = SurveySetting::getInstance()->getSurveyMiscSetting('survey_date');
if ($ip == 0 || $ip == '') $_ip = Helper::remote_address(); else $ip = "";
if ($date == 0 || $date == '') $_time_insert = "NOW()"; else $_time_insert = "''";
if ($referal == 0 || $referal == '') $_referer = $referer; else $_referer = '';
if ($browser == 0 || $browser == '') $_useragent = $_SERVER['HTTP_USER_AGENT']; else $_useragent = '';
// Ce dovolimo useragent in ce je instaliran browscap
$_browser = '';
$_device = 0;
$_os = '';
if ($_useragent != '' && get_cfg_var('browscap')) {
$browser_detect = get_browser($_useragent, true);
$detect = New \Detection\MobileDetect;
$detect->setUserAgent($_useragent);
// Detect browserja
if ($browser_detect['browser'] == 'Default Browser')
$_browser = self::$lang['srv_para_graph_other'];
else
$_browser = $browser_detect['browser'] . ' ' . $browser_detect['version'];
// Detect naprave (pc, mobi, tablet, robot)
if ($detect->isMobile()) {
if ($detect->isTablet())
$_device = 2;
else
$_device = 1;
}
elseif (isset($browser_detect['crawler']) && $browser_detect['crawler'] == 1)
$_device = 3;
else
$_device = 0;
// Detect operacijskega sistema
if ($browser_detect['platform'] == 'unknown')
$_os = self::$lang['srv_para_graph_other'];
else
$_os = $browser_detect['platform'];
}
$recnum = 0;
if (isset($_GET['language'])) save('language', (int)$_GET['language']); else save('language', self::$lang['id']);
$s = sisplet_query("UPDATE srv_user SET recnum = MAX_RECNUM('" . get('anketa') . "'), time_insert=" . $_time_insert . ", language='" . get('language') . "', ip='" . $_ip . "', useragent='" . $_useragent . "', device='" . $_device . "', browser='" . $_browser . "', os='" . $_os . "' WHERE id = '" . get('usr_id') . "'");
if (!$s) {
echo 'err3432' . mysqli_error($GLOBALS['connect_db']);
die();
}
}
// Preverimo, ce je ze koncal anketo (in se kasneje vrnil), ce lahko se ureja svoje odgovore
if ($rowa['return_finished'] == 0) {
$sqls = sisplet_query("SELECT MAX(status) AS status FROM srv_userstatus WHERE usr_id='" . get('usr_id') . "'");
$rows = mysqli_fetch_array($sqls);
if ($rows['status'] == 6) { // Koncal anketo
Header::getInstance()->header();
Body::getInstance()->displayKonec();
die();
}
}
// ce ze ima kuki in ni poslana grupa pomeni, da se je vrnil se enkrat resevat anketo
if (!isset($_GET['grupa'])) {
Check::getInstance()->check_cookie_return();
}
}
else { // koda ne obstaja
//#TODO Tukaj preverimo userja iz novih e-mail vabil
if ($rowa['usercode_skip'] != 1 && !($_GET['preview'] == 'on' && isset($_GET['disablecode']) && $_GET['disablecode'] == 1)) {
// Pri Ne in Samo avtor prikazemo obvestilo, pri Da spustimo naprej in kreiramo nov cookie
SurveySetting::getInstance()->init(get('anketa'));
$srv_wrongcode = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_wrongcode' . $_lang);
if ($srv_wrongcode == '') $srv_wrongcode = self::$lang['srv_wrongcode'];
Display::getInstance()->displayNapaka($srv_wrongcode);
die();
}
}
} else {
# če imamo formo
if ($rowa['survey_type'] == 1) {
# TODO.. Mitja, tu je treba vse pravilno pohandlat.. men se niti sanja ne kak in kaj
# problem pri formi je da ko enkrat pošlješ email vabilo, potem vedno prikazuje header
// TODO: kolk casa je ze tole tukaj? :) -mitja
# TODO: ziher več kot leto in pol. :) tak da ni neskončno pomembno
}
else {
// baza respondentov - ce ni poslana koda
Language::getInstance()->multilang_init();
Header::getInstance()->header();
Body::getInstance()->displayIntroduction();
die();
}
}
}
// Kolektor modul - respondent s kodo - poenostavljeno vabilo
elseif(Common::checkModule('kolektor') == '1' && isset($_GET['code'])) {
$usercode = strtolower($_GET['code']);
$sql2 = sisplet_query("SELECT id, recnum, cookie FROM srv_user WHERE TRIM(pass) = '$usercode' AND ank_id='".get('anketa')."' AND deleted='0'");
if (!$sql2) echo mysqli_error($GLOBALS['connect_db']);
$row2 = mysqli_fetch_array($sql2);
// Pravilna koda
if (mysqli_num_rows($sql2) > 0) {
$rand = $row2['cookie'];
$this->set_cookie('survey-' . get('anketa'), $rand, $this->expire);
save('usr_id', $row2['id']);
// Preverimo ce imamo vklopljeno da uporabnik nadaljuje kjer je ostal - potem ga preusmerimo na pravo stran
Check::getInstance()->check_cookie_return();
if ($row2['recnum'] == 0) {
if (isset($_POST['referer']))
$referer = $_POST['referer'];
elseif (isset($_SERVER['HTTP_REFERER']))
$referer = $_SERVER['HTTP_REFERER'];
else
$referer = 0;
SurveySetting::getInstance()->Init(get('anketa'));
$ip = SurveySetting::getInstance()->getSurveyMiscSetting('survey_ip');
$browser = SurveySetting::getInstance()->getSurveyMiscSetting('survey_browser');
$referal = SurveySetting::getInstance()->getSurveyMiscSetting('survey_referal');
$date = SurveySetting::getInstance()->getSurveyMiscSetting('survey_date');
if ($ip == 0 || $ip == '') $_ip = Helper::remote_address(); else $ip = "";
if ($date == 0 || $date == '') $_time_insert = "NOW()"; else $_time_insert = "''";
if ($referal == 0 || $referal == '') $_referer = $referer; else $_referer = '';
if ($browser == 0 || $browser == '') $_useragent = $_SERVER['HTTP_USER_AGENT']; else $_useragent = '';
// Ce dovolimo useragent in ce je instaliran browscap
$_browser = '';
$_device = 0;
$_os = '';
if ($_useragent != '' && get_cfg_var('browscap')) {
$browser_detect = get_browser($_useragent, true);
$detect = New \Detection\MobileDetect;
$detect->setUserAgent($_useragent);
// Detect browserja
if ($browser_detect['browser'] == 'Default Browser')
$_browser = self::$lang['srv_para_graph_other'];
else
$_browser = $browser_detect['browser'] . ' ' . $browser_detect['version'];
// Detect naprave (pc, mobi, tablet, robot)
if ($detect->isMobile()) {
if ($detect->isTablet())
$_device = 2;
else
$_device = 1;
}
elseif (isset($browser_detect['crawler']) && $browser_detect['crawler'] == 1)
$_device = 3;
else
$_device = 0;
// Detect operacijskega sistema
if ($browser_detect['platform'] == 'unknown')
$_os = self::$lang['srv_para_graph_other'];
else
$_os = $browser_detect['platform'];
}
$recnum = 0;
if (isset($_GET['language'])) save('language', (int)$_GET['language']); else save('language', self::$lang['id']);
$s = sisplet_query("UPDATE srv_user SET recnum = MAX_RECNUM('" . get('anketa') . "'), time_insert=" . $_time_insert . ", language='" . get('language') . "', ip='" . $_ip . "', useragent='" . $_useragent . "', device='" . $_device . "', browser='" . $_browser . "', os='" . $_os . "' WHERE id = '" . get('usr_id') . "'");
if (!$s) {
echo 'err3432' . mysqli_error($GLOBALS['connect_db']);
die();
}
}
// Preverimo, ce je ze koncal anketo (in se kasneje vrnil), ce lahko se ureja svoje odgovore
if ($rowa['return_finished'] == 0) {
$sqls = sisplet_query("SELECT MAX(status) AS status FROM srv_userstatus WHERE usr_id='" . get('usr_id') . "'");
$rows = mysqli_fetch_array($sqls);
if ($rows['status'] == 6) { // Koncal anketo
Header::getInstance()->header();
Body::getInstance()->displayKonec();
die();
}
}
// ce ze ima kuki in ni poslana grupa pomeni, da se je vrnil se enkrat resevat anketo
if (!isset($_GET['grupa'])) {
Check::getInstance()->check_cookie_return();
}
}
// koda ne obstaja
else {
// Pri Ne in Samo avtor prikazemo obvestilo, pri Da spustimo naprej in kreiramo nov cookie
SurveySetting::getInstance()->init(get('anketa'));
$srv_wrongcode = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_wrongcode' . $_lang);
if ($srv_wrongcode == '') $srv_wrongcode = self::$lang['srv_wrongcode'];
Display::getInstance()->displayNapaka($srv_wrongcode);
die();
}
}
// drugace gremo kreirat nov cookie
if (get('usr_id') == null) {
// Najprej preverimo limit responsov na anketi - zaenkrat ne naredimo nic, samo posljemo mail ko je limit dosezen
$check = new SurveyCheck(get('anketa'));
if($check->checkLimitResponses()){
/*Display::getInstance()->displayNapaka(self::$lang['srv_survey_repsonse_limit']);
die();*/
}
// izberemo random hash, ki se ni v bazi
do {
$rand = md5(mt_rand(1, mt_getrandmax()) . '@' . Helper::remote_address());
$sql = sisplet_query("SELECT id FROM srv_user WHERE cookie = '$rand'");
} while (mysqli_num_rows($sql) > 0);
$this->set_cookie('survey-' . get('anketa'), $rand, $this->expire);
// ce je izbrana povezava s sisplet userjem, ga povezemo
if ($rowa['user_from_cms'] >= 1) {
$sqlu = Model::db_select_user(self::$global_user_id);
$rowu = mysqli_fetch_array($sqlu);
} else
$rowu['id'] = 0;
if (isset($_GET['preview']) && $_GET['preview'] == 'on') {
$preview = 1;
} else {
$preview = 0;
}
# če smo v prezentaciji (slideshow) in ne beležimo vnosov jih označimo kot preview = 1
if (isset($rowa['slideshow']) && $rowa['slideshow'] == 1) {
$ss = new SurveySlideshow(get('anketa'));
$ss_setings = $ss->getSettings();
# če beležimo vnose: save_entries == 1
if ($ss_setings['save_entries'] == 0) {
$preview = 1;
}
}
$testdata = 0;
if (isset($_GET['testdata']) && $_GET['testdata'] == 'on') {
$preview = 0;
$testdata = 1;
}
if (isset($_POST['referer']))
$referer = $_POST['referer'];
elseif (isset($_SERVER['HTTP_REFERER']))
$referer = $_SERVER['HTTP_REFERER'];
else
$referer = 0;
SurveySetting::getInstance()->Init(get('anketa'));
$ip = SurveySetting::getInstance()->getSurveyMiscSetting('survey_ip');
$browser = SurveySetting::getInstance()->getSurveyMiscSetting('survey_browser');
$referal = SurveySetting::getInstance()->getSurveyMiscSetting('survey_referal');
$date = SurveySetting::getInstance()->getSurveyMiscSetting('survey_date');
if ($ip == 0 || $ip == '') $_ip = Helper::remote_address(); else $_ip = "";
if ($date == 0 || $date == '') $_time_insert = "NOW()"; else $_time_insert = "''";
if ($referal == 0 || $referal == '') $_referer = $referer; else $_referer = '';
if ($browser == 0 || $browser == '') $_useragent = $_SERVER['HTTP_USER_AGENT']; else $_useragent = '';
// Ce dovolimo useragent in ce je instaliran browscap
$_browser = '';
$_device = 0;
$_os = '';
if ($_useragent != '' && get_cfg_var('browscap')) {
$browser_detect = get_browser($_useragent, true);
$detect = New \Detection\MobileDetect;
$detect->setUserAgent($_useragent);
// Detect browserja
if ($browser_detect['browser'] == 'Default Browser')
$_browser = self::$lang['srv_para_graph_other'];
else
$_browser = $browser_detect['browser'] . ' ' . $browser_detect['version'];
// Detect naprave (pc, mobi, tablet, robot)
if ($detect->isMobile()) {
if ($detect->isTablet())
$_device = 2;
else
$_device = 1;
}
elseif (isset($browser_detect['crawler']) && $browser_detect['crawler'] == 1)
$_device = 3;
else
$_device = 0;
// Detect operacijskega sistema
if ($browser_detect['platform'] == 'unknown')
$_os = self::$lang['srv_para_graph_other'];
else
$_os = $browser_detect['platform'];
}
if (isset($_GET['language'])) save('language', (int)$_GET['language']); else save('language', self::$lang['id']);
$recnum = 0;
$sql = sisplet_query("INSERT INTO srv_user (id, ank_id, preview, testdata, cookie, user_id, ip, time_insert, recnum, referer, useragent, device, browser, os, language) VALUES (0, '" . get('anketa') . "', '$preview', '$testdata', '$rand', '$rowu[id]', '" . $_ip . "', " . $_time_insert . ", MAX_RECNUM('" . get('anketa') . "'), '" . $_referer . "', '" . $_useragent . "', '" . $_device . "', '" . $_browser . "', '" . $_os . "', '" . get('language') . "')");
if (!$sql) {
echo 'err3431' . mysqli_error($GLOBALS['connect_db']);
die();
}
save('usr_id', mysqli_insert_id($GLOBALS['connect_db']), 1);
//sisplet_query("COMMIT");
# če je testni vnos in če že imamo skreirano datoteko s podatki v kateri še ni označeno da imamo testem je potrebno generirati na novo
if ((int)$testdata > 0) {
$head_file_name = self::$site_path . 'admin/survey/SurveyData/export_header_' . get('anketa') . '.dat';
if (file_exists($head_file_name)) {
$header = unserialize(file_get_contents($head_file_name));
if ((int)$header['_settings']['hasTestData'] == 0) {
unlink($head_file_name);
}
}
}
//potrebuje se za modul MAZA - za povezavo respondenta med tebelama maza_app_users in srv_user
if(SurveyInfo::checkSurveyModule('maza')){
//error_log(json_encode($_GET));
$maza = new MAZA(get('anketa'));
//check if id and identifier match
if($_GET['maza_user_id'] && ($maza->maza_validate_user($_GET['maza_user_id'], $_GET['maza_identifier']))){
//update last_active of user
$maza->maza_update_user_active($_GET['maza_user_id']);
//insert pair of users id's in DB table
$maza->maza_save_srv_user($_GET['maza_user_id'], get('usr_id'), $_GET['maza_srv_version'], $_GET['maza_tgeofence_id'], $_GET['maza_tactivity_id'], $_GET['maza_mode']);
}
}
// EVALVACIJA - Ce je nov respondent se to zapise v posebno tabelo, da ga prepoznamo naslednjic brez cookija (da lahko nadaljuje kjer je ostal)
if (Common::checkModule('evalvacija') == '1') {
$student = (isset($_GET['sifstud'])) ? $_GET['sifstud'] : 0;
$predmet = (isset($_GET['sifpredm'])) ? $_GET['sifpredm'] : -1; // Ce resuje splosno anketo ni predmeta -> predmet = -1
if ($student > 0)
sisplet_query("INSERT INTO eval_data_userCookie (ank_id, usr_id, student, predmet) VALUES ('" . get('anketa') . "', '" . get('usr_id') . "', '" . $student . "', '" . $predmet . "')");
}
// V kolikor gre za hierarhijo in je respondent učitelj, potem usr_id shranimo, da lahko obnovimo anketo
if (Common::checkModule('hierarhija') == '1' && SurveyInfo::checkSurveyModule('hierarhija') == 2) {
$url = base64_decode(urldecode($this->get->enc));
$polje = sisplet_query("SELECT koda, vloga FROM srv_hierarhija_koda WHERE url='" . $url . "'", "obj");
if ($polje->vloga == 'ucitelj')
sisplet_query("UPDATE srv_hierarhija_koda SET srv_user_id='" . get('usr_id') . "' WHERE url='" . $url . "'");
// V kolikor gre za super šifro potem shranimo v bazo, uporabnika in katero anketo je reševal.
if (!empty($this->get->supersifra)) {
$kode = sisplet_query("SELECT kode FROM srv_hierarhija_supersifra WHERE koda='".$this->get->supersifra."'", "obj");
$kode = unserialize($kode->kode);
sisplet_query("INSERT INTO
srv_hierarhija_supersifra_resevanje
(user_id, supersifra, koda, status)
VALUES
('".get('usr_id')."', '".$this->get->supersifra."', '".$kode[$this->get->resujem]."', 1)
");
}
}
}
}
/**
* nastavi cookie, oz. v primeru ankete brez cookieja, nastavi spremenljivko za url
*/
protected $anketa, $rand, $expire;
private function set_cookie($anketa, $rand, $expire){
// ce je nastavljeno na brez piskotka
if (get('cookie_expire') == -1) { // cookie prenasamo preko URLja
save('cookie_url', '&' . $anketa . '=' . $rand); // ta string se bo dodal vsem URLjem na konec
// & dodamo naknadno samo tam, kjer se pise v html (v header() more bit samo &)
}
else {
setcookie($anketa, $rand, $expire); // ce je cookie, ga obicajno nastavimo
}
}
/**
* @desc nastavi status za trenutnega userja
*/
private function set_userstatus($status)
{
$sql_userbase = sisplet_query("SELECT MAX(tip) AS tip FROM srv_userbase WHERE usr_id = '" . get('usr_id') . "'");
if (!$sql_userbase) echo mysqli_error($GLOBALS['connect_db']);
$row_userbase = mysqli_fetch_array($sql_userbase);
if ($row_userbase['tip'] > 0) {
$tip = $row_userbase['tip'];
}
else {
$tip = 0;
}
$sqlu = sisplet_query("SELECT MAX(status) AS status FROM srv_userstatus WHERE usr_id = '" . get('usr_id') . "'");
if (!$sqlu) echo mysqli_error($GLOBALS['connect_db']);
$rowu = mysqli_fetch_array($sqlu);
$sqlu = sisplet_query("SELECT inv_res_id FROM srv_user WHERE id = '" . get('usr_id') . "' AND inv_res_id IS NOT NULL");
$inv_res_id = null;
if (mysqli_num_rows($sqlu) > 0) {
# userj je dodan preko novih vabil zato updejtamo status še tam
$row_inv_res_id = mysqli_fetch_assoc($sqlu);
$inv_res_id = (int)$row_inv_res_id['inv_res_id'];
}
// spremenimo tip
if ($status > $rowu['status'] && is_numeric(get('usr_id'))) {
$s = sisplet_query("REPLACE INTO srv_userstatus (usr_id, tip, status, datetime) VALUES ('" . get('usr_id') . "', '$tip', '$status', NOW())");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
SurveySetting::getInstance()->Init(get('anketa'));
$date = SurveySetting::getInstance()->getSurveyMiscSetting('survey_date');
if ($date == 0 || $date == '') $_time_insert = "NOW()"; else $_time_insert = "''";
if (isset($_GET['language'])) save('language', (int)$_GET['language']); else save('language', self::$lang['id']);
$s = sisplet_query("UPDATE srv_user SET last_status = '$status', time_edit = " . $_time_insert . ", language='" . get('language') . "' WHERE id = '" . get('usr_id') . "'");
if (!$s) {
echo mysqli_error($GLOBALS['connect_db']);
die();
}
# updejtamo še status pri respondentih.
if ((int)$inv_res_id > 0) {
# userj je dodan preko novih vabil zato updejtamo status še tam
$sqlString = "UPDATE srv_invitations_recipients SET last_status='$status' WHERE ank_id='" . get('anketa') . "' AND id ='$inv_res_id' ";
$u = sisplet_query($sqlString);
}
// Modul kolektor - shranimo poseben status "koncano - 5" in posljemo opomnik
if(Common::checkModule('kolektor') == '1' && $status == '6'){
$kr = new KolektorResponse(get('usr_id'));
$kr->setStatus($kolektor_status='5');
}
}
// updatamo samo datum - tip se ni spremenil
else {
SurveySetting::getInstance()->Init(get('anketa'));
$date = SurveySetting::getInstance()->getSurveyMiscSetting('survey_date');
if ($date == 0 || $date == '') $_time_insert = "NOW()"; else $_time_insert = "''";
if (isset($_GET['language'])) save('language', (int)$_GET['language']); else save('language', self::$lang['id']);
# osvežimo datum spremembe
sisplet_query("UPDATE srv_user SET time_edit = " . $_time_insert . ", language='" . get('language') . "' WHERE id='" . get('usr_id') . "'");
}
// Ce ne belezimo parapodatka za cas responsa, anonimno zabelezimo cas zadnjega responsa
if(SurveySetting::getInstance()->getSurveyMiscSetting('survey_date') == 1) {
sisplet_query("UPDATE srv_anketa SET last_response_time=NOW() WHERE id='".get('anketa')."'");
}
# dodamo še tracking arhivov vabil
if (get('user_inv_archive') > 0 && $inv_res_id > 0) {
# ignoriramo podvojene kluče
$s = sisplet_query("INSERT IGNORE INTO srv_invitations_tracking
(inv_arch_id, time_insert, res_id, status)
VALUES
('" . (int)get('user_inv_archive') . "',NOW(),'$inv_res_id','$status')
");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
else {
}
# potrebno bo osvežit seznam anket
Model::setUpdateSurveyList();
}
}
|