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
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
|
<?php
class BranchingAjax {
var $anketa; // trenutna anketa
var $grupa; // trenutna grupa
var $spremenljivka; // trenutna spremenljivka
//var $SurveyAdmin; // globalna spremenljivka za SurveyAdmin // SurveyAdmin se nikjer vec ne klice iz Branchinga
//var $sidebar; // ali prikazemo sidebar: 0-ne, 1-vprasanja, 2-library
//var $collapsed_content; // ali prikazujemo vseibno IFa (ce ne se poklice z ajaxom)
var $skin = 0;
// tele nastavitve so tudi v BranchingAjax in jih je treba tudi tam popravit!
//var $maxIfCount = 0; // koliko ifov je meja za prikaz. Če je 0 prikeže vse
//var $autoRecount = 0; // ce je vec kot 50 spremenljivk nimamo avtomatskega prestevilcevanja
/**
* @desc konstruktor
*/
function __construct ($anketa=0) {
global $surveySkin;
global $site_path;
$this->anketa = $anketa;
if (isset($surveySkin))
$this->skin = $surveySkin;
SurveyInfo::getInstance()->SurveyInit($this->anketa);
}
/**
* @desc pohendla ajax zahteve
*/
function ajax () {
if (isset($_POST['anketa'])) $this->anketa = $_POST['anketa'];
if (isset($_POST['spremenljivka'])) $this->spremenljivka = $_POST['spremenljivka'];
if (strpos($_SERVER['HTTP_REFERER'], 'parent_if') !== false) {
$_GET['parent_if'] = substr( $_SERVER['HTTP_REFERER'], strpos($_SERVER['HTTP_REFERER'], 'parent_if')+10 );
}
// genericna resitev
$ajax = 'ajax_' . $_GET['a'];
if ( method_exists('BranchingAjax', $ajax) )
$this->$ajax();
else
echo 'method '.$ajax.' does not exist';
}
function ajax_follow_up_condition($ank_id = null, $if_id = null, $odg_id = null, $spr_id = null)
{
if ($ank_id == null) $ank_id = $_POST['ank_id'];
if ($if_id == null) $if_id = $_POST['if_id'];
if ($odg_id == null) $odg_id = $_POST['odg_id'];
if ($spr_id == null) $spr_id = $_POST['spr_id'];
$sql = sisplet_query("SELECT naslov FROM srv_vrednost WHERE id = '$odg_id'");
$naslov = mysqli_fetch_array($sql);
sisplet_query("UPDATE srv_if SET label='$naslov[0]' WHERE id='$if_id'");
$sql_id = sisplet_query("SELECT id FROM srv_condition WHERE if_id='$if_id'");
$id_condition = mysqli_fetch_array($sql_id);
sisplet_query("UPDATE srv_condition SET spr_id='$spr_id' WHERE id='$id_condition[0]'");
sisplet_query("INSERT INTO srv_condition_vre (cond_id, vre_id) VALUES ('$id_condition[0]', '$odg_id')");
}
//generira blok (dropdown in menu) za missinge za kategorije
function ajax_get_missing_block () {
global $lang;
$b = new Branching($this->anketa);
$b->missings_menu($this->spremenljivka);
}
function ajax_if_new ($spremenljivka = null, $if = null, $endif = null, $tip = null) {
global $lang;
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$spremenljivka = (isset($_POST['spremenljivka']) && $spremenljivka == null) ? $_POST['spremenljivka'] : $spremenljivka;
$if = (isset($_POST['if']) && $if == null) ? $_POST['if'] : $if;
$endif = (isset($_POST['endif']) && $endif == null) ? $_POST['endif'] : $endif;
$tip = (isset($_POST['tip']) && $tip == null) ? $_POST['tip'] : $tip;
$copy = isset($_POST['copy']) ? $_POST['copy'] : 0;
$no_content = isset($_POST['no_content']) ? $_POST['no_content'] : 0;
$include_element = false;
$b = new Branching($this->anketa);
if ($spremenljivka >= 0 || $if >= 0) {
$sqln = sisplet_query("SELECT MAX(i.number) AS number FROM srv_if i, srv_branching b WHERE b.ank_id='$this->anketa' AND b.element_if=i.id");
if (!$sqln) echo mysqli_error($GLOBALS['connect_db']);
$rown = mysqli_fetch_array($sqln);
$number = $rown['number'] + 1;
$sql = sisplet_query("INSERT INTO srv_if (id, number, tip) VALUES ('', '$number', '$tip')");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$if_id = mysqli_insert_id($GLOBALS['connect_db']);
if ($spremenljivka > 0 || ($if > 0 && $endif == 1)) {
$sql = sisplet_query("SELECT parent, vrstni_red, element_spr, element_if FROM srv_branching WHERE element_spr = '$spremenljivka' AND element_if='$if'");
$row = mysqli_fetch_array($sql);
}
if ($spremenljivka == 0 && $if == 0) {
if ($endif == 0) { // dodajanje na zacetek
$row['parent'] = 0;
$row['vrstni_red'] = 0;
} else { // dodajanje na konec
$row['parent'] = 0;
$row['vrstni_red'] = 99999999;
// ce je blok Demografija na zadnjem mestu v anketi, potem pri "dodajanju na konec" dodamo pred demografijo --da je demografija vedno na koncu
$sqld = sisplet_query("SELECT b.element_if, b.vrstni_red FROM srv_if i, srv_branching b
WHERE i.label = '$lang[srv_demografija]' AND i.tip='1' AND b.ank_id='$this->anketa' AND b.element_if=i.id AND parent='0'
AND b.vrstni_red = (SELECT MAX(vrstni_red) FROM srv_branching WHERE ank_id='$this->anketa' AND parent = '0')
");
if (mysqli_num_rows($sqld) > 0) {
$rowd = mysqli_fetch_array($sqld);
sisplet_query("UPDATE srv_branching SET vrstni_red = vrstni_red+1 WHERE element_if = $rowd[element_if] AND element_spr = '0' AND ank_id='$this->anketa'");
$row['vrstni_red'] = $rowd['vrstni_red'];
}
}
}
if ($if > 0 && $endif != 1) {
$row['parent'] = $if;
$row['vrstni_red'] = 0;
}
// dodajanje ifa na trenutno spremenljivko
if ($spremenljivka > 0 && $endif == 1) {
$next_element = $row;
$include_element = true; // v if vkljucimo tudi trenutno spremenljivko
// dodajanje ifa na naslednji element
} else {
$next_element = $b->find_next_element($row['parent'], $row['vrstni_red']);
}
if ($next_element == null) { // next_element je prazen na koncu ifa, takrat je tudi nov if prazen
$next_element['parent'] = $row['parent'];
$next_element['vrstni_red'] = $row['vrstni_red'] + 1;
$next_element['element_spr'] = 0;
$next_element['element_if'] = 0;
}
$add = true;
// dodajamo loop - preverimo da ga ne zelimo vgnezditi v drug loop
if ($tip == 2) {
// preverimo, da ga ne dodamo v ze obstojec loop
if ($b->find_loop_parent($next_element['parent']) > 0)
$add = false;
// preverimo, da ge ne dodamo direktno pred obstojec loop (ker potem objame obstojec loop in dobimo vgnezdenje)
if ($next_element['element_if'] > 0)
if ($b->find_loop_child($next_element['element_if']) > 0)
$add = false;
}
if ($add) {
$b->if_new($endif, $next_element['parent'], $if_id, $next_element['vrstni_red'], $next_element['element_spr'], $next_element['element_if'], $copy, $no_content, $include_element);
sisplet_query("UPDATE srv_anketa SET branching='1' WHERE id = '$this->anketa'");
} else {
$b->dropped_alert($lang['srv_loop_no_nesting']);
}
}
$this->check_loop();
$b->repare_vrstni_red();
Common::getInstance()->prestevilci($spremenljivka, $all=true);
// Zacasno shranimo zadnji ustvarjen if, da vemo katerega odpreti
echo '<input type="hidden" id="temp_new_if_id" name="temp_new_if_id" value="'.$if_id.'" />';
$b->branching_struktura();
return $if_id;
}
function ajax_spremenljivka_new ($spremenljivka = null, $if = null, $endif = null, $copy=null, $tip=null, $podtip=null, $drop=null) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if ($spremenljivka == null && isset($_POST['spremenljivka']))
$spremenljivka = $_POST['spremenljivka'];
if ($if == null && isset($_POST['if']))
$if = $_POST['if'];
if ($endif == null && isset($_POST['endif']))
$endif = $_POST['endif'];
if ($copy == null && isset($_POST['copy']))
$copy = $_POST['copy'];
if ($drop == null && isset($_POST['drop']))
$drop = $_POST['drop'];
if ($tip == null && isset($_POST['tip']))
$tip = $_POST['tip'];
if ($podtip == null && isset($_POST['podtip']))
$podtip = $_POST['podtip'];
if ($tip == 23) {
$copy = $podtip;
$tip = 0;
$podtip = 0;
}
elseif ($tip == 26) {
$podtip = 1;
}
$b = new Branching($this->anketa);
$this->spremenljivka_new($spremenljivka, $if, $endif, $copy, $drop);
if ($tip > 0) {
Vprasanje::change_tip($this->spremenljivka, $tip, $podtip);
}
if ($podtip > 0) {
$v = new Vprasanje($this->anketa);
$v->spremenljivka = $this->spremenljivka;
ob_start();
if ($tip == 6) { // tabela en odgovor
$v->ajax_change_diferencial($podtip);
}
elseif ($tip == 21) { // besedilo*
if ($podtip == 1) { // captcha
$v->set_captcha();
} elseif ($podtip == 2) { // email
$v->set_email();
} elseif ($podtip == 3) { // url
$v->set_url();
} elseif ($podtip == 4) { // upload
$v->set_upload();
} elseif ($podtip == 5) { // text box
$v->set_box();
} elseif ($podtip == 6) { // podpis
$v->set_signature();
} elseif ($podtip == 7) { // fotografija
$v->set_fotografija();
}
}
elseif ($tip == 19) {
if ($podtip == 1) {
$v->set_datum(); // multigrid datum
}
}
elseif($tip == 26){
$v->set_map ($podtip);
}
elseif($tip == 5 && $podtip == 2){
$v->set_chat();
}
elseif($tip == 7 && $podtip == 2){
$v->set_slider();
}
elseif($tip == 1 && $podtip == 10) { // GDPR
$v->set_GDPR();
}
ob_clean();
}
$b->repare_vrstni_red();
Common::getInstance()->prestevilci();
//$b->branching_struktura();
Cache::clear_cache();
$data = array();
$data['nova_spremenljivka_id'] = $this->spremenljivka;
ob_start();
$b = new Branching($this->anketa);
$b->spremenljivka = $this->spremenljivka;
$b->branching_struktura();
$branching_struktura_text = ob_get_clean();
if(!mb_detect_encoding($branching_struktura_text, 'UTF-8', true))
$data['branching_struktura'] = utf8_encode($branching_struktura_text);
else
$data['branching_struktura'] = $branching_struktura_text;
$this->check_loop();
ob_start();
$v = new Vprasanje($this->anketa);
$v->spremenljivka = $this->spremenljivka;
$v->ajax_vprasanje_fullscreen();
$vprasanje_fullscreen_text = ob_get_clean();
if(!mb_detect_encoding($vprasanje_fullscreen_text, 'UTF-8', true))
$data['vprasanje_fullscreen'] = utf8_encode($vprasanje_fullscreen_text);
else
$data['vprasanje_fullscreen'] = $vprasanje_fullscreen_text;
echo json_encode($data);
}
/**
* @desc kreira novo spremeniljvko v branchingu -- doda zapis tudi v srv_branching
*/
function spremenljivka_new ($spremenljivka, $if=0, $endif=0, $copy=0, $drop=0, $toStart=false) {
Common::updateEditStamp();
global $lang;
$b = new Branching($this->anketa);
if ($spremenljivka >= 0 || $if > 0) {
if ($if > 0) {
if ($endif != 1)
$spr_id = $b->find_first_in_if($if);
else
$spr_id = $b->find_next_spr($b->find_last_in_if($if));
} elseif ($spremenljivka > 0) {
$spr_id = $spremenljivka;
} elseif ($spremenljivka == 0 && $toStart==false) {
$spr_id = $b->find_first_spr();
} elseif ($spremenljivka == 0 && $toStart==true) {
$spr_id = $b->find_last_spr();
}
$sqlS = sisplet_query("SELECT gru_id, vrstni_red FROM srv_spremenljivka WHERE id='$spr_id'");
$rowS = mysqli_fetch_array($sqlS);
// Mogoce ni se nobenega vprasanja v anketi
if ($rowS['gru_id'] == '0'){
$sqlG = sisplet_query("SELECT id, vrstni_red FROM srv_grupa WHERE ank_id='$this->anketa'");
$rowG = mysqli_fetch_array($sqlG);
// Dodaten pogoj da nikoli tega ne pustimo, ce je gru_id==0
if($rowG['id'] == '0')
die('group id error');
$spr_id = $b->nova_spremenljivka($rowG['id'], $rowG['vrstni_red'], 1, $copy);
}
elseif($rowS['gru_id'] < 0){
die('group id < 0 error');
}
else{
// Povecamo vrstni red vsem kasnejsim vprasanjem v isti grupi
sisplet_query("UPDATE srv_spremenljivka SET vrstni_red=vrstni_red+1 WHERE gru_id='$rowS[gru_id]' AND vrstni_red>'$rowS[vrstni_red]'");
$sqlG = sisplet_query("SELECT id, vrstni_red FROM srv_grupa WHERE ank_id='$this->anketa' AND id='$rowS[gru_id]'");
$rowG = mysqli_fetch_array($sqlG);
$spr_id = $b->nova_spremenljivka($rowS['gru_id'], $rowG['vrstni_red'], $rowS['vrstni_red']+1, $copy);
}
$this->spremenljivka = $spr_id;
if ( $this->spremenljivka == $spremenljivka ) die('copy error');
// Dodaten pogoj da nikoli ne vstavimo v srv_branching elementa ki ima element_spr=0 in element_if=0 (potem lahko pride do neskoncnega loopa kjer se dodajajo grupe v anketo)
if ($this->spremenljivka == 0 && $if == 0) die('copy error2');
if ($if > 0) {
if ($endif != 1) {
$sql = sisplet_query("INSERT INTO srv_branching (ank_id, parent, element_spr, element_if, vrstni_red) VALUES ('$this->anketa', '$if', '$spr_id', '0', '0')");
$b->repare_branching($if);
} else {
$sqlb = sisplet_query("SELECT parent, vrstni_red FROM srv_branching WHERE element_spr='$spremenljivka' AND element_if='$if'");
$rowb = mysqli_fetch_array($sqlb);
sisplet_query("UPDATE srv_branching SET vrstni_red=vrstni_red+1 WHERE parent='$rowb[parent]' AND vrstni_red>'$rowb[vrstni_red]' AND ank_id='$this->anketa'");
$rowb['vrstni_red']++;
$sql = sisplet_query("INSERT INTO srv_branching (ank_id, parent, element_spr, element_if, vrstni_red) VALUES ('$this->anketa', '$rowb[parent]', '$spr_id', '0', '$rowb[vrstni_red]')");
$b->repare_branching($rowb['parent']);
}
} else {
if ($spremenljivka > 0) {
$sqlb = sisplet_query("SELECT parent, vrstni_red FROM srv_branching WHERE element_spr='$spremenljivka' AND element_if='$if'");
$rowb = mysqli_fetch_array($sqlb);
sisplet_query("UPDATE srv_branching SET vrstni_red=vrstni_red+1 WHERE parent='$rowb[parent]' AND vrstni_red>'$rowb[vrstni_red]' AND ank_id='$this->anketa'");
$rowb['vrstni_red']++;
} elseif ($spremenljivka == 0) {
if ($endif == 0) { // dodajanje na zacetek
$rowb['parent'] = 0;
$rowb['vrstni_red'] = 0;
} else { // dodajanje na konec
$rowb['parent'] = 0;
$rowb['vrstni_red'] = 99999999;
// ce je blok Demografija na zadnjem mestu v anketi, potem pri "dodajanju na konec" dodamo pred demografijo --da je demografija vedno na koncu
$sqld = sisplet_query("SELECT b.element_if, b.vrstni_red FROM srv_if i, srv_branching b
WHERE i.label = '$lang[srv_demografija]' AND i.tip='1' AND b.ank_id='$this->anketa' AND b.element_if=i.id AND parent='0' AND b.vrstni_red = (
SELECT MAX(vrstni_red) FROM srv_branching WHERE ank_id='$this->anketa' AND parent = '0'
)");
if (mysqli_num_rows($sqld) > 0) {
$rowd = mysqli_fetch_array($sqld);
sisplet_query("UPDATE srv_branching SET vrstni_red = vrstni_red+1 WHERE element_if = $rowd[element_if] AND element_spr = '0' AND ank_id='$this->anketa'");
$rowb['vrstni_red'] = $rowd['vrstni_red'];
}
}
}
$sql = sisplet_query("INSERT INTO srv_branching (ank_id, parent, element_spr, element_if, vrstni_red) VALUES ('$this->anketa', '$rowb[parent]', '$spr_id', '0', '$rowb[vrstni_red]')");
$b->repare_branching($rowb['parent']);
// ++ nastavljanje pagebreakov //
if ($drop == 2) {
$s = sisplet_query("SELECT pagebreak FROM srv_branching WHERE element_spr='$spremenljivka' AND ank_id='$this->anketa'");
$r = mysqli_fetch_array($s);
// preverimo se, ce imamo res pagebreak
if ($r['pagebreak'] == 1) {
$s = sisplet_query("UPDATE srv_branching SET pagebreak='1' WHERE element_spr='$this->spremenljivka' AND ank_id='$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("UPDATE srv_branching SET pagebreak='0' WHERE element_spr='$spremenljivka' AND ank_id='$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
Cache::clear_branching_cache(); // drugace se polje pagebreak zakesira pri prikazu
}
}
// -- nastavljanje pagebreakov //
}
}
//return id nove spremenljivke za API
return $spr_id;
}
/**
* Uporablja se tudi v API, ampak zaenkrat samo za mobile app, zato sem ignoriral vse alerte in droppanje ifa
* V kolikor se bo to uporabljalo tudi v API za sirso uporabo, je funkcijo potrebno ustrezno prilagoditi
*/
function ajax_accept_droppable ($child = 0, $vrstni_red = 0, $page_break = 0, $API_call = false, $parent = 0) {
global $lang;
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if(!$API_call){
$parent = $_POST['parent'];
$tmp_p = str_replace('droppable_', '', $parent);
$tmp_p = explode('-', $tmp_p);
$parent = isset($tmp_p[0]) ? $tmp_p[0] : $parent;
$vrstni_red = isset($tmp_p[1]) ? $tmp_p[1] : $vrstni_red;
$page_break = isset($tmp_p[2]) ? $tmp_p[2] : $page_break;
$child = $_POST['child'];
$child = str_replace('branching_', '', $child);
}
$b = new Branching($this->anketa);
// droppal smo spremenljivko
if (is_numeric($parent) && is_numeric($child) && $child > 0) {
if ($b->check_dropped_spremenljivka($child, $parent, $vrstni_red)) {
$sql = sisplet_query("SELECT pagebreak FROM srv_branching WHERE element_spr = '$child'");
$row = mysqli_fetch_array($sql);
$prev = $b->find_prev_spr($child); // preden zacnemo premikati, poiscemo predhodno spremenljivko, ki jo rabimo pri PB
$s = sisplet_query("UPDATE srv_branching SET vrstni_red = (vrstni_red+1) WHERE parent='$parent' AND vrstni_red > '$vrstni_red' AND ank_id='$this->anketa'");
if (!$s && !$API_call) echo mysqli_error($GLOBALS['connect_db']);
else if (!$s && $API_call) return mysqli_error($GLOBALS['connect_db']);
$sql = sisplet_query("UPDATE srv_branching SET parent='$parent', vrstni_red=('$vrstni_red'+1) WHERE element_spr='$child' AND ank_id='$this->anketa'");
if (!$sql && !$API_call) echo mysqli_error($GLOBALS['connect_db']);
else if (!$sql && $API_call) return mysqli_error($GLOBALS['connect_db']);
// ++ nastavljanje pagebreakov //
// spremenljivko smo spustili pred page break, zato zamenjamo pagebreak polja (to oznacuje $page_break == 2)
if ($page_break == 2) { /*echo '$page_break == 2';*/
$s = sisplet_query("SELECT pagebreak FROM srv_branching WHERE parent='$parent' AND vrstni_red='$vrstni_red' AND ank_id='$this->anketa'");
$r = mysqli_fetch_array($s);
// preverimo se, ce imamo res pagebreak - npr. ce spustimo cisto na konec, ga ni
if ($r['pagebreak'] == 1) { /*echo '$r[pb] == 1';*/
$s = sisplet_query("UPDATE srv_branching SET pagebreak='1' WHERE element_spr='$child' AND ank_id='$this->anketa'");
if (!$s && !$API_call) echo mysqli_error($GLOBALS['connect_db']);
else if (!$s && $API_call) return mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("UPDATE srv_branching SET pagebreak='0' WHERE parent='$parent' AND vrstni_red='$vrstni_red' AND ank_id='$this->anketa'");
if (!$s && !$API_call) echo mysqli_error($GLOBALS['connect_db']);
else if (!$s && $API_call) return mysqli_error($GLOBALS['connect_db']);
Cache::clear_branching_cache(); // drugace se polje pagebreak zakesira pri prikazu
}
// ce je za spremenljivko page break, ga moramo ohraniti tam, kjer je
}
elseif ($row['pagebreak'] == 1) { /*echo '$row[pb] == 1';*/
$s = sisplet_query("SELECT element_spr FROM srv_branching WHERE parent='$parent' AND vrstni_red>='$vrstni_red' AND ank_id='$this->anketa' ORDER BY vrstni_red ASC LIMIT 1");
$r = mysqli_fetch_array($s);
/*echo ' r: '.$r['element_spr'].' c:'. $child. ' prev:'.$prev.' previous:'. $b->find_prev_spr_branching($child);*/
// ce spremenljivko s PB spustimo na isto mesto, ne smemo popravljati PB
if ($b->find_prev_spr_branching($child) != $prev /*|| $r['element_spr']==$child*/) { /*echo ' yes ';*/
if ($prev == 0 && $page_break != 2) { /*echo '$prev==0';*/ // ce premikamo prvo spremenljivko spustimo nekam za PB, ga zbrisemo (ker na prvem mestu ostane prazna stran)
$s = sisplet_query("UPDATE srv_branching SET pagebreak='0' WHERE element_spr='$child' AND ank_id='$this->anketa'");
if (!$s && !$API_call) echo mysqli_error($GLOBALS['connect_db']);
else if (!$s && $API_call) return mysqli_error($GLOBALS['connect_db']);
} elseif ($prev > 0) { /*echo '$prev>0';*/ // normalno - zamenjamo pagebreak-a
$s = sisplet_query("UPDATE srv_branching SET pagebreak='0' WHERE element_spr='$child' AND ank_id='$this->anketa'");
if (!$s && !$API_call) echo mysqli_error($GLOBALS['connect_db']);
else if (!$s && $API_call) return mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("UPDATE srv_branching SET pagebreak='1' WHERE element_spr='$prev' AND ank_id='$this->anketa'");
if (!$s && !$API_call) echo mysqli_error($GLOBALS['connect_db']);
else if (!$s && $API_call) return mysqli_error($GLOBALS['connect_db']);
}
} /*else echo ' no';*/
Cache::clear_branching_cache(); // drugace se polje pagebreak zakesira pri prikazu
}
// na zadnjem mestu vedno popravimo, da ni pagebreaka (ker je nepotreben in lahko kasneje ko se premika kaj pokvari)
$last = $b->find_last_spr_branching();
sisplet_query("UPDATE srv_branching SET pagebreak='0' WHERE element_spr='$last' AND ank_id='$this->anketa'");
// -- nastavljanje pagebreakov //
$b->repare_branching();
}
else
$b->dropped_alert();
}
// droppal smo if ali endif
else {
$child = str_replace('if', '', $child);
// droppal smo if
if (is_numeric($child)) {
if (is_numeric($parent) && $child > 0 && $child != $parent) {
$loop = false;
// premikamo loop ali blok/if ki vsebuje loop
if ($b->find_loop_child($child) > 0) {
if ($parent > 0) {
if ($b->find_loop_parent($parent) > 0)
$loop = true;
}
}
if ($b->check_dropped_if($child, $parent, $vrstni_red) && !$loop) {
sisplet_query("UPDATE srv_branching SET vrstni_red = (vrstni_red+1) WHERE parent='$parent' AND vrstni_red > '$vrstni_red' AND ank_id='$this->anketa'");
$sql = sisplet_query("UPDATE srv_branching SET parent='$parent', vrstni_red=('$vrstni_red'+1) WHERE element_if='$child' AND ank_id='$this->anketa'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
// ++ nastavljanje pagebreakov //
// ce if premaknemo na zgornjo stran pagebreaka, potem PB premaknemo na zadnjo spremenljivko v IFu
if ($page_break == 2) {
$s = sisplet_query("SELECT pagebreak FROM srv_branching WHERE parent='$parent' AND vrstni_red='$vrstni_red' AND ank_id='$this->anketa'");
$r = mysqli_fetch_array($s);
if ($r['pagebreak'] == 1) {
$s = sisplet_query("UPDATE srv_branching SET pagebreak='0' WHERE parent='$parent' AND vrstni_red='$vrstni_red' AND ank_id='$this->anketa'");
$s = sisplet_query("UPDATE srv_branching SET pagebreak='1' WHERE element_spr='{$b->find_last_spr_branching($child)}' AND ank_id='$this->anketa'");
Cache::clear_branching_cache(); // drugace se polje pagebreak zakesira pri prikazu
}
}
// -- nastavljanje pagebreakov //
$b->repare_branching();
} else {
if ($loop)
$b->dropped_alert($lang['srv_loop_no_nesting']);
else
$b->dropped_alert();
}
}
// droppal smo endif
} else {
$child = str_replace('end', '', $child);
if (is_numeric($parent) && is_numeric($child)) {
$sql = sisplet_query("SELECT parent, vrstni_red FROM srv_branching WHERE element_if = '$child'");
$row = mysqli_fetch_array($sql);
$sql1 = sisplet_query("SELECT * FROM srv_branching WHERE parent='$child'");
$elements = mysqli_num_rows($sql1);
// podaljsamo IF
if ($row['parent'] == $parent && $row['vrstni_red'] <= $vrstni_red) {
$loop = false;
// preverjanje, ce premikamo ENDLOOP, da ne potegnemo cez kaksen drug loop
$sqli = sisplet_query("SELECT tip FROM srv_if WHERE id = '$child'");
$rowi = mysqli_fetch_array($sqli);
if ($rowi['tip'] == '2') {
for ($i=$row['vrstni_red']+1; $i<=$vrstni_red; $i++) {
$sqli = sisplet_query("SELECT element_if FROM srv_branching WHERE parent='$parent' AND vrstni_red='$i' AND ank_id='$this->anketa'");
$rowi = mysqli_fetch_array($sqli);
if ($rowi['element_if'] > 0)
if ($b->find_loop_child($rowi['element_if']) > 0)
$loop = true;
}
}
if (!$loop) {
$vr = $elements+1;
for ($i=$row['vrstni_red']+1; $i<=$vrstni_red; $i++) {
sisplet_query("UPDATE srv_branching SET parent='$child', vrstni_red='$vr' WHERE parent='$parent' AND vrstni_red='$i' AND ank_id='$this->anketa'");
$vr++;
}
} else $b->dropped_alert($lang['srv_loop_no_nesting']);
// krajsamo IF
} elseif ($parent == $child) {
$vr = $row['vrstni_red']+1;
sisplet_query("UPDATE srv_branching SET vrstni_red=(vrstni_red+'$elements'-'$vrstni_red') WHERE
parent='$row[parent]' AND vrstni_red>'$row[vrstni_red]' AND ank_id='$this->anketa'");
for ($i=$vrstni_red+1; $i<=$elements; $i++) {
sisplet_query("UPDATE srv_branching SET parent='$row[parent]', vrstni_red='$vr' WHERE parent='$child' AND vrstni_red='$i' AND ank_id='$this->anketa'");
$vr++;
}
} else $b->dropped_alert();
$b->repare_branching();
}
}
}
$this->check_loop();
$b->repare_vrstni_red();
Common::getInstance()->prestevilci();
if(!$API_call)
$b->branching_struktura();
}
function ajax_if_remove ($if=0, $first=1) {
global $lang;
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = ($if == 0 && isset($_POST['if'])) ? $_POST['if'] : $if;
// ali brisemo tudi celotno vsebino pogoja/bloka
$all = (isset($_POST['all']) && $_POST['all'] == 1) ? 1 : 0;
$b = new Branching($this->anketa);
if ($if > 0) {
// preverimo, ce obstajajo ze podatki za spremenljivko - v tem primeru damo dodaten error
$confirmed = $_POST['confirmed'];
if ($all == 1 && $confirmed != '1') {
$sql = sisplet_query("SELECT count(*) AS count FROM srv_user WHERE ank_id='$this->anketa' AND deleted='0' AND preview='0'");
$row = mysqli_fetch_array($sql);
if ($row['count'] > 0) {
echo '<h2>'.$lang['srv_warning'].'</h2>';
echo '<div class="popup_close"><a href="#" onClick="$(\'#dropped_alert\').hide(); $(\'#fade\').fadeOut(); return false;">✕</a></div>';
echo '<p>'.$lang['if_delete_data'].'</p>';
echo '<p class="top16">'.$lang['srv_brisiifconfirm_all'].'</p>';
echo '<div class="button_holder">';
echo ' <button class="medium white-blue" onclick="$(\'#dropped_alert\').hide(); $(\'#fade\').fadeOut(); return false;">'.$lang['srv_analiza_arhiviraj_cancle'].'</button>';
echo ' <button class="medium blue" onclick="if_remove(\''.$if.'\', \'1\'); return false;">'.$lang['srv_if_rem_all'].'</button>';
echo '</div>';
return;
}
}
$sql = sisplet_query("SELECT * FROM srv_condition WHERE if_id = '$if'");
while ($row = mysqli_fetch_array($sql))
sisplet_query("DELETE FROM srv_condition_vre WHERE cond_id='$row[id]'");
sisplet_query("DELETE FROM srv_condition WHERE if_id = '$if'");
sisplet_query("DELETE FROM srv_if WHERE id = '$if'");
sisplet_query("DELETE FROM srv_validation WHERE if_id='$if'");
$sql = sisplet_query("SELECT parent, vrstni_red FROM srv_branching WHERE element_if = '$if'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$row = mysqli_fetch_array($sql);
if ($all == 0) {
$sql1 = sisplet_query("SELECT * FROM srv_branching WHERE parent = '$if'");
$childs = mysqli_num_rows($sql1);
sisplet_query("UPDATE srv_branching SET vrstni_red=(vrstni_red+'$childs'-1) WHERE parent='$row[parent]' AND vrstni_red > '$row[vrstni_red]' AND ank_id='$this->anketa'");
sisplet_query("UPDATE srv_branching SET parent='$row[parent]', vrstni_red=(vrstni_red+'$row[vrstni_red]'-1) WHERE parent='$if' AND ank_id='$this->anketa'");
} else {
$sa = null;
$sql1 = sisplet_query("SELECT element_spr, element_if FROM srv_branching WHERE parent = '$if'");
while ($row1 = mysqli_fetch_array($sql1)) {
if ($row1['element_spr'] > 0) {
if ($sa == null) $sa = new SurveyAdmin(-1, $this->anketa);
$sa->brisi_spremenljivko($row1['element_spr']);
} else {
$this->ajax_if_remove($row1['element_if'], 0);
}
}
}
sisplet_query("DELETE FROM srv_branching WHERE element_if = '$if'");
$b->repare_branching($row['parent']);
$b->repare_vrstni_red();
$sql = sisplet_query("SELECT * FROM srv_branching WHERE ank_id='$this->anketa' AND element_if > 0");
if (mysqli_num_rows($sql) == 0) {
sisplet_query("UPDATE srv_anketa SET branching='0' WHERE id='$this->anketa'");
}
}
// izpisemo samo pri prvem klicu, pri rekurzivnih pa ne
if ($first == 1)
$b->branching_struktura();
}
function ajax_vrednost_if_remove ($if=0) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if ($if == 0)
$if = $_POST['if'];
$vrednost = $_POST['vrednost'];
if ($if > 0) {
$sql = sisplet_query("SELECT * FROM srv_condition WHERE if_id = '$if'");
while ($row = mysqli_fetch_array($sql))
sisplet_query("DELETE FROM srv_condition_vre WHERE cond_id='$row[id]'");
sisplet_query("DELETE FROM srv_condition WHERE if_id = '$if'");
sisplet_query("DELETE FROM srv_if WHERE id = '$if'");
sisplet_query("UPDATE srv_vrednost SET if_id='0' WHERE if_id='$if'");
}
}
function ajax_if_tip() {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = $_POST['if'];
$tip = $_POST['tip'];
sisplet_query("UPDATE srv_if SET tip = '$tip' WHERE id = '$if'");
$b = new Branching($this->anketa);
$b->condition_editing($if);
}
function ajax_vrednost_condition_editing () {
Common::updateEditStamp();
$vrednost = $_POST['vrednost'];
$sql = sisplet_query("SELECT if_id FROM srv_vrednost WHERE id = '$vrednost'");
$row = mysqli_fetch_array($sql);
if ($row['if_id'] > 0) {
$if = $row['if_id'];
} else {
sisplet_query("INSERT INTO srv_if (id) VALUES ('')");
$if = mysqli_insert_id($GLOBALS['connect_db']);
sisplet_query("INSERT INTO srv_condition (id, if_id, vrstni_red) VALUES ('', '$if', '1')");
sisplet_query("UPDATE srv_vrednost SET if_id='$if' WHERE id = '$vrednost'");
}
$b = new Branching($this->anketa);
$b->condition_editing($if, $vrednost);
}
function ajax_condition_editing () {
$if = $_POST['if'];
if ($if == 0) {
$sql = sisplet_query("SELECT id FROM srv_if ORDER BY id DESC LIMIT 1");
$row = mysqli_fetch_array($sql);
$if = $row['id'];
}
$b = new Branching($this->anketa);
$b->condition_editing($if);
}
function ajax_data_condition_editing () {
$if = $_POST['if'];
if ($if == 0) {
$sql = sisplet_query("SELECT id FROM srv_if ORDER BY id DESC LIMIT 1");
$row = mysqli_fetch_array($sql);
$if = $row['id'];
}
$b = new Branching($this->anketa);
$b->condition_editing($if,-1);
}
function ajax_condition_add () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$if = $_POST['if'];
$conjunction = $_POST['conjunction'];
$negation = $_POST['negation'];
$sql = sisplet_query("SELECT MAX(vrstni_red) AS max FROM srv_condition WHERE if_id = '$if'");
$row = mysqli_fetch_array($sql);
$vrstni_red = $row['max'] + 1;
sisplet_query("INSERT INTO srv_condition (if_id, conjunction, negation, vrstni_red) VALUES ('$if', '$conjunction', '$negation', '$vrstni_red')");
$b = new Branching($this->anketa);
$b->condition_editing_inner($if, $_POST['vrednost']);
}
function ajax_condition_edit () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$text = isset($_POST['text']) ? strip_tags($_POST['text']) : '';
$operator = isset($_POST['operator']) ? $_POST['operator'] : '';
$negation = isset($_POST['negation']) ? $_POST['negation'] : '';
$conjunction = isset($_POST['conjunction']) ? $_POST['conjunction'] : '';
$vrednost = isset($_POST['vrednost']) ? $_POST['vrednost'] : '';
$condition = isset($_POST['condition']) ? $_POST['condition'] : '';
$spremenljivka = isset($_POST['spremenljivka']) ? $_POST['spremenljivka'] : '';
$ostanek = isset($_POST['ostanek']) ? $_POST['ostanek'] : '';
//$vrednost = explode(',', $vrednost);
sisplet_query("DELETE FROM srv_condition_vre WHERE cond_id='$condition'");
sisplet_query("DELETE FROM srv_condition_grid WHERE cond_id='$condition'");
// obicna spremenljivka
if (is_numeric($spremenljivka)) {
$spremenljivka = $spremenljivka;
$vre_id = 0;
if ($vrednost != null)
foreach ($vrednost AS $val)
if ($val > 0 || $val == -1)
sisplet_query("INSERT INTO srv_condition_vre (cond_id, vre_id) VALUES ('$condition', '$val')");
// multigrid
} elseif ( is_numeric(str_replace('vre_', '', $spremenljivka)) ) {
$vre_id = str_replace('vre_', '', $spremenljivka);
$sql2 = sisplet_query("SELECT spr_id FROM srv_vrednost WHERE id = '$vre_id'");
$row2 = mysqli_fetch_array($sql2);
$spremenljivka = $row2['spr_id'];
if ($vrednost != null)
foreach ($vrednost AS $val) {
if ($val > 0 || $val < 0) // neustrezni so minus
sisplet_query("INSERT INTO srv_condition_grid (cond_id, grd_id) VALUES ('$condition', '$val')");
}
// tabela besedilo, tabela stevilo
} elseif (substr($spremenljivka,0,4) == 'grd_') {
$e = explode('_', $spremenljivka);
$vre_id = $e[1];
$grid = $e[2];
$sql2 = sisplet_query("SELECT spr_id FROM srv_vrednost WHERE id = '$vre_id'");
$row2 = mysqli_fetch_array($sql2);
$spremenljivka = $row2['spr_id'];
// number
} elseif (substr($spremenljivka,0,4) == 'num_') {
$e = explode('_', $spremenljivka);
$spremenljivka = $e[1];
$grid = $e[2];
$vre_id = 0;
}
// calculation
if ($spremenljivka == -2) {
$sqlc = sisplet_query("SELECT vre_id FROM srv_condition WHERE id = '$condition'");
$rowc = mysqli_fetch_array($sqlc);
$vre_id = $rowc['vre_id'];
}
sisplet_query("UPDATE srv_condition SET spr_id='$spremenljivka', vre_id='$vre_id', text='$text', conjunction='$conjunction', negation='$negation', operator='$operator', ostanek='$ostanek' WHERE id = '$condition'");
$sql = sisplet_query("SELECT * FROM srv_condition WHERE id = '$condition'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
$b->conditions_display($row['if_id'], 1, 1);
}
function ajax_bracket_edit () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$right_bracket = $_POST['right_bracket'];
$left_bracket = $_POST['left_bracket'];
$condition = $_POST['condition'];
sisplet_query("UPDATE srv_condition SET left_bracket='$left_bracket', right_bracket='$right_bracket' WHERE id = '$condition'");
$sql = sisplet_query("SELECT * FROM srv_condition WHERE id = '$condition'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
$b->condition_editing($row['if_id'], $_POST['vrednost']);
}
function ajax_bracket_edit_new () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$who = $_POST['who'];
$what = $_POST['what'];
$left_bracket = $_POST['left_bracket'];
$condition = $_POST['condition'];
if ($who == 'left')
if ($what == 'plus')
$bracket = 'left_bracket=left_bracket+1';
else
$bracket = 'left_bracket=left_bracket-1';
else
if ($what == 'plus')
$bracket = 'right_bracket=right_bracket+1';
else
$bracket = 'right_bracket=right_bracket-1';
sisplet_query("UPDATE srv_condition SET $bracket WHERE id = '$condition'");
$sql = sisplet_query("SELECT * FROM srv_condition WHERE id = '$condition'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
$b->condition_editing_inner($row['if_id'], $_POST['vrednost']);
}
function ajax_conjunction_edit () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$conjunction = $_POST['conjunction'];
$negation = $_POST['negation'];
$condition = $_POST['condition'];
sisplet_query("UPDATE srv_condition SET conjunction='$conjunction', negation='$negation' WHERE id = '$condition'");
$sql = sisplet_query("SELECT * FROM srv_condition WHERE id = '$condition'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
$b->condition_editing_inner($row['if_id'], $_POST['vrednost']);
}
function ajax_fill_value () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$condition = $_POST['condition'];
$spremenljivka = $_POST['spremenljivka'];
// obicna spremenljivka
if (is_numeric($spremenljivka)) {
$spremenljivka = $spremenljivka;
$vrednost = 0;
$grid = 0;
// multigrid
} elseif ( is_numeric( str_replace('vre_', '', $spremenljivka) ) ) {
$vrednost = str_replace('vre_', '', $spremenljivka);
$sql2 = sisplet_query("SELECT spr_id FROM srv_vrednost WHERE id = '$vrednost'");
$row2 = mysqli_fetch_array($sql2);
$spremenljivka = $row2['spr_id'];
$grid = 0;
// tabela besedilo, tabela stevilo
} elseif (substr($spremenljivka,0,4) == 'grd_') {
$e = explode('_', $spremenljivka);
$vrednost = $e[1];
$grid = $e[2];
$sql2 = sisplet_query("SELECT spr_id FROM srv_vrednost WHERE id = '$vrednost'");
$row2 = mysqli_fetch_array($sql2);
$spremenljivka = $row2['spr_id'];
// number
} elseif (substr($spremenljivka,0,4) == 'num_') {
$e = explode('_', $spremenljivka);
$spremenljivka = $e[1];
$grid = $e[2];
$vrednost = 0;
}
sisplet_query("DELETE FROM srv_condition_vre WHERE cond_id='$condition'");
sisplet_query("DELETE FROM srv_condition_grid WHERE cond_id='$condition'");
sisplet_query("UPDATE srv_condition SET spr_id='$spremenljivka', vre_id='$vrednost', grd_id='$grid' WHERE id = '$condition'");
$sql = sisplet_query("SELECT * FROM srv_condition WHERE id = '$condition'");
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
$b->condition_editing_inner($row['if_id'], $_POST['vrednost'], $_POST['condition']);
}
function ajax_fill_ostanek () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$condition = $_POST['condition'];
$modul = $_POST['modul'];
sisplet_query("UPDATE srv_condition SET modul='$modul' WHERE id = '$condition'");
$b = new Branching($this->anketa);
$b->fill_ostanek($condition);
}
function ajax_edit_label() {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$if = $_POST['if'];
$label = strip_tags($_POST['label']);
sisplet_query("UPDATE srv_if SET label='$label' WHERE id = '$if'");
}
function ajax_edit_panel_status() {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$if = $_POST['if'];
$panel_status = $_POST['panel_status'];
// Ce je prazen ga pobrisemo iz baze
if($panel_status == ''){
$sqlP = sisplet_query("DELETE FROM srv_panel_if WHERE ank_id='".$this->anketa."' AND if_id='".$if."'");
}
else{
$sqlP = sisplet_query("INSERT INTO srv_panel_if (ank_id, if_id, value) VALUES ('".$this->anketa."', '".$if."', '".$panel_status."')
ON DUPLICATE KEY UPDATE value='".$panel_status."'");
}
}
function ajax_condition_remove () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$condition = $_POST['condition'];
sisplet_query("DELETE FROM srv_condition WHERE id='$condition'");
$b = new Branching($this->anketa);
$b->repare_condition($_POST['if']);
$b->condition_editing_inner($_POST['if'], $_POST['vrednost']);
}
function ajax_calculation_editing () {
if ($_POST['noupdate'] != 1) {
Common::updateEditStamp();
}
$condition = $_POST['condition'];
$vrednost = $_POST['vrednost'];
$sql = sisplet_query("SELECT * FROM srv_condition WHERE id = '$condition'");
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
$calculation = $b->calculation_editing($condition, $vrednost);
if ($row['vre_id'] == 0) {
$s = sisplet_query("UPDATE srv_condition SET vre_id='$calculation' WHERE id='$condition'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
}
function ajax_calculation_editing_close () {
$condition = $_POST['condition'];
$vrednost = $_POST['vrednost'];
$sql = sisplet_query("SELECT if_id FROM srv_condition WHERE id = '$condition'");
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
if ($condition >= 0)
$b->condition_editing($row['if_id'], $vrednost);
else {
$row = SurveyInfo::getInstance()->getSurveyRow();
if ($row['expanded'] == 1) {
$b->vprasanje(-$condition);
} else {
$b->spremenljivka_name(-$condition);
}
}
}
function ajax_calculation_save () {
if ($_POST['noupdate'] != 1) {
Common::updateEditStamp();
}
$calculation = $_POST['calculation'];
$expression = $_POST['expression'];
sisplet_query("UPDATE srv_calculation SET expression='$expression' WHERE id = '$calculation'");
}
function ajax_calculation_add () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$condition = $_POST['condition'];
$operator = $_POST['operator'];
$vrednost = $_POST['vrednost'];
$sql = sisplet_query("SELECT MAX(vrstni_red) AS max FROM srv_calculation WHERE cnd_id = '$condition'");
$row = mysqli_fetch_array($sql);
$vrstni_red = $row['max'] + 1;
$s = sisplet_query("INSERT INTO srv_calculation (id, cnd_id, operator, vrstni_red) VALUES ('', '$condition', '$operator', '$vrstni_red')");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$b = new Branching($this->anketa);
$b->calculation_editing_inner($condition, $vrednost);
}
function ajax_calculation_operator_edit () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$calculation = $_POST['calculation'];
$operator = $_POST['operator'];
sisplet_query("UPDATE srv_calculation SET operator='$operator' WHERE id = '$calculation'");
$sql = sisplet_query("SELECT * FROM srv_calculation WHERE id = '$calculation'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
$b->calculation_editing_inner($row['cnd_id'], $_POST['vrednost']);
}
function ajax_calculation_edit () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$spremenljivka = $_POST['spremenljivka'];
$calculation = $_POST['calculation'];
$number = $_POST['number'];
$vrednost = $_POST['vrednost'];
$grd_id = 0;
// obicna spremenljivka
if (is_numeric($spremenljivka)) {
$spr_id = $spremenljivka;
$vre_id = 0;
// checkbox, multigrid
} elseif ( strpos($spremenljivka, 'vre_') !== false ) {
$e = explode('_', $spremenljivka);
list( , $vre_id, $grd_id) = $e;
$sql2 = sisplet_query("SELECT spr_id FROM srv_vrednost WHERE id = '$vre_id'");
$row2 = mysqli_fetch_array($sql2);
$spr_id = $row2['spr_id'];
// number
} elseif ( strpos($spremenljivka, 'num_') !== false ) {
$e = explode('_', $spremenljivka);
list( , $spr_id, $grd_id) = $e;
$vre_id = 0;
// multicheckbox, multinumber
} else {
$e = explode('_', $spremenljivka);
list( , $spr_id, $vre_id, $grd_id) = $e;
}
if (!is_numeric($number)) $number = 0;
$s = sisplet_query("UPDATE srv_calculation SET spr_id='$spr_id', vre_id='$vre_id', grd_id='$grd_id', number='$number' WHERE id = '$calculation'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$sql = sisplet_query("SELECT * FROM srv_calculation WHERE id = '$calculation'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
$b->calculation_editing_inner($row['cnd_id'], $vrednost);
}
function ajax_calculation_remove () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$calculation = $_POST['calculation'];
$vrednost = $_POST['vrednost'];
sisplet_query("DELETE FROM srv_calculation WHERE id='$calculation'");
$b = new Branching($this->anketa);
$b->repare_calculation($_POST['condition']);
$b->calculation_editing_inner($_POST['condition'], $vrednost);
}
function ajax_calculation_bracket_edit_new () {
if ($_POST['noupdate'] != 1) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
}
$who = $_POST['who'];
$what = $_POST['what'];
$left_bracket = $_POST['left_bracket'];
$calculation = $_POST['calculation'];
if ($who == 'left')
if ($what == 'plus')
$bracket = 'left_bracket=left_bracket+1';
else
$bracket = 'left_bracket=left_bracket-1';
else
if ($what == 'plus')
$bracket = 'right_bracket=right_bracket+1';
else
$bracket = 'right_bracket=right_bracket-1';
sisplet_query("UPDATE srv_calculation SET $bracket WHERE id = '$calculation'");
$sql = sisplet_query("SELECT * FROM srv_calculation WHERE id = '$calculation'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$row = mysqli_fetch_array($sql);
$b = new Branching($this->anketa);
$b->calculation_editing_inner($row['cnd_id'], $_POST['vrednost']);
}
function ajax_condition_editing_close () {
$if = $_POST['if'];
$b = new Branching($this->anketa);
$b->display_if_label($if);
}
function ajax_vrednost_condition_editing_close () {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$vrednost = $_POST['vrednost'];
$if = $_POST['if'];
$grid = $_POST['grid'];
$b = new Branching($this->anketa);
if($grid == 1) {
echo '<span class="red" style="cursor:pointer" onclick="vrednost_condition_editing(\''.$vrednost.'\'); return false;" title="'.$lang['srv_podif_edit'].'">*</span>';
}else{
$b->conditions_display($if, 0, 1);
}
//dodamo trikotnik error na koncu
if ($b->condition_check($if) != 0)
echo '<span class="faicon warning icon-orange"></span>';
}
function ajax_pagebreak ($spr = 0, $force_on = 0) {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$spremenljivka = $_POST['spremenljivka'];
if ($spr > 0) $spremenljivka = $spr;
$sql = sisplet_query("SELECT pagebreak FROM srv_branching WHERE element_spr = '$spremenljivka'");
$row = mysqli_fetch_array($sql);
if ($row['pagebreak'] == 0 || $force_on == 1)
$pagebreak = 1;
else
$pagebreak = 0;
sisplet_query("UPDATE srv_branching SET pagebreak = '$pagebreak' WHERE element_spr = '".$spremenljivka."' AND ank_id='".$this->anketa."'");
$this->check_loop();
$b = new Branching($this->anketa);
$b->repare_vrstni_red();
$b->trim_grupe();
//$this->pagebreak_display($spremenljivka);
$this->spremenljivka = 0;
$b->branching_struktura();
}
function ajax_pagebreak_all () {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
sisplet_query("UPDATE srv_branching SET pagebreak = '1' WHERE element_spr > '0' AND ank_id='".$this->anketa."'");
$b = new Branching($this->anketa);
$b->repare_vrstni_red();
$b->trim_grupe();
//$this->pagebreak_display($spremenljivka);
$this->spremenljivka = 0;
$b->branching_struktura();
}
function ajax_vprasanje_edit () {
$spremenljivka = $_POST['spremenljivka'];
$this->spremenljivka = $spremenljivka;
$b = new Branching($this->anketa);
$b->display_vprasanja();
}
function ajax_refresh_left () {
$b = new Branching($this->anketa);
$b->spremenljivka = $this->spremenljivka;
$b->branching_struktura();
}
function ajax_refresh_right () {
$b = new Branching($this->anketa);
$b->display_vprasanja();
$b->showVprasalnikBottom();
}
function ajax_get_new_spr () {
$sql = sisplet_query("SELECT s.id FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id=g.id AND g.ank_id='$this->anketa' ORDER BY s.id DESC LIMIT 1");
$row = mysqli_fetch_array($sql);
echo $row['id'];
}
function ajax_if_collapsed () {
Common::updateEditStamp();
$if = $_POST['if'];
$collapsed = $_POST['collapsed'];
sisplet_query("UPDATE srv_if SET collapsed='$collapsed' WHERE id = '$if'");
}
function ajax_if_display_collapsed () {
$if = $_POST['if'];
$b = new Branching($this->anketa);
$b->display_if_content($if);
}
function ajax_editmode_introconcl () {
$id = $_POST['id'];
$b = new Branching($this->anketa);
$b->introduction_conclusion($id, 1);
}
function ajax_normalmode_introconcl () {
$id = $_POST['id'];
$b = new Branching($this->anketa);
$b->introduction_conclusion($id);
}
function ajax_edit_introconcl () {
Common::updateEditStamp();
$id = $_POST['id'];
$text = $_POST['text'];
$opomba = strip_tags($_POST['opomba']);
if ($id == -1) {
sisplet_query("UPDATE srv_anketa SET introduction='$text', intro_opomba='$opomba' WHERE id='$this->anketa'");
}
elseif ($id == -2) {
sisplet_query("UPDATE srv_anketa SET conclusion='$text', concl_opomba='$opomba' WHERE id='$this->anketa'");
}
else{
sisplet_query("UPDATE srv_anketa SET statistics='$text' WHERE id='$this->anketa'");
}
}
function ajax_introconcl_visible () {
Common::updateEditStamp();
$id = $_POST['id'];
$row = SurveyInfo::getInstance()->getSurveyRow();
if ($id == -1) {
$name = 'show_intro';
} else {
$name = 'show_concl';
}
$show = $row[$name];
if ($show == 1)
$newshow = 0;
else
$newshow = 1;
sisplet_query("UPDATE srv_anketa SET $name = '$newshow' WHERE id ='$this->anketa'");
SurveyInfo :: getInstance()->resetSurveyData();
$b = new Branching($this->anketa);
$b->introduction_conclusion($id);
}
function ajax_concl_settings () {
Common::updateEditStamp();
$text = $_POST['text'];
$url = $_POST['url'];
if ($_POST['concl_link'] == 'true')
$concl_link = 0;
else
$concl_link = 1;
if ($_POST['concl_back_button'] == 'true')
$concl_back_button = 1;
else
$concl_back_button = 0;
sisplet_query("UPDATE srv_anketa SET text='$text', url='$url', concl_link='$concl_link', concl_back_button='$concl_back_button' WHERE id = '$this->anketa'");
}
function ajax_scale_ordnom () {
Common::updateEditStamp();
$spremenljivka = $_POST['spremenljivka'];
$value = $_POST['value'];
sisplet_query("UPDATE srv_spremenljivka SET skala='$value' WHERE id='$spremenljivka'");
$b = new Branching($this->anketa);
$b->vprasanje($spremenljivka);
}
function ajax_expand () {
$mode = $_POST['mode'];
$b = new Branching($this->anketa);
$b->display_vprasanja($mode);
}
function ajax_refresh_spremenljivka_name () {
$spremenljivka = $_POST['spremenljivka'];
$b = new Branching($this->anketa);
$b->spremenljivka_name($spremenljivka);
}
function ajax_prestevilci () {
global $site_url;
Common::updateEditStamp();
Common::getInstance()->Init($this->anketa);
Common::getInstance()->prestevilci(0, true);
echo $site_url.'admin/survey/index.php?anketa='.$this->anketa.'&a=branching';
}
function ajax_dodaj_blok_interpretacije () {
global $site_url;
global $lang;
Common::updateEditStamp();
// blok
$this->ajax_if_new(0, 0, 0, 1);
$sql = sisplet_query("SELECT element_if FROM srv_branching WHERE ank_id='$this->anketa' AND parent='0' AND element_if>0 ORDER BY vrstni_red DESC LIMIT 1");
$row = mysqli_fetch_array($sql);
$if_id = $row['element_if'];
// bloku nastavimo labelo
sisplet_query("UPDATE srv_if SET label = '".$lang['srv_zakljucek_vprasalnika']."' WHERE id = '$if_id'");
// spremenljivka compute
$this->ajax_spremenljivka_new(0, $if_id, 1);
// spremenljivko nastavimo tip na compute
sisplet_query("UPDATE srv_spremenljivka SET tip='22', size='1', naslov='$lang[srv_vprasanje_tip_22]', variable='sum', variable_custom='1' WHERE id = '$this->spremenljivka'");
// nastavimo page break
sisplet_query("UPDATE srv_branching SET pagebreak = '1' WHERE element_spr = '".$this->spremenljivka."' AND ank_id='".$this->anketa."'");
$b = new Branching($this->anketa);
$b->repare_vrstni_red();
$b->trim_grupe();
// spremenljivka label
$this->ajax_spremenljivka_new(0, $if_id, 1);
// spremenljivko nastavimo tip label
sisplet_query("UPDATE srv_spremenljivka SET tip='5', naslov='Rezultat: #sum#' WHERE id = '$this->spremenljivka'");
}
function ajax_check_pogoji() {
global $lang;
$b = new Branching($this->anketa);
$code = $b->check_pogoji();
// ce je vse ok, preverimo se loope
if ($code === true)
$code = $b->check_loops();
// ce je vse ok, preverimo se validacije
if ($code === true)
$code = $b->check_validation();
// ce je vse ok, preverimo se imena variabel (vprasanj in variabel znotraj vprasanj)
if ($code === true)
$code = $b->check_variable();
// ce je vse ok, preverimo se vrednosti stolpcev v gridu (ce je slucajno kaksna prazna)
if ($code === true)
$code = $b->check_grid_value();
// pogoji so ok
if ($code === true) {
if ($_GET['izpis'] == 'long') {
echo '<h2>'.$lang['srv_check_pogoji_ok2'].'</h2>';
echo '<div class="popup_close"><a href="#" onClick="$(\'#check_pogoji\').fadeOut(\'slow\'); $(\'#fade\').fadeOut(\'slow\');">✕</a></div>';
echo '<p>'.$lang['srv_check_pogoji_ok'].'!</p>';
echo '<div class="button_holder">';
echo '<button class="medium blue" onClick="$(\'#check_pogoji\').fadeOut(\'slow\'); $(\'#fade\').fadeOut(\'slow\');">'.$lang['srv_zapri'].'</button>';
echo '</div>';
} else {
echo '1';
}
// pogoji niso ok
} else {
if ($_GET['izpis'] == 'long') {
if ($code['type'] == 'if' || $code['type'] == 'podif')
echo '<h2>'.$lang['srv_check_pogoji_not_ok'].'</h2>';
elseif ($code['type'] == 'loop')
echo '<h2>'.$lang['srv_loop_no_nesting'].'</h2>';
elseif ($code['type'] == 'question_variable')
echo '<h2>'.$lang['srv_duplicate_question_variable'].'</h2>';
elseif ($code['type'] == 'variable')
echo '<h2>'.$lang['srv_duplicate_variables'].'</h2>';
elseif ($code['type'] == 'grid_value')
echo '<h2>'.$lang['srv_empty_grid_values'].'</h2>';
echo '<div class="popup_close"><a href="#" onClick="$(\'#check_pogoji\').fadeOut(\'slow\'); $(\'#fade\').fadeOut(\'slow\');">✕</a></div>';
// napaka v ifih
if ($code['type'] == 'if') {
$sql = sisplet_query("SELECT id, number FROM srv_if WHERE id = '$code[id]'");
$row = mysqli_fetch_array($sql);
echo '<p class="bottom16">'.$lang['srv_check_pogoji_if'].' <a class="noline" href="javascript:condition_editing(\''.$row['id'].'\');$(\'#check_pogoji\').fadeOut(\'slow\');popupClose();"><b>'.$row['number'].'</b></a>.</p>';
}
// napaka v podifih, ki so nastavljeni na vrednosti spremenljivk
elseif ($code['type'] == 'podif') {
$sql = sisplet_query("SELECT id, naslov, variable FROM srv_spremenljivka WHERE id = '$code[id]'");
$row = mysqli_fetch_array($sql);
echo '<p>'.$lang['srv_check_pogoji_spremenljivka'].': <b><a href="javascript:vprasanje_fullscreen(\''.$row['id'].'\');$(\'#check_pogoji\').fadeOut(\'slow\');popupClose();">'.$row['variable'].' - '.strip_tags($row['naslov']).'</a></b></p>';
}
// napaka z gnezdenjem loopov
elseif ($code['type'] == 'loop') {
$sql = sisplet_query("SELECT id, number FROM srv_if WHERE id = '$code[id]'");
$row = mysqli_fetch_array($sql);
echo '<p>'.$lang['srv_check_pogoji_loop'].' <a href="javascript:condition_editing(\''.$row['id'].'\');$(\'#check_pogoji\').fadeOut(\'slow\');popupClose();"><b>'.$row['number'].'</b></a></p>';
}
elseif ($code['type'] == 'validation') {
$sql = sisplet_query("SELECT id, naslov, variable FROM srv_spremenljivka WHERE id = '$code[id]'");
$row = mysqli_fetch_array($sql);
echo '<p>'.$lang['srv_check_validacija'].': <b><a href="javascript:vprasanje_fullscreen(\''.$row['id'].'\');$(\'#check_pogoji\').fadeOut(\'slow\');popupClose();">'.$row['variable'].' - '.strip_tags($row['naslov']).'</a></b></p>';
}
// napaka z imeni variabel
elseif ($code['type'] == 'variable') {
foreach ($code['vars'] AS $var) {
echo '<strong>'.$var.'</strong><br />';
};
}
// napaka z vrednostmi v gridu
elseif ($code['type'] == 'grid_value') {
foreach ($code['vars'] AS $var) {
echo '<strong>'.$var.'</strong><br />';
};
}
// error code
echo '<p>';
if ($code['code'] == 1) {
echo '<img src="img_'.$this->skin.'/error.png" alt="" /> '.$lang['srv_error_oklepaji'].'';
} elseif ($code['code'] == 2) {
echo '<img src="img_'.$this->skin.'/error.png" alt="" /> '.$lang['srv_error_spremenljivka'].'';
} elseif ($code['code'] == 3) {
echo '<img src="img_'.$this->skin.'/error.png" alt="" /> '.$lang['srv_error_vrednost'].'';
} elseif ($code['code'] == 4) {
echo '<img src="img_'.$this->skin.'/error.png" alt="" /> '.$lang['srv_error_numericno'].'';
} elseif ($code['code'] == 5) {
echo '<img src="img_'.$this->skin.'/error.png" alt="" /> '.$lang['srv_error_calculation'].'';
} elseif ($code['code'] == 6) {
echo '<img src="img_'.$this->skin.'/error.png" alt="" /> '.$lang['srv_error_loop'].'';
}
echo '</p>';
echo '<div class="button_holder">';
echo '<button class="medium blue" onClick="$(\'#check_pogoji\').fadeOut(\'slow\'); $(\'#fade\').fadeOut(\'slow\');">'.$lang['srv_zapri'].'</button>';
echo '</div>';
}
else {
echo '<h2>'.$lang['srv_check_pogoji_not_ok'].'</h2>';
echo '<div class="popup_close"><a href="#" onClick="$(\'#surveyTrajanje\').fadeOut(\'slow\'); $(\'#fade\').fadeOut(\'slow\');">✕</a></div>';
echo '<p>'.$lang['srv_check_pogoji_not_ok_txt'].'</p>';
echo '<div class="button_holder">';
echo '<button class="medium blue" onclick="$(\'#surveyTrajanje\').fadeOut(\'slow\'); $(\'#fade\').fadeOut(\'slow\');">'.$lang['srv_zapri'].'</button>';
echo '</div>';
}
}
}
/**
* alert, da se naj zapira bloke (shranimo da se ne prikazuje vec)
*
*/
function ajax_alert_close_block () {
global $lang;
SurveySetting::getInstance()->Init($this->anketa);
$show_alert = SurveySetting::getInstance()->getSurveyMiscSetting('alert_close_block');
if($show_alert != '2'){
echo '<h2>'.$lang['alert_close_block_title'].'</h2>';
echo $lang['alert_close_block'];
echo '<div class="button_holder">';
echo '<button class="medium blue" onclick="alert_close_block(); return false;">'.$lang['srv_zapri'].'</button>';
echo '</div>';
/* echo '<span class="buttonwrapper floatRight">';
echo '<a class="ovalbutton ovalbutton_grey" href="#" onclick="alert_close_block(); return false;"><span>'.$lang['srv_zapri'].'</span></a>';
echo '</span>'; */
SurveySetting::getInstance()->setSurveyMiscSetting('alert_close_block', '2');
}
else{
return false;
}
}
/**
* spremeni nastavitve toolboxa ali nacina prikaza ankete
*
*/
function ajax_change_mode () {
Common::updateEditStamp();
$what = $_REQUEST['what'];
$value = $_REQUEST['value'];
$row = SurveyInfo::getInstance()->getSurveyRow();
if ($what == 'expanded') {
$s = sisplet_query("UPDATE srv_anketa SET expanded = '$value' WHERE id = '$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
} elseif ($what == 'flat') {
$s = sisplet_query("UPDATE srv_anketa SET flat = '$value' WHERE id = '$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
} elseif ($what == 'toolbox') {
if ($value == 1) { // basic nacin
$s = sisplet_query("UPDATE srv_anketa SET toolbox = '$value', expanded = '1', flat = '1' WHERE id = '$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
elseif ($value == 2) { // advanced nacin
$s = sisplet_query("UPDATE srv_anketa SET toolbox = '$value', expanded = '0', flat = '0' WHERE id = '$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
elseif ($value == 3 || $value == 4) { // knjiznica (3 in 4 da se ve za nazaj na 1 ali 2)
$s = sisplet_query("UPDATE srv_anketa SET toolbox = '$value' WHERE id = '$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
//else die();
} elseif ($what == 'toolboxback') { // iz knjiznice nazaj v obicno urejanje
$s = sisplet_query("UPDATE srv_anketa SET toolbox = '$value' WHERE id = '$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
} elseif ($what == 'popup') {
$s = sisplet_query("UPDATE srv_anketa SET popup = '$value' WHERE id = '$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
} elseif ($what == 'form_settings_obvescanje'){
SurveySetting::getInstance()->setSurveyMiscSetting('srvtoolbox_form_alert', $value);
} elseif ($what == 'form_settings_vabila'){
SurveySetting::getInstance()->setSurveyMiscSetting('srvtoolbox_form_email', $value);
}
SurveyInfo::getInstance()->resetSurveyData();
}
/**
* spreminjanje hitrih nastavitev
*
*/
function ajax_edit_quick_settings () {
Common::updateEditStamp();
$what = $_POST['what'];
$results = $_POST['results'];
$status1 = $_POST['status1'];
if($what == 'finish_author' || $what == 'finish_respondent_cms' || $what == 'finish_respondent' || $what == 'finish_other' | $what == 'finish_other_emails') {
sisplet_query("INSERT INTO srv_alert (ank_id, $what) VALUES ('$this->anketa', '$results')
ON DUPLICATE KEY UPDATE $what = '$results' ");
}
else{
sisplet_query("UPDATE srv_anketa SET $what = '$results' WHERE id = '$this->anketa'");
}
$b = new Branching($this->anketa);
$b->toolbox_settings($status1);
}
/**
* @desc funkcije, ki pohendla komentarje ankete in vprasanj (kreira novo temo, ce se ni itd...)
*
*/
function ajax_comment_manage ($t = false, $s = false, $v = false, $o = false) {
global $site_path;
global $site_url;
global $lang;
global $global_user_id;
global $admin_type;
/**
* $type : 0 - komentar na anketo
* 1 - komentar na vprasanje
* 2 - komentar respondentov na vprasanje
* 4 - komentar respondentov na anketo
* 5 - komentar na if
* 6 - komentar na blok
*
* $view : 0 - izpise se samo field za dodajanje komentarja (komentarjev se ne da brati)
* 1 - izpisejo se tudi ze vneseni komentarji
* 3 - izpis komentarjev v urejanju vprasanja tabu 'Komentarji'
* 4 - izpis komentarjev v zgornjem zavihku Komentarji
* 5 - izpis komentarjev v zgornjem zavihku Komentarji - za respondente
*/
$spremenljivka = !$s ? $_REQUEST['spremenljivka'] : $s;
$type = !$t ? $_REQUEST['type'] : $t;
$view = $_REQUEST['view'];
SurveySetting::getInstance()->Init($this->anketa);
$sortpostorder = SurveySetting::getInstance()->getSurveyMiscSetting('sortpostorder');
$addfieldposition = SurveySetting::getInstance()->getSurveyMiscSetting('addfieldposition');
$survey_comment_viewadminonly = SurveySetting::getInstance()->getSurveyMiscSetting('survey_comment_viewadminonly');
$survey_comment_viewauthor = SurveySetting::getInstance()->getSurveyMiscSetting('survey_comment_viewauthor');
$question_comment_viewadminonly = SurveySetting::getInstance()->getSurveyMiscSetting('question_comment_viewadminonly');
$question_comment_viewauthor = SurveySetting::getInstance()->getSurveyMiscSetting('question_comment_viewauthor');
$commentmarks = SurveySetting::getInstance()->getSurveyMiscSetting('commentmarks');
$commentmarks_who = SurveySetting::getInstance()->getSurveyMiscSetting('commentmarks_who');
$comment_history = SurveySetting::getInstance()->getSurveyMiscSetting('comment_history');
$survey_comment_viewadminonly_resp = SurveySetting::getInstance()->getSurveyMiscSetting('survey_comment_viewadminonly_resp');
$survey_comment_viewauthor_resp = SurveySetting::getInstance()->getSurveyMiscSetting('survey_comment_viewauthor_resp');
//$question_resp_comment_viewadminonly = SurveySetting::getInstance()->getSurveyMiscSetting('question_resp_comment_viewadminonly');
$f = new Forum;
$rowi = SurveyInfo::getInstance()->getSurveyRow();
// vprasanje (1) in en oblacek za celo anketo (0)
if ($type == 1 or $type == 0) {
// okvir, da se lahko refresha pri oddaji novega komentarja
if ($_REQUEST['refresh'] != '1')
echo '<div id="survey_comment_'.$spremenljivka.'_'.$view.'">';
$vsebina = !$v ? $_REQUEST['vsebina'] : $v;
if ($spremenljivka > 0) { // komentar na spremenljivko
$rows = Cache::srv_spremenljivka($spremenljivka);
if ($rows['thread'] > 0)
$tid = $rows['thread'];
} elseif ($spremenljivka == -1) { // komentar na uvod
$tid = $rowi['thread_intro'];
$rows['naslov'] = $lang['srv_intro_label'];
} elseif ($spremenljivka == -2) { // komentar na zakljucek
$tid = $rowi['thread_concl'];
$rows['naslov'] = $lang['srv_end_label'];
} else { // komeentar na anketo
$tid = $rowi['thread'];
$rows['naslov'] = $rowi['naslov'];
}
// poslali smo vsebino, ki jo shranimo v forum
if ($vsebina != '') {
Common::updateEditStamp();
if ($rowi['forum'] == 0) {
$rowi['forum'] = $this->comment_create_forum();
}
$f->currentForum = $rowi['forum'];
if ($tid == 0) {
if ($type == 1)
$vsebina_post = $lang['srv_forum_intro'].strip_tags($rows['naslov']).'<br /><br /><a href="'.$site_url.'admin/survey/index.php?anketa='.$this->anketa.'">'.$lang['srv_forum_back'].'</a>';
else
$vsebina_post = $lang['srv_forum_srv_intro'].strip_tags($rows['naslov']).'<br /><br /><a href="'.$site_url.'admin/survey/index.php?anketa='.$this->anketa.'">'.$lang['srv_forum_back'].'</a>';
$tid = $f->addPost($global_user_id, strip_tags($rows['naslov']), $vsebina_post, 0, 0, 0, false);
if ($spremenljivka > 0)
$sql = sisplet_query("UPDATE srv_spremenljivka SET thread = '$tid' WHERE id = '$spremenljivka'");
elseif ($spremenljivka == -1)
$sql = sisplet_query("UPDATE srv_anketa SET thread_intro = '$tid' WHERE id = '$this->anketa'");
elseif ($spremenljivka == -2)
$sql = sisplet_query("UPDATE srv_anketa SET thread_concl = '$tid' WHERE id = '$this->anketa'");
else
$sql = sisplet_query("UPDATE srv_anketa SET thread = '$tid' WHERE id = '$this->anketa'");
// vsilimo refresh podatkov
SurveyInfo :: getInstance()->resetSurveyData();
}
$f->currentThread = $tid;
$_id = $f->addPost($global_user_id, strip_tags($rows['naslov']), nl2br($vsebina), 0, 0, 0, false);
if ($o !== false) sisplet_query("UPDATE post SET ocena = '$o' WHERE id = '$_id'");
}
// prikazemo komentarje, ce le-ti obstajajo
if ($tid != 0 && ($view == 1 || $view == 3)) {
$orderby = $sortpostorder == 1 ? 'DESC' : 'ASC' ;
$tema_vsebuje = substr($lang['srv_forum_intro'],0,10); // da ne prikazujemo 1. default sporocila
if ($admin_type <= $question_comment_viewadminonly) { // vidi vse komentarje
$sql = sisplet_query("SELECT * FROM post WHERE vsebina NOT LIKE '%{$tema_vsebuje}%' AND tid='$tid' ORDER BY time $orderby, id $orderby");
} elseif (($type==0 && $survey_comment_viewauthor==1) || ($type==1 && $question_comment_viewauthor==1)) { // vidi samo svoje komentarje
$sql = sisplet_query("SELECT * FROM post WHERE vsebina NOT LIKE '%{$tema_vsebuje}%' AND tid='$tid' AND uid='$global_user_id' ORDER BY time $orderby, id $orderby");
} else { // ne vidi nobenih komentarjev
$sql = sisplet_query("SELECT * FROM post WHERE 1=0");
}
/*/ textarea za oddat komentar - zgoraj
if ($addfieldposition == 1) {
$this->add_comment_field($spremenljivka, $type, $view);
echo '<br /><br />';
}*/
// textarea za oddat komentar - spodaj
if ($addfieldposition == 0 || $addfieldposition == '') {
echo '<div id="survey_comment_0_1">';
$this->add_comment_field($spremenljivka, $type, $view, true, false);
echo '</div>';
}
} else {
//$this->add_comment_field($spremenljivka, $type, $view);
}
if ($_REQUEST['refresh'] != '1' || $view==3)
echo '</div>';
}
// komentarji na if ali blok
elseif ($type == 5 || $type == 6){
// okvir, da se lahko refresha pri oddaji novega komentarja
if ($_REQUEST['refresh'] != '1')
echo '<div id="survey_comment_'.$spremenljivka.'_'.$view.'">';
$vsebina = !$v ? $_REQUEST['vsebina'] : $v;
$rows = Cache::srv_if($spremenljivka);
if ($rows['thread'] > 0)
$tid = $rows['thread'];
// poslali smo vsebino, ki jo shranimo v forum
if ($vsebina != '') {
Common::updateEditStamp();
if ($row['forum'] == 0) {
$row['forum'] = $this->comment_create_forum();
}
$f->currentForum = $row['forum'];
if ($tid == 0) {
if ($type == 5)
$vsebina_post = $lang['srv_forum_intro_if'].strip_tags($rows['naslov']).'<br /><br /><a href="'.$site_url.'admin/survey/index.php?anketa='.$this->anketa.'">'.$lang['srv_forum_back'].'</a>';
else
$vsebina_post = $lang['srv_forum_intro_blok'].strip_tags($rows['naslov']).'<br /><br /><a href="'.$site_url.'admin/survey/index.php?anketa='.$this->anketa.'">'.$lang['srv_forum_back'].'</a>';
$tid = $f->addPost($global_user_id, strip_tags($rows['naslov']), $vsebina_post, 0, 0, 0, false);
$sql = sisplet_query("UPDATE srv_if SET thread = '$tid' WHERE id = '$spremenljivka'");
// vsilimo refresh podatkov
SurveyInfo :: getInstance()->resetSurveyData();
}
$f->currentThread = $tid;
$_id = $f->addPost($global_user_id, strip_tags($rows['naslov']), nl2br($vsebina), 0, 0, 0, false);
if ($o !== false) sisplet_query("UPDATE post SET ocena = '$o' WHERE id = '$_id'");
}
// prikazemo komentarje, ce le-ti obstajajo
if ($tid != 0 && ($view == 1 || $view == 3)) {
$orderby = $sortpostorder == 1 ? 'DESC' : 'ASC' ;
$tema_vsebuje = substr($lang['srv_forum_intro'],0,10); // da ne prikazujemo 1. default sporocila
if ($admin_type <= $question_comment_viewadminonly) { // vidi vse komentarje
$sql = sisplet_query("SELECT * FROM post WHERE vsebina NOT LIKE '%{$tema_vsebuje}%' AND tid='$tid' ORDER BY time $orderby, id $orderby");
} elseif ($survey_comment_viewauthor==1 || $question_comment_viewauthor==1) { // vidi samo svoje komentarje
$sql = sisplet_query("SELECT * FROM post WHERE vsebina NOT LIKE '%{$tema_vsebuje}%' AND tid='$tid' AND uid='$global_user_id' ORDER BY time $orderby, id $orderby");
} else { // ne vidi nobenih komentarjev
$sql = sisplet_query("SELECT * FROM post WHERE 1=0");
}
if (mysqli_num_rows($sql) > 0) {
if ($view == 1) {
//echo '<b><a href="'.$site_url.'index.php?fl=4&fid='.$row['forum'].'&tid='.$tid.'&sortpostorder='.$sortpostorder.'" target="_blank">'.$lang['srv_forum_go'].'</a></b>';
$rows = mysqli_num_rows($sql);
if ($rows > 0) echo '<img src="'.$site_url.'/admin/survey/img_0/'.($sortpostorder==1?'up':'down').'.gif" style="float:right" title="'.($sortpostorder==1?$lang['forum_desc']:$lang['forum_asc']).'" />';
echo '<br /><br />';
} elseif ($view == 3) {
echo '<div style="width:45%; float:left">';
echo '<h3 class="red"><b>'.$lang['comments'].'</b>';
$rows = mysqli_num_rows($sql);
if ($rows > 0) echo '<img src="img_0/'.($sortpostorder==1?'up':'down').'.gif" style="float:right" title="'.($sortpostorder==1?$lang['forum_desc']:$lang['forum_asc']).'" />';
echo '</h3>';
}
}
// textarea za oddat komentar - zgoraj
if ($addfieldposition == 1) {
$this->add_comment_field($spremenljivka, $type, $view);
echo '<br /><br />';
}
if (mysqli_num_rows($sql) > 0) {
$i = 0;
$rows = mysqli_num_rows($sql);
while ($row = mysqli_fetch_array($sql)) {
// Prikazemo zgodovino glede na nastavitev
if($comment_history == '2' || (($comment_history == '0' || $comment_history == '') && $row['uid'] == $global_user_id)){
if ($row['ocena'] == 0) echo '<span style="color:black">';
elseif ($row['ocena'] == 1) echo '<span style="color:darkgreen">';
elseif ($row['ocena'] == 2) echo '<span style="color:#999999">';
elseif ($row['ocena'] == 3) echo '<span style="color:#999999">';
else echo '<span>';
echo '<b>'.$f->user($row['uid']).'</b> ('.$f->datetime1($row['time']).'):';
if ($admin_type <= 1 || $rowi['insert_uid']==$global_user_id || $commentmarks_who==0) {
echo '<div style="float:right">';
if ($commentmarks == 1) {
echo ' <select name="ocena" onchange="$.post(siteurl+\'ajax.php?a=comment_ocena\', {type: \'question_comment\', ocena: this.value, id: \''.$row['id'].'\', anketa: \''.$rowi['id'].'\'}, function () { add_comment(\''.$spremenljivka.'\', \''.$type.'\', \''.$view.'\', \'\' ); });">
<option value="0"'.($row['ocena']==0?' selected':'').'>'.$lang['srv_undecided'].'</option>
<option value="1"'.($row['ocena']==1?' selected':'').'>'.$lang['srv_todo'].'</option>
<option value="2"'.($row['ocena']==2?' selected':'').'>'.$lang['srv_done'].'</option>
<option value="3"'.($row['ocena']==3?' selected':'').'>'.$lang['srv_not_relevant'].'</option>
</select>';
} else {
echo '<input type="checkbox" name="ocena_'.$row['id'].'" id="ocena_'.$row['id'].'" style="margin-right:3px;" onchange="$.post(siteurl+\'ajax.php?a=comment_ocena\', {type: \'question_comment\', ocena: (this.checked?\'2\':\'0\'), id: \''.$row['id'].'\', anketa: \''.$rowi['id'].'\'}, function () { add_comment(\''.$spremenljivka.'\', \''.$type.'\', \''.$view.'\', \'\' ); });" value="2" '.($row['ocena'] >= 2?' checked':'').' /><label for="ocena_'.$row['id'].'">'.$lang['srv_done'].'</label>';
}
//echo ' <br /><a href="javascript:comment_on_comment(\''.$rowt['id'].'\');">'.$lang['srv_comment_comment'].'</a>';
echo '</div>';
}
echo '<br/>'.$row['vsebina'].'<hr>';
echo '</span>';
}
//}
$i++;
// Nastavimo oglede foruma in teme
if ($global_user_id > 0) {
$sqla2 = sisplet_query("SELECT time FROM views WHERE pid='" .$row['id'] ."' AND uid='$global_user_id'");
if (mysqli_num_rows($sqla2) > 0) {
$sqla3 = sisplet_query("UPDATE views SET time=NOW() WHERE pid='" .$row['id'] ."' AND uid='$global_user_id'");
} else {
$sqla3 = sisplet_query("INSERT INTO views (pid, uid, time) VALUES ('" .$row['id'] ."', '$global_user_id', NOW())");
}
}
}
}
// textarea za oddat komentar - spodaj
if ($addfieldposition == 0 || $addfieldposition == '') {
echo '<br />';
$this->add_comment_field($spremenljivka, $type, $view);
}
} else {
$this->add_comment_field($spremenljivka, $type, $view);
}
if ($_REQUEST['refresh'] != '1' || $view==3)
echo '</div>';
}
// komentarji respondentov
elseif ($type == 2) {
$db_table = SurveyInfo::getInstance()->getSurveyArchiveDBString();
$orderby = $sortpostorder == 1 ? 'DESC' : 'ASC' ;
$sql = sisplet_query("SELECT d.*, u.time_edit FROM srv_data_text".$db_table." d, srv_user u WHERE d.spr_id='0' AND d.vre_id='$spremenljivka' AND u.id=d.usr_id ORDER BY d.id $orderby");
if (mysqli_num_rows($sql) > 0) echo '<img src="img_0/'.($sortpostorder==1?'up':'down').'.gif" style="float:right" title="'.($sortpostorder==1?$lang['forum_desc']:$lang['forum_asc']).'" />';
while ($row = mysqli_fetch_array($sql)) {
if ($row['text2'] == 0) echo '<span style="color:black">';
elseif ($row['text2'] == 1) echo '<span style="color:darkgreen">';
elseif ($row['text2'] == 2) echo '<span style="color:#999999">';
elseif ($row['text2'] == 3) echo '<span style="color:#999999">';
else echo '<span>';
echo $f->datetime1($row['time_edit']).':';
if ($admin_type <= 1 || $rowi['insert_uid']==$global_user_id || $commentmarks_who==0) {
echo '<div style="float:right">';
if ($commentmarks == 1) {
echo ' <select name="ocena'.$row['id'].'" onchange="$.post(siteurl+\'ajax.php?a=comment_ocena\', {type: \'respondent_comment\', text2: this.value, id: \''.$row['id'].'\', anketa: \''.$rowi['id'].'\'}, function () {window.location.reload();});">
<option value="0"'.($row['text2']==0?' selected':'').'>'.$lang['srv_undecided'].'</option>
<option value="1"'.($row['text2']==1?' selected':'').'>'.$lang['srv_todo'].'</option>
<option value="2"'.($row['text2']==2?' selected':'').'>'.$lang['srv_done'].'</option>
<option value="3"'.($row['text2']==3?' selected':'').'>'.$lang['srv_not_relevant'].'</option>
</select>';
} else {
echo '<input type="checkbox" name="ocena_'.$row['id'].'" id="ocena_'.$row['id'].'" onchange="$.post(siteurl+\'ajax.php?a=comment_ocena\', {type: \'respondent_comment\', text2: (this.checked?\'2\':\'0\'), id: \''.$row['id'].'\', anketa: \''.$rowi['id'].'\'}, function () {window.location.reload();});" value="2" '.($row['text2'] >= 2?' checked':'').' /><label for="ocena_'.$row['id'].'">'.$lang['srv_done'].'</label>';
}
echo ' </div>';
}
echo '<br />'.nl2br($row['text']).'<hr>';
echo '</span>';
}
}
// komentarji respondentov za celo anketo
elseif($type == 4){
// okvir, da se lahko refresha pri oddaji novega komentarja
if ($_REQUEST['refresh'] != '1')
echo '<div id="survey_comment_'.$spremenljivka.'_'.$view.'">';
$vsebina = !$v ? $_REQUEST['vsebina'] : $v;
// poslali smo vsebino, ki jo shranimo
if ($vsebina != '') {
$ocena = ($o !== false) ? $o : 0;
$sql = sisplet_query("INSERT INTO srv_comment_resp (ank_id, usr_id, comment, comment_time, ocena) VALUES ('$this->anketa', '$global_user_id', '$vsebina', NOW(), '$ocena')");
}
// prikazemo komentarje, ce le-ti obstajajo
$sql = sisplet_query("SELECT id FROM srv_comment_resp WHERE ank_id='".$this->anketa."' ORDER BY comment_time $orderby");
if (mysqli_num_rows($sql) > 0 && ($view == 1 || $view == 3)) {
$orderby = $sortpostorder == 1 ? 'DESC' : 'ASC' ;
if ($admin_type <= $survey_comment_viewadminonly_resp) { // vidi vse komentarje
$sql = sisplet_query("SELECT * FROM srv_comment_resp WHERE ank_id='".$this->anketa."' ORDER BY comment_time $orderby, id $orderby");
} elseif ($survey_comment_viewauthor_resp == 1) { // vidi samo svoje komentarje
$sql = sisplet_query("SELECT * FROM srv_comment_resp WHERE ank_id='".$this->anketa."' AND usr_id='$global_user_id' ORDER BY comment_time $orderby, id $orderby");
} else { // ne vidi nobenih komentarjev
$sql = sisplet_query("SELECT * FROM srv_comment_resp WHERE 1=0");
}
if (mysqli_num_rows($sql) > 0) {
if ($view == 1) {
$rows = mysqli_num_rows($sql);
if ($rows > 0) echo '<img src="'.$site_url.'/admin/survey/img_0/'.($sortpostorder==1?'up':'down').'.gif" style="float:right" title="'.($sortpostorder==1?$lang['forum_desc']:$lang['forum_asc']).'" />';
echo '<br /><br />';
} elseif ($view == 3) {
echo '<div style="width:45%; float:left">';
echo '<h3 class="red"><b>'.$lang['comments'].'</b>';
$rows = mysqli_num_rows($sql);
if ($rows > 0) echo '<img src="img_0/'.($sortpostorder==1?'up':'down').'.gif" style="float:right" title="'.($sortpostorder==1?$lang['forum_desc']:$lang['forum_asc']).'" />';
echo '</h3>';
}
}
// textarea za oddat komentar - zgoraj
if ($addfieldposition == 1) {
$this->add_comment_field($spremenljivka, $type, $view);
echo '<br /><br />';
}
if (mysqli_num_rows($sql) > 0) {
$rows = mysqli_num_rows($sql);
while ($row = mysqli_fetch_array($sql)) {
// Prikazemo zgodovino glede na nastavitev
if($comment_history == '2' || (($comment_history == '0' || $comment_history == '') && $row['usr_id'] == $global_user_id && $global_user_id != 0)){
if ($row['ocena'] == 0) echo '<span style="color:black">';
elseif ($row['ocena'] == 1) echo '<span style="color:darkgreen">';
elseif ($row['ocena'] == 2) echo '<span style="color:#999999">';
elseif ($row['ocena'] == 3) echo '<span style="color:#999999">';
else echo '<span>';
$datetime = strtotime($row['comment_time']);
$datetime = date("d.m G:i", $datetime);
if($row['usr_id'] == 0){
$user = $lang['guest'];
}
else{
$sqlU = sisplet_query("SELECT name FROM users WHERE id='$row[usr_id]'");
$rowU = mysqli_fetch_array($sqlU);
$user = $rowU['name'];
}
echo '<b>'.$user.'</b> ('.$datetime.'):';
if ($admin_type <= 1 || $rowi['insert_uid']==$global_user_id || $commentmarks_who==0) {
// Zaenkrat ni ocen ce respondent komentira pri resevanju
/*echo '<div style="float:right">';
if ($commentmarks == 1) {
echo ' <select name="ocena" onchange="$.post(siteurl+\'ajax.php?a=comment_ocena\', {type: \'respondent_survey_comment\', ocena: this.value, id: \''.$row['id'].'\'}, function () { add_comment(\''.$spremenljivka.'\', \''.$type.'\', \''.$view.'\', \'\' ); });">
<option value="0"'.($row['ocena']==0?' selected':'').'>'.$lang['srv_undecided'].'</option>
<option value="1"'.($row['ocena']==1?' selected':'').'>'.$lang['srv_todo'].'</option>
<option value="2"'.($row['ocena']==2?' selected':'').'>'.$lang['srv_done'].'</option>
<option value="3"'.($row['ocena']==3?' selected':'').'>'.$lang['srv_not_relevant'].'</option>
</select>';
} else {
echo '<input type="checkbox" name="ocena_'.$row['id'].'" id="ocena_'.$row['id'].'" onchange="$.post(siteurl+\'ajax.php?a=comment_ocena\', {type: \'question_comment\', ocena: (this.checked?\'2\':\'0\'), id: \''.$row['id'].'\'}, function () { add_comment(\''.$spremenljivka.'\', \''.$type.'\', \''.$view.'\', \'\' ); });" value="2" '.($row['ocena'] >= 2?' checked':'').' /><label for="ocena_'.$row['id'].'">'.$lang['srv_done'].'</label>';
}
echo '</div>';*/
}
echo '<br/>'.$row['comment'].'<hr>';
echo '</span>';
}
}
}
// textarea za oddat komentar - spodaj
if ($addfieldposition == 0 || $addfieldposition == '') {
echo '<br />';
$this->add_comment_field($spremenljivka, $type, $view);
}
} else {
$this->add_comment_field($spremenljivka, $type, $view);
}
if ($_REQUEST['refresh'] != '1' || $view==3)
echo '</div>';
}
}
function add_comment_field ($spremenljivka, $type, $view, $form=true, $buttons=true) {
global $admin_type;
global $global_user_id;
global $lang;
global $site_url;
$rowanketa = SurveyInfo::getInstance()->getSurveyRow();
$tip_lang = '';
if ($type == 1 && $view == 4) //splošen komentar na strani testiranje
$tip_lang = 'S';
if ($type == 0 && $view == 1) //splošen komentar v dropdownu
$tip_lang = 'S';
if ($spremenljivka != 0) //komentar na vprašanja
$tip_lang = 'Q';
if ($type == 5) //komentar na pogoj
$tip_lang = 'IF';
elseif ($type == 6) //komentar na blok
$tip_lang = 'B';
echo '<textarea name="vsebina" placeholder="'.$lang['srv_comments_add_comment'.$tip_lang.''].'" id="vsebina_'.$spremenljivka.'_'.$view.'"></textarea>';
if ($buttons) {
echo '<div class="button_holder bottom0">';
if($_GET['a'] == 'comment_manage')
echo ' <button class="medium white-blue" onClick="closeCommentQtip(\''.$spremenljivka.'_'.$view.'\');">'.$lang['edit1338'].'</button>';
else
echo ' <button class="medium white-blue" onClick="toggleAddComment(\''.$spremenljivka.'_'.$view.'\');">'.$lang['edit1338'].'</button>';
echo ' <button class="medium blue" onclick="add_comment(\''.$spremenljivka.'\', \''.$type.'\', \''.$view.'\', $(\'#vsebina_'.$spremenljivka.'_'.$view.'\').val()); return false;">'.$lang['srv_comments_new'].'</button>';
echo '</div>';
}
}
/**
* @desc kreira nov forum za komentiranje ankete
*/
function comment_create_forum() {
global $site_path;
global $site_url;
global $lang;
global $global_user_id;
Common::updateEditStamp();
$sql = sisplet_query("SELECT * FROM misc WHERE what = 'SurveyForum'");
$row = mysqli_fetch_array($sql);
$parent = $row['value'];
$sqlp = sisplet_query("SELECT * FROM forum WHERE id='$parent'");
$rowp = mysqli_fetch_array($sqlp);
$row = SurveyInfo::getInstance()->getSurveyRow();
$sql = sisplet_query("INSERT INTO forum (parent, ord, naslov, opis, user, clan, admin) VALUES ('$parent', '2132154', '$row[naslov]', '', '$rowp[user]', '$rowp[clan]', '$rowp[admin]')");
$id = mysqli_insert_id($GLOBALS['connect_db']);
$sql = sisplet_query("UPDATE srv_anketa SET forum='$id' WHERE id = '$this->anketa'");
// vsilimo refresh podatkov
SurveyInfo :: getInstance()->resetSurveyData();
return $id;
}
function ajax_preview_spremenljivka () {
include_once('../../main/survey/app/global_function.php');
new \App\Controllers\SurveyController(true);
if(isset($_POST['spremenljivka'])){
$spremenljivka = $_POST['spremenljivka'];
save('forceShowSpremenljivka', true);
\App\Controllers\Vprasanja\VprasanjaController::getInstance()->displaySpremenljivka($spremenljivka);
}
}
function ajax_calculation_edit_variable () {
Common::updateEditStamp();
$variable = $_POST['variable'];
// preverimo, da ni se kje drugje v anekti tako ime spremenljivke
$sqlv = sisplet_query("SELECT s.variable FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id=g.id AND g.ank_id='$this->anketa'");
$ok = true;
while ($rowv = mysqli_fetch_array($sqlv)) {
if ($rowv['variable'] == $variable)
$ok = false;
}
// Ce se ime ze pojavi v anketi mu dodamo stevilko
if(!$ok){
$ok = false;
$i = 2;
while(!$ok){
$ok = true;
$variable = $_POST['variable'].'_'.$i;
$sqlv = sisplet_query("SELECT s.variable, s.id as id FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id=g.id AND g.ank_id='$this->anketa'");
while ($rowv = mysqli_fetch_array($sqlv)) {
if ($rowv['variable'] == $variable && $this->spremenljivka != $rowv['id']){
$ok = false;
$i++;
}
}
}
}
sisplet_query("UPDATE srv_spremenljivka SET variable='$variable', variable_custom='1' WHERE id='$this->spremenljivka'");
}
function ajax_calculation_edit_decimalna () {
Common::updateEditStamp();
$decimalna = $_POST['decimalna'];
sisplet_query("UPDATE srv_spremenljivka SET decimalna='$decimalna' WHERE id='$this->spremenljivka'");
}
function ajax_calculation_edit_missing () {
Common::updateEditStamp();
if(isset($_POST['spremenljivka']) && isset($_POST['missing'])){
$spremenljivka = $_POST['spremenljivka'];
$missing = $_POST['missing'];
$row = Cache::srv_spremenljivka($spremenljivka);
$newParams = new enkaParameters($row['params']);
$newParams->set('calcMissing', $missing);
$params = $newParams->getString();
$sql = sisplet_query("UPDATE srv_spremenljivka SET params='$params' WHERE id='$spremenljivka'");
}
}
function ajax_fill_value_loop () {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = $_POST['if'];
$spremenljivka = $_POST['spremenljivka'];
$row = Cache::srv_spremenljivka($spremenljivka);
// obicna spremenljivka
if (is_numeric($spremenljivka)) {
$spremenljivka = $spremenljivka;
$vrednost = 0;
// multigrid
} /*else {
$vrednost = str_replace('vre_', '', $spremenljivka);
$sql2 = sisplet_query("SELECT * FROM srv_vrednost WHERE id = '$vrednost'");
$row2 = mysqli_fetch_array($sql2);
$spremenljivka = $row2['spr_id'];
}*/
sisplet_query("REPLACE INTO srv_loop (if_id, spr_id) VALUES ('$if', '$spremenljivka')");
// na zacetku damo po defaultu na 'izbran'
$s = sisplet_query("DELETE FROM srv_loop_vre WHERE if_id = '$if'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("DELETE FROM srv_loop_data WHERE if_id = '$if'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
// pri numberju nafilamo 20 opcij - omogocali bomo max 20 zank po numberju
if ($row['tip'] == 7) {
$s = sisplet_query("INSERT INTO srv_loop_vre (if_id, vre_id) VALUES ('$if', NULL)");
for ($i=0; $i<20; $i++) {
$s = sisplet_query("INSERT INTO srv_loop_data (id, if_id, vre_id) VALUES ('', '$if', NULL)");
}
// pri ostalih se nafila vse ki so v srv_vrednost
} else {
$sql2 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='$spremenljivka' ORDER BY vrstni_red ASC");
while ($row2 = mysqli_fetch_array($sql2)) {
$vrednost = $row2['id'];
if ($vrednost > 0) {
$s = sisplet_query("INSERT INTO srv_loop_vre (if_id, vre_id) VALUES ('$if', '$vrednost')");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("INSERT INTO srv_loop_data (id, if_id, vre_id) VALUES ('', '$if', '$vrednost')");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
}
}
$b = new Branching($this->anketa);
$b->condition_editing($if);
}
function ajax_loop_edit () {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = $_POST['if'];
$vrednost = $_POST['vrednost'];
$s = sisplet_query("DELETE FROM srv_loop_vre WHERE if_id = '$if' ".(count($vrednost)>0?"AND vre_id NOT IN (".implode(',', $vrednost).")":"")."");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("DELETE FROM srv_loop_data WHERE if_id = '$if' ".(count($vrednost)>0?"AND vre_id NOT IN (".implode(',', $vrednost).")":"")."");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
if ($vrednost != null)
foreach ($vrednost AS $val)
if ($val > 0) {
$sql = sisplet_query("SELECT * FROM srv_loop_vre WHERE if_id='$if' AND vre_id='$val'");
if (mysqli_num_rows($sql) == 0) {
$s = sisplet_query("INSERT INTO srv_loop_vre (if_id, vre_id) VALUES ('$if', '$val')");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
$sql = sisplet_query("SELECT * FROM srv_loop_data WHERE if_id='$if' AND vre_id='$val'");
if (mysqli_num_rows($sql) == 0) {
$s = sisplet_query("INSERT INTO srv_loop_data (id, if_id, vre_id) VALUES ('', '$if', '$val')");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
}
$b = new Branching($this->anketa);
$b->condition_editing($if);
}
function ajax_loop_edit_advanced () {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = $_POST['if'];
$vrednost = $_POST['vrednost'];
$sql = sisplet_query("SELECT spr_id FROM srv_loop WHERE if_id='$if'");
$row = mysqli_fetch_array($sql);
// ko postnemo izbrane vrednosti, so podani vrstni_red in ne ID, ker JS zapolni cel array s praznimi vrednostmi do izbranega IDja (ki pa so lahko zelo veliki in je zato zelooo velik array)
$vre = array();
$sql = sisplet_query("SELECT id, vrstni_red FROM srv_vrednost WHERE spr_id='$row[spr_id]' ORDER BY vrstni_red ASC");
while ($row = mysqli_fetch_array($sql)) {
$vre[$row['vrstni_red']] = $row['id'];
}
$delete = array();
foreach ($vrednost AS $key => $val) {
if ($val != 'undefined' && $val < 3) { // 3 pomeni nikoli in tega ne shranimo v bazo
$delete[] = $vre[$key];
}
}
$s = sisplet_query("DELETE FROM srv_loop_vre WHERE if_id = '$if' ".(count($delete)>0?"AND vre_id NOT IN (".implode(',', $delete).")":"")."");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("DELETE FROM srv_loop_data WHERE if_id = '$if' ".(count($delete)>0?"AND vre_id NOT IN (".implode(',', $delete).")":"")."");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
foreach ($vrednost AS $key => $val) {
if ($val != 'undefined' && $val < 3) { // 3 pomeni nikoli in tega ne shranimo v bazo
//echo $vre[$key].': '.$val."\n";
$sql = sisplet_query("SELECT * FROM srv_loop_vre WHERE if_id='$if' AND vre_id='$vre[$key]'");
if (mysqli_num_rows($sql) == 0) {
$s = sisplet_query("INSERT INTO srv_loop_vre (if_id, vre_id, tip) VALUES ('$if', '$vre[$key]', '$val')");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
} else {
$s = sisplet_query("UPDATE srv_loop_vre SET tip='$val' WHERE if_id='$if' AND vre_id='$vre[$key]'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
$sql = sisplet_query("SELECT * FROM srv_loop_data WHERE if_id='$if' AND vre_id='$vre[$key]'");
if (mysqli_num_rows($sql) == 0) {
$s = sisplet_query("INSERT INTO srv_loop_data (id, if_id, vre_id) VALUES ('', '$if', '$vre[$key]')");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
}
}
$b = new Branching($this->anketa);
$b->condition_editing($if);
}
function ajax_loop_edit_max () {
Common::updateEditStamp();
$max = $_POST['max'];
$if = $_POST['if'];
$s = sisplet_query("UPDATE srv_loop SET max='$max' WHERE if_id = '$if'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
/**
* preveri, ce so loopi v redu postavljeni
*
*/
function check_loop () {
// preverimo za loope, ce so in ce so ok postavljeni
$b = new Branching($this->anketa);
$b->check_loop();
}
/**
* zakleni / odkleni anketo
*
*/
function ajax_anketa_lock () {
Common::updateEditStamp();
$locked = $_POST['locked'];
//mobile created nastavi na 0, ce je slucajno prej 1 (zaradi mobilne aplikacije)
$s = sisplet_query("UPDATE srv_anketa SET locked = '$locked', mobile_created = '0' WHERE id = '$this->anketa'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
echo 'index.php?anketa='.$this->anketa.'&a=branching';
}
function ajax_condition_sort() {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = $_POST['if'];
$sortable = $_POST['sortable'];
$sortable = explode('&', $sortable);
$i=1;
foreach ($sortable AS $cond) {
$condition = explode('=', $cond);
$condition = $condition[1];
$s = sisplet_query("UPDATE srv_condition SET vrstni_red='{$i}' WHERE id='{$condition}'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$i++;
}
$b = new Branching($this->anketa);
$b->repare_condition($if);
$b->condition_editing_inner($if);
}
function ajax_calculation_sort() {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$condition = $_POST['condition'];
$sortable = $_POST['sortable'];
$sortable = explode('&', $sortable);
$i=1;
foreach ($sortable AS $calc) {
$calculation = explode('=', $calc);
$calculation = $calculation[1];
$s = sisplet_query("UPDATE srv_calculation SET vrstni_red='{$i}' WHERE id='{$calculation}'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$i++;
}
$b = new Branching($this->anketa);
$b->repare_condition($if);
$b->calculation_editing_inner($condition);
}
function ajax_quota_sort() {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$condition = $_POST['condition'];
$sortable = $_POST['sortable'];
$sortable = explode('&', $sortable);
$i=1;
foreach ($sortable AS $val) {
$quota = explode('=', $val);
$quota = $quota[1];
$s = sisplet_query("UPDATE srv_quota SET vrstni_red='{$i}' WHERE id='{$quota}'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$i++;
}
$b = new Branching($this->anketa);
$b->repare_condition($if);
//$b->calculation_editing_inner($condition);
}
function ajax_spremenljivka_preview_print() {
global $lang;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>CMS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="minify/g=css" media="screen" rel="stylesheet" />
<link type="text/css" href="minify/g=cssPrint" media="print" rel="stylesheet" />
<!--[if lt IE 7]>
<link rel="stylesheet" href="http://localhost/fdv/cms2/admin/survey/css/ie6hacks.css" type="text/css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" href="http://localhost/fdv/cms2/admin/survey/css/ie7hacks.css" type="text/css" />
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" href="http://localhost/fdv/cms2/admin/survey/css/ie8hacks.css" type="text/css" />
<![endif]-->
</head>
<body>
<?
echo '<div class="button_holder print_button">';
echo '<button class="small blue" onclick="window.print(); return false;">'.$lang['hour_print2'].'</button>';
echo '</div>';
include_once('../../main/survey/app/global_function.php');
new \App\Controllers\SurveyController(true);
echo ' <div id="spremenljivka_preview">';
if ( $_GET['spremenljivka'] == -1 ) {
\App\Controllers\BodyController::getInstance()->displayIntroduction();
}
elseif ( $_GET['spremenljivka'] == -2 ) {
\App\Controllers\BodyController::getInstance()->displayKonec();
}
elseif ( $_GET['spremenljivka'] == -3 ) {
\App\Controllers\StatisticController::displayStatistika();
}
else {
save('forceShowSpremenljivka', true);
\App\Controllers\Vprasanja\VprasanjaController::getInstance()->displaySpremenljivka($_GET['spremenljivka']);
}
?>
</body>
</html>
<?
}
function ajax_toolbox_add_advanced () {
$b = new Branching($this->anketa);
$b->toolbox_add_advanced($popup=true);
}
function ajax_toggle_toolbox () {
$b = new Branching($this->anketa);
$b->toogle_toolbox_nastavitve();
}
function ajax_if_edit_enabled () {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = $_POST['if'];
$enabled = $_POST['enabled'];
sisplet_query("UPDATE srv_if SET enabled = '$enabled' WHERE id = '$if'");
}
function ajax_vprasanje_full () {
$b = new Branching($this->anketa);
if ($this->spremenljivka > 0) {
$b->vprasanje($this->spremenljivka);
} else {
$b->introduction_conclusion($this->spremenljivka);
}
}
function ajax_find_replace() {
global $lang;
echo '<div class="popup_close"><a href="#" onClick="$(\'#vrednost_edit\').hide().html(\'\'); $(\'#fade\').fadeOut(); return false;">✕</a></div>';
echo '<h2><span class="faicon blue replace"></span>'.$lang['srv_find_replace'].'</h2>';
echo '<p class="bottom16">'.$lang['srv_find_text'].'</p>';
echo '<div class="setting_holder">';
echo '<p>'.$lang['srv_find'].':</p>';
echo '<div class="find-holder">';
echo '<input type="text" class="text large" name="find">';
echo '<span class="red" id="find_count" style="margin-left: 16px;"></span>';
echo '</div>';
echo '</div>';
echo '<div class="setting_holder">';
echo '<p>'.$lang['srv_replace_with'].':</p>';
echo '<input type="text" class="text large" name="replace">';
echo '</div>';
echo '<div class="button_holder">';
echo '<button class="medium white-blue" onClick="$(\'#vrednost_edit\').hide().html(\'\'); $(\'#fade\').fadeOut(); return false;">'.$lang['srv_cancel'].'</button>';
echo '<button class="medium blue" onclick="find_replace_do(); return false;">'.$lang['srv_replace'].'</button>';
echo '</div>';
}
function ajax_find_replace_count() {
global $lang;
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$find = $_POST['find'];
$replace = $find.'foo'; // more bit drugacen od $find da mysql_affected_rows prime
if ($find == '') return;
$count = 0;
sisplet_query("BEGIN");
$s = sisplet_query("UPDATE srv_anketa SET naslov = REPLACE(naslov, '$find', '$replace'),
akronim = REPLACE(akronim, '$find', '$replace'),
introduction = REPLACE(introduction, '$find', '$replace'),
conclusion = REPLACE(conclusion, '$find', '$replace'),
intro_opomba = REPLACE(intro_opomba, '$find', '$replace'),
intro_note = REPLACE(intro_note, '$find', '$replace'),
concl_note = REPLACE(concl_note, '$find', '$replace')
WHERE id = '$this->anketa'
");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$count += mysqli_affected_rows($GLOBALS['connect_db']);
$s = sisplet_query("UPDATE srv_spremenljivka s, srv_grupa g SET
s.naslov = REPLACE(s.naslov, '$find', '$replace'),
s.info = REPLACE(s.info, '$find', '$replace'),
s.naslov_graf = REPLACE(s.naslov_graf, '$find', '$replace')
WHERE s.gru_id=g.id AND g.ank_id='$this->anketa'
");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$count += mysqli_affected_rows($GLOBALS['connect_db']);
$s = sisplet_query("UPDATE srv_vrednost v, srv_spremenljivka s, srv_grupa g SET
v.naslov = REPLACE(v.naslov, '$find', '$replace'),
v.naslov2 = REPLACE(v.naslov2, '$find', '$replace'),
v.naslov_graf = REPLACE(v.naslov_graf, '$find', '$replace')
WHERE v.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='$this->anketa'
");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$count += mysqli_affected_rows($GLOBALS['connect_db']);
$s = sisplet_query("UPDATE srv_grid gr, srv_spremenljivka s, srv_grupa g SET
gr.naslov = REPLACE(gr.naslov, '$find', '$replace'),
gr.naslov_graf = REPLACE(gr.naslov_graf, '$find', '$replace')
WHERE gr.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='$this->anketa'
");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$count += mysqli_affected_rows($GLOBALS['connect_db']);
sisplet_query("ROLLBACK");
echo $lang['srv_find_replace_count'].': '.$count;
}
function ajax_find_replace_do () {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$find = $_POST['find'];
$replace = $_POST['replace'];
if ($find == '' || $replace == '') return;
$s = sisplet_query("UPDATE srv_anketa SET naslov = REPLACE(naslov, '$find', '$replace'),
akronim = REPLACE(akronim, '$find', '$replace'),
introduction = REPLACE(introduction, '$find', '$replace'),
conclusion = REPLACE(conclusion, '$find', '$replace'),
intro_opomba = REPLACE(intro_opomba, '$find', '$replace'),
intro_note = REPLACE(intro_note, '$find', '$replace'),
concl_note = REPLACE(concl_note, '$find', '$replace')
WHERE id = '$this->anketa'
");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("UPDATE srv_spremenljivka s, srv_grupa g SET
s.naslov = REPLACE(s.naslov, '$find', '$replace'),
s.info = REPLACE(s.info, '$find', '$replace'),
s.naslov_graf = REPLACE(s.naslov_graf, '$find', '$replace')
WHERE s.gru_id=g.id AND g.ank_id='$this->anketa'
");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("UPDATE srv_vrednost v, srv_spremenljivka s, srv_grupa g SET
v.naslov = REPLACE(v.naslov, '$find', '$replace'),
v.naslov2 = REPLACE(v.naslov2, '$find', '$replace'),
v.naslov_graf = REPLACE(v.naslov_graf, '$find', '$replace')
WHERE v.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='$this->anketa'
");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("UPDATE srv_grid gr, srv_spremenljivka s, srv_grupa g SET
gr.naslov = REPLACE(gr.naslov, '$find', '$replace'),
gr.naslov_graf = REPLACE(gr.naslov_graf, '$find', '$replace')
WHERE gr.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='$this->anketa'
");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
function ajax_SN_generator_new ($spremenljivka = null, $endif = null) {
global $lang;
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if ($spremenljivka == null) $spremenljivka = $_POST['spremenljivka'];
if ($endif == null) $endif = $_POST['endif'];
$tip = 9;
$b = new Branching($this->anketa);
$this->spremenljivka_new($spremenljivka, 0, $endif, 0, 2);
Vprasanje::change_tip($this->spremenljivka, $tip);
$gen_id = $this->spremenljivka;
// USTVARIMO PAGEBREAK
sisplet_query("UPDATE srv_branching SET pagebreak = '1' WHERE element_spr = '$this->spremenljivka' AND ank_id='".$this->anketa."'");
// USTVARIMO NAGOVOR
$this->spremenljivka_new($gen_id, 0, 0, 0, 0);
Vprasanje::change_tip($this->spremenljivka, 5);
// nastavimo text nagovora
$row = Cache::srv_spremenljivka($gen_id);
$naslov = $lang['srv_SN_nagovor_title'].'#'.$row['variable'].'#';
$purifier = New Purifier();
$naslov = $purifier->purify_DB($naslov);
sisplet_query("UPDATE srv_spremenljivka SET naslov = '$naslov' WHERE id = '$this->spremenljivka'");
// USTVARIMO LOOP NA NAGOVORU
$sqln = sisplet_query("SELECT MAX(i.number) AS number FROM srv_if i, srv_branching b WHERE b.ank_id='$this->anketa' AND b.element_if=i.id");
if (!$sqln) echo mysqli_error($GLOBALS['connect_db']);
$rown = mysqli_fetch_array($sqln);
$number = $rown['number'] + 1;
$sql = sisplet_query("INSERT INTO srv_if (id, number, tip) VALUES ('', '$number', '2')");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
$if_id = mysqli_insert_id($GLOBALS['connect_db']);
if ($this->spremenljivka > 0 || ($if > 0 && $endif == 1)) {
$sql = sisplet_query("SELECT * FROM srv_branching WHERE element_spr = '$this->spremenljivka' AND element_if='$if'");
$row = mysqli_fetch_array($sql);
}
if ($if > 0 && $endif != 1) {
$row['parent'] = $if;
$row['vrstni_red'] = 0;
}
// dodajanje ifa na trenutno spremenljivko
if ($this->spremenljivka > 0) {
$next_element = $row;
$include_element = true; // v if vkljucimo tudi trenutno spremenljivko
// dodajanje ifa na naslednji element
} else {
$next_element = $b->find_next_element($row['parent'], $row['vrstni_red']);
}
if ($next_element == null) { // next_element je prazen na koncu ifa, takrat je tudi nov if prazen
$next_element['parent'] = $row['parent'];
$next_element['vrstni_red'] = $row['vrstni_red'] + 1;
$next_element['element_spr'] = 0;
$next_element['element_if'] = 0;
}
$add = true;
// preverimo, da ga ne dodamo v ze obstojec loop
if ($b->find_loop_parent($next_element['parent']) > 0)
$add = false;
// preverimo, da ge ne dodamo direktno pred obstojec loop (ker potem objame obstojec loop in dobimo vgnezdenje)
if ($next_element['element_if'] > 0)
if ($b->find_loop_child($next_element['element_if']) > 0)
$add = false;
if ($add) {
$b->if_new($endif, $next_element['parent'], $if_id, $next_element['vrstni_red'], $next_element['element_spr'], $next_element['element_if'], $copy, $no_content, $include_element);
sisplet_query("UPDATE srv_anketa SET branching='1' WHERE id = '$this->anketa'");
} else {
$b->dropped_alert($lang['srv_loop_no_nesting']);
}
// NASTAVIMO LOOP NA GENERATOR
if (is_numeric($gen_id )) {
$vrednost = 0;
}
sisplet_query("REPLACE INTO srv_loop (if_id, spr_id) VALUES ('$if_id', '$gen_id ')");
// na zacetku damo po defaultu na 'izbran'
$s = sisplet_query("DELETE FROM srv_loop_vre WHERE if_id = '$if_id'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("DELETE FROM srv_loop_data WHERE if_id = '$if_id'");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$sql2 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='$gen_id ' ORDER BY vrstni_red ASC");
while ($row2 = mysqli_fetch_array($sql2)) {
$vrednost = $row2['id'];
if ($vrednost > 0) {
$s = sisplet_query("INSERT INTO srv_loop_vre (if_id, vre_id) VALUES ('$if_id', '$vrednost')");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
$s = sisplet_query("INSERT INTO srv_loop_data (id, if_id, vre_id) VALUES ('', '$if_id', '$vrednost')");
if (!$s) echo mysqli_error($GLOBALS['connect_db']);
}
}
$b->repare_vrstni_red();
Common::getInstance()->prestevilci();
Cache::clear_cache();
$data = array();
$data['nova_spremenljivka_id'] = $gen_id;
ob_start();
$b = new Branching($this->anketa);
$b->spremenljivka = $gen_id;
$b->branching_struktura();
$data['branching_struktura'] = ob_get_clean();
$this->check_loop();
ob_start();
$v = new Vprasanje($this->anketa);
$v->spremenljivka = $gen_id;
$v->ajax_vprasanje_fullscreen();
$data['vprasanje_fullscreen'] = ob_get_clean();
echo json_encode($data);
}
/**
* dodajanje demografije preko obrazca na prvi strani nove ankete
*
*/
function ajax_demografija_new () {
global $lang;
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if ( count($_POST['variable']) > 0 ) {
$type = $_POST['type'];
$b = new Branching($this->anketa);
ob_start();
$if_id = 0;
// ce ze obstaja blok demografija
$if_id = $b->get_demografija_id();
// dodajanje nove spremenljivke
if ($type == 'add') {
// blok obstaja, novo bomo dodali na dno
if ($if_id > 0) {
$sql = sisplet_query("SELECT element_spr FROM srv_branching WHERE parent='$if_id' AND ank_id='$this->anketa' ORDER BY vrstni_red DESC LIMIT 1");
$row = mysqli_fetch_array($sql);
$spr = $row['element_spr'];
$if = 0;
}
// sicer naredimo nov blok
if ($if_id == 0) {
$if_id = $this->ajax_if_new(0, 0, 1, 1);
sisplet_query("UPDATE srv_if SET label = '$lang[srv_demografija]' WHERE id = '$if_id'");
// novo spremenljivko bomo dodali v blok
$spr = 0;
$if = $if_id;
}
// id spremenljivke v knjiznici, ki jo bomo dodali
$d_id = Demografija::getInstance()->getSpremenljivkaID($_POST['variable']);
$this->ajax_spremenljivka_new($spr, $if, 0, 0, 23, $d_id);
// brisanje demografske spremenljivke
} elseif ($type == 'remove') {
// poiscemo ID spremenljivke v bloku demografija glede na variablo
$sql = sisplet_query("SELECT s.id FROM srv_branching b, srv_spremenljivka s WHERE b.element_spr=s.id AND b.parent='$if_id' AND s.variable='$_POST[variable]' LIMIT 1");
$row = mysqli_fetch_array($sql);
if ($row['id'] > 0) {
$sa = new SurveyAdmin(1, $this->anketa);
$sa->brisi_spremenljivko($row['id']);
}
// preverimo ce je blok demografija prazen in ga odstranimo
$sql = sisplet_query("SELECT COUNT(*) AS count FROM srv_branching WHERE parent='$if_id'");
$row = mysqli_fetch_array($sql);
if ($row['count'] == 0)
$this->ajax_if_remove($if_id);
}
ob_clean();
Cache::clear_cache_all();
$b->branching_struktura();
$output['branching'] = ob_get_clean();
$output['spremenljivka'] = $this->spremenljivka;
echo json_encode($output);
}
}
function ajax_if_blok_tab() {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = $_POST['if'];
$tab = $_POST['tab'];
if ($if > 0) {
sisplet_query("UPDATE srv_if SET tab='$tab' WHERE id='$if'");
if ($tab == 1) {
$b = new Branching($this->anketa);
$spr = $b->find_last_in_if($if);
if ($spr > 0)
$this->ajax_pagebreak($spr, 1);
$spr = $b->find_before_if($if);
if ($spr > 0)
$this->ajax_pagebreak($spr, 1);
}
}
}
function ajax_if_blok_random() {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = $_POST['if'];
$random = $_POST['random'];
if ($if > 0)
sisplet_query("UPDATE srv_if SET random='$random' WHERE id='$if'");
}
function ajax_if_blok_horizontal() {
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$if = $_POST['if'];
$horizontal = $_POST['horizontal'];
if ($if > 0)
sisplet_query("UPDATE srv_if SET horizontal='$horizontal' WHERE id='$if'");
}
/*
* spremenimo odgovor VISIBLE/DISABLE/HIDDEN
*
* @odg = 0 -> imajo vsi odgovori - visible
* @odg = 1 -> hidden
* @odg = 2 -> disable (viden, vendar ni mogoča izbira)
* @return $odg
*
*/
function ajax_hidden_answer(){
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
$odg = $_POST['odgovor'];
$id = $_POST['id'];
switch ($odg){
case 2:
$odg = 0;
break;
default:
$odg++;
}
sisplet_query("UPDATE srv_vrednost SET hidden='$odg' WHERE id='$id'");
echo $odg;
}
/*
* spremenimo odgovor CORRECT za modul KVIZ
*
*
*/
function ajax_correct_answer(){
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if(isset($_POST['vre_id']) && isset($_POST['spr_id']) && isset($_POST['action'])){
$spr_id = $_POST['spr_id'];
$vre_id = $_POST['vre_id'];
$action = $_POST['action'];
if($action == 'add'){
$sql = sisplet_query("INSERT INTO srv_quiz_vrednost (spr_id, vre_id) VALUES ('".$spr_id."', '".$vre_id."')");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
}
else{
sisplet_query("DELETE FROM srv_quiz_vrednost WHERE spr_id='".$spr_id."' AND vre_id='".$vre_id."'");
if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
}
}
}
/**
* Lokacija - 26
* shrane v bazo koordinate za fokus, da se ne vedno porabljajo kvote geocodinga
*/
function ajax_fokus_koordiante_map(){
if(isset($_POST['anketa']))
$this->anketa = $_POST['anketa'];
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if(isset($_POST['spr_id'])){
$spr_id = $_POST['spr_id'];
$koordinate = $_POST['koordinate'];
$row = Cache::srv_spremenljivka($spr_id);
$newParams = new enkaParameters($row['params']);
$newParams->set('fokus_koordinate', json_encode($koordinate));
$params = $newParams->getString();
sisplet_query("UPDATE srv_spremenljivka SET params='$params' WHERE id='$spr_id'");
}
}
/**
* Lokacija - 26
* shrane v bazo string za fokus
*/
function ajax_fokus_string_map(){
if(isset($_POST['anketa']))
$this->anketa = $_POST['anketa'];
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if(isset($_POST['spr_id'])){
$spr_id = $_POST['spr_id'];
$string = $_POST['fokus'];
$row = Cache::srv_spremenljivka($spr_id);
$newParams = new enkaParameters($row['params']);
$newParams->set('fokus_mape', json_encode($string));
$params = $newParams->getString();
sisplet_query("UPDATE srv_spremenljivka SET params='$params' WHERE id='$spr_id'");
}
}
/**
* Lokacija - 26 - podtip 3 choose location
* shrane v nov marker - vrednost
*/
function ajax_save_marker(){
if(isset($_POST['anketa']))
$this->anketa = $_POST['anketa'];
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if(isset($_POST['spr_id'])){
$spr_id = $_POST['spr_id'];
$add = $_POST['address'];
$lat = $_POST['lat'];
$lng = $_POST['lng'];
$v = new Vprasanje();
$v->spremenljivka = $spr_id;
$vrednost = $v->vrednost_new('');
Common::prestevilci($spr_id);
//last decimals of coordiates are not exact same in database, because float in mySql is not precise - practical variations are minimal
$sql = sisplet_query("INSERT INTO srv_vrednost_map (spr_id, vre_id, address, lat, lng, overlay_type) "
. "VALUES ('$spr_id', '$vrednost', '$add', '$lat', '$lng', 'marker')", "id");
echo $vrednost;
}
}
/**
* Lokacija - 26 - podtip 3 choose location
* shrane v nov shape - ni vrednost, samo info
*/
function ajax_save_polyline(){
if(isset($_POST['anketa']))
$this->anketa = $_POST['anketa'];
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if(isset($_POST['spr_id'])){
$spr_id = $_POST['spr_id'];
$overlay_id = $_POST['overlay_id'];
$path = $_POST['path'];
//create row for each point of path of line
foreach ($path as $point) {
$sql = sisplet_query("INSERT INTO srv_vrednost_map (spr_id, vre_id, lat, lng, vrstni_red, overlay_id, overlay_type) "
. "VALUES ('$spr_id', '-1', '".$point['lat']."', '".$point['lng']."', '".$point['vrstni_red']."', '$overlay_id', 'polyline')");
}
}
}
/**
* Lokacija - 26 - podtip 3 choose location
* izvede query za brisanje shape iz baze - tabela srv_vrednost_map
* @param type $spr_id
* @param type $overlay_id
*/
function deleteShapeQuery($spr_id, $overlay_id){
//first dele old line
$sql = sisplet_query("DELETE FROM srv_vrednost_map WHERE spr_id='$spr_id' AND overlay_id='$overlay_id'");
}
/**
* Lokacija - 26 - podtip 3 choose location
* shrane spremenjen shape - ni vrednost, samo info
*/
function ajax_edit_polyline(){
if(isset($_POST['anketa']))
$this->anketa = $_POST['anketa'];
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if(isset($_POST['spr_id'])){
$spr_id = $_POST['spr_id'];
$overlay_id = $_POST['overlay_id'];
$path = $_POST['path'];
//first dele old line
$this -> deleteShapeQuery($spr_id, $overlay_id);
//create new line
foreach ($path as $point) {
$sql = sisplet_query("INSERT INTO srv_vrednost_map (spr_id, vre_id, lat, lng, vrstni_red, overlay_id, overlay_type) "
. "VALUES ('$spr_id', '-1', '".$point['lat']."', '".$point['lng']."', '".$point['vrstni_red']."', '$overlay_id', 'polyline')");
}
}
}
/**
* Lokacija - 26 - podtip 3 choose location
* izbrise shape - ni vrednost, samo info
*/
function ajax_delete_polyline(){
if(isset($_POST['anketa']))
$this->anketa = $_POST['anketa'];
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if(isset($_POST['spr_id'])){
$spr_id = $_POST['spr_id'];
$overlay_id = $_POST['overlay_id'];
$this -> deleteShapeQuery($spr_id, $overlay_id);
}
}
/**
* Lokacija - 26 - podtip 3 choose location
* shrane naslov shapea - ni vrednost, samo info
*/
function ajax_edit_naslov_polyline(){
if(isset($_POST['anketa']))
$this->anketa = $_POST['anketa'];
Common::getInstance()->Init($this->anketa);
Common::getInstance()->updateEditStamp();
if(isset($_POST['spr_id'])){
$spr_id = $_POST['spr_id'];
$overlay_id = $_POST['overlay_id'];
$address = $_POST['address'];
$sql = sisplet_query("UPDATE srv_vrednost_map SET address='$address' WHERE spr_id='$spr_id' AND overlay_id='$overlay_id'");
}
}
}
?>
|