summaryrefslogblamecommitdiffstats
path: root/admin/survey/classes/class.Common.php
blob: 66946f061737dead25080de903ee3184c3d24f3e (plain) (tree)
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
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
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




















                                                                                                             
                                      





















                                                        
 

                                                                                                 

































































































































































































                                                                                                                                                                                                                                                                                                      

                                                                           











                                                                                   
             























































                                                                                                                                  



                                    












































































































































































































































































































































































































                                                                                                                                                                                                                             
 

                                                                                                          

                                                                
                                                                                                  

                                                   
 




















































































                                                                                                                                    

                                                                                     
                                                         





                                                                            



                                                                                                    

                       




















                                                                                                             
                                                                      























































































































































































































































































                                                                                                                                                                                                                                                                                  
                                                                                                                               






































                                                                                                                                              
                                                                                                                                                                                               


















































                                                                                                                                                                                                                   
                                                                                                                              



































































































































































































































































































































































































                                                                                                                                                                   
                                                                                                                     




















































































































































































































































































































































































































































































                                                                                                                                                                                



                                                                
 
                         
 

                                                                
 






                                                                                             
















































                                                                                                   
                                                
                      

                                  

                                            












































                                                                                                                                                                                               


                       

































































                                                                                                                                                                                                                                                                                                                                                          


                                                                                 
 

                                                                                                                           










                                                               
                                                                                                                                                       
                 
                                                                                                                                                       















                                                                                                                                                                                                                                                                                                                                                                                                                
<?php

/**
 * pogoste funkcije iz SurveyAdmin
 * da se klice raje tale mali file, namesto tisti gromozanski
 */
class Common {

	static private $instance;

	static private $anketa;

	static private $db_table = '';

	static private $time_start = null;	// pri stetju casa izvajanja, sem shranimo zacetek izvajanja

	static private $updateEditStamp = false;	// ali ob koncu posodobimo time stamp ankete

	// konstrutor
	protected function __construct() {}
	// kloniranje
	private function __clone() {}

	/**
	 * Poskrbimo za samo eno instanco
	 */
	static function getInstance()
	{
		if(!self::$instance)
		{
			self::$instance = new Common();
		}
		return self::$instance;
	}

	/**
	 * Inicializacija
	 *
	 * @param int $anketa
	 */
	static function Init( $anketa = null )
	{
		if ($anketa) {
			self::$anketa = $anketa;

			SurveyInfo::getInstance()->SurveyInit(self::$anketa);
			self::$db_table = SurveyInfo::getInstance()->getSurveyArchiveDBString();
		}
	}

	/**
	 * @desc prestevilci variable vseh vprasanj v anketi
	 */
	static function prestevilci ($spremenljivka = 0, $all = false, $force = false) {

		// Preverimo ce imamo izklopljeno atomatsko prestevilcevanje
        SurveySetting::getInstance()->Init(self::$anketa);
        
		$enumerate = SurveySetting::getInstance()->getSurveyMiscSetting('enumerate'); if ($enumerate == '') $enumerate = 1;
		if($enumerate == 0 && $all != true)
			return;

		// prestevilcimo spremenljivke (vse v anketi)
		if ($spremenljivka == 0) {
			self::prestevilci_if();

			$i = 1;

			$sql = sisplet_query("SELECT s.id, variable, variable_custom, s.tip AS tip FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id=g.id AND g.ank_id='".self::$anketa."' AND s.tip!='9' ORDER BY g.vrstni_red, s.vrstni_red");

			// ce je vec kot 50 spremenljivk nimamo avtomatskega prestevilcevanja
			if ( ( mysqli_num_rows($sql) <= 50 or $all == true ) && mysqli_num_rows($sql)>0 ) {

				$values = "";
				$val_array = array();

				$variable_array = array();

				$j=1;
				while ($row = mysqli_fetch_array($sql)) {
					$variable_array[$row['id']]['id'] = $row['id'];
					$variable_array[$row['id']]['variable'] = $row['variable'];
					$variable_array[$row['id']]['variable_custom'] = $row['variable_custom'];
					$variable_array[$row['id']]['vrstni_red'] = $j;

					// Dodaten loop po spremenljivkah, ki so znotraj kombinirane tabele (gru_id == -2)
					if($row['tip'] == 24){

						$sqlM2 = sisplet_query("SELECT s.id, s.variable, s.variable_custom FROM srv_spremenljivka s, srv_grid_multiple m 
												WHERE m.parent='".$row['id']."' AND m.ank_id='".self::$anketa."' AND s.id=m.spr_id
												ORDER BY m.vrstni_red");
						while ($rowM2 = mysqli_fetch_array($sqlM2)) {

							$j++;

							$variable_array[$rowM2['id']]['id'] = $rowM2['id'];
							$variable_array[$rowM2['id']]['variable'] = $rowM2['variable'];
							$variable_array[$rowM2['id']]['variable_custom'] = $rowM2['variable_custom'];
							$variable_array[$rowM2['id']]['vrstni_red'] = $j;
						}
					}

					$j++;
				}

				$variable_array2 = $variable_array;

				// Loop cez vsa vprasanja v anketi po vrstnem redu
				foreach($variable_array2 as $row) {

					// Ce vprasanje nima custom variable jo lahko prestevilcimo
					if ($row['variable_custom'] == 0) {

						do {
							// Nastavimo variablo na stevilko ki pripada njenemu vrstnemu redu
							$variable = 'Q' . $i;
							$variable_ok = true;
							$i++;

							// Loop cez vsa ostala vprasanja, kjer preverimo ce obstaja se kaksna z istim imenom (ki je custom ali pa ima manjsi vrstni red)
							foreach ($variable_array AS $spr => $var) {
								if ($spr != $row['id'] && $var['variable'] == $variable && ($var['variable_custom'] == 1 || $i > $var['vrstni_red'])) {
									$variable_ok = false;
								}
							}
						} while ( ! $variable_ok );

						// Nasli smo ustrezno poimenovanje in ga updatamo
						if ($row['variable'] != $variable) {
							$variable_array[$row['id']]['variable'] = $variable;
							sisplet_query("UPDATE srv_spremenljivka SET variable = '$variable' WHERE id = '$row[id]'");
							if ($values != "") $values .= ", ";
							$values .= "('$row[id]', '$variable')";
						}
					}

					// po vrsti shranjujemo vprasanja v array, ker moramo na koncu se prestevilciti njihove notranje variable
					array_push($val_array, $row['id']);
				}

				// prestevilcimo se variable znotraj posameznih vprasanja - prestevilci moramo poklicati sele za zgornjim INSERTom!
				foreach ($val_array AS $key => $val) {
					self::prestevilci($val);
				}
			}
		}
		// prestevilcimo variable v spremenljivki
		else {

			// Nastavitev da ostevilcujemo v obratnem vrstnem redu (samo radio tip)
			$rowSpr = Cache::srv_spremenljivka($spremenljivka);	
			$spremenljivkaParams = new enkaParameters($rowSpr['params']);
			$reverse_var = ($spremenljivkaParams->get('reverse_var') ? $spremenljivkaParams->get('reverse_var') : 0);

			//sisplet_query("BEGIN");
			$j = 1;
			// Ce je katerakoli variabla custom, potem ne prestevilcimo vec
			$sql = sisplet_query("SELECT v.id AS id, s.tip AS tip, s.variable AS variable, v.other as other, v.variable AS variable_vre
			                    FROM srv_vrednost v, srv_spremenljivka s
			                    WHERE
			                    v.spr_id = s.id AND
			                    v.spr_id = '$spremenljivka' AND
			                    v.variable_custom = '0' AND
			                    v.vrstni_red > '0' AND
								NOT EXISTS (SELECT v2.* from srv_vrednost v2 WHERE v2.spr_id=v.spr_id AND v2.vrstni_red>'0' AND v2.variable_custom='1')
			                    ORDER BY v.vrstni_red ".($reverse_var == 1 ? ' DESC' : ' ASC')."
			                    ");

			$values = "";
			$tip = 0;
			while ($row = mysqli_fetch_array($sql)) {
				if ($row['other'] == 0 || $row['other'] == 1) { # missing value ne preštevilčimo 
					//do {
					// Popravimo imena spremenljivk pri tabelah (zdruzimo ime variable + abeceda)
					//if ($row['tip'] == 2 || $row['tip'] == 6 || $row['tip'] == 7 || $row['tip'] == 16 || $row['tip'] == 17 || $row['tip'] == 18  || $row['tip'] == 19 || $row['tip'] == 20 || $row['tip'] == 21 || $row['tip'] == 24) {
					if ($row['tip'] == 2 || $row['tip'] == 6 || $row['tip'] == 7 || $row['tip'] == 16 || $row['tip'] == 17 || $row['tip'] == 18  || $row['tip'] == 19 || $row['tip'] == 20 || $row['tip'] == 21 || $row['tip'] == 24 || $row['tip'] == 26 || $row['tip'] == 27) {
						if (mysqli_num_rows($sql) <= 26) {
							$variable_vre = $row['variable'] . chr($j +96);
						} else {
							$jjj = bcdiv($j-1, 26) + 1;
							$jj = bcmod($j-1, 26) + 1; if ($jj == 0) { $jj=26; $jjj--; };
							$variable_vre = $row['variable'] . chr($jjj +96) . chr($jj +96);
						}
					} else {
						$variable_vre = $j;
					}
					//$sqlCheckVariable = sisplet_query("SELECT id FROM srv_vrednost WHERE variable='$variable_vre' AND spr_id = '$spremenljivka' AND id <> '$row[id]'");
					$j++;
					//} while (mysqli_num_rows($sqlCheckVariable) > 0);

					if ($row['variable_vre'] != $variable_vre) {
						sisplet_query("UPDATE srv_vrednost SET variable='$variable_vre' WHERE id = '$row[id]'");
						if ($values != "") $values .= ", ";
						$values .= "('$row[id]', '$variable_vre')";
					}
				}
			}

			//sisplet_query("COMMIT");
		}
	}

	/**
	 * @desc prestevilci ife
	 */
	static $prestevilci_if = '';
	static function prestevilci_if($parent = 0, & $number = 1) {

		if ($parent == 0)
			self::$prestevilci_if = '';

		$sql = sisplet_query("SELECT element_if FROM srv_branching WHERE ank_id='".self::$anketa."' AND parent='$parent' AND element_if>'0' ORDER BY vrstni_red");
		while ($row = mysqli_fetch_array($sql)) {

			if (self::$prestevilci_if != "") self::$prestevilci_if .= ", ";
			self::$prestevilci_if .= "('$row[element_if]', '$number')";

			$number++;
			self::prestevilci_if($row['element_if'], $number);
		}

		if ($parent == 0 && self::$prestevilci_if != "") {
			$s = sisplet_query("INSERT INTO srv_if (id, number) VALUES ".self::$prestevilci_if." ON DUPLICATE KEY UPDATE number = VALUES (number)");
			if (!$s) echo 'e345'.mysqli_error($GLOBALS['connect_db']);
		}
	}


	/**
	 * pobrise podatke, ki se izpolnijo v preview modu ankete
	 *
	 * @param boolean vedno brišemo samo iz trenutne ankete zaradi brisanja iz podatkovne datoteke
	 */
	static function deletePreviewData ($sid = null) {

		if ($sid == null || (int)$sid == 0)
			return;
		else
			$sql = sisplet_query("SELECT id FROM srv_user WHERE preview='1' AND time_edit < NOW() - INTERVAL 3 HOUR AND ank_id = '".$sid."'");

		# polovimo vrsto tabel za to anketo
        SurveyInfo::getInstance()->SurveyInit($sid);
        $db_table = SurveyInfo::getInstance()->getSurveyArchiveDBString();

		$list = '';
		// se je dogajalo da je 0 ... pa se je pojavljal mysql_fetch error
		if (mysqli_num_rows($sql) > 0) {
			$prefix = '';
			while ($row = mysqli_fetch_array($sql)) {
				$list = $list.$prefix.$row['id'];
				$prefix = ', ';
			}
		}
		if ($list != '') {
			sisplet_query("BEGIN");
            
			// tabela z respondenti
			$deleted = sisplet_query("DELETE FROM srv_user WHERE preview='1' AND id IN ($list) AND ank_id = '$sid'");

			// tabele s podatki
			sisplet_query("DELETE FROM srv_data_checkgrid".$db_table." WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_data_glasovanje WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_data_grid".$db_table." WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_data_imena WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_data_number WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_data_rating WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_data_text".$db_table." WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_data_textgrid".$db_table." WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_data_vrednost".$db_table." WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_userstatus WHERE usr_id IN ($list)");
			sisplet_query("DELETE FROM srv_user_grupa".$db_table." WHERE usr_id IN ($list)");

			sisplet_query("COMMIT");
		}
	}

	/**
	 * ob zacetku izvajanja shranimo cas izvajanja
	 *
	 */
	static function start () {
		self::$time_start = microtime(true);
	}

	/**
	 * ob koncu izvajanja izracunamo cas izvajanja in pozenemo updateEditStampSave(), ce je treba
	 *
	 */
	static function stop () {

		// racunanje casa izvedemo v updateTracking(), ki se poklice iz updateEditStampSave()	
		if ( self::$updateEditStamp == 1 ) {

			self::updateEditStampSave();
		}
	}

	/**
	 * oznacimo, da na koncu izvajanja popravimo timestamp ankete
	 *
	 */
	static function updateEditStamp () {
		self::$updateEditStamp = true;
	}

	/**
	 * @desc popravimo cas in userja popravka
	 */
	static function updateEditStampSave() {
		global $admin_type;
		global $global_user_id;

		$anketa = 0;
		$grupa = 0;
		$spremenljivka = 0;

		if (isset ($_REQUEST['spremenljivka']))
			$spremenljivka = $_REQUEST['spremenljivka'];
		if (isset ($_REQUEST['anketa']))
			$anketa = $_REQUEST['anketa'];
		if (isset ($_REQUEST['grupa']))
			$grupa = $_REQUEST['grupa'];

		if (!$anketa > 0) {
			if ($grupa > 0) {
				$sql = sisplet_query("SELECT ank_id FROM srv_grupa WHERE id='$grupa'");
				$row = mysqli_fetch_array($sql);
				$anketa = $row['ank_id'];
			}
			elseif ($spremenljivka > 0) {
				$sql = sisplet_query("SELECT gru_id FROM srv_spremenljivka WHERE id='$spremenljivka'");
				$row = mysqli_fetch_array($sql);
				$grupa = $row['gru_id'];
				$sql = sisplet_query("SELECT ank_id FROM srv_grupa WHERE id='$grupa'");
				$row = mysqli_fetch_array($sql);
				$anketa = $row['ank_id'];
			}
			//Uros dodal, za API
			elseif(isset(self::$anketa) && self::$anketa > 0)
				$anketa = self::$anketa;
		}

		if ($anketa > 0) {
			$update = true;
			if ($admin_type == 0) {
				$sql = sisplet_query("SELECT * FROM srv_dostop WHERE ank_id='$anketa' AND uid='$global_user_id'");
				if (mysqli_num_rows($sql) == 0)
					$update = false;
			}

			if ($update) {
				$sql = sisplet_query("UPDATE srv_anketa SET edit_uid = '$global_user_id', edit_time=NOW() WHERE id='$anketa'");

				# popravimo še polje za osvežitev podatkov seznama anket uporablja class: class.SurveyList.php
				$updateString = "INSERT INTO srv_survey_list (id, updated) "
					." VALUES ('$anketa', '1') ON DUPLICATE KEY UPDATE updated='1'";
				$s = sisplet_query($updateString);
				if (!$s) echo mysqli_error($GLOBALS['connect_db']);

				// vsilimo refresh podatkov
				SurveyInfo :: getInstance()->resetSurveyData();
			}

			# vsilimo refresh header datoteke in datoteke s podatki
			$update_header = "UPDATE srv_data_files SET head_file_time='0000-00-00', data_file_time='0000-00-00' WHERE sid='$anketa'";
			sisplet_query($update_header);
			sisplet_query("COMMIT");
		}
	}


	/**
	 * @desc Vrne ID trenutnega uporabnika (ce ni prijavljen vrne 0)
	 */
	static function uid() {
		global $global_user_id;

		return $global_user_id;
	}

	/**
	 * @desc popravi celotno anketo
	 */
	static function repareAnketa($anketa = 0) {
		if ($anketa == 0)
			$anketa = self::$anketa;

		if($anketa > 0){
			self::repareGrupa($anketa);

			$sql = sisplet_query("SELECT id FROM srv_grupa WHERE ank_id='".$anketa."'");
			while ($row = mysqli_fetch_array($sql)) {
				self::repareSpremenljivka($row['id']);

				$sql1 = sisplet_query("SELECT id FROM srv_spremenljivka WHERE gru_id='$row[id]'");
				while ($row1 = mysqli_fetch_array($sql1)) {
					self::repareVrednost($row1['id']);
				}
			}
		}
	}

	/**
	 * @desc popravi vrstni red v tabeli srv_grupa
	 */
	static function repareGrupa($anketa) {

		if($anketa > 0){
			sisplet_query("BEGIN");

			$sql = sisplet_query("SELECT id, vrstni_red FROM srv_grupa WHERE ank_id='$anketa' ORDER BY vrstni_red");
			$i = 1;

			$values = "";

			while ($row = mysqli_fetch_array($sql)) {
				if ($row['vrstni_red'] != $i) {
					$sql1 = sisplet_query("UPDATE srv_grupa SET vrstni_red='$i' WHERE id = '$row[id]'");
					if ($values != "") $values .= ", ";
					$values .= "('$row[id]', '$i')";
				}
				$i++;
			}

			//if ($values != "") sisplet_query("INSERT INTO srv_grupa (id, vrstni_red) VALUES $values ON DUPLICATE KEY UPDATE vrstni_red=VALUES(vrstni_red)");
			sisplet_query("COMMIT");
		}
	}

	/**
	 * @desc popravi vrstni red v tabeli srv_spremenljivka
	 */
	static function repareSpremenljivka($grupa) {

		if($grupa > 0){
			sisplet_query("BEGIN");
			$sql = sisplet_query("SELECT id, vrstni_red FROM srv_spremenljivka WHERE gru_id='$grupa' ORDER BY vrstni_red");
			$i = 1;

			$values = "";

			while ($row = mysqli_fetch_array($sql)) {
				if ($row['vrstni_red'] != $i) {
					$sql1 = sisplet_query("UPDATE srv_spremenljivka SET vrstni_red='$i' WHERE id = '$row[id]'");
					if ($values != "") $values .= ", ";
					$values .= "('$row[id]', '$i')";
				}
				$i++;
			}

			//if ($values != "") sisplet_query("INSERT INTO srv_spremenljivka (id, vrstni_red) VALUES $values ON DUPLICATE KEY UPDATE vrstni_red=VALUES(vrstni_red)");
			sisplet_query("COMMIT");
		}
	}

	/**
	 * @desc popravi vrstni red v tabeli srv_vrednost
	 */
	static function repareVrednost($spremenljivka) {

		if($spremenljivka > 0){
			sisplet_query("BEGIN");

			$sql = sisplet_query("SELECT id, vrstni_red FROM srv_vrednost WHERE spr_id='$spremenljivka' AND vrstni_red>0 AND other <= 1 ORDER BY vrstni_red ASC");
			$i = 1;
			while ($row = mysqli_fetch_array($sql)) {
				if ($row['vrstni_red'] != $i) {
					$sql1 = sisplet_query("UPDATE srv_vrednost SET vrstni_red='$i' WHERE id = '$row[id]'");
				}
				$i++;
			}

			//tole je za opcijo drugo (kjer gre vrstni_red v minus)
			$sql = sisplet_query("SELECT id, vrstni_red FROM srv_vrednost WHERE spr_id='$spremenljivka' AND vrstni_red<0 AND other <= 1 ORDER BY vrstni_red DESC");
			$i = -1;
			while ($row = mysqli_fetch_array($sql)) {
				if ($row['vrstni_red'] != $i)
					$sql1 = sisplet_query("UPDATE srv_vrednost SET vrstni_red='$i' WHERE id = '$row[id]'");
				$i--;
			}

			sisplet_query("COMMIT");
		}
	}

	/**
	 * shrani trenutno stanje ankete in obvesti administratorja, da nekaj ni ok z anketo
	 *
	 * Vcasih se je sesuval srv_branching zaradi nekih bugov, ki so popravljeni. Zdaj se to zgodi samo v primerih, ce se kopira staro pokvarjeno anketo.
	 * Ce se pokvari srv_branching je ponavadi dovolj, da se v anketi premakne kaksno vprasanje (lahko na isto mesto), da se spet izvede funkcija, ki pocisti bazo
	 *
	 * TOLE UGASNEMO KER VČASIH KAR LETIJO MAILI:)
	 */
	static function checkStruktura () {
		global $site_path;
		global $site_url;

		return;

		if ( ! self::$anketa > 0 ) self::$anketa = (int)$_REQUEST['anketa'];
		if ( ! self::$anketa > 0 ) return;

		$check = null;
		if ( self::$anketa < 8730 ) {
			return;
			$check = self::checkBranchingOld();
		} else {
			$check = self::checkBranching();
		}

		if ( ! $check ) {

			$user = self::uid();

			$get = '';
			foreach ($_GET AS $key => $val) {
				if ($get != '')
					$get .= ', ';
				$get .= $key . ': "' . $val . '"';
			}

			$post = '';
			foreach ($_POST AS $key => $val) {
				if ($post != '')
					$post .= ', ';
				$post .= $key . ': "' . $val . '"';
			}

			$branching = 'ank_id'. " \t - \t ".'parent'." \t - \t ".'vrstni_red'." \t - \t ".'element_spr'." \t - \t ".'element_if'." \t - \t ".'pagebreak'.'<br>';
			$sql = sisplet_query("SELECT * FROM srv_branching WHERE ank_id = '".self::$anketa."' ORDER BY parent, vrstni_red");
			while ($row = mysqli_fetch_array($sql)) {
				$branching .= $row['ank_id']. " \t - \t ".$row['parent']." \t - \t ".$row['vrstni_red']." \t - \t ".$row['element_spr']." \t - \t ".$row['element_if']." \t - \t ".$row['pagebreak'].'<br>';
			}

			$content = 	" ce se pokvari srv_branching je ponavadi dovolj, da se v anketi premakne kaksno vprasanje (lahko na isto mesto), da se spet izvede funkcija, ki pocisti bazo<br><br>".
				" anketa id:<br> 	" . self::$anketa . "<br><br>".
				" <a href=\"".$site_url."admin/survey/index.php?anketa=".self::$anketa."\">".$site_url."admin/survey/index.php?anketa=".self::$anketa."</a><br><br>".
				" site:<br> 		" . $site_path ."<br><br>".
				" get:<br> 			" . $get ."<br><br>".
				" post:<br> 		" . $post ."<br><br>".
				" srv_branching:<br><pre>" . $branching ."</pre><br><br>".
				" user:<br> 		" . $user ."<br><br>"
			;

			try
			{
				$MA = new MailAdapter(self::$anketa, $type='admin');
				//$MA->addRecipients('mitja@sisplet.org');
				$MA->addRecipients('peter.hrvatin@siol.net');
				$resultX = $MA->sendMail($content, 'Sesut srv_branching '.self::$anketa);
			}
			catch (Exception $e)
			{
			}
		}

	}

	/**
	 * rekurzivno preverja, ce je z srv_branchingom vse ok
	 * v nulo, vrstni_red mora bit 1, 2, 3, ...
	 *
	 * @param mixed $parent
	 */
	static function checkBranching ($parent = 0) {

		if ( ! self::$anketa > 0 ) return false;

		$sql = sisplet_query("SELECT parent, vrstni_red, element_if FROM srv_branching WHERE ank_id = '".self::$anketa."' AND parent='$parent' ORDER BY parent, vrstni_red");
		$parent = null;
		$vrstni_red = null;
		while ($row = mysqli_fetch_array($sql)) {

			if ($parent == null || $parent != $row['parent']) {
				$parent = $row['parent'];
				//$vrstni_red = 0;
				$vrstni_red = 1;
			} else {
				$vrstni_red++;
			}

			if ( $row['vrstni_red'] == $vrstni_red ) {

				//ok
			} else {
				// not ok
				return false;
			}

			if ($row['element_if'] > 0) {
				if ( ! self::checkBranching($row['element_if']) )
					return false;
			}
		}

		return true;
	}

	/**
	 * rekurzivno preverja, ce je z srv_branchingom vse ok
	 * za starejse ankete, vazno je da se vrstni_red ne ponavlja, ok je npr: 123, 124, 125, 160, 162
	 *
	 * @param mixed $parent
	 */
	static function checkBranchingOld ($parent = 0) {

		if ( ! self::$anketa > 0 ) return false;

		$sql = sisplet_query("SELECT parent, vrstni_red, element_if FROM srv_branching WHERE ank_id = '".self::$anketa."' AND parent='$parent' ORDER BY parent, vrstni_red");
		$parent = null;
		$vrstni_red = null;
		while ($row = mysqli_fetch_array($sql)) {

			if ($parent == null || $parent != $row['parent']) {
				$parent = $row['parent'];
				$vrstni_red = 0;
				//$vrstni_red = 1;
			} else {
				//$vrstni_red++;
			}

			//echo $row['parent'].' '.$row['vrstni_red'].' ( '.$vrstni_red.' )<br>';

			if ( $row['vrstni_red'] > $vrstni_red ) {

				//ok
			} else {
				// not ok
				return false;
			}

			if ($row['element_if'] > 0) {
				if ( ! self::checkBranchingOld($row['element_if']) )
					return false;
			}

			$vrstni_red = $row['vrstni_red'];
		}

		return true;
	}

	/**
	 * rekurzivno se sprehodimo cez vse elemente v anketi in vrnemo seznam v pravem vrstnem redu
	 *
	 * @param mixed $parent
	 */
	static $branching_array = array();
	static function getBranchingOrder ($parent = 0) {

		if (! self::$anketa > 0) return false;

		$sql = sisplet_query("SELECT element_spr, element_if, parent FROM srv_branching WHERE ank_id = '".self::$anketa."' AND parent='$parent' ORDER BY parent, vrstni_red");
		while ($row = mysqli_fetch_array($sql)) {

			self::$branching_array[] = array('spr_id'=>$row['element_spr'], 'if_id'=>$row['element_if'], 'parent'=>$row['parent']);

			if ($row['element_if'] > 0)
				self::getBranchingOrder($row['element_if']);
		}

		if($parent == 0)
			return self::$branching_array;
		else
			return false;
	}


	/** Naslov za odgovor email sporočil.
	 * Privzeto je avtor ankete
	 * Če ne uporabimo email uporabnika
	 * v nasprotnem primeru damo info@1ka.si ali info@safe.si (odvisno od domene)
	 *
	 * @return Ambigous <string, multitype:>
	 */
	function getReplyToEmail() {
		global $global_user_id, $site_domain;

		# naslov za odgovor je avtor ankete
		$sql = sisplet_query("SELECT email FROM users WHERE id = (select insert_uid from srv_anketa where id='".self::$anketa."')");
		list($MailReplyTo) = mysqli_fetch_row($sql);
		# preverimo veljavnost e-maila
		if ($MailReplyTo == null || !$this->validEmail($MailReplyTo))
		{
			$sql = sisplet_query("SELECT email FROM users WHERE id = '$global_user_id'");
			list($MailReplyTo) = mysqli_fetch_row($sql);
		}

		if ($MailReplyTo == null || trim($MailReplyTo) == '' || !$this->validEmail($MailReplyTo) )
		{
			if (strpos($site_domain, "safe.si") === false)
			{
				$MailReplyTo = '1ka@1ka.si';
			}
			else
			{
				$MailReplyTo = '1ka@safe.si';
			}
		}

		return $MailReplyTo;
	}

	/** Naslov pošiljatelja email sporočil.
	 * odvisno od strani če smo na safe.si uporabimo info@safe.si
	 * če ne pa preberemo nastavitev iz baze
	 * oziroma uporabimo info@1ka.si
	 * po novem se vabila in obvescanje posilja iz raziskave@1ka.si (namesto info@1ka.si)
	 *
	 * @return Ambigous <string, multitype:>
	 */
	function getFromEmail() {
		global $global_user_id, $site_domain;

        if(AppSettings::getInstance()->getSetting('email_server_settings-SMTPFrom') !== false)
		    $MailFrom = AppSettings::getInstance()->getSetting('email_server_settings-SMTPFrom');

		# Če je slučanjo napaka nastavimo info@1ka.si
		if ($MailFrom == null || trim($MailFrom) == '' || !$this->validEmail($MailFrom)){
			$MailFrom = 'info@1ka.si';
		}

		return $MailFrom;
	}



	/**
	Validate an email address.
	Provide email address (raw input)
	Returns true if the email address has the email
	address format and the domain exists.
	 */
	function validEmail($email = null) {

		$isValid = true;
		$atIndex = strrpos($email, "@");

		if (is_bool($atIndex) && !$atIndex) {
			$isValid = false;
		}
		else {
			$domain = substr($email, $atIndex+1);
			$local = substr($email, 0, $atIndex);
			$localLen = strlen($local);
			$domainLen = strlen($domain);
			$domain_parts = explode('.',$domain);

			if ($localLen < 1 || $localLen > 64) {
				// local part length exceeded
				$isValid = false;
			} else if ($domainLen < 1 || $domainLen > 255) {
				// domain part length exceeded
				$isValid = false;
			} else if ($local[0] == '.' || $local[$localLen-1] == '.') {
				// local part starts or ends with '.'
				$isValid = false;
			} else if ($domain[0] == '.' || $domain[$domainLen-1] == '.') {
				// domain part starts or ends with '.'
				$isValid = false;
			} else if (preg_match('/\\.\\./', $local)) {
				// local part has two consecutive dots
				$isValid = false;
			} else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
				// character not valid in domain part
				$isValid = false;
			} else if (preg_match('/\\.\\./', $domain)) {
				// domain part has two consecutive dots
				$isValid = false;
			} else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) {
				// character not valid in local part unless
				// local part is quoted
				if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) {
					$isValid = false;
				}
			} else if ( strlen($domain_parts[0]) < 1) {
				// num chars in
				$isValid = false;
			} else if ( strlen($domain_parts[1]) < 1) {
				$isValid = false;
			}

			/*if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
				// domain not found in DNS
				$isValid = false;
			}*/
		}

		return $isValid;
	}

	static function formatNumberSimple ($value, $digit = 0, $sufix = "") {
		if ($value <> 0 && $value != null)
			$result = round($value, $digit);
		else
			$result = "0";

		# polovimo decimalna mesta in vejice za tisočice

		$decimal_point = SurveyDataSettingProfiles :: getSetting('decimal_point');
		$thousands = SurveyDataSettingProfiles :: getSetting('thousands');

		$result = number_format($result, $digit, $decimal_point, $thousands) . $sufix;

		return $result;
	}

	static function formatNumber ($value, $digit = 0, $form=null, $sufix = "") {
		
		# Kako izpisujemo decimalke in tisočice
		$default_seperators = array(	
			'decimal_point'	=>	'.', 
			'thousands'		=>	','
			/*0=>array('decimal_point'=>'.', 'thousands'=>','),
			1=>array('decimal_point'=>',', 'thousands'=>'.')*/
		);

		if (is_array($form) && isset($form['decimal_point'])&& isset($form['thousands'])) {
			$decimal_point = $form['decimal_point'];
			$thousands = $form['thousands'];
		} 
		else {
			$decimal_point = $default_seperators['decimal_point'];
			$thousands = $default_seperators['thousands'];
		}

		if ($value <> 0 && $value != null)
			$result = round($value, $digit);
		else
			$result = "0";

		$result = number_format($result, $digit, $decimal_point, $thousands).$sufix;

		return $result;
	}


	/**
	 * @desc V podanem stringu poisce spremenljivke in jih spajpa z vrednostmi
	 */
	private $dataPiping_query = null;   // kesiramo query, ker ga bomo ponavljali za vsako spremenljivko
	public function dataPiping ($text, $usr_id, $loop_id=null, $lang_id=null) {

		if ($text != null && stripos($text, "#") !== false) {
			if ($this->dataPiping_query == null)
				$this->dataPiping_query = sisplet_query("SELECT s.* FROM srv_spremenljivka s, srv_grupa g WHERE g.ank_id='".self::$anketa."' AND s.gru_id=g.id AND s.tip!='5' AND (s.tip < '10' OR s.tip = '17' OR s.tip = '22' OR s.tip = '25' OR s.tip='21')");
			if (mysqli_num_rows($this->dataPiping_query))
				mysqli_data_seek($this->dataPiping_query, 0);

			// pri loopih izpisemo samo vrednost spremenljivke za trenuten loop
			if ($loop_id != null) {
				$sql = sisplet_query("SELECT * FROM srv_loop_data WHERE id = '$loop_id'");
				$row = mysqli_fetch_array($sql);
				$loop_vre_id = $row['vre_id'];
				$sql = sisplet_query("SELECT * FROM srv_loop WHERE if_id = '$row[if_id]'");
				$row = mysqli_fetch_array($sql);
				$loop_spr_id = $row['spr_id'];
			} else $loop_spr_id = 0;

			while ($row1 = mysqli_fetch_array($this->dataPiping_query)) {

				if ($row1['tip'] <= 3) {    // radio, checkbox, select

					if (stripos($text, '#'.$row1['variable'].'#') !== false) {
						$pipe = '';
						if ($loop_spr_id == 0) {	// obicen piping
							$sql2 = sisplet_query("SELECT v.id, v.naslov, v.other FROM srv_data_vrednost".self::$db_table." d, srv_vrednost v WHERE d.vre_id=v.id AND d.spr_id='$row1[id]' AND v.spr_id='$row1[id]' AND d.usr_id='$usr_id'");

							while ($row2 = mysqli_fetch_assoc($sql2)) {

								// Piping za multilang anketo
								if($lang_id != null){
									$translate = self::translate_vrednost($lang_id, $row2['id']);
									$row2['naslov'] = $translate ? $translate : $row2['naslov'];
								}

								if ($pipe != '') $pipe .= ', ';

								if ($row2['other'] == 0) {
									$pipe .= $row2['naslov'];
								}
								elseif ($row2['other'] == 1) {
									$sql3 = sisplet_query("SELECT text FROM srv_data_text".self::$db_table." WHERE spr_id='$row1[id]' AND vre_id='$row2[id]' AND usr_id='$usr_id'");
									$row3 = mysqli_fetch_array($sql3);
									$pipe .= $row3['text'];
								}
							}
						}
						// piping v loopu
						else {
							$sql2 = sisplet_query("SELECT v.id, v.naslov, v.other FROM srv_vrednost v WHERE id = '$loop_vre_id'");
							while ($row2 = mysqli_fetch_array($sql2)) {
								// Piping za multilang anketo
								if($lang_id != null){
									$translate = self::translate_vrednost($lang_id, $row2['id']);
									$row2['naslov'] = $translate ? $translate : $row2['naslov'];
								}

								if ($pipe != '') $pipe .= ', ';

								if ($row2['other'] == 0) {
									$pipe .= $row2['naslov'];
								}
								elseif ($row2['other'] == 1) {
									$sql3 = sisplet_query("SELECT text FROM srv_data_text".self::$db_table." WHERE spr_id='$row1[id]' AND vre_id='$row2[id]' AND usr_id='$usr_id'");
									$row3 = mysqli_fetch_array($sql3);
									$pipe .= $row3['text'];
								}
							}
						}

						$text = str_ireplace('#'.$row1['variable'].'#', '<span class="data-piping-'.$row1['id'].'">'.$pipe.'</span>', $text);
					}
				}
				elseif ($row1['tip'] == 9) {    // SN - imena

					if (stripos($text, '#'.$row1['variable'].'#') !== false) {
						$pipe = '';

						// piping v loopu
						$sql2 = sisplet_query("SELECT v.id FROM srv_vrednost v WHERE id = '$loop_vre_id'");
						while ($row2 = mysqli_fetch_array($sql2)) {
							if ($pipe != '') $pipe .= ', ';

							$sql3 = sisplet_query("SELECT text FROM srv_data_text".self::$db_table." WHERE spr_id='$row1[id]' AND vre_id='$row2[id]' AND usr_id='$usr_id'");
							$row3 = mysqli_fetch_array($sql3);
							$pipe .= $row3['text'];
						}

						$text = str_ireplace('#'.$row1['variable'].'#', '<span class="data-piping-'.$row1['id'].'">'.$pipe.'</span>', $text);
					}

				}
				elseif ($row1['tip'] == 4 or $row1['tip'] == 7 or $row1['tip'] == 8 or $row1['tip'] == 22 or $row1['tip'] == 25 or $row1['tip'] == 21) {    // textbox, number, datum

					// piping v loopu za number
					if ($row1['tip'] == 7 && $loop_spr_id != 0) {

						$sql3 = sisplet_query("SELECT COUNT(*)+1 AS c FROM srv_loop_data WHERE if_id='$row[if_id]' AND id<'$loop_id'");
						$row3 = mysqli_fetch_array($sql3);
						$text = str_ireplace('#'.$row1['variable'].'#', '<span class="data-piping-'.$row1['id'].'">'.$row3['c'].'</span>', $text);
					}
					else {
						if (stripos($text, '#'.$row1['variable'].'#') !== false) {
							$sql2 = sisplet_query("SELECT text FROM srv_data_text".self::$db_table." WHERE spr_id='$row1[id]' AND usr_id='$usr_id'");
							if (!$sql2) echo mysqli_error($GLOBALS['connect_db']);

							$row2 = mysqli_fetch_array($sql2);

							$text = str_ireplace('#'.$row1['variable'].'#', '<span class="data-piping-'.$row1['id'].'">'.nl2br($row2['text']).'</span>', $text);
						}
					}

				}
				elseif ($row1['tip'] == 6) {  // multigrid

					$sqlm = sisplet_query("SELECT id, variable FROM srv_vrednost WHERE spr_id = '$row1[id]'");
					while ($rowm = mysqli_fetch_array($sqlm)) {
						if (stripos($text, '#'.$rowm['variable'].'#') !== false) {

							$pipe = '';

							$sql2 = sisplet_query("SELECT g.id, g.naslov FROM srv_data_grid".self::$db_table." d, srv_grid g WHERE d.grd_id=g.id AND d.spr_id=g.spr_id AND d.spr_id='$row1[id]' AND d.vre_id='$rowm[id]' AND d.usr_id='$usr_id'");
							while ($row2 = mysqli_fetch_array($sql2)) {

								// Piping za multilang anketo
								if($lang_id != null){
									$translate = self::translate_grid($lang_id, $row1['id'], $row2['id']);
									$row2['naslov'] = $translate ? $translate : $row2['naslov'];
								}

								if ($pipe != '') $pipe .= ', ';

								$pipe .= $row2['naslov'];
							}

							$text = str_ireplace('#'.$rowm['variable'].'#', '<span class="data-piping-'.$row1['id'].'">'.$pipe.'</span>', $text);
						}
					}
				}
				elseif ($row1['tip'] == 17) {    // Ranking

					if (stripos($text, '#'.$row1['variable'].'#') !== false) {
						$pipe = '';

						// piping v loopu
						$sql2 = sisplet_query("SELECT v.id, v.naslov FROM srv_vrednost v WHERE id = '$loop_vre_id'");
						while ($row2 = mysqli_fetch_array($sql2)) {						
							if ($pipe != '') $pipe .= ', ';

							$pipe .= $row2['naslov'];
						}

						$text = str_ireplace('#'.$row1['variable'].'#', '<span class="data-piping-'.$row1['id'].'">'.$pipe.'</span>', $text);
					}

				}
			}
		}

		return $text;
	}

	/**
	 * prevod za srv_spremenljivka
	 */
	static function translate_spremenljivka($lang_id, $spremenljivka) {

		if ($lang_id != null) {
			$sqll = sisplet_query("SELECT * FROM srv_language_spremenljivka WHERE ank_id='".self::$anketa."' AND spr_id='".$spremenljivka."' AND lang_id='".$lang_id."'");
			$rowl = mysqli_fetch_array($sqll);

			return $rowl;
		}

		return false;
	}

	/**
	 * prevod za srv_vrednost
	 */
	static function translate_vrednost($lang_id, $vrednost) {

		if ($lang_id != null) {

			$sqll = sisplet_query("SELECT naslov FROM srv_language_vrednost WHERE ank_id='".self::$anketa."' AND vre_id='".$vrednost."' AND lang_id='".$lang_id."'");
			$rowl = mysqli_fetch_array($sqll);

			if ($rowl['naslov'] != '')
				return $rowl['naslov'];
		}

		return false;
	}

	/**
	 * prevod za srv_grid
	 */
	static function translate_grid($lang_id, $spremenljivka, $grid) {

		if ($lang_id != null) {

			$sqll = sisplet_query("SELECT naslov FROM srv_language_grid WHERE ank_id='".self::$anketa."' AND spr_id=".$spremenljivka." AND grd_id='".$grid."' AND lang_id='".$lang_id."'");
			$rowl = mysqli_fetch_array($sqll);

			if ($rowl['naslov'] != '')
				return $rowl['naslov'];
		}

		return false;
	}


	static function isUserAnketar($anketa,$user) {

		$str = " (SELECT count(*)FROM srv_dostop AS sd WHERE sd.ank_id='$anketa' AND sd.aktiven = '1'"
			." AND uid = '$user' "
			." AND FIND_IN_SET('phone',sd.dostop )>0 AND FIND_IN_SET('edit',sd.dostop ) = 0)";
		$qry = sisplet_query($str);
		list($cnt) = mysqli_fetch_row($qry);

		return ((int)$cnt > 0) ? true : false;;
	}

	static function getSpremenljivkaSkala($spr_id) {
		# skala se lahko nastavlja samo za:
		# ($row['tip'] == 1 || $row['tip'] == 2 || $row['tip'] == 3 || $row['tip'] == 6)


		// uporabniško nastavljena
		# skala - 1 Nominalna
		# skala - 0 Ordinalna - računamo povprečja

		# v bazi je privzeto -1

		$row = Cache::srv_spremenljivka($spr_id);
		$value = $row['skala'];
		//pri checkboxu je default nominalna
		if($row['skala'] == -1 && $row['tip'] == 2) {
			$value = (int)1;

			# če uporabnik še ni spremninjal
		} elseif($row['skala'] == -1) {
			# če je radio
			if ($row['tip'] == 1 ) {
				# če imamo opcij 4 ali več je ordinalna
				$sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id = '$spr_id' ORDER BY vrstni_red ASC");
				if (mysqli_num_rows($sql1) > 3) {
					$value = (int)0; # Ordinalna - računamo povprečja
				}
			}
			# če je multiradio
			if ($row['tip'] == 6 ) {
				# če imamo opcij 4 ali več je ordinalna
				$sql_grid = sisplet_query("SELECT id FROM srv_grid WHERE spr_id='".$spr_id."'");
				if (mysqli_num_rows($sql_grid) > 3) {
					$value = (int)0; # Ordinalna - računamo povprečja
				}
			}
		} else {
			# drugače pustimo uporabniško nastavljeno (ali default (-1))
			$value = (int)$row['skala'];
		}

		return $value;
	}

	// ime pove vse :-)
	static function RemoveNiceUrl($ank_id) {
		global $site_path;

		$sql = sisplet_query("SELECT link FROM srv_nice_links WHERE ank_id = '$ank_id'");
		$row = mysqli_fetch_array($sql);

		$nice_url = $row['link'];

		$f = fopen($site_path.'.htaccess', 'rb');

		if ($f !== false) {
			$output = array();

			while (!feof($f)) {
				$r = fgets($f);

				if (strpos($r, "^".$nice_url.'\b') !== false && strpos($r, "?anketa=".$ank_id."") !== false) {
					// kao pobrisemo vrstico
				} else {
					$output[] = $r;
				}
			}

			fclose($f);
		}

		if (count($output) > 0) {

			$f = fopen($site_path.'.htaccess', 'w');

			if ($f !== false) {
				foreach ($output AS $line) {
					fwrite($f, $line);
				}
				fclose($f);

				$sql = sisplet_query("DELETE FROM srv_nice_links WHERE ank_id = '$ank_id'");

				// Preverimo ce imamo skupine s tem urljem in jih pobrisemo
				$sqlS = sisplet_query("SELECT * FROM srv_nice_links_skupine WHERE ank_id='$ank_id'");
				if(mysqli_num_rows($sqlS) > 0){

					$f = fopen($site_path.'.htaccess', 'rb');

					if ($f !== false) {
						$outputS = array();

						while (!feof($f)) {
							$r = fgets($f);

							// Loop cez vse skupine
							$delete = false;
							$sqlS = sisplet_query("SELECT * FROM srv_nice_links_skupine WHERE ank_id='$ank_id'");

							while($rowS = mysqli_fetch_array($sqlS)){

								if (strpos($r, "^".$rowS['link'].'\b') !== false && strpos($r, "?anketa=".$ank_id."&skupina=".$rowS['vre_id']."") !== false) {

									// pobrisemo vrstico in vnos v bazi
									$sqlD = sisplet_query("DELETE FROM srv_nice_links_skupine WHERE ank_id='$ank_id' AND nice_link_id='$row[id]' AND vre_id='$rowS[vre_id]'");
									$delete = true;
								}
							}

							if($delete == false){
								$outputS[] = $r;
							}
						}
						fclose($f);
					}

					if (count($outputS) > 0) {

						$f = fopen($site_path.'.htaccess', 'w');
						if ($f !== false) {
							foreach ($outputS AS $line) {
								fwrite($f, $line);
							}
							fclose($f);
						}
					}
				}
			}
		}
	}

	/**
	 * preveri ce je dolocen modul vklopljen na tej instalaciji 1ke (npr. hirearhija, evalvacija, 360...)
	 */
	static function checkModule($module) {

		$sql = sisplet_query("SELECT active FROM srv_module WHERE module_name='$module'");
		$row = mysqli_fetch_array($sql);

		return ($row['active'] == '1') ? true : false;
	}


	// Vrne help url glede na ustrezno podstran
	public static function getHelpUrl($subdomain, $podstran){

		// Default help url
		$help_url = 'http://www.1ka.si/d/sl/pomoc';

		// Angleški vmesnik - usmerimo na english.1ka.si help
		if($subdomain == 'english'){

			// Nastavitve in podzavihki
			if ((!isset($_GET['anketa']) || $_GET['anketa'] == '') && ($_GET['a'] == 'nastavitve' # in podzavihki
				|| $_GET['a'] == 'osn_pod'
				|| $_GET['a'] == 'trajanje'
				|| $_GET['a'] == 'dostop'
				|| $_GET['a'] == 'urejanje') ) {
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/my-surveys/settings';
			}
			
			//Mobilne nastavitve
			elseif($_GET['a']== 'mobile_settings'){
				$help_url = 'https://www.1ka.si/d/en/help/manuals/mobile-survey-adjustments';
			}
			
			//Standardne besede
			elseif($_GET['a']== 'jezik'){
				$help_url = 'https://www.1ka.si/d/en/help/faq/can-standard-words-be-altered';
			}
			
			//Dostop uredniki
			elseif($_GET['a']== 'dostop'){
				$help_url = 'https://www.1ka.si/d/en/help/faq/how-can-i-add-another-survey-administrator';
			}
			
			//Dostop respondenti
			elseif($_GET['a']== 'piskot'){
				$help_url = 'https://www.1ka.si/d/en/help/manuals/settings-for-respondent-access-cookies-and-passwords';
			}
			
			// Obvescanje
			else if ($_GET['a'] == 'alert') {
				if($_GET['m']=='email_server'){
					$help_url = 'https://www.1ka.si/d/en/help/manuals/sending-emails-via-an-arbitrary-server-eg-gmail ';
				}
				else{
					$help_url = 'https://www.1ka.si/d/en/help/manuals/notifications';
				}
			}
			
			//Aktivnost/kvote
			elseif($_GET['a']== 'trajanje'){
				$help_url = 'https://www.1ka.si/d/en/help/manuals/survey-duration-based-on-date-or-the-number-of-responses';
			}

			//Skupine
			elseif($_GET['a']== 'skupine'){
				$help_url = 'https://www.1ka.si/d/en/help/manuals/creating-respondent-groups';
			}
			
			//Komentarji
			elseif($_GET['a']== 'urejanje'){
				$help_url = 'https://www.1ka.si/d/en/help/manuals/comments';
			}

			//Prikaz podatkov
			elseif($_GET['a']== A_PRIKAZ){	//|| $_GET['a'] == A_PRIKAZ
				$help_url = 'https://www.1ka.si/d/en/help/manuals/data-display-settings';
			}

			//Parapodatki
			elseif($_GET['a']== 'metadata'){	//|| $_GET['a'] == 'metadata'
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/edit/settings';
			}

			//Manjkajoce vrednosti
			elseif($_GET['a']== 'missing'){	//|| $_GET['a'] == 'missing'
				$help_url = 'https://www.1ka.si/d/en/help/manuals/status-of-units-relevance-validity-and-missing-values';
			}
			
			//PDF/RFT Izvozi
			elseif($_GET['a']== 'export_settings'){
				$help_url = 'https://www.1ka.si/d/en/help/manuals/settings-for-exporting-pdfrtf-files-with-responses';
			}
			
			//GDPR
			elseif($_GET['a']== 'gdpr_settings'){
				$help_url = 'https://www.1ka.si/d/en/help/manuals/gdpr-survey-settings';
			}
			
			//Samoevalvacija v solah
			elseif($_GET['a']== 'hierarhija_superadmin'){
				//if($_GET['m']== 'uredi-sifrante'){
				if($_GET['m']== 'uredi-sifrante' || $_GET['m']== 'status'){
					$help_url = 'https://www.1ka.si/d/en/help/user-guide/advanced-modules/self-evaluation-schools';
				}
			}
			
			//Klepet
			elseif($_GET['a']== 'chat'){
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/advanced-modules/chat';
			}
			
			//Panel
			elseif($_GET['a']== 'panel'){
				$help_url = ' https://www.1ka.si/d/en/help/user-guide/advanced-modules/panel';
			}
			
			//Napredni parapodatki
			elseif($_GET['a']== 'advanced_paradata'){
				$help_url = 'https://www.1ka.si/d/en/about/general-description/user-levels/administrator';
			}
			
			//JSON izvoz ankete
			elseif($_GET['a']== 'json_survey_export'){
				$help_url = 'https://www.1ka.si/d/en/help';
			}
			
			//TABLICE, PRENOSNIKI (BETA)
			elseif($_GET['a']== 'fieldwork'){
				//$help_url = 'https://www.1ka.si/d/en/about/uses-of-1ka-services/1ka-offline';
				$help_url = 'https://www.1ka.si/d/en/help';
			}

			//360 stopinj
			elseif($_GET['a']== '360_stopinj'){
				$help_url = 'https://www.1ka.si/d/en/help';
			}

			//borza
			elseif($_GET['a']== 'borza'){
				$help_url = 'https://www.1ka.si/d/en/help';
			}

			//mju
			elseif($_GET['a']== 'mju'){
				$help_url = 'https://www.1ka.si/d/en/help';
			}

			//excelleration matrix
			elseif($_GET['a']== 'excell_matrix'){
				$help_url = 'https://www.1ka.si/d/en/help';
			}
			
			//Povezave - jezik
			elseif($_GET['a']== 'prevajanje'){
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/edit/settings/language';
			}

			// Napredni moduli
			else if ($_GET['a'] == A_TELEPHONE) {
				$help_url = 'http://www.1ka.si/d/en/help/user-guide/advanced-modules/telephone-survey';
			}
			else if ($_GET['a'] == 'uporabnost') {
				$help_url = 'http://www.1ka.si/d/en/help/user-guide/advanced-modules/website-evaluation-split-screen';
			}
			else if ($_GET['a'] == 'vnos') {
				$help_url = 'http://www.1ka.si/d/en/help/user-guide/advanced-modules/administrative-data-input';
			}
			else if ($_GET['a'] == 'kviz') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/quiz';
			}
			else if ($_GET['a'] == 'slideshow') {
				$help_url = 'http://www.1ka.si/d/en/help/user-guide/advanced-modules/slideshow';
			}
			else if ($_GET['a'] == 'social_network') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/social-networks';
			}

			// Oblika
			else if ($_GET['a'] == 'tema') {
				$help_url = 'http://www.1ka.si/d/en/help/user-guide/edit/design';
			}
			else if ($_GET['a'] == 'theme-editor') {
				if($_GET['t'] == 'css'){
					$help_url = 'https://www.1ka.si/d/en/help/faq/can-i-alter-the-design-of-an-individual-survey';
				}else{
					$help_url = 'https://www.1ka.si/d/en/help/manuals/design';
				}
			}

			// Arhivi
			else if ($_GET['a'] == 'arhivi') {
				if($_GET['m']== 'data'){
					$help_url = 'https://www.1ka.si/d/en/help/manuals/data-archive';
				}elseif($_GET['m']== 'survey'){
					$help_url = 'https://www.1ka.si/d/en/help/manuals/export-survey-archive';
				}elseif($_GET['m']== 'survey_data'){
					$help_url = 'https://www.1ka.si/d/en/help/manuals/export-survey-archive';
				}elseif($_GET['m']== 'testdata'){
					$help_url = 'https://www.1ka.si/d/en/help/manuals/test-entries';
				}
				else{
					$help_url = 'https://www.1ka.si/d/en/help/manuals/questionnaire-archives';
				}
			}
			
			//Spremembe
			elseif($_GET['a']== 'tracking'){
					$help_url = 'https://www.1ka.si/d/en/help/manuals/archives-survey-changes';				
			}
			
			// STATUS in podstrani
			elseif($_GET['a']== 'reporti'){
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/dashboard/summary';
			}elseif($_GET['a']== 'para_graph'){
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/dashboard/paradata';
			}elseif($_GET['a']== 'nonresponse_graph'){
				if($_GET['m']== 'breaks'){
					$help_url = 'https://www.1ka.si/d/en/help/manuals/interruptions-beta';
				}elseif($_GET['m']== 'advanced'){
					$help_url = 'https://www.1ka.si/d/en/help/user-guide/dashboard/item-nonresponse';
				}else{
					$help_url = 'https://www.1ka.si/d/en/help/user-guide/dashboard/item-nonresponse';
				}				
			}elseif($_GET['a']== 'usable_resp'){
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/dashboard/usable-respondents';
			}elseif($_GET['a']== 'speeder_index'){
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/dashboard/speed-index';
			}elseif($_GET['a']== 'text_analysis'){
				$help_url = '';
			}elseif($_GET['a']== 'geoip_location'){
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/dashboard/ip-location';
			}

			// Komentarji
			else if ($_GET['a'] == 'komentarji' || $_GET['a'] == 'komentarji_anketa') {
				$help_url = 'http://www.1ka.si/d/en/help/user-guide/testing/comments';
			}

			// Testiranje
			else if ($_GET['a'] == 'testiranje') {
				if ($_GET['m'] == 'diagnostika') {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/testing/diagnostics';
				}
				else if ($_GET['m'] == 'testnipodatki') {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/testing/automatic-entries';
				}
				else if ($_GET['m'] == 'predvidenicas') {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/testing/diagnostics';
				}
				else if ($_GET['m'] == 'cas') {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/testing/diagnostics';
				}
				else {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/testing/diagnostics';
				}
			}

			// Vabila
			else if ($_GET['a'] == 'vabila') {
				if($_GET['m'] == 'url') {
					$help_url = 'https://www.1ka.si/d/en/help/user-guide/publish/link-url';
				}else{
					$help_url = 'https://www.1ka.si/d/en/help/user-guide/publish/settings';
				}
			}
			
			else if ($_GET['a'] == 'invitations') {
				if ($_GET['m'] == 'add_recipients_view') {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/publish/1ka-invitations';
				} else if ($_GET['m'] == 'view_recipients') {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/publish/1ka-invitations';
				} else if ($_GET['m'] == 'view_message') {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/publish/1ka-invitations';
				} else if ($_GET['m'] == 'send_message') {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/publish/1ka-invitations';
				} else if ($_GET['m'] == 'view_archive') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/invitation-archives';
				} else {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/publish/1ka-invitations';
				}
			}

			// Podatki
			else if ($_GET['a'] == 'data') {
				if ($_GET['m'] == 'quick_edit') {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/data/browse';
				} else if ($_GET['m'] == 'calculation') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/computed-values';
				} else if ($_GET['m'] == 'coding') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/manual-coding';
				} else if ($_GET['m'] == 'coding_auto') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/automatic-coding';
				} else if ($_GET['m'] == 'recoding') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/recoding';
				} else if ($_GET['m'] == 'append') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/adding-data-append';
				} else if ($_GET['m'] == 'merge') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/merging-data';
				} else {
					$help_url = 'http://www.1ka.si/d/en/help/user-guide/data/browse';
				}
			}
			// Izvoz podatkov
			else if ($_GET['a'] == 'export') {
				if ($_GET['m'] == 'spss' || $_GET['m'] == 'sav') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/export-to-spss';
				}else if ($_GET['m'] == 'excel_xls') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/export-to-excel';
				}else if ($_GET['m'] == 'excel') {
					$help_url = 'https://www.1ka.si/d/en/help/faq/export-to-excel-why-are-answers-incomplete-when-i-export-the-data-to-excel';
				} 
				else if ($_GET['m'] == 'txt') {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/export-to-text-file';
				} else {
					$help_url = 'https://www.1ka.si/d/en/help/manuals/export-to-spss';
				}
			}

			// Analiza
			else if ($_GET['a'] == 'analysis' && (in_array($_GET['m'], array('', 'sumarnik', 'ttest', 'para')))) {
				$help_url = 'http://www.1ka.si/d/en/help/user-guide/analysis/statistics';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'charts') {
				$help_url = 'http://www.1ka.si/d/en/help/user-guide/analysis/charts';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'anal_arch') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/analysis-archives';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'analysis_links') {
				$help_url = 'http://www.1ka.si/d/en/help/user-guide/analysis/reports';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'analysis_creport') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/custom-reports';
			}			
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'descriptor') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/descriptive-statistics';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'frequency') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/frequencies';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'crosstabs') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/crosstabs';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'multicrosstabs') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/multitables';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'means') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/means';
			}else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'break') {
				$help_url = 'https://www.1ka.si/d/en/help/manuals/break';
			}
			
			//My surveys
			else if ($_GET['a'] == 'ustvari_anketo') {
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/creating-new-survey';
			}
			
			//Activities
			else if ($_GET['a'] == 'diagnostics' && $_GET['t'] != 'uporabniki' && $_GET['m'] != 'my') {
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/my-surveys/activity';
			}
			
			//Users
			else if ($_GET['a'] == 'diagnostics' && $_GET['t'] == 'uporabniki') {
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/my-surveys/users';
			}
			
			//Library
			else if ($_GET['a'] == 'knjiznica') {
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/my-surveys/library';
			}
			
			//Sporocila
			else if ($_GET['a'] == 'obvestila') {
				$help_url = 'https://www.1ka.si/d/sl/o-1ka/splosen-opis/nivoji-uporabnikov/administrator';
			}
			
			//GDPR
			else if ($_GET['a'] == 'gdpr') {				
				switch($_GET['m']){
					case 'gdpr_survey_list':
						$help_url = 'https://www.1ka.si/d/en/help/user-guide/list-of-surveys';
					break;
					case 'gdpr_requests':
						$help_url = 'https://www.1ka.si/d/en/help/user-guide/my-surveys/gdpr-profile/processing-requests';
					break;					
					case 'gdpr_requests_all':
						$help_url = 'https://www.1ka.si/d/en/help/user-guide/my-surveys/gdpr-profile/processing-requests';
					break;
					case 'gdpr_dpa':
						$help_url = 'https://www.1ka.si/d/en/help/user-guide/my-surveys/gdpr-profile/dpa';
					break;
					default:
						$help_url = 'https://www.1ka.si/d/en/my-surveys/gdpr-profile/general-settings';
					break;					
				}				
			}
			
			//Analize urejanja
			else if ($_GET['a'] == 'edits_analysis') {
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/dashboard/edits-analyses';
			}
			
			//Urejanje - Vprasalnik
			else if ($_GET['a'] == 'branching') {
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/edit/questionnaire';				
			}
			
			//Urejanje - Nastavitve
			else if ((!isset($_GET['anketa']) || $_GET['anketa'] == '') && $_GET['a'] == 'nastavitve') {
				$help_url = 'https://www.1ka.si/d/en/help/user-guide/edit/settings';
			}

            // Moje ankete - narocila
			else if ($_GET['a'] == 'narocila') {
				$help_url = 'https://www.1ka.si/d/en/services';
			}

			// Ostale default podstrani
			else {
				switch ($podstran) {
					case NAVI_UREJANJE:
						$help_url = 'http://www.1ka.si/d/en/help/user-guide/edit';
						break;
					case NAVI_OBJAVA:
						$help_url = 'http://www.1ka.si/d/en/help/user-guide/publish';
						break;
					case NAVI_RESULTS:
						$help_url = 'http://www.1ka.si/d/en/help/user-guide/data';
						break;
					case NAVI_ANALYSIS:
						$help_url = 'http://www.1ka.si/d/en/help/user-guide/analysis';
						break;
					case NAVI_TESTIRANJE:
						$help_url = 'http://www.1ka.si/d/en/help/user-guide/testing';
						break;
					case NAVI_STATUS:
						$help_url = 'http://www.1ka.si/d/en/help/user-guide/dashboard';
						break;
					case NAVI_ADVANCED:
						$help_url = 'http://www.1ka.si/d/en/help/user-guide/advanced-modules';
						break;
					default:
						//$help_url = 'https://www.1ka.si/d/en/help/my-surveys';
						$help_url = 'https://www.1ka.si/d/en/help/user-guide/edit/questionnaire';
						break;
				}
			}
		}
		// Slovenski vmesnik - usmerimo na www.1ka.si help
		else{

			// Nastavitve in podzavihki
			if ($_GET['a'] == 'nastavitve' # in podzavihki
				|| $_GET['a'] == 'osn_pod') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/moje-ankete/nastavitve';
			}
			
			
			//Mobilne nastavitve
			elseif($_GET['a']== 'mobile_settings'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/prilagoditve-za-mobilno-anketo';
			}
			
			//Standardne besede
			elseif($_GET['a']== 'jezik'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/pogosta-vprasanja/ali-mozno-spremeniti-standardne-besede';
			}			
			
			//Dostop uredniki
			elseif($_GET['a']== 'dostop'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/pogosta-vprasanja/kako-dodam-se-eno-osebo-za-urejanje-vprasalnika';
			}
			
			//Dostop respondenti
			elseif($_GET['a']== 'piskot'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/nastavitve-za-dostop-respondentov-piskotki-ip-naslovi-gesla-sistemsko-prepoznavanja';
			}
			
			//Aktivnost/kvote
			elseif($_GET['a']== 'trajanje'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/trajanje-ankete-glede-na-datum-ali-stevilo-odgovorov-kvote';
			}			
			
			//Skupine
			elseif($_GET['a']== 'skupine'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/ustvarjanje-skupin-respondentov';
			}			
			
			//Komentarji
			elseif($_GET['a']== 'urejanje'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/komentarji';
			}			
			
			//Prikaz podatkov
			elseif($_GET['a']== A_PRIKAZ){	//|| $_GET['a'] == A_PRIKAZ
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/prikaz-podatkov-nastavitve';
			}			
			
			//Parapodatki
			elseif($_GET['a']== 'metadata'){	//|| $_GET['a'] == 'metadata'
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/anketni-podatki-parapodatki-identifikatorji-sistemske-spremenljivke';
			}			
			
			//Manjkajoce vrednosti
			elseif($_GET['a']== 'missing'){	//|| $_GET['a'] == 'missing'
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/statusi-enot-ustreznost-veljavnost-manjkajoce-vrednosti';
			}
			
			//PDF/RFT Izvozi
			elseif($_GET['a']== 'export_settings'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/nastavitve-izvoza-pdfrtf-datotek-z-odgovori';
			}			
			
			//GDPR
			elseif($_GET['a']== 'gdpr_settings'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/gdpr-nastavitve-ankete';
			}
			
			//Samoevalvacija v solah
			elseif($_GET['a']== 'hierarhija_superadmin'){
				//if($_GET['m']== 'uredi-sifrante'){
				if($_GET['m']== 'uredi-sifrante' || $_GET['m']== 'status'){
					$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/napredni-moduli/samoevalvacija-solah';
				}
			}
			
			//Klepet
			elseif($_GET['a']== 'chat'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/napredni-moduli/klepet';
			}			
			
			//Panel
			elseif($_GET['a']== 'panel'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/napredni-moduli/panel';
			}			
			
			//Napredni parapodatki
			elseif($_GET['a']== 'advanced_paradata'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/indeks-kakovosti-sledenje-opozorilom';
			}
			
			//JSON izvoz ankete
			elseif($_GET['a']== 'json_survey_export'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc';
			}
			
			//
			
			//TABLICE, PRENOSNIKI (BETA)
			elseif($_GET['a']== 'fieldwork'){
				//$help_url = 'https://www.1ka.si/d/sl/o-1ka/nacini-uporabe-1ka/1ka-offline';
				$help_url = 'https://www.1ka.si/d/sl/pomoc';
			}

			//360 stopinj
			elseif($_GET['a']== '360_stopinj'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc';
			}

			//borza
			elseif($_GET['a']== 'borza'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc';
			}

			//mju
			elseif($_GET['a']== 'mju'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc';
			}

			//excelleration matrix
			elseif($_GET['a']== 'excell_matrix'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc';
			}
			
			//Povezave - jezik
			elseif($_GET['a']== 'prevajanje'){
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/urejanje/nastavitve/jezik';
			}
			
			//Arhivi
			elseif($_GET['a']== 'arhivi'){
				if($_GET['m']== 'data'){
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/arhivi-podatkov';
				}elseif($_GET['m']== 'survey'){
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/izvoz-arhivi-ankete';
				}elseif($_GET['m']== 'survey_data'){
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/izvoz-arhivi-ankete';
				}elseif($_GET['m']== 'testdata'){
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/testni-vnosi';
				}
				else{
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/arhivi-vprasalnika';
				}				
			}
						
			//Spremembe
			elseif($_GET['a']== 'tracking'){
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/arhivi-spremembe-ankete';				
			}

			// STATUS in podstrani
			elseif($_GET['a']== 'reporti'){
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/status/povzetek/?from1ka=1';
			}elseif($_GET['a']== 'para_graph'){
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/status/parapodatki/?from1ka=1';
			}elseif($_GET['a']== 'nonresponse_graph'){
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/status/neodgovor-spremenljivke/?from1ka=1';
			}elseif($_GET['a']== 'usable_resp'){
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/status/uporabni-respondenti/?from1ka=1';
			}elseif($_GET['a']== 'speeder_index'){
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/status/indeks-hitrosti/?from1ka=1';
			}elseif($_GET['a']== 'text_analysis'){
				$help_url = '';
			}elseif($_GET['a']== 'geoip_location'){
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/status/ip-lokacija/?from1ka=1';
			}

			// Obvescanje
			else if ($_GET['a'] == 'alert') {
				if($_GET['m']=='email_server'){
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/posiljanje-emailov-preko-smtp-email-sistema-1ka-na-strezniku-uporabnika-oziroma';
				}
				else{
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/obvescanje';
				}
			}

			// Napredni moduli
			else if ($_GET['a'] == A_TELEPHONE) {
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/napredni-moduli/telefonska-anketa/?from1ka=1';
			}
			else if ($_GET['a'] == 'uporabnost') {
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/napredni-moduli/evalvacija-strani/?from1ka=1';
			}
			else if ($_GET['a'] == 'vnos') {
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/napredni-moduli/vnos-vprasalnikov/?from1ka=1';
			}
			else if ($_GET['a'] == 'kviz') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/kviz';
			}
			else if ($_GET['a'] == 'slideshow') {
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/napredni-moduli/prezentacija/?from1ka=1';
			}
			else if ($_GET['a'] == 'social_network') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/socialna-omrezja';
			}

			// Oblika
			else if ($_GET['a'] == 'tema') {
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/urejanje/oblika/?from1ka=1';
			}
			else if ($_GET['a'] == 'theme-editor') {
				if($_GET['t'] == 'css'){
					$help_url = 'https://www.1ka.si/d/sl/pomoc/pogosta-vprasanja/ali-lahko-spremenim-izgled-posamezne-ankete';
				}else{
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/oblika';
				}
				
			}

			// Komentarji
			else if ($_GET['a'] == 'komentarji' || $_GET['a'] == 'komentarji_anketa') {
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/testiranje/komentarji/?from1ka=1';
			}

			// Testiranje
			else if ($_GET['a'] == 'testiranje') {
				if ($_GET['m'] == 'diagnostika') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/testiranje/diagnostika/?from1ka=1';
				}
				else if ($_GET['m'] == 'testnipodatki') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/testiranje/avtomatski-vnosi/?from1ka=1';
				}
				else if ($_GET['m'] == 'predvidenicas') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/testiranje/diagnostika/?from1ka=1';
				}
				else if ($_GET['m'] == 'cas') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/testiranje/diagnostika/?from1ka=1';
				}
				else {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/testiranje/diagnostika/?from1ka=1';
				}
			}

			// Vabila
			else if ($_GET['a'] == 'vabila') {
				if($_GET['m'] == 'url') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/objava/povezava-url/?from1ka=1';
				}else{
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/objava/nastavitve-objave/?from1ka=1';
				}
			}
			else if ($_GET['a'] == 'invitations') {
				if ($_GET['m'] == 'add_recipients_view') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/objava/1ka-vabila/?from1ka=1';
				} else if ($_GET['m'] == 'view_recipients') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/objava/1ka-vabila/?from1ka=1';
				} else if ($_GET['m'] == 'view_message') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/objava/1ka-vabila/?from1ka=1';
				} else if ($_GET['m'] == 'send_message') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/objava/1ka-vabila/?from1ka=1';
				} else if ($_GET['m'] == 'view_archive') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/arhivi-vabil';
				} else {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/objava/email-vabila';
				}
			}

			// Podatki
			else if ($_GET['a'] == 'data') {
				if ($_GET['m'] == 'quick_edit') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/podatki/pregledovanje/?from1ka=1';
				} else if ($_GET['m'] == 'calculation') {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/podatki/izracuni/?from1ka=1';
				} else if ($_GET['m'] == 'coding') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/rocno-kodiranje';
				} else if ($_GET['m'] == 'coding_auto') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/avtomatsko-kodiranje';
				} else if ($_GET['m'] == 'recoding') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/rekodiranje';
				} else if ($_GET['m'] == 'append') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/dodajanje-podatkov-append';
				} else if ($_GET['m'] == 'merge') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/zdruzevanje-podatkov';
				} else {
					$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/podatki/pregledovanje/?from1ka=1';
				}
			}
			// Izvoz podatkov
			else if ($_GET['a'] == 'export') {
				if ($_GET['m'] == 'spss' || $_GET['m'] == 'sav') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/izvoz-spss';					
				}else if ($_GET['m'] == 'excel_xls') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/izvoz-excel';
				}else if ($_GET['m'] == 'excel') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/pogosta-vprasanja/izvoz-excel-zakaj-se-pri-izvozu-excel-odprti-odgovori-ne-izpisejo-celoti';
				} 
				else if ($_GET['m'] == 'txt') {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/izvoz-tekstovno-datoteko';
				} else {
					$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/izvoz-spss';
				}
			}

			// Analiza
			else if ($_GET['a'] == 'analysis' && (in_array($_GET['m'], array('', 'sumarnik', 'ttest', 'para')))) {
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/analize/statistike/?from1ka=1';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'charts') {
				$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/analize/grafi/?from1ka=1';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'anal_arch') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/arhivi-analiz';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'analysis_links') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/analize/porocila';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'analysis_creport') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/porocila-meri';
			}			
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'descriptor') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/opisne-statistike';
			}			
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'frequency') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/frekvence';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'crosstabs') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/tabele';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'multicrosstabs') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/multitabele';
			}
			else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'means') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/povprecja';
			}else if ($_GET['a'] == 'analysis' && $_GET['m'] == 'break') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/prirocniki/razbitje';
			}
			
			//Moje ankete
			else if ($_GET['a'] == 'ustvari_anketo') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/kreiranje-nove-ankete';
			}
			
			//Aktivnost
			else if ($_GET['a'] == 'diagnostics' && $_GET['t'] != 'uporabniki' && $_GET['m'] != 'my') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/moje-ankete/aktivnost';
			}
			
			//Uporabniki
			else if ($_GET['a'] == 'diagnostics' && $_GET['t'] == 'uporabniki') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/moje-ankete/uporabniki';
			}
			
			//Knjiznica
			else if ($_GET['a'] == 'knjiznica') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/moje-ankete/knjiznica';
			}
			
			//Sporocila
			else if ($_GET['a'] == 'obvestila') {
				$help_url = 'https://www.1ka.si/d/sl/o-1ka/splosen-opis/nivoji-uporabnikov/administrator';
			}

			//GDPR
			else if ($_GET['a'] == 'gdpr') {				
				switch($_GET['m']){
					case 'gdpr_survey_list':
						$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/moje-ankete/gdpr-profil/seznam-anket';
					break;
					case 'gdpr_requests':
						$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/moje-ankete/gdpr-profil/procesiranje-zahtevkov';
					break;					
					case 'gdpr_requests_all':
						$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/moje-ankete/gdpr-profil/procesiranje-zahtevkov';
					break;
					case 'gdpr_dpa':
						$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/moje-ankete/gdpr-profil/dpa';
					break;
					default:
						$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/moje-ankete/gdpr-profil/splosne-nastavitve';
					break;					
				}				
			}
			
			//Analize urejanja
			else if ($_GET['a'] == 'edits_analysis') {
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/status/analize-urejanja';
			}
			
			//Urejanje - Vprasalnik
			else if ($_GET['a'] == 'branching') {				
				$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/urejanje/vprasalnik';
			}

            // Moje ankete - narocila
			else if ($_GET['a'] == 'narocila') {
				$help_url = 'https://www.1ka.si/d/en/services';
				$help_url = 'https://www.1ka.si/d/sl/cenik';
			}
			
			// Ostale default podstrani
			else {
				switch ($podstran) {
					case NAVI_STATUS;
						$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/status/povzetek/?from1ka=1';
						break;
					case NAVI_UREJANJE:
						$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/urejanje/?from1ka=1';
						break;
					case NAVI_OBJAVA:
						$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/objava/?from1ka=1';
						break;
					case NAVI_RESULTS:
						$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/podatki/?from1ka=1';
						break;
					case NAVI_ANALYSIS:
						$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/analize/?from1ka=1';
						break;
					case NAVI_TESTIRANJE:
						$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/testiranje/?from1ka=1';
						break;
					case NAVI_STATUS:
						$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/status/?from1ka=1';
						break;
					case NAVI_ADVANCED:
						$help_url = 'http://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/napredni-moduli/?from1ka=1';
						break;
					default:
						//$help_url = 'https://www.1ka.si/d/sl/pomoc/moje-ankete';
						$help_url = 'https://www.1ka.si/d/sl/pomoc/vodic-za-uporabnike/urejanje/vprasalnik';
						break;
				}
			}
		}

		return $help_url;
	}

	// Nov algoritem za id ankete v url-ju za izpolnjevanje
	public static function generateSurveyHash(){
        
        $unique = false;

        while(!$unique){

            // Zgeneriramo random string z 8 znaki
            $hash = substr(md5(uniqid(mt_rand(), true)), 0, 8);

            // Preverimo ce slucajno ze obstaja v bazi
            $sql = sisplet_query("SELECT 1 FROM srv_anketa WHERE hash='".$hash."' LIMIT 1");
            if (mysqli_num_rows($sql) == 0)
                $unique = true;
        }
       
		return $hash;
	}

	// Algoritem, ki iz texta ustvari strukturo vprasanj in variabel (za uvoz anekte iz texta)
	public static function anketaArrayFromText($raw_text){
		
		if($raw_text != ''){
			
			// Trenutna vrstica je vprasanje (0) ali variabla (1)
			$prev_blank = true;
			$questin_cnt = -1;
			$variable_cnt = 0;
			
			$text_array = array();	
			
			// Gremo cez vse vrstice
			$lines = explode('\n', str_replace('\r', '', $raw_text));
			foreach($lines as $line){
				
				$line = trim($line);
				
				// Ce imamo prazno vrstico
				if($line == ''){
					$prev_blank = true;

					$variable_cnt = 0;
				}
				else{
					// Ce je bila prejsnja prazna gre za novo vprasanje
					if($prev_blank){
						$questin_cnt++;
						$text_array[$questin_cnt]['title'] = $line;
					}
					// Drugace gre za variablo v vprasanju
					else{
						$text_array[$questin_cnt][$variable_cnt] = $line;
						$variable_cnt++;
					}

					$prev_blank = false;
				}
			}
			
			return $text_array;
		}
		else
			return false;
    }
    
    // Izpise obvestilo, da ni podatkov
    static function noDataAlert($location='') {
        global $lang;
		global $anketa;
		global $site_url;
        
        echo '<div class="no_data_alert">';

        if($lang['id'] == '1')
		    echo '<img src="/public/img/images/no_data.svg" />';
        else
		    echo '<img src="/public/img/images/no_data_eng.svg" />';

        if($location == 'status') {
			echo '<h2>'.$lang['srv_dashboard_no_data'].'</h2>';
		}
		else {
			echo '<h2>'.$lang['srv_data_no_data'].'</h2>';
		}

        echo '<div id="note">';
		if($location == 'status') {
			echo '<p>'.$lang['srv_data_no_data3'].'</p>';
		}
		else {
			echo '<p>'.$lang['srv_data_no_data2'].'</p>';
		}
        echo '</div>';

		if($location == 'status') {
			$buttonA = 'index.php?anketa='.$anketa.'&a=branching'; //urejanje
			$buttonB = 'index.php?anketa='.$anketa.'&a=testiranje'; //testiranje
			$textA = $lang['edit2'];
			$textB = $lang['srv_testiranje'];
			$textC = $lang['srv_vabila'];
		}
		else {
			$buttonA = 'index.php?anketa='.$anketa.'&a=testiranje&m=testnipodatki'; //avtomatski testni vnos
			$buttonB = SurveyInfo::getSurveyLink() . '?preview=on&testdata=on'; //ročni testni vnos
			$textA = $lang['srv_testiranje_vnosi2'];
			$textB = $lang['srv_archive_test_data_text2a'];
			$textC = $lang['srv_anketa_share'];
		}

		$buttonC = 'index.php?anketa='.$anketa.'&amp;a=vabila'; //objava

		echo '<div id="buttons">';
		echo '  <a href="'.$buttonA.'"><button class="medium white-blue buttonA" onClick="window.location.href='.$buttonA.';return false;">'.$textA.'</button></a>';              
		echo '  <a href="'.$buttonB.'"><button class="medium white-blue buttonB" onClick="window.open('.$buttonB.', \'_blank\');return false;">'.$textB.'</button></a>';              
        echo '  <a href="'.$buttonC.'"><button class="medium blue buttonC">'.$textC.'</button></a>';
        echo '</div>';

        echo '</div>';
    }

    // Izpise obvestilo, da ni podatkov v javni povezavi
    static function noDataAlertPublic($action) {
        global $lang;
		global $anketa;
		global $site_url;
        
        header('Cache-Control: no-cache');
        header('Pragma: no-cache');
        
        #izpišemo HTML
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
        echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';


        echo '<head>';

        echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
        echo '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />';
        echo '<link type="text/css" href="'.$site_url.'admin/survey/minify/g=css" media="screen" rel="stylesheet" />';
        echo '<link type="text/css" href="'.$site_url.'admin/survey/minify/g=cssPrint" media="print" rel="stylesheet" />';
        echo '<style>';
        echo 'body{box-sizing: border-box; padding: 40px 20px; width: 100%; display: flex; align-items: center; justify-content: center; flex-direction: column;} h2{font-weight: 300; font-size: 24px; margin-block-start: 0; margin-block-end: 0; margin-bottom: 16px; text-align: center;} img {width: 100%; max-width: 466px; margin-bottom: 32px;}';
        echo '</style>';

        echo '</head>';


        echo '<body class="public_link data">'; 
            

		switch ($action) {			
			case 'data':
			case 'data_nijz':
				echo '<h2>'.$lang['srv_publc_data_title_for'].SurveyInfo::getSurveyTitle() .'</h2>';
			break;

			case M_ANALYSIS_CHARTS:
				echo '<h2>'.$lang['srv_publc_chart_title_for'].SurveyInfo::getSurveyTitle() .'</h2>';
			break;
				
			case M_ANALYSIS_CREPORT:
				echo '<h2>'.$lang['srv_publc_creport_title_for'].SurveyInfo::getSurveyTitle() .'</h2>';
			break;
					
			case 'analysis':
				echo '<h2>'.$lang['srv_publc_analysis_title_for'].SurveyInfo::getSurveyTitle() .'</h2>';	
			break;

			default:
				echo 'Error!';
			break;
		}

		if($lang['id'] == '1')
        	echo '<img src="/public/img/images/no_data.svg" />';
		else
        	echo '<img src="/public/img/images/no_data_eng.svg" />';

        echo '<h2>'.$lang['srv_data_no_data'].'</h2>';
        
        echo '</body>';


        echo '</html>';
    }

    // Vrne string s signaturjem za email v ustreznem jeziku (default slovenski)
    public static function getEmailSignature($lang_id = 0){
        global $lang;

        if(AppSettings::getInstance()->getSetting('app_settings-email_signature_custom') !== false){
            $signature = '<br /><br /><br />'.AppSettings::getInstance()->getSetting('app_settings-email_signature_text');
        }
        else{

            $signature = '<br /><br /><br />';

            $signature .= $lang['srv_1ka_mail_signature_bye'];

            $signature .= '<br /><br />';

            // Logo
            if($lang['id'] == '1')
                $signature .= '<img src="https://www.1ka.si/public/img/logo/1ka_logo_slo.jpg" width=90 style="width:90px; height:auto; border:0;" />';
            else
                $signature .= '<img src="https://www.1ka.si/public/img/logo/1ka_logo_eng.jpg" width=90 style="width:90px; height:auto; border:0;" />';

            $signature .= '<br/>-------------------------------------------------------------------<br/>';

            // Footer
            $signature .= '<span style="font-size:13px; line-height:30px;">';
            
            $signature .= ' <strong><span style="color:#1e88e5;">'.$lang['srv_1ka_mail_signature_help'].'</span></strong>';
            $signature .= ' <br/><strong><span style="color:#777777;">'.$lang['srv_1ka_mail_signature_click'].':</span></strong> <a href="'.($lang['id'] == '1' ? 'https://www.1ka.si/d/sl/storitve' : 'https://www.1ka.si/d/en/services').'" target="_blank" style="color:#1e88e5;">'.$lang['srv_1ka_mail_signature_link'].'</a>';
            $signature .= ' <br/><span style="color:#777777;">'.$lang['srv_1ka_mail_signature_social'].':</span> <a href="https://www.facebook.com/1KA-123545614388521/" target="_blank" style="color:#1e88e5;">Facebook</a> <span style="color:#777777;">'.$lang['srv_1ka_mail_signature_and'].'</span> <a href="https://twitter.com/enklikanketa" target="_blank" style="color:#1e88e5;">Twitter</a></span>';

            $signature .= '</span>';
        }

        return $signature;
    }
}?>