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
|
<?php
/* Za potrebe kopiranja ankete
*
* lahko v okviru istega strežnika ali pa iz strežnika na strežnik oz v datoteko
*
* Tabele ki se avtomatsko prilagajajo in kopirajo:
* - fixed, sedaj se vse prilagajajo
*
*
* Created on 23.02.2010
*
* UPDATES:
* 24.02.2001 - nov način kopiranja, večina tabel se avtomatsko prilagodi (razen pogojev)
* 23.11.2010 - spremenjeno, da se vse tabele klicejo preko preformCopyTable() - funkcijo sem tudi malo spremenil, je komentar -mitja
* 24.11.2010 - dela z bazo ver. 10.11.24 za naprej je treba dodajati samo nove tabele. obstojece tabele se vse cele kopirajo
* 04.04.2011 - spremenljen način kopiranja, da gre najprej vse v 1 array, potem pa se bere iz arraya (da omogocimo export - import v datoteko)
*
*
* TODO:
*
* preimenovat funckijo preform.. v perform... :)
*
*/
class SurveyCopy {
static private $inited = null; #je inicializiran, ali imamo vse podatke
static private $src_survey = null; #izvorna anketa
static private $src_connect_db = null; #db povezava na izvorna streznik
static private $dest_connect_db = null; #db povezava na streznik kamor kopiramo
static private $destSite = 0;
static private $errors = null; #array z napakami
static private $source_array = null;
public static function setSrcSurvey($srcSurvey){
self :: $src_survey = $srcSurvey;
}
public static function setSrcConectDb($src_connect_db){
self :: $src_connect_db = $src_connect_db;
}
public static function setDestSite($destSite = 0) {
$connect_db2 = null;
// mitja - kopiranje na localhost
if ($destSite == -1 && isset ($_GET['ip'])) {
self::$destSite = -1;
$ip = $_GET['ip'];
$connect_db2 = $GLOBALS['connect_db'] = mysqli_connect($ip, 'mitja', 'geslo');
$sql = mysqli_select_db($GLOBALS['connect_db'], "sisplet", $connect_db2);
if (!$sql) {
self :: $errors[] = mysqli_error($GLOBALS['connect_db']);
}
} elseif ($destSite == 0) { // backup
self::$destSite = 0;
if ( self :: $src_connect_db != null )
$connect_db2 = self :: $src_connect_db;
else {
self :: $errors[] = "Src connection is missing! ".mysqli_error($GLOBALS['connect_db']);
}
} elseif ($destSite > 0) { // kopiranje na drug server
self::$destSite = $destSite;
// Predlagam da se tole da v locen config fajl!
// v /etc/hosts (windows: %SystemRoot%\System32\drivers\etc\hosts ) vpisi serverje (server1, server2,...)
// da se ne bo v kodi vleklo ime pravega serverja!!!
global $site_path;
$servers_array = array (
'1' => array('mirisorg', 'server1'),
'2' => array('www1kasi', 'server4'),
'3' => array('wwwrisorg', 'server1'),
'4' => array('wwwfdvinfonet', 'server1'),
'5' => array('wwwsafesi', 'server1'),
'6' => array('praksafdvinfonet', 'server1'),
'7' => array('skin1kasi', 'server2'),
'8' => array('back1kasi', 'server2'),
'9' => array('back14031kasi', 'server2'),
'10' => array('back30031kasi', 'server2'),
'11' => array('pizza1kasi', 'server3'),
'12' => array('fdv1kasi', 'server2'),
'13' => array('ef1kasi', 'server2'),
'14' => array('20101kasi', 'server2'),
'15' => array('new1kasi', 'server2'),
'16' => array('beta1kasi', 'server4'),
'17' => array('www1cssi', 'server4')
);
$server = $servers_array[$destSite][1];
$db = $servers_array[$destSite][0];
$connect_db2 = $GLOBALS['connect_db'] = mysqli_connect($server, 'survey_push', 'survey_push');
$sql = mysqli_select_db($GLOBALS['connect_db'],$db, $connect_db2);
if (!$sql) {
self :: $errors[] = '0'.mysqli_error($GLOBALS['connect_db']);
}
} else {
self :: $errors[] = "Invalid site ID";
}
if ($connect_db2 != null) {
# povezava do drugega streznikla dela
self :: $dest_connect_db = $connect_db2;
} else {
self :: $errors[] = "Could not connect to dest server";
}
}
static function getErrors() {
return self :: $errors;
}
/**
* shrani array ankete kot datoteko
*
*/
static function saveArrayFile ( $data = false ) {
// pocistimo, ce se ze prej kaj izpisuje
ob_end_clean();
// preberemo array
$array = self::getArraySource( $data );
$array['srv_anketa'][0]['naslov'] = $array['srv_anketa'][0]['naslov'].' '.date("j.n.Y");
// zapisemo file na disk
$fp = fopen( dirname(__FILE__) . '/../SurveyBackup/'.$array['srv_anketa'][0]['id'].'-'.date("d.m.Y-H.i.s").'.1ka', 'w');
fwrite($fp, serialize($array));
fclose($fp);
}
/**
* restavrira anketo iz datoteke na strezniku
*
* @param mixed $filename
*/
static function restoreArrayFile ( $filename ) {
$handle = fopen(dirname(__FILE__) . '/../SurveyBackup/'.$filename, "rb");
$contents = fread($handle, filesize(dirname(__FILE__) . '/../SurveyBackup/'.$filename));
fclose($handle);
$array = unserialize($contents);
self::setSourceArray($array);
return self::doCopy();
}
/**
* vrne array ankete kot datoteko
*
*/
static function downloadArrayFile ( $data = false ) {
// Samo za ekstremne primere (zelo velike ankete) :)
//ini_set('memory_limit', '1000M');
// pocistimo, ce se ze prej kaj izpisuje
ob_end_clean();
// preberemo array
$array = self::getArraySource( $data );
// nastavimo attachment header
header('Content-Disposition: attachment; filename="'.$array['srv_anketa'][0]['naslov'].' '.date("j.n.Y").'.1ka"');
$array['srv_anketa'][0]['naslov'] = $array['srv_anketa'][0]['naslov'].' '.date("j.n.Y");
// izpisemo serializiran array
//echo serialize($array);
echo base64_encode(serialize($array));
}
/**
* vrne array ankete kot datoteko
*
*/
static function downloadArrayVar ( $data = false ) {
// pocistimo, ce se ze prej kaj izpisuje
ob_end_clean();
// preberemo array
$array = self::getArraySource( $data );
$array['srv_anketa'][0]['naslov'] = $array['srv_anketa'][0]['naslov'].' '.date("j.n.Y");
// izpisemo serializiran array
return $array;
}
static function setSourceArray ($array) {
self::$source_array = $array;
}
/**
* vrne array z vsebino celotne ankete
*
*/
public static function getArraySource ( $data = false ) {
$arr_src = array();
// subqueryji mysql cist ubijejo zato sem razbil v 2 locena queryja... v bistvu si zakesiramo seznam spremenljivk in ifov
// TODO ko se MySQL upgrada na 5.6 mogoce prestavit nazaj na navaden subquery, ali pa tut ne - bo za sprobat
$qry_src_survey = sisplet_query("SELECT * FROM srv_anketa WHERE id = '".self :: $src_survey."'", self :: $src_connect_db);
$anketa_array = self::sql2array($qry_src_survey);
//Če imamo vklopljeno hierarhijo, potem vrednosti spremenljivk od hierarhije ne kopiramo
// V kolikor imamo vklopljeno hierarhijo potem ne kopiramo spremenljivke od hierarhije
$hierarhija_sql = null;
$hierarhija_not_in = null;
SurveyInfo::getInstance()->SurveyInit(self::$src_survey);
if(SurveyInfo::getInstance()->checkSurveyModule('hierarhija')) {
$hierarhija_sql = "AND s.variable!='vloga' AND s.variable NOT LIKE 'nivo%'";
$hierarhija_not_in = "AND element_spr NOT IN (SELECT s.id AS spr_id
FROM srv_spremenljivka s, srv_grupa g
WHERE
g.ank_id='" . self::$src_survey . "'
AND g.id=s.gru_id
AND (s.variable='vloga' OR s.variable LIKE 'nivo%'))";
}
// pripravimo si seznam spremenljivk in IF stavkov
$qry_cache_spr_id = self::prepareSubquery(sisplet_query("SELECT element_spr AS spr_id FROM srv_branching
WHERE ank_id='" . self::$src_survey . "' AND element_spr>0 ".$hierarhija_not_in."
UNION SELECT s.id AS spr_id FROM srv_spremenljivka s, srv_grupa g
WHERE g.ank_id='" . self::$src_survey . "' AND g.id=s.gru_id AND s.skupine='1' ".$hierarhija_sql."
UNION SELECT s.id AS spr_id FROM srv_spremenljivka s, srv_grupa g
WHERE g.ank_id='" . self::$src_survey . "' AND g.id=s.gru_id AND s.skupine='3'
UNION SELECT spr_id FROM srv_grid_multiple
WHERE ank_id='" . self::$src_survey . "'", self::$src_connect_db));
// pripravimo si seznam IFov, ker se pogosto rabijo
$qry_cache_if_id = self::prepareSubquery( sisplet_query("SELECT element_if FROM srv_branching
WHERE element_if>0 AND ank_id = '".self::$src_survey."'
UNION SELECT v.if_id AS element_if FROM srv_vrednost v, srv_spremenljivka s, srv_grupa g
WHERE v.if_id>0 AND v.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='".self::$src_survey."'", self::$src_connect_db) );
$qry_src_version = sisplet_query("SELECT * FROM misc WHERE what = 'version'");
$row_src_version = mysqli_fetch_assoc($qry_src_version);
$arr_src['version'] = $row_src_version['value'];
$qry_src_survey = sisplet_query("SELECT * FROM srv_anketa WHERE id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_anketa'] = self::sql2array($qry_src_survey);
$qry_src_alert = sisplet_query("SELECT * FROM srv_alert WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_alert'] = self::sql2array($qry_src_alert);
$qry_src_call_setting = sisplet_query("SELECT * FROM srv_call_setting WHERE survey_id = '".self::$src_survey."'", self::$src_connect_db);
$arr_src['srv_call_setting'] = self::sql2array($qry_src_call_setting);
$qry_src_dostop = sisplet_query("SELECT * FROM srv_dostop WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_dostop'] = self::sql2array($qry_src_dostop);
$qry_src_dostop_language = sisplet_query("SELECT * FROM srv_dostop_language WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_dostop_language'] = self::sql2array($qry_src_dostop_language);
$qry_language = sisplet_query("SELECT * FROM srv_language WHERE ank_id = '".self::$src_survey."'", self::$src_connect_db);
$arr_src['srv_language'] = self::sql2array($qry_language);
$qry_src_grupa = sisplet_query("SELECT * FROM srv_grupa WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_grupa'] = self::sql2array($qry_src_grupa);
$qry_src_spremenljivke = sisplet_query("SELECT s.* FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id = g.id AND g.ank_id = '".self :: $src_survey."' ".$hierarhija_sql." UNION SELECT s.* FROM srv_spremenljivka s, srv_grid_multiple gm WHERE s.id=gm.spr_id AND gm.ank_id = '".self::$src_survey."'", self :: $src_connect_db);
$arr_src['srv_spremenljivka'] = self::sql2array($qry_src_spremenljivke);
//$qry_src_vrednosti = sisplet_query("SELECT v.* FROM srv_vrednost v WHERE v.spr_id IN (SELECT element_spr FROM srv_branching WHERE ank_id='".self::$src_survey."' AND element_spr>0 UNION SELECT spr_id FROM srv_grid_multiple WHERE ank_id='".self::$src_survey."')", self :: $src_connect_db);
$qry_src_vrednosti = sisplet_query("SELECT v.* FROM srv_vrednost v WHERE v.spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_vrednost'] = self::sql2array($qry_src_vrednosti);
$qry_src_hotspot_regions = sisplet_query("SELECT hr.* FROM srv_hotspot_regions hr WHERE hr.spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_hotspot_regions'] = self::sql2array($qry_src_hotspot_regions);
$qry_src_vrednosti_map = sisplet_query("SELECT vm.* FROM srv_vrednost_map vm WHERE vm.spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_vrednost_map'] = self::sql2array($qry_src_vrednosti_map);
//$qry_src_grid = sisplet_query("SELECT gr.* FROM srv_grid gr WHERE gr.spr_id IN (SELECT element_spr FROM srv_branching WHERE ank_id='".self::$src_survey."' AND element_spr>0 UNION SELECT spr_id FROM srv_grid_multiple WHERE ank_id='".self::$src_survey."')", self :: $src_connect_db);
$qry_src_grid = sisplet_query("SELECT gr.* FROM srv_grid gr WHERE gr.spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_grid'] = self::sql2array($qry_src_grid);
$qry_src_grid_multiple = sisplet_query("SELECT * FROM srv_grid_multiple WHERE ank_id = '".self::$src_survey."'", self::$src_connect_db);
$arr_src['srv_grid_multiple'] = self::sql2array($qry_src_grid_multiple);
$qry_src_language_spremenljivka = sisplet_query("SELECT * FROM srv_language_spremenljivka WHERE ank_id = '".self::$src_survey."'", self::$src_connect_db);
$arr_src['srv_language_spremenljivka'] = self::sql2array($qry_src_language_spremenljivka);
$qry_src_language_vrednost = sisplet_query("SELECT * FROM srv_language_vrednost WHERE ank_id = '".self::$src_survey."'", self::$src_connect_db);
$arr_src['srv_language_vrednost'] = self::sql2array($qry_src_language_vrednost);
$qry_src_language_grid = sisplet_query("SELECT * FROM srv_language_grid WHERE ank_id = '".self::$src_survey."'", self::$src_connect_db);
$arr_src['srv_language_grid'] = self::sql2array($qry_src_language_grid);
$qry_missing_values = sisplet_query("SELECT * FROM srv_missing_values WHERE sid = '".self::$src_survey."'", self::$src_connect_db);
$arr_src['srv_missing_values'] = self::sql2array($qry_missing_values);
// v cnd_id je -spr_id OR cnd_id = srv_condition.id
$qry_calculation = sisplet_query("SELECT * FROM srv_calculation WHERE cnd_id IN ( SELECT (0 - s.id) AS id FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id = g.id AND g.ank_id = '".self :: $src_survey."' ) OR cnd_id IN ( SELECT id FROM srv_condition WHERE if_id IN (".$qry_cache_if_id.") ) ", self::$src_connect_db);
$arr_src['srv_calculation'] = self::sql2array($qry_calculation);
$qry_src_misc = sisplet_query("SELECT * FROM srv_survey_misc WHERE sid = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_survey_misc'] = self::sql2array($qry_src_misc);
$qry_src_glasovanje = sisplet_query("SELECT * FROM srv_glasovanje WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_glasovanje'] = self::sql2array($qry_src_glasovanje);
$qry_src_if = sisplet_query("SELECT i.* FROM srv_if i, srv_branching b WHERE b.element_if=i.id AND b.element_if>0 AND b.ank_id='".self :: $src_survey."' UNION SELECT i.* FROM srv_if i, srv_vrednost v, srv_spremenljivka s, srv_grupa g WHERE i.id=v.if_id AND v.if_id>0 AND v.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='".self::$src_survey."'", self :: $src_connect_db);
$arr_src['srv_if'] = self::sql2array($qry_src_if);
//$qry_condition = sisplet_query("SELECT * FROM srv_condition WHERE if_id IN (SELECT element_if FROM srv_branching WHERE element_if>0 AND ank_id = '".self::$src_survey."' UNION SELECT v.if_id AS element_if FROM srv_vrednost v, srv_spremenljivka s, srv_grupa g WHERE v.if_id>0 AND v.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='".self::$src_survey."')", self :: $src_connect_db);
$qry_condition = sisplet_query("SELECT * FROM srv_condition WHERE if_id IN (".$qry_cache_if_id.")", self :: $src_connect_db);
$arr_src['srv_condition'] = self::sql2array($qry_condition);
//$qry_src_condition_grid = sisplet_query("SELECT cg.* FROM srv_condition_grid cg, srv_condition c WHERE cg.cond_id = c.id AND c.if_id IN (SELECT element_if FROM srv_branching WHERE element_if>0 AND ank_id = '".self::$src_survey."' UNION SELECT v.if_id AS element_if FROM srv_vrednost v, srv_spremenljivka s, srv_grupa g WHERE v.if_id>0 AND v.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='".self::$src_survey."')", self :: $src_connect_db);
$qry_src_condition_grid = sisplet_query("SELECT cg.* FROM srv_condition_grid cg, srv_condition c WHERE cg.cond_id = c.id AND c.if_id IN (".$qry_cache_if_id.")", self :: $src_connect_db);
$arr_src['srv_condition_grid'] = self::sql2array($qry_src_condition_grid);
//$qry_src_condition_vre = sisplet_query("SELECT cv.* FROM srv_condition_vre cv, srv_condition c WHERE cv.cond_id = c.id AND c.if_id IN (SELECT element_if FROM srv_branching WHERE element_if>0 AND ank_id = '".self::$src_survey."' UNION SELECT v.if_id AS element_if FROM srv_vrednost v, srv_spremenljivka s, srv_grupa g WHERE v.if_id>0 AND v.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='".self::$src_survey."')", self :: $src_connect_db);
$qry_src_condition_vre = sisplet_query("SELECT cv.* FROM srv_condition_vre cv, srv_condition c WHERE cv.cond_id = c.id AND c.if_id IN (".$qry_cache_if_id.")", self :: $src_connect_db);
$arr_src['srv_condition_vre'] = self::sql2array($qry_src_condition_vre);
$qry_src_loop = sisplet_query("SELECT * FROM srv_loop WHERE if_id IN (".$qry_cache_if_id.")", self::$src_connect_db);
$arr_src['srv_loop'] = self::sql2array($qry_src_loop);
$qry_src_loop_vre = sisplet_query("SELECT * FROM srv_loop_vre WHERE if_id IN (".$qry_cache_if_id.")", self::$src_connect_db);
$arr_src['srv_loop_vre'] = self::sql2array($qry_src_loop_vre);
$qry_src_loop_data = sisplet_query("SELECT * FROM srv_loop_data WHERE if_id IN (".$qry_cache_if_id.")", self::$src_connect_db);
$arr_src['srv_loop_data'] = self::sql2array($qry_src_loop_data);
$qry_src_branching = sisplet_query("SELECT * FROM srv_branching WHERE ank_id = '".self :: $src_survey."' ".$hierarhija_not_in, self :: $src_connect_db);
$arr_src['srv_branching'] = self::sql2array($qry_src_branching);
// Vklopljeni moduli in njihove nastavitve
$qry_src_anketa_module = sisplet_query("SELECT * FROM srv_anketa_module WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_anketa_module'] = self::sql2array($qry_src_anketa_module);
$qry_src_chat_settings = sisplet_query("SELECT * FROM srv_chat_settings WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_chat_settings'] = self::sql2array($qry_src_chat_settings);
$qry_src_panel_settings = sisplet_query("SELECT * FROM srv_panel_settings WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_panel_settings'] = self::sql2array($qry_src_panel_settings);
$qry_src_quiz_settings = sisplet_query("SELECT * FROM srv_quiz_settings WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_quiz_settings'] = self::sql2array($qry_src_quiz_settings);
$qry_src_quiz_vrednost = sisplet_query("SELECT v.* FROM srv_quiz_vrednost v WHERE v.spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_quiz_vrednost'] = self::sql2array($qry_src_quiz_vrednost);
$qry_src_slideshow_settings = sisplet_query("SELECT * FROM srv_slideshow_settings WHERE ank_id = '".self :: $src_survey."'", self :: $src_connect_db);
$arr_src['srv_slideshow_settings'] = self::sql2array($qry_src_slideshow_settings);
if ( $data ) {
// pripravimo si se seznam respondentov
$qry_cache_usr_id = self::prepareSubquery( sisplet_query("SELECT id FROM srv_user WHERE ank_id = '".self::$src_survey."'", self::$src_connect_db) );
$arr_src['data'] = true;
$qry_src_user = sisplet_query("SELECT * FROM srv_user WHERE ank_id = '".self::$src_survey."'", self :: $src_connect_db);
$arr_src['srv_user'] = self::sql2array($qry_src_user);
$qry_src_data_checkgrid = sisplet_query("SELECT * FROM srv_data_checkgrid WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_checkgrid'] = self::sql2array($qry_src_data_checkgrid);
$qry_src_data_checkgrid_active = sisplet_query("SELECT * FROM srv_data_checkgrid_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_checkgrid_active'] = self::sql2array($qry_src_data_checkgrid_active);
$qry_src_data_glasovanje = sisplet_query("SELECT * FROM srv_data_glasovanje WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_glasovanje'] = self::sql2array($qry_src_data_glasovanje);
$qry_src_data_grid = sisplet_query("SELECT * FROM srv_data_grid WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_grid'] = self::sql2array($qry_src_data_grid);
$qry_src_data_grid_active = sisplet_query("SELECT * FROM srv_data_grid_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_grid_active'] = self::sql2array($qry_src_data_grid_active);
$qry_src_data_rating = sisplet_query("SELECT * FROM srv_data_rating WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_rating'] = self::sql2array($qry_src_data_rating);
$qry_src_data_text = sisplet_query("SELECT * FROM srv_data_text WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_text'] = self::sql2array($qry_src_data_text);
$qry_src_data_text_active = sisplet_query("SELECT * FROM srv_data_text_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_text_active'] = self::sql2array($qry_src_data_text_active);
$qry_src_data_textgrid = sisplet_query("SELECT * FROM srv_data_textgrid WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_textgrid'] = self::sql2array($qry_src_data_textgrid);
$qry_src_data_textgrid_active = sisplet_query("SELECT * FROM srv_data_textgrid_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_textgrid_active'] = self::sql2array($qry_src_data_textgrid_active);
$qry_src_data_upload = sisplet_query("SELECT * FROM srv_data_upload WHERE ank_id='".self::$src_survey."'", self :: $src_connect_db);
$arr_src['srv_data_upload'] = self::sql2array($qry_src_data_upload);
$qry_src_data_vrednost = sisplet_query("SELECT * FROM srv_data_vrednost WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_vrednost'] = self::sql2array($qry_src_data_vrednost);
$qry_src_data_vrednost_active = sisplet_query("SELECT * FROM srv_data_vrednost_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_vrednost_active'] = self::sql2array($qry_src_data_vrednost_active);
$qry_src_user_grupa = sisplet_query("SELECT * FROM srv_user_grupa WHERE usr_id IN (".$qry_cache_usr_id.")", self::$src_connect_db);
$arr_src['srv_user_grupa'] = self::sql2array($qry_src_user_grupa);
$qry_src_user_grupa_active = sisplet_query("SELECT * FROM srv_user_grupa_active WHERE usr_id IN (".$qry_cache_usr_id.")", self::$src_connect_db);
$arr_src['srv_user_grupa_active'] = self::sql2array($qry_src_user_grupa_active);
$qry_src_data_map = sisplet_query("SELECT * FROM srv_data_map WHERE spr_id IN (".$qry_cache_spr_id.") AND ank_id='".self::$src_survey."' AND usr_id IN (".$qry_cache_usr_id.")", self :: $src_connect_db);
$arr_src['srv_data_map'] = self::sql2array($qry_src_data_map);
$qry_src_data_heatmap = sisplet_query("SELECT * FROM srv_data_heatmap WHERE spr_id IN (".$qry_cache_spr_id.") AND ank_id='".self::$src_survey."' AND usr_id IN (".$qry_cache_usr_id.")", self :: $src_connect_db);
$arr_src['srv_data_heatmap'] = self::sql2array($qry_src_data_heatmap);
/*$qry_src_data_hotspot_regions = sisplet_query("SELECT * FROM srv_hotspot_regions WHERE spr_id IN (".$qry_cache_spr_id.") AND ank_id='".self::$src_survey."' AND usr_id IN (".$qry_cache_usr_id.")", self :: $src_connect_db);
$arr_src['srv_data_hotspot_regions'] = self::sql2array($qry_src_data_hotspot_regions); */
}
return $arr_src;
}
// Vrne implodan rezultat querija primeren za vstavit v subquery - to delamo ponavadi zarad performanca
static function prepareSubquery ($sql_resorce) {
if (!$sql_resorce) echo 'sub-q-error: '.mysqli_error($GLOBALS['connect_db']);
$src_prepare = array();
while ($row_src = mysqli_fetch_row($sql_resorce)) {
$src_prepare[] = $row_src[0];
}
if (count($src_prepare) == 0)
return 'null';
return implode(',', $src_prepare);
}
static function doCopy( $data = false ){
global $global_user_id;
if ( self::$source_array == null ) {
$arr_src = self::getArraySource( $data );
}
else {
$arr_src = self::$source_array;
}
if (!(self::$dest_connect_db != null)) {
self :: $errors[] = "Mandatory data missing!";
}
else {
// iz izvorne ankete preberemo vsa polja
if ( count($arr_src['srv_anketa']) > 0) {
// predefinirana polja (vsilimo vrednosti)
$pre_set = array('id' => "NULL",
'backup' => "'0'",
'active' => "'0'",
'locked' => "'0'",
'db_table' => "'1'",
'insert_uid' => "'".$global_user_id."'",
'insert_time' => "NOW()",
'edit_uid' => "'".$global_user_id."'",
'edit_time' => "NOW()",
'folder' => "'1'",
'forum' => "'0'",
'thread' => "'0'");
# user_id ni enak če je anketa na drugem strežniku zato v tem primeru damo -1 da na drugem strežniku vemo da je to kopija od drugod
if (self::$destSite != 0) {
$pre_set['insert_uid'] = "'-1'";
$pre_set['edit_uid'] = "'-1'";
}
$new_survey_ids = self :: preformCopyTable('srv_anketa', 'id', $arr_src['srv_anketa'], $pre_set);
if ( isset($new_survey_ids[$arr_src['srv_anketa'][0]['id']]) && $new_survey_ids[$arr_src['srv_anketa'][0]['id']] != $arr_src['srv_anketa'][0]['id'] ) {
// novo anketo smo uspesno skreirali
$new_survey_id = $new_survey_ids[$arr_src['srv_anketa'][0]['id']];
// tabela srv_alert
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'finish_respondent_if' => "NULL",
'finish_respondent_cms_if' => "NULL",
'finish_other_if' => "NULL");
$new_alert_ids = self :: preformCopyTable('srv_alert', null, $arr_src['srv_alert'], $pre_set);
// tabela srv_call_setting
$pre_set = array('survey_id' => "'".$new_survey_id."'");
$new_call_setting_ids = self::preformCopyTable('srv_call_setting', null, $arr_src['srv_call_setting'], $pre_set);
// tabela srv_language
$pre_set = array('ank_id' => "'".$new_survey_id."'");
$new_language_ids = self::preformCopyTable('srv_language', null, $arr_src['srv_language'], $pre_set);
// tale zgornji if pogoj ne vem ce takole dela
if (self::$destSite == 0 && self::$src_survey > 0) { // to je smiselno samo na istem strezniku, kjer so user_id-ji enaki
// dostop userjev, tabela srv_dostop
$pre_set = array('ank_id' => "'".$new_survey_id."'");
$new_dostop_ids = self :: preformCopyTable('srv_dostop', null, $arr_src['srv_dostop'], $pre_set);
// dostop userjev do prevodov, tabela srv_dostop_language
$pre_set = array('ank_id' => "'".$new_survey_id."'");
$new_dostop_language_ids = self :: preformCopyTable('srv_dostop_language', null, $arr_src['srv_dostop_language'], $pre_set);
// kopiranje iz datoteke (vse user IDje nastavimo na ID userja, ki uploada)
} elseif ( self::$src_survey == -1 ) {
$new_users_ids = array();
foreach ($arr_src['srv_dostop'] AS $dostop) {
$new_users_ids[$dostop['uid']] = $global_user_id;
}
foreach ($arr_src['srv_dostop_language'] AS $dostop) {
$new_users_ids[$dostop['uid']] = $global_user_id;
}
// da damo dostop samo 1 userju
$tmp = $arr_src['srv_dostop'][0];
$arr_src['srv_dostop'] = null;
$arr_src['srv_dostop'][0] = $tmp;
if ( count($arr_src['srv_dostop_language']) > 0 ) {
$tmp = $arr_src['srv_dostop_language'][0];
$arr_src['srv_dostop_language'] = null;
$arr_src['srv_dostop_language'][0] = $tmp;
}
// dostop userjev, tabela srv_dostop
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'uid' => array('field'=>'uid', 'from'=>$new_users_ids));
$new_dostop_ids = self :: preformCopyTable('srv_dostop', null, $arr_src['srv_dostop'], $pre_set);
// dostop userjev do prevodov, tabela srv_dostop_language
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'uid' => array('field'=>'uid', 'from'=>$new_users_ids));
$new_dostop_language_ids = self :: preformCopyTable('srv_dostop_language', null, $arr_src['srv_dostop_language'], $pre_set);
// ce kopiramo na drug streznik, probamo najti iste uporabnike na drugem strezniku
} else {
$sql_dostop = sisplet_query("SELECT u.id, u.email FROM srv_dostop d, users u WHERE u.id=d.uid AND d.ank_id = '".self::$src_survey."'", self::$src_connect_db);
$new_users_ids = array();
while ($row_dostop = mysqli_fetch_array($sql_dostop)) {
$sql_dostop_new = sisplet_query("SELECT id FROM users WHERE email='$row_dostop[email]'");
if (mysqli_num_rows($sql_dostop_new) > 0) {
$row_dostop_new = mysqli_fetch_array($sql_dostop_new);
$new_users_ids[$row_dostop['id']] = $row_dostop_new['id'];
}
}
$sql_dostop = sisplet_query("SELECT u.id, u.email FROM srv_dostop_language d, users u WHERE u.id=d.uid AND d.ank_id = '".self::$src_survey."'", self::$src_connect_db);
while ($row_dostop = mysqli_fetch_array($sql_dostop)) {
$sql_dostop_new = sisplet_query("SELECT id FROM users WHERE email='$row_dostop[email]'");
if (mysqli_num_rows($sql_dostop_new) > 0) {
$row_dostop_new = mysqli_fetch_array($sql_dostop_new);
$new_users_ids[$row_dostop['id']] = $row_dostop_new['id'];
}
}
// dostop userjev, tabela srv_dostop
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'uid' => array('field'=>'uid', 'from'=>$new_users_ids));
$new_dostop_ids = self :: preformCopyTable('srv_dostop', null, $arr_src['srv_dostop'], $pre_set);
// dostop userjev do prevodov, tabela srv_dostop_language
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'uid' => array('field'=>'uid', 'from'=>$new_users_ids));
$new_dostop_language_ids = self :: preformCopyTable('srv_dostop_language', null, $arr_src['srv_dostop_language'], $pre_set);
}
// grupe - strani, tabela srv_grupa
$pre_set = array('id' => "NULL",
'ank_id' => "'".$new_survey_id."'");
$new_grupa_ids = self :: preformCopyTable('srv_grupa', 'id', $arr_src['srv_grupa'], $pre_set);
$new_grupa_ids[-1] = -1; // spremenljivke v knjiznici imajo -1 (ampak tega tukaj niti nebi smel bit...)
$new_grupa_ids[-2] = -2; // spremenljivke v multiple gridu imajo gru_id -2
$new_grupa_ids[0] = 0; // pri srv_user_grupa je 0 za prvo stran
$new_spremenljivke_ids = array();
if (count($new_grupa_ids) > 0) {
foreach ($new_grupa_ids as $old_grupa_id => $new_grupa_id) {
// spremenljivke, tabela srv_spremenljivka
$src_srv_spremenljivka = self::arrayfilter($arr_src['srv_spremenljivka'], 'gru_id', $old_grupa_id);
$pre_set = array('id' => "NULL",
'gru_id' => "'".$new_grupa_id."'",
'thread' => "'0'");
$tmp_spremenljivke_ids = self :: preformCopyTable('srv_spremenljivka', 'id', $src_srv_spremenljivka, $pre_set);
// shranimo stare in nove id-je spremenljivk
if ( is_countable($tmp_spremenljivke_ids) && count($tmp_spremenljivke_ids) > 0 )
foreach ($tmp_spremenljivke_ids as $key => $value)
$new_spremenljivke_ids[$key] = $value;
}
}
// gridi - srv_grid
$new_grid_ids = array();
if (count($new_spremenljivke_ids) > 0) {
foreach ($new_spremenljivke_ids AS $old_spremenljivka_id => $new_spremenljivka_id) {
// gridi, tabela srv_grid
$src_srv_grid = self::arrayfilter($arr_src['srv_grid'], 'spr_id', $old_spremenljivka_id);
$pre_set = array('spr_id' => "'".$new_spremenljivka_id."'");
$tmp_grid_ids = self :: preformCopyTable('srv_grid', 'variable', $src_srv_grid, $pre_set);
// shranimo stare in nove id-je spremenljivk
if ( count($tmp_grid_ids) > 0 )
foreach ($tmp_grid_ids as $key => $value)
$new_grid_ids[$new_spremenljivka_id][$key] = $value;
}
}
// srv_grid_multiple
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'parent' => array('field'=>'parent','from'=>$new_spremenljivke_ids), # uporabimo dinamično preslikavo iz stare spr_id na novo spr_id za vsako vrstico
'spr_id' => array('field'=>'spr_id','from'=>$new_spremenljivke_ids)); # uporabimo dinamično preslikavo iz stare spr_id na novo spr_id za vsako vrstico
$new_grid_multiple_ids = self::preformCopyTable('srv_grid_multiple', null, $arr_src['srv_grid_multiple'], $pre_set);
// srv_language_spremenljivka
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'spr_id' => array('field'=>'spr_id','from'=>$new_spremenljivke_ids)); # uporabimo dinamično preslikavo iz stare spr_id na novo spr_id za vsako vrstico
$new_language_spremenljivka_ids = self::preformCopyTable('srv_language_spremenljivka', null, $arr_src['srv_language_spremenljivka'], $pre_set);
// srv_language_grid
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'spr_id' => array('field'=>'spr_id','from'=>$new_spremenljivke_ids)); # uporabimo dinamično preslikavo iz stare spr_id na novo spr_id za vsako vrstico
$new_language_grid_ids = self::preformCopyTable('srv_language_grid', null, $arr_src['srv_language_grid'], $pre_set);
// srv_missing_values
$pre_set = array('sid' => "'".$new_survey_id."'");
$new_missing_values_ids = self::preformCopyTable('srv_missing_values', null, $arr_src['srv_missing_values'], $pre_set);
// vrednosti - prestavljeno pod srv_if da se ne porusijo notranji pogoji! Patrik - zakaj je bilo to prestavljeno višje??
/*$new_vrednosti_ids = array();
if ( count($new_spremenljivke_ids) > 0) {
foreach( $new_spremenljivke_ids AS $old_spremenljivka_id => $new_spremenljivka_id) {
// vrednosti, tabela srv_vrednost
$src_srv_vrednost = self::arrayfilter($arr_src['srv_vrednost'], 'spr_id', $old_spremenljivka_id);
$pre_set = array('id' => "NULL",
'spr_id' => array('field'=>'spr_id', 'from'=>$new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from'=>$new_vrednosti_ids));
$tmp_vrednosti_ids = self :: preformCopyTable('srv_vrednost', 'id', $src_srv_vrednost, $pre_set);
// shranimo stare in nove id-je spremenljivk
if ( count($tmp_vrednosti_ids) > 0 )
foreach ($tmp_vrednosti_ids as $key => $value){
$new_vrednosti_ids[$key] = $value;
}
}
}*/
// splosne nastavitve ankete, tabela srv_survey_misc
$pre_set = array('sid' => "'".$new_survey_id."'");
$new_misc_ids = self :: preformCopyTable('srv_survey_misc', null, $arr_src['srv_survey_misc'], $pre_set);
// glasovanje, tabela srv_glasovanje
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'spr_id' => array('field'=>'spr_id','from'=>$new_spremenljivke_ids)); # uporabimo dinamično preslikavo iz stare spr_id na novo spr_id za vsako vrstico
$new_glasovanje_ids = self :: preformCopyTable('srv_glasovanje', null, $arr_src['srv_glasovanje'], $pre_set);
// IF-im tabela srv_if
// Mora biti pred kopiranjem srv_vrednost, ker drugace wswe porusijo notranji pogoji!
$new_if_ids = array ();
$srv_if = $arr_src['srv_if'];
foreach ($srv_if AS $row) {
// IF-i, tabela srv_if
//$qry_src_if = sisplet_query("SELECT * FROM srv_if WHERE id = '".$row[id]."'", self :: $src_connect_db);
$qry_src_if = self::arrayfilter($arr_src['srv_if'], 'id', $row['id']);
$pre_set = array('id' => "NULL");
$tmp_if_ids = self :: preformCopyTable('srv_if', 'id', $qry_src_if, $pre_set);
$new_if_ids += $tmp_if_ids;
}
// vrednosti
$new_vrednosti_ids = array();
if ( count($new_spremenljivke_ids) > 0) {
foreach( $new_spremenljivke_ids AS $old_spremenljivka_id => $new_spremenljivka_id) {
// vrednosti, tabela srv_vrednost
$src_srv_vrednost = self::arrayfilter($arr_src['srv_vrednost'], 'spr_id', $old_spremenljivka_id);
$pre_set = array('id' => "NULL",
'spr_id' => "'".$new_spremenljivka_id."'",
'if_id' => array('field'=>'if_id', 'from'=>$new_if_ids));
$tmp_vrednosti_ids = self :: preformCopyTable('srv_vrednost', 'id', $src_srv_vrednost, $pre_set);
// shranimo stare in nove id-je spremenljivk
if ( count($tmp_vrednosti_ids) > 0 )
foreach ($tmp_vrednosti_ids as $key => $value)
$new_vrednosti_ids[$key] = $value;
}
}
// srv_calculation
// za vsak condition , če je spr_id > 0 priredimo novo, če ne damo enako (-1,-2)
if (count($new_spremenljivke_ids) > 0) {
foreach ($new_spremenljivke_ids AS $old_spremenljivka_id => $new_spremenljivka_id) {
$srv_calculation = self::arrayfilter($arr_src['srv_calculation'], 'cnd_id', -$old_spremenljivka_id);
foreach ($srv_calculation AS $row) {
$new_spr = $row['spr_id'] > 0
? $new_spremenljivke_ids[$row['spr_id']] #naredimo preslikavo
: $row['spr_id']; # uporabimo staro vrednost
$new_vre = $row['vre_id'] > 0
? $new_vrednosti_ids[$row['vre_id']]
: $row['vre_id'];
$src_srv_calculation = self::arrayfilter($arr_src['srv_calculation'], 'id', $row['id']);
$pre_set = array('id' => "NULL",
'cnd_id' => -$new_spremenljivka_id,
'spr_id' => $new_spr,
'vre_id' => $new_vre);
$new_calculation_ids = self::preformCopyTable('srv_calculation', 'id', $src_srv_calculation, $pre_set);
}
}
}
// srv_hotspot_regions
$pre_set = array('id' => "NULL",
'spr_id' => array('field'=>'spr_id', 'from'=>$new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from'=>$new_vrednosti_ids));
$hotspot_regions = self::preformCopyTable('srv_hotspot_regions', 'id', $arr_src['srv_hotspot_regions'], $pre_set);
// srv_vrednost_map
$pre_set = array('id' => "NULL",
'spr_id' => array('field'=>'spr_id', 'from'=>$new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from'=>$new_vrednosti_ids));
self::preformCopyTable('srv_vrednost_map', 'id', $arr_src['srv_vrednost_map'], $pre_set);
// srv_language_vrednost
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'vre_id' => array('field'=>'vre_id','from'=>$new_vrednosti_ids)); # uporabimo dinamično preslikavo iz stare vre_id na novo vre_id za vsako vrstico
$new_language_vrednost_ids = self::preformCopyTable('srv_language_vrednost', null, $arr_src['srv_language_vrednost'], $pre_set);
// srv_condition
$pre_set = array('id' => "NULL",
'if_id' => array('field'=>'if_id', 'from'=>$new_if_ids),
'spr_id' => array('field'=>'spr_id', 'from'=>$new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from'=>$new_vrednosti_ids));
$condition = self::preformCopyTable('srv_condition', 'id', $arr_src['srv_condition'], $pre_set);
// condtition grid, tabela srv_condition_grid
if (count($condition) > 0) {
foreach ($condition AS $orig => $bckp) {
// condtition grid, tabela srv_condition_grid
//$qry_src_condition_grid = sisplet_query("SELECT * FROM srv_condition_grid WHERE cond_id = '".$orig."'", self :: $src_connect_db);
$src_srv_condition_grid = self::arrayfilter($arr_src['srv_condition_grid'], 'cond_id', $orig);
$pre_set = array('id'=>"NULL",
'cond_id' => "'".$bckp."'");
$new_condition_grid_ids = self :: preformCopyTable('srv_condition_grid', 'id', $src_srv_condition_grid, $pre_set);
}
}
// condtition vrednost, tabela srv_condition_vre
if (count($condition) > 0) {
foreach ($condition AS $orig => $bckp) {
//$qry_src_condition_vre = sisplet_query("SELECT * FROM srv_condition_vre WHERE cond_id = '$orig'", self :: $src_connect_db);
$src_srv_condition_vre = self::arrayfilter($arr_src['srv_condition_vre'], 'cond_id', $orig);
$pre_set = array('cond_id' => $bckp,
'vre_id' => array('field'=>'vre_id', 'from'=>$new_vrednosti_ids));
self::preformCopyTable('srv_condition_vre', null, $src_srv_condition_vre, $pre_set);
}
}
// srv_loop
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'if_id' => array('field'=>'if_id','from'=>$new_if_ids), # uporabimo dinamično preslikavo iz stare if_id na novo if_id za vsako vrstico
'spr_id' => array('field'=>'spr_id','from'=>$new_spremenljivke_ids)); # uporabimo dinamično preslikavo iz stare spr_id na novo spr_id za vsako vrstico
$new_loop_ids = self::preformCopyTable('srv_loop', null, $arr_src['srv_loop'], $pre_set);
// srv_loop_vre
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'if_id' => array('field'=>'if_id','from'=>$new_if_ids), # uporabimo dinamično preslikavo iz stare if_id na novo if_id za vsako vrstico
'vre_id' => array('field'=>'vre_id','from'=>$new_vrednosti_ids)); # uporabimo dinamično preslikavo iz stare spr_id na novo spr_id za vsako vrstico
$new_loop_vre_ids = self::preformCopyTable('srv_loop_vre', null, $arr_src['srv_loop_vre'], $pre_set);
// srv_loop_data
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'id' => "NULL",
'if_id' => array('field'=>'if_id','from'=>$new_if_ids), # uporabimo dinamično preslikavo iz stare if_id na novo if_id za vsako vrstico
'vre_id' => array('field'=>'vre_id','from'=>$new_vrednosti_ids)); # uporabimo dinamično preslikavo iz stare spr_id na novo spr_id za vsako vrstico
$new_loop_data_ids = self::preformCopyTable('srv_loop_data', 'id', $arr_src['srv_loop_data'], $pre_set);
// srv_branching
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'parent' => array('field'=>'parent', 'from' => $new_if_ids),
'element_spr' => array('field'=>'element_spr', 'from' => $new_spremenljivke_ids),
'element_if' => array('field' => 'element_if', 'from' => $new_if_ids));
self::preformCopyTable('srv_branching', null, $arr_src['srv_branching'], $pre_set);
// srv_calculation
// za vsak condition , če je spr_id > 0 priredimo novo, če ne damo enako (-1,-2)
if (count($condition) > 0) {
foreach ($condition AS $orig => $bckp) {
//$qry_src_calculation = sisplet_query("SELECT * FROM srv_calculation WHERE cnd_id = '$orig'", self :: $src_connect_db);
$src_srv_calculation = self::arrayfilter($arr_src['srv_calculation'], 'cnd_id', $orig);
$pre_set = array('id' => "NULL",
'cnd_id' => $bckp,
'spr_id' => array('field'=>'spr_id', 'from'=>$new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from'=>$new_vrednosti_ids));
self::preformCopyTable('srv_calculation', 'id', $src_srv_calculation, $pre_set);
}
}
// srv_anketa_module - skopiramo samo nekatere module
$copy_modules = array('social_network', 'quiz', 'uporabnost', 'slideshow', 'chat', 'panel');
foreach($copy_modules as $copy_module){
$src_srv_modules = self::arrayfilter($arr_src['srv_anketa_module'], 'modul', $copy_module);
$pre_set = array('ank_id' => "'".$new_survey_id."'");
self::preformCopyTable('srv_anketa_module', null, $src_srv_modules, $pre_set);
}
// srv_chat_settings
$pre_set = array('ank_id' => "'".$new_survey_id."'");
self::preformCopyTable('srv_chat_settings', null, $arr_src['srv_chat_settings'], $pre_set);
// srv_panel_settings
$pre_set = array('ank_id' => "'".$new_survey_id."'");
self::preformCopyTable('srv_panel_settings', null, $arr_src['srv_panel_settings'], $pre_set);
// srv_slideshow_settings
$pre_set = array('ank_id' => "'".$new_survey_id."'");
self::preformCopyTable('srv_slideshow_settings', null, $arr_src['srv_slideshow_settings'], $pre_set);
// srv_quiz_settings
$pre_set = array('ank_id' => "'".$new_survey_id."'");
self::preformCopyTable('srv_quiz_settings', null, $arr_src['srv_quiz_settings'], $pre_set);
// srv_quiz_vrednost
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from'=>$new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from'=>$new_vrednosti_ids));
self::preformCopyTable('srv_quiz_vrednost', null, $arr_src['srv_quiz_vrednost'], $pre_set);
/**
* PODATKI
*/
if ( $arr_src['data'] ) {
$ip = GetIP();
// srv_user
$new_user_ids = array();
foreach ( $arr_src['srv_user'] AS $row_array ) {
do {
$rand = md5(mt_rand(1, mt_getrandmax()).'@'.$ip);
$sql = sisplet_query("SELECT id FROM srv_user WHERE cookie = '$rand'");
} while (mysqli_num_rows($sql) > 0);
$pre_set = array('id' => "NULL",
'cookie' => "'$rand'",
'pass' => "'".substr($rand, 0, 6)."'",
'ank_id' => "'".$new_survey_id."'");
$src_srv_user = self::arrayfilter($arr_src['srv_user'], 'id', $row_array['id']);
$tmp_user_ids = self::preformCopyTable('srv_user', 'id', $src_srv_user, $pre_set);
if ( count($tmp_user_ids) > 0 )
foreach ($tmp_user_ids as $key => $value)
$new_user_ids[$key] = $value;
}
// srv_data_checkgrid - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_checkgrid_active', null, $arr_src['srv_data_checkgrid'], $pre_set);
// srv_data_checkgrid_active
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_checkgrid_active', null, $arr_src['srv_data_checkgrid_active'], $pre_set);
// srv_data_glasovanje
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids));
self::preformCopyTable('srv_data_glasovanje', null, $arr_src['srv_data_glasovanje'], $pre_set);
// srv_data_grid - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_grid_active', null, $arr_src['srv_data_grid'], $pre_set);
// srv_data_grid_active
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_grid_active', null, $arr_src['srv_data_grid_active'], $pre_set);
// srv_data_rating
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_rating', null, $arr_src['srv_data_rating'], $pre_set);
// srv_data_text - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('id' => "NULL",
'spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_text_active', 'id', $arr_src['srv_data_text'], $pre_set);
// srv_data_text_active
$pre_set = array('id' => "NULL",
'spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_text_active', 'id', $arr_src['srv_data_text_active'], $pre_set);
// srv_data_textgrid - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_textgrid_active', null, $arr_src['srv_data_textgrid'], $pre_set);
// srv_data_textgrid_active
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_textgrid_active', null, $arr_src['srv_data_textgrid_active'], $pre_set);
// srv_data_upload
$pre_set = array('ank_id' => "'".$new_survey_id."'",
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids));
self::preformCopyTable('srv_data_upload', null, $arr_src['srv_data_upload'], $pre_set);
// srv_data_vrednost - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_vrednost_active', null, $arr_src['srv_data_vrednost'], $pre_set);
// srv_data_vrednost_active
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_vrednost_active', null, $arr_src['srv_data_vrednost_active'], $pre_set);
// srv_user_grupa - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('gru_id' => array('field'=>'gru_id', 'from' => $new_grupa_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids));
self::preformCopyTable('srv_user_grupa_active', null, $arr_src['srv_user_grupa'], $pre_set);
// srv_user_grupa_active
$pre_set = array('gru_id' => array('field'=>'gru_id', 'from' => $new_grupa_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids));
self::preformCopyTable('srv_user_grupa_active', null, $arr_src['srv_user_grupa_active'], $pre_set);
// srv_data_map
$pre_set = array('id' => "NULL",
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'ank_id' => "'".$new_survey_id."'",
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_map', 'id', $arr_src['srv_data_map'], $pre_set);
// srv_data_heatmap
$pre_set = array('id' => "NULL",
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'ank_id' => "'".$new_survey_id."'",
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_heatmap', 'id', $arr_src['srv_data_heatmap'], $pre_set);
}
}
else {
self :: $errors[] = "Survey could not be copied! Please contact web admin. (Error code: 2)";
}
}
else {
self :: $errors[] = "Survey could not be copied! Source survey does not exist. Please contact web admin. (Error code: 1)";
}
}
return $new_survey_id;
}
// query SHOW COLUMS si kesiramo, ker se lahko izvaja zelo pogosto na istih tabelah (in se zlo pozna)
static $show_columns = array();
/** Prekopira samo polja ki so v dest tabeli pred tem popravi $pre_set polja
*
* @param $table_name
* @param $id_field (insert_id polje)
* @param $array_source - tole smo spremenili, da ne podamo sql querija, ampak array s podatki
* @param $pre_set
* @return array(oldId=>newId) Id-ji vpisanega zapisa
*/
static function preformCopyTable($table_name, $id_field, $array_source, $pre_set) {
//if (!$array_source)
// self :: $errors[] = 'Qry src string error: ' . mysqli_error($GLOBALS['connect_db']);
$result = null;
if (isset(self::$show_columns[$table_name])) {
$dest_table_fields = self::$show_columns[$table_name];
mysqli_data_seek($dest_table_fields, 0);
} else {
self::$show_columns[$table_name] = sisplet_query("SHOW COLUMNS FROM ".$table_name, self::$dest_connect_db);
$dest_table_fields = self::$show_columns[$table_name];
}
if (!$dest_table_fields) {
self :: $errors[] = 'Could not run query: ' . mysqli_error($GLOBALS['connect_db']);
}
if ( count($array_source) > 0 ) {
// zloopamo skozi polja druge tabele in predpripravimo insert string polja
if (mysqli_num_rows($dest_table_fields) > 0) {
$insert_fields = '';
$insert_fields_prefix = '';
// vsebuje polja
while ($row_dest_table_fields = mysqli_fetch_assoc($dest_table_fields)) {
// polja dodamo v insert string
$dest_field = $row_dest_table_fields['Field'];
$insert_fields .= $insert_fields_prefix . $dest_field;
$insert_fields_prefix = ',';
}
// zloopamo skozi zapise izvorne tabele
// lahko updejtamo več zapisov, nove id-je damo v array, star_id=>nov_id
//while ( $row_src = mysqli_fetch_assoc($qry_src_string)) {
foreach ( $array_source AS $row_src ) {
// pripravimo prvi del insert stringa
$insert_string = 'INSERT INTO '.$table_name.' ('.$insert_fields.') VALUES (';
$insert_values = '';
$insert_values_prefix = '';
// zloopamo skozi polja druge tabele in dodamo vrednosti
mysqli_data_seek($dest_table_fields, 0);
while ($row_dest_table_fields = mysqli_fetch_assoc($dest_table_fields)) {
// ime polja v drugi tabeli
$dest_field = $row_dest_table_fields['Field'];
/* vrednosti se lahko dodeljujejo dinamično preko pre_set
* se pravi za preslikavo starege vrednosti "spr_id" na novo vrednost "spr_id"
* je kot pre_set polje potrebno navesti ime polja ('field') in array z preslikavami (stara_vrednost=>nova_vrednost)
*
* primer:
* $pre_set = array('ank_id' => "'".$new_survey_id."'",
* 'spr_id' => array('field'=>'spr_id','from'=>$new_spremenljivke_ids)); # uporabimo dinamično preslikavo iz stare spr_id na novo spr_id za vsako vrstico
*/
// ce polje v src datoteki ni nastavljeno ga damo na praznega
if ( ! isset($row_src[$dest_field]) && ! isset($pre_set[$dest_field]) ) {
$dest_value = "''";
// ce je polje NULL, ga moramo rocno nastavit na NULL
} elseif ($row_src[$dest_field] === NULL) {
$dest_value = "NULL";
} else {
$dest_value = isset($pre_set[$dest_field])
? ( !(is_array($pre_set[$dest_field]) && isset($pre_set[$dest_field]['field']) && isset($pre_set[$dest_field]['from']))
? $pre_set[$dest_field]
: ( isset($pre_set[$dest_field]['from'][$row_src[$pre_set[$dest_field]['field']]]) # dodal sem se preverjenje, ce ID v tabeli preslikav obstaja - cene se uporabi original (kje se uporablja -1, -2...) -mitja
? $pre_set[$dest_field]['from'][$row_src[$pre_set[$dest_field]['field']]] # je array in sta potrebni polji preberemo iz arraya "from" za source polja "field"
: "'".mysqli_real_escape_string($GLOBALS['connect_db'], $row_src[$dest_field])."'"
)
)
: "'".mysqli_real_escape_string($GLOBALS['connect_db'], $row_src[$dest_field])."'";
}
$insert_values .= $insert_values_prefix . $dest_value;
$insert_values_prefix = ',';
}
// dodamo zaklepaj
$insert_values .= ')';
$insert_string .= $insert_values;
$updated = sisplet_query($insert_string, self::$dest_connect_db);
if (!$updated) self::$errors[] = "Insert failed (".$table_name."): ".mysqli_error(self::$dest_connect_db).'('.$insert_string.')';
$insert_id = mysqli_insert_id(self::$dest_connect_db);
if ($insert_id > 0) {
if (isset($row_src[$id_field])) {
// poiscemo source id
$result[$row_src[$id_field]] = $insert_id;
} else {
$result[] = $insert_id;
}
} else {
// lahko da je sql ne vrne id-ja (kadar ni primary key-a)
$result[$row_src[$id_field]] = $row_src[$id_field];
}
}
} else {
self :: $errors[] = "Dest fields missing for table:".$table_name;
}
} else {
// nothing to copy
}
return $result;
}
/**
* @desc Naredi kopijo respondenta v podatkih
*/
public static function copyRespondent($usr_id){
global $global_user_id;
// Dobimo podatke o respondentu ki ga kopiramo
$sqlU = sisplet_query("SELECT preview, testdata, last_status, lurker, unsubscribed, language FROM srv_user WHERE ank_id='".self::$src_survey."' AND id='".$usr_id."'");
$rowU = mysqli_fetch_array($sqlU);
// Nastavimo nov cookie - izberemo random hash, ki se ni v bazi
do {
$rand = md5(mt_rand(1, mt_getrandmax()) . '@' . $global_user_id);
$sql = sisplet_query("SELECT id FROM srv_user WHERE cookie = '$rand'");
} while (mysqli_num_rows($sql) > 0);
// Kopiramo respondenta
$sql = sisplet_query("INSERT INTO srv_user
(
ank_id,
preview,
testdata,
cookie,
time_insert,
time_edit,
recnum,
last_status,
lurker,
unsubscribed,
language
)
VALUES (
'".self::$src_survey."',
'".$rowU['preview']."',
'".$rowU['testdata']."',
'".$rand."',
NOW(),
NOW(),
MAX_RECNUM('".self::$src_survey."'),
'".$rowU['last_status']."',
'".$rowU['lurker']."',
'".$rowU['unsubscribed']."',
'".$rowU['language']."'
)
");
$new_usr_id = mysqli_insert_id($GLOBALS['connect_db']);
// Kopiramo odgovore
// srv_data_vrednost
$sqlD = sisplet_query("SELECT * FROM srv_data_vrednost WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_vrednost', null, self::sql2array($sqlD), $pre_set);
// srv_data_vrednost_active
$sqlD = sisplet_query("SELECT * FROM srv_data_vrednost_active WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_vrednost_active', null, self::sql2array($sqlD), $pre_set);
// srv_data_text
$sqlD = sisplet_query("SELECT * FROM srv_data_text WHERE usr_id='".$usr_id."'");
$pre_set = array( 'id' => "NULL",
'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_text', 'id', self::sql2array($sqlD), $pre_set);
// srv_data_text_active
$sqlD = sisplet_query("SELECT * FROM srv_data_text_active WHERE usr_id='".$usr_id."'");
$pre_set = array( 'id' => "NULL",
'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_text_active', 'id', self::sql2array($sqlD), $pre_set);
// srv_data_checkgrid
$sqlD = sisplet_query("SELECT * FROM srv_data_checkgrid WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_checkgrid', null, self::sql2array($sqlD), $pre_set);
// srv_data_checkgrid_active
$sqlD = sisplet_query("SELECT * FROM srv_data_checkgrid_active WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_checkgrid_active', null, self::sql2array($sqlD), $pre_set);
// srv_data_grid
$sqlD = sisplet_query("SELECT * FROM srv_data_grid WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_grid', null, self::sql2array($sqlD), $pre_set);
// srv_data_grid_active
$sqlD = sisplet_query("SELECT * FROM srv_data_grid_active WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_grid_active', null, self::sql2array($sqlD), $pre_set);
// srv_data_textgrid
$sqlD = sisplet_query("SELECT * FROM srv_data_textgrid WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_textgrid', null, self::sql2array($sqlD), $pre_set);
// srv_data_textgrid_active
$sqlD = sisplet_query("SELECT * FROM srv_data_textgrid_active WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_textgrid_active', null, self::sql2array($sqlD), $pre_set);
// srv_data_rating
$sqlD = sisplet_query("SELECT * FROM srv_data_rating WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_rating', null, self::sql2array($sqlD), $pre_set);
// srv_data_upload
$sqlD = sisplet_query("SELECT * FROM srv_data_upload WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id);
self::preformCopyTable('srv_data_upload', null, self::sql2array($sqlD), $pre_set);
// srv_data_glasovanje
$sqlD = sisplet_query("SELECT * FROM srv_data_glasovanje WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id);
self::preformCopyTable('srv_data_glasovanje', null, self::sql2array($sqlD), $pre_set);
// srv_user_grupa
$sqlD = sisplet_query("SELECT * FROM srv_user_grupa WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'time_edit' => "NOW()");
self::preformCopyTable('srv_user_grupa', null, self::sql2array($sqlD), $pre_set);
// srv_user_grupa_active
$sqlD = sisplet_query("SELECT * FROM srv_user_grupa_active WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'time_edit' => "NOW()");
self::preformCopyTable('srv_user_grupa_active', null, self::sql2array($sqlD), $pre_set);
// srv_data_map
$sqlD = sisplet_query("SELECT * FROM srv_data_map WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_map', null, self::sql2array($sqlD), $pre_set);
// srv_data_heatmap
$sqlD = sisplet_query("SELECT * FROM srv_data_heatmap WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
self::preformCopyTable('srv_data_heatmap', null, self::sql2array($sqlD), $pre_set);
return $new_usr_id;
}
/**
* sql result vrne kot multi array
*
* @param mixed $sql
*/
static function sql2array($sql) {
$array = array();
while ($row = mysqli_fetch_assoc($sql)) {
$array[] = $row;
}
return $array;
}
/**
* pofilitira array in vrne samo vrstice, ki ustrezajo field == value
*
* @param mixed $array
* @param mixed $field
* @param mixed $value
*/
static function arrayfilter ($array, $field, $value) {
$arr = array();
foreach ($array AS $row) {
if ($row[$field] == $value){
$arr[] = $row;
}
}
return $arr;
}
}
?>
|